Mercurial > hg > mlmmj
view src/gethdrline.c @ 17:b045203f558b
Add GPL info in top of files where it was missing, and remove a file that
was committed by mistake
author | mmj |
---|---|
date | Thu, 22 Apr 2004 23:00:27 +1000 |
parents | 8e1ebc68ee62 |
children | 91830455b49c |
line wrap: on
line source
/* Copyright (C) 2004 Mads Martin Joergensen <mmj at mmj.dk> * * $Id$ * * This file is redistributable under version 2 of the GNU General * Public License as described at http://www.gnu.org/licenses/gpl.txt */ #include <stdio.h> #include <stdlib.h> #include "mygetline.h" #include "gethdrline.h" #include "strgen.h" char *gethdrline(FILE *infile) { char *line = NULL, *retstr = NULL, *nextline = NULL, *tmp = NULL; int ch; for(;;) { line = mygetline(infile); if(line == NULL) return NULL; ch = getc(infile); ungetc(ch, infile); if(ch == '\t' || ch == ' ') { nextline = mygetline(infile); tmp = retstr; retstr = concatstr(3, retstr, line, nextline); free(tmp); free(line); free(nextline); tmp = line = nextline = NULL; ch = getc(infile); ungetc(ch, infile); if(!(ch == '\t' || ch == ' ')) return retstr; } else { tmp = retstr; retstr = concatstr(3, retstr, line, nextline); free(tmp); return retstr; } } } #if 0 int main(int argc, char **argv) { char *str; while((str = gethdrline(stdin))) { printf("%s", str); free(str); } free(str); return 0; } #endif