ngspice/src/frontend/arg.c

137 lines
2.3 KiB
C
Raw Normal View History

2000-04-27 22:03:57 +02:00
/**********
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1987 Jeffrey M. Hsu
**********/
/*
This files contains the routines to evalute arguments to a command
and prompt the user if necessary.
*/
#include <ngspice.h>
#include <fteinput.h>
#include <cpdefs.h>
#include <fteext.h>
2000-04-27 22:03:57 +02:00
#include "arg.h"
2001-02-09 20:46:36 +01:00
#include "variable.h"
2000-04-27 22:03:57 +02:00
static void common(char *string, struct wordlist *wl, struct comm *command);
/* returns a private copy of the string */
char *prompt(FILE *fp)
{
char buf[100];
char *p;
size_t n;
2000-04-27 22:03:57 +02:00
if (!fgets(buf, sizeof(buf), fp))
2011-07-17 18:40:34 +02:00
return NULL;
2000-04-27 22:03:57 +02:00
n = strlen(buf) - 1;
buf[n] = '\0'; /* fgets leaves the \n */
p = TMALLOC(char, n + 1);
2000-04-27 22:03:57 +02:00
strcpy(p, buf);
return p;
}
int countargs(wordlist *wl)
{
int number=0;
wordlist *w;
for (w = wl; w; w = w->wl_next) {
number++ ;
}
return(number);
}
wordlist *process(wordlist *wlist)
{
wlist = cp_variablesubst(wlist);
wlist = cp_bquote(wlist);
wlist = cp_doglob(wlist);
return (wlist);
}
void arg_print(wordlist *wl, struct comm *command)
{
common("which variable", wl, command);
}
void arg_plot(wordlist *wl, struct comm *command)
{
common("which variable", wl, command);
}
void arg_load(wordlist *wl, struct comm *command)
{
/* just call com_load */
2011-04-27 20:30:15 +02:00
command->co_func (wl);
2000-04-27 22:03:57 +02:00
}
void arg_let(wordlist *wl, struct comm *command)
{
common("which vector", wl, command);
}
void arg_set(wordlist *wl, struct comm *command)
{
common("which variable", wl, command);
}
void arg_display(wordlist *wl, struct comm *command)
2000-04-27 22:03:57 +02:00
{
2010-11-16 21:38:24 +01:00
NG_IGNORE(wl);
NG_IGNORE(command);
2000-04-27 22:03:57 +02:00
/* just return; display does the right thing */
}
/* a common prompt routine */
static void
common(char *string, struct wordlist *wl, struct comm *command)
{
struct wordlist *w;
char *buf;
if (!countargs(wl)) {
outmenuprompt(string);
if ((buf = prompt(cp_in)) == NULL) /* prompt aborted */
return; /* don't execute command */
/* do something with the wordlist */
w = alloc(struct wordlist);
w->wl_word = buf;
w->wl_next = NULL;
w = process(w);
/* O.K. now call fn */
2011-04-27 20:30:15 +02:00
command->co_func (w);
2000-04-27 22:03:57 +02:00
}
}
void
outmenuprompt(char *string)
{
fprintf(cp_out, "%s: ", string);
fflush(cp_out);
return;
}