Commit | Line | Data |
---|---|---|
440f05ef | 1 | /*- |
ba5e8546 KB |
2 | * Copyright (c) 1992, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
440f05ef KB |
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 | |
ba5e8546 | 12 | static char sccsid[] = "@(#)f.c 8.1 (Berkeley) %G%"; |
440f05ef KB |
13 | #endif /* not lint */ |
14 | ||
ecbf4ad0 KB |
15 | #include <sys/types.h> |
16 | ||
afdef93a | 17 | #include <limits.h> |
ecbf4ad0 KB |
18 | #include <regex.h> |
19 | #include <setjmp.h> | |
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | #include <string.h> | |
23 | ||
e692f66f KB |
24 | #ifdef DBI |
25 | #include <db.h> | |
26 | #endif | |
27 | ||
440f05ef | 28 | #include "ed.h" |
ecbf4ad0 | 29 | #include "extern.h" |
440f05ef KB |
30 | |
31 | /* | |
32 | * Prints out or sets the remembered filename. | |
33 | */ | |
440f05ef KB |
34 | void |
35 | f(inputt, errnum) | |
ecbf4ad0 KB |
36 | FILE *inputt; |
37 | int *errnum; | |
440f05ef | 38 | { |
ecbf4ad0 | 39 | char *l_temp; |
440f05ef | 40 | |
ecbf4ad0 | 41 | l_temp = filename(inputt, errnum); |
ecbf4ad0 | 42 | if (*errnum == 1) { |
e692f66f | 43 | sigspecial++; |
afdef93a KB |
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 | } | |
ecbf4ad0 KB |
68 | free(filename_current); |
69 | filename_current = l_temp; | |
e692f66f KB |
70 | sigspecial--; |
71 | if (sigint_flag && (!sigspecial)) | |
72 | SIGINT_ACTION; | |
ecbf4ad0 KB |
73 | } else |
74 | if (*errnum == -2) | |
75 | while (((ss = getc(inputt)) != '\n') || (ss == EOF)); | |
76 | else | |
77 | if (*errnum < 0) | |
78 | return; | |
e692f66f KB |
79 | if (filename_current) |
80 | fwrite(filename_current, | |
81 | sizeof(char), strlen(filename_current), stdout); | |
ecbf4ad0 KB |
82 | putchar('\n'); |
83 | *errnum = 1; | |
84 | } |