summaryrefslogtreecommitdiff
path: root/chat
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@ozlabs.org>2020-12-29 16:08:24 +1100
committerPaul Mackerras <paulus@ozlabs.org>2020-12-29 16:08:24 +1100
commit75870d7b55e36af526a0786fff94912989c73fd1 (patch)
tree1de0db83a52899c60f3b7abc0934e377a1667ab7 /chat
parent505ec5cbd15ec23ed84282462ae9e451a1978133 (diff)
downloadppp-75870d7b55e36af526a0786fff94912989c73fd1.tar.gz
Convert to ANSI C
This gets rid of the __P and __V macros that were used so that the code was in theory compilable by a K&R C compiler, and converts the function definitions to ANSI C style. In fact there were already quite a few function definitions in the ANSI C style, so it would not have been compilable by a K&R C compiler in fact. The Solaris and BSD kernel code modules have had __P removed but the function definitions have not been converted. There are some other minor changes here to remove warnings. Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Diffstat (limited to 'chat')
-rw-r--r--chat/chat.c205
1 files changed, 70 insertions, 135 deletions
diff --git a/chat/chat.c b/chat/chat.c
index bf10733..1639b3e 100644
--- a/chat/chat.c
+++ b/chat/chat.c
@@ -82,14 +82,6 @@
*
*/
-#ifndef __STDC__
-#define const
-#endif
-
-#ifndef lint
-static const char rcsid[] = "$Id: chat.c,v 1.30 2004/01/17 05:47:55 carlsonj Exp $";
-#endif
-
#include <stdio.h>
#include <ctype.h>
#include <time.h>
@@ -102,6 +94,7 @@ static const char rcsid[] = "$Id: chat.c,v 1.30 2004/01/17 05:47:55 carlsonj Exp
#include <sys/types.h>
#include <sys/stat.h>
#include <syslog.h>
+#include <stdarg.h>
#ifndef TERMIO
#undef TERMIOS
@@ -121,20 +114,6 @@ static const char rcsid[] = "$Id: chat.c,v 1.30 2004/01/17 05:47:55 carlsonj Exp
#define SIGTYPE void
#endif
-#undef __P
-#undef __V
-
-#ifdef __STDC__
-#include <stdarg.h>
-#define __V(x) x
-#define __P(x) x
-#else
-#include <varargs.h>
-#define __V(x) (va_alist) va_dcl
-#define __P(x) ()
-#define const
-#endif
-
#ifndef O_NONBLOCK
#define O_NONBLOCK O_NDELAY
#endif
@@ -209,43 +188,41 @@ int clear_report_next = 0;
int say_next = 0, hup_next = 0;
-void *dup_mem __P((void *b, size_t c));
-void *copy_of __P((char *s));
-char *grow __P((char *s, char **p, size_t len));
-void usage __P((void));
-void msgf __P((const char *fmt, ...));
-void fatal __P((int code, const char *fmt, ...));
-SIGTYPE sigalrm __P((int signo));
-SIGTYPE sigint __P((int signo));
-SIGTYPE sigterm __P((int signo));
-SIGTYPE sighup __P((int signo));
-void unalarm __P((void));
-void init __P((void));
-void set_tty_parameters __P((void));
-void echo_stderr __P((int));
-void break_sequence __P((void));
-void terminate __P((int status));
-void do_file __P((char *chat_file));
-int get_string __P((register char *string));
-int put_string __P((register char *s));
-int write_char __P((int c));
-int put_char __P((int c));
-int get_char __P((void));
-void chat_send __P((register char *s));
-char *character __P((int c));
-void chat_expect __P((register char *s));
-char *clean __P((register char *s, int sending));
-void break_sequence __P((void));
-void terminate __P((int status));
-void pack_array __P((char **array, int end));
-char *expect_strtok __P((char *, char *));
-int vfmtmsg __P((char *, int, const char *, va_list)); /* vsprintf++ */
-
-int main __P((int, char *[]));
-
-void *dup_mem(b, c)
-void *b;
-size_t c;
+void *dup_mem (void *b, size_t c);
+void *copy_of (char *s);
+char *grow (char *s, char **p, size_t len);
+void usage (void);
+void msgf (const char *fmt, ...);
+void fatal (int code, const char *fmt, ...);
+SIGTYPE sigalrm (int signo);
+SIGTYPE sigint (int signo);
+SIGTYPE sigterm (int signo);
+SIGTYPE sighup (int signo);
+void unalarm (void);
+void init (void);
+void set_tty_parameters (void);
+void echo_stderr (int);
+void break_sequence (void);
+void terminate (int status);
+void do_file (char *chat_file);
+int get_string (register char *string);
+int put_string (register char *s);
+int write_char (int c);
+int put_char (int c);
+int get_char (void);
+void chat_send (register char *s);
+char *character (int c);
+void chat_expect (register char *s);
+char *clean (register char *s, int sending);
+void break_sequence (void);
+void terminate (int status);
+void pack_array (char **array, int end);
+char *expect_strtok (char *, char *);
+int vfmtmsg (char *, int, const char *, va_list); /* vsprintf++ */
+
+int main (int, char *[]);
+
+void *dup_mem(void *b, size_t c)
{
void *ans = malloc (c);
if (!ans)
@@ -255,17 +232,13 @@ size_t c;
return ans;
}
-void *copy_of (s)
-char *s;
+void *copy_of (char *s)
{
return dup_mem (s, strlen (s) + 1);
}
/* grow a char buffer and keep a pointer offset */
-char *grow(s, p, len)
-char *s;
-char **p;
-size_t len;
+char *grow(char *s, char **p, size_t len)
{
size_t l = *p - s; /* save p as distance into s */
@@ -284,9 +257,7 @@ size_t len;
* Perform a UUCP-dialer-like chat script on stdin and stdout.
*/
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char **argv)
{
int option;
char *arg;
@@ -413,8 +384,7 @@ main(argc, argv)
* Process a chat script when read from a file.
*/
-void do_file (chat_file)
-char *chat_file;
+void do_file (char *chat_file)
{
int linect, sendflg;
char *sp, *arg, quote;
@@ -482,7 +452,7 @@ char *chat_file;
/*
* We got an error parsing the command line.
*/
-void usage()
+void usage(void)
{
fprintf(stderr, "\
Usage: %s [-e] [-E] [-v] [-V] [-t timeout] [-r report-file]\n\
@@ -495,17 +465,11 @@ char line[1024];
/*
* Send a message to syslog and/or stderr.
*/
-void msgf __V((const char *fmt, ...))
+void msgf(const char *fmt, ...)
{
va_list args;
-#ifdef __STDC__
va_start(args, fmt);
-#else
- char *fmt;
- va_start(args);
- fmt = va_arg(args, char *);
-#endif
vfmtmsg(line, sizeof(line), fmt, args);
if (to_log)
@@ -519,19 +483,11 @@ void msgf __V((const char *fmt, ...))
* Print an error message and terminate.
*/
-void fatal __V((int code, const char *fmt, ...))
+void fatal(int code, const char *fmt, ...)
{
va_list args;
-#ifdef __STDC__
va_start(args, fmt);
-#else
- int code;
- char *fmt;
- va_start(args);
- code = va_arg(args, int);
- fmt = va_arg(args, char *);
-#endif
vfmtmsg(line, sizeof(line), fmt, args);
if (to_log)
@@ -544,8 +500,7 @@ void fatal __V((int code, const char *fmt, ...))
int alarmed = 0;
-SIGTYPE sigalrm(signo)
-int signo;
+SIGTYPE sigalrm(int signo)
{
int flags;
@@ -563,7 +518,7 @@ int signo;
msgf("alarm");
}
-void unalarm()
+void unalarm(void)
{
int flags;
@@ -574,25 +529,22 @@ void unalarm()
fatal(2, "Can't set file mode flags on stdin: %m");
}
-SIGTYPE sigint(signo)
-int signo;
+SIGTYPE sigint(int signo)
{
fatal(2, "SIGINT");
}
-SIGTYPE sigterm(signo)
-int signo;
+SIGTYPE sigterm(int signo)
{
fatal(2, "SIGTERM");
}
-SIGTYPE sighup(signo)
-int signo;
+SIGTYPE sighup(int signo)
{
fatal(2, "SIGHUP");
}
-void init()
+void init(void)
{
signal(SIGINT, sigint);
signal(SIGTERM, sigterm);
@@ -604,7 +556,7 @@ void init()
alarmed = 0;
}
-void set_tty_parameters()
+void set_tty_parameters(void)
{
#if defined(get_term_param)
term_parms t;
@@ -628,15 +580,14 @@ void set_tty_parameters()
#endif
}
-void break_sequence()
+void break_sequence(void)
{
#ifdef TERMIOS
tcsendbreak (0, 0);
#endif
}
-void terminate(status)
-int status;
+void terminate(int status)
{
static int terminating = 0;
@@ -683,9 +634,8 @@ int status;
/*
* 'Clean up' this string.
*/
-char *clean(s, sending)
-register char *s;
-int sending; /* set to 1 when sending (putting) this string. */
+char *clean(register char *s,
+ int sending) /* set to 1 when sending (putting) this string. */
{
char cur_chr;
char *s1, *p, *phchar;
@@ -870,8 +820,7 @@ int sending; /* set to 1 when sending (putting) this string. */
* A modified version of 'strtok'. This version skips \ sequences.
*/
-char *expect_strtok (s, term)
- char *s, *term;
+char *expect_strtok (char *s, char *term)
{
static char *str = "";
int escape_flag = 0;
@@ -925,8 +874,7 @@ char *expect_strtok (s, term)
* Process the expect string
*/
-void chat_expect (s)
-char *s;
+void chat_expect (char *s)
{
char *expect;
char *reply;
@@ -1014,8 +962,7 @@ char *s;
* the data.
*/
-char *character(c)
-int c;
+char *character(int c)
{
static char string[10];
char *meta;
@@ -1036,8 +983,7 @@ int c;
/*
* process the reply string
*/
-void chat_send (s)
-register char *s;
+void chat_send (register char *s)
{
char file_data[STR_LEN];
@@ -1227,7 +1173,7 @@ register char *s;
fatal(1, "Failed");
}
-int get_char()
+int get_char(void)
{
int status;
char c;
@@ -1252,8 +1198,7 @@ int get_char()
}
}
-int put_char(c)
-int c;
+int put_char(int c)
{
int status;
char ch = c;
@@ -1280,8 +1225,7 @@ int c;
}
}
-int write_char (c)
-int c;
+int write_char(int c)
{
if (alarmed || put_char(c) < 0) {
alarm(0);
@@ -1298,8 +1242,7 @@ int c;
return (1);
}
-int put_string (s)
-register char *s;
+int put_string(register char *s)
{
quiet = 0;
s = clean(s, 1);
@@ -1353,8 +1296,7 @@ register char *s;
* When called with -1, a '\n' character is generated when
* the cursor is not at the beginning of a line.
*/
-void echo_stderr(n)
-int n;
+void echo_stderr(int n)
{
static int need_lf;
char *s;
@@ -1381,8 +1323,7 @@ int n;
/*
* 'Wait for' this string to appear on this file descriptor.
*/
-int get_string(string)
-register char *string;
+int get_string(register char *string)
{
char temp[STR_LEN];
int c, printed = 0, len, minlen;
@@ -1550,9 +1491,8 @@ register char *string;
extern int select();
-int
-usleep( usec ) /* returns 0 if ok, else -1 */
- long usec; /* delay in microseconds */
+/* returns 0 if ok, else -1 */
+int usleep(long usec) /* delay in microseconds */
{
static struct { /* `timeval' */
long tv_sec; /* seconds */
@@ -1566,10 +1506,9 @@ usleep( usec ) /* returns 0 if ok, else -1 */
}
#endif
-void
-pack_array (array, end)
- char **array; /* The address of the array of string pointers */
- int end; /* The index of the next free entry before CLR_ */
+void pack_array (
+ char **array, /* The address of the array of string pointers */
+ int end) /* The index of the next free entry before CLR_ */
{
int i, j;
@@ -1595,11 +1534,7 @@ pack_array (array, end)
#define OUTCHAR(c) (buflen > 0? (--buflen, *buf++ = (c)): 0)
int
-vfmtmsg(buf, buflen, fmt, args)
- char *buf;
- int buflen;
- const char *fmt;
- va_list args;
+vfmtmsg(char *buf, int buflen, const char *fmt, va_list args)
{
int c, i, n;
int width, prec, fillch;