/* FLJOIN.C * * This file is part of the * Fortran single/double converter * Copyright (c) 1990, Jim Meyering * * You may redistribute under the terms of the GNU General * Public License as specified in the files README and COPYING. */ #include #ifndef _SYSTEM_H #define _SYSTEM_H #ifdef __STDC__ typedef void* ptr; #define PROTO(arglist) arglist #else typedef char* ptr; # define const /* NOTHING */ # define volatile /* NOTHING */ # define PROTO(arglist) () #endif int _filbuf PROTO((FILE*)); int _flsbuf PROTO((unsigned char x, FILE*)); volatile void exit PROTO((int)); int read PROTO((int d, ptr buf, int nbytes)); volatile void abort PROTO((void)); char *malloc PROTO((unsigned int)); char *realloc PROTO((char *,unsigned int)); #endif char *xmalloc(unsigned int n) { char *p; p = malloc(n); if (p == NULL) { fprintf(stderr, "xmalloc: Exhausted available memory.\n"); exit(2); } return (p); } char *xrealloc(char *p, unsigned int n) { p = realloc(p, n); if (p == NULL) { fprintf(stderr, "xrealloc: Exhausted available memory.\n"); exit(2); } return (p); } long readline(FILE * stream, char **line) /* Read a line of text from `stream' into a static buffer * and return a pointer to it. The text of the line is * returned in `*line' and has a trailing '\0' instead of * the original NEWLINE. Returns the length of the line * a` la strlen. When EOF is reached (i.e. on the call * after the last line is read), -1 is returned. */ { #define INIT_BUFFER_SIZE 80; static char *buffer; static int buf_size = 0; register char *p; register int i, n; if (buf_size == 0) { buf_size = INIT_BUFFER_SIZE; buffer = xmalloc(buf_size * sizeof(*buffer)); } p = buffer; n = buf_size; i = 0; for (;;) { int c = getc(stream); if (i >= n) { n += (n + 1) / 2; p = xrealloc(p, n); } if (c == '\n') { p[i] = '\0'; break; } if (c < 0) { p[i] = '\0'; return (-1); } p[i++] = c; } *line = p; buf_size = n; return (i); } void main() { /* join f77 continued lines */ /* * Believe it or not this is according to the standard: * A blank or a 0 (zero) in column 6 * demark NON-continuation lines. */ #define is_continuation_line(len,c1,c6) \ ( (len) >= 6 && (c1) != 'c' && (c1) != 'C' && (c1) != '*' \ && (c6) != ' ' && (c6) != '0' ) char *line; int line_length, first_line; first_line = 1; while ((line_length = readline(stdin, &line)) >= 0) { /* * Print a newline character if the line we just read is * neither a continuation line nor the first line of input. */ if (!first_line && !is_continuation_line(line_length, line[0], line[5])) { putchar('\n'); } if (is_continuation_line(line_length,line[0], line[5])) { fputs(&line[6], stdout); } else { fputs(line, stdout); } first_line = 0; } putchar('\n'); exit(0); }