move log file to /var/games
[unix-history] / usr / src / games / battlestar / getcom.c
index c52bfa7..e6cf5de 100644 (file)
@@ -1,6 +1,23 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)getcom.c   1.1 %G%";
-#endif
+static char sccsid[] = "@(#)getcom.c   5.2 (Berkeley) %G%";
+#endif /* not lint */
 
 #include <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -13,8 +30,10 @@ getcom(buf, size, prompt, error)
 {
        for (;;) {
                fputs(prompt, stdout); 
 {
        for (;;) {
                fputs(prompt, stdout); 
-               if (fgets(buf, size, stdin) == 0)
-                       exit(1);
+               if (fgets(buf, size, stdin) == 0) {
+                       clearerr(stdin);
+                       continue;
+               }
                while (isspace(*buf))
                        buf++;
                if (*buf)
                while (isspace(*buf))
                        buf++;
                if (*buf)
@@ -25,13 +44,16 @@ getcom(buf, size, prompt, error)
        return (buf);
 }
 
        return (buf);
 }
 
+
+/*
+ * shifts to UPPERCASE if flag > 0, lowercase if flag < 0,
+ * and leaves it unchanged if flag = 0
+ */
 char *
 getword(buf1, buf2, flag)
 char *
 getword(buf1, buf2, flag)
-       char *buf1, *buf2;
+       register char *buf1, *buf2;
+       register flag;
 {
 {
-       /* shifts to UPPERCASE if flag > 0, lowercase if    */
-       /* flag < 0, and leaves it unchanged if flag = 0    */
-
        while (isspace(*buf1))
                buf1++;
        if (*buf1 != ',') {
        while (isspace(*buf1))
                buf1++;
        if (*buf1 != ',') {
@@ -40,7 +62,18 @@ getword(buf1, buf2, flag)
                        return (0);
                }
                while (*buf1 && !isspace(*buf1) && *buf1 != ',')
                        return (0);
                }
                while (*buf1 && !isspace(*buf1) && *buf1 != ',')
-                       *buf2++ = shift(*buf1++, flag);
+                       if (flag < 0)
+                               if (isupper(*buf1))
+                                       *buf2++ = tolower(*buf1++);
+                               else
+                                       *buf2++ = *buf1++;
+                       else if (flag > 0)
+                               if (islower(*buf1))
+                                       *buf2++ = toupper(*buf1++);
+                               else
+                                       *buf2++ = *buf1++;
+                       else
+                               *buf2++ = *buf1++;
        } else
                *buf2++ = *buf1++;
        *buf2 = 0;
        } else
                *buf2++ = *buf1++;
        *buf2 = 0;
@@ -48,14 +81,3 @@ getword(buf1, buf2, flag)
                buf1++;
        return (*buf1 ? buf1 : 0);
 }
                buf1++;
        return (*buf1 ? buf1 : 0);
 }
-
-shift(c, flg)
-       char c;
-       int flg;
-{
-       if (flg < 0)
-               return isupper(c) ? tolower(c) : c;
-       if (flg > 0)
-               return islower(c) ? toupper(c) : c;
-       return c;
-}