#! /usr/bin/awk -f # BEGIN { # f = fopen("preproc.c"); # while((c = fgetc(f)) != -1) # printf("%c", c); # fclose(f); # exit(0); # } function fopen(filename) { _FOPEN[filename] = 1; return (filename); } function fclose(filename) { if(_FOPEN[filename]) { delete _FOPEN[filename]; delete _FGETC; close(filename); } return; } function fgetc(filename ,lastline) { if(! _FOPEN[filename]) return (-1); _FGETC[1] = ((_FGETC[1] > 0) ? _FGETC[1] : 1); if((_FGETC[1] >= _FGETC[0]) || ((!_FGETC[2]))) { if((getline lastline < filename) > 0) { _FGETC[2] = (lastline "\n"); _FGETC[0] = (length(_FGETC[2]) + 1); _FGETC[1] = 1; } else return (-1); } return (substr(_FGETC[2], (_FGETC[1]++), 1)); } function ungetc(char) { return (ungets(substr(char, 1, 1))); } function fgetline(filename, c,l) { if((c = fgetc(filename)) == -1) return (-1); if(c == "\n") return (""); l = (l c); while(((c = fgetc(filename)) != -1) && (c != "\n")) l = (l c); return (l); } function ungets(string ,result) { result = (substr(_FGETC[2], 1, (_FGETC[1] - 1)) (string) \ substr(_FGETC[2], _FGETC[1], (_FGETC[0] - _FGETC[1]))); _FGETC[2] = (result); _FGETC[0] += (length(string) + ((_FGETC[1] > 0) ? 0 : 1)); return (result); }