void creadfile(char *save, int eraseflg) { register FILE *f; int pipefd[2]; int fildes; int pid; if (eraseflg && strcmp(save, curfile) && modcheck(" first")) return; if ((fildes = open(findhome(save), O_RDONLY, 0)) < 0) { error ("Can't read file \"%s\"", save); return; } if (eraseflg) erasedb(); if (pipe(pipefd) < 0) { error("Can't make pipe to child"); return; } deraw(1); (void) strcpy(KeyWord, getpass("Enter key:")); goraw(); if ((pid=fork()) == 0) { /* if child */ (void) close(0); /* close stdin */ (void) close(1); /* close stdout */ (void) close(pipefd[0]); /* close pipe input */ (void) dup(fildes); /* standard in from file */ (void) dup(pipefd[1]); /* connect to pipe */ (void) fprintf(stderr, " "); (void) execl(CRYPT_PATH, "crypt", KeyWord, 0); (void) fprintf(stderr, "execl(%s, \"crypt\", %s, 0) in creadfile() failed", CRYPT_PATH, KeyWord); exit(-127); } else { /* else parent */ (void) close(fildes); (void) close(pipefd[1]); /* close pipe output */ if ((f = fdopen(pipefd[0], "r")) == (FILE *)0) { (void) kill(pid, 9); error("Can't fdopen file \"%s\"", save); (void)close(pipefd[0]); return; } } loading++; while (fgets(line, sizeof(line), f)) { linelim = 0; if (line[0] != '#') (void) yyparse(); } --loading; (void) fclose(f); (void) close(pipefd[0]); while (pid != wait(&fildes)) /**/; linelim = -1; if (eraseflg) { (void) strcpy(curfile, save); modflg = 0; } }
int readfile(char * fname, int eraseflg) { register FILE * f; char save[PATHLEN]; //int tempautolabel; //char *p; //char *plugin; int pid = 0; int rfd = STDOUT_FILENO;//, savefd; //tempautolabel = autolabel; /* turn off auto label when */ //autolabel = 0; /* reading a file */ if (*fname == '*' && mdir) { (void) strcpy(save, mdir); (void) strcat(save, fname); } else { if (*fname == '\0') fname = curfile; (void) strcpy(save, fname); } /*if ((p = strrchr(fname, '.')) && (fname[0] != '|')) { // exclude macros if ((plugin = findplugin(p+1, 'r')) != NULL) { if (!(plugin_exists(plugin, strlen(plugin), save + 1))) { error("plugin not found"); return -1; } *save = '|'; if ((strlen(save) + strlen(fname) + 2) > PATHLEN) { error("Path too long"); return -1; } sprintf(save + strlen(save), " \"%s\"", fname); eraseflg = 0; // get filename: could be preceded by params if this is a save while (p > fname) { if (*p == ' ') { p++; break; } p--; } (void) strcpy(curfile, p); } }*/ // what is this? //if (eraseflg && strcmp(fname, curfile) && modcheck(" first")) // return 0; if (fname[0] == '-' && fname[1] == '\0') { f = stdin; *save = '\0'; } else { if ((f = openfile(save, &pid, &rfd)) == NULL) { error("Can't read file \"%s\"", save); //autolabel = tempautolabel; return 0; } else if (eraseflg) { info("Reading file \"%s\"", save); //refresh(); } } if (*fname == '|') *save = '\0'; if (eraseflg) erasedb(); loading++; //savefd = macrofd; //macrofd = rfd; while (! brokenpipe && fgets(line, sizeof(line), f)) { if (line[0] == '|' && pid != 0) { line[0] = ' '; } linelim = 0; if (line[0] != '#') (void) yyparse(); } //macrofd = savefd; --loading; closefile(f, pid, rfd); if (f == stdin) { freopen("/dev/tty", "r", stdin); } linelim = -1; if (eraseflg) { (void) strcpy(curfile, save); modflg = 0; cellassign = 0; if (autorun && !skipautorun) (void) readfile(autorun, 0); skipautorun = 0; EvalAll(); } //autolabel = tempautolabel; return 1; }