/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "copy.p" */ #include /* file copying program thomas schneider copyright 1982 module libraries: delman, delmods */ /* end of program */ /* begin module version */ #define version 1.07 /* of copy.p 1994 sep 5 */ /* end module version */ /* begin module describe.copy */ /* name copy: copy one file to another file synopsis copy(fin: in, fout: out, output: out) files fin: the file to be copied fout: the copy of fin output: messages to the user description copy makes one copy of the file fin on the file fout. you may discover that this is a simple task that you often want to do, but that your system does not provide an easy way. see also shift.p author thomas d. schneider bugs none known */ /* end module describe.copy */ Static _TEXT fin, fout; /* copy from fin to fout */ Static long linescopied; /* the number of lines copied */ Static jmp_buf _JL1; /* begin module package.primitive */ /* ************************************************************************ */ /* begin module halt */ Static Void halt() { /* stop the program. the procedure performs a goto to the end of the program. you must have a label: label 1; declared, and also the end of the program must have this label: 1: end. examples are in the module libraries. this is the only goto in the delila system. */ printf(" program halt.\n"); longjmp(_JL1, 1); } /* end module halt version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module unlimitln */ Static Void unlimitln(afile) _TEXT *afile; { /* this procedure removes a stupid system dependent limit on the number of lines that one can write to a file. you may remove it from the code if your system does not want or need this. suggested method: place comments around the contents of the procedure. */ /* linelimit(afile, maxint); (* set 'infinite' lines allowed for afile */ } /* end module unlimitln version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module copyaline */ Static Void copyaline(fin, fout) _TEXT *fin, *fout; { /* copy a line from file fin to file fout */ while (!P_eoln(fin->f)) { putc(P_peek(fin->f), fout->f); getc(fin->f); } fscanf(fin->f, "%*[^\n]"); getc(fin->f); putc('\n', fout->f); } /* copyaline */ /* end module copyaline version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module copylines */ Static long copylines(fin, fout, n) _TEXT *fin, *fout; long n; { /* copy n lines of file fin to file fout. the actual number of lines copied is returned. */ long index = 0; /* the current line number */ while (!BUFEOF(fin->f) && index < n) { copyaline(fin, fout); index++; } return index; } /* copylines */ /* end module copylines version = 'delmod 6.51 85 apr 17 tds/gds' */ /* ************************************************************************ */ /* end module package.primitive version = 'delmod 6.51 85 apr 17 tds/gds' */ main(argc, argv) int argc; Char *argv[]; { /* begin module copy.main */ PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; fout.f = NULL; strcpy(fout.name, "fout"); fin.f = NULL; strcpy(fin.name, "fin"); printf(" copy %4.2f\n", version); if (*fin.name != '\0') { if (fin.f != NULL) fin.f = freopen(fin.name, "r", fin.f); else fin.f = fopen(fin.name, "r"); } else rewind(fin.f); if (fin.f == NULL) _EscIO2(FileNotFound, fin.name); RESETBUF(fin.f, Char); if (*fout.name != '\0') { if (fout.f != NULL) fout.f = freopen(fout.name, "w", fout.f); else fout.f = fopen(fout.name, "w"); } else { if (fout.f != NULL) rewind(fout.f); else fout.f = tmpfile(); } if (fout.f == NULL) _EscIO2(FileNotFound, fout.name); SETUPBUF(fout.f, Char); unlimitln(&fout); linescopied = 0; while (!BUFEOF(fin.f)) linescopied += copylines(&fin, &fout, LONG_MAX); printf(" %ld lines copied\n", linescopied); /* end module copy.main */ _L1: if (fin.f != NULL) fclose(fin.f); if (fout.f != NULL) fclose(fout.f); exit(EXIT_SUCCESS); } /* copy */ /* End. */