aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorpowwow@askgustav.com <powwow@askgustav.com>2019-03-18 23:05:26 (GMT)
committerSteve Slaven <bpk@hoopajoo.net>2019-04-23 20:37:05 (GMT)
commit304a722c426f47a461dc88c4493f800c0690b29b (patch)
tree151b974354c0c7ec4e89649a949db32f11b56442 /main.c
parent7db984561ef8fd0ff9165288324dbc81516113f0 (diff)
downloadpowwow-304a722c426f47a461dc88c4493f800c0690b29b.zip
powwow-304a722c426f47a461dc88c4493f800c0690b29b.tar.gz
powwow-304a722c426f47a461dc88c4493f800c0690b29b.tar.bz2
remove some non-ANSI C support
Diffstat (limited to 'main.c')
-rw-r--r--main.c484
1 files changed, 242 insertions, 242 deletions
diff --git a/main.c b/main.c
index a9f3088..b6988ab 100644
--- a/main.c
+++ b/main.c
@@ -10,8 +10,8 @@
*
*
* History:
- *
- * Initially inspired to the Tintin client by Peter Unold,
+ *
+ * Initially inspired to the Tintin client by Peter Unold,
* Powwow contains no Tintin code.
* The original program Cancan, written by Mattias Engdegård (Yorick)
* (f91-men@nada.kth.se) 1992-94,
@@ -20,7 +20,7 @@
* to make it yet more powerful.
* AmigaDOS porting attempt by Fror.
* Many new features added by Dain.
- * As usual, all the developers are in debt to countless users
+ * As usual, all the developers are in debt to countless users
* for suggestions and debugging.
* Maintance was taken over by Steve Slaven (bpk@hoopajoo.net) in 2005
*/
@@ -95,22 +95,22 @@ extern int select();
/* local function declarations */
#ifdef MOTDFILE
-static void printmotd __P ((void));
+static void printmotd(void);
#endif
-static void mainloop __P ((void));
-static void exec_delays __P ((void));
-static void prompt_reset_iac __P ((void));
-static void get_remote_input __P ((void));
-static void get_user_input __P ((void));
+static void mainloop(void);
+static void exec_delays(void);
+static void prompt_reset_iac(void);
+static void get_remote_input(void);
+static void get_user_input(void);
-static int search_action_or_prompt __P ((char *line, char clearline, char copyprompt));
+static int search_action_or_prompt(char *line, char clearline, char copyprompt);
#define search_action(line, clearline) search_action_or_prompt((line), (clearline), 0)
#define search_prompt(line, copyprompt) search_action_or_prompt((line), 0, (copyprompt)+1)
-static void set_params __P ((char *line, int *match_s, int *match_e));
-static void parse_commands __P ((char *command, char *arg));
-static int subst_param __P ((ptr *buf, char *src));
-static int jit_subst_vars __P ((ptr *buf, char *src));
+static void set_params(char *line, int *match_s, int *match_e);
+static void parse_commands(char *command, char *arg);
+static int subst_param(ptr *buf, char *src);
+static int jit_subst_vars(ptr *buf, char *src);
/* GLOBALS */
@@ -120,8 +120,8 @@ static char *copyname = COPYNAME;
long received = 0; /* amount of data received from remote host */
long sent = 0; /* amount of data sent to remote host */
-VOLATILE char confirm = 0; /* 1 if just tried to quit */
-int history_done = 0; /* number of recursive #history commands */
+volatile char confirm = 0; /* 1 if just tried to quit */
+int history_done = 0; /* number of recursive #history commands */
int prompt_status = 0; /* prompt status: 0 = ready -> nothing to do;
* 1 if internal echo -> must redraw;
* -1 if something sent to MUD -> waiting for it.
@@ -217,7 +217,7 @@ char edattrend[CAPLEN]; /* ending input line attributes */
int edattrbg; /* input line attributes do change bg color */
/* signals handling */
-VOLATILE int sig_pending, sig_winch_got, sig_chld_got;
+volatile int sig_pending, sig_winch_got, sig_chld_got;
/* GH: different ID characters for different action types */
@@ -236,7 +236,7 @@ int delim_mode = DELIM_NORMAL;
/* Group delimiter */
char *group_delim;
-int main __P2 (int,argc, char **,argv)
+int main(int argc, char **argv)
{
char *p;
int i;
@@ -256,12 +256,12 @@ int main __P2 (int,argc, char **,argv)
update_now();
ref_time = start_time = movie_last = now;
-
+
start_clock = cpu_clock = clock();
#ifndef NO_RANDOM
init_random((int)now.tv_sec);
#endif
-
+
initialize_cmd();
if ((p = getenv("POWWOWDIR"))) {
@@ -270,20 +270,20 @@ int main __P2 (int,argc, char **,argv)
strcat(powwow_dir, "/");
} else
powwow_dir[0] = '\0';
-
+
if ((p = getenv("POWWOWHELP")))
strcpy(helpfile, p);
else if (powwow_dir[0])
strcpy(helpfile, powwow_dir);
else
strcpy(helpfile, POWWOW_DIR);
-
+
if (helpfile[strlen(helpfile) - 1] != '/')
strcat(helpfile, "/");
strcat(helpfile, helpname);
if (access(helpfile, R_OK) == -1 && !access(helpname, R_OK))
strcpy(helpfile, helpname);
-
+
if (powwow_dir[0])
strcpy(copyfile, powwow_dir);
else
@@ -293,7 +293,7 @@ int main __P2 (int,argc, char **,argv)
strcat(copyfile, copyname);
if (access(copyfile, R_OK) == -1 && !access(copyname, R_OK))
strcpy(copyfile, copyname);
-
+
/* initialize variables */
if ((var = (vars *)malloc(sizeof(vars)*(NUMTOT+max_named_vars)))) {
for (i=0; i<NUMTOT; i++) {
@@ -302,10 +302,10 @@ int main __P2 (int,argc, char **,argv)
}
} else
syserr("malloc");
-
+
/* stack is empty */
paramstk.curr = 0;
-
+
/* allocate permanent variables */
if ((prompt = add_varnode("prompt", 1))
&& (prompt->str = ptrnew(PARAMLEN))
@@ -318,8 +318,8 @@ int main __P2 (int,argc, char **,argv)
;
else
syserr("malloc");
-
-
+
+
/*
ptr_bootstrap();
utils_bootstrap();
@@ -332,13 +332,13 @@ int main __P2 (int,argc, char **,argv)
*/
edit_bootstrap();
tty_bootstrap();
-
+
#ifdef MOTDFILE
printmotd();
#endif
-
+
printver();
-
+
if (argc == 1) {
tty_printf(
"\nPowwow comes with ABSOLUTELY NO WARRANTY; for details type \"#help warranty\".\n\
@@ -346,7 +346,7 @@ This is free software, and you are welcome to redistribute it\n\
under certain conditions; type \"#help copyright\" for details.\n"
);
}
-
+
if (argc == 1 || argc == 3) {
tty_add_initial_binds();
tty_add_walk_binds();
@@ -358,7 +358,7 @@ under certain conditions; type \"#help copyright\" for details.\n"
* (they overwrite the ones in definition file)
*/
set_deffile(argv[1]);
-
+
if (access(deffile,R_OK) == -1 || access(deffile,W_OK) == -1) {
char portnum[INTLEN];
tty_printf("Creating %s\nHost name :", deffile);
@@ -381,37 +381,37 @@ under certain conditions; type \"#help copyright\" for details.\n"
exit(0);
else
read_file = 1;
- }
+ }
if (argc == 3 || argc == 4) {
/* assume last two args are hostname and port number */
my_strncpy(hostname, argv[argc - 2], BUFSIZE-1);
portnumber = atoi(argv[argc - 1]);
}
-
+
signal_start();
tty_start();
-
+
tty_puts(tty_clreoscr);
tty_putc('\n');
- tty_gotoxy(col0 = 0, lines - 2);
+ tty_gotoxy(col0 = 0, lines - 2);
tty_puts("Type #help for help.\n");
line0 = lines - 1;
-
+
FD_ZERO(&fdset);
FD_SET(tty_read_fd, &fdset);
-
+
if (*hostname)
tcp_open("main", (*initstr ? initstr : NULL), hostname, portnumber);
-
+
if (read_file && !*hostname && *initstr) {
parse_instruction(initstr, 0, 0, 1);
history_done = 0;
}
-
+
confirm = 0;
-
+
mainloop();
-
+
/* NOTREACHED */
return 0;
}
@@ -419,9 +419,9 @@ under certain conditions; type \"#help copyright\" for details.\n"
/*
* show current version
*/
-void printver __P0 (void)
+void printver(void)
{
- tty_printf("Powwow version %s\nOptions: %s%s\n", POWWOW_VERSION,
+ tty_printf("Powwow version %s\nOptions: %s%s\n", POWWOW_VERSION,
#ifdef USE_VT100
"vt100-only,"
#else
@@ -447,7 +447,7 @@ void printver __P0 (void)
#if __STDC__
" compiled " __TIME__ " " __DATE__
#else
- " uknown compile date"
+ " uknown compile date"
#endif
);
}
@@ -456,7 +456,7 @@ void printver __P0 (void)
/*
* print the message of the day if present
*/
-static void printmotd __P0 (void)
+static void printmotd(void)
{
char line[BUFSIZE];
FILE *f = fopen(MOTDFILE, "r");
@@ -468,7 +468,7 @@ static void printmotd __P0 (void)
}
#endif
-static void redraw_everything __P0 (void)
+static void redraw_everything(void)
{
if (prompt_status == 1 && line_status == 0)
line_status = 1;
@@ -483,11 +483,11 @@ static void redraw_everything __P0 (void)
}
/* how much can we sleep in select() ? */
-static void compute_sleeptime __P1 (vtime **,timeout)
+static void compute_sleeptime(vtime **timeout)
{
static vtime tbuf;
int sleeptime = 0;
-
+
if (delays) {
update_now();
sleeptime = diff_vtime(&delays->when, &now);
@@ -497,7 +497,7 @@ static void compute_sleeptime __P1 (vtime **,timeout)
}
if (flashback && (!sleeptime || sleeptime > FLASHDELAY))
sleeptime = FLASHDELAY;
-
+
if (sleeptime) {
tbuf.tv_sec = sleeptime / mSEC_PER_SEC;
tbuf.tv_usec = (sleeptime % mSEC_PER_SEC) * uSEC_PER_mSEC;
@@ -509,46 +509,46 @@ static void compute_sleeptime __P1 (vtime **,timeout)
/*
* main loop.
*/
-static void mainloop __P0 (void)
+static void mainloop(void)
{
fd_set readfds;
int i, err;
vtime *timeout;
-
+
for (;;) {
tcp_fd = tcp_main_fd;
exec_delays();
-
+
do {
if (sig_pending)
sig_bottomhalf(); /* this might set errno... */
-
+
tcp_flush();
-
+
if (!(pos <= edlen)) {
PRINTF("\n#*ARGH* assertion failed (pos <= edlen): mail bpk@hoopajoo.net\n");
pos = edlen;
}
-
+
redraw_everything();
tty_flush();
-
+
compute_sleeptime(&timeout);
-
+
error = now_updated = 0;
-
+
readfds = fdset;
err = select(tcp_max_fd+1, &readfds, NULL, NULL, timeout);
-
+
prompt_reset_iac();
-
+
} while (err < 0 && errno == EINTR);
-
+
if (err < 0 && errno != EINTR)
syserr("select");
-
+
if (flashback) putbackcursor();
-
+
/* process subsidiary and spawned connections first */
if (tcp_count > 1 || tcp_attachcount) {
for (i=0; err && i<conn_max_index; i++) {
@@ -571,14 +571,14 @@ static void mainloop __P0 (void)
confirm = 0;
get_user_input();
}
-
+
}
}
/*
* set the new prompt / input line status
*/
-void status __P1 (int,s)
+void status(int s)
{
if (s < 0) {
/* waiting prompt from the MUD */
@@ -596,19 +596,19 @@ void status __P1 (int,s)
* execute the delayed labels that have expired
* and place them in the disabled delays list
*/
-static void exec_delays __P0 (void)
+static void exec_delays(void)
{
delaynode *dying;
ptr *pbuf, buf = (ptr)0;
-
+
if (!delays)
return;
-
+
update_now();
-
+
if (cmp_vtime(&delays->when, &now) > 0)
return;
-
+
/* remember delayed command may modify the prompt and/or input line! */
if (prompt_status == 0) {
clear_input_line(opt_compact || !opt_info);
@@ -618,29 +618,29 @@ static void exec_delays __P0 (void)
status(1);
}
}
-
+
TAKE_PTR(pbuf, buf);
-
+
while (delays && cmp_vtime(&delays->when, &now) <= 0) {
dying = delays; /* remove delayed command from active list */
delays = dying->next; /* and put it in the dead one */
-
+
add_node((defnode *)dying, (defnode **)&dead_delays, rev_time_sort);
-
+
/* must be moved before executing delay->command
* and command must be copied in a buffer
* (can't you imagine why? The command may edit itself...)
*/
-
+
if (opt_info)
tty_printf("#now [%s]\n", dying->command);
-
+
if (*dying->command) {
-
+
error = 0;
-
+
*pbuf = ptrmcpy(*pbuf, dying->command, strlen(dying->command));
- if (MEM_ERROR)
+ if (MEM_ERROR)
errmsg("malloc (#in/#at)");
else {
parse_instruction(ptrdata(*pbuf), 0, 0, 1);
@@ -656,28 +656,28 @@ static void exec_delays __P0 (void)
static char *iac_v[IAC_N];
static int iac_f, iac_l;
-static void prompt_reset_iac __P0 (void)
+static void prompt_reset_iac(void)
{
iac_f = iac_l = 0;
}
-void prompt_set_iac __P1 (char *,p)
+void prompt_set_iac(char *p)
{
if (iac_f == iac_l)
iac_f = iac_l = 0;
-
+
if (iac_l < IAC_N)
iac_v[iac_l++] = p;
}
-static char *prompt_get_iac __P0 (void)
+static char *prompt_get_iac(void)
{
return iac_l > iac_f ? iac_v[iac_f] : NULL;
}
/* compute the effective prompt string; may end in \b* or \r */
-static void effective_prompt __P0 (void)
+static void effective_prompt(void)
{
char *const pstr = promptstr;
char *dst = pstr;
@@ -723,11 +723,11 @@ static void effective_prompt __P0 (void)
ptrsetlen(prompt->str, maxpos);
}
-static int grab_prompt __P3 (char *,linestart, int,len, int,islast)
+static int grab_prompt(char *linestart, int len, int islast)
{
char *p;
int is_iac_prompt = surely_isprompt = 0;
-
+
/* recognize IAC GA as end-of-prompt marker */
if ((CONN_LIST(tcp_fd).flags & IDPROMPT)) {
if ((p = prompt_get_iac()) && p > linestart && p <= linestart+len)
@@ -735,7 +735,7 @@ static int grab_prompt __P3 (char *,linestart, int,len, int,islast)
else if (!islast)
return 0;
}
-
+
/*
* We may get a prompt in the middle of a bunch of lines, so
* match #prompts. They usually have no #print, so we print manually
@@ -760,7 +760,7 @@ static int grab_prompt __P3 (char *,linestart, int,len, int,islast)
if (MEM_ERROR) { promptzero(); errmsg("malloc(prompt)"); return 0; }
prompt_status = 1;
}
-
+
/*
* following data may be the reply to a previously sent command,
* so we may have to reprint that command.
@@ -778,7 +778,7 @@ static int grab_prompt __P3 (char *,linestart, int,len, int,islast)
prompt_status = 1; /* good, we got what to redraw */
} else
len = 0;
-
+
return len;
}
@@ -786,24 +786,24 @@ static int grab_prompt __P3 (char *,linestart, int,len, int,islast)
/*
* process remote input one line at time. stop at "\n".
*/
-static void process_singleline __P2 (char **,pbuf, int *,psize)
+static void process_singleline(char **pbuf, int *psize)
{
int size, len = 0;
char *wasn = 0, *buf, *linestart = *pbuf, *lineend, *end = *pbuf + *psize;
-
+
if ((lineend = memchr(linestart, '\n', *psize))) {
/* ok, there is a newline */
-
+
*(wasn = lineend) = '\0';
buf = lineend + 1; /* start of next line */
}
-
+
if (!lineend)
/* line continues till end of buffer, no trailing \n */
buf = lineend = end;
-
+
size = buf - linestart;
-
+
#ifdef DEBUGCODE_2
/* debug code to see in detail what codes come from the server */
{
@@ -819,13 +819,13 @@ static void process_singleline __P2 (char **,pbuf, int *,psize)
tty_puts("}\n");
}
#endif
-
+
/*
* Try to guess where is the prompt... really not much more than
* a guess. Again, do it only on main connection: we do not want
* output from other connections to mess with the prompt
* of main connection :)
- *
+ *
* Since we now have #prompt, behave more restrictively:
* if no #prompts match or a #prompt matches but does not set #isprompt
* (i.e. recognize it for not being a prompt),
@@ -842,14 +842,14 @@ static void process_singleline __P2 (char **,pbuf, int *,psize)
draw_prompt(); tty_putc('\n'); col0 = 0;
}
surely_isprompt = 0;
- promptzero();
+ promptzero();
if (lineend > linestart && (len = grab_prompt(linestart, lineend-linestart, 1)))
size = len;
} else {
if (tcp_fd == tcp_main_fd) {
surely_isprompt = 0;
promptzero();
-
+
if (linestart[0]) {
/* set $last_line */
last_line->str = ptrmcpy(last_line->str, linestart, strlen(linestart));
@@ -864,11 +864,11 @@ static void process_singleline __P2 (char **,pbuf, int *,psize)
line0++;
if (tcp_fd != tcp_main_fd) /* sub connection */
tty_printf("##%s> ", CONN_LIST(tcp_fd).id);
-
+
smart_print(linestart, 1);
}
}
-
+
/*
* search_prompt and search_action above
* might set error: clear it to avoid troubles.
@@ -879,20 +879,20 @@ static void process_singleline __P2 (char **,pbuf, int *,psize)
*psize -= size;
}
-/*
+/*
* Code to merge lines from host that were splitted
* into different packets: it is a horrible kludge (sigh)
* and can be used only on one connection at time.
* We currently do it on main connection.
- *
+ *
* Note that this code also works for _prompts_ splitted into
* different packets, as long as no #prompts execute #isprompt
* on an incomplete prompt (as stated in the docs).
*/
-static int process_first_fragment __P2 (char *,buf, int,got)
+static int process_first_fragment(char *buf, int got)
{
int processed = 0;
-
+
/*
* Don't merge if the first part of the line was intercepted
* by a #prompt action which executed #isprompt
@@ -900,13 +900,13 @@ static int process_first_fragment __P2 (char *,buf, int,got)
*/
if (*buf == '\n') {
char deleteprompt = 0, matched = 0;
-
+
if (opt_compact) {
/* in compact mode, skip the first \n */
deleteprompt = 1;
processed++;
}
-
+
/*
* the prompt was actually a complete line.
* no need to put it on the top of received data.
@@ -916,7 +916,7 @@ static int process_first_fragment __P2 (char *,buf, int,got)
if (!surely_isprompt) {
last_line->str = ptrcpy(last_line->str, prompt->str);
if (MEM_ERROR) { print_error(error); return 0; }
-
+
/*
* Kludge for kludge: don't delete the old prompt immediately.
* Instead, match actions on it first.
@@ -924,7 +924,7 @@ static int process_first_fragment __P2 (char *,buf, int,got)
* (done by the "1" in search_action() )
* If it doesn't match, delete it only if opt_compact != 0
*/
-
+
matched = search_action(promptstr, 1);
}
if (!matched)
@@ -943,13 +943,13 @@ static int process_first_fragment __P2 (char *,buf, int,got)
lineend++;
else
lineend = buf + got;
-
+
if (surely_isprompt) {
/*
* either #isprompt _was_ executed,
* or we got a MUME spinning bar.
* in both cases, don't try to merge.
- *
+ *
* print a newline (to keep the old prompt on screen)
* only if !opt_compact and we didn't get a MUME spinning bar.
*/
@@ -961,12 +961,12 @@ static int process_first_fragment __P2 (char *,buf, int,got)
ptr *pp, p = (ptr)0;
char *dummy;
int dummyint;
-
+
/* ok, merge this junk with the prompt */
TAKE_PTR(pp, p);
*pp = ptrcpy(*pp, prompt->str);
*pp = ptrmcat(*pp, buf, lineend - buf);
-
+
if (MEM_ERROR) { print_error(error); return 0; }
if (!*pp)
return 0;
@@ -975,7 +975,7 @@ static int process_first_fragment __P2 (char *,buf, int,got)
/* this also sets last_line or prompt->str : */
clear_input_line(1);
process_singleline(&dummy, &dummyint);
-
+
processed = lineend - buf;
}
}
@@ -987,20 +987,20 @@ static int process_first_fragment __P2 (char *,buf, int,got)
* detect special sequences, trigger actions, locate prompt,
* word-wrap, print to tty
*/
-void process_remote_input __P2 (char *,buf, int,size)
+void process_remote_input(char *buf, int size)
{
-
+
if (promptlen && tcp_fd == tcp_main_fd)
promptzero(); /* discard the prompt, we look for another one */
-
+
status(1);
-
+
do {
process_singleline(&buf, &size);
} while (size > 0);
}
-static void common_clear __P1 (int,newline)
+static void common_clear(int newline)
{
clear_input_line(opt_compact);
if (newline) {
@@ -1011,7 +1011,7 @@ static void common_clear __P1 (int,newline)
/*
* get data from the socket and process/display it.
*/
-static void get_remote_input __P0 (void)
+static void get_remote_input(void)
{
char buffer[BUFSIZE + 2]; /* allow for a terminating \0 later */
char *buf = buffer, *newline;
@@ -1030,11 +1030,11 @@ static void get_remote_input __P0 (void)
CONN_LIST(tcp_fd).fragment = 0;
} else
i = 0;
-
+
got = tcp_read(tcp_fd, buf, BUFSIZE - i);
if (!got)
return;
-
+
buf[got]='\0'; /* Safe, there is space. Do it now not to forget it later */
received += got;
@@ -1052,13 +1052,13 @@ static void get_remote_input __P0 (void)
tty_puts("}\n");
}
#endif
-
+
if (!(CONN_LIST(tcp_fd).flags & ACTIVE))
return; /* process only active connections */
got += (buf - buffer);
buf = buffer;
-
+
if (CONN_LIST(tcp_fd).flags & SPAWN) {
/* this is data from a spawned child or an attached program.
* execute as if typed */
@@ -1068,7 +1068,7 @@ static void get_remote_input __P0 (void)
if ((newline = strchr(buf, '\n'))) {
/* instead of newline = strtok(buf, "\n") */
*newline = '\0';
-
+
if (opt_autoclear && line_status == 0) {
common_clear(!opt_compact);
}
@@ -1095,7 +1095,7 @@ static void get_remote_input __P0 (void)
*newline = '\0';
} while (buf && newline);
}
-
+
if (buf && *buf && !newline) {
/*
* save last fragment for later, when spawned command will
@@ -1113,23 +1113,23 @@ static void get_remote_input __P0 (void)
tcp_fd = otcp_fd;
return;
}
-
+
if (linemode & LM_CHAR) {
/* char-by-char mode: just display output, no fuss */
clear_input_line(0);
tty_puts(buf);
return;
}
-
+
/* line-at-a-time mode: process input in a number of ways */
-
+
if (tcp_fd == tcp_main_fd && promptlen) {
i = process_first_fragment(buf, got);
buf += i, got -= i;
} else {
common_clear(promptlen && !opt_compact);
}
-
+
if (got > 0)
process_remote_input(buf, got);
}
@@ -1140,13 +1140,13 @@ static void get_remote_input __P0 (void)
* GH: matches precompiled regexp, return actual params in param array
* return 1 if matched, 0 if not
*/
-static int match_regexp_action __P4 (void *,regexp, char *,line, int *,match_s, int *,match_e)
+static int match_regexp_action(void *regexp, char *line, int *match_s, int *match_e)
{
regmatch_t reg_match[NUMPARAM - 1];
-
+
if (!regexec((regex_t *)regexp, line, NUMPARAM - 1, reg_match, 0)) {
int n;
-
+
match_s[0] = 0;
match_e[0] = strlen(line);
for (n = 1; n < NUMPARAM; n++)
@@ -1167,15 +1167,15 @@ static int match_regexp_action __P4 (void *,regexp, char *,line, int *,match_s,
* match action containing &1..&9 and $1..$9 and return actual params start/end
* in match_s/match_e - return 1 if matched, 0 if not
*/
-static int match_weak_action __P4 (char *,pat, char *,line, int *,match_s, int *,match_e)
+static int match_weak_action(char *pat, char *line, int *match_s, int *match_e)
{
char mpat[BUFSIZE], *npat=0, *npat2=0, *src=line, *nsrc=0, c;
ptr *pbuf, buf = (ptr)0;
char *tmp, *realpat = pat;
int mbeg = 0, mword = 0, prm = -1, p;
-
+
TAKE_PTR(pbuf, buf);
-
+
if (jit_subst_vars(pbuf, pat))
pat = ptrdata(*pbuf);
if (REAL_ERROR) {
@@ -1184,18 +1184,18 @@ static int match_weak_action __P4 (char *,pat, char *,line, int *,match_s, int *
return 0;
}
unescape(pat);
-
+
for (p = 0; p < NUMPARAM; p++)
match_s[p] = match_e[p] = 0;
p = 0;
-
+
if (*pat == '^') {
pat++;
mbeg = 1; /* anchor match at line start */
}
if (*pat == '&' || *pat == '$')
mbeg = - mbeg - 1; /* pattern starts with '&' or '$' */
-
+
while (pat && *pat) {
if (((c=*pat) == '&' || c == '$')) {
/* &x matches a string */
@@ -1222,18 +1222,18 @@ static int match_weak_action __P4 (char *,pat, char *,line, int *,match_s, int *
return 0;
}
}
-
+
npat = first_valid(pat, '&');
npat2 = first_valid(pat, '$');
if (npat2 < npat) npat = npat2;
if (!*npat) npat = 0;
-
+
if (npat) {
my_strncpy(mpat, pat, npat-pat);
/* mpat[npat - pat] = 0; */
} else
strcpy(mpat, pat);
-
+
if (*mpat) {
nsrc = strstr(src, mpat);
if (!nsrc) {
@@ -1256,7 +1256,7 @@ static int match_weak_action __P4 (char *,pat, char *,line, int *,match_s, int *
match_s[prm] = src - line;
match_e[prm] = strlen(line);
}
-
+
/* post-processing of param */
if (prm != -1 && match_e[prm] && mword) {
if (mbeg == -1) {
@@ -1288,7 +1288,7 @@ static int match_weak_action __P4 (char *,pat, char *,line, int *,match_s, int *
pat = npat;
}
DROP_PTR(pbuf);
-
+
match_s[0] = 0; match_e[0] = strlen(line);
return 1;
}
@@ -1297,10 +1297,10 @@ static int match_weak_action __P4 (char *,pat, char *,line, int *,match_s, int *
* Search for #actions or #prompts to trigger on an input line.
* The line can't be trashed since we want to print it on the screen later.
* Return 1 if line matched to some #action, 0 otherwise
- *
+ *
* Optionally clear the input line before running the trigger command.
*/
-static int search_action_or_prompt __P3 (char *,line, char,clearline, char,onprompt)
+static int search_action_or_prompt(char *line, char clearline, char onprompt)
{
/*
* we need actionnode and promptnode to be the same "triggernode" type
@@ -1308,15 +1308,15 @@ static int search_action_or_prompt __P3 (char *,line, char,clearline, char,onpro
triggernode *p;
int ret = 0;
int match_s[NUMPARAM], match_e[NUMPARAM];
-
+
for (p = onprompt ? prompts : actions; p; p = p->next) {
#ifdef USE_REGEXP
- if (p->active &&
+ if (p->active &&
((p->type == ACTION_WEAK && match_weak_action(p->pattern, line, match_s, match_e))
|| (p->type == ACTION_REGEXP && match_regexp_action(p->regexp, line, match_s, match_e))
))
#else
- if (p->active &&
+ if (p->active &&
((p->type == ACTION_WEAK && match_weak_action(p->pattern, line, match_s, match_e))
))
#endif
@@ -1345,14 +1345,14 @@ static int search_action_or_prompt __P3 (char *,line, char,clearline, char,onpro
* read terminal input and send to parser.
* decode keys that send escape sequences
*/
-static void get_user_input __P0 (void)
+static void get_user_input(void)
{
int i, j, chunk = 1;
static char buf[BUFSIZE+1]; /* allow for terminating \0 */
char *c = buf;
static char typed[CAPLEN]; /* chars typed so far (with partial match) */
static int nchars = 0; /* number of them */
-
+
/* We have 4 possible line modes:
* line mode, local echo: line editing functions in effect
* line mode, no echo: sometimes used for passwords, no line editing
@@ -1361,7 +1361,7 @@ static void get_user_input __P0 (void)
*/
if (!(linemode & (LM_NOECHO | LM_CHAR))) /* line mode, local echo */
chunk = BUFSIZE;
-
+
while ((j = tty_read(c, chunk)) < 0 && errno == EINTR)
;
if (j == 0)
@@ -1369,9 +1369,9 @@ static void get_user_input __P0 (void)
if (j < 0 || (chunk == 1 && j != chunk))
syserr("read from tty");
-
+
c[chunk] = '\0';
-
+
if (linemode & LM_CHAR) {
/* char mode. chunk == 1 */
while ((i = write(tcp_fd, c, 1)) < 0 && errno == EINTR)
@@ -1393,7 +1393,7 @@ static void get_user_input __P0 (void)
else
#endif
tty_putc('\n');
-
+
tcp_write(tcp_fd, edbuf);
edlen = 0;
typed[nchars = 0] = 0;
@@ -1404,14 +1404,14 @@ static void get_user_input __P0 (void)
/* normal mode (line mode, echo). chunk == BUFSIZE */
int done = 0;
keynode *p;
-
+
for (; j > 0; c++, j--) {
-
+
/* search function key strings for match */
/* GH: support for \0 in sequence */
- done = 0;
+ done = 0;
typed[nchars++] = *c;
-
+
while (!done) {
done = 1;
/*
@@ -1421,14 +1421,14 @@ static void get_user_input __P0 (void)
if (nchars == 1 && *c >= ' ' && *c <= '~')
p = NULL;
else {
- for (p = keydefs; (p && (p->seqlen < nchars ||
+ for (p = keydefs; (p && (p->seqlen < nchars ||
memcmp(typed, p->sequence, nchars)));
p = p->next)
;
}
-
+
if (!p) {
- /*
+ /*
* GH: type the first character and keep processing
* the rest in the input buffer
*/
@@ -1458,12 +1458,12 @@ static void get_user_input __P0 (void)
* VAR[1].str ... VAR[9].str -
* the whole str is put in VAR[0].str
*/
-static char *split_words __P1 (char *,str)
+static char *split_words(char *str)
{
int i;
char *end;
ptr *prm;
-
+
*VAR[0].str = ptrmcpy(*VAR[0].str, str, strlen(str));
for (i = 1; i < NUMPARAM; i++) {
*VAR[i].num = 0;
@@ -1484,7 +1484,7 @@ static char *split_words __P1 (char *,str)
/*
* free the whole stack and reset it to empty
*/
-static void free_allparams __P0 (void)
+static void free_allparams(void)
{
int i,j;
@@ -1502,10 +1502,10 @@ static void free_allparams __P0 (void)
}
}
-void push_params __P0 (void)
+void push_params(void)
{
int i;
-
+
if (paramstk.curr < MAX_STACK - 1)
paramstk.curr++;
else {
@@ -1519,10 +1519,10 @@ void push_params __P0 (void)
}
}
-void pop_params __P0 (void)
+void pop_params(void)
{
int i;
-
+
if (paramstk.curr > 0)
paramstk.curr--;
else {
@@ -1537,7 +1537,7 @@ void pop_params __P0 (void)
}
}
-static void set_params __P3 (char *,line, int *,match_s, int *,match_e)
+static void set_params(char *line, int *match_s, int *match_e)
{
int i;
@@ -1555,28 +1555,28 @@ static void set_params __P3 (char *,line, int *,match_s, int *,match_e)
}
}
-char *get_next_instr __P1 (char *,p)
+char *get_next_instr(char *p)
{
int count, is_if;
char *sep, *q;
-
+
p = skipspace(p);
-
+
if (!*p)
return p;
-
+
count = is_if = !strncmp(p, "#if", 3);
-
+
do {
sep = first_regular(p, CMDSEP);
-
+
q = p;
if (*q) do {
if (*q == '#') q++;
-
+
q = first_regular(q, '#');
} while (*q && strncmp(q, "#if", 3));
-
+
if (sep<=q) {
if (*(p = sep))
p++;
@@ -1588,15 +1588,15 @@ char *get_next_instr __P1 (char *,p)
print_error(error=SYNTAX_ERROR);
return NULL;
}
- sep = skipspace(p);
- } while (*p && count-- &&
+ sep = skipspace(p);
+ } while (*p && count-- &&
(!is_if || (!strncmp(sep, "#else", 5) &&
(*(p = sep + 5)))));
-
+
return p;
}
-static void send_line __P2 (char *,line, char,silent)
+static void send_line(char *line, char silent)
{
if (!silent && opt_echo) { PRINTF("[%s]\n", line); }
tcp_write(tcp_fd, line);
@@ -1607,7 +1607,7 @@ static void send_line __P2 (char *,line, char,silent)
* Parse and exec the first instruction in 'line', and return pointer to the
* second instruction in 'line' (if any).
*/
-char *parse_instruction __P4 (char *,line, char,silent, char,subs, char,jit_subs)
+char *parse_instruction(char *line, char silent, char subs, char jit_subs)
{
aliasnode *np;
char *buf, *arg, *end, *ret;
@@ -1615,14 +1615,14 @@ char *parse_instruction __P4 (char *,line, char,silent, char,subs, char,jit_subs
int len, copied = 0, otcp_fd = -1;
ptr p1 = (ptr)0, p2 = (ptr)0;
ptr *pbuf, *pbusy, *tmp;
-
+
if (error) return NULL;
-
+
ret = get_next_instr(line);
-
+
if (!ret || ret==line) /* error or empty instruction, bail out */
return ret;
-
+
/*
* remove the optional ';' after an instruction,
* to have an usable string, ending with \0.
@@ -1638,17 +1638,17 @@ char *parse_instruction __P4 (char *,line, char,silent, char,subs, char,jit_subs
last_is_sep = 1;
}
}
-
+
/*
* using two buffers, p1 and p2, for four strings:
* result of subs_param, result of jit_subst_vars, result of
* unescape and first word of line.
- *
+ *
* So care is required to avoid clashes.
*/
TAKE_PTR(pbuf, p1);
TAKE_PTR(pbusy, p2);
-
+
if (subs && subst_param(pbuf, line)) {
line = *pbuf ? ptrdata(*pbuf) : "";
SWAP2(pbusy, pbuf, tmp);
@@ -1666,13 +1666,13 @@ char *parse_instruction __P4 (char *,line, char,silent, char,subs, char,jit_subs
}
if (subs || jit_subs)
unescape(line);
-
+
/* now line is in (pbusy) and (pbuf) is available */
-
+
/* restore integrity of original line: must still put it in history */
if (last_is_sep)
*ret++ = CMDSEP;
-
+
if (REAL_ERROR) {
print_error(error);
DROP_PTR(pbuf); DROP_PTR(pbusy);
@@ -1682,12 +1682,12 @@ char *parse_instruction __P4 (char *,line, char,silent, char,subs, char,jit_subs
if (opt_debug) {
PRINTF("#parsing: %s\n", line);
}
-
+
if (!*line)
send_line(line, silent);
else do {
arg = skipspace(line);
-
+
if (arg[0] == '#' && arg[1] == '#') { /* send to other connection */
*pbuf = ptrsetlen(*pbuf, len = strlen(arg));
if (REAL_ERROR) { print_error(error); break; }
@@ -1716,10 +1716,10 @@ char *parse_instruction __P4 (char *,line, char,silent, char,subs, char,jit_subs
}
/* now we can trash (pbuf) */
}
-
+
if (*arg == '{') { /* instruction contains a block */
end = first_regular(line = arg + 1, '}');
-
+
if (*end) {
*end = '\0';
parse_user_input(line, silent);
@@ -1729,33 +1729,33 @@ char *parse_instruction __P4 (char *,line, char,silent, char,subs, char,jit_subs
} else {
int oneword;
/* initial spaces are NOT skipped this time */
-
+
*pbuf = ptrsetlen(*pbuf, len = strlen(line));
if (REAL_ERROR) { print_error(error); break; }
-
+
buf = ptrdata(*pbuf);
arg = split_first_word(buf, len+1, line);
/* buf contains the first word, arg points to arguments */
-
+
/* now pbuf is used too */
if (!*arg) oneword = 1;
else oneword = 0;
-
+
if ((np = *lookup_alias(buf))&&np->active) {
push_params();
if (REAL_ERROR) break;
-
+
split_words(arg); /* split argument into words
and place them in $0 ... $9 */
parse_instruction(np->subst, 0, 1, 1);
-
+
if (error!=DYN_STACK_UND_ERROR && error!=DYN_STACK_OV_ERROR)
pop_params();
-
+
/* now check for internal commands */
/* placed here to allow also aliases starting with "#" */
} else if (*(end = skipspace(line)) == '#') {
-
+
if (*(end = skipspace(end + 1)) == '(') { /* execute #() */
end++;
(void)evaln(&end);
@@ -1765,14 +1765,14 @@ char *parse_instruction __P4 (char *,line, char,silent, char,subs, char,jit_subs
/* ok, buf contains skipspace(first word) */
} else if (!oneword || !map_walk(buf, silent, 0)) {
/* it is ok, map_walk accepts only one word */
-
+
if (!subs && !jit_subs)
unescape(line);
send_line(line, silent);
}
}
} while (0);
-
+
if (otcp_fd != -1)
tcp_fd = otcp_fd;
DROP_PTR(pbuf); DROP_PTR(pbusy);
@@ -1784,7 +1784,7 @@ char *parse_instruction __P4 (char *,line, char,silent, char,subs, char,jit_subs
* in cmd_line.
* silent = 1 if the line should not be echoed, 0 otherwise.
*/
-void parse_user_input __P2 (char *,line, char,silent)
+void parse_user_input(char *line, char silent)
{
do {
line = parse_instruction(line, silent, 0, 0);
@@ -1794,13 +1794,13 @@ void parse_user_input __P2 (char *,line, char,silent)
/*
* parse powwow's own commands
*/
-static void parse_commands __P2 (char *,command, char *,arg)
+static void parse_commands(char *command, char *arg)
{
int i, j;
cmdstruct *c;
/* We ALLOW special commands also on subsidiary connections ! */
-
+
/* assume output will be enough to make input line = last screen line */
/* line0 = lines - 1; */
if (isdigit(*command) && (i = atoi(command))) {
@@ -1818,7 +1818,7 @@ static void parse_commands __P2 (char *,command, char *,arg)
return;
}
- for( c = commands; c != NULL; c = c -> next )
+ for( c = commands; c != NULL; c = c -> next )
if (!strncmp(command, c -> name, j)) {
if (c -> funct) {
(*(c -> funct))(arg);
@@ -1831,20 +1831,20 @@ static void parse_commands __P2 (char *,command, char *,arg)
}
/*
- * substitute $0..$9 and @0..@9 in a string
+ * substitute $0..$9 and @0..@9 in a string
* (unless $ or @ is escaped with backslash)
- *
+ *
* return 0 if dst not filled. if returned 0 and not error,
* there was nothing to substitute.
*/
-static int subst_param __P2 (ptr *,buf, char *,src)
+static int subst_param(ptr *buf, char *src)
{
int done, i;
char *dst, *tmp, kind;
-
+
if (!strchr(src, '$') && !strchr(src, '@'))
return 0;
-
+
i = strlen(src);
if (!*buf || ptrlen(*buf) < i) {
*buf = ptrsetlen(*buf, i);
@@ -1852,19 +1852,19 @@ static int subst_param __P2 (ptr *,buf, char *,src)
return 0;
}
dst = ptrdata(*buf);
-
+
while (*src) {
while (*src && *src != '$' && *src != '@' && *src != ESC)
*dst++ = *src++;
-
+
if (*src == ESC) {
while (*src == ESC)
*dst++ = *src++;
-
+
if (*src)
*dst++ = *src++;
}
-
+
done = 0;
if (*src == '$' || *src == '@') {
kind = *src == '$' ? 1 : 0;
@@ -1873,14 +1873,14 @@ static int subst_param __P2 (ptr *,buf, char *,src)
i = atoi(tmp);
while (isdigit(*tmp))
tmp++;
-
+
if (i < NUMPARAM) {
int max = 0, n;
char *data = NULL, buf2[LONGLEN];
-
+
done = 1;
src = tmp;
-
+
/* now the actual substitution */
if (kind) {
if (*VAR[i].str && (data = ptrdata(*VAR[i].str)))
@@ -1910,22 +1910,22 @@ static int subst_param __P2 (ptr *,buf, char *,src)
/*
* just-in-time substitution:
- * substitute ${name}, @{name} and #{expression} in a string
+ * substitute ${name}, @{name} and #{expression} in a string
* (unless "${", "@{" or "#{" are escaped with backslash)
- *
+ *
* return 0 if dst not filled. if returned 0 and not error,
* there was nothing to substitute.
*/
-static int jit_subst_vars __P2 (ptr *,buf, char *,src)
+static int jit_subst_vars(ptr *buf, char *src)
{
int i, done, kind;
char *tmp, *name, *dst, c;
varnode *named_var;
-
+
if (!strstr(src, "${") && !strstr(src, "@{") && !strstr(src, "#{"))
return 0;
-
+
i = strlen(src);
if (!*buf || ptrlen(*buf) < i) {
*buf = ptrsetlen(*buf, i);
@@ -1933,19 +1933,19 @@ static int jit_subst_vars __P2 (ptr *,buf, char *,src)
return 0;
}
dst = ptrdata(*buf);
-
+
while (*src) {
while (*src && *src != '$' && *src != '@' && *src != '#' && *src != ESC)
*dst++ = *src++;
-
+
if (*src == ESC) {
while (*src == ESC)
*dst++ = *src++;
-
+
if (*src)
*dst++ = *src++;
}
-
+
done = 0;
if (*src == '$' || *src == '@') {
i = 0;
@@ -1981,9 +1981,9 @@ static int jit_subst_vars __P2 (ptr *,buf, char *,src)
if (done) {
int max = 0, n;
char *data = NULL, buf2[LONGLEN];
-
+
src = tmp + 1; /* skip the '}' */
-
+
/* now the actual substitution */
if (kind == 1) {
if (*VAR[i].str && (data = ptrdata(*VAR[i].str)))
@@ -2004,13 +2004,13 @@ static int jit_subst_vars __P2 (ptr *,buf, char *,src)
} else if (*tmp == '}')
/* met an undefined variable, consider empty */
src = tmp + 1;
-
+
/* else syntax error, do nothing */
}
} else if (src[0] == '#' && src[1] == '{') {
int max, n;
ptr pbuf = (ptr)0;
-
+
src += 2;
(void)evalp(&pbuf, &src);
if (REAL_ERROR) {
@@ -2030,7 +2030,7 @@ static int jit_subst_vars __P2 (ptr *,buf, char *,src)
dst += max;
}
ptrdel(pbuf);
-
+
if (*src)
src = skipspace(src);
if (*src != '}') {
@@ -2042,7 +2042,7 @@ static int jit_subst_vars __P2 (ptr *,buf, char *,src)
if (*src)
src++;
}
-
+
if (!done && (*src == '$' || *src == '@' || *src == '#'))
/* not matched, just copy */
*dst++ = *src++;
@@ -2058,7 +2058,7 @@ static int jit_subst_vars __P2 (ptr *,buf, char *,src)
* if file doesn't exist, it is created there.
* If a slash appears in the name, the powwow_dir isn't used.
*/
-void set_deffile __P1 (char *,arg)
+void set_deffile(char *arg)
{
if (!strchr(arg, '/') && *powwow_dir) {
strcpy(deffile, powwow_dir);
@@ -2073,7 +2073,7 @@ void set_deffile __P1 (char *,arg)
/*
* GH: return true if var is one of the permanent variables
*/
-int is_permanent_variable __P1 (varnode *,v)
+int is_permanent_variable(varnode *v)
{
return (v == prompt || v == last_line);
}