From 304a722c426f47a461dc88c4493f800c0690b29b Mon Sep 17 00:00:00 2001 From: "powwow@askgustav.com" Date: Tue, 19 Mar 2019 00:05:26 +0100 Subject: remove some non-ANSI C support diff --git a/ChangeLog.old b/ChangeLog.old index 9b4a97a..b459ac1 100644 --- a/ChangeLog.old +++ b/ChangeLog.old @@ -1,5 +1,6 @@ 2019-03-18 powwow@askgustav.com * handle more control characters in prompts + * drop support for non-ANSI C Changes from 1.2.4 to 1.2.5 (Massimiliano Ghilardi, ...) 21 Jan 2002 * Added append-mode to #capture: use #capture >file-name diff --git a/Hacking b/Hacking index 5cf46d1..2063884 100644 --- a/Hacking +++ b/Hacking @@ -7,25 +7,6 @@ improve powwow, fix bugs or just have fun: maintain his own code, who can?). If you write any new functions, ok, use your own style as long as it's clear and consistent. -* For portability, powwow is written using a few #defines that can - generate either K&R and ANSI function prototypes depending on the compiler, - so that it (should) compile fine in both cases. - If people convince me that non-ANSI compilers are rare enough these days, - we could switch to ANSI-only prototypes. Even then, please, do NOT - use any gcc-specific features (I've seen the char constant '\e' in some - places) even if gcc is very common. Our goal should be to let the - maximum number of people use powwow. (Most non-ANSI compilers grok - void and unsigned, so these are safe to use.) - -* For the same reason, do NOT use C++ style comments // - -* To sum it up, assume that the user has: - - a non-ANSI C compiler (use the __P, __P0, __P1, ... defines!) - - an exotic non-VT100 terminal (use TERMCAP!), possibly on a slow line - - a slow workstation, or a larger computer shared by 100 users and - aggressive sysadmins who think that mudding doesn't justify 10% or - even 5% CPU load. - * Document your changes! A brief report of changes in the Changelog file is absolutely necessary. So is updating the doc files (powwow.doc, powwow_help and README) Also, sending an e-mail to the code author/mantainer documenting diff --git a/beam.c b/beam.c index d0c29da..4da6f2e 100644 --- a/beam.c +++ b/beam.c @@ -37,10 +37,10 @@ editsess *edit_sess; /* head of session list */ -char edit_start[BUFSIZE]; /* messages to send to host when starting */ -char edit_end[BUFSIZE]; /* or leaving editing sessions */ +char edit_start[BUFSIZE]; /* messages to send to host when starting */ +char edit_end[BUFSIZE]; /* or leaving editing sessions */ -static void write_message __P1 (char *,s) +static void write_message(char *s) { clear_input_line(opt_compact); if (!opt_compact) { @@ -54,7 +54,7 @@ static void write_message __P1 (char *,s) * Process editing protocol message from buf with len remaining chars. * Return number of characters used in the message. */ -int process_message __P2 (char *,buf, int,len) +int process_message(char *buf, int len) { int msglen, i, l, used; char *text, *from, *to; @@ -62,17 +62,17 @@ int process_message __P2 (char *,buf, int,len) int got_iac; status(1); - + msglen = atoi(buf + 1); for (i = 1; i < len && isdigit(buf[i]); i++) ; - + if (i < len && buf[i] == '\r') i++; if (i >= len || buf[i] != '\n') { write_message ("#warning: MPI protocol error\n"); return 0; } - + l = len - ++i; text = (char *)malloc(msglen); @@ -125,7 +125,7 @@ int process_message __P2 (char *,buf, int,len) tty_flush(); } tty_printf("\rread all %d chars.%s\n", msglen, tty_clreoln); - + switch(*buf) { case 'E': message_edit(text, msglen, 0, 0); @@ -147,18 +147,18 @@ int process_message __P2 (char *,buf, int,len) * abort an editing session when * the MUD socket it comes from gets closed */ -void abort_edit_fd __P1 (int,fd) +void abort_edit_fd(int fd) { editsess **sp, *p; if (fd < 0) return; - + for (sp = &edit_sess; *sp; sp = &(*sp)->next) { p = *sp; if (p->fd != fd) continue; - + if (kill(p->pid, SIGKILL) < 0) { /* Editicide */ errmsg("kill editor child"); continue; @@ -173,11 +173,11 @@ void abort_edit_fd __P1 (int,fd) * cancel an editing session; does not free anything * (the child death signal handler will remove the session from the list) */ -void cancel_edit __P1 (editsess *,sp) +void cancel_edit(editsess *sp) { char buf[BUFSIZE]; char keystr[16]; - + if (kill(sp->pid, SIGKILL) < 0) { /* Editicide */ errmsg("kill editor child"); return; @@ -212,16 +212,16 @@ static ssize_t read_file(int fd, void *buf, size_t count) * send back edited text to server, or cancel the editing session if the * file was not changed. */ -static void finish_edit __P1 (editsess *,sp) +static void finish_edit(editsess *sp) { char *realtext = NULL, *text; int fd, txtlen, hdrlen; struct stat sbuf; char keystr[16], buf[256], hdr[65]; - + if (sp->fd == -1) goto cleanup_file; - + fd = open(sp->file, O_RDONLY); if (fd == -1) { errmsg("open edit file"); @@ -231,19 +231,19 @@ static void finish_edit __P1 (editsess *,sp) errmsg("fstat edit file"); goto cleanup_fd; } - + txtlen = sbuf.st_size; - + if (!sp->cancel && (sbuf.st_mtime > sp->ctime || txtlen != sp->oldsize)) { /* file was changed by editor: send back result to server */ - + realtext = (char *)malloc(txtlen + 65); /* +1 is for possible LF, +64 for header */ if (!realtext) { errmsg("malloc"); goto cleanup_fd; } - + text = realtext + 64; txtlen = read_file(fd, text, txtlen); if (txtlen < 0) @@ -255,30 +255,30 @@ static void finish_edit __P1 (editsess *,sp) text[txtlen] = '\n'; txtlen++; } - + sprintf(keystr, "E%u\n", sp->key); - + sprintf(hdr, "%sE%d\n%s", MPI, (int)(txtlen + strlen(keystr)), keystr); - + text -= (hdrlen = strlen(hdr)); memcpy(text, hdr, hdrlen); - + /* text[hdrlen + txtlen] = '\0'; */ tcp_write_escape_iac(sp->fd, text, hdrlen + txtlen); - + sprintf(buf, "#completed session %s (%u)\n", sp->descr, sp->key); write_message(buf); } else { /* file wasn't changed, cancel editing session */ sprintf(keystr, "C%u\n", sp->key); sprintf(hdr, "%sE%d\n%s", MPI, (int) strlen(keystr), keystr); - + tcp_raw_write(sp->fd, hdr, strlen(hdr)); - + sprintf(buf, "#cancelled session %s (%u)\n", sp->descr, sp->key); write_message(buf); } - + cleanup_text: if (realtext) free(realtext); cleanup_fd: close(fd); cleanup_file: if (unlink(sp->file) < 0) @@ -289,7 +289,7 @@ cleanup_file: if (unlink(sp->file) < 0) * start an editing session: process the EDIT/VIEW message * if view == 1, text will be viewed, else edited */ -void message_edit __P4 (char *,text, int,msglen, char,view, char,builtin) +void message_edit(char *text, int msglen, char view, char builtin) { char tmpname[BUFSIZE], command_str[BUFSIZE], buf[BUFSIZE]; char *errdesc = "#warning: protocol error (message_edit, no %s)\n"; @@ -299,11 +299,11 @@ void message_edit __P4 (char *,text, int,msglen, char,view, char,builtin) char *editor, *descr; char *args[4]; int waitforeditor; - + status(1); args[0] = "/bin/sh"; args[1] = "-c"; - args[2] = command_str; args[3] = 0; + args[2] = command_str; args[3] = 0; if (view) { key = (unsigned int)-1; @@ -331,7 +331,7 @@ void message_edit __P4 (char *,text, int,msglen, char,view, char,builtin) return; } text[i++] = '\0'; - + sprintf(tmpname, "/tmp/powwow.%u.%d%d", key, getpid(), abs(rand()) >> 8); if ((tmpfd = open(tmpname, O_WRONLY | O_CREAT, 0600)) < 0) { errmsg("create temp edit file"); @@ -345,7 +345,7 @@ void message_edit __P4 (char *,text, int,msglen, char,view, char,builtin) return; } close(tmpfd); - + s = (editsess*)malloc(sizeof(editsess)); if (!s) { errmsg("malloc"); @@ -359,14 +359,14 @@ void message_edit __P4 (char *,text, int,msglen, char,view, char,builtin) s->descr = my_strdup(descr); s->file = my_strdup(tmpname); free(text); - - /* send a edit_start message (if wanted) */ + + /* send a edit_start message (if wanted) */ if ((!edit_sess) && (*edit_start)) { error = 0; parse_instruction(edit_start, 0, 0, 1); history_done = 0; } - + if (view) { if (!(editor = getenv("POWWOWPAGER")) && !(editor = getenv("PAGER"))) editor = "more"; @@ -374,13 +374,13 @@ void message_edit __P4 (char *,text, int,msglen, char,view, char,builtin) if (!(editor = getenv("POWWOWEDITOR")) && !(editor = getenv("EDITOR"))) editor = "emacs"; } - + if (editor[0] == '&') { waitforeditor = 0; editor++; } else waitforeditor = 1; - + if (waitforeditor) { tty_quit(); /* ignore SIGINT since interrupting the child would interrupt us too, @@ -388,7 +388,7 @@ void message_edit __P4 (char *,text, int,msglen, char,view, char,builtin) sig_permanent(SIGINT, SIG_IGN); sig_permanent(SIGCHLD, SIG_DFL); } - + switch(childpid = fork()) { /* let's get schizophrenic */ case 0: sprintf(command_str, "%s %s", editor, s->file); @@ -412,17 +412,17 @@ void message_edit __P4 (char *,text, int,msglen, char,view, char,builtin) signal_start(); /* reset SIGINT and SIGCHLD handlers */ tty_start(); - + if (s->fd != -1) { tty_gotoxy(0, lines - 1); tty_putc('\n'); } - + if (i == -1) errmsg("waitpid"); else finish_edit(s); - + free(s->descr); free(s->file); if (i != -1 && !edit_sess && *edit_end) { @@ -430,9 +430,9 @@ void message_edit __P4 (char *,text, int,msglen, char,view, char,builtin) parse_instruction(edit_end, 0, 0, 1); history_done = 0; } - + free(s); - + } else { s->next = edit_sess; edit_sess = s; @@ -443,11 +443,11 @@ void message_edit __P4 (char *,text, int,msglen, char,view, char,builtin) * Our child has snuffed it. check if it was an editor, and update the * session list if that is the case. */ -void sig_chld_bottomhalf __P0 (void) +void sig_chld_bottomhalf(void) { int fd, pid, ret; editsess **sp, *p; - + /* GH: while() instead of just one check */ while ((pid = waitpid(-1, &ret, WNOHANG)) > 0) { @@ -465,7 +465,7 @@ void sig_chld_bottomhalf __P0 (void) /* GH: only send message if found matching session */ - /* send the edit_end message if this is the last editor... */ + /* send the edit_end message if this is the last editor... */ if ((!edit_sess) && (*edit_end)) { int otcp_fd = tcp_fd; /* backup current socket fd */ tcp_fd = fd; diff --git a/beam.h b/beam.h index cd1ce09..84189d9 100644 --- a/beam.h +++ b/beam.h @@ -3,11 +3,11 @@ #ifndef _BEAM_H_ #define _BEAM_H_ -int process_message __P ((char *buf, int len)); -void cancel_edit __P ((editsess *sp)); -void abort_edit_fd __P ((int fd)); -void message_edit __P ((char *text, int msglen, char view, char builtin)); -void sig_chld_bottomhalf __P ((void)); +int process_message(char *buf, int len); +void cancel_edit(editsess *sp); +void abort_edit_fd(int fd); +void message_edit(char *text, int msglen, char view, char builtin); +void sig_chld_bottomhalf(void); extern char edit_start[]; extern char edit_end[]; diff --git a/catrw.c b/catrw.c index e19e4e5..40d06e3 100644 --- a/catrw.c +++ b/catrw.c @@ -1,6 +1,6 @@ /* * catrw.c -- open a file with O_RDWR and print it. - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or diff --git a/cmd.c b/cmd.c index 551a069..f11dd53 100644 --- a/cmd.c +++ b/cmd.c @@ -2,7 +2,7 @@ * cmd.c -- functions for powwow's built-in #commands * * (created: Finn Arne Gangstad (Ilie), Dec 25th, 1993) - * + * * Copyright (C) 1998 by Massimiliano Ghilardi * * This program is free software; you can redistribute it and/or modify @@ -12,6 +12,7 @@ * */ +#include #include #include #include @@ -45,30 +46,30 @@ #include "log.h" /* local function declarations */ -#define _ __P ((char *arg)) - -static void cmd_help _, cmd_shell _, cmd_action _, cmd_add _, - cmd_addstatic _, cmd_alias _, cmd_at _, cmd_beep _, cmd_bind _, - cmd_cancel _, cmd_capture _, cmd_clear _, cmd_connect _, cmd_cpu _, - cmd_do _, cmd_delim _, cmd_edit _, cmd_emulate _, cmd_exe _, - cmd_file _, cmd_for _, cmd_hilite _, cmd_history _, cmd_host _, - cmd_identify _, cmd_if _, cmd_in _, cmd_init _, cmd_isprompt _, - cmd_key _, cmd_keyedit _, - cmd_load _, cmd_map _, cmd_mark _, cmd_movie _, - cmd_net _, cmd_nice _, cmd_option _, - cmd_prefix _, cmd_print _, cmd_prompt _, cmd_put _, - cmd_qui _, cmd_quit _, cmd_quote _, - cmd_rawsend _, cmd_rawprint _, cmd_rebind _, cmd_rebindall _, cmd_rebindALL _, - cmd_record _, cmd_request _, cmd_reset _, cmd_retrace _, - cmd_save _, cmd_send _, cmd_setvar _, cmd_snoop _, cmd_spawn _, cmd_stop _, - cmd_time _, cmd_var _, cmd_ver _, cmd_while _, cmd_write _, - cmd_eval _, cmd_zap _, cmd_module _, cmd_group _, cmd_speedwalk _, cmd_groupdelim _; +#define F(name) cmd_ ## name(char *arg) + +static void F(help), F(shell), F(action), F(add), + F(addstatic), F(alias), F(at), F(beep), F(bind), + F(cancel), F(capture), F(clear), F(connect), F(cpu), + F(do), F(delim), F(edit), F(emulate), F(exe), + F(file), F(for), F(hilite), F(history), F(host), + F(identify), F(if), F(in), F(init), F(isprompt), + F(key), F(keyedit), + F(load), F(map), F(mark), F(movie), + F(net), F(nice), F(option), + F(prefix), F(print), F(prompt), F(put), + F(qui), F(quit), F(quote), + F(rawsend), F(rawprint), F(rebind), F(rebindall), F(rebindALL), + F(record), F(request), F(reset), F(retrace), + F(save), F(send), F(setvar), F(snoop), F(spawn), F(stop), + F(time), F(var), F(ver), F(while), F(write), + F(eval), F(zap), F(module), F(group), F(speedwalk), F(groupdelim); #ifdef BUG_TELNET -static void cmd_color _; +static void F(color); #endif -#undef _ +#undef F /* This must be init'd now at runtime */ cmdstruct *commands = NULL; @@ -262,7 +263,7 @@ void cmd_add_command( cmdstruct *cmd ) { * but if a module defined the command in the global static * space, it would create an infinite loop because the -> next * ptr would point at itself - * + * * doing it up front because based on the sortname, we may never see * the dup item if we do it at sort time */ @@ -273,7 +274,7 @@ void cmd_add_command( cmdstruct *cmd ) { } } - + /* catch insertion to head of list */ if( commands == NULL ) { /* no commands yet */ @@ -318,7 +319,7 @@ void initialize_cmd(void) { } #ifdef HAVE_LIBDL -static void cmd_module __P1 (char *,arg) { +static void cmd_module(char *arg) { char libname[1024]; void *lib; void (*func)(); @@ -374,7 +375,7 @@ static void cmd_module __P1 (char *,arg) { } #endif -static void cmd_group __P1 (char *,arg) { +static void cmd_group(char *arg) { char *group; int active; aliasnode *p; @@ -417,7 +418,7 @@ static void cmd_group __P1 (char *,arg) { } } -static void cmd_groupdelim __P1 (char *,arg) { +static void cmd_groupdelim(char *arg) { if( *arg != 0 ) { free( group_delim ); group_delim = my_strdup( arg ); @@ -425,7 +426,7 @@ static void cmd_groupdelim __P1 (char *,arg) { } } -static void cmd_help __P1 (char *,arg) +static void cmd_help(char *arg) { int i, size; char *text, *tmp; @@ -433,14 +434,14 @@ static void cmd_help __P1 (char *,arg) char line[BUFSIZE]; int len; cmdstruct *c; - + arg = skipspace(arg); if (*arg == '#') arg++; if (!*arg) { size = 25; for( c = commands; c != NULL; c = c -> next ) size += strlen(c -> name) + strlen(c -> help) + 5; - + text = tmp = (char *)malloc(size); if (!text) { errmsg("malloc"); @@ -455,20 +456,20 @@ static void cmd_help __P1 (char *,arg) sprintf(tmp, "#%s %s\n", c -> name, c -> help); tmp += strlen(tmp); } - + message_edit(text, strlen(text), 1, 1); return; } - + if (!strncmp(arg, "copyright", strlen(arg))) { int fd, left, got = 0; struct stat stbuf; - + if (stat(copyfile, &stbuf) < 0) { errmsg("stat(copyright file)"); return; } - + if (!(text = (char *)malloc(left = stbuf.st_size))) { errmsg("malloc"); return; @@ -495,20 +496,20 @@ static void cmd_help __P1 (char *,arg) message_edit(text, strlen(text), 1, 1); return; } - + /* !copyright */ - + f = fopen(helpfile, "r"); if (!f) { PRINTF("#cannot open help file \"%s\": %s\n", helpfile, strerror(errno)); return; } - + while ((tmp = fgets(line, BUFSIZE, f)) && (line[0] != '@' || strncmp(line + 1, arg, strlen(arg)))) ; - + if (!tmp) { PRINTF("#no entry for \"%s\" in the help file.\n", arg); fclose(f); @@ -532,7 +533,7 @@ static void cmd_help __P1 (char *,arg) do { if ((len = strlen(line)) >= size - i) { /* Not enough space in current buffer */ - + if (!(tmp = (char *)malloc(size += BUFSIZE))) { errmsg("malloc"); free(text); @@ -547,13 +548,13 @@ static void cmd_help __P1 (char *,arg) memcpy(text + i, line, len); i += len; } while (fgets(line, BUFSIZE, f) && line[0] != '@'); - + fclose(f); text[i] = '\0'; /* safe, there is space */ message_edit(text, strlen(text), 1, 1); } -static void cmd_clear __P1 (char *,arg) +static void cmd_clear(char *arg) { if (line_status == 0) { clear_input_line(opt_compact); @@ -566,7 +567,7 @@ static void cmd_clear __P1 (char *,arg) } #ifndef NO_SHELL -static void cmd_shell __P1 (char *,arg) +static void cmd_shell(char *arg) { if (!*arg) { if (opt_info) { @@ -586,7 +587,7 @@ static void cmd_shell __P1 (char *,arg) } #endif -static void cmd_alias __P1 (char *,arg) +static void cmd_alias(char *arg) { arg = skipspace(arg); if (!*arg) @@ -595,7 +596,7 @@ static void cmd_alias __P1 (char *,arg) parse_alias(arg); } -static void cmd_action __P1 (char *,arg) +static void cmd_action(char *arg) { arg = skipspace(arg); if (!*arg) @@ -604,7 +605,7 @@ static void cmd_action __P1 (char *,arg) parse_action(arg, 0); } -static void cmd_prompt __P1 (char *,arg) +static void cmd_prompt(char *arg) { arg = skipspace(arg); if (!*arg) @@ -613,7 +614,7 @@ static void cmd_prompt __P1 (char *,arg) parse_action(arg, 1); } -static void cmd_beep __P1 (char *,arg) +static void cmd_beep(char *arg) { tty_putc('\007'); } @@ -621,7 +622,7 @@ static void cmd_beep __P1 (char *,arg) /* * create/list/edit/delete bindings */ -static void cmd_bind __P1 (char *,arg) +static void cmd_bind(char *arg) { arg = skipspace(arg); if (!*arg) @@ -632,7 +633,7 @@ static void cmd_bind __P1 (char *,arg) parse_bind(arg); } -static void cmd_delim __P1 (char *,arg) +static void cmd_delim(char *arg) { char buf[BUFSIZE]; int n; @@ -647,7 +648,7 @@ static void cmd_delim __P1 (char *,arg) n = 0; while (n < DELIM_MODES && strncmp(delim_name[n], buf, strlen(buf)) != 0) n++; - + if (n >= DELIM_MODES) { PRINTF("#delim [normal|program|{custom }\n"); return; @@ -665,11 +666,11 @@ static void cmd_delim __P1 (char *,arg) delim_mode = n; } -static void cmd_do __P1 (char *,arg) +static void cmd_do(char *arg) { int type; long result; - + arg = skipspace(arg); if (*arg != '(') { PRINTF("#do: "); @@ -677,16 +678,16 @@ static void cmd_do __P1 (char *,arg) return; } arg++; - + type = evall(&result, &arg); if (REAL_ERROR) return; - + if (type != TYPE_NUM) { PRINTF("#do: "); print_error(error=NO_NUM_VALUE_ERROR); return; } - + if (*arg == ')') { /* skip the ')' */ if (*++arg == ' ') arg++; @@ -696,7 +697,7 @@ static void cmd_do __P1 (char *,arg) print_error(error=MISSING_PAREN_ERROR); return; } - + if (result >= 0) while (!error && result--) (void)parse_instruction(arg, 1, 0, 1); @@ -705,10 +706,10 @@ static void cmd_do __P1 (char *,arg) } } -static void cmd_hilite __P1 (char *,arg) +static void cmd_hilite(char *arg) { int attr; - + arg = skipspace(arg); attr = parse_attributes(arg); if (attr == -1) { @@ -720,7 +721,7 @@ static void cmd_hilite __P1 (char *,arg) edattrbg = ATTR(attr) & ATTR_INVERSE ? 1 : BACKGROUND(attr) != NO_COLOR || ATTR(attr) & ATTR_BLINK; - + if (opt_info) { PRINTF("#input highlighting is now %so%s%s.\n", edattrbeg, (attr == NOATTRCODE) ? "ff" : "n", @@ -729,19 +730,19 @@ static void cmd_hilite __P1 (char *,arg) } } -static void cmd_history __P1 (char *,arg) +static void cmd_history(char *arg) { int num = 0; long buf; - + arg = skipspace(arg); - + if (history_done >= MAX_HIST) { print_error(error=HISTORY_RECURSION_ERROR); return; } history_done++; - + if (*arg == '(') { arg++; num = evall(&buf, &arg); @@ -755,17 +756,17 @@ static void cmd_history __P1 (char *,arg) num = (int)buf; } else num = atoi(arg); - + if (num > 0) - exe_history(num); + exe_history(num); else show_history(-num); } -static void cmd_host __P1 (char *,arg) +static void cmd_host(char *arg) { char newhost[BUFSIZE]; - + arg = skipspace(arg); if (*arg) { arg = split_first_word(newhost, BUFSIZE, arg); @@ -786,13 +787,13 @@ static void cmd_host __P1 (char *,arg) } } -static void cmd_request __P1 (char *,arg) +static void cmd_request(char *arg) { char *idprompt = "~$#EP2\nG\n"; char *ideditor = "~$#EI\n"; char buf[256]; int all, len; - + if (tcp_fd == -1) { PRINTF("#not connected to a MUD!\n"); return; @@ -818,10 +819,10 @@ static void cmd_request __P1 (char *,arg) } } } - + } -static void cmd_identify __P1 (char *,arg) +static void cmd_identify(char *arg) { edit_start[0] = edit_end[0] = '\0'; if (*arg) { @@ -835,28 +836,28 @@ static void cmd_identify __P1 (char *,arg) cmd_request("editor"); } -static void cmd_in __P1 (char *,arg) +static void cmd_in(char *arg) { char *name; long millisec, buf; int type; delaynode **p; - + arg = skipspace(arg); if (!*arg) { show_delays(); return; } - + arg = first_regular(name = arg, ' '); if (*arg) *arg++ = 0; - + unescape(name); - + p = lookup_delay(name, 0); if (!*p) p = lookup_delay(name, 1); - + if (!*arg && !*p) { PRINTF("#unknown delay label, cannot show: \"%s\"\n", name); return; @@ -871,7 +872,7 @@ static void cmd_in __P1 (char *,arg) return; } arg++; /* skip the '(' */ - + type = evall(&buf, &arg); if (!REAL_ERROR) { if (type!=TYPE_NUM) @@ -884,7 +885,7 @@ static void cmd_in __P1 (char *,arg) print_error(error); return; } - + arg = skipspace(arg+1); millisec = buf; if (*p && millisec) @@ -905,7 +906,7 @@ static void cmd_in __P1 (char *,arg) } } -static void cmd_at __P1 (char *,arg) +static void cmd_at(char *arg) { char *name, *buf = NULL; char dayflag=0; @@ -914,22 +915,22 @@ static void cmd_at __P1 (char *,arg) delaynode **p; long millisec; ptr pbuf = (ptr)0; - + arg = skipspace(arg); if (!*arg) { show_delays(); return; } - + arg = first_regular(name = arg, ' '); if (*arg) *arg++ = 0; - + unescape(name); - + p = lookup_delay(name, 0); if (!*p) p = lookup_delay(name, 1); - + if (!*arg && !*p) { PRINTF("#unknown delay label, cannot show: \"%s\"\n", name); return; @@ -944,7 +945,7 @@ static void cmd_at __P1 (char *,arg) return; } arg++; /* skip the '(' */ - + (void)evalp(&pbuf, &arg); if (REAL_ERROR) { print_error(error); @@ -967,7 +968,7 @@ static void cmd_at __P1 (char *,arg) } if (hour < 0 || hour>23 || minute < 0 || minute>59 || second < 0 || second>59) { - + PRINTF("#at: #error: invalid time \"%s\"\n", pbuf && buf ? buf : (char *)""); error=OUT_RANGE_ERROR; @@ -985,15 +986,15 @@ static void cmd_at __P1 (char *,arg) print_error(error=MISSING_PAREN_ERROR); return; } - + arg = skipspace(arg); update_now(); - twhen = localtime((time_t *)&now.tv_sec); + twhen = localtime((time_t *)&now.tv_sec); /* put current year, month, day in calendar struct */ - if (hour < twhen->tm_hour || - (hour == twhen->tm_hour && - (minute < twhen->tm_min || + if (hour < twhen->tm_hour || + (hour == twhen->tm_hour && + (minute < twhen->tm_min || (minute == twhen->tm_min && second <= twhen->tm_sec)))) { dayflag = 1; @@ -1001,13 +1002,13 @@ static void cmd_at __P1 (char *,arg) } /* if you use a time smaller than the current, it refers to tomorrow */ - - millisec = (hour - twhen->tm_hour) * 3600 + (minute - twhen->tm_min) * 60 + + + millisec = (hour - twhen->tm_hour) * 3600 + (minute - twhen->tm_min) * 60 + second - twhen->tm_sec + (dayflag ? 24*60*60 : 0); millisec *= mSEC_PER_SEC; /* Comparing time with current calendar, we finally got the delay */ millisec -= now.tv_usec / uSEC_PER_mSEC; - + if (*p) change_delaynode(p, arg, millisec); else @@ -1018,10 +1019,10 @@ static void cmd_at __P1 (char *,arg) } } -static void cmd_init __P1 (char *,arg) +static void cmd_init(char *arg) { arg = skipspace(arg); - + if (*arg == '=') { if (*++arg) { my_strncpy(initstr, arg, BUFSIZE-1); @@ -1038,7 +1039,7 @@ static void cmd_init __P1 (char *,arg) sprintf(inserted_next, "#init =%.*s", BUFSIZE-8, initstr); } -static void cmd_isprompt __P1 (char *,arg) +static void cmd_isprompt(char *arg) { if (tcp_fd == tcp_main_fd) { int i; @@ -1061,7 +1062,7 @@ static void cmd_isprompt __P1 (char *,arg) i = (int)l; } else i = atoi(arg); - + if (i == 0) surely_isprompt = -1; else if (i < 0) { @@ -1072,14 +1073,14 @@ static void cmd_isprompt __P1 (char *,arg) } } -static void cmd_key __P1 (char *,arg) +static void cmd_key(char *arg) { keynode *q=NULL; - + arg = skipspace(arg); if (!*arg) return; - + if ((q = *lookup_key(arg))) q->funct(q->call_data); else { @@ -1087,15 +1088,15 @@ static void cmd_key __P1 (char *,arg) } } -static void cmd_keyedit __P1 (char *,arg) +static void cmd_keyedit(char *arg) { int function; char *param; - + arg = skipspace(arg); if (!*arg) return; - + if ((function = lookup_edit_name(arg, ¶m))) internal_functions[function].funct(param); else { @@ -1103,7 +1104,7 @@ static void cmd_keyedit __P1 (char *,arg) } } -static void cmd_map __P1 (char *,arg) +static void cmd_map(char *arg) { arg = skipspace(arg); if (!*arg) /* show map */ @@ -1114,12 +1115,12 @@ static void cmd_map __P1 (char *,arg) map_walk(arg, 1, 1); } -static void cmd_retrace __P1 (char *,arg) +static void cmd_retrace(char *arg) { map_retrace(atoi(arg), 1); } -static void cmd_mark __P1 (char *,arg) +static void cmd_mark(char *arg) { if (!*arg) show_marks(); @@ -1127,7 +1128,7 @@ static void cmd_mark __P1 (char *,arg) parse_mark(arg); } -static void cmd_nice __P1 (char *,arg) +static void cmd_nice(char *arg) { int nnice = a_nice; arg = skipspace(arg); @@ -1167,7 +1168,7 @@ static void cmd_nice __P1 (char *,arg) } } -static void cmd_prefix __P1 (char *,arg) +static void cmd_prefix(char *arg) { strcpy(prefixstr, arg); if (opt_info) { @@ -1175,7 +1176,7 @@ static void cmd_prefix __P1 (char *,arg) } } -static void cmd_quote __P1 (char *,arg) +static void cmd_quote(char *arg) { arg = skipspace(arg); if (!*arg) @@ -1192,16 +1193,16 @@ static void cmd_quote __P1 (char *,arg) /* * change the escape sequence of an existing binding */ -static void cmd_rebind __P1 (char *,arg) +static void cmd_rebind(char *arg) { parse_rebind(arg); } -static void cmd_rebindall __P1 (char *,arg) +static void cmd_rebindall(char *arg) { keynode *kp; char *seq; - + for (kp = keydefs; kp; kp = kp->next) { seq = kp->sequence; if (kp->seqlen == 1 && seq[0] < ' ') @@ -1216,10 +1217,10 @@ static void cmd_rebindall __P1 (char *,arg) } } -static void cmd_rebindALL __P1 (char *,arg) +static void cmd_rebindALL(char *arg) { keynode *kp; - + for (kp = keydefs; kp; kp = kp->next) { parse_rebind(kp->name); if (error) @@ -1227,7 +1228,7 @@ static void cmd_rebindALL __P1 (char *,arg) } } -static void cmd_reset __P1 (char *,arg) +static void cmd_reset(char *arg) { char all = 0; arg = skipspace(arg); @@ -1291,11 +1292,11 @@ static void cmd_reset __P1 (char *,arg) while (*first) { if (is_permanent_variable(*first)) first = &(*first)->next; - else + else delete_varnode(first, 1); } } - + for (n = 0; n < NUMVAR; n++) { *var[n].num = 0; ptrdel(*var[n].str); @@ -1306,7 +1307,7 @@ static void cmd_reset __P1 (char *,arg) } } -static void cmd_snoop __P1 (char *,arg) +static void cmd_snoop(char *arg) { if (!*arg) { PRINTF("#snoop: which connection?\n"); @@ -1314,13 +1315,13 @@ static void cmd_snoop __P1 (char *,arg) tcp_togglesnoop(arg); } -static void cmd_stop __P1 (char *,arg) +static void cmd_stop(char *arg) { delaynode *dying; - + if (delays) update_now(); - + while (delays) { dying = delays; delays = dying->next; @@ -1334,37 +1335,37 @@ static void cmd_stop __P1 (char *,arg) } } -static void cmd_time __P1 (char *,arg) +static void cmd_time(char *arg) { struct tm *s; char buf[BUFSIZE]; - + update_now(); s = localtime((time_t *)&now.tv_sec); (void)strftime(buf, BUFSIZE - 1, "%a, %d %b %Y %H:%M:%S", s); PRINTF("#current time is %s\n", buf); } -static void cmd_ver __P1 (char *,arg) +static void cmd_ver(char *arg) { printver(); } -static void cmd_emulate __P1 (char *,arg) +static void cmd_emulate(char *arg) { char kind; FILE *fp; long start, end, i = 1; int len; ptr pbuf = (ptr)0; - + arg = redirect(arg, &pbuf, &kind, "emulate", 0, &start, &end); if (REAL_ERROR || !arg) return; - + if (kind) { char buf[BUFSIZE]; - + fp = (kind == '!') ? popen(arg, "r") : fopen(arg, "r"); if (!fp) { PRINTF("#emulate: #error opening \"%s\"\n", arg); @@ -1376,7 +1377,7 @@ static void cmd_emulate __P1 (char *,arg) while (!error && (!start || i<=end) && fgets(buf, BUFSIZE, fp)) if (!start || i++>=start) process_remote_input(buf, strlen(buf)); - + if (kind == '!') pclose(fp); else fclose(fp); } else { status(-1); /* idem */ @@ -1388,7 +1389,7 @@ static void cmd_emulate __P1 (char *,arg) ptrdel(pbuf); } -static void cmd_eval __P1 (char *,arg) +static void cmd_eval(char *arg) { arg = skipspace(arg); if (*arg=='(') { @@ -1405,21 +1406,21 @@ static void cmd_eval __P1 (char *,arg) } } -static void cmd_exe __P1 (char *,arg) +static void cmd_exe(char *arg) { char kind; char *clear; long offset, start, end, i = 1; FILE *fp; ptr pbuf = (ptr)0; - + arg = redirect(arg, &pbuf, &kind, "exe", 0, &start, &end); if (REAL_ERROR || !arg) return; if (kind) { char buf[BUFSIZE]; - + fp = (kind == '!') ? popen(arg, "r") : fopen(arg, "r"); if (!fp) { PRINTF("#exe: #error opening \"%s\"\n", arg); @@ -1445,27 +1446,27 @@ static void cmd_exe __P1 (char *,arg) offset = 0; } } - + if (kind == '!') pclose(fp); else fclose(fp); } else parse_user_input(arg, 0); ptrdel(pbuf); } -static void cmd_print __P1 (char *,arg) +static void cmd_print(char *arg) { char kind; long start, end, i = 1; FILE *fp; ptr pbuf = (ptr)0; - + clear_input_line(opt_compact); - + if (!*arg) { smart_print(*VAR[0].str ? ptrdata(*VAR[0].str) : (char *)"", 1); return; } - + arg = redirect(arg, &pbuf, &kind, "print", 1, &start, &end); if (REAL_ERROR || !arg) return; @@ -1483,24 +1484,24 @@ static void cmd_print __P1 (char *,arg) if (!start || i++>=start) tty_puts(buf); tty_putc('\n'); - + if (kind == '!') pclose(fp); else fclose(fp); } else smart_print(arg, 1); ptrdel(pbuf); } -static void cmd_send __P1 (char *,arg) +static void cmd_send(char *arg) { char *newline, kind; long start, end, i = 1; FILE *fp; ptr pbuf = (ptr)0; - + arg = redirect(arg, &pbuf, &kind, "send", 0, &start, &end); if (REAL_ERROR ||!arg) return; - + if (kind) { char buf[BUFSIZE]; fp = (kind == '!') ? popen(arg, "r") : fopen(arg, "r"); @@ -1513,7 +1514,7 @@ static void cmd_send __P1 (char *,arg) while (!error && (!start || i<=end) && fgets(buf, BUFSIZE, fp)) { if ((newline = strchr(buf, '\n'))) *newline = '\0'; - + if (!start || i++>=start) { if (opt_echo) { PRINTF("[%s]\n", buf); @@ -1531,10 +1532,10 @@ static void cmd_send __P1 (char *,arg) ptrdel(pbuf); } -static void cmd_rawsend __P1 (char *,arg) +static void cmd_rawsend(char *arg) { char *tmp = skipspace(arg); - + if (*tmp=='(') { ptr pbuf = (ptr)0; arg = tmp + 1; @@ -1551,10 +1552,10 @@ static void cmd_rawsend __P1 (char *,arg) } } -static void cmd_rawprint __P1 (char *,arg) +static void cmd_rawprint(char *arg) { char *tmp = skipspace(arg); - + if (*tmp=='(') { ptr pbuf = (ptr)0; arg = tmp + 1; @@ -1572,24 +1573,24 @@ static void cmd_rawprint __P1 (char *,arg) } -static void cmd_write __P1 (char *,arg) +static void cmd_write(char *arg) { ptr p1 = (ptr)0, p2 = (ptr)0; char *tmp = skipspace(arg), kind; FILE *fp; - + kind = *tmp; if (kind == '!' || kind == '>') arg = ++tmp; else kind = 0; - + if (*tmp=='(') { arg = tmp + 1; (void)evalp(&p1, &arg); if (REAL_ERROR) goto write_cleanup; - + if (*arg == CMDSEP) { arg++; (void)evalp(&p2, &arg); @@ -1608,7 +1609,7 @@ static void cmd_write __P1 (char *,arg) goto write_cleanup; } arg = ptrdata(p2); - + fp = (kind == '!') ? popen(arg, "w") : fopen(arg, kind ? "w" : "a"); if (!fp) { PRINTF("#write: #error opening \"%s\"\n", arg); @@ -1631,7 +1632,7 @@ write_cleanup2: ptrdel(p2); } -static void cmd_var __P1 (char *,arg) +static void cmd_var(char *arg) { char *buf, *expr, *tmp, kind, type, right = 0, deleting = 0; varnode **p_named_var = NULL, *named_var = NULL; @@ -1639,10 +1640,10 @@ static void cmd_var __P1 (char *,arg) long start, end, i = 1; int len, idx; ptr pbuf = (ptr)0; - + arg = skipspace(arg); expr = first_regular(arg, '='); - + if (*expr) { *expr++ = '\0'; /* skip the = */ if (!*expr) @@ -1653,7 +1654,7 @@ static void cmd_var __P1 (char *,arg) expr++; } } - + if (*arg == '$') type = TYPE_TXT_VAR; else if (*arg == '@') @@ -1665,7 +1666,7 @@ static void cmd_var __P1 (char *,arg) show_vars(); return; } - + kind = *++arg; if (isalpha(kind) || kind == '_') { /* found a named variable */ @@ -1695,7 +1696,7 @@ static void cmd_var __P1 (char *,arg) } else /* it exists, hold on */ named_var = *p_named_var; - + idx = named_var->index; } else { /* not a named variable, may be @@ -1730,7 +1731,7 @@ static void cmd_var __P1 (char *,arg) } } else { print_error(error=INVALID_NAME_ERROR); - return; + return; } } else { if (!isalpha(*buf) && *buf!='_') { @@ -1739,7 +1740,7 @@ static void cmd_var __P1 (char *,arg) } tmp = buf + 1; while (*tmp && (isalnum(*tmp) || *tmp=='_')) - tmp++; + tmp++; if (*tmp) { print_error(error=INVALID_NAME_ERROR); return; @@ -1767,7 +1768,7 @@ static void cmd_var __P1 (char *,arg) } else { /* an unnamed var */ long buf2; - + idx = evall(&buf2, &arg); if (!REAL_ERROR && idx != TYPE_NUM) error=NO_STRING_ERROR; @@ -1785,7 +1786,7 @@ static void cmd_var __P1 (char *,arg) } } - + if (type == TYPE_TXT_VAR && right && !*VAR[idx].str) { /* create it */ *VAR[idx].str = ptrnew(PARAMLEN); @@ -1808,7 +1809,7 @@ static void cmd_var __P1 (char *,arg) } } } else if ((type = TYPE_TXT_VAR)) { - /* R.I.P. unnamed variables */ + /* R.I.P. unnamed variables */ if (*VAR[idx].str) { if (idx < 0) { ptrdel(*VAR[idx].str); @@ -1853,7 +1854,7 @@ static void cmd_var __P1 (char *,arg) ptrdel(pbuf); return; } - + /* only case left: assign a value to a variable */ arg = redirect(expr, &pbuf, &kind, "var", 1, &start, &end); if (REAL_ERROR || !arg) @@ -1873,24 +1874,24 @@ static void cmd_var __P1 (char *,arg) while (!error && (!start || i<=end) && fgets(buf2+len, BUFSIZE-len, fp)) if (!start || i++>=start) len += strlen(buf2 + len); - + if (kind == '!') pclose(fp); else fclose(fp); if (len>PARAMLEN) len = PARAMLEN; buf2[len] = '\0'; arg = buf2; } - + if (type == TYPE_NUM_VAR) { arg = skipspace(arg); type = 1; len = 0; - + if (*arg == '-') arg++, type = -1; else if (*arg == '+') arg++; - + if (isdigit(kind=*arg)) while (isdigit(kind)) { len*=10; len+=(kind-'0'); @@ -1910,12 +1911,12 @@ static void cmd_var __P1 (char *,arg) ptrdel(pbuf); } -static void cmd_setvar __P1 (char *,arg) +static void cmd_setvar(char *arg) { char *name; int i, func = 0; /* show */ long buf; - + name = arg = skipspace(arg); arg = first_regular(arg, '='); if (*arg) { @@ -1933,14 +1934,14 @@ static void cmd_setvar __P1 (char *,arg) buf = strtol(arg, NULL, 0); } else buf = 0; - + if (REAL_ERROR) { PRINTF("#setvar: "); print_error(error); return; } } - + i = strlen(name); if (i && !strncmp(name, "timer", i)) { vtime t; @@ -1991,11 +1992,11 @@ static void cmd_setvar __P1 (char *,arg) } } -static void cmd_if __P1 (char *,arg) +static void cmd_if(char *arg) { long buf; int type; - + arg = skipspace(arg); if (*arg!='(') { PRINTF("#if: "); @@ -2003,7 +2004,7 @@ static void cmd_if __P1 (char *,arg) return; } arg++; /* skip the '(' */ - + type = evall(&buf, &arg); if (!REAL_ERROR) { if (type!=TYPE_NUM) @@ -2020,7 +2021,7 @@ static void cmd_if __P1 (char *,arg) print_error(error); return; } - + if (buf) (void)parse_instruction(arg, 0, 0, 1); else { @@ -2030,12 +2031,12 @@ static void cmd_if __P1 (char *,arg) } } -static void cmd_for __P1 (char *,arg) +static void cmd_for(char *arg) { int type = TYPE_NUM, loop=MAX_LOOP; long buf; char *check, *tmp, *increm = 0; - + arg = skipspace(arg); if (*arg != '(') { PRINTF("#for: "); @@ -2045,13 +2046,13 @@ static void cmd_for __P1 (char *,arg) push_params(); if (REAL_ERROR) return; - + arg = skipspace(arg + 1); /* skip the '(' */ if (*arg != CMDSEP) (void)evaln(&arg); /* execute */ - + check = arg + 1; - + if (REAL_ERROR) ; else if (*arg != CMDSEP) { @@ -2061,7 +2062,7 @@ static void cmd_for __P1 (char *,arg) else while (!error && loop && (increm=check, (type = evall(&buf, &increm)) == TYPE_NUM && !error && *increm == CMDSEP && buf)) { - + tmp = first_regular(increm + 1, ')'); if (*tmp) (void)parse_instruction(tmp + 1, 1, 1, 1); @@ -2069,13 +2070,13 @@ static void cmd_for __P1 (char *,arg) PRINTF("#for: "); print_error(error=MISSING_PAREN_ERROR); } - + if (!error) { tmp = increm + 1; if (*tmp != ')') (void)evaln(&tmp); } - + loop--; } if (REAL_ERROR) @@ -2094,12 +2095,12 @@ static void cmd_for __P1 (char *,arg) pop_params(); } -static void cmd_while __P1 (char *,arg) +static void cmd_while(char *arg) { int type = TYPE_NUM, loop=MAX_LOOP; long buf; char *check, *tmp; - + arg = skipspace(arg); if (!*arg) { PRINTF("#while: "); @@ -2107,12 +2108,12 @@ static void cmd_while __P1 (char *,arg) return; } push_params(); - + check = ++arg; /* skip the '(' */ while (!error && loop && (arg=check, (type = evall(&buf, &arg)) == TYPE_NUM && !error && *arg == ')' && buf)) { - + if (*(tmp = arg + 1) == ' ') /* skip the ')' */ tmp++; if (*tmp) @@ -2135,10 +2136,10 @@ static void cmd_while __P1 (char *,arg) pop_params(); } -static void cmd_capture __P1 (char *,arg) +static void cmd_capture(char *arg) { arg = skipspace(arg); - + if (!*arg) { if (capturefile) { log_flush(); @@ -2156,7 +2157,7 @@ static void cmd_capture __P1 (char *,arg) } else { short append = 0; /* Append to log file, if the name starts with '>' */ - if (*arg == '>') { + if (*arg == '>') { arg++; append = 1; } @@ -2169,10 +2170,10 @@ static void cmd_capture __P1 (char *,arg) } } -static void cmd_movie __P1 (char *,arg) +static void cmd_movie(char *arg) { arg = skipspace(arg); - + if (!*arg) { if (moviefile) { log_flush(); @@ -2202,10 +2203,10 @@ static void cmd_movie __P1 (char *,arg) } } -static void cmd_record __P1 (char *,arg) +static void cmd_record(char *arg) { arg = skipspace(arg); - + if (!*arg) { if (recordfile) { fclose(recordfile); @@ -2229,10 +2230,10 @@ static void cmd_record __P1 (char *,arg) } } -static void cmd_edit __P1 (char *,arg) +static void cmd_edit(char *arg) { editsess *sp; - + if (edit_sess) { for (sp = edit_sess; sp; sp = sp->next) { PRINTF("# %s (%u)\n", sp->descr, sp->key); @@ -2242,10 +2243,10 @@ static void cmd_edit __P1 (char *,arg) } } -static void cmd_cancel __P1 (char *,arg) +static void cmd_cancel(char *arg) { editsess *sp; - + if (!edit_sess) { PRINTF("#no editing sessions to cancel.\n"); } else { @@ -2267,7 +2268,7 @@ static void cmd_cancel __P1 (char *,arg) } } -static void cmd_net __P1 (char *,arg) +static void cmd_net(char *arg) { PRINTF("#received from host: %ld chars, sent to host: %ld chars.\n", received, sent); @@ -2279,7 +2280,7 @@ static void cmd_net __P1 (char *,arg) #endif /* hope it works.... */ -static void cmd_cpu __P1 (char *,arg) +static void cmd_cpu(char *arg) { float f, l; update_now(); @@ -2289,27 +2290,27 @@ static void cmd_cpu __P1 (char *,arg) (l > 0 && l > f) ? f * 100.0 / l : 100.0); } -void show_stat __P0 (void) +void show_stat(void) { cmd_net(NULL); cmd_cpu(NULL); } #ifdef BUG_TELNET -static void cmd_color __P1 (char *,arg) +static void cmd_color(char *arg) { int attrcode; - + arg = skipspace(arg); if (!*arg) { strcpy(tty_modenorm, tty_modenormbackup); - tty_puts(tty_modenorm); + tty_puts(tty_modenorm); if (opt_info) { PRINTF("#standard color cleared.\n"); } return; } - + attrcode = parse_attributes(arg); if (attrcode == -1) { PRINTF("#invalid attribute syntax.\n"); @@ -2332,14 +2333,14 @@ static void cmd_color __P1 (char *,arg) } #endif -static void cmd_connect __P1 (char *,arg) +static void cmd_connect(char *arg) { #ifdef TERM PRINTF("#connect: multiple connections not supported in term version.\n"); #else char *s1, *s2, *s3 = NULL, *s4 = NULL; int argc = 1; - + if (!*skipspace(arg)) { tcp_show(); return; @@ -2358,7 +2359,7 @@ static void cmd_connect __P1 (char *,arg) } } } - + if (argc <= 2) { if (*hostname) tcp_open(s1, s2, hostname, portnumber); @@ -2382,7 +2383,7 @@ static void cmd_connect __P1 (char *,arg) } -static void cmd_spawn __P1 (char *,arg) +static void cmd_spawn(char *arg) { char s[BUFSIZE]; if (*(arg = skipspace(arg))) { @@ -2397,7 +2398,7 @@ static void cmd_spawn __P1 (char *,arg) /* If you have speedwalk off but still want to use a speedwalk sequence, * you can manually trigger a speedwalk this way */ -static void cmd_speedwalk __P1 (char *,arg) +static void cmd_speedwalk(char *arg) { char save_speedwalk = opt_speedwalk; PRINTF( "Executing speedwalk '%s'\n", arg ); @@ -2408,7 +2409,7 @@ static void cmd_speedwalk __P1 (char *,arg) opt_speedwalk = save_speedwalk; } -static void cmd_zap __P1 (char *,arg) +static void cmd_zap(char *arg) { if (!*arg) { PRINTF("#zap: no connection name.\n"); @@ -2416,12 +2417,12 @@ static void cmd_zap __P1 (char *,arg) tcp_close(arg); } -static void cmd_qui __P1 (char *,arg) +static void cmd_qui(char *arg) { PRINTF("#you have to write '#quit' - no less, to quit!\n"); } -static void cmd_quit __P1 (char *,arg) +static void cmd_quit(char *arg) { if (*arg) { /* no skipspace() here! */ PRINTF("#quit: spurious argument?\n"); @@ -2467,7 +2468,7 @@ static const struct { /* print all options to 'file', or tty if file is NULL; return -1 on * error, 1 on success */ -int print_all_options __P1 (FILE *,file) +int print_all_options(FILE *file) { const char *prefix = "#option"; int width = (file ? 80 : cols) - 16; @@ -2502,7 +2503,7 @@ int print_all_options __P1 (FILE *,file) return 1; } -static void cmd_option __P1 (char *,arg) +static void cmd_option(char *arg) { char buf[BUFSIZE]; int count = 0; @@ -2576,7 +2577,7 @@ static void cmd_option __P1 (char *,arg) } } -static void cmd_file __P1 (char *,arg) +static void cmd_file(char *arg) { arg = skipspace(arg); if (*arg == '=') { @@ -2590,13 +2591,13 @@ static void cmd_file __P1 (char *,arg) } } else if (*deffile) { sprintf(inserted_next, "#file =%.*s", BUFSIZE-8, deffile); - } else { + } else { PRINTF("#save-file not defined.\n"); } } -static void cmd_save __P1 (char *,arg) -{ +static void cmd_save(char *arg) +{ arg = skipspace(arg); if (*arg) { set_deffile(arg); @@ -2607,16 +2608,16 @@ static void cmd_save __P1 (char *,arg) PRINTF("#save-file not defined.\n"); return; } - + if (*deffile && save_settings() > 0 && opt_info) { PRINTF("#settings saved to file.\n"); } } -static void cmd_load __P1 (char *,arg) +static void cmd_load(char *arg) { int res; - + arg = skipspace(arg); if (*arg) { set_deffile(arg); @@ -2628,9 +2629,9 @@ static void cmd_load __P1 (char *,arg) PRINTF("#save-file not defined.\n"); return; } - + res = read_settings(); - + if (res > 0) { /* success */ if (opt_info) { @@ -2647,13 +2648,13 @@ static void cmd_load __P1 (char *,arg) } } -static char *trivial_eval __P3 (ptr *,pbuf, char *,arg, char *,name) +static char *trivial_eval(ptr *pbuf, char *arg, char *name) { char *tmp = skipspace(arg); - + if (!pbuf) return NULL; - + if (*tmp=='(') { arg = tmp + 1; (void)evalp(pbuf, &arg); @@ -2671,15 +2672,15 @@ static char *trivial_eval __P3 (ptr *,pbuf, char *,arg, char *,name) } else unescape(arg); - + return arg; } -static void do_cmd_add __P2(char *,arg, int,is_static) +static void do_cmd_add(char *arg, int is_static) { ptr pbuf = (ptr)0; char buf[BUFSIZE]; - + arg = trivial_eval(&pbuf, arg, "add"); if (!REAL_ERROR) while (*arg) { @@ -2690,17 +2691,17 @@ static void do_cmd_add __P2(char *,arg, int,is_static) ptrdel(pbuf); } -static void cmd_add __P1 (char *,arg) +static void cmd_add(char *arg) { do_cmd_add(arg, 0); } -static void cmd_addstatic __P1 (char *,arg) +static void cmd_addstatic(char *arg) { do_cmd_add(arg, 1); } -static void cmd_put __P1 (char *,arg) +static void cmd_put(char *arg) { ptr pbuf = (ptr)0; arg = trivial_eval(&pbuf, arg, "put"); diff --git a/cmd.h b/cmd.h index 1c655fb..74cf53f 100644 --- a/cmd.h +++ b/cmd.h @@ -14,13 +14,13 @@ typedef struct cmdstruct { extern cmdstruct *commands; -void show_stat __P ((void)); +void show_stat(void); void cmd_add_command( cmdstruct *cmd ); void initialize_cmd(void); -int print_all_options __P1 (FILE *,file); +int print_all_options(FILE *file); #endif /* _CMD_H_ */ diff --git a/cmd2.c b/cmd2.c index 41a26eb..81275b6 100644 --- a/cmd2.c +++ b/cmd2.c @@ -2,7 +2,7 @@ * cmd2.c -- back-end for the various #commands * * (created: Massimiliano Ghilardi (Cosmos), Aug 14th, 1998) - * + * * Copyright (C) 1998 by Massimiliano Ghilardi * * This program is free software; you can redistribute it and/or modify @@ -13,6 +13,7 @@ */ +#include #include #include #include @@ -52,18 +53,18 @@ static char *colornames[] = { /* * show defined aliases */ -void show_aliases __P0 (void) +void show_aliases(void) { aliasnode *p; char buf[BUFSIZE]; - + PRINTF("#%s alias%s defined%c\n", sortedaliases ? "the following" : "no", (sortedaliases && !sortedaliases->snext) ? " is" : "es are", sortedaliases ? ':' : '.'); reverse_sortedlist((sortednode **)&sortedaliases); for (p = sortedaliases; p; p = p->snext) { escape_specials(buf, p->name); - tty_printf("#alias %s%s%s%s=%s\n", + tty_printf("#alias %s%s%s%s=%s\n", p->active ? "" : "(disabled) ", buf, group_delim, p->group == NULL ? "*" : p->group, p->subst); } @@ -75,7 +76,7 @@ void show_aliases __P0 (void) * return 1 if illegal name (and print reason). * if valid, print a warning for unbalanced () {} and "" */ -static int check_alias __P1 (char *,name) +static int check_alias(char *name) { char *p = name, c; enum { NORM, ESCAPE } state = NORM; @@ -126,13 +127,13 @@ static int check_alias __P1 (char *,name) default: break; } - + if (!ok) { PRINTF("#illegal non-escaped ';' in alias name: \"%s\"\n", name); error = INVALID_NAME_ERROR; return 1; } - + if (quotes || paren || braces) { PRINTF("#warning: unbalanced%s%s%s in alias name \"%s\" may cause problems\n", quotes ? " \"\"" : "", paren ? " ()" : "", braces ? " {}" : "", name); @@ -145,13 +146,13 @@ static int check_alias __P1 (char *,name) /* * parse the #alias command */ -void parse_alias __P1 (char *,str) +void parse_alias(char *str) { char *left, *right, *group; aliasnode **np, *p; - + left = str = skipspace(str); - + str = first_valid(str, '='); if (*str == '=') { @@ -181,12 +182,12 @@ void parse_alias __P1 (char *,str) } } else { /* add/redefine alias */ - + /* direct recursion is supported (alias CAN be defined by itself) */ if (p) { free(p->subst); p->subst = my_strdup(right); - } else + } else add_aliasnode(left, right); /* get alias again to add group (if needed) @@ -209,7 +210,7 @@ void parse_alias __P1 (char *,str) } } else { /* show alias */ - + *str = '\0'; unescape(left); if (check_alias(left)) @@ -219,7 +220,7 @@ void parse_alias __P1 (char *,str) char buf[BUFSIZE]; escape_specials(buf, left); snprintf(inserted_next, BUFSIZE, "#alias %s%s%s=%s", - buf, + buf, group_delim, (*np)->group == NULL ? "*" : (*np)->group, (*np)->subst); @@ -232,7 +233,7 @@ void parse_alias __P1 (char *,str) /* * delete an action node */ -static void delete_action __P1 (actionnode **,nodep) +static void delete_action(actionnode **nodep) { if (opt_info) { PRINTF("#deleting action: >%c%s %s\n", (*nodep)->active ? @@ -244,7 +245,7 @@ static void delete_action __P1 (actionnode **,nodep) /* * delete a prompt node */ -static void delete_prompt __P1 (actionnode **,nodep) +static void delete_prompt(actionnode **nodep) { if (opt_info) { PRINTF("#deleting prompt: >%c%s %s\n", (*nodep)->active ? @@ -256,11 +257,11 @@ static void delete_prompt __P1 (actionnode **,nodep) /* * create new action */ -static void add_new_action __P6 (char *,label, char *,pattern, char *,command, int,active, int,type, void *,q) +static void add_new_action(char *label, char *pattern, char *command, int active, int type, void *q) { add_actionnode(pattern, command, label, active, type, q); if (opt_info) { - PRINTF("#new action: %c%c%s %s=%s\n", + PRINTF("#new action: %c%c%s %s=%s\n", action_chars[type], active ? '+' : '-', label, pattern, command); @@ -270,11 +271,11 @@ static void add_new_action __P6 (char *,label, char *,pattern, char *,command, i /* * create new prompt */ -static void add_new_prompt __P6 (char *,label, char *,pattern, char *,command, int,active, int,type, void *,q) +static void add_new_prompt(char *label, char *pattern, char *command, int active, int type, void *q) { add_promptnode(pattern, command, label, active, type, q); if (opt_info) { - PRINTF("#new prompt: %c%c%s %s=%s\n", + PRINTF("#new prompt: %c%c%s %s=%s\n", action_chars[type], active ? '+' : '-', label, pattern, command); @@ -284,7 +285,7 @@ static void add_new_prompt __P6 (char *,label, char *,pattern, char *,command, i /* * add an action with numbered label */ -static void add_anonymous_action __P4 (char *,pattern, char *,command, int,type, void *,q) +static void add_anonymous_action(char *pattern, char *command, int type, void *q) { static int last = 0; char label[16]; @@ -300,7 +301,7 @@ static void add_anonymous_action __P4 (char *,pattern, char *,command, int,type, * change fields of an existing action node * pattern or commands can be NULL if no change */ -static void change_actionorprompt __P6 (actionnode *,node, char *,pattern, char *,command, int,type, void *,q, int,onprompt) +static void change_actionorprompt(actionnode *node, char *pattern, char *command, int type, void *q, int onprompt) { #ifdef USE_REGEXP if (node->type == ACTION_REGEXP && node->regexp) { @@ -318,7 +319,7 @@ static void change_actionorprompt __P6 (actionnode *,node, char *,pattern, char free(node->command); node->command = my_strdup(command); } - + if (opt_info) { PRINTF("#changed %s %c%c%s %s=%s\n", ONPROMPT, action_chars[node->type], @@ -330,10 +331,10 @@ static void change_actionorprompt __P6 (actionnode *,node, char *,pattern, char /* * show defined actions */ -void show_actions __P0 (void) +void show_actions(void) { actionnode *p; - + PRINTF("#%s action%s defined%c\n", actions ? "the following" : "no", (actions && !actions->next) ? " is" : "s are", actions ? ':' : '.'); for (p = actions; p; p = p->next) @@ -341,7 +342,7 @@ void show_actions __P0 (void) action_chars[p->type], p->active ? '+' : '-', p->label, group_delim, - p->group == NULL ? "*" : p->group, + p->group == NULL ? "*" : p->group, p->pattern, p->command); } @@ -349,10 +350,10 @@ void show_actions __P0 (void) /* * show defined prompts */ -void show_prompts __P0 (void) +void show_prompts(void) { promptnode *p; - + PRINTF("#%s prompt%s defined%c\n", prompts ? "the following" : "no", (prompts && !prompts->next) ? " is" : "s are", prompts ? ':' : '.'); for (p = prompts; p; p = p->next) @@ -367,22 +368,22 @@ void show_prompts __P0 (void) * this function is too damn complex because of the hairy syntax. it should be * split up or rewritten as an fsm instead. */ -void parse_action __P2 (char *,str, int,onprompt) +void parse_action(char *str, int onprompt) { char *p, label[BUFSIZE], pattern[BUFSIZE], *command, *group; actionnode **np = NULL; char sign, assign, hastail; char active, type = ACTION_WEAK, kind; void *regexp = 0; - + sign = *(p = skipspace(str)); if (!sign) { PRINTF("%s: no arguments given\n", ONPROMPT); return; } - + str = p + 1; - + switch (sign) { case '+': case '-': /* edit */ @@ -394,7 +395,7 @@ void parse_action __P2 (char *,str, int,onprompt) type = ACTION_REGEXP; /* falltrough */ case '>': /* action_chars[ACTION_WEAK] */ - + /* define/edit */ assign = '>'; sign = *(p + 1); @@ -411,7 +412,7 @@ void parse_action __P2 (char *,str, int,onprompt) str = p; break; } - + /* labelled action: */ if (assign != 0) { p = first_regular(str, ' '); @@ -424,11 +425,11 @@ void parse_action __P2 (char *,str, int,onprompt) *group = 0; group += strlen( group_delim ); } - + my_strncpy(label, str, BUFSIZE-1); if (hastail) *p++ = ' '; /* p points to start of pattern, or to \0 */ - + if (!*label) { PRINTF("#%s: label expected\n", ONPROMPT); return; @@ -439,7 +440,7 @@ void parse_action __P2 (char *,str, int,onprompt) np = lookup_prompt(label); else np = lookup_action(label); - + /* '<' : remove action */ if (assign == '<') { if (!np || !*np) { @@ -452,26 +453,26 @@ void parse_action __P2 (char *,str, int,onprompt) else delete_action(np); } - + /* '>' : define action */ } else if (assign == '>') { #ifndef USE_REGEXP if (type == ACTION_REGEXP) { PRINTF("#error: regexp not allowed\n"); return; - } + } #endif - + if (sign == '+') active = 1; else active = 0; - + if (!*label) { PRINTF("#%s: label expected\n", ONPROMPT); return; } - + p = skipspace(p); if (*p == '(') { ptr pbuf = (ptr)0; @@ -500,21 +501,21 @@ void parse_action __P2 (char *,str, int,onprompt) if ((hastail = *p)) *p = '\0'; my_strncpy(pattern, command, BUFSIZE-1); - + if (hastail) *p++ = '='; } - + if (!*pattern) { PRINTF("#error: pattern of #%ss must be non-empty.\n", ONPROMPT); return; } - + #ifdef USE_REGEXP if (type == ACTION_REGEXP && hastail) { int errcode; char unesc_pat[BUFSIZE]; - + /* * HACK WARNING: * we unescape regexp patterns now, instead of doing @@ -522,13 +523,13 @@ void parse_action __P2 (char *,str, int,onprompt) */ strcpy(unesc_pat, pattern); unescape(unesc_pat); - - regexp = malloc(sizeof(regex_t)); + + regexp = malloc(sizeof(regex_t)); if (!regexp) { errmsg("malloc"); return; } - + if ((errcode = regcomp((regex_t *)regexp, unesc_pat, REG_EXTENDED))) { int n; char *tmp; @@ -552,17 +553,17 @@ void parse_action __P2 (char *,str, int,onprompt) } #endif command = p; - + if (hastail) { if (np && *np) { change_actionorprompt(*np, pattern, command, type, regexp, onprompt); (*np)->active = active; } else { if (onprompt) - add_new_prompt(label, pattern, command, active, + add_new_prompt(label, pattern, command, active, type, regexp); else - add_new_action(label, pattern, command, active, + add_new_action(label, pattern, command, active, type, regexp); } @@ -582,7 +583,7 @@ void parse_action __P2 (char *,str, int,onprompt) (*np) -> group = my_strdup( group ); } } - + /* '=': list action */ } else if (assign == '='){ if (np && *np) { @@ -596,7 +597,7 @@ void parse_action __P2 (char *,str, int,onprompt) } else { PRINTF("#no %s, cannot list label: \"%s\"\n", ONPROMPT, label); } - + /* '+', '-': turn action on/off */ } else { if (np && *np) { @@ -612,17 +613,17 @@ void parse_action __P2 (char *,str, int,onprompt) (sign == '+') ? "n" : "ff", label); } } - + /* anonymous action, cannot be regexp */ } else { - + if (onprompt) { PRINTF("#anonymous prompts not supported.\n#please use labelled prompts.\n"); return; } - + command = first_regular(str, '='); - + if (*command == '=') { *command = '\0'; @@ -660,7 +661,7 @@ void parse_action __P2 (char *,str, int,onprompt) /* * display attribute syntax */ -void show_attr_syntax __P0 (void) +void show_attr_syntax(void) { int i; PRINTF("#attribute syntax:\n\tOne or more of:\tbold, blink, underline, inverse\n\tand/or\t[foreground] [ON background]\n\tColors: "); @@ -673,17 +674,17 @@ void show_attr_syntax __P0 (void) /* * put escape sequences to turn on/off an attribute in given buffers */ -void attr_string __P3 (int,attrcode, char *,begin, char *,end) +void attr_string(int attrcode, char *begin, char *end) { int fg = FOREGROUND(attrcode), bg = BACKGROUND(attrcode), tok = ATTR(attrcode); char need_end = 0; *begin = *end = '\0'; - + if (tok > (ATTR_BOLD | ATTR_BLINK | ATTR_UNDERLINE | ATTR_INVERSE) || fg > COLORS || bg > COLORS || attrcode == NOATTRCODE) return; /* do nothing */ - + if (fg < COLORS) { if (bg < COLORS) { sprintf(begin, "\033[%c%d;%s%dm", @@ -700,13 +701,13 @@ void attr_string __P3 (int,attrcode, char *,begin, char *,end) #endif } } else if (bg < COLORS) { - sprintf(begin, "\033[%s%dm", + sprintf(begin, "\033[%s%dm", bg (ATTR_BOLD | ATTR_BLINK | ATTR_UNDERLINE | ATTR_INVERSE) || fg > COLORS || bg > COLORS) return name; /* error! */ - + if (tok & ATTR_BOLD) strcat(name, "bold "); if (tok & ATTR_BLINK) @@ -856,25 +857,25 @@ char *attr_name __P1 (int,attrcode) strcat(name, "underline "); if (tok & ATTR_INVERSE) strcat(name, "inverse "); - + if (fg < COLORS || (fg == bg && fg == COLORS && !tok)) strcat(name, colornames[fg]); - + if (bg < COLORS) { strcat(name, " on "); strcat(name, colornames[bg]); } - + if (!*name) strcpy(name, "none"); - + return name; } /* * show defined marks */ -void show_marks __P0 (void) +void show_marks(void) { marknode *p; PRINTF("#%s marker%s defined%c\n", markers ? "the following" : "no", @@ -889,12 +890,12 @@ void show_marks __P0 (void) /* * parse arguments to the #mark command */ -void parse_mark __P1 (char *,str) +void parse_mark(char *str) { char *p; marknode **np, *n; char mbeg = 0; - + if (*str == '=') { PRINTF("#marker must be non-null.\n"); return; @@ -918,7 +919,7 @@ void parse_mark __P1 (char *,str) } else { PRINTF("#unknown marker, cannot show: \"%s\"\n", str); } - + } else { int attrcode, wild = 0; char pattern[BUFSIZE], *p2; @@ -983,11 +984,11 @@ void parse_mark __P1 (char *,str) * into raw escape sequence * return pointer to end of ASCII description */ -static char *unescape_seq __P3 (char *,buf, char *,seq, int *,seqlen) +static char *unescape_seq(char *buf, char *seq, int *seqlen) { char c, *start = buf; enum { NORM, ESCSINGLE, ESCAPE, CARET, DONE } state = NORM; - + for (; (c = *seq); seq++) { switch (state) { case NORM: @@ -1019,7 +1020,7 @@ static char *unescape_seq __P3 (char *,buf, char *,seq, int *,seqlen) */ if (state == ESCSINGLE && ISODIGIT(seq[0]) && ISODIGIT(seq[1]) && ISODIGIT(seq[2])) { - *(buf++) =(((seq[0] - '0') << 6) | + *(buf++) =(((seq[0] - '0') << 6) | ((seq[1] - '0') << 3) | (seq[2] - '0')); seq += 2; @@ -1047,13 +1048,13 @@ static char *unescape_seq __P3 (char *,buf, char *,seq, int *,seqlen) * timeout == 0 means wait indefinitely (no timeout). * return char or -1 if timeout was reached. */ -static int get_one_char __P1 (int,timeout) +static int get_one_char(int timeout) { struct timeval timeoutbuf; fd_set fds; int n; char c; - + again: FD_ZERO(&fds); FD_SET(tty_read_fd, &fds); @@ -1086,7 +1087,7 @@ static int get_one_char __P1 (int,timeout) /* * print an escape sequence in human-readably form. */ -void print_seq __P2 (char *,seq, int,len) +void print_seq(char *seq, int len) { while (len--) { unsigned char ch = *(seq++); @@ -1113,14 +1114,14 @@ void print_seq __P2 (char *,seq, int,len) * return a static pointer to escape sequence made printable, for use in * definition-files */ -char *seq_name __P2 (char *,seq, int,len) +char *seq_name(char *seq, int len) { static char buf[CAPLEN*4]; char *p = buf; /* * rules: control chars are written as ^X, where * X is char | 64 - * + * * GH: codes > 0x80 ==> octal \012 * * special case: 0x7f is written ^? @@ -1129,7 +1130,7 @@ char *seq_name __P2 (char *,seq, int,len) unsigned char c = *seq++; if (c == '^' || (c && strchr(SPECIAL_CHARS, c))) *(p++) = ESC; - + if (c < ' ') { *(p++) = '^'; *(p++) = c | '@'; @@ -1151,11 +1152,11 @@ char *seq_name __P2 (char *,seq, int,len) * read a single escape sequence from the keyboard * prompting user for it; return static pointer */ -char *read_seq __P2 (char *,name, int *,len) +char *read_seq(char *name, int *len) { static char seq[CAPLEN]; int i = 1, tmp; - + PRINTF("#please press the key \"%s\" : ", name); tty_flush(); @@ -1165,13 +1166,13 @@ char *read_seq __P2 (char *,name, int *,len) tty_puts("#unable to get key. Giving up.\n"); return NULL; } - + while (i < CAPLEN - 1 && (tmp = get_one_char(KBD_TIMEOUT)) >= 0) seq[i++] = tmp; *len = i; print_seq(seq, i); - + tty_putc('\n'); if (seq[0] >= ' ' && seq[0] <= '~') { PRINTF("#that is not a redefinable key.\n"); @@ -1184,7 +1185,7 @@ char *read_seq __P2 (char *,name, int *,len) * show full definition of one binding, * with custom message */ -static void show_single_bind __P2 (char *,msg, keynode *,p) +static void show_single_bind(char *msg, keynode *p) { if (p->funct == key_run_command) { PRINTF("#%s %s %s=%s\n", msg, p->name, @@ -1201,7 +1202,7 @@ static void show_single_bind __P2 (char *,msg, keynode *,p) /* * list keyboard bindings */ -void show_binds __P1 (char,edit) +void show_binds(char edit) { keynode *p; int count = 0; @@ -1227,29 +1228,29 @@ void show_binds __P1 (char,edit) /* * interactively create a new keybinding */ -static void define_new_key __P2 (char *,name, char *,command) +static void define_new_key(char *name, char *command) { char *seq, *arg; keynode *p; int seqlen, function; - + seq = read_seq(name, &seqlen); if (!seq) return; - + for (p = keydefs; p; p = p->next) /* GH: don't allow binding of supersets of another bind */ if (!memcmp(p->sequence, seq, MIN2(p->seqlen, seqlen))) { show_single_bind("key already bound as:", p); return; } - + function = lookup_edit_name(command, &arg); if (function) add_keynode(name, seq, seqlen, internal_functions[function].funct, arg); else add_keynode(name, seq, seqlen, key_run_command, command); - + if (opt_info) { PRINTF("#new key binding: %s %s=%s\n", name, seq_name(seq, seqlen), command); @@ -1259,12 +1260,12 @@ static void define_new_key __P2 (char *,name, char *,command) /* * parse the #bind command non-interactively. */ -static void parse_bind_noninteractive __P1 (char *,arg) +static void parse_bind_noninteractive(char *arg) { char rawseq[CAPLEN], *p, *seq, *params; int function, seqlen; keynode **kp; - + p = strchr(arg, ' '); if (!p) { PRINTF("#syntax error: \"#bind %s\"\n", arg); @@ -1272,24 +1273,24 @@ static void parse_bind_noninteractive __P1 (char *,arg) } *(p++) = '\0'; seq = p = skipspace(p); - + p = unescape_seq(rawseq, p, &seqlen); if (!p[0] || !p[1]) { PRINTF("#syntax error: \"#bind %s %s\"\n", arg, seq); return; } *p++ = '\0'; - + kp = lookup_key(arg); if (kp && *kp) delete_keynode(kp); - + if ((function = lookup_edit_name(p, ¶ms))) - add_keynode(arg, rawseq, seqlen, + add_keynode(arg, rawseq, seqlen, internal_functions[function].funct, params); else add_keynode(arg, rawseq, seqlen, key_run_command, p); - + if (opt_info) { PRINTF("#%s: %s %s=%s\n", (kp && *kp) ? "redefined key" : "new key binding", @@ -1300,22 +1301,22 @@ static void parse_bind_noninteractive __P1 (char *,arg) /* * parse the argument of the #bind command (interactive) */ -void parse_bind __P1 (char *,arg) +void parse_bind(char *arg) { char *p, *q, *command, *params; char *name = arg; keynode **npp, *np; int function; - + p = first_valid(arg, '='); q = first_valid(arg, ' '); q = skipspace(q); - - if (*p && *q && p > q) { + + if (*p && *q && p > q) { parse_bind_noninteractive(arg); return; } - + if (*p) { *(p++) = '\0'; np = *(npp = lookup_key(name)); @@ -1354,7 +1355,7 @@ void parse_bind __P1 (char *,arg) int seqlen; seqname = seq_name(np->sequence, np->seqlen); seqlen = strlen(seqname); - + if (np->funct == key_run_command) sprintf(inserted_next, "#bind %.*s %s=%.*s", BUFSIZE-seqlen-9, name, seqname, @@ -1374,30 +1375,30 @@ void parse_bind __P1 (char *,arg) } } -void parse_rebind __P1 (char *,arg) +void parse_rebind(char *arg) { char rawseq[CAPLEN], *seq, **old; keynode **kp, *p; int seqlen; - + arg = skipspace(arg); if (!*arg) { PRINTF("#rebind: missing key.\n"); return; } - + seq = first_valid(arg, ' '); if (*seq) { *seq++ = '\0'; seq = skipspace(seq); } - + kp = lookup_key(arg); if (!kp || !*kp) { PRINTF("#no such key: \"%s\"\n", arg); return; } - + if (!*seq) { seq = read_seq(arg, &seqlen); if (!seq) @@ -1415,7 +1416,7 @@ void parse_rebind __P1 (char *,arg) return; } } - + old = &((*kp)->sequence); if (*old) free(*old); @@ -1432,24 +1433,24 @@ void parse_rebind __P1 (char *,arg) * if needed, use/malloc "pbuf" as buffer (on error, also free pbuf) * return resulting char * */ -char *redirect __P7 (char *,arg, ptr *,pbuf, char *,kind, char *,name, int,also_num, long *,start, long *,end) +char *redirect(char *arg, ptr *pbuf, char *kind, char *name, int also_num, long *start, long *end) { char *tmp = skipspace(arg), k; int type, i; - + if (!pbuf) { print_error(error=INTERNAL_ERROR); return NULL; } - + k = *tmp; if (k == '!' || k == '<') arg = ++tmp; else k = 0; - + *start = *end = 0; - + if (*tmp=='(') { arg = tmp + 1; @@ -1464,7 +1465,7 @@ char *redirect __P7 (char *,arg, ptr *,pbuf, char *,kind, char *,name, int,also_ } for (i=0; i<2; i++) if (*arg == CMDSEP) { long buf; - + arg++; if (!i && *arg == CMDSEP) { *start = 1; @@ -1474,7 +1475,7 @@ char *redirect __P7 (char *,arg, ptr *,pbuf, char *,kind, char *,name, int,also_ *end = LONG_MAX; continue; } - + type = evall(&buf, &arg); if (!REAL_ERROR && type != TYPE_NUM) error=NO_NUM_VALUE_ERROR; @@ -1510,19 +1511,19 @@ char *redirect __P7 (char *,arg, ptr *,pbuf, char *,kind, char *,name, int,also_ *start = 1; } else unescape(arg); - + *kind = k; return arg; } -void show_vars __P0 (void) -{ +void show_vars(void) +{ varnode *v; int i, type; ptr p = (ptr)0; - + PRINTF("#the following variables are defined:\n"); - + for (type = 0; !REAL_ERROR && type < 2; type++) { reverse_sortedlist((sortednode **)&sortednamed_vars[type]); v = sortednamed_vars[type]; @@ -1556,7 +1557,7 @@ void show_vars __P0 (void) ptrdel(p); } -void show_delaynode __P2 (delaynode *,p, int,in_or_at) +void show_delaynode(delaynode *p, int in_or_at) { long d; struct tm *s; @@ -1564,10 +1565,10 @@ void show_delaynode __P2 (delaynode *,p, int,in_or_at) update_now(); d = diff_vtime(&p->when, &now); - s = localtime((time_t *)&p->when.tv_sec); + s = localtime((time_t *)&p->when.tv_sec); /* s now points to a calendar struct */ if (in_or_at) { - + if (in_or_at == 2) { /* write time in buf */ (void)strftime(buf, BUFSIZE - 1, "%H%M%S", s); @@ -1585,12 +1586,12 @@ void show_delaynode __P2 (delaynode *,p, int,in_or_at) } } -void show_delays __P0 (void) +void show_delays(void) { delaynode *p; int n = (delays ? delays->next ? 2 : 1 : 0) + (dead_delays ? dead_delays->next ? 2 : 1 : 0); - + PRINTF("#%s delay label%s defined%c\n", n ? "the following" : "no", n == 1 ? " is" : "s are", n ? ':' : '.'); for (p = delays; p; p = p->next) @@ -1599,10 +1600,10 @@ void show_delays __P0 (void) show_delaynode(p, 0); } -void change_delaynode __P3 (delaynode **,p, char *,command, long,millisec) +void change_delaynode(delaynode **p, char *command, long millisec) { delaynode *m=*p; - + *p = m->next; m->when.tv_usec = (millisec % mSEC_PER_SEC) * uSEC_PER_mSEC; m->when.tv_sec = millisec / mSEC_PER_SEC; @@ -1626,11 +1627,11 @@ void change_delaynode __P3 (delaynode **,p, char *,command, long,millisec) } } -void new_delaynode __P3 (char *,name, char *,command, long,millisec) +void new_delaynode(char *name, char *command, long millisec) { vtime t; delaynode *node; - + t.tv_usec = (millisec % mSEC_PER_SEC) * uSEC_PER_mSEC; t.tv_sec = millisec / mSEC_PER_SEC; update_now(); @@ -1642,15 +1643,15 @@ void new_delaynode __P3 (char *,name, char *,command, long,millisec) } } -void show_history __P1 (int,count) +void show_history(int count) { int i = curline; - + if (!count) count = lines - 1; if (count >= MAX_HIST) count = MAX_HIST - 1; i -= count; if (i < 0) i += MAX_HIST; - + while (count) { if (hist[i]) { PRINTF("#%2d: %s\n", count, hist[i]); @@ -1660,11 +1661,11 @@ void show_history __P1 (int,count) } } -void exe_history __P1 (int,count) +void exe_history(int count) { int i = curline; char buf[BUFSIZE]; - + if (count >= MAX_HIST) count = MAX_HIST - 1; i -= count; diff --git a/cmd2.h b/cmd2.h index abc456a..96cb067 100644 --- a/cmd2.h +++ b/cmd2.h @@ -1,32 +1,32 @@ /* public things from cmd2.c */ -void show_aliases __P ((void)); -void parse_alias __P ((char *str)); - -void show_actions __P ((void)); -void show_prompts __P ((void)); -void parse_action __P ((char *str, int onprompt)); - -void show_attr_syntax __P ((void)); -void attr_string __P ((int attrcode, char *begin, char *end)); -int parse_attributes __P ((char *line)); -char *attr_name __P ((int attrcode)); -void show_marks __P ((void)); -void parse_mark __P ((char *str)); - -char *seq_name __P ((char *seq, int len)); -void show_binds __P ((char edit)); -void parse_bind __P ((char *arg)); -void parse_rebind __P ((char *arg)); - -char *redirect __P ((char *arg, ptr *pbuf, char *kind, char *name, int also_num, long *start, long *end)); - -void show_vars __P ((void)); -void show_delaynode __P ((delaynode *p, int in_or_at)); -void show_delays __P ((void)); -void change_delaynode __P ((delaynode **p, char *command, long millisec)); -void new_delaynode __P ((char *name, char *command, long millisec)); - -void show_history __P ((int count)); -void exe_history __P ((int count)); +void show_aliases(void); +void parse_alias(char *str); + +void show_actions(void); +void show_prompts(void); +void parse_action(char *str, int onprompt); + +void show_attr_syntax(void); +void attr_string(int attrcode, char *begin, char *end); +int parse_attributes(char *line); +char *attr_name(int attrcode); +void show_marks(void); +void parse_mark(char *str); + +char *seq_name(char *seq, int len); +void show_binds(char edit); +void parse_bind(char *arg); +void parse_rebind(char *arg); + +char *redirect(char *arg, ptr *pbuf, char *kind, char *name, int also_num, long *start, long *end); + +void show_vars(void); +void show_delaynode(delaynode *p, int in_or_at); +void show_delays(void); +void change_delaynode(delaynode **p, char *command, long millisec); +void new_delaynode(char *name, char *command, long millisec); + +void show_history(int count); +void exe_history(int count); diff --git a/defines.h b/defines.h index 79b15e7..33a96ad 100644 --- a/defines.h +++ b/defines.h @@ -23,64 +23,6 @@ # define init_random srand48 #endif -#ifdef __STDC__ - -# define VOLATILE volatile -# ifndef __P -# define __P(args) args -# endif -# define __P0(dummy) (void) -# define __P1(t1,a1) (t1 a1) -# define __P2(t1,a1,t2,a2) (t1 a1, t2 a2) -# define __P3(t1,a1,t2,a2,t3,a3) (t1 a1, t2 a2, t3 a3) -# define __P4(t1,a1,t2,a2,t3,a3,t4,a4) (t1 a1, t2 a2, t3 a3, t4 a4) -# define __P5(t1,a1,t2,a2,t3,a3,t4,a4,t5,a5) (t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) -# define __P6(t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6) (t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) -# define __P7(t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6,t7,a7) (t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) - -#else /* ! __STDC__ */ - -# define VOLATILE -# ifndef __P -# define __P(args) () -# endif -# define __P0(dummy) () -# define __P1(t1,a1) (a1) t1 a1; -# define __P2(t1,a1,t2,a2) (a1, a2) t1 a1; t2 a2; -# define __P3(t1,a1,t2,a2,t3,a3) (a1, a2, a3) t1 a1; t2 a2; t3 a3; -# define __P4(t1,a1,t2,a2,t3,a3,t4,a4) (a1, a2, a3, a4) t1 a1; t2 a2; t3 a3; t4 a4; -# define __P5(t1,a1,t2,a2,t3,a3,t4,a4,t5,a5) (a1, a2, a3, a4, a5) t1 a1; t2 a2; t3 a3; t4 a4; t5 a5; -# define __P6(t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6) (a1, a2, a3, a4, a5, a6) t1 a1; t2 a2; t3 a3; t4 a4; t5 a5; t6 a6; -# define __P7(t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6,t7,a7) (a1, a2, a3, a4, a5, a6, a7) t1 a1; t2 a2; t3 a3; t4 a4; t5 a5; t6 a6; t7 a7; - -#endif /* __STDC__ */ - -#ifdef __GNUC__ -# define INLINE static inline -#else -# define INLINE static -#endif - -#ifndef NULL -# define NULL ((void *)0) -#endif - -#ifndef LONG_MAX -# define LONG_MAX ( (long) ((~(unsigned long)0) >> 1) ) -#endif - -#ifndef LONG_MIN -# define LONG_MIN ( (long) (((~(unsigned long)0) >> 1) + 1) ) -#endif - -#ifndef INT_MAX -# define INT_MAX ( (int) ((~(unsigned int)0) >> 1) ) -#endif - -#ifndef INT_MIN -# define INT_MIN ( (int) (((~(unsigned int)0) >> 1) + 1) ) -#endif - #define uSEC_PER_SEC ((long)1000000) /* microseconds in a second */ #define mSEC_PER_SEC ((long)1000) /* milliseconds in a second */ #define uSEC_PER_mSEC ((long)1000) /* microseconds in a millisecond */ @@ -232,11 +174,11 @@ typedef unsigned char byte; typedef void (*function_any) (); /* generic function pointer */ -typedef void (*function_int) __P ((int i)); +typedef void (*function_int)(int i); typedef function_int function_signal; -typedef void (*function_str) __P ((char *arg)); +typedef void (*function_str)(char *arg); typedef struct timeval vtime; /* needs #include */ @@ -303,7 +245,7 @@ typedef struct triggernode { typedef triggernode actionnode; typedef triggernode promptnode; -typedef int (*function_sort) __P ((defnode *node1, defnode *node2)); +typedef int (*function_sort)(defnode *node1, defnode *node2); typedef struct keynode { struct keynode *next; diff --git a/edit.c b/edit.c index 8f4a052..7229f81 100644 --- a/edit.c +++ b/edit.c @@ -29,7 +29,7 @@ #include "eval.h" #include "log.h" -static void insert_string __P ((char *arg)); +static void insert_string(char *arg); /* history buffer */ char *hist[MAX_HIST]; /* saved history lines */ @@ -71,16 +71,16 @@ edit_function internal_functions[] = { {(char *)0, (function_str)0 } }; -int lookup_edit_name __P2 (char *,name, char **,arg) +int lookup_edit_name(char *name, char **arg) { int i, len, flen; char *fname, *extra = NULL; - + if ((fname = strchr(name, ' '))) len = fname - name; else len = strlen(name); - + for (i=1; (fname = internal_functions[i].name); i++) { flen = strlen(fname); if (flen == len && !strncmp(name, fname, flen)) { @@ -95,20 +95,20 @@ int lookup_edit_name __P2 (char *,name, char **,arg) return 0; } -int lookup_edit_function __P1 (function_str,funct) +int lookup_edit_function(function_str funct) { int i; function_str ffunct; - + for (i = 1; (ffunct = internal_functions[i].funct); i++) if (funct == ffunct) return i; - + return 0; } /* return pointer to any unterminated escape code at the end of s */ -static char *find_partial_esc __P1 (char *,s) +static char *find_partial_esc(char *s) { size_t len = strlen(s); char *end = s + len; @@ -126,7 +126,7 @@ static char *find_partial_esc __P1 (char *,s) * redisplay the prompt * assume cursor is at beginning of line */ -void draw_prompt __P0 (void) +void draw_prompt(void) { if (promptlen && prompt_status == 1) { char *esc, *pstr; @@ -154,11 +154,11 @@ void draw_prompt __P0 (void) /* * clear current input line (deleteprompt == 1 if to clear also prompt) * cursor is left right after the prompt. - * + * * since we do not expect data from the user at this point, * do not print edattrbeg now. */ -void clear_input_line __P1 (int,deleteprompt) +void clear_input_line(int deleteprompt) { /* * be careful: if prompt and/or input line have been erased from screen, @@ -167,7 +167,7 @@ void clear_input_line __P1 (int,deleteprompt) if ((edlen && line_status == 0) || (promptlen && prompt_status == 0 && deleteprompt)) { int newcol = deleteprompt ? 0 : col0; int realpos = line_status == 0 ? pos : (prompt_status == 0 ? 0 : -col0); - + tty_gotoxy_opt(CURCOL(realpos), CURLINE(realpos), newcol, line0); tty_puts(edattrend); if (line0 < lines - 1) @@ -187,7 +187,7 @@ void clear_input_line __P1 (int,deleteprompt) /* * clear input line, but do nothing else */ -void clear_line __P1 (char *,dummy) +void clear_line(char *dummy) { if (!edlen) return; @@ -201,15 +201,15 @@ void clear_line __P1 (char *,dummy) * Redraw the input line and put the cursor at the current position. * The cursor is assumed to be directly after the prompt. */ -void draw_input_line __P0 (void) +void draw_input_line(void) { int i, oldline0; - + if (line_status == 0 || linemode & LM_NOECHO) return; - + tty_puts(edattrbeg); - + if (edlen) { oldline0 = line0; if (edlen < cols_1 - col0) { @@ -218,7 +218,7 @@ void draw_input_line __P0 (void) tty_printf("%.*s", cols_1 - col0, edbuf); for (i = cols_1 - col0; i <= edlen; i += cols_1) { #ifdef BUG_ANSI - if (edattrbg) + if (edattrbg) tty_printf("%s\n%s%.*s", edattrend, edattrbeg, cols_1, edbuf + i); else #endif @@ -240,7 +240,7 @@ void draw_input_line __P0 (void) /* * redraw the input line */ -void redraw_line __P1 (char *,dummy) +void redraw_line(char *dummy) { clear_input_line(1); } @@ -248,7 +248,7 @@ void redraw_line __P1 (char *,dummy) /* * redraw the input line, clearing the prompt */ -void redraw_line_noprompt __P1 (char *,dummy) +void redraw_line_noprompt(char *dummy) { clear_input_line(0); tty_putc('\n'); @@ -260,32 +260,32 @@ void redraw_line_noprompt __P1 (char *,dummy) /* * GH: transpose two words to the left */ -void transpose_words __P1 (char *,dummy) +void transpose_words(char *dummy) { /* other refers to the word to the left, this is the one we are at */ - + int this_so, other_so, this_eo, other_eo; char buf[BUFSIZE]; int n; - + if (pos > 2) { - + this_eo = this_so = pos; /* optionally traceback to find a word */ while (this_so && strchr(DELIM, edbuf[this_so])) this_so--; - + /* now find where the current word ends */ while (this_eo < edlen && !strchr(DELIM, edbuf[this_eo])) this_eo++; - + /* found a word; now find its start */ while (this_so > 0 && !strchr(DELIM, edbuf[this_so - 1])) this_so--; - + if (this_so < 2) return; /* impossible that there's another word */ - + other_so = this_so - 1; while (other_so >= 0 && strchr(DELIM, edbuf[other_so])) other_so--; @@ -294,12 +294,12 @@ void transpose_words __P1 (char *,dummy) other_eo = other_so + 1; while (other_so > 0 && !strchr(DELIM, edbuf[other_so - 1])) other_so--; - + sprintf(buf, "%.*s%.*s%.*s", - this_eo - this_so, edbuf + this_so, + this_eo - this_so, edbuf + this_so, this_so - other_eo, edbuf + other_eo, other_eo - other_so, edbuf + other_so); - + input_moveto(other_so); for (n = 0; buf[n]; input_overtype_follow(buf[n++])) ; @@ -309,7 +309,7 @@ void transpose_words __P1 (char *,dummy) /* * transpose two characters to the left */ -void transpose_chars __P1 (char *,dummy) +void transpose_chars(char *dummy) { int i, j; char c; @@ -322,7 +322,7 @@ void transpose_chars __P1 (char *,dummy) i = pos - 2; } c = edbuf[j]; edbuf[j] = edbuf[i]; edbuf[i] = c; - + if (line_status == 0) { tty_gotoxy_opt(CURCOL(pos), CURLINE(pos), CURCOL(i), CURLINE(i)); tty_putc(edbuf[i]); @@ -340,12 +340,12 @@ void transpose_chars __P1 (char *,dummy) /* * erase everything to the end of line */ -void kill_to_eol __P1 (char *,dummy) +void kill_to_eol(char *dummy) { if (line_status == 0) { - if (edattrbg) + if (edattrbg) tty_printf("%s%s", edattrend, tty_clreoln); - else + else tty_puts(tty_clreoln); if (CURLINE(edlen) > CURLINE(pos)) { tty_printf("\n%s", tty_clreoscr); @@ -360,7 +360,7 @@ void kill_to_eol __P1 (char *,dummy) /* * move cursor to end of line */ -void end_of_line __P1 (char *,dummy) +void end_of_line(char *dummy) { input_moveto(edlen); } @@ -368,7 +368,7 @@ void end_of_line __P1 (char *,dummy) /* * move cursor to beginning of line */ -void begin_of_line __P1 (char *,dummy) +void begin_of_line(char *dummy) { input_moveto(0); } @@ -376,7 +376,7 @@ void begin_of_line __P1 (char *,dummy) /* * delete a character to the right */ -void del_char_right __P1 (char *,dummy) +void del_char_right(char *dummy) { input_delete_nofollow_chars(1); } @@ -384,7 +384,7 @@ void del_char_right __P1 (char *,dummy) /* * delete a character to the left */ -void del_char_left __P1 (char *,dummy) +void del_char_left(char *dummy) { if (pos) { input_moveto(pos-1); @@ -395,7 +395,7 @@ void del_char_left __P1 (char *,dummy) /* * move a line into history, but don't do anything else */ -void to_history __P1 (char *,dummy) +void to_history(char *dummy) { if (!edlen) return; @@ -410,7 +410,7 @@ void to_history __P1 (char *,dummy) * put string in history at current position * (string is assumed to be trashable) */ -void put_history __P1 (char *,str) +void put_history(char *str) { char *p; if (hist[curline]) free(hist[curline]); @@ -418,14 +418,14 @@ void put_history __P1 (char *,str) errmsg("malloc"); return; } - + if (++curline == MAX_HIST) curline = 0; - + /* split into words and put into completion list */ - for (p = strtok(str, DELIM); p; + for (p = strtok(str, DELIM); p; p = strtok(NULL, DELIM)) { - if (strlen(p) >= MIN_WORDLEN && + if (strlen(p) >= MIN_WORDLEN && p[0] != '#') /* no commands/short words */ put_word(p); } @@ -434,7 +434,7 @@ void put_history __P1 (char *,str) /* * move a node before wordindex, i.e. make it the last word */ -static void demote_word __P1 (int,i) +static void demote_word(int i) { words[words[i].prev].next = words[i].next; words[words[i].next].prev = words[i].prev; @@ -447,7 +447,7 @@ static struct { char **words; } static_words; -static int compl_next_word __P1 (int,i) +static int compl_next_word(int i) { if (i < 0) { go_static: @@ -464,7 +464,7 @@ static int compl_next_word __P1 (int,i) return i; } -static char *compl_get_word __P1 (int,i) +static char *compl_get_word(int i) { return i < 0 ? static_words.words[-i - 1] : words[i].word; } @@ -472,7 +472,7 @@ static char *compl_get_word __P1 (int,i) /* * match and complete a word referring to the word list */ -void complete_word __P1 (char *,dummy) +void complete_word(char *dummy) { /* * GH: rewritten to allow circulating through history with @@ -482,12 +482,12 @@ void complete_word __P1 (char *,dummy) * comp_len length of current completition * root_len length of the root word (before the completition) * root start of the root word - */ - + */ + static int curr_word, comp_len = 0, root_len = 0; char *root, *p; int k, n; - + /* find word start */ if (last_edit_cmd == (function_any)complete_word && comp_len) { k = comp_len; @@ -501,9 +501,9 @@ void complete_word __P1 (char *,dummy) root_len = pos - n; } root = edbuf + n; comp_len = 0; - + /* k = chars to delete, n = position of starting word */ - + /* scan word list for next match */ while ((p = compl_get_word(curr_word = compl_next_word(curr_word)))) { if (!strncasecmp(p, root, root_len) && @@ -519,12 +519,12 @@ void complete_word __P1 (char *,dummy) } if (k > 0) input_delete_nofollow_chars(k); - + /* delete duplicate instances of the word */ if (p && curr_word >= 0 && !(words[k = curr_word].flags & WORD_UNIQUE)) { words[k].flags |= WORD_UNIQUE; - p = words[k].word; + p = words[k].word; n = words[k].next; while (words[k = n].word) { n = words[k].next; @@ -544,16 +544,16 @@ void complete_word __P1 (char *,dummy) * match and complete entire lines backwards in history * GH: made repeated complete_line cycle through history */ -void complete_line __P1 (char *,dummy) +void complete_line(char *dummy) { static int curr_line = MAX_HIST-1, root_len = 0, first_line = 0; int i; - + if (last_edit_cmd != (function_any)complete_line) { root_len = edlen; first_line = curr_line = curline; } - + for (i = curr_line - 1; i != curr_line; i--) { if (i < 0) i = MAX_HIST - 1; if (i == first_line) @@ -579,7 +579,7 @@ void complete_line __P1 (char *,dummy) * GH: word history handling stolen from cancan 2.6.3a */ -static void default_completions __P0 (void) +static void default_completions(void) { char buf[BUFSIZE]; cmdstruct *p; @@ -598,7 +598,7 @@ static void default_completions __P0 (void) words[MAX_WORDS - 1].next = 0; } -void put_static_word __P1 (char *,s) +void put_static_word(char *s) { if (static_words.used >= static_words.size) { do { @@ -619,7 +619,7 @@ void put_static_word __P1 (char *,s) /* * put word in word completion ring */ -void put_word __P1 (char *,s) +void put_word(char *s) { int r = wordindex; if (!(words[r].word = my_strdup(s))) { @@ -630,16 +630,16 @@ void put_word __P1 (char *,s) r = words[r].prev; demote_word(r); wordindex = r; - if (words[r].word) { - free(words[r].word); - words[r].word = 0; + if (words[r].word) { + free(words[r].word); + words[r].word = 0; } } /* * GH: set delimeters[DELIM_CUSTOM] */ -void set_custom_delimeters __P1 (char *,s) +void set_custom_delimeters(char *s) { char *old = delim_list[DELIM_CUSTOM]; if (!(delim_list[DELIM_CUSTOM] = my_strdup(s))) @@ -655,10 +655,10 @@ void set_custom_delimeters __P1 (char *,s) /* * enter a line */ -void enter_line __P1 (char *,dummy) +void enter_line(char *dummy) { char *p; - + if (line_status == 0) input_moveto(edlen); else { @@ -667,21 +667,21 @@ void enter_line __P1 (char *,dummy) draw_input_line(); } PRINTF("%s\n", edattrend); - + line0 = CURLINE(edlen); if (line0 < lines - 1) line0++; - + if (recordfile) fprintf(recordfile, "%s\n", edbuf); - + col0 = error = pos = line_status = 0; - + if (!*edbuf || (verbatim && *edbuf != '#')) tcp_write(tcp_fd, edbuf); else - parse_user_input(edbuf, 1); + parse_user_input(edbuf, 1); history_done = 0; - + /* don't put identical lines in history, nor empty ones */ p = hist[curline ? curline - 1 : MAX_HIST - 1]; if (!p || (edlen > 0 && strcmp(edbuf, p))) @@ -702,7 +702,7 @@ void enter_line __P1 (char *,dummy) /* * move one word forward */ -void next_word __P1 (char *,dummy) +void next_word(char *dummy) { int i; for (i = pos; edbuf[i] && !isalnum(edbuf[i]); i++) @@ -715,7 +715,7 @@ void next_word __P1 (char *,dummy) /* * move one word backward */ -void prev_word __P1 (char *,dummy) +void prev_word(char *dummy) { int i; for (i = pos; i && !isalnum(edbuf[i - 1]); i--) @@ -728,7 +728,7 @@ void prev_word __P1 (char *,dummy) /* * delete word to the right */ -void del_word_right __P1 (char *,dummy) +void del_word_right(char *dummy) { int i; for (i = pos; edbuf[i] && !isalnum(edbuf[i]); i++) @@ -741,7 +741,7 @@ void del_word_right __P1 (char *,dummy) /* * delete word to the left */ -void del_word_left __P1 (char *,dummy) +void del_word_left(char *dummy) { int i; for (i = pos; i && !isalnum(edbuf[i - 1]); i--) @@ -756,11 +756,11 @@ void del_word_left __P1 (char *,dummy) /* * GH: make word upcase */ -void upcase_word __P1 (char *,dummy) +void upcase_word(char *dummy) { int opos = pos; int npos = pos; - + if (last_edit_cmd == (function_any)upcase_word) npos = 0; else { @@ -777,7 +777,7 @@ void upcase_word __P1 (char *,dummy) /* * GH: make word downcase */ -void downcase_word __P1 (char *,dummy) +void downcase_word(char *dummy) { int opos = pos; int npos = pos; @@ -799,7 +799,7 @@ void downcase_word __P1 (char *,dummy) /* * get previous line from history list */ -void prev_line __P1 (char *,dummy) +void prev_line(char *dummy) { int i = pickline - 1; if (i < 0) i = MAX_HIST - 1; @@ -824,7 +824,7 @@ void prev_line __P1 (char *,dummy) /* * get next line from history list */ -void next_line __P1 (char *,dummy) +void next_line(char *dummy) { int i = pickline + 1; if (i == MAX_HIST) i = 0; @@ -849,7 +849,7 @@ void next_line __P1 (char *,dummy) /* * move one char backward */ -void prev_char __P1 (char *,dummy) +void prev_char(char *dummy) { input_moveto(pos-1); } @@ -857,7 +857,7 @@ void prev_char __P1 (char *,dummy) /* * move one char forward */ -void next_char __P1 (char *,dummy) +void next_char(char *dummy) { input_moveto(pos+1); } @@ -865,7 +865,7 @@ void next_char __P1 (char *,dummy) /* * Flash cursor at parentheses that matches c inserted before current pos */ -static void flashparen __P1 (char,c) +static void flashparen(char c) { int lev, i; if (line_status != 0) @@ -893,7 +893,7 @@ static void flashparen __P1 (char,c) /* * put cursor back where it belongs */ -void putbackcursor __P0 (void) +void putbackcursor(void) { if (line_status == 0) tty_gotoxy_opt(CURCOL(excursion), CURLINE(excursion), CURCOL(pos), CURLINE(pos)); @@ -903,7 +903,7 @@ void putbackcursor __P0 (void) /* * insert a typed character on screen (if it is printable) */ -void insert_char __P1 (char,c) +void insert_char(char c) { if (((c & 0x80) || (c >= ' ' && c <= '~')) && edlen < BUFSIZE - 2) { if (flashback) putbackcursor(); @@ -913,18 +913,18 @@ void insert_char __P1 (char,c) } } -static void insert_string __P1 (char *,arg) +static void insert_string(char *arg) { char buf[BUFSIZE]; int len; - + if (!arg || !*arg) return; - + my_strncpy(buf, arg, BUFSIZE-1); unescape(buf); len = strlen(buf); - + if (len > 1) { if (flashback) putbackcursor(); input_insert_follow_chars(buf, len); @@ -935,25 +935,25 @@ static void insert_string __P1 (char *,arg) /* * execute string as if typed */ -void key_run_command __P1 (char *,cmd) +void key_run_command(char *cmd) { clear_input_line(opt_compact && !opt_keyecho); if (opt_keyecho) { tty_printf("%s%s%s\n", edattrbeg, cmd, edattrend); } else if (!opt_compact) tty_putc('\n'); - + status(1); error = 0; - + if (recordfile) fprintf(recordfile, "%s\n", edbuf); - + parse_instruction(cmd, 1, 0, 1); history_done = 0; } -void edit_bootstrap __P0 (void) +void edit_bootstrap(void) { default_completions(); } diff --git a/edit.h b/edit.h index e49cea2..b3b5a50 100644 --- a/edit.h +++ b/edit.h @@ -10,9 +10,9 @@ typedef struct { extern edit_function internal_functions[]; -/* +/* * GH: completion list, stolen from cancan 2.6.3a - * + * * words[wordindex] is where the next word will go (always empty) * words[wordindex].prev is last (least interesting) * words[wordindex].next is 2nd (first to search for completion) @@ -32,44 +32,44 @@ extern wordnode words[MAX_WORDS]; extern int wordindex; /* public function declarations */ -void edit_bootstrap __P ((void)); +void edit_bootstrap(void); -int lookup_edit_name __P ((char *name, char **arg)); -int lookup_edit_function __P ((function_str funct)); -void draw_prompt __P ((void)); -void clear_input_line __P ((int deleteprompt)); -void draw_input_line __P ((void)); -void redraw_line __P ((char *dummy)); -void redraw_line_noprompt __P ((char *dummy)); -void transpose_words __P ((char *dummy)); -void transpose_chars __P ((char *dummy)); -void kill_to_eol __P ((char *dummy)); -void end_of_line __P ((char *dummy)); -void begin_of_line __P ((char *dummy)); -void del_char_right __P ((char *dummy)); -void del_char_left __P ((char *dummy)); -void to_history __P ((char *dummy)); -void put_history __P ((char *str)); -void complete_word __P ((char *dummy)); -void complete_line __P ((char *dummy)); -void put_word __P ((char *s)); -void put_static_word __P ((char *s)); -void set_custom_delimeters __P ((char *s)); -void to_input_line __P ((char *str)); -void clear_line __P ((char *dummy)); -void enter_line __P ((char *dummy)); -void putbackcursor __P ((void)); -void insert_char __P ((char c)); -void next_word __P ((char *dummy)); -void prev_word __P ((char *dummy)); -void del_word_right __P ((char *dummy)); -void del_word_left __P ((char *dummy)); -void upcase_word __P ((char *dummy)); -void downcase_word __P ((char *dummy)); -void prev_line __P ((char *dummy)); -void next_line __P ((char *dummy)); -void prev_char __P ((char *dummy)); -void next_char __P ((char *dummy)); -void key_run_command __P ((char *cmd)); +int lookup_edit_name(char *name, char **arg); +int lookup_edit_function(function_str funct); +void draw_prompt(void); +void clear_input_line(int deleteprompt); +void draw_input_line(void); +void redraw_line(char *dummy); +void redraw_line_noprompt(char *dummy); +void transpose_words(char *dummy); +void transpose_chars(char *dummy); +void kill_to_eol(char *dummy); +void end_of_line(char *dummy); +void begin_of_line(char *dummy); +void del_char_right(char *dummy); +void del_char_left(char *dummy); +void to_history(char *dummy); +void put_history(char *str); +void complete_word(char *dummy); +void complete_line(char *dummy); +void put_word(char *s); +void put_static_word(char *s); +void set_custom_delimeters(char *s); +void to_input_line(char *str); +void clear_line(char *dummy); +void enter_line(char *dummy); +void putbackcursor(void); +void insert_char(char c); +void next_word(char *dummy); +void prev_word(char *dummy); +void del_word_right(char *dummy); +void del_word_left(char *dummy); +void upcase_word(char *dummy); +void downcase_word(char *dummy); +void prev_line(char *dummy); +void next_line(char *dummy); +void prev_char(char *dummy); +void next_char(char *dummy); +void key_run_command(char *cmd); #endif /* _EDIT_H_ */ diff --git a/eval.c b/eval.c index e349666..8673c65 100644 --- a/eval.c +++ b/eval.c @@ -2,7 +2,7 @@ * eval.c -- functions for builtin calculator * * (created: Massimiliano Ghilardi (Cosmos), Jan 15th, 1995) - * + * * Copyright (C) 1998 by Massimiliano Ghilardi * * This program is free software; you can redistribute it and/or modify @@ -125,9 +125,9 @@ char *error_msg[] = { operator_list op_list[] = { { 0, 0, 0, "", null }, - + { 1, LEFT, BINARY, ",", comma }, - + { 2, RIGHT, BINARY, "=", eq }, { 2, RIGHT, BINARY, "||=", or_or_eq }, { 2, RIGHT, BINARY, "^^=", xor_xor_eq }, @@ -142,36 +142,36 @@ operator_list op_list[] = { { 2, RIGHT, BINARY, "*=", times_eq }, { 2, RIGHT, BINARY, "/=", div_eq }, { 2, RIGHT, BINARY, "%=", ampersand_eq }, - + { 3, LEFT, BINARY, "||", or_or }, - + { 4, LEFT, BINARY, "^^", xor_xor }, - + { 5, LEFT, BINARY, "&&", and_and }, - + { 6, LEFT, BINARY, "|", or }, - + { 7, LEFT, BINARY, "^", xor }, - + { 8, LEFT, BINARY, "&", and }, - + { 9, LEFT, BINARY, "<", less }, { 9, LEFT, BINARY, "<=", less_eq }, { 9, LEFT, BINARY, ">", greater }, { 9, LEFT, BINARY, ">=", greater_eq }, { 9, LEFT, BINARY, "==", eq_eq }, { 9, LEFT, BINARY, "!=", not_eq }, - + {10, LEFT, BINARY, "<<", lshift }, {10, LEFT, BINARY, ">>", rshift }, - + {11, LEFT, BINARY, "+", plus }, {11, LEFT, BINARY, "-", minus }, - + {12, LEFT, BINARY, "*", times }, {12, LEFT, BINARY, "/", division }, {12, LEFT, BINARY, "%", ampersand }, - + {14, LEFT, BINARY, ":<", colon_less }, {14, LEFT, BINARY, ":>", colon_greater }, {14, LEFT, BINARY, "<:", less_colon }, @@ -183,12 +183,12 @@ operator_list op_list[] = { {14, LEFT, BINARY, ":", colon }, {14, LEFT, BINARY, ".", point }, {14, LEFT, BINARY, "?", question }, - + { 0, 0, 0, "", another_null }, - + { 0, RIGHT, PRE_UNARY, "(", left_paren }, { 0, RIGHT, POST_UNARY, ")", right_paren }, - + {13, RIGHT, PRE_UNARY, "!", not }, {13, RIGHT, PRE_UNARY, "~", tilde }, {13, RIGHT, PRE_UNARY, "++", pre_plus_plus }, @@ -199,15 +199,15 @@ operator_list op_list[] = { {13, RIGHT, PRE_UNARY, "%", print }, {13, RIGHT, PRE_UNARY, "rand", _random_ }, {13, RIGHT, PRE_UNARY, "attr", _attr_ }, - + {14, LEFT, PRE_UNARY, ":?", colon_question }, {14, LEFT, PRE_UNARY, ".?", point_question }, - + {15, RIGHT, PRE_UNARY, "+", pre_plus }, {15, RIGHT, PRE_UNARY, "-", pre_minus }, {15, RIGHT, PRE_UNARY, "@", a_circle }, {15, RIGHT, PRE_UNARY, "$", dollar }, - + { 0, 0, PRE_UNARY, "", pre_null }, { 0, 0, POST_UNARY, "", post_null } }; @@ -217,7 +217,7 @@ static char *line; static int depth; int error; -void print_error __P1 (int,err_num) +void print_error(int err_num) { clear_input_line(1); if (error == NO_MEM_ERROR) { @@ -227,7 +227,7 @@ void print_error __P1 (int,err_num) tty_printf("#error: %s.\n", error_msg[err_num]); } -static int push_op __P1 (operator *,op) +static int push_op(operator *op) { if (stk.curr_op=0) { *op=stk.op[stk.curr_op--]; @@ -251,12 +251,12 @@ static int pop_op __P1 (operator *,op) } } -static int push_obj __P1 (object *,obj) +static int push_obj(object *obj) { object *tmp; - + int curr=stk.curr_obj; - + if (curr=0) { tmp = stk.obj + curr; stk.curr_obj--; @@ -286,19 +286,19 @@ static int pop_obj __P1 (object *,obj) } } -static int check_operator __P3 (char,side, operator *,op, int,mindepth) +static int check_operator(char side, operator *op, int mindepth) { int i, max, len; operator match; char *name, c, d; - + if (!(c=*line) || c == CMDSEP) { *op = side==BINARY ? null : side==LEFT ? pre_null : post_null; return 1; } else if ((c=='$' || c=='@') && (d=line[1]) && (isalpha(d) || d=='_')) return 0; /* Danger! found named variable */ - + else if (side==LEFT && c=='(') { line++; depth++; @@ -320,7 +320,7 @@ static int check_operator __P3 (char,side, operator *,op, int,mindepth) *op=post_null; return 1; } - + for (max=match=0, i=(side==BINARY ? 1 : LOWEST_UNARY_CODE); *(name = op_list[i].name); i++) if ((len=strlen(name)) > max && @@ -329,7 +329,7 @@ static int check_operator __P3 (char,side, operator *,op, int,mindepth) match=op_list[i].code; max=len; } - + if (match) { *op=match; line+=max; @@ -343,11 +343,11 @@ static int check_operator __P3 (char,side, operator *,op, int,mindepth) return 0; } -static int check_object __P1 (object *,obj) +static int check_object(object *obj) { long i=0, base = 10; char c, *end, digit; - + if (c=*line, c == '#' || isdigit(c)) { while (c == '#' || isalnum(c)) { digit = !!isdigit(c); @@ -390,7 +390,7 @@ static int check_object __P1 (object *,obj) } else if ((c=='$' || c=='@') && (c=line[1]) && (isalpha(c) || c=='_')) { varnode *named_var; /* Found named variable */ - + if (*(line++) == '@') { i = 0; obj->type = TYPE_NUM_VAR; @@ -444,11 +444,11 @@ static int check_object __P1 (object *,obj) } else error=NO_VALUE_ERROR; - + return (int)i; } -static void check_delete __P1 (object *,obj) +static void check_delete(object *obj) { if (obj->type==TYPE_TXT && obj->txt) { ptrdel(obj->txt); @@ -456,7 +456,7 @@ static void check_delete __P1 (object *,obj) } } -static int exe_op __P1 (operator *,op) +static int exe_op(operator *op) { object o1, o2, *p=NULL; long *l, rnd, delta; @@ -464,9 +464,9 @@ static int exe_op __P1 (operator *,op) int srclen; char *ssrc, *tmp; int ret=0, i=0, j=0, danger=0; - + o1.txt = o2.txt = NULL; - + switch ((int)*op) { case (int)comma: if (pop_obj(&o2) && pop_obj(&o1)); @@ -478,12 +478,12 @@ static int exe_op __P1 (operator *,op) case (int)eq: if (pop_obj(&o2) && pop_obj(&o1)); else if (REAL_ERROR) break; - + if (o2.type==TYPE_NUM_VAR) { o2.num = *VAR[o2.num].num; o2.type = TYPE_NUM; } - + if (o1.type==TYPE_NUM_VAR && o2.type==TYPE_NUM) { *VAR[o1.num].num = o2.num; p=&o2; @@ -491,13 +491,13 @@ static int exe_op __P1 (operator *,op) } else if (o1.type==TYPE_TXT_VAR && (o2.type==TYPE_TXT || o2.type==TYPE_TXT_VAR)) { - + if (o2.type==TYPE_TXT_VAR) { o2.txt = ptrdup(*VAR[o2.num].str); if (REAL_ERROR) break; o2.type=TYPE_TXT; } - + *VAR[o1.num].str = ptrcpy(*VAR[o1.num].str, o2.txt); if (REAL_ERROR) break; p=&o2; @@ -521,15 +521,15 @@ static int exe_op __P1 (operator *,op) case (int)ampersand_eq: if (pop_obj(&o2) && pop_obj(&o1)); else if (REAL_ERROR) break; - + if (o2.type==TYPE_NUM_VAR) { o2.num = *VAR[o2.num].num; o2.type = TYPE_NUM; } - + if (o1.type==TYPE_NUM_VAR && o2.type==TYPE_NUM) { l=VAR[o1.num].num; - + switch ((int)*op) { case (int)or_or_eq: if ( o2.num) *l = 1; else *l = !!*l; break; case (int)xor_xor_eq:if ( o2.num) *l = !*l; else *l = !!*l; break; @@ -552,18 +552,18 @@ static int exe_op __P1 (operator *,op) } else if (*op==plus_eq && o1.type==TYPE_TXT_VAR && (o2.type==TYPE_TXT || o2.type==TYPE_TXT_VAR)) { - + if (o2.type==TYPE_TXT) src=o2.txt; else src=*VAR[o2.num].str; - + *VAR[o1.num].str = ptrcat(*VAR[o1.num].str, src); check_delete(&o2); - + dst = ptrdup(*VAR[o1.num].str); if (REAL_ERROR) break; - + o1.type=TYPE_TXT; o1.txt=dst; p=&o1; @@ -571,12 +571,12 @@ static int exe_op __P1 (operator *,op) } else if (*op==times_eq && o1.type==TYPE_TXT_VAR && (o2.type==TYPE_NUM || o2.type==TYPE_NUM_VAR)) { - + if (o2.type==TYPE_NUM_VAR) { o2.num = *VAR[o2.num].num; o2.type = TYPE_NUM; } - + if (o2.num < 0) error = OUT_RANGE_ERROR; else if (o2.num == 0) @@ -590,11 +590,11 @@ static int exe_op __P1 (operator *,op) for (n = 1; !error && n 0 && o1.type==TYPE_TXT_VAR) { o1.txt = ptrdup(*VAR[o1.num].str); if (REAL_ERROR) break; } dst = o1.txt; - + if (o2.num < 0) error = OUT_RANGE_ERROR; else if (o2.num == 0) @@ -735,7 +735,7 @@ static int exe_op __P1 (operator *,op) } check_delete(&o2); if (REAL_ERROR) break; - + o1.type=TYPE_TXT; o1.txt=dst; p=&o1; @@ -756,22 +756,22 @@ static int exe_op __P1 (operator *,op) case (int)point: if (pop_obj(&o2) && pop_obj(&o1)); else if (REAL_ERROR) break; - + if (o2.type==TYPE_NUM_VAR) { o2.num = *VAR[o2.num].num; o2.type = TYPE_NUM; } - + if ((o1.type!=TYPE_TXT_VAR && o1.type!=TYPE_TXT) || o2.type!=TYPE_NUM) { error=SYNTAX_ERROR; break; } - + if (o2.num<=0) { error=OUT_RANGE_ERROR; break; } - + if (o1.type==TYPE_TXT_VAR) { o1.type=TYPE_TXT; o1.txt=dst=NULL; @@ -782,7 +782,7 @@ static int exe_op __P1 (operator *,op) src=dst=start=o1.txt; danger=1; } - + if (!src) { /* src == empty string. just return it */ check_delete(&o2); @@ -791,10 +791,10 @@ static int exe_op __P1 (operator *,op) p=&o1; ret=1; break; } - + srclen = ptrlen(src); ssrc = ptrdata(src); - + switch ((int)*op) { case (int)colon_less: while (o2.num && srclen) { @@ -806,7 +806,7 @@ static int exe_op __P1 (operator *,op) i=tmp-ssrc, o2.num--, ssrc+=i, j+=i, srclen-=i; else break; } - + if (o2.num) { /* end of valid string before the n-th word */ if (danger) ; @@ -834,7 +834,7 @@ static int exe_op __P1 (operator *,op) srclen--, ssrc++; } else break; } - + if (o2.num) /* end of valid string before the n-th word */ ptrzero(dst); else { @@ -857,7 +857,7 @@ static int exe_op __P1 (operator *,op) o2.num--, srclen=tmp-ssrc; else break; } - + if (o2.num) /* end of valid string before the n-th word */ ptrzero(dst); else @@ -873,7 +873,7 @@ static int exe_op __P1 (operator *,op) o2.num--, srclen=tmp-ssrc; else break; } - + if (o2.num) /* end of valid string before the n-th word */ dst = ptrcpy(dst, start); else @@ -920,7 +920,7 @@ static int exe_op __P1 (operator *,op) case (int)point_question: if (pop_obj(&o1)); else if (REAL_ERROR) break; - + if (o1.type==TYPE_TXT) src=o1.txt; else if (o1.type==TYPE_TXT_VAR) @@ -938,10 +938,10 @@ static int exe_op __P1 (operator *,op) ret=1; break; } - + ssrc = ptrdata(src); srclen = ptrlen(src); - + if (*op==colon_question) { o1.num = 0; /* skip span of multiple word delimeters */ @@ -962,7 +962,7 @@ static int exe_op __P1 (operator *,op) } else o1.num=srclen; - + check_delete(&o1); o1.type=TYPE_NUM; p=&o1; @@ -971,21 +971,21 @@ static int exe_op __P1 (operator *,op) case (int)question: if (pop_obj(&o2) && pop_obj(&o1)); else if (REAL_ERROR) break; - + if (o1.type==TYPE_TXT) src = o1.txt; else if (o1.type==TYPE_TXT_VAR) src = *VAR[o1.num].str; - else + else error = SYNTAX_ERROR; - + if (o2.type==TYPE_TXT) dst = o2.txt; else if (o2.type==TYPE_TXT_VAR) dst = *VAR[o2.num].str; - else + else error = SYNTAX_ERROR; - + if (!error) { if ((ssrc = ptrfind(src, dst))) i = (int)(ssrc - ptrdata(src)) + 1; @@ -1002,12 +1002,12 @@ static int exe_op __P1 (operator *,op) case (int)another_null: if (pop_obj(&o2) && pop_obj(&o1)); else if (REAL_ERROR) break; - + check_delete(&o1); check_delete(&o2); - + o1.type=0, o1.num=0, o1.txt=NULL; - + p=&o1; ret=1; break; @@ -1017,12 +1017,12 @@ static int exe_op __P1 (operator *,op) case (int)right_paren: if (pop_op(op)); else if (REAL_ERROR) break; - + if (*op!=left_paren) error=MISMATCH_PAREN_ERROR; else ret=1; - + break; case (int)_random_: #ifdef NO_RANDOM @@ -1033,10 +1033,10 @@ static int exe_op __P1 (operator *,op) case (int)pre_minus: case (int)not: case (int)tilde: - + if (pop_obj(&o1)); else if (REAL_ERROR) break; - + if (o1.type==TYPE_NUM_VAR) { o1.num = *VAR[o1.num].num; o1.type = TYPE_NUM; @@ -1070,16 +1070,16 @@ static int exe_op __P1 (operator *,op) case (int)_attr_: if (pop_obj(&o1)); else if (REAL_ERROR) break; - + if (o1.type==TYPE_TXT_VAR) { o1.txt = ptrdup(*VAR[o1.num].str); if (REAL_ERROR) break; o1.type = TYPE_TXT; - } - + } + if (o1.type==TYPE_TXT) { char dummy[CAPLEN]; /* just because attr_string must write somewhere */ - + if (o1.txt) i = parse_attributes(ptrdata(o1.txt)); else @@ -1097,17 +1097,17 @@ static int exe_op __P1 (operator *,op) } else error=NO_STRING_ERROR; break; - + case (int)star: case (int)print: if (pop_obj(&o1)); else if (REAL_ERROR) break; - + if (o1.type==TYPE_NUM_VAR) o1.num = *VAR[o1.num].num; else if (o1.type==TYPE_TXT_VAR) o1.txt = *VAR[o1.num].str; - + if (o1.type==TYPE_NUM || o1.type==TYPE_NUM_VAR) { o1.txt = NULL; if (*op==print) { @@ -1138,7 +1138,7 @@ static int exe_op __P1 (operator *,op) o1.type = TYPE_NUM; p=&o1; ret=1; } - else + else error=SYNTAX_ERROR; break; case (int)pre_plus_plus: @@ -1147,11 +1147,11 @@ static int exe_op __P1 (operator *,op) case (int)post_minus_minus: if (pop_obj(&o1)); else if (REAL_ERROR) break; - + if (o1.type==TYPE_NUM_VAR) { l=VAR[o1.num].num; o1.type=TYPE_NUM; - + if (*op==pre_plus_plus) o1.num=++*l; else if (*op==post_plus_plus) @@ -1160,7 +1160,7 @@ static int exe_op __P1 (operator *,op) o1.num=--*l; else o1.num=(*l)--; - + p=&o1; ret=1; } @@ -1171,36 +1171,36 @@ static int exe_op __P1 (operator *,op) case (int)dollar: if (pop_obj(&o1)); else if (REAL_ERROR) break; - + if (*op == dollar) delta = 1; else delta = 0; - + if (o1.type==TYPE_NUM_VAR) { o1.type=TYPE_NUM; o1.num=*VAR[o1.num].num; } - + if (o1.type==TYPE_NUM) { if (o1.num<-NUMVAR || o1.num>=NUMPARAM) { error=OUT_RANGE_ERROR; break; } - o1.type= delta ? TYPE_TXT_VAR : TYPE_NUM_VAR; + o1.type= delta ? TYPE_TXT_VAR : TYPE_NUM_VAR; p=&o1; ret=1; } else { varnode *named_var; char c; - + if (o1.type==TYPE_TXT_VAR) o1.txt = *VAR[o1.num].str; else if (o1.type!=TYPE_TXT) { error=SYNTAX_ERROR; break; } - + if (o1.txt && (tmp=ptrdata(o1.txt)) && ((c=*tmp) == '_' || isalpha(c))) { tmp++; @@ -1211,7 +1211,7 @@ static int exe_op __P1 (operator *,op) error=INVALID_NAME_ERROR; break; } - + if (!(named_var = *lookup_varnode(ptrdata(o1.txt), delta))) { named_var = add_varnode(ptrdata(o1.txt), delta); if (REAL_ERROR) @@ -1221,7 +1221,7 @@ static int exe_op __P1 (operator *,op) ? '$' : '@', ptrdata(o1.txt)); } } - o1.type= delta ? TYPE_TXT_VAR : TYPE_NUM_VAR; + o1.type= delta ? TYPE_TXT_VAR : TYPE_NUM_VAR; p=&o1; ret=1; } @@ -1233,12 +1233,12 @@ static int exe_op __P1 (operator *,op) default: break; } - + if (REAL_ERROR) { check_delete(&o2); check_delete(&o1); } - + if (!REAL_ERROR) { if (!ret) error=NOT_DONE_ERROR; @@ -1249,39 +1249,39 @@ static int exe_op __P1 (operator *,op) check_delete(p); } } - + if (REAL_ERROR) return 0; - + return ret; } -static int whichfirst __P2 (operator *,op1, operator *,op2) +static int whichfirst(operator *op1, operator *op2) { int p1, p2; - + p1=op_list[*op1].priority; p2=op_list[*op2].priority; if (p1!=p2) return p1>p2 ? -1 : 1; - + p1 = op_list[*op1].assoc == LEFT; return p1 ? -1 : 1; } -static int compare_and_unload __P1 (operator *,op) +static int compare_and_unload(operator *op) { int first=0; operator new; - + if (REAL_ERROR || stk.curr_op<0) return 1; - + while (stk.curr_op>=0 && pop_op(&new) && !REAL_ERROR && (first = whichfirst(&new, op)) == -1 && (first = 0, exe_op(&new)) ); - + if (!REAL_ERROR) { if (!first) return 1; @@ -1291,49 +1291,49 @@ static int compare_and_unload __P1 (operator *,op) return 0; } -static int _eval __P1 (int,mindepth) +static int _eval(int mindepth) { operator op; object obj; char endreached = 0; - + for (;;) { memzero(&obj, sizeof(obj)); - + while (*line==' ') line++; if (!*line || *line == CMDSEP) endreached = 1; - + while (check_operator(LEFT, &op, mindepth) && push_op(&op) && !endreached) { - + if (error) return 0; while (*line==' ') line++; if (!*line || *line == CMDSEP) endreached = 1; } - + if (!endreached && check_object(&obj) && push_obj(&obj)); else if (error) return 0; - + while (*line==' ') line++; if (!*line || *line == CMDSEP) endreached = 1; - + while (check_operator(RIGHT, &op, mindepth) && compare_and_unload(&op) && exe_op(&op) && depth>=mindepth && !endreached) { - + if (error) return 0; while (*line==' ') line++; if (!*line || *line == CMDSEP) - endreached = 1; + endreached = 1; } if (error) return 0; - + if (endreached || depth < mindepth) break; - + if (check_operator(BINARY, &op, mindepth) && compare_and_unload(&op) && push_op(&op)); else if (error) return 0; @@ -1341,13 +1341,13 @@ static int _eval __P1 (int,mindepth) return 1; } -int eval_any __P3 (long *,lres, ptr *,pres, char **,what) +int eval_any(long *lres, ptr *pres, char **what) { int printmode; long val; ptr txt; object res; - + if (pres) printmode = PRINT_AS_PTR; else if (lres) @@ -1358,10 +1358,10 @@ int eval_any __P3 (long *,lres, ptr *,pres, char **,what) error=0; stk.curr_obj=stk.curr_op=-1; line = *what; - + depth = 0; (void)_eval(0); - + if (!error) (void)pop_obj(&res); if (error) { @@ -1370,9 +1370,9 @@ int eval_any __P3 (long *,lres, ptr *,pres, char **,what) } } else if (printmode!=PRINT_NOTHING || opt_debug) { if (res.type==TYPE_NUM || res.type==TYPE_NUM_VAR) { - + val = res.type==TYPE_NUM ? res.num : *VAR[res.num].num; - + if (printmode==PRINT_AS_PTR) { *pres = ptrsetlen(*pres, LONGLEN); if (!MEM_ERROR) { @@ -1413,7 +1413,7 @@ int eval_any __P3 (long *,lres, ptr *,pres, char **,what) } } *what=line; - + if (!error) { if (printmode==PRINT_AS_PTR && res.type == TYPE_TXT && res.txt && ptrdata(res.txt)) @@ -1428,26 +1428,26 @@ int eval_any __P3 (long *,lres, ptr *,pres, char **,what) } res.type = 0; } - + if (res.type==TYPE_TXT_VAR) res.type = TYPE_TXT; else if (res.type==TYPE_NUM_VAR) res.type = TYPE_NUM; - + return res.type; } -int evalp __P2 (ptr *,res, char **,what) +int evalp(ptr *res, char **what) { return eval_any((long *)0, res, what); } -int evall __P2 (long *,res, char **,what) +int evall(long *res, char **what) { return eval_any(res, (ptr *)0, what); } -int evaln __P1 (char **,what) +int evaln(char **what) { return eval_any((long *)0, (ptr *)0, what); } diff --git a/eval.h b/eval.h index 67041d1..d717103 100644 --- a/eval.h +++ b/eval.h @@ -41,12 +41,12 @@ #define PRINT_AS_PTR 1 #define PRINT_AS_LONG 2 -int eval_any __P ((long *lres, ptr *pres, char **what)); -int evalp __P (( ptr *pres, char **what)); -int evall __P ((long *lres, char **what)); -int evaln __P (( char **what)); +int eval_any(long *lres, ptr *pres, char **what); +int evalp( ptr *pres, char **what); +int evall(long *lres, char **what); +int evaln( char **what); -void print_error __P ((int err_num)); +void print_error(int err_num); extern char *error_msg[]; extern int error; diff --git a/follow.c b/follow.c index a9eb087..09456c9 100644 --- a/follow.c +++ b/follow.c @@ -1,6 +1,6 @@ /* * follow.c -- interactively print an ASCII file. - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -135,8 +135,8 @@ int main(int argc, char *argv[]) { FILE *f; char c = 0, buf[512]; int d; - - if (argc < 2) { + + if (argc < 2) { fprintf(stderr, "needed a file name\n"); exit(0); } @@ -145,7 +145,7 @@ int main(int argc, char *argv[]) { fprintf(stderr, "unable to open %s\n", argv[1]); exit(0); } - + set_terminal(); while(c!=0x1b) { read(0, &c, 1); diff --git a/list.c b/list.c index 8bab96f..e38021f 100644 --- a/list.c +++ b/list.c @@ -1,6 +1,6 @@ /* * list.c -- list utility functions. - * + * * Copyright (C) 1998 by Massimiliano Ghilardi * * This program is free software; you can redistribute it and/or modify @@ -32,7 +32,7 @@ /* * compare two times, return -1 if t1 < t2, 1 if t1 > t2, 0 if t1 == t2 */ -int cmp_vtime __P2 (vtime *,t1, vtime *,t2) +int cmp_vtime(vtime *t1, vtime *t2) { int i; i = t1->tv_sec < t2->tv_sec ? -1 : t1->tv_sec > t2->tv_sec ? 1 : 0; @@ -44,7 +44,7 @@ int cmp_vtime __P2 (vtime *,t1, vtime *,t2) /* * add t2 to t1 (i.e. t1 += t2) */ -void add_vtime __P2 (vtime *,t1, vtime *,t2) +void add_vtime(vtime *t1, vtime *t2) { t1->tv_sec += t2->tv_sec; if ((t1->tv_usec += t2->tv_usec) >= uSEC_PER_SEC) { @@ -56,13 +56,13 @@ void add_vtime __P2 (vtime *,t1, vtime *,t2) /* * Return t1 - t2, in milliseconds */ -long diff_vtime __P2 (vtime *,t1, vtime *,t2) +long diff_vtime(vtime *t1, vtime *t2) { return (t1->tv_sec - t2->tv_sec) * mSEC_PER_SEC + (t1->tv_usec - t2->tv_usec) / uSEC_PER_mSEC; } -int rev_sort __P2 (defnode *,node1, defnode *,node2) +int rev_sort(defnode *node1, defnode *node2) { return -1; } @@ -70,12 +70,12 @@ int rev_sort __P2 (defnode *,node1, defnode *,node2) /* * standard ASCII comparison between nodes */ -int ascii_sort __P2 (defnode *,node1, defnode *,node2) +int ascii_sort(defnode *node1, defnode *node2) { return strcmp(node1->sortfield, node2->sortfield); } -int rev_ascii_sort __P2 (defnode *,node1, defnode *,node2) +int rev_ascii_sort(defnode *node1, defnode *node2) { return strcmp(node2->sortfield, node1->sortfield); } @@ -85,7 +85,7 @@ int rev_ascii_sort __P2 (defnode *,node1, defnode *,node2) * comparison between times of execution of nodes * (return -1 if node1->when < node2->when) */ -int time_sort __P2 (defnode *,node1, defnode *,node2) +int time_sort(defnode *node1, defnode *node2) { return cmp_vtime(&((delaynode *)node1)->when, &((delaynode *)node2)->when); } @@ -94,7 +94,7 @@ int time_sort __P2 (defnode *,node1, defnode *,node2) * reverse comparison between times of execution of nodes * (return -1 if node1->when > node2->when) */ -int rev_time_sort __P2 (defnode *,node1, defnode *,node2) +int rev_time_sort(defnode *node1, defnode *node2) { return cmp_vtime(&((delaynode *)node2)->when, &((delaynode *)node1)->when); } @@ -102,7 +102,7 @@ int rev_time_sort __P2 (defnode *,node1, defnode *,node2) /* * compute the hash value of a name */ -int hash __P2 (char *,name, int,optlen) +int hash(char *name, int optlen) { int h = 0, i = 0; if (optlen < 0) @@ -118,7 +118,7 @@ int hash __P2 (char *,name, int,optlen) /* * generic list node adding routine */ -void add_node __P3 (defnode *,newnode, defnode **,base, function_sort,sort) +void add_node(defnode *newnode, defnode **base, function_sort sort) { while((*base) && (!sort || (*sort)(newnode, *base) > 0)) base = &(*base)->next; @@ -126,7 +126,7 @@ void add_node __P3 (defnode *,newnode, defnode **,base, function_sort,sort) *base = newnode; } -static void add_sortednode __P3 (sortednode *,newnode, sortednode **,base, function_sort,sort) +static void add_sortednode(sortednode *newnode, sortednode **base, function_sort sort) { while((*base) && (!sort || (*sort)((defnode *)newnode, (defnode *)*base) > 0)) base = &(*base)->snext; @@ -134,7 +134,7 @@ static void add_sortednode __P3 (sortednode *,newnode, sortednode **,base, funct *base = newnode; } -void reverse_list __P1 (defnode **,base) +void reverse_list(defnode **base) { defnode *node = *base, *list = NULL, *tmp; while (node) { @@ -146,7 +146,7 @@ void reverse_list __P1 (defnode **,base) *base = list; } -void reverse_sortedlist __P1 (sortednode **,base) +void reverse_sortedlist(sortednode **base) { sortednode *node = *base, *list = NULL, *tmp; while (node) { @@ -158,7 +158,7 @@ void reverse_sortedlist __P1 (sortednode **,base) *base = list; } -static sortednode **selflookup_sortednode __P2 (sortednode *,self, sortednode **,base) +static sortednode **selflookup_sortednode(sortednode *self, sortednode **base) { sortednode **p = base; while (*p && *p != self) @@ -173,14 +173,14 @@ static sortednode **selflookup_sortednode __P2 (sortednode *,self, sortednode ** /* * add a node to the alias list */ -void add_aliasnode __P2 (char *,name, char *,subst) +void add_aliasnode(char *name, char *subst) { aliasnode *new = (aliasnode*)malloc(sizeof(aliasnode)); if (!new) { errmsg("malloc"); return; } - + new->group = NULL; new->active = 1; new->name = my_strdup(name); @@ -201,7 +201,7 @@ void add_aliasnode __P2 (char *,name, char *,subst) /* * add a node to the marker list */ -void add_marknode __P4 (char *,pattern, int,attrcode, char,mbeg, char,wild) +void add_marknode(char *pattern, int attrcode, char mbeg, char wild) { marknode **p, *new = (marknode*)malloc(sizeof(marknode)); int i; @@ -232,7 +232,7 @@ void add_marknode __P4 (char *,pattern, int,attrcode, char,mbeg, char,wild) /* * add a node to the action list */ -void add_actionnode __P6 (char *,pattern, char *,command, char *,label, int,active, int,type, void *,vregexp) +void add_actionnode(char *pattern, char *command, char *label, int active, int type, void *vregexp) { actionnode **p, *new = (actionnode*)malloc(sizeof(actionnode)); int i; @@ -240,7 +240,7 @@ void add_actionnode __P6 (char *,pattern, char *,command, char *,label, int,acti errmsg("malloc"); return; } - + new->group = NULL; new->pattern = my_strdup(pattern); new->command = my_strdup(command); @@ -274,7 +274,7 @@ void add_actionnode __P6 (char *,pattern, char *,command, char *,label, int,acti /* * add a node to the prompt list */ -void add_promptnode __P6 (char *,pattern, char *,command, char *,label, int,active, int,type, void *,vregexp) +void add_promptnode(char *pattern, char *command, char *label, int active, int type, void *vregexp) { promptnode **p, *new = (promptnode*)malloc(sizeof(promptnode)); int i; @@ -282,7 +282,7 @@ void add_promptnode __P6 (char *,pattern, char *,command, char *,label, int,acti errmsg("malloc"); return; } - + new->pattern = my_strdup(pattern); new->command = my_strdup(command); new->label = my_strdup(label); @@ -315,7 +315,7 @@ void add_promptnode __P6 (char *,pattern, char *,command, char *,label, int,acti /* * add a node to the keydef list */ -void add_keynode __P5 (char *,name, char *,sequence, int,seqlen, function_str,funct, char *,call_data) +void add_keynode(char *name, char *sequence, int seqlen, function_str funct, char *call_data) { keynode *new = (keynode*)malloc(sizeof(keynode)); if (!new) { @@ -339,7 +339,7 @@ void add_keynode __P5 (char *,name, char *,sequence, int,seqlen, function_str,fu free(new->call_data); free(new); return; - } + } add_node((defnode*)new, (defnode**)&keydefs, ascii_sort); } @@ -347,7 +347,7 @@ void add_keynode __P5 (char *,name, char *,sequence, int,seqlen, function_str,fu * add a node to the delayed command list * is_dead == 1 means when < now (and so cannot be executed anymore) */ -delaynode *add_delaynode __P4 (char *,name, char *,command, vtime *,when, int,is_dead) +delaynode *add_delaynode(char *name, char *command, vtime *when, int is_dead) { delaynode *new = (delaynode*)malloc(sizeof(delaynode)); if (!new) { @@ -365,30 +365,30 @@ delaynode *add_delaynode __P4 (char *,name, char *,command, vtime *,when, int,is free(new); return NULL; } - + new->when.tv_sec = when->tv_sec; new->when.tv_usec = when->tv_usec; if (is_dead) add_node((defnode*)new, (defnode**)&dead_delays, rev_time_sort); else add_node((defnode*)new, (defnode**)&delays, time_sort); - + return new; } /* * add a node to named variables list - * + * * do NOT allocate a ptr! */ -varnode *add_varnode __P2 (char *,name, int,type) +varnode *add_varnode(char *name, int type) { varnode *new; int m, n; - + if (type) type = 1; - + if (num_named_vars[type] >= max_named_vars) { /* we are running low on var pointers. try to enlarge */ m = NUMTOT + max_named_vars; @@ -414,7 +414,7 @@ varnode *add_varnode __P2 (char *,name, int,type) memzero(var + m, (n-m)*sizeof(vars)); } } - + new = (varnode*)malloc(sizeof(varnode)); if (!new) { errmsg("malloc"); @@ -429,13 +429,13 @@ varnode *add_varnode __P2 (char *,name, int,type) new->num = 0; new->str = (ptr)0; new->index = m = NUMPARAM + num_named_vars[type]; - + if (type) VAR[m].str = &new->str; else VAR[m].num = &new->num; num_named_vars[type]++; - + add_node((defnode*)new, (defnode**)&named_vars[type][hash(name,-1)], rev_sort); add_sortednode((sortednode*)new, (sortednode**)&sortednamed_vars[type], rev_ascii_sort); return new; @@ -445,7 +445,7 @@ varnode *add_varnode __P2 (char *,name, int,type) * look up an alias node by name: * return pointer to pointer to node or a pointer to NULL if nothing found */ -aliasnode **lookup_alias __P1 (char *,name) +aliasnode **lookup_alias(char *name) { aliasnode **p = &aliases[hash(name,-1)]; while (*p && strcmp(name, (*p)->name)) @@ -457,7 +457,7 @@ aliasnode **lookup_alias __P1 (char *,name) * look up an action node by label: * return pointer to pointer to node or a pointer to NULL if nothing found */ -actionnode **lookup_action __P1 (char *,label) +actionnode **lookup_action(char *label) { actionnode **p = &actions; while (*p && strcmp(label, (*p)->label)) @@ -469,7 +469,7 @@ actionnode **lookup_action __P1 (char *,label) * look up an action node by pattern: * return pointer to pointer to node or a pointer to NULL if nothing found */ -actionnode **lookup_action_pattern __P1 (char *,pattern) +actionnode **lookup_action_pattern(char *pattern) { actionnode **p = &actions; while (*p && strcmp(pattern, (*p)->pattern)) @@ -481,7 +481,7 @@ actionnode **lookup_action_pattern __P1 (char *,pattern) * look up a prompt node by label: * return pointer to pointer to node or a pointer to NULL if nothing found */ -actionnode **lookup_prompt __P1 (char *,label) +actionnode **lookup_prompt(char *label) { promptnode **p = &prompts; while (*p && strcmp(label, (*p)->label)) @@ -493,7 +493,7 @@ actionnode **lookup_prompt __P1 (char *,label) * look up an marker node by pattern: * return pointer to pointer to node or a pointer to NULL if nothing found */ -marknode **lookup_marker __P2 (char *,pattern, char,mbeg) +marknode **lookup_marker(char *pattern, char mbeg) { marknode **p = &markers; while (*p && (mbeg != (*p)->mbeg || strcmp(pattern, (*p)->pattern))) @@ -505,10 +505,10 @@ marknode **lookup_marker __P2 (char *,pattern, char,mbeg) * look up a key node by name: * return pointer to pointer to node or a pointer to NULL if nothing found */ -keynode **lookup_key __P1 (char *,name) +keynode **lookup_key(char *name) { keynode **p = &keydefs; - + while (*p && strcmp(name, (*p)->name)) p = &(*p)->next; return p; @@ -518,7 +518,7 @@ keynode **lookup_key __P1 (char *,name) * look up a delayed command node by label: * return pointer to pointer to node or a pointer to NULL if nothing found */ -delaynode **lookup_delay __P2 (char *,name, int,is_dead) +delaynode **lookup_delay(char *name, int is_dead) { delaynode **p = (is_dead ? &dead_delays : &delays); while (*p && strcmp(name, (*p)->name)) @@ -530,7 +530,7 @@ delaynode **lookup_delay __P2 (char *,name, int,is_dead) * look up a named variable node by name: * return pointer to pointer to node or a pointer to NULL if nothing found */ -varnode **lookup_varnode __P2 (char *,name, int,type) +varnode **lookup_varnode(char *name, int type) { varnode **p = &named_vars[type][hash(name,-1)]; while (*p && strcmp(name, (*p)->name)) @@ -541,7 +541,7 @@ varnode **lookup_varnode __P2 (char *,name, int,type) /* * delete an alias node, given a pointer to its precessor's pointer */ -void delete_aliasnode __P1 (aliasnode **,base) +void delete_aliasnode(aliasnode **base) { aliasnode *p = *base; *base = p->next; @@ -558,7 +558,7 @@ void delete_aliasnode __P1 (aliasnode **,base) /* * delete an action node, given a pointer to its precessor's pointer */ -void delete_actionnode __P1 (actionnode **,base) +void delete_actionnode(actionnode **base) { actionnode *p = *base; if (p->pattern) free(p->pattern); @@ -577,7 +577,7 @@ void delete_actionnode __P1 (actionnode **,base) /* * delete an prompt node, given a pointer to its precessor's pointer */ -void delete_promptnode __P1 (promptnode **,base) +void delete_promptnode(promptnode **base) { promptnode *p = *base; if (p->pattern) free(p->pattern); @@ -596,7 +596,7 @@ void delete_promptnode __P1 (promptnode **,base) /* * delete an marker node, given a pointer to its precessor's pointer */ -void delete_marknode __P1 (marknode **,base) +void delete_marknode(marknode **base) { marknode *p = *base; if (p->pattern) free(p->pattern); @@ -607,7 +607,7 @@ void delete_marknode __P1 (marknode **,base) /* * delete a keydef node, given a pointer to its precessor's pointer */ -void delete_keynode __P1 (keynode **,base) +void delete_keynode(keynode **base) { keynode *p = *base; if (p->name) free(p->name); @@ -620,7 +620,7 @@ void delete_keynode __P1 (keynode **,base) /* * delete a delayed command node, given a pointer to its precessor's pointer */ -void delete_delaynode __P1 (delaynode **,base) +void delete_delaynode(delaynode **base) { delaynode *p = *base; if (p->name) free(p->name); @@ -632,11 +632,11 @@ void delete_delaynode __P1 (delaynode **,base) /* * delete a named variable node, given a pointer to its precessor's pointer */ -void delete_varnode __P2 (varnode **,base, int,type) +void delete_varnode(varnode **base, int type) { varnode *p = *base; int idx = p->index, i, n; - + *base = p->next; if (*(base = (varnode**)selflookup_sortednode ((sortednode*)p, (sortednode**)&sortednamed_vars[type]))) @@ -646,28 +646,28 @@ void delete_varnode __P2 (varnode **,base, int,type) if (p->name) free(p->name); if (type && p->str) ptrdel(p->str); free((void*)p); - + i = NUMPARAM + --num_named_vars[type]; - + if (idx == i) return; - + /* now I must fill the hole in var[idx].*** */ - + for (n = 0; n < MAX_HASH; n++) for (p = named_vars[type][n]; p; p = p->next) if (p->index == i) { n = MAX_HASH; break; } - + if (!p) { /* should NEVER happen */ print_error(error=UNDEFINED_VARIABLE_ERROR); return; } - + p->index = idx; - + if (type) { VAR[idx].str = &p->str; VAR[ i ].str = NULL; diff --git a/list.h b/list.h index 24588d3..c336049 100644 --- a/list.h +++ b/list.h @@ -3,45 +3,45 @@ #ifndef _LIST_H_ #define _LIST_H_ -int cmp_vtime __P ((vtime *t1, vtime *t2)); -void add_vtime __P ((vtime *t1, vtime *t2)); -long diff_vtime __P ((vtime *t1, vtime *t2)); - -int rev_sort __P ((defnode *node1, defnode *node2)); -int ascii_sort __P ((defnode *node1, defnode *node2)); -int rev_ascii_sort __P ((defnode *node1, defnode *node2)); -int time_sort __P ((defnode *node1, defnode *node2)); -int rev_time_sort __P ((defnode *node1, defnode *node2)); - -int hash __P ((char *name)); - -void add_node __P ((defnode *newnode, defnode **base, function_sort sort)); -void reverse_sortedlist __P ((sortednode **base)); - -void add_aliasnode __P ((char *name, char *subst)); -void add_actionnode __P ((char *pattern, char *command, char *label, int active, int type, void *qregexp)); -void add_promptnode __P ((char *pattern, char *command, char *label, int active, int type, void *qregexp)); -void add_marknode __P ((char *pattern, int attrcode, char mbeg, char wild)); -void add_keynode __P ((char *name, char *sequence, int seqlen, function_str funct, char *call_data)); -delaynode *add_delaynode __P ((char *name, char *command, vtime *when, int is_dead)); -varnode *add_varnode __P ((char *name, int type)); - -aliasnode **lookup_alias __P ((char *name)); -actionnode **lookup_action __P ((char *label)); -actionnode **lookup_prompt __P ((char *label)); -actionnode **lookup_action_pattern __P ((char *pattern)); -marknode **lookup_marker __P ((char *pattern, char mbeg)); -keynode **lookup_key __P ((char *name)); -delaynode **lookup_delay __P ((char *name, int is_dead)); -varnode **lookup_varnode __P ((char *name, int type)); - -void delete_aliasnode __P ((aliasnode **base)); -void delete_actionnode __P ((actionnode **base)); -void delete_promptnode __P ((promptnode **base)); -void delete_marknode __P ((marknode **base)); -void delete_keynode __P ((keynode **base)); -void delete_delaynode __P ((delaynode **base)); -void delete_varnode __P ((varnode **base, int type)); +int cmp_vtime(vtime *t1, vtime *t2); +void add_vtime(vtime *t1, vtime *t2); +long diff_vtime(vtime *t1, vtime *t2); + +int rev_sort(defnode *node1, defnode *node2); +int ascii_sort(defnode *node1, defnode *node2); +int rev_ascii_sort(defnode *node1, defnode *node2); +int time_sort(defnode *node1, defnode *node2); +int rev_time_sort(defnode *node1, defnode *node2); + +int hash(char *name); + +void add_node(defnode *newnode, defnode **base, function_sort sort); +void reverse_sortedlist(sortednode **base); + +void add_aliasnode(char *name, char *subst); +void add_actionnode(char *pattern, char *command, char *label, int active, int type, void *qregexp); +void add_promptnode(char *pattern, char *command, char *label, int active, int type, void *qregexp); +void add_marknode(char *pattern, int attrcode, char mbeg, char wild); +void add_keynode(char *name, char *sequence, int seqlen, function_str funct, char *call_data); +delaynode *add_delaynode(char *name, char *command, vtime *when, int is_dead); +varnode *add_varnode(char *name, int type); + +aliasnode **lookup_alias(char *name); +actionnode **lookup_action(char *label); +actionnode **lookup_prompt(char *label); +actionnode **lookup_action_pattern(char *pattern); +marknode **lookup_marker(char *pattern, char mbeg); +keynode **lookup_key(char *name); +delaynode **lookup_delay(char *name, int is_dead); +varnode **lookup_varnode(char *name, int type); + +void delete_aliasnode(aliasnode **base); +void delete_actionnode(actionnode **base); +void delete_promptnode(promptnode **base); +void delete_marknode(marknode **base); +void delete_keynode(keynode **base); +void delete_delaynode(delaynode **base); +void delete_varnode(varnode **base, int type); #endif /* _LIST_H_ */ diff --git a/log.c b/log.c index f539330..b831b6f 100644 --- a/log.c +++ b/log.c @@ -1,7 +1,7 @@ /* * log.c -- code for #movie / #capture backbuffering * and code for reprint-on-prompt - * + * * Copyright (C) 1998 by Massimiliano Ghilardi * * This program is free software; you can redistribute it and/or modify @@ -57,7 +57,7 @@ static char *names[] = { NULL, "line", "prompt", "sleep" }; /* * flush a single buffer line */ -static void log_flushline __P1 (int,i) +static void log_flushline(int i) { if (capturefile) fprintf(capturefile, "%s%s", @@ -74,14 +74,14 @@ static void log_flushline __P1 (int,i) /* * remove the oldest (first) line from the buffer */ -static void log_clearline __P0 (void) +static void log_clearline(void) { int next; - + if (logstart == logend) return; log_flushline(logstart); - + next = (logstart + 1) % logsize; if (next == logend) datastart = dataend = logstart = logend = 0; @@ -92,7 +92,7 @@ static void log_clearline __P0 (void) /* * remove an initial SLEEP from the buffer */ -void log_clearsleep __P0 (void) +void log_clearsleep(void) { if (logstart != logend) loglist[logstart].msecs = 0; @@ -101,7 +101,7 @@ void log_clearsleep __P0 (void) /* * flush the buffer */ -void log_flush __P0 (void) +void log_flush(void) { int i = logstart; while (i != logend) { @@ -112,12 +112,12 @@ void log_flush __P0 (void) datastart = dataend = logstart = logend = 0; } -int log_getsize __P0 (void) +int log_getsize(void) { return datasize; } -static void log_reset __P0 (void) +static void log_reset(void) { if (datasize) { if (datalist) free(datalist); @@ -129,7 +129,7 @@ static void log_reset __P0 (void) } -void log_resize __P1 (int,newsize) +void log_resize(int newsize) { if (newsize && newsize < 1000) { PRINTF("#buffer size must be 0 (zero) or >= 1000\n"); @@ -138,16 +138,16 @@ void log_resize __P1 (int,newsize) if (newsize == datasize) return; - + log_flush(); log_reset(); if (newsize) { datalist = (char *)malloc(newsize); if (!datalist) { log_reset(); errmsg("malloc"); return; } - + loglist = (logentry *)malloc(newsize/16*sizeof(logentry)); if (!loglist) { log_reset(); errmsg("malloc"); return; } - + datasize = newsize; logsize = newsize / 16; } @@ -159,10 +159,10 @@ void log_resize __P1 (int,newsize) /* * add a single line to the buffer */ -static void log_writeline __P4 (char *,line, int,len, int,kind, long,msecs) +static void log_writeline(char *line, int len, int kind, long msecs) { int dst; - + if (++len >= datasize) { PRINTF("#line too long, discarded from movie/capture buffer\n"); return; @@ -170,13 +170,13 @@ static void log_writeline __P4 (char *,line, int,len, int,kind, long,msecs) while (LOGFULL || DATALEFT < len) log_clearline(); /* ok, now we know there IS enough space */ - + if (datastart >= dataend /* is == iff loglist is empty */ || datasize - dataend > len) dst = dataend; else dst = 0; - + memcpy(loglist[logend].line = datalist + dst, line, len - 1); datalist[dst + len - 1] = '\0'; @@ -185,23 +185,23 @@ static void log_writeline __P4 (char *,line, int,len, int,kind, long,msecs) if ((dataend = dst + len) == datasize) dataend = 0; - + if (++logend == logsize) logend = 0; } - + /* * write to #capture / #movie buffer */ -void log_write __P3 (char *,str, int,len, int,newline) +void log_write(char *str, int len, int newline) { char *next; long diff; int i, last = 0; - + if (!datasize && !moviefile && !capturefile) return; - + update_now(); diff = diff_vtime(&now, &movie_last); movie_last = now; @@ -222,7 +222,7 @@ void log_write __P3 (char *,str, int,len, int,newline) if (diff) fprintf(moviefile, "%s %ld\n", names[SLEEP], diff); - fprintf(moviefile, "%s %.*s\n", + fprintf(moviefile, "%s %.*s\n", names[last && !newline ? PROMPT : LINE], i, str); } if (capturefile) { @@ -260,13 +260,13 @@ static int repsize = BUFSIZE/8; /* size of circular (pointer to string) list */ /* * remove the oldest (first) line from reprintlist */ -static void reprint_clearline __P0 (void) +static void reprint_clearline(void) { int next; - + if (repstart == repend) return; - + next = (repstart + 1) % repsize; if (next == repend) reprintstart = reprintend = repstart = repend = 0; @@ -274,7 +274,7 @@ static void reprint_clearline __P0 (void) reprintstart = replist[next] - reprintlist, repstart = next; } -void reprint_clear __P0 (void) +void reprint_clear(void) { reprintstart = reprintend = repstart = repend = 0; } @@ -282,18 +282,18 @@ void reprint_clear __P0 (void) /* * add a single line to the buffer */ -void reprint_writeline __P1 (char *,line) +void reprint_writeline(char *line) { int len = strlen(line) + 1; int dst; - + if (!opt_reprint || (promptlen && prompt_status != -1)) /* * if prompt is valid, we'll never have to reprint, as we * _already_ printed the command at the right moment */ return; - + if (len >= reprintsize) { PRINTF("#line too long, discarded from prompt reprint buffer\n"); return; @@ -301,24 +301,24 @@ void reprint_writeline __P1 (char *,line) while (REPFULL || REPRINTLEFT < len) reprint_clearline(); /* ok, now we know there IS enough space */ - + if (reprintstart >= reprintend /* is == iff replist is empty */ || reprintsize - reprintend > len) dst = reprintend; else dst = 0; - + memcpy(replist[repend] = reprintlist + dst, line, len - 1); reprintlist[dst + len - 1] = '\0'; if ((reprintend = dst + len) == reprintsize) reprintend = 0; - + if (++repend == repsize) repend = 0; } -char *reprint_getline __P0 (void) +char *reprint_getline(void) { char *line = NULL; if (opt_reprint && repend != repstart) diff --git a/log.h b/log.h index 0fe3a54..a5822b4 100644 --- a/log.h +++ b/log.h @@ -8,15 +8,15 @@ enum linetype { EMPTY = 0, LINE = 1, PROMPT = 2, SLEEP = 3 }; extern FILE *capturefile, *recordfile, *moviefile; extern vtime movie_last; -void log_clearsleep __P ((void)); -void log_flush __P ((void)); -int log_getsize __P ((void)); -void log_resize __P ((int newsize)); -void log_write __P ((char *str, int len, int newline)); +void log_clearsleep(void); +void log_flush(void); +int log_getsize(void); +void log_resize(int newsize); +void log_write(char *str, int len, int newline); -void reprint_writeline __P ((char *line)); -char *reprint_getline __P ((void)); -void reprint_clear __P ((void)); +void reprint_writeline(char *line); +char *reprint_getline(void); +void reprint_clear(void); #endif /* _LOG_H_ */ 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; istr = 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 && iwhen, &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); } diff --git a/main.h b/main.h index 85f11f4..e76f7cb 100644 --- a/main.h +++ b/main.h @@ -7,24 +7,24 @@ #define _MAIN_H_ /* shared functions from main.c */ -void printver __P ((void)); -void status __P ((int s)); -void process_remote_input __P ((char *buf, int size)); -void push_params __P ((void)); -void pop_params __P ((void)); -void prompt_set_iac __P ((char *p)); -char *parse_instruction __P ((char *line, char silent, char subs, char jit_subs)); -char *get_next_instr __P ((char *p)); -void parse_user_input __P ((char *line, char silent)); -void set_deffile __P ((char *arg)); -int is_permanent_variable __P ((varnode *v)); +void printver(void); +void status(int s); +void process_remote_input(char *buf, int size); +void push_params(void); +void pop_params(void); +void prompt_set_iac(char *p); +char *parse_instruction(char *line, char silent, char subs, char jit_subs); +char *get_next_instr(char *p); +void parse_user_input(char *line, char silent); +void set_deffile(char *arg); +int is_permanent_variable(varnode *v); /* shared vars from main.c */ extern int prompt_status, line_status; extern int limit_mem; extern char ready; -extern VOLATILE char confirm; +extern volatile char confirm; extern int history_done; extern int linemode; extern char hostname[]; @@ -49,7 +49,7 @@ extern int pos; /* cursor position in edbuf */ extern char edattrbeg[], edattrend[]; extern int edattrbg; -extern VOLATILE int sig_pending, sig_winch_got, sig_chld_got; +extern volatile int sig_pending, sig_winch_got, sig_chld_got; extern long received, sent; diff --git a/map.c b/map.c index 1b6a375..7fd9b56 100644 --- a/map.c +++ b/map.c @@ -39,7 +39,7 @@ static int mapend = 0; /* index one past last map entry */ /* * return reverse direction */ -static char reverse_dir __P1 (char,dir) +static char reverse_dir(char dir) { static char dirs[] = "nsewud"; char *p = strchr(dirs, dir); @@ -49,12 +49,12 @@ static char reverse_dir __P1 (char,dir) /* * retrace steps on map, optionally walk them back */ -void map_retrace __P2 (int,steps, int,walk_back) +void map_retrace(int steps, int walk_back) { char cmd[2]; - + cmd[1] = '\0'; - + if (!steps && !walk_back) mapend = mapstart; else { @@ -64,7 +64,7 @@ void map_retrace __P2 (int,steps, int,walk_back) status(1); tty_putc('['); } - + while (mapstart != mapend && steps--) { mapend = MAPINDEX(mapend - 1); if (walk_back) { @@ -82,7 +82,7 @@ void map_retrace __P2 (int,steps, int,walk_back) /* * show automatic map (latest steps) in the form s2ews14n */ -void map_show __P0 (void) +void map_show(void) { char lastdir; int count = 0; @@ -110,13 +110,13 @@ void map_show __P0 (void) tty_printf("%d", count); tty_printf("%c\n", lastdir); - } + } } /* * print map to string in the form seewsnnnnn */ -void map_sprintf __P1 (char *,buf) +void map_sprintf(char *buf) { int i; @@ -129,7 +129,7 @@ void map_sprintf __P1 (char *,buf) /* * add direction to automap */ -void map_add_dir __P1 (char,dir) +void map_add_dir(char dir) { #ifdef NOMAZEMAPPING if (mapend != mapstart && dir == reverse_dir(MAPENTRY(mapend - 1))) { @@ -148,25 +148,25 @@ void map_add_dir __P1 (char,dir) * execute walk if word is valid [speed]walk sequence - * return 1 if walked, 0 if not */ -int map_walk __P3 (char *,word, int,silent, int,maponly) +int map_walk(char *word, int silent, int maponly) { char buf[16]; int n = strlen(word); int is_main = (tcp_fd == tcp_main_fd); - + if (!is_main && !maponly && !opt_speedwalk) return 0; if (!n || (n > 1 && !opt_speedwalk && !maponly) || !strchr("neswud", word[n - 1]) || (int)strspn(word, "neswud0123456789") != n) return 0; - + if (maponly) silent = 1; buf[1] = '\0'; while (*word) { if (!silent) { status(1); tty_putc('['); } - + if (isdigit(*word)) { n = strtol(word, &word, 10); if (!silent) diff --git a/map.h b/map.h index 97c0edf..49abc1f 100644 --- a/map.h +++ b/map.h @@ -3,13 +3,13 @@ #ifndef _MAP_H_ #define _MAP_H_ -void map_bootstrap __P ((void)); +void map_bootstrap(void); -void map_retrace __P ((int steps, int walk_back)); -void map_show __P ((void)); -void map_sprintf __P ((char *buf)); -void map_add_dir __P ((char dir)); -int map_walk __P ((char *word, int silent, int maponly)); +void map_retrace(int steps, int walk_back); +void map_show(void); +void map_sprintf(char *buf); +void map_add_dir(char dir); +int map_walk(char *word, int silent, int maponly); #endif /* _MAP_H_ */ diff --git a/powwow-movieplay.c b/powwow-movieplay.c index d49078d..91854b3 100644 --- a/powwow-movieplay.c +++ b/powwow-movieplay.c @@ -37,7 +37,7 @@ int argc; char *argv[]; fprintf(stderr, "Please run this program as \"powwow-movieplay\" or \"powwow-movie2ascii\"\n"); return 1; } - + if (play) { if (argc == 2) { infile = fopen(argv[1], "rb"); @@ -67,7 +67,7 @@ int argc; char *argv[]; return 1; } } - + while (fgets(buf, 4096, infile) != NULL) { i = strlen(buf); if (i > 0 && buf[i-1] == '\n') diff --git a/ptr.c b/ptr.c index 4c765b5..5878cd4 100644 --- a/ptr.c +++ b/ptr.c @@ -26,7 +26,7 @@ * create a new, empty ptr. * return NULL if max == 0 */ -ptr ptrnew __P1 (int,max) +ptr ptrnew(int max) { ptr p = (ptr)0; @@ -48,10 +48,10 @@ ptr ptrnew __P1 (int,max) /* * create a new ptr giving an initial contents, * which gets duplicated. - * + * * warning: newmax could be so small that we must truncate the copied data! */ -ptr ptrdup2 __P2 (ptr,src, int,newmax) +ptr ptrdup2(ptr src, int newmax) { ptr p = (ptr)0; @@ -75,7 +75,7 @@ ptr ptrdup2 __P2 (ptr,src, int,newmax) return p; } -ptr ptrdup __P1 (ptr,src) +ptr ptrdup(ptr src) { if (!src) return src; @@ -83,7 +83,7 @@ ptr ptrdup __P1 (ptr,src) } /* delete (free) a ptr */ -void _ptrdel __P1 (ptr,p) +void _ptrdel(ptr p) { if (p && p->signature == PTR_SIG) free((void *)p); @@ -92,7 +92,7 @@ void _ptrdel __P1 (ptr,p) } /* clear a ptr */ -void ptrzero __P1 (ptr,p) +void ptrzero(ptr p) { if (p) { p->len = 0; @@ -101,17 +101,17 @@ void ptrzero __P1 (ptr,p) } /* truncate a ptr to len chars */ -void ptrtrunc __P2 (ptr,p, int,len) +void ptrtrunc(ptr p, int len) { if (p) { if (len < 0 || len > ptrlen(p)) return; ptrdata(p)[p->len = len] = '\0'; - } + } } /* shrink a ptr by len chars */ -void ptrshrink __P2 (ptr,p, int,len) +void ptrshrink(ptr p, int len) { if (p) { if (len < 0 || len > ptrlen(p)) @@ -128,11 +128,11 @@ void ptrshrink __P2 (ptr,p, int,len) * You have been warned! Don't use any statically created ptr for * write operations, and you will be fine. */ -ptr __ptrmcat __P4 (ptr,dst, char *,src, int,len, int,shrink) +ptr __ptrmcat(ptr dst, char *src, int len, int shrink) { int newmax, failmax, overlap; char mustalloc; - + if (!src || len <= 0) return dst; if (len + sizeofptr < 0) { @@ -140,14 +140,14 @@ ptr __ptrmcat __P4 (ptr,dst, char *,src, int,len, int,shrink) error = NO_MEM_ERROR; return dst; } - + if (!dst) { failmax = len; mustalloc = 1; } else { failmax = ptrlen(dst) + len; mustalloc = ptrmax(dst) < ptrlen(dst) + len; - + if (shrink && ptrmax(dst) > PARAMLEN && ptrmax(dst)/4 > ptrlen(dst) + len) /* we're wasting space, shrink dst */ @@ -159,7 +159,7 @@ ptr __ptrmcat __P4 (ptr,dst, char *,src, int,len, int,shrink) error = NO_MEM_ERROR; return dst; } - + if (mustalloc) { /* dst must be (re)allocated */ ptr p; @@ -169,7 +169,7 @@ ptr __ptrmcat __P4 (ptr,dst, char *,src, int,len, int,shrink) overlap = 1; else overlap = 0; - + /* find a suitable new size */ if (limit_mem && failmax > limit_mem) { error = MEM_LIMIT_ERROR; @@ -214,12 +214,12 @@ ptr __ptrmcat __P4 (ptr,dst, char *,src, int,len, int,shrink) return dst; } -ptr ptrmcat __P3 (ptr,dst, char *,src, int,len) +ptr ptrmcat(ptr dst, char *src, int len) { return __ptrmcat(dst, src, len, 1); } -ptr ptrcat __P2 (ptr,dst, ptr,src) +ptr ptrcat(ptr dst, ptr src) { if (src) return __ptrmcat(dst, ptrdata(src), ptrlen(src), 1); @@ -230,11 +230,11 @@ ptr ptrcat __P2 (ptr,dst, ptr,src) * copy a ptr into another (ptrcpy), or a char* into a ptr (ptrmcpy); * same warning as above if dst is too small or way too big. */ -ptr __ptrmcpy __P4(ptr,dst, char *,src, int,len, int,shrink) +ptr __ptrmcpy(ptr dst, char *src, int len, int shrink) { int newmax, failmax = len, overlap; char mustalloc; - + if (!src || len<=0) { if (len>=0) ptrzero(dst); @@ -245,7 +245,7 @@ ptr __ptrmcpy __P4(ptr,dst, char *,src, int,len, int,shrink) error = NO_MEM_ERROR; return dst; } - + if (!dst) { mustalloc = 1; } else { @@ -255,7 +255,7 @@ ptr __ptrmcpy __P4(ptr,dst, char *,src, int,len, int,shrink) /* we're wasting space, shrink dst */ mustalloc = 1; } - + if (mustalloc) { /* dst must be (re)allocated */ ptr p; @@ -309,12 +309,12 @@ ptr __ptrmcpy __P4(ptr,dst, char *,src, int,len, int,shrink) return dst; } -ptr ptrmcpy __P3 (ptr,dst, char *,src, int,len) +ptr ptrmcpy(ptr dst, char *src, int len) { return __ptrmcpy(dst, src, len, 1); } -ptr ptrcpy __P2 (ptr,dst, ptr,src) +ptr ptrcpy(ptr dst, ptr src) { if (src) return __ptrmcpy(dst, ptrdata(src), ptrlen(src), 1); @@ -323,7 +323,7 @@ ptr ptrcpy __P2 (ptr,dst, ptr,src) } /* enlarge a ptr by len chars. create new if needed */ -ptr ptrpad __P2 (ptr,p, int,len) +ptr ptrpad(ptr p, int len) { if (!p) { if (len<=0) @@ -354,7 +354,7 @@ ptr ptrpad __P2 (ptr,p, int,len) } /* set a ptr to be len chars at minimum. create new if needed */ -ptr ptrsetlen __P2 (ptr,p, int,len) +ptr ptrsetlen(ptr p, int len) { if (!p) { if (len<=0) @@ -366,13 +366,13 @@ ptr ptrsetlen __P2 (ptr,p, int,len) } } return ptrpad(p, len - ptrlen(p)); -} +} /* * compare two ptr (ptrcmp) or a ptr and a char* (ptrmcmp) * if one is a truncated copy of the other, the shorter is considered smaller */ -int ptrmcmp __P3 (ptr,p, char *,q, int,lenq) +int ptrmcmp(ptr p, char *q, int lenq) { int res; if (!p || !ptrlen(p)) { @@ -394,7 +394,7 @@ int ptrmcmp __P3 (ptr,p, char *,q, int,lenq) return res; } -int ptrcmp __P2 (ptr,p, ptr,q) +int ptrcmp(ptr p, ptr q) { if (q) return ptrmcmp(p, ptrdata(q), ptrlen(q)); @@ -408,7 +408,7 @@ int ptrcmp __P2 (ptr,p, ptr,q) * find first occurrence of c in p * return NULL if none found. */ -char *ptrchr __P2 (ptr,p, char,c) +char *ptrchr(ptr p, char c) { if (p) return (char *)memchr(ptrdata(p), c, ptrlen(p)); @@ -419,13 +419,13 @@ char *ptrchr __P2 (ptr,p, char,c) * find last occurrence of c in p * return NULL if none found. */ -char *memrchr __P3 (char *,p, int,lenp, char,c) +char *memrchr(char *p, int lenp, char c) { char *v, *s = p; if (!p || lenp<=0) return NULL; - + v = s + lenp - 1; while (v != s && *v != c) { v--; @@ -436,7 +436,7 @@ char *memrchr __P3 (char *,p, int,lenp, char,c) return NULL; } -char *ptrrchr __P2 (ptr,p, char,c) +char *ptrrchr(ptr p, char c) { if (p) return memrchr(ptrdata(p), ptrlen(p), c); @@ -446,18 +446,18 @@ char *ptrrchr __P2 (ptr,p, char,c) #ifndef _GNU_SOURCE /* * find first occurrence of needle in hay - * + * * GNU libc has memmem(), for others we do by hand. */ -char *memfind __P4 (char *,hay, int,haylen, char *,needle, int,needlelen) +char *memfind(char *hay, int haylen, char *needle, int needlelen) { char *tmp; - + if (!hay || haylen<=0 || needlelen<0) return NULL; if (!needle || !needlelen) return hay; - + while (haylen >= needlelen) { /* find a matching first char */ if ((tmp = memchr(hay, *needle, haylen))) { @@ -466,7 +466,7 @@ char *memfind __P4 (char *,hay, int,haylen, char *,needle, int,needlelen) hay = tmp; } else return NULL; - + /* got a matching first char, * check the rest */ if (!memcmp(needle, tmp, needlelen)) @@ -474,7 +474,7 @@ char *memfind __P4 (char *,hay, int,haylen, char *,needle, int,needlelen) hay++, haylen --; } - + return NULL; } #endif /* !_GNU_SOURCE */ @@ -483,7 +483,7 @@ char *memfind __P4 (char *,hay, int,haylen, char *,needle, int,needlelen) * find first occurrence of q in p, * return NULL if none found. */ -char *ptrmfind __P3 (ptr,p, char *,q, int,lenq) +char *ptrmfind(ptr p, char *q, int lenq) { if (p) { if (q && lenq>0) @@ -493,7 +493,7 @@ char *ptrmfind __P3 (ptr,p, char *,q, int,lenq) return (char*)p; /* shortcut for NULL */ } -char *ptrfind __P2 (ptr,p, ptr,q) +char *ptrfind(ptr p, ptr q) { if (p) { if (q) @@ -508,33 +508,33 @@ char *ptrfind __P2 (ptr,p, ptr,q) * Scan p for the first occurrence of one of the characters in q, * return NULL if none of them is found. */ -char *memchrs __P4 (char *,p, int,lenp, char *,q, int,lenq) +char *memchrs(char *p, int lenp, char *q, int lenq) { char *endp; - + if (!q || lenq<=0) return p; if (!p || lenp<=0) return NULL; - + endp = p + lenp; - + while (p < endp && !memchr(q, *p, lenq)) p++; - + if (p == endp) return NULL; return p; } -char *ptrmchrs __P3 (ptr,p, char *,q, int,lenq) +char *ptrmchrs(ptr p, char *q, int lenq) { if (p) return memchrs(ptrdata(p), ptrlen(p), q, lenq); return (char*)p; /* shortcut for NULL */ } -char *ptrchrs __P2 (ptr,p, ptr,q) +char *ptrchrs(ptr p, ptr q) { if (p) { if (q) @@ -549,7 +549,7 @@ char *ptrchrs __P2 (ptr,p, ptr,q) * Scan p for the last occurrence of one of the characters in q, * return NULL if none of them is found. */ -char *memrchrs __P4 (char *,p, int,lenp, char *,q, int,lenq) +char *memrchrs(char *p, int lenp, char *q, int lenq) { if (!p || lenp<=0) { if (!q || lenq<=0) @@ -557,27 +557,27 @@ char *memrchrs __P4 (char *,p, int,lenp, char *,q, int,lenq) else return NULL; } - + p += lenp; if (!q || lenq<=0) return p; do { lenp--, p--; } while (lenp >= 0 && !memchr(q, *p, lenq)); - + if (lenp < 0) return NULL; return p; } -char *ptrmrchrs __P3 (ptr,p, char *,q, int,lenq) +char *ptrmrchrs(ptr p, char *q, int lenq) { if (p) return memrchrs(ptrdata(p), ptrlen(p), q, lenq); return (char*)p; /* shortcut for NULL */ } -char *ptrrchrs __P2 (ptr,p, ptr,q) +char *ptrrchrs(ptr p, ptr q) { if (p && q) return memrchrs(ptrdata(p), ptrlen(p), ptrdata(q), ptrlen(q)); diff --git a/ptr.h b/ptr.h index 4f1654a..2a19843 100644 --- a/ptr.h +++ b/ptr.h @@ -22,54 +22,54 @@ typedef _ptr * ptr; #define ptrdata(p) ((char *)((ptr)(p) + 1)) /* if p is a valid (ptr), ptrdata(p) is guaranteed to be a valid (char *) */ -ptr ptrnew __P ((int max)); -ptr ptrdup2 __P ((ptr src, int newmax)); -ptr ptrdup __P ((ptr src)); +ptr ptrnew(int max); +ptr ptrdup2(ptr src, int newmax); +ptr ptrdup(ptr src); #define PTR_SIG 91887 #define ptrdel(x) _ptrdel(x);x=(ptr)0; -void _ptrdel __P ((ptr p)); +void _ptrdel(ptr p); -void ptrzero __P ((ptr p)); -void ptrshrink __P ((ptr p, int len)); -void ptrtrunc __P ((ptr p, int len)); -ptr ptrpad __P ((ptr p, int len)); -ptr ptrsetlen __P ((ptr p, int len)); +void ptrzero(ptr p); +void ptrshrink(ptr p, int len); +void ptrtrunc(ptr p, int len); +ptr ptrpad(ptr p, int len); +ptr ptrsetlen(ptr p, int len); -ptr ptrcpy __P ((ptr dst, ptr src)); -ptr ptrmcpy __P ((ptr dst, char *src, int len)); +ptr ptrcpy(ptr dst, ptr src); +ptr ptrmcpy(ptr dst, char *src, int len); -ptr ptrcat __P ((ptr dst, ptr src)); -ptr ptrmcat __P ((ptr dst, char *src, int len)); +ptr ptrcat(ptr dst, ptr src); +ptr ptrmcat(ptr dst, char *src, int len); -ptr __ptrcat __P ((ptr dst, char *src, int len, int shrink)); -ptr __ptrmcpy __P ((ptr dst, char *src, int len, int shrink)); +ptr __ptrcat(ptr dst, char *src, int len, int shrink); +ptr __ptrmcpy(ptr dst, char *src, int len, int shrink); -int ptrcmp __P ((ptr p, ptr q)); -int ptrmcmp __P ((ptr p, char *q, int lenq)); +int ptrcmp(ptr p, ptr q); +int ptrmcmp(ptr p, char *q, int lenq); -char *ptrchr __P ((ptr p, char c)); -char *ptrrchr __P ((ptr p, char c)); +char *ptrchr(ptr p, char c); +char *ptrrchr(ptr p, char c); -char *ptrfind __P ((ptr p, ptr q)); -char *ptrmfind __P ((ptr p, char *q, int lenq)); +char *ptrfind(ptr p, ptr q); +char *ptrmfind(ptr p, char *q, int lenq); -char *ptrchrs __P ((ptr p, ptr q)); -char *ptrmchrs __P ((ptr p, char *q, int lenq)); -char *ptrrchrs __P ((ptr p, ptr q)); -char *ptrmrchrs __P ((ptr p, char *q, int lenq)); +char *ptrchrs(ptr p, ptr q); +char *ptrmchrs(ptr p, char *q, int lenq); +char *ptrrchrs(ptr p, ptr q); +char *ptrmrchrs(ptr p, char *q, int lenq); -char *memchrs __P ((char *p, int lenp, char *q, int lenq)); -char *memrchrs __P ((char *p, int lenp, char *q, int lenq)); +char *memchrs(char *p, int lenp, char *q, int lenq); +char *memrchrs(char *p, int lenp, char *q, int lenq); #ifdef _GNU_SOURCE # define memfind memmem #else -char *memfind __P ((char *hay, int haylen, char *needle, int needlelen)); +char *memfind(char *hay, int haylen, char *needle, int needlelen); /* TODO: watch memrchr, it is defined differently here than under _GNU_SOURCE, * so it could cause bizarre results if a module makes use of a library that * uses it */ -char *memrchr __P ((char *p, int lenp, char c)); +char *memrchr(char *p, int lenp, char c); #endif #endif /* _PTR_H_ */ diff --git a/tcp.c b/tcp.c index 8de41a4..d5a6be8 100644 --- a/tcp.c +++ b/tcp.c @@ -71,7 +71,7 @@ fd_set fdset; /* set of descriptors to select() on */ * so far, only terminal type is processed but future extensions are * window size, X display location, etc. */ -static void dosubopt __P1 (byte *,str) +static void dosubopt(byte *str) { char buf[256], *term; int len, err; @@ -85,7 +85,7 @@ static void dosubopt __P1 (byte *,str) if (!(term = getenv("TERM"))) term = "unknown"; sprintf(buf, "%c%c%c%c%.*s%c%c", IAC, SB, TELOPT_TTYPE, 0, 256-7, term, IAC, SE); /* 0 == IS */ - + len = strlen(term) + 6; while ((err = write(tcp_fd, buf, len)) < 0 && errno == EINTR) ; @@ -104,12 +104,12 @@ static void dosubopt __P1 (byte *,str) * send an option negotiation * 'what' is one of WILL, WONT, DO, DONT */ -static void sendopt __P2 (byte,what, byte,opt) +static void sendopt(byte what, byte opt) { static byte buf[3] = { IAC, 0, 0 }; int i; buf[1] = what; buf[2] = opt; - + while ((i = write(tcp_fd, buf, 3)) < 0 && errno == EINTR) ; if (i != 3) { @@ -129,7 +129,7 @@ static void sendopt __P2 (byte,what, byte,opt) * connect to remote host * Warning: some voodoo code here */ -int tcp_connect __P2 (const char *,addr, int,port) +int tcp_connect(const char *addr, int port) { struct addrinfo *host_info; struct addrinfo addrinfo; @@ -214,7 +214,7 @@ int tcp_connect __P2 (const char *,addr, int,port) } #else /* term */ - + if ((newtcp_fd = connect_server(0)) < 0) { tty_puts("\n#powwow: unable to connect to term server\n"); return -1; @@ -228,15 +228,15 @@ int tcp_connect __P2 (const char *,addr, int,port) tty_puts("Connected to term server...\n"); #ifdef TERM_COMPRESS send_command(newtcp_fd, C_COMPRESS, 1, "y"); -#endif +#endif send_command(newtcp_fd, C_DUMB, 1, 0); } #endif /* term */ - + tty_puts("connected!\n"); - - + + { /* * Now set some options on newtcp_fd : @@ -248,7 +248,7 @@ int tcp_connect __P2 (const char *,addr, int,port) # endif if (setsockopt(newtcp_fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt))) errmsg("setsockopt(TCP_NODELAY) failed"); - + /* TCP keep-alive */ if (setsockopt(newtcp_fd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt))) errmsg("setsockopt(SO_KEEPALIVE) failed"); @@ -257,10 +257,10 @@ int tcp_connect __P2 (const char *,addr, int,port) * Then, close-on-exec: * we don't want children to inherit the socket! */ - + fcntl(newtcp_fd, F_SETFD, FD_CLOEXEC); } - + return newtcp_fd; } @@ -268,12 +268,12 @@ int tcp_connect __P2 (const char *,addr, int,port) * we don't expect IAC commands here, except IAC IAC (a protected ASCII 255) * which we replace with a single IAC (a plain ASCII 255) */ -int tcp_unIAC __P2 (char *,buffer, int,len) +int tcp_unIAC(char *buffer, int len) { char *s, *start, warnIACs = 1; if (!memchr(buffer, IAC, len)) return len; - + for (s = start = buffer; len > 0; buffer++, len--) { if (buffer[0] == (char)(byte)IAC) { if (len > 1 && buffer[1] == (char)(byte)IAC) @@ -292,7 +292,7 @@ int tcp_unIAC __P2 (char *,buffer, int,len) * the reverse step: protect ASCII 255 as IAC IAC * the dest buffer is assumed to be big enough to hold the whole data */ -static int tcp_addIAC __P3 (char *,dest, char *,txt, int,len) +static int tcp_addIAC(char *dest, char *txt, int len) { char *s = dest; while (len-- > 0) { @@ -306,7 +306,7 @@ static int tcp_addIAC __P3 (char *,dest, char *,txt, int,len) * read a maximum of size chars from remote host * using the telnet protocol. return chars read. */ -int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) +int tcp_read(int fd, char *buffer, int maxsize) { char state = CONN_LIST(fd).state; char old_state = CONN_LIST(fd).old_state; @@ -314,7 +314,7 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) static byte subopt[MAX_SUBOPT]; static int subchars; byte *p, *s, *linestart; - + char *ibuffer = buffer; if (state == GOT_R) { /* make room for the leading \r */ @@ -324,7 +324,7 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) while ((i = read(fd, ibuffer, maxsize)) < 0 && errno == EINTR) ; - + if (i == 0) { CONN_LIST(fd).state = NORMAL; tcp_close(NULL); @@ -334,7 +334,7 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) errmsg("read from socket"); return 0; } - + /* * scan through the buffer, * interpret telnet protocol escapes and MUME MPI messages @@ -379,9 +379,9 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) /* first, flush any missing \r */ if (state == GOT_R) *p++ = '\r'; - + *p++ = *s; - + /* check for MUME MPI messages: */ if (p - linestart == MPILEN && !memcmp(linestart, MPI, MPILEN)) { if (!(CONN_LIST(fd).flags & IDEDITOR)) { @@ -396,13 +396,13 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) p = linestart; } } - + if (state != ALTNORMAL) state = NORMAL; break; } break; - + case GOTIAC: switch (*s) { case WILL: @@ -436,7 +436,7 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) break; } break; - + case GOTWILL: #ifdef TELOPTS tty_printf("[got WILL %s]\n", TELOPTSTR(*s)); @@ -465,7 +465,7 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) } state = old_state; break; - + case GOTWONT: #ifdef TELOPTS tty_printf("[got WONT %s]\n", TELOPTSTR(*s)); @@ -478,7 +478,7 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) sendopt(DONT, *s); state = old_state; break; - + case GOTDO: #ifdef TELOPTS tty_printf("[got DO %s]\n", TELOPTSTR(*s)); @@ -502,7 +502,7 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) } state = old_state; break; - + case GOTDONT: #ifdef TELOPTS tty_printf("[got DONT %s]\n", TELOPTSTR(*s)); @@ -514,7 +514,7 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) sendopt(WONT, *s); state = old_state; break; - + case GOTSB: if (*s == IAC) { state = GOTSBIAC; @@ -523,7 +523,7 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) subopt[subchars++] = *s; } break; - + case GOTSBIAC: if (*s == IAC) { if (subchars < MAX_SUBOPT) @@ -544,15 +544,15 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize) } CONN_LIST(fd).state = state; CONN_LIST(fd).old_state = old_state; - + if (!(CONN_LIST(tcp_fd).flags & SPAWN)) { log_write(buffer, (char *)p - buffer, 0); } - + return (char *)p - buffer; } -static void internal_tcp_raw_write __P3 (int,fd, const char *,data, int,len) +static void internal_tcp_raw_write(int fd, const char *data, int len) { while (len > 0) { int i; @@ -567,14 +567,14 @@ static void internal_tcp_raw_write __P3 (int,fd, const char *,data, int,len) } } -void tcp_raw_write __P3 (int,fd, const char *,data, int,len) +void tcp_raw_write(int fd, const char *data, int len) { tcp_flush(); internal_tcp_raw_write(fd, data, len); } /* write data, escape any IACs */ -void tcp_write_escape_iac __P3 (int,fd, const char *,data, int,len) +void tcp_write_escape_iac(int fd, const char *data, int len) { tcp_flush(); @@ -593,15 +593,15 @@ void tcp_write_escape_iac __P3 (int,fd, const char *,data, int,len) /* * Send current terminal size (RFC 1073) */ -void tcp_write_tty_size __P0 (void) +void tcp_write_tty_size(void) { static byte buf[] = { IAC, SB, TELOPT_NAWS, 0, 0, 0, 0, IAC, SE }; - + buf[3] = cols >> 8; buf[4] = cols & 0xff; buf[5] = lines >> 8; buf[6] = lines & 0xff; - + tcp_raw_write(tcp_main_fd, (char *)buf, 9); #ifdef TELOPTS tty_printf("[sent term size %d %d]\n", cols, lines); @@ -611,7 +611,7 @@ void tcp_write_tty_size __P0 (void) /* * send a string to the main connection on the remote host */ -void tcp_main_write __P1 (char *,data) +void tcp_main_write(char *data) { tcp_write(tcp_main_fd, data); } @@ -624,12 +624,12 @@ static int output_socket = -1; /* to which socket buffer should be sent*/ /* * put data in the output buffer for transmission to the remote host */ -void tcp_write __P2 (int,fd, char *,data) +void tcp_write(int fd, char *data) { char *iacs, *out; int len, space, iacp; len = strlen(data); - + if (tcp_main_fd != -1 && tcp_main_fd == fd) { if (linemode & LM_NOECHO) log_write("", 0, 1); /* log a newline only */ @@ -643,19 +643,19 @@ void tcp_write __P2 (int,fd, char *,data) status(1); else status(-1); - + if (fd != output_socket) { /* is there data to another socket? */ tcp_flush(); /* then flush it */ output_socket = fd; } - + out = output_buffer + output_len; space = BUFSIZE - output_len; - + while (len) { iacs = memchr(data, IAC, len); iacp = iacs ? iacs - data : len; - + if (iacp == 0) { /* we're at the IAC, send it */ if (space < 2) { @@ -667,18 +667,18 @@ void tcp_write __P2 (int,fd, char *,data) data++; len--; continue; } - + while (space < iacp) { memcpy(out, data, space); data += space; len -= space; iacp -= space; output_len = BUFSIZE; - + tcp_flush(); out = output_buffer; space = BUFSIZE; } - + if (iacp /* && space >= iacp */ ) { memcpy(out, data, iacp); out += iacp; output_len += iacp; space -= iacp; @@ -696,22 +696,22 @@ void tcp_write __P2 (int,fd, char *,data) /* * send all buffered data to the remote host */ -void tcp_flush __P0 (void) +void tcp_flush(void) { int n; char *p = output_buffer; - + if (output_len && output_socket == -1) { clear_input_line(1); PRINTF("#no open connections. Use '#connect main
' to open a connection.\n"); output_len = 0; return; } - + if (!output_len) return; - - while (output_len) { + + while (output_len) { while ((n = write(output_socket, p, output_len)) < 0 && errno == EINTR) ; if (n < 0) { @@ -723,7 +723,7 @@ void tcp_flush __P0 (void) p += n; output_len -= n; } - + if (CONN_LIST(output_socket).flags & SPAWN) status(1); else @@ -739,10 +739,10 @@ void tcp_flush __P0 (void) * return connection's fd given id, * or -1 if null or invalid id is given */ -int tcp_find __P1 (char *,id) +int tcp_find(char *id) { int i; - + for (i=0; i= MAX_CONNECTS) { PRINTF("#too many open connections.\n"); return; @@ -808,7 +808,7 @@ void tcp_open __P4 (char *,id, char *,initstring, char *,host, int,port) PRINTF("#connection \"%s\" already open.\n", id); return; } - + /* find a free slot */ for (i=0; i=0 && !CONN_INDEX(i).id); conn_max_index = i+1; } - + /* recalculate tcp_max_fd */ for (i = tcp_max_fd = 0; i=0) { CONN_LIST(sfd).flags ^= ACTIVE; @@ -973,7 +973,7 @@ void tcp_togglesnoop __P1 (char *,id) } } -void tcp_spawn __P2 (char *,id, char *,cmd) +void tcp_spawn(char *id, char *cmd) { int i, childpid, sockets[2]; @@ -986,7 +986,7 @@ void tcp_spawn __P2 (char *,id, char *,cmd) return; } unescape(cmd); - + switch (childpid = fork()) { case 0: /* child */ @@ -1007,10 +1007,10 @@ void tcp_spawn __P2 (char *,id, char *,cmd) return; } close(sockets[1]); - + /* Again, we don't want children to inherit sockets */ fcntl(sockets[0], F_SETFD, FD_CLOEXEC); - + /* now find a free slot */ for (i=0; i index translation table */ extern fd_set fdset; /* set of descriptors to select() on */ -int tcp_connect __P ((const char *addr, int port)); -int tcp_read __P ((int fd, char *buffer, int maxsize)); -void tcp_raw_write __P ((int fd, const char *data, int len)); -void tcp_write_escape_iac __P3 (int,fd, const char *,data, int,len); -void tcp_write_tty_size __P ((void)); -void tcp_write __P ((int fd, char *data)); -void tcp_main_write __P ((char *data)); -void tcp_flush __P ((void)); -void tcp_set_main __P ((int fd)); -void tcp_open __P ((char *id, char *initstring, char *host, int port)); -int tcp_find __P ((char *id)); -void tcp_show __P ((void)); -void tcp_close __P ((char *id)); -void tcp_togglesnoop __P ((char *id)); -void tcp_spawn __P ((char *id, char *cmd)); -int tcp_unIAC __P ((char *data, int len)); +int tcp_connect(const char *addr, int port); +int tcp_read(int fd, char *buffer, int maxsize); +void tcp_raw_write(int fd, const char *data, int len); +void tcp_write_escape_iac(int fd, const char *data, int len); +void tcp_write_tty_size(void); +void tcp_write(int fd, char *data); +void tcp_main_write(char *data); +void tcp_flush(void); +void tcp_set_main(int fd); +void tcp_open(char *id, char *initstring, char *host, int port); +int tcp_find(char *id); +void tcp_show(void); +void tcp_close(char *id); +void tcp_togglesnoop(char *id); +void tcp_spawn(char *id, char *cmd); +int tcp_unIAC(char *data, int len); #endif /* _TCP_H_ */ diff --git a/tty.c b/tty.c index 57aa5b6..243384b 100644 --- a/tty.c +++ b/tty.c @@ -1,6 +1,6 @@ /* * tty.c -- terminal handling routines for powwow - * + * * Copyright (C) 1998 by Massimiliano Ghilardi * * This program is free software; you can redistribute it and/or modify @@ -97,9 +97,9 @@ static char kpadstart[] = "", kpadend[] = "", begoln[] = "\r", modebold[] = "\033[1m", modeblink[] = "\033[5m", modeinv[] = "\033[7m", modeuline[] = "\033[4m", modestandon[] = "", modestandoff[] = "", modenorm[] = "\033[m", modenormbackup[4], - cursor_left[] = "\033[D", cursor_right[] = "\033[C", + cursor_left[] = "\033[D", cursor_right[] = "\033[C", cursor_up[] = "\033[A", cursor_down[] = "\033[B"; - + #define insertfinish (0) static int len_begoln = 1, len_leftcur = 3, len_upcur = 3, gotocost = 8; @@ -114,7 +114,7 @@ char *tgoto(); /* terminal escape sequences */ static char kpadstart[CAPLEN], kpadend[CAPLEN], leftcur[CAPLEN], rightcur[CAPLEN], upcur[CAPLEN], curgoto[CAPLEN], - delchar[CAPLEN], insstart[CAPLEN], insstop[CAPLEN], + delchar[CAPLEN], insstart[CAPLEN], insstop[CAPLEN], inschar[CAPLEN], begoln[CAPLEN], clreoln[CAPLEN], clreoscr[CAPLEN], cursor_left[CAPLEN], cursor_right[CAPLEN], cursor_up[CAPLEN], @@ -128,7 +128,7 @@ static char modebold[CAPLEN], modeblink[CAPLEN], modeinv[CAPLEN], static int len_begoln, len_clreoln, len_leftcur, len_upcur, gotocost, deletecost, insertcost, insertfinish, inscharcost; -static int extract __P ((char *cap, char *buf)); +static int extract(char *cap, char *buf); #endif /* USE_VT100 */ @@ -172,7 +172,7 @@ static termiostruct ttybsave; * Set the terminal to character-at-a-time-without-echo mode, and save the * original state in ttybsave */ -void tty_start __P0 (void) +void tty_start(void) { #ifdef USE_SGTTY struct sgttyb ttyb; @@ -221,7 +221,7 @@ void tty_start __P0 (void) /* * Reset the terminal to its original state */ -void tty_quit __P0 (void) +void tty_quit(void) { #ifdef USE_SGTTY ioctl(tty_read_fd, TIOCSETP, &ttybsave); @@ -240,7 +240,7 @@ void tty_quit __P0 (void) /* * enable/disable special keys depending on the current linemode */ -void tty_special_keys __P0 (void) +void tty_special_keys(void) { #ifdef USE_SGTTY struct tchars tc = {-1, -1, -1, -1, -1, -1}; @@ -285,7 +285,7 @@ void tty_special_keys __P0 (void) /* * get window size and react to any window size change */ -void tty_sig_winch_bottomhalf __P0 (void) +void tty_sig_winch_bottomhalf(void) { struct winsize wsiz; /* if ioctl fails or gives silly values, don't change anything */ @@ -298,11 +298,11 @@ void tty_sig_winch_bottomhalf __P0 (void) cols_1 = cols = wsiz.ws_col; if (!wrapglitch) cols_1--; - + if (tcp_main_fd != -1) tcp_write_tty_size(); line0 += lines - olines; - + tty_gotoxy(0, line0); /* so we know where the cursor is */ #ifdef BUG_ANSI @@ -311,7 +311,7 @@ void tty_sig_winch_bottomhalf __P0 (void) else #endif tty_puts(tty_clreoscr); - + olines = lines; status(1); } @@ -320,7 +320,7 @@ void tty_sig_winch_bottomhalf __P0 (void) /* * read termcap definitions */ -void tty_bootstrap __P0 (void) +void tty_bootstrap(void) { #ifdef USE_LOCALE tty_read_stream = stdin; @@ -407,7 +407,7 @@ void tty_bootstrap __P0 (void) gotocost = strlen(tgoto(curgoto, cols - 1, lines - 1)); insertfinish = gotocost + len_clreoln; - + /* this must be before getting window size */ wrapglitch = tgetflag("xn"); @@ -418,7 +418,7 @@ void tty_bootstrap __P0 (void) #ifdef BUG_TELNET if (strncmp(term, "vt10", 4) == 0) { /* might be NCSA Telnet 2.2 for PC, which doesn't reset colours */ - sprintf(modenorm, "\033[;%c%d;%s%dm", + sprintf(modenorm, "\033[;%c%d;%s%dm", DEFAULTFGlabel, p->seq, 0, p->funct, NULL); } while((++p)->seq[0]); - + if (*cursor_left ) add_keynode("Left" , cursor_left , 0, prev_char, NULL); if (*cursor_right) add_keynode("Right", cursor_right, 0, next_char, NULL); if (*cursor_up ) add_keynode("Up" , cursor_up , 0, prev_line, NULL); @@ -500,7 +500,7 @@ void tty_add_initial_binds __P0 (void) * extract termcap 'cap' and strcat it to buf. * return the lenght of the extracted string. */ -static int extract __P2 (char *,cap, char *,buf) +static int extract(char *cap, char *buf) { static char *bp; char *d = buf + strlen(buf); @@ -524,7 +524,7 @@ static int extract __P2 (char *,cap, char *,buf) * position the cursor using absolute coordinates * note: does not flush the output buffer */ -void tty_gotoxy __P2 (int,col, int,line) +void tty_gotoxy(int col, int line) { #ifdef USE_VT100 tty_printf("\033[%d;%dH", line + 1, col + 1); @@ -538,15 +538,15 @@ void tty_gotoxy __P2 (int,col, int,line) * from (fromcol, fromline) to (tocol, toline) * if tocol > 0, (tocol, toline) must lie on editline. */ -void tty_gotoxy_opt __P4 (int,fromcol, int,fromline, int,tocol, int,toline) +void tty_gotoxy_opt(int fromcol, int fromline, int tocol, int toline) { static char buf[BUFSIZE]; char *cp = buf; int cost, i, dist; - + CLIP(fromline, 0, lines-1); CLIP(toline , 0, lines-1); - + /* First, move vertically to the correct line, then horizontally * to the right column. If this turns out to be fewer characters * than a direct cursor positioning (tty_gotoxy), use that. @@ -612,7 +612,7 @@ void tty_gotoxy_opt __P4 (int,fromcol, int,fromline, int,tocol, int,toline) * GH: change the position on input line (gotoxy there, and set pos) * from cancan 2.6.3a */ -void input_moveto __P1 (int,new_pos) +void input_moveto(int new_pos) { /* * FEATURE: the line we are moving to might be less than 0, or greater @@ -625,7 +625,7 @@ void input_moveto __P1 (int,new_pos) new_pos = edlen; if (new_pos == pos) return; - + if (line_status == 0) { int fromline = CURLINE(pos), toline = CURLINE(new_pos); if (toline < 0) @@ -641,12 +641,12 @@ void input_moveto __P1 (int,new_pos) * delete n characters at current position (the position is unchanged) * assert(n < edlen - pos) */ -void input_delete_nofollow_chars __P1 (int,n) +void input_delete_nofollow_chars(int n) { int r_cost, p = pos, d_cost; int nl = pos - CURCOL(pos); /* this line's starting pos (can be <= 0) */ int cl = CURLINE(pos); /* current line */ - + if (n > edlen - p) n = edlen - p; if (n <= 0) @@ -658,7 +658,7 @@ void input_delete_nofollow_chars __P1 (int,n) edlen -= n; return; } - + memmove(edbuf + p, edbuf + d_cost, edlen - d_cost); memset(edbuf + edlen - n, (int)' ', n); for (;; tty_putc('\n'), p = nl, cl++) { @@ -677,17 +677,17 @@ void input_delete_nofollow_chars __P1 (int,n) #ifdef BUG_ANSI if (edattrbg) tty_puts(edattrend); -#endif +#endif for (d_cost = n; d_cost; d_cost--) tty_puts(delchar); #ifdef BUG_ANSI if (edattrbg) tty_puts(edattrbeg); -#endif +#endif if (edlen <= nl) break; - + tty_gotoxy(cols_1 - n, cl); tty_printf("%.*s", n, edbuf + nl - n); } else @@ -701,9 +701,9 @@ void input_delete_nofollow_chars __P1 (int,n) else #endif tty_printf("%.*s", r_cost, edbuf + p); - + p += r_cost; - + if (edlen <= nl) { #ifdef BUG_ANSI if (edattrbg) @@ -730,7 +730,7 @@ void input_delete_nofollow_chars __P1 (int,n) * GH: print a char on current position (overwrite), advance position * from cancan 2.6.3a */ -void input_overtype_follow __P1 (char,c) +void input_overtype_follow(char c) { if (pos >= edlen) return; @@ -753,7 +753,7 @@ void input_overtype_follow __P1 (char,c) * insert n characters at input line current position. * The position is set to after the inserted characters. */ -void input_insert_follow_chars __P2 (char *,str, int,n) +void input_insert_follow_chars(char *str, int n) { int r_cost, i_cost, p = pos; int nl = p - CURCOL(p); /* next line's starting pos */ @@ -763,14 +763,14 @@ void input_insert_follow_chars __P2 (char *,str, int,n) n = BUFSIZE - edlen - 1; if (n <= 0) return; - + memmove(edbuf + p + n, edbuf + p, edlen + 1 - p); memmove(edbuf + p, str, n); edlen += n; pos += n; - + if (line_status != 0) return; - + do { i_cost = n; if ((r_cost = edlen) > (nl += cols_1)) @@ -804,7 +804,7 @@ void input_insert_follow_chars __P2 (char *,str, int,n) line0--; } } while (edlen > nl); - + if (p != pos) tty_gotoxy_opt(CURCOL(p), cl, CURCOL(pos), CURLINE(pos)); } @@ -812,13 +812,13 @@ void input_insert_follow_chars __P2 (char *,str, int,n) #ifdef USE_LOCALE /* curses wide character support by Dain */ -void tty_puts __P ((const char *s)) +void tty_puts(const char *s) { while (*s) tty_putc(*s++); } -void tty_putc __P ((char c)) +void tty_putc(char c) { size_t r; int ignore_error = 0; @@ -844,7 +844,7 @@ again: tty_write_state.used += r; } -int tty_printf __P ((const char *format, ...)) +int tty_printf(const char *format, ...) { char buf[1024], *bufp = buf; va_list va; @@ -877,12 +877,12 @@ int tty_printf __P ((const char *format, ...)) static char tty_in_buf[MB_LEN_MAX + 1]; static size_t tty_in_buf_used = 0; -int tty_has_chars __P ((void)) +int tty_has_chars(void) { return tty_in_buf_used != 0; } -static int safe_mbtowc __P3 (wchar_t *,pwc, char *,s, size_t *,n) +static int safe_mbtowc(wchar_t *pwc, char *s, size_t *n) { static mbstate_t ps; @@ -908,7 +908,7 @@ again: return r; } -int tty_read __P ((char *buf, size_t count)) +int tty_read(char *buf, size_t count) { int result = 0; int converted; @@ -965,7 +965,7 @@ int tty_read __P ((char *buf, size_t count)) } -void tty_gets __P ((char *s, int size)) +void tty_gets(char *s, int size) { wchar_t *ws = alloca(size * sizeof *ws); @@ -979,7 +979,7 @@ void tty_gets __P ((char *s, int size)) } } -void tty_flush __P ((void)) +void tty_flush(void) { size_t n = tty_write_state.used; char *data = tty_write_state.data; @@ -1017,7 +1017,7 @@ void tty_flush __P ((void)) tty_write_state.used = 0; } -void tty_raw_write __P ((char *data, size_t len)) +void tty_raw_write(char *data, size_t len) { if (len == 0) return; diff --git a/tty.h b/tty.h index 24a3162..a4965b6 100644 --- a/tty.h +++ b/tty.h @@ -10,31 +10,28 @@ extern char *tty_clreoln, *tty_clreoscr, *tty_begoln, *tty_modenorm, *tty_modenormbackup, *tty_modeinv, *tty_modestandon, *tty_modestandoff; -void tty_bootstrap __P ((void)); -void tty_start __P ((void)); -void tty_quit __P ((void)); -void tty_special_keys __P ((void)); -void tty_sig_winch_bottomhalf __P ((void)); -void tty_add_walk_binds __P ((void)); -void tty_add_initial_binds __P ((void)); -void tty_gotoxy __P ((int col, int line)); -void tty_gotoxy_opt __P ((int fromcol, int fromline, int tocol, int toline)); - -void input_delete_nofollow_chars __P ((int n)); -void input_overtype_follow __P ((char c)); -void input_insert_follow_chars __P ((char *str, int n)); -void input_moveto __P ((int new_pos)); - -#ifndef USE_LOCALE - -#define tty_puts(s) fputs((s), stdout) -/* printf("%s", (s)); would be as good */ - - -#define tty_putc(c) putc((unsigned char)(c), stdout) -#define tty_printf printf +void tty_bootstrap(void); +void tty_start(void); +void tty_quit(void); +void tty_special_keys(void); +void tty_sig_winch_bottomhalf(void); +void tty_add_walk_binds(void); +void tty_add_initial_binds(void); +void tty_gotoxy(int col, int line); +void tty_gotoxy_opt(int fromcol, int fromline, int tocol, int toline); + +void input_delete_nofollow_chars(int n); +void input_overtype_follow(char c); +void input_insert_follow_chars(char *str, int n); +void input_moveto(int new_pos); + +#ifndef USE_LOCALE + +#define tty_puts(s) fputs((s), stdout) +#define tty_putc(c) fputc((unsigned char)(c), stdout) +#define tty_printf(...) printf(__VA_ARGS__) #define tty_read(buf, cnt) read(tty_read_fd, (buf), (cnt)) -#define tty_gets(s,size) fgets((s), (size), stdin) +#define tty_gets(s, size) fgets((s), (size), stdin) #define tty_flush() fflush(stdout) #define tty_raw_write(s,size) do { tty_flush(); write(1, (s), (size)); } while (0) @@ -47,14 +44,14 @@ void input_moveto __P ((int new_pos)); #define PRINTF_FUNCTION(string, first) #endif -void tty_puts __P ((const char *s)); -void tty_putc __P ((char c)); -int tty_printf __P ((const char *format, ...)) PRINTF_FUNCTION(1, 2); -int tty_read __P ((char *buf, size_t count)); -void tty_gets __P ((char *s, int size)); -void tty_flush __P ((void)); -void tty_raw_write __P ((char *data, size_t len)); -int tty_has_chars __P ((void)); +void tty_puts(const char *s); +void tty_putc(char c); +int tty_printf(const char *format, ...) PRINTF_FUNCTION(1, 2); +int tty_read(char *buf, size_t count); +void tty_gets(char *s, int size); +void tty_flush(void); +void tty_raw_write(char *data, size_t len); +int tty_has_chars(void); #endif /* USE_LOCALE */ diff --git a/utils.c b/utils.c index 1b2013a..2211a8c 100644 --- a/utils.c +++ b/utils.c @@ -38,7 +38,7 @@ static char can_suspend = 0; /* 1 if shell has job control */ /* * GH: memory-"safe" strdup */ -char *my_strdup __P1 (char *,s) +char *my_strdup(char *s) { if (s) { s = strdup(s); @@ -53,7 +53,7 @@ char *my_strdup __P1 (char *,s) * copy up to len chars from src to dst, then add a final \0 * (i.e. dst[len] = '\0') */ -char *my_strncpy __P3 (char *,dst, char *,src, int,len) +char *my_strncpy(char *dst, char *src, int len) { int slen = strlen(src); if (slen < len) @@ -69,7 +69,7 @@ char *my_strncpy __P3 (char *,dst, char *,src, int,len) * " [ ", " ", "". * This is not entirely universal but covers the most common cases (i.e. ansi) */ -int printstrlen __P1 (char *,s) +int printstrlen(char *s) { int l; enum { NORM, ESCAPE, BRACKET } state = NORM; @@ -83,11 +83,11 @@ int printstrlen __P1 (char *,s) } else if (*s == '\r') l = (l / cols) * cols; break; - + case ESCAPE: state = (*s == '[') ? BRACKET : NORM; break; - + case BRACKET: if (isalpha(*s)) state = NORM; @@ -100,7 +100,7 @@ int printstrlen __P1 (char *,s) /* * return pointer to next non-blank char */ -char *skipspace __P1 (char *,p) +char *skipspace(char *p) { while (*p == ' ' || *p == '\t') p++; return p; @@ -110,7 +110,7 @@ char *skipspace __P1 (char *,p) * find the first valid (non-escaped) * char in a string */ -char *first_valid __P2 (char *,p, char,ch) +char *first_valid(char *p, char ch) { if (*p && *p != ch) { p++; @@ -126,7 +126,7 @@ char *first_valid __P2 (char *,p, char,ch) * find the first regular (non-escaped, non in "" () or {} ) * char in a string */ -char *first_regular __P2 (char *,p, char,c) +char *first_regular(char *p, char c) { int escaped, quotes=0, paren=0, braces=0; @@ -168,16 +168,16 @@ char *first_regular __P2 (char *,p, char,c) /* * remove escapes (backslashes) from a string */ -int memunescape __P2 (char *,p, int,lenp) +int memunescape(char *p, int lenp) { char *start, *s; enum { NORM, ESCSINGLE, ESCAPE } state = NORM; if (!p || !*p) return 0; - + start = s = p; - + while (lenp) switch (state) { case NORM: if (*s != ESC) { @@ -192,12 +192,12 @@ int memunescape __P2 (char *,p, int,lenp) case ESCAPE: if (*s == ESC) state = ESCAPE, *p++ = *s++, lenp--; - else if (*s == ESC2) + else if (*s == ESC2) state = NORM, *p++ = ESC, s++, lenp--; else { if (state == ESCSINGLE && lenp >= 3 && ISODIGIT(s[0]) && ISODIGIT(s[1]) && ISODIGIT(s[2])) { - + *p++ = ((s[0]-'0') << 6) | ((s[1]-'0') << 3) | (s[2]-'0'); s += 3, lenp -= 3; } else @@ -212,12 +212,12 @@ int memunescape __P2 (char *,p, int,lenp) return (int)(p - start); } -void unescape __P1 (char *,s) +void unescape(char *s) { (void)memunescape(s, strlen(s)); } -void ptrunescape __P1 (ptr,p) +void ptrunescape(ptr p) { if (!p) return; @@ -227,42 +227,42 @@ void ptrunescape __P1 (ptr,p) /* * add escapes (backslashes) to src */ -ptr ptrmescape __P4 (ptr,dst, char *,src, int,srclen, int,append) +ptr ptrmescape(ptr dst, char *src, int srclen, int append) { int len; char *p; enum { NORM, ESCAPE } state; - + if (!src || srclen <= 0) { if (!append) ptrzero(dst); return dst; } - + if (dst && append) len = ptrlen(dst); else len = 0; - + dst = ptrsetlen(dst, len + srclen*4); /* worst case */ if (MEM_ERROR) return dst; - + dst->len = len; p = ptrdata(dst) + len; - + while (srclen) { state = NORM; if (*src == ESC) { while (srclen && *src == ESC) dst->len++, *p++ = *src++, srclen--; - + if (!srclen || *src == ESC2) dst->len++, *p++ = ESC2; else state = ESCAPE; } if (!srclen) break; - + if (*src < ' ' || *src > '~') { sprintf(p, "\\%03o", (int)(byte)*src++); len = strlen(p); @@ -270,7 +270,7 @@ ptr ptrmescape __P4 (ptr,dst, char *,src, int,srclen, int,append) } else { if (state == ESCAPE || strchr(SPECIAL_CHARS, *src)) dst->len++, *p++ = ESC; - + dst->len++, *p++ = *src++, srclen--; } } @@ -278,7 +278,7 @@ ptr ptrmescape __P4 (ptr,dst, char *,src, int,srclen, int,append) return dst; } -ptr ptrescape __P3 (ptr,dst, ptr,src, int,append) +ptr ptrescape(ptr dst, ptr src, int append) { if (!src) { if (!append) @@ -291,7 +291,7 @@ ptr ptrescape __P3 (ptr,dst, ptr,src, int,append) /* * add escapes to protect special characters from being escaped. */ -void escape_specials __P2 (char *,dst, char *,src) +void escape_specials(char *dst, char *src) { enum { NORM, ESCAPE } state; while (*src) { @@ -299,21 +299,21 @@ void escape_specials __P2 (char *,dst, char *,src) if (*src == ESC) { while (*src == ESC) *dst++ = *src++; - + if (!*src || *src == ESC2) *dst++ = ESC2; else state = ESCAPE; } if (!*src) break; - + if (*src < ' ' || *src > '~') { sprintf(dst, "\\%03o", (int)(byte)*src++); dst += strlen(dst); } else { if (state == ESCAPE || strchr(SPECIAL_CHARS, *src)) *dst++ = ESC; - + *dst++ = *src++; } } @@ -325,13 +325,13 @@ void escape_specials __P2 (char *,dst, char *,src) * if 1, start and end contain the match bounds * if 0, start and end are undefined on return */ -static int match_mark __P2 (marknode *,mp, char *,src) +static int match_mark(marknode *mp, char *src) { char *pat = mp->pattern; char *npat=0, *npat2=0, *nsrc=0, *prm=0, *endprm=0, *tmp, c; static char mpat[BUFSIZE]; int mbeg = mp->mbeg, mword = 0, p; - + /* shortcut for #marks without wildcards */ if (!mp->wild) { if ((nsrc = strstr(src, pat))) { @@ -343,7 +343,7 @@ static int match_mark __P2 (marknode *,mp, char *,src) } mp->start = NULL; - + if (ISMARKWILDCARD(*pat)) mbeg = - mbeg - 1; /* pattern starts with '&' or '$' */ @@ -358,22 +358,22 @@ static int match_mark __P2 (marknode *,mp, char *,src) mp->start = src; ++pat; } - + 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) - return 0; + return 0; if (mbeg > 0) { if (nsrc != src) return 0; @@ -391,8 +391,8 @@ static int match_mark __P2 (marknode *,mp, char *,src) mp->end = endprm = prm + strlen(prm); else mp->end = src; - - + + /* post-processing of param */ if (mword) { if (prm) { @@ -432,14 +432,14 @@ static int match_mark __P2 (marknode *,mp, char *,src) /* * add marks to line. write in dst. */ -ptr ptrmaddmarks __P3 (ptr,dst, char *,line, int,len) +ptr ptrmaddmarks(ptr dst, char *line, int len) { marknode *mp, *mfirst; char begin[CAPLEN], end[CAPLEN], *lineend = line + len; int start = 1, matchlen, matched = 0; - + ptrzero(dst); - + if (!line || len <= 0) return dst; @@ -459,16 +459,16 @@ ptr ptrmaddmarks __P3 (ptr,dst, char *,line, int,len) (!mfirst || mp->start < mfirst->start)) mfirst = mp; } - + if (mfirst) { start = 0; attr_string(mfirst->attrcode, begin, end); - + dst = ptrmcat(dst, line, matchlen = mfirst->start - line); if (MEM_ERROR) break; line += matchlen; len -= matchlen; - + dst = ptrmcat(dst, begin, strlen(begin)); if (MEM_ERROR) break; @@ -476,19 +476,19 @@ ptr ptrmaddmarks __P3 (ptr,dst, char *,line, int,len) if (MEM_ERROR) break; line += matchlen; len -= matchlen; - + dst = ptrmcat(dst, end, strlen(end)); if (MEM_ERROR) break; } } while (mfirst); if (!MEM_ERROR) - dst = ptrmcat(dst, line, len); - + dst = ptrmcat(dst, line, len); + return dst; } -ptr ptraddmarks __P2 (ptr,dst, ptr,line) +ptr ptraddmarks(ptr dst, ptr line) { if (line) return ptrmaddmarks(dst, ptrdata(line), ptrlen(line)); @@ -500,7 +500,7 @@ ptr ptraddmarks __P2 (ptr,dst, ptr,line) * write string to tty, word wrapping to next line if needed. * don't print a final \n */ -static void wrap_print __P1 (char *,s) +static void wrap_print(char *s) { /* ls = last space in *s, lp = last space in *p */ char *ls, *lp, *p, c, follow = 1; @@ -520,7 +520,7 @@ static void wrap_print __P1 (char *,s) #endif while (l >= cols_1 - col0 && *s) { - p = buf; m = 0; state = NORM; + p = buf; m = 0; state = NORM; lp = ls = NULL; /* this scans over the remaining part of the line adding stuff to @@ -542,7 +542,7 @@ static void wrap_print __P1 (char *,s) m++, l--; }else if (c == '\r') { ls = lp = NULL; - m = 0; + m = 0; } break; @@ -578,7 +578,7 @@ static void wrap_print __P1 (char *,s) if (ansibug) tty_printf("%s%s%s", follow ? s : "" , tty_modenorm, tty_clreoln); - else + else #endif if (follow) tty_puts(s); @@ -588,11 +588,11 @@ static void wrap_print __P1 (char *,s) * add marks to line and print. * if newline, also print a final \n */ -void smart_print __P2 (char *,line, char,newline) +void smart_print(char *line, char newline) { static ptr ptrbuf = NULL; static char *buf; - + do { if (!ptrbuf) { ptrbuf = ptrnew(PARAMLEN); @@ -602,7 +602,7 @@ void smart_print __P2 (char *,line, char,newline) if (MEM_ERROR || !ptrbuf) break; buf = ptrdata(ptrbuf); - + if (opt_wrap) wrap_print(buf); else { @@ -626,18 +626,18 @@ void smart_print __P2 (char *,line, char,newline) /* * copy first word of src into dst, and return pointer to second word of src */ -char *split_first_word __P3 (char *,dst, int,dstlen, char *,src) +char *split_first_word(char *dst, int dstlen, char *src) { char *tmp; int len; - + src = skipspace(src); if (!*src) { *dst='\0'; return src; } len = strlen(src); - + tmp = memchrs(src, len, DELIM, DELIM_LEN); if (tmp) { if (dstlen > tmp-src+1) dstlen = tmp-src+1; @@ -650,46 +650,46 @@ char *split_first_word __P3 (char *,dst, int,dstlen, char *,src) return tmp; } -static void sig_pipe_handler __P1 (int,signum) +static void sig_pipe_handler(int signum) { tty_puts("\n#broken pipe.\n"); } -static void sig_winch_handler __P1 (int,signum) +static void sig_winch_handler(int signum) { sig_pending = sig_winch_got = 1; } -static void sig_chld_handler __P1 (int,signum) +static void sig_chld_handler(int signum) { sig_pending = sig_chld_got = 1; } -static void sig_term_handler __P1 (int,signum) +static void sig_term_handler(int signum) { tty_printf("%s\n#termination signal.\n", edattrend); exit_powwow(); } -static void sig_intr_handler __P1 (int,signum) +static void sig_intr_handler(int signum) { if (confirm) { tty_printf("%s\n#interrupted.%s\n", edattrend, tty_clreoln); exit_powwow(); } - + PRINTF("%s\n#interrupted. Press again to quit%s\n", edattrend, tty_clreoln); tty_flush(); /* in case we are not in mainlupe */ confirm = 1; error = USER_BREAK; - + sig_oneshot(SIGINT, sig_intr_handler); } /* * suspend ourselves */ -void suspend_powwow __P1 (int, signum) +void suspend_powwow(int signum) { if (can_suspend) { sig_permanent(SIGTSTP, SIG_DFL); @@ -697,12 +697,12 @@ void suspend_powwow __P1 (int, signum) sig_permanent(SIGINT, SIG_IGN); tty_puts(edattrend); tty_quit(); - + if (kill(0, SIGTSTP) < 0) { errmsg("suspend powwow"); return; } - + signal_start(); tty_start(); tty_sig_winch_bottomhalf(); /* in case size changed meanwhile */ @@ -715,11 +715,11 @@ void suspend_powwow __P1 (int, signum) * GH: Sets a signal-handler permanently (like bsd signal()) * from Ilie */ -function_signal sig_permanent __P2 (int,signum, function_signal,sighandler) +function_signal sig_permanent(int signum, function_signal sighandler) { struct sigaction act; function_signal oldhandler; - + if (sigaction(signum, NULL, &act)) return SIG_ERR; oldhandler = act.sa_handler; @@ -738,11 +738,11 @@ function_signal sig_permanent __P2 (int,signum, function_signal,sighandler) * One-shot only signal. Hope it will work as intended. */ #ifdef SA_ONESHOT -function_signal sig_oneshot __P2 (int,signum, function_signal,sighandler) +function_signal sig_oneshot(int signum, function_signal sighandler) { struct sigaction act; function_signal oldhandler; - + if (sigaction(signum, NULL, &act)) return SIG_ERR; oldhandler = act.sa_handler; @@ -758,7 +758,7 @@ function_signal sig_oneshot __P2 (int,signum, function_signal,sighandler) /* * set up our signal handlers */ -void signal_start __P0 (void) +void signal_start(void) { if (sig_permanent(SIGTSTP, SIG_IGN) == SIG_DFL) { sig_permanent(SIGTSTP, suspend_powwow); @@ -776,21 +776,21 @@ void signal_start __P0 (void) sig_oneshot(SIGINT, sig_intr_handler); } -void sig_bottomhalf __P0 (void) +void sig_bottomhalf(void) { if (sig_chld_got) sig_chld_bottomhalf(); if (sig_winch_got) tty_sig_winch_bottomhalf(); - + sig_pending = sig_chld_got = sig_winch_got = 0; } -void errmsg __P1 (char *,msg) +void errmsg(char *msg) { if (!msg) msg = ""; - + clear_input_line(opt_compact); if (!opt_compact) { tty_putc('\n'); @@ -815,7 +815,7 @@ void errmsg __P1 (char *,msg) /* * print system call error message and terminate */ -void syserr __P1 (char *,msg) +void syserr(char *msg) { if (msg && *msg) { clear_input_line(opt_compact); @@ -824,13 +824,13 @@ void syserr __P1 (char *,msg) /* status(1); */ } tty_flush(); - + fprintf(stderr, "#powwow: fatal system call error:\n\t%s (%d", msg, errno); if (errno > 0) fprintf(stderr, ": %s", strerror(errno)); fprintf(stderr, ")\n"); } - + #ifdef SAVE_ON_SYSERR /* Try to do an emergency save. This can wreak havoc * if called from the wrong place, like @@ -842,15 +842,15 @@ void syserr __P1 (char *,msg) #else tty_puts("#settings NOT saved to file.\n"); #endif - + tty_quit(); exit(1); } -static void load_missing_stuff __P1 (int,n) +static void load_missing_stuff(int n) { char buf[BUFSIZE]; - + if (n < 1) { tty_add_walk_binds(); tty_puts("#default keypad settings loaded\n"); @@ -892,19 +892,19 @@ static void load_missing_stuff __P1 (int,n) * try to save the definition file even if it got * a broken or empty one. */ -int read_settings __P0 (void) +int read_settings(void) { FILE *f; char *buf, *p, *cmd, old_nice = a_nice; int failed = 1, n, savefilever = 0, left, len, limit_mem_hit = 0; varnode **first; ptr ptrbuf; - + if (!*deffile) { PRINTF("#warning: no save-file defined!\n"); return 0; } - + f = fopen(deffile, "r"); if (!f) { PRINTF("#error: cannot open file \"%s\": %s\n", deffile, strerror(errno)); @@ -919,9 +919,9 @@ int read_settings __P0 (void) buf = ptrdata(ptrbuf); left = ptrmax(ptrbuf); len = 0; - + opt_info = a_nice = 0; - + for (n = 0; n < MAX_HASH; n++) { while (aliases[n]) delete_aliasnode(&aliases[n]); @@ -941,31 +941,31 @@ int read_settings __P0 (void) while (*first) { if (is_permanent_variable(*first)) first = &(*first)->next; - else + else delete_varnode(first, 1); } } - + for (n = 0; n < NUMVAR; n++) { *var[n].num = 0; ptrdel(*var[n].str); *var[n].str = NULL; } - + while (left > 0 && fgets(buf+len, left+1, f)) { /* WARNING: accessing private field ->len */ len += n = strlen(buf+len); ptrbuf->len = len; left -= n; - /* Clear all \n prefixed with a literal backslash '\\' */ + /* Clear all \n prefixed with a literal backslash '\\' */ while ((cmd = strstr(buf, "\\\n"))) { cmd[ 0 ] = ' '; cmd[ 1 ] = ' '; } cmd = strchr(buf, '\n'); - + if (!cmd) { if (feof(f)) { PRINTF("#error: missing newline at end of file \"%s\"\n", deffile); @@ -988,11 +988,11 @@ int read_settings __P0 (void) cmd = buf; left += len; len = 0; - + cmd = skipspace(cmd); if (!*cmd) continue; - + error = 0; if (*(p = first_regular(cmd, ' '))) { *p++ = '\0'; @@ -1004,7 +1004,7 @@ int read_settings __P0 (void) } parse_user_input(cmd, 1); } - + if (error) failed = -1; else if (ferror(f) && !feof(f)) { @@ -1019,19 +1019,19 @@ int read_settings __P0 (void) PRINTF("\n#warning: config file is from an older version\n"); load_missing_stuff(savefilever); } - + fclose(f); a_nice = old_nice; - + if (ptrbuf) ptrdel(ptrbuf); - + return failed; } static char tmpname[BUFSIZE]; -static void fail_msg __P0 (void) +static void fail_msg(void) { PRINTF("#error: cannot write to temporary file \"%s\": %s\n", tmpname, strerror(errno)); } @@ -1042,7 +1042,7 @@ static void fail_msg __P0 (void) * NEVER call syserr() from here or powwow will * enter an infinite loop! */ -int save_settings __P0 (void) +int save_settings(void) { FILE *f; int l; @@ -1060,7 +1060,7 @@ int save_settings __P0 (void) return -1; } error = 0; - + if (!*deffile) { PRINTF("#warning: no save-file defined!\n"); return -1; @@ -1076,20 +1076,20 @@ int save_settings __P0 (void) l--; if (l) l++; - + sprintf(tmpname + l, "tmpsav%d%d", getpid(), rand() >> 8); if (!(f = fopen(tmpname, "w"))) { fail_msg(); return -1; } - + pp = ptrnew(PARAMLEN); if (MEM_ERROR) failed = -1; failed = fprintf(f, "#savefile-version %d\n", SAVEFILEVER); if (failed > 0 && *hostname) failed = fprintf(f, "#host %s %d\n", hostname, portnumber); - + if (failed > 0) { if (delim_mode == DELIM_CUSTOM) { pp = ptrmescape(pp, DELIM, strlen(DELIM), 0); @@ -1105,7 +1105,7 @@ int save_settings __P0 (void) if (failed > 0 && *initstr) failed = fprintf(f, "#init =%s\n", initstr); - + if (failed > 0 && limit_mem) failed = fprintf(f, "#setvar mem=%d\n", limit_mem); @@ -1119,18 +1119,18 @@ int save_settings __P0 (void) if (MEM_ERROR) { failed = -1; break; } failed = fprintf(f, "#alias %s%s%s=%s\n", ptrdata(pp), alp -> group == NULL ? "" : group_delim, - alp -> group == NULL ? "" : alp -> group, + alp -> group == NULL ? "" : alp -> group, alp->subst); } reverse_sortedlist((sortednode **)&sortedaliases); } - + for (acp = actions; acp && failed > 0; acp = acp->next) { failed = fprintf(f, "#action %c%c%s%s%s %s=%s\n", action_chars[acp->type], acp->active ? '+' : '-', - acp->label, + acp->label, acp -> group == NULL ? "" : group_delim, - acp -> group == NULL ? "" : acp -> group, + acp -> group == NULL ? "" : acp -> group, acp->pattern, acp->command); } @@ -1139,7 +1139,7 @@ int save_settings __P0 (void) action_chars[ptp->type], ptp->active ? '+' : '-', ptp->label, ptp->pattern, ptp->command); } - + for (mp = markers; mp && failed > 0; mp = mp->next) { pp = ptrmescape(pp, mp->pattern, strlen(mp->pattern), 0); if (MEM_ERROR) { failed = -1; break; } @@ -1147,7 +1147,7 @@ int save_settings __P0 (void) ptrdata(pp), attr_name(mp->attrcode)); } /* save value of global variables */ - + for (flag = 0, i=0; i 0; i++) { if (var[i].num && *var[i].num) { /* first check was missing!!! */ failed = fprintf(f, "%s@%d = %ld", flag ? ", " : "#(", @@ -1156,7 +1156,7 @@ int save_settings __P0 (void) } } if (failed > 0 && flag) failed = fprintf(f, ")\n"); - + for (i=0; i 0; i++) { if (var[i].str && *var[i].str && ptrlen(*var[i].str)) { pp = ptrescape(pp, *var[i].str, 0); @@ -1164,7 +1164,7 @@ int save_settings __P0 (void) failed = fprintf(f, "#($%d = \"%s\")\n", i-NUMVAR, ptrdata(pp)); } } - + if (failed > 0) { reverse_sortedlist((sortednode **)&sortednamed_vars[0]); for (flag = 0, vp = sortednamed_vars[0]; vp && failed > 0; vp = vp->snext) { @@ -1177,7 +1177,7 @@ int save_settings __P0 (void) reverse_sortedlist((sortednode **)&sortednamed_vars[0]); } if (failed > 0 && flag) failed = fprintf(f, ")\n"); - + if (failed > 0) { reverse_sortedlist((sortednode **)&sortednamed_vars[1]); for (vp = sortednamed_vars[1]; vp && failed > 0; vp = vp->snext) { @@ -1189,7 +1189,7 @@ int save_settings __P0 (void) } reverse_sortedlist((sortednode **)&sortednamed_vars[1]); } - + /* GH: fixed the history and word completions saves */ if (failed > 0 && opt_history) { l = (curline + 1) % MAX_HIST; @@ -1203,7 +1203,7 @@ int save_settings __P0 (void) l = 0; } } - + if (failed > 0 && opt_words) { int cl = 4, len; l = wordindex; @@ -1226,10 +1226,10 @@ int save_settings __P0 (void) if (failed > 0 && flag) failed = fprintf(f, "\n"); } - + for (kp = keydefs; kp && failed > 0; kp = kp->next) { if (kp->funct==key_run_command) - failed = fprintf(f, "#bind %s %s=%s\n", kp->name, + failed = fprintf(f, "#bind %s %s=%s\n", kp->name, seq_name(kp->sequence, kp->seqlen), kp->call_data); else failed = fprintf(f, "#bind %s %s=%s%s%s\n", kp->name, @@ -1238,12 +1238,12 @@ int save_settings __P0 (void) kp->call_data ? " " : "", kp->call_data ? kp->call_data : ""); } - + if (failed > 0) failed = print_all_options(f); fclose(f); - + if (error) errmsg("malloc"); else if (failed <= 0) @@ -1256,17 +1256,17 @@ int save_settings __P0 (void) } else failed = 1; } - + if (pp) ptrdel(pp); - + return failed > 0 ? 1 : -1; } /* * update "now" to current time */ -void update_now __P0 (void) +void update_now(void) { if (!now_updated) { gettimeofday(&now, NULL); @@ -1277,7 +1277,7 @@ void update_now __P0 (void) /* * terminate powwow as cleanly as possible */ -void exit_powwow __P0 (void) +void exit_powwow(void) { log_flush(); if (capturefile) fclose(capturefile); diff --git a/utils.h b/utils.h index 1386301..f5b8704 100644 --- a/utils.h +++ b/utils.h @@ -3,46 +3,46 @@ #ifndef _UTILS_H_ #define _UTILS_H_ -char *my_strdup __P ((char *s)); -char *my_strncpy __P ((char *dst, char *src, int len)); -int printstrlen __P ((char *s)); - -void ptrunescape __P ((ptr p)); -int memunescape __P ((char *p, int lenp)); - -ptr ptrescape __P ((ptr dst, ptr src, int append)); -ptr ptrmescape __P ((ptr dst, char *src, int srclen, int append)); - -ptr ptraddmarks __P ((ptr dst, ptr line)); -ptr ptrmaddmarks __P ((ptr dst, char *line, int len)); - -void put_marks __P ((char *dst, char *line)); -void smart_print __P ((char *line, char newline)); -char *split_first_word __P ((char *dst, int dstlen, char *src)); -char *first_valid __P ((char *p, char ch)); -char *first_regular __P ((char *p, char c)); -void unescape __P ((char *s)); -void escape_specials __P ((char *str, char *p)); -char *skipspace __P ((char *p)); -void exit_powwow __P ((void)); -void suspend_powwow __P ((int signum)); -function_signal sig_permanent __P ((int signum, function_signal sighandler)); +char *my_strdup(char *s); +char *my_strncpy(char *dst, char *src, int len); +int printstrlen(char *s); + +void ptrunescape(ptr p); +int memunescape(char *p, int lenp); + +ptr ptrescape(ptr dst, ptr src, int append); +ptr ptrmescape(ptr dst, char *src, int srclen, int append); + +ptr ptraddmarks(ptr dst, ptr line); +ptr ptrmaddmarks(ptr dst, char *line, int len); + +void put_marks(char *dst, char *line); +void smart_print(char *line, char newline); +char *split_first_word(char *dst, int dstlen, char *src); +char *first_valid(char *p, char ch); +char *first_regular(char *p, char c); +void unescape(char *s); +void escape_specials(char *str, char *p); +char *skipspace(char *p); +void exit_powwow(void); +void suspend_powwow(int signum); +function_signal sig_permanent(int signum, function_signal sighandler); #ifdef SA_ONESHOT - function_signal sig_oneshot __P ((int signum, function_signal sighandler)); + function_signal sig_oneshot(int signum, function_signal sighandler); #else # define sig_oneshot signal #endif -void signal_start __P ((void)); -void sig_bottomhalf __P ((void)); -void errmsg __P ((char *msg)); -void syserr __P ((char *msg)); -int read_settings __P ((void)); -int save_settings __P ((void)); -void movie_write __P ((char *str, int newline)); +void signal_start(void); +void sig_bottomhalf(void); +void errmsg(char *msg); +void syserr(char *msg); +int read_settings(void); +int save_settings(void); +void movie_write(char *str, int newline); -void update_now __P ((void)); +void update_now(void); #endif /* _UTILS_H_ */ -- cgit v0.10.2