157684Sbostic /*- 257684Sbostic * Copyright (c) 1992 The Regents of the University of California. 357684Sbostic * All rights reserved. 457684Sbostic * 557684Sbostic * This code is derived from software contributed to Berkeley by 657684Sbostic * Rodney Ruddock of the University of Guelph. 757684Sbostic * 857684Sbostic * %sccs.include.redist.c% 957684Sbostic */ 1057684Sbostic 1157684Sbostic #ifndef lint 12*59475Sbostic static char sccsid[] = "@(#)f.c 5.4 (Berkeley) 04/28/93"; 1357684Sbostic #endif /* not lint */ 1457684Sbostic 1557710Sbostic #include <sys/types.h> 1657710Sbostic 17*59475Sbostic #include <limits.h> 1857710Sbostic #include <regex.h> 1957710Sbostic #include <setjmp.h> 2057710Sbostic #include <stdio.h> 2157710Sbostic #include <stdlib.h> 2257710Sbostic #include <string.h> 2357710Sbostic 2458315Sbostic #ifdef DBI 2558315Sbostic #include <db.h> 2658315Sbostic #endif 2758315Sbostic 2857684Sbostic #include "ed.h" 2957710Sbostic #include "extern.h" 3057684Sbostic 3157684Sbostic /* 3257684Sbostic * Prints out or sets the remembered filename. 3357684Sbostic */ 3457684Sbostic void 3557684Sbostic f(inputt, errnum) 3657710Sbostic FILE *inputt; 3757710Sbostic int *errnum; 3857684Sbostic { 3957710Sbostic char *l_temp; 4057684Sbostic 4157710Sbostic l_temp = filename(inputt, errnum); 4257710Sbostic if (*errnum == 1) { 4358315Sbostic sigspecial++; 44*59475Sbostic /* user wants the name from a sh command */ 45*59475Sbostic if (l_temp && l_temp[FILENAME_LEN+1]) { 46*59475Sbostic FILE *namestream, *popen(); 47*59475Sbostic int l_len; 48*59475Sbostic 49*59475Sbostic if (l_temp[0] == '\0') { 50*59475Sbostic strcpy(help_msg, "no command given"); 51*59475Sbostic *errnum = -1; 52*59475Sbostic return; 53*59475Sbostic } 54*59475Sbostic if (((namestream = popen(l_temp, "r")) == NULL) || 55*59475Sbostic ((fgets(l_temp, FILENAME_LEN - 1, namestream)) == NULL)) { 56*59475Sbostic strcpy(help_msg, "error executing command"); 57*59475Sbostic *errnum = -1; 58*59475Sbostic if (namestream != NULL) 59*59475Sbostic pclose(namestream); 60*59475Sbostic ungetc('\n', inputt); 61*59475Sbostic return; 62*59475Sbostic } 63*59475Sbostic l_len = strlen(l_temp) - 1; 64*59475Sbostic if (l_temp[l_len] == '\n') 65*59475Sbostic l_temp[l_len] = '\0'; 66*59475Sbostic pclose(namestream); 67*59475Sbostic } 6857710Sbostic free(filename_current); 6957710Sbostic filename_current = l_temp; 7058315Sbostic sigspecial--; 7158315Sbostic if (sigint_flag && (!sigspecial)) 7258315Sbostic SIGINT_ACTION; 7357710Sbostic } else 7457710Sbostic if (*errnum == -2) 7557710Sbostic while (((ss = getc(inputt)) != '\n') || (ss == EOF)); 7657710Sbostic else 7757710Sbostic if (*errnum < 0) 7857710Sbostic return; 7958315Sbostic if (filename_current) 8058315Sbostic fwrite(filename_current, 8158315Sbostic sizeof(char), strlen(filename_current), stdout); 8257710Sbostic putchar('\n'); 8357710Sbostic *errnum = 1; 8457710Sbostic } 85