* (614)451-1883
*/
-static char rcsid[] = "$Id: chat.c,v 1.5 1995/01/11 03:14:45 paulus Exp $";
+static char rcsid[] = "$Id: chat.c,v 1.8 1995/05/19 04:19:29 paulus Exp $";
#include <stdio.h>
#include <fcntl.h>
#define const
#endif
+#ifndef O_NONBLOCK
+#define O_NONBLOCK FNDELAY
+#endif
+
/*************** Micro getopt() *********************************************/
#define OPTION(c,v) (_O&2&&**v?*(*v)++:!c||_O&4?0:(!(_O&1)&& \
(--c,++v),_O=4,c&&**v=='-'&&v[0][1]?*++*v=='-'\
void break_sequence __P((void));
void terminate __P((int status));
void do_file __P((char *chat_file));
-void delay __P((void));
int get_string __P((register char *string));
int put_string __P((register char *s));
int write_char __P((int c));
-int put_char __P((char c));
+int put_char __P((int c));
int get_char __P((void));
void chat_send __P((register char *s));
-char *character __P((char c));
+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));
if ((flags = fcntl(0, F_GETFL, 0)) == -1)
sysfatal("Can't get file mode flags on stdin");
else
- if (fcntl(0, F_SETFL, flags | FNDELAY) == -1)
+ if (fcntl(0, F_SETFL, flags | O_NONBLOCK) == -1)
sysfatal("Can't set file mode flags on stdin");
if (verbose)
if ((flags = fcntl(0, F_GETFL, 0)) == -1)
sysfatal("Can't get file mode flags on stdin");
else
- if (fcntl(0, F_SETFL, flags & ~FNDELAY) == -1)
+ if (fcntl(0, F_SETFL, flags & ~O_NONBLOCK) == -1)
sysfatal("Can't set file mode flags on stdin");
}
}
char *character(c)
-char c;
+int c;
{
static char string[10];
char *meta;
s1 = clean(s, 0);
- if (strlen(s1) > strlen(s) || strlen(s1) > sizeof fail_buffer - 1)
+ if (strlen(s1) > strlen(s)
+ || strlen(s1) + 1 > sizeof(fail_buffer))
{
syslog(LOG_WARNING, "Illegal or too-long ABORT string ('%s')", s);
die();
if ((status = fcntl(0, F_GETFL, 0)) == -1)
sysfatal("Can't get file mode flags on stdin");
else
- if (fcntl(0, F_SETFL, status & ~FNDELAY) == -1)
+ if (fcntl(0, F_SETFL, status & ~O_NONBLOCK) == -1)
sysfatal("Can't set file mode flags on stdin");
return (-1);
}
int put_char(c)
-char c;
+int c;
{
int status;
+ char ch = c;
- delay();
+ usleep(10000); /* inter-character typing delay (?) */
- status = write(1, &c, 1);
+ status = write(1, &ch, 1);
switch (status)
{
if ((status = fcntl(0, F_GETFL, 0)) == -1)
sysfatal("Can't get file mode flags on stdin");
else
- if (fcntl(0, F_SETFL, status & ~FNDELAY) == -1)
+ if (fcntl(0, F_SETFL, status & ~O_NONBLOCK) == -1)
sysfatal("Can't set file mode flags on stdin");
return (-1);
return (0);
}
-#ifdef ultrix
-#undef NO_USLEEP
+#ifdef NO_USLEEP
#include <sys/types.h>
#include <sys/time.h>
return select( 0, (long *)0, (long *)0, (long *)0, &delay );
}
#endif
-
-/*
- * Delay an amount appropriate for between typed characters.
- */
-void delay()
- {
-# ifdef NO_USLEEP
- register int i;
-
- for (i = 0; i < 30000; ++i) /* ... did we just say appropriate? */
- ;
-# else /* NO_USLEEP */
- usleep(100);
-# endif /* NO_USLEEP */
- }