home *** CD-ROM | disk | FTP | other *** search
- # include <stdio.h>
- # include <string.h>
- # include "ptcmain.h"
- # include "ptcerror.h"
-
- static char rcsid[] = "$Id: c.FOPEN 1.3 91/03/09 20:57:15 gtoal Exp Locker: gtoal $";
-
- FILE *
- F_open(n, l, m, lineno, fname)
- char *n, *m;
- int l, lineno;
- char *fname;
- {
- /* fname is the internal filename as in the prog hdr */
- FILE *f;
- register char *s;
- char tmp[MAXFILENAME+1];
- #ifndef __STDC__
- extern int unlink(); /* remove = ANSI preferred to Posix */
- #define remove(f) unlink(f)
- extern char *tempnam(); /* tmpnam = ANSI in <stdio.h> */
- #define tmpnam(s) tempnam(NULL, s)
- #endif
- if (n == NULL) {
- /*
- * Do an 'extended getopt' with fname as the keystring; if none
- * found, prompt from :TT using keystring as a prompt. Ideally
- * would also use positional parameters but can't access them at
- * this stage.
- */
- static char line[256];
- fprintf(stderr, "%s: ", fname); fflush(stderr);
- gets(line); l = strlen(line);
- if (line[l-1] == '\n') line[--l] = '\0';
- if (line[0] != '\0') n = line;
- }
- if (n == NULL) {
- if (*m == 'r') strcpy(tmp, "NULL:"); else strcpy(tmp, tmpnam("ptc"));
- } else {
- if (strcmp(n, "TTY:") == 0) n = ":TT";
- if (l < 0)
- l = strlen(n);
- if (l > MAXFILENAME)
- PTCerror(PTC_E_TOOLONGFILENAME, lineno, 0, 0, 0);
- strncpy(tmp, n, l);
- tmp[l] = '\0';
- /* Scan for first blank or null */
- for (s = tmp; *s != ' ' && *s != '\0'; )
- s++;
- *s = '\0';
- }
- s = tmp;
- if ((f = fopen(s, m)) == NULL)
- PTCerror(PTC_E_CANTOPEN, lineno, (int)s, (int)m, 0); /* Unsafe if ptr not same size as int */
- if (n == NULL)
- remove(tmp);
- return (f);
- }
-
-
-