1 /*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rodney Ruddock of the University of Guelph. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char sccsid[] = "@(#)f.c 8.1 (Berkeley) 05/31/93"; 13 #endif /* not lint */ 14 15 #include <sys/types.h> 16 17 #include <limits.h> 18 #include <regex.h> 19 #include <setjmp.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <string.h> 23 24 #ifdef DBI 25 #include <db.h> 26 #endif 27 28 #include "ed.h" 29 #include "extern.h" 30 31 /* 32 * Prints out or sets the remembered filename. 33 */ 34 void 35 f(inputt, errnum) 36 FILE *inputt; 37 int *errnum; 38 { 39 char *l_temp; 40 41 l_temp = filename(inputt, errnum); 42 if (*errnum == 1) { 43 sigspecial++; 44 /* user wants the name from a sh command */ 45 if (l_temp && l_temp[FILENAME_LEN+1]) { 46 FILE *namestream, *popen(); 47 int l_len; 48 49 if (l_temp[0] == '\0') { 50 strcpy(help_msg, "no command given"); 51 *errnum = -1; 52 return; 53 } 54 if (((namestream = popen(l_temp, "r")) == NULL) || 55 ((fgets(l_temp, FILENAME_LEN - 1, namestream)) == NULL)) { 56 strcpy(help_msg, "error executing command"); 57 *errnum = -1; 58 if (namestream != NULL) 59 pclose(namestream); 60 ungetc('\n', inputt); 61 return; 62 } 63 l_len = strlen(l_temp) - 1; 64 if (l_temp[l_len] == '\n') 65 l_temp[l_len] = '\0'; 66 pclose(namestream); 67 } 68 free(filename_current); 69 filename_current = l_temp; 70 sigspecial--; 71 if (sigint_flag && (!sigspecial)) 72 SIGINT_ACTION; 73 } else 74 if (*errnum == -2) 75 while (((ss = getc(inputt)) != '\n') || (ss == EOF)); 76 else 77 if (*errnum < 0) 78 return; 79 if (filename_current) 80 fwrite(filename_current, 81 sizeof(char), strlen(filename_current), stdout); 82 putchar('\n'); 83 *errnum = 1; 84 } 85