157684Sbostic /*-
2*60663Sbostic * Copyright (c) 1992, 1993
3*60663Sbostic * The Regents of the University of California. 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*60663Sbostic static char sccsid[] = "@(#)f.c 8.1 (Berkeley) 05/31/93";
1357684Sbostic #endif /* not lint */
1457684Sbostic
1557710Sbostic #include <sys/types.h>
1657710Sbostic
1759475Sbostic #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
f(inputt,errnum)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++;
4459475Sbostic /* user wants the name from a sh command */
4559475Sbostic if (l_temp && l_temp[FILENAME_LEN+1]) {
4659475Sbostic FILE *namestream, *popen();
4759475Sbostic int l_len;
4859475Sbostic
4959475Sbostic if (l_temp[0] == '\0') {
5059475Sbostic strcpy(help_msg, "no command given");
5159475Sbostic *errnum = -1;
5259475Sbostic return;
5359475Sbostic }
5459475Sbostic if (((namestream = popen(l_temp, "r")) == NULL) ||
5559475Sbostic ((fgets(l_temp, FILENAME_LEN - 1, namestream)) == NULL)) {
5659475Sbostic strcpy(help_msg, "error executing command");
5759475Sbostic *errnum = -1;
5859475Sbostic if (namestream != NULL)
5959475Sbostic pclose(namestream);
6059475Sbostic ungetc('\n', inputt);
6159475Sbostic return;
6259475Sbostic }
6359475Sbostic l_len = strlen(l_temp) - 1;
6459475Sbostic if (l_temp[l_len] == '\n')
6559475Sbostic l_temp[l_len] = '\0';
6659475Sbostic pclose(namestream);
6759475Sbostic }
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