$NetBSD: patch-ab,v 1.1.1.1 1999/10/08 04:34:43 dbj Exp $

Index: chat/chat.c
diff -u chat/chat.c:1.1.1.5 chat/chat.c:1.18
--- chat/chat.c:1.1.1.5	Tue Aug 24 19:50:04 1999
+++ chat/chat.c	Tue Aug 24 20:15:00 1999
@@ -144,18 +150,6 @@
 				 "unknown error")
 #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=='-'\
-				&&!v[0][1]?(--c,++v,0):(_O=2,*(*v)++):0))
-#define	OPTARG(c,v)	(_O&2?**v||(++v,--c)?(_O=1,--c,*v++): \
-				(_O=4,(char*)0):(char*)0)
-#define	OPTONLYARG(c,v)	(_O&2&&**v?(_O=1,--c,*v++):(char*)0)
-#define	ARG(c,v)	(c?(--c,*v++):(char*)0)
-
-static int _O = 0;		/* Internal state */
-/*************** Micro getopt() *********************************************/
-
 char *program_name;
 
 #define	MAX_ABORTS		50
@@ -269,12 +263,12 @@
      char **argv;
 {
     int option;
-    char *arg;
+    int i;
 
     program_name = *argv;
     tzset();
 
-    while ((option = OPTION(argc, argv)) != 0) {
+    while ((option = getopt(argc, argv, ":evVf:t:r:sST:U:")) != -1) {
 	switch (option) {
 	case 'e':
 	    ++echo;
@@ -297,25 +291,24 @@
 	    break;
 
 	case 'f':
-	    if ((arg = OPTARG(argc, argv)) != NULL)
-		    chat_file = copy_of(arg);
+	    if (optarg != NULL)
+		    chat_file = copy_of(optarg);
 	    else
 		usage();
 	    break;
 
 	case 't':
-	    if ((arg = OPTARG(argc, argv)) != NULL)
-		timeout = atoi(arg);
+	    if (optarg != NULL)
+		timeout = atoi(optarg);
 	    else
 		usage();
 	    break;
 
 	case 'r':
-	    arg = OPTARG (argc, argv);
-	    if (arg) {
+	    if (optarg) {
 		if (report_fp != NULL)
 		    fclose (report_fp);
-		report_file = copy_of (arg);
+		report_file = copy_of (optarg);
 		report_fp   = fopen (report_file, "a");
 		if (report_fp != NULL) {
 		    if (verbose)
@@ -327,15 +320,15 @@
 	    break;
 
 	case 'T':
-	    if ((arg = OPTARG(argc, argv)) != NULL)
-		phone_num = copy_of(arg);
+	    if (optarg != NULL)
+		phone_num = copy_of(optarg);
 	    else
 		usage();
 	    break;
 
 	case 'U':
-	    if ((arg = OPTARG(argc, argv)) != NULL)
-		phone_num2 = copy_of(arg);
+	    if (optarg != NULL)
+		phone_num2 = copy_of(optarg);
 	    else
 		usage();
 	    break;
@@ -345,6 +338,8 @@
 	    break;
 	}
     }
+    argc -= optind;
+    argv += optind;
 /*
  * Default the report file to the stderr location
  */
@@ -367,17 +362,15 @@
     init();
     
     if (chat_file != NULL) {
-	arg = ARG(argc, argv);
-	if (arg != NULL)
+	if (argc)
 	    usage();
 	else
 	    do_file (chat_file);
     } else {
-	while ((arg = ARG(argc, argv)) != NULL) {
-	    chat_expect(arg);
-
-	    if ((arg = ARG(argc, argv)) != NULL)
-		chat_send(arg);
+	for (i = 0; i < argc; i++) {
+	    chat_expect(argv[i]);
+	    if (++i < argc)
+		chat_send(argv[i]);
 	}
     }
 
@@ -590,7 +583,7 @@
     have_tty_parameters  = 1;
 
     t.c_iflag     |= IGNBRK | ISTRIP | IGNPAR;
-    t.c_oflag      = 0;
+    t.c_oflag     |= OPOST | ONLCR;
     t.c_lflag      = 0;
     t.c_cc[VERASE] =
     t.c_cc[VKILL]  = 0;
