[3ae31e9] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | stdopen.c -- standard C file openers
|
---|
| 4 | Version 1 -- 1988-11-07 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #define OPEN_AB /* define to compile stdopna(), stdopnb() */
|
---|
| 9 |
|
---|
| 10 | #include "stdio.h" /* standard I/O definitions */
|
---|
| 11 | #include "stddefs.h" /* standard C utility definitions */
|
---|
| 12 |
|
---|
| 13 | extern char *pgmname; /* program name string pointer */
|
---|
| 14 |
|
---|
| 15 | extern short (*errterm)(); /* program error termination exit function */
|
---|
| 16 |
|
---|
| 17 | extern FILE *(*opnfail)(); /* file open error function */
|
---|
| 18 |
|
---|
| 19 | /*
|
---|
| 20 | =============================================================================
|
---|
| 21 | stdopen() -- standard C file opener -- system standard files
|
---|
| 22 | =============================================================================
|
---|
| 23 | */
|
---|
| 24 |
|
---|
| 25 | FILE *
|
---|
| 26 | stdopen(name, mode)
|
---|
| 27 | char *name, *mode;
|
---|
| 28 | {
|
---|
| 29 | FILE *fp;
|
---|
| 30 |
|
---|
| 31 | if ((FILE *)NULL EQ (fp = fopen(name, mode))) {
|
---|
| 32 |
|
---|
| 33 | if (opnfail)
|
---|
| 34 | if ((FILE *)NULL NE (fp = (*opnfail)(name, mode)))
|
---|
| 35 | return(fp);
|
---|
| 36 |
|
---|
| 37 | fprintf(stderr, "%s: ERROR - Unable to open \"%s\" in mode \"%s\".\n",
|
---|
| 38 | name, mode);
|
---|
| 39 |
|
---|
| 40 | if (errterm)
|
---|
| 41 | (*errterm)();
|
---|
| 42 |
|
---|
| 43 | fprintf(stderr, "%s: Program terminated due to I/O error.\n");
|
---|
| 44 | exit(1);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | return(fp);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | /* |
---|
| 51 |
|
---|
| 52 | */
|
---|
| 53 |
|
---|
| 54 | #ifdef OPEN_AB
|
---|
| 55 |
|
---|
| 56 | /*
|
---|
| 57 | =============================================================================
|
---|
| 58 | stdopna() -- standard C file opener -- ASCII files
|
---|
| 59 | =============================================================================
|
---|
| 60 | */
|
---|
| 61 |
|
---|
| 62 | FILE *
|
---|
| 63 | stdopna(name, mode)
|
---|
| 64 | char *name, *mode;
|
---|
| 65 | {
|
---|
| 66 | FILE *fp;
|
---|
| 67 |
|
---|
| 68 | if ((FILE *)NULL EQ (fp = fopena(name, mode))) {
|
---|
| 69 |
|
---|
| 70 | if (opnfail)
|
---|
| 71 | if ((FILE *)NULL NE (fp = (*opnfail)(name, mode)))
|
---|
| 72 | return(fp);
|
---|
| 73 |
|
---|
| 74 | fprintf(stderr, "%s: ERROR - Unable to open \"%s\" in mode \"%s\".\n",
|
---|
| 75 | name, mode);
|
---|
| 76 |
|
---|
| 77 | if (errterm)
|
---|
| 78 | (*errterm)();
|
---|
| 79 |
|
---|
| 80 | fprintf(stderr, "%s: Program terminated due to I/O error.\n");
|
---|
| 81 | exit(1);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | return(fp);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | #endif
|
---|
| 88 |
|
---|
| 89 | /* |
---|
| 90 |
|
---|
| 91 | */
|
---|
| 92 |
|
---|
| 93 | #ifdef OPEN_AB
|
---|
| 94 |
|
---|
| 95 | /*
|
---|
| 96 | =============================================================================
|
---|
| 97 | stdopnb() -- standard C file opener -- binary files
|
---|
| 98 | =============================================================================
|
---|
| 99 | */
|
---|
| 100 |
|
---|
| 101 | FILE *
|
---|
| 102 | stdopnb(name, mode)
|
---|
| 103 | char *name, *mode;
|
---|
| 104 | {
|
---|
| 105 | FILE *fp;
|
---|
| 106 |
|
---|
| 107 | if ((FILE *)NULL EQ (fp = fopenb(name, mode))) {
|
---|
| 108 |
|
---|
| 109 | if (opnfail)
|
---|
| 110 | if ((FILE *)NULL NE (fp = (*opnfail)(name, mode)))
|
---|
| 111 | return(fp);
|
---|
| 112 |
|
---|
| 113 | fprintf(stderr, "%s: ERROR - Unable to open \"%s\" in mode \"%s\".\n",
|
---|
| 114 | name, mode);
|
---|
| 115 |
|
---|
| 116 | if (errterm)
|
---|
| 117 | (*errterm)();
|
---|
| 118 |
|
---|
| 119 | fprintf(stderr, "%s: Program terminated due to I/O error.\n");
|
---|
| 120 | exit(1);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | return(fp);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | #endif
|
---|