annotate Lib/fftw-3.2.1/api/.svn/text-base/mkprinter-file.c.svn-base @ 9:262e084a15a9

Vectorised everything and made use of unique_ptr so there should be no more memory leaks. Hurrah for RAII
author Geogaddi\David <d.m.ronan@qmul.ac.uk>
date Wed, 12 Aug 2015 22:25:06 +0100
parents 25bf17994ef1
children
rev   line source
d@0 1 /*
d@0 2 * Copyright (c) 2003, 2007-8 Matteo Frigo
d@0 3 * Copyright (c) 2003, 2007-8 Massachusetts Institute of Technology
d@0 4 *
d@0 5 * This program is free software; you can redistribute it and/or modify
d@0 6 * it under the terms of the GNU General Public License as published by
d@0 7 * the Free Software Foundation; either version 2 of the License, or
d@0 8 * (at your option) any later version.
d@0 9 *
d@0 10 * This program is distributed in the hope that it will be useful,
d@0 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d@0 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d@0 13 * GNU General Public License for more details.
d@0 14 *
d@0 15 * You should have received a copy of the GNU General Public License
d@0 16 * along with this program; if not, write to the Free Software
d@0 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
d@0 18 *
d@0 19 */
d@0 20
d@0 21 #include "api.h"
d@0 22 #include <stdio.h>
d@0 23
d@0 24 #define BUFSZ 256
d@0 25
d@0 26 typedef struct {
d@0 27 printer super;
d@0 28 FILE *f;
d@0 29 char buf[BUFSZ];
d@0 30 char *bufw;
d@0 31 } P;
d@0 32
d@0 33 static void myflush(P *p)
d@0 34 {
d@0 35 fwrite(p->buf, 1, p->bufw - p->buf, p->f);
d@0 36 p->bufw = p->buf;
d@0 37 }
d@0 38
d@0 39 static void myputchr(printer *p_, char c)
d@0 40 {
d@0 41 P *p = (P *) p_;
d@0 42 if (p->bufw >= p->buf + BUFSZ)
d@0 43 myflush(p);
d@0 44 *p->bufw++ = c;
d@0 45 }
d@0 46
d@0 47 static void mycleanup(printer *p_)
d@0 48 {
d@0 49 P *p = (P *) p_;
d@0 50 myflush(p);
d@0 51 }
d@0 52
d@0 53 printer *X(mkprinter_file)(FILE *f)
d@0 54 {
d@0 55 P *p = (P *) X(mkprinter)(sizeof(P), myputchr, mycleanup);
d@0 56 p->f = f;
d@0 57 p->bufw = p->buf;
d@0 58 return &p->super;
d@0 59 }