changing window size, new struct ww
[unix-history] / usr / src / usr.bin / window / scanner.c
index 27269a7..41f0010 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)scanner.c   3.4 84/04/11";
+static char sccsid[] = "@(#)scanner.c  3.7 %G%";
 #endif
 
 #include <stdio.h>
 #endif
 
 #include <stdio.h>
@@ -54,30 +54,22 @@ s_gettok()
        register char *p = buf;
        register c;
        register state = 0;
        register char *p = buf;
        register c;
        register state = 0;
-       char quote;
 
 loop:
        c = s_getc();
        switch (state) {
 
 loop:
        c = s_getc();
        switch (state) {
-       case 0:                         /* blank skipping */
+       case 0:
                switch (c) {
                case ' ':
                case '\t':
                        break;
                switch (c) {
                case ' ':
                case '\t':
                        break;
-               default:
-                       (void) s_ungetc(c);
-                       state = 1;
-               }
-               break;
-       case 1:                         /* beginning of token */
-               switch (c) {
                case '\n':
                case ';':
                        cx.x_token = T_EOL;
                        state = -1;
                        break;
                case '#':
                case '\n':
                case ';':
                        cx.x_token = T_EOL;
                        state = -1;
                        break;
                case '#':
-                       state = 4;
+                       state = 1;
                        break;
                case EOF:
                        cx.x_token = T_EOF;
                        break;
                case EOF:
                        cx.x_token = T_EOF;
@@ -100,10 +92,11 @@ loop:
                        state = 2;
                        break;
                case '"':
                        state = 2;
                        break;
                case '"':
-               case '\'':
-                       quote = c;
                        state = 3;
                        break;
                        state = 3;
                        break;
+               case '\'':
+                       state = 4;
+                       break;
                case '\\':
                        switch (c = s_gettok1()) {
                        case -1:
                case '\\':
                        switch (c = s_gettok1()) {
                        case -1:
@@ -143,6 +136,9 @@ loop:
                case '|':
                        state = 25;
                        break;
                case '|':
                        state = 25;
                        break;
+               case '$':
+                       state = 26;
+                       break;
                case '~':
                        cx.x_token = T_COMP;
                        state = -1;
                case '~':
                        cx.x_token = T_COMP;
                        state = -1;
@@ -179,10 +175,6 @@ loop:
                        cx.x_token = T_RP;
                        state = -1;
                        break;
                        cx.x_token = T_RP;
                        state = -1;
                        break;
-               case '$':
-                       cx.x_token = T_DOLLAR;
-                       state = -1;
-                       break;
                case ',':
                        cx.x_token = T_COMMA;
                        state = -1;
                case ',':
                        cx.x_token = T_COMMA;
                        state = -1;
@@ -202,6 +194,12 @@ loop:
                        break;
                }
                break;
                        break;
                }
                break;
+       case 1:                         /* got # */
+               if (c == '\n' || c == EOF) {
+                       (void) s_ungetc(c);
+                       state = 0;
+               }
+               break;
        case 2:                         /* unquoted string */
                switch (c) {
                case 'a': case 'b': case 'c': case 'd': case 'e':
        case 2:                         /* unquoted string */
                switch (c) {
                case 'a': case 'b': case 'c': case 'd': case 'e':
@@ -223,10 +221,11 @@ loop:
                                *p++ = c;
                        break;
                case '"':
                                *p++ = c;
                        break;
                case '"':
-               case '\'':
-                       quote = c;
                        state = 3;
                        break;
                        state = 3;
                        break;
+               case '\'':
+                       state = 4;
+                       break;
                case '\\':
                        switch (c = s_gettok1()) {
                        case -2:
                case '\\':
                        switch (c = s_gettok1()) {
                        case -2:
@@ -249,38 +248,38 @@ loop:
                                        cx.x_token = T_IF;
                                break;
                        case 't':
                                        cx.x_token = T_IF;
                                break;
                        case 't':
-                               if (strcmp(buf, "then") == 0)
+                               if (buf[1] == 'h' && buf[2] == 'e'
+                                   && buf[3] == 'n' && buf[4] == 0)
                                        cx.x_token = T_THEN;
                                break;
                        case 'e':
                                        cx.x_token = T_THEN;
                                break;
                        case 'e':
-                               switch (buf[1]) {
-                               case 'n':
-                                       if (strcmp(buf, "endif") == 0)
-                                               cx.x_token = T_ENDIF;
-                                       break;
-                               case 'l':
-                                       if (strcmp(buf, "else") == 0)
-                                               cx.x_token = T_ELSE;
-                                       if (strcmp(buf, "elsif") == 0)
+                               if (buf[1] == 'n' && buf[2] == 'd'
+                                   && buf[3] == 'i' && buf[4] == 'f'
+                                   && buf[5] == 0)
+                                       cx.x_token = T_ENDIF;
+                               else if (buf[1] == 'l' && buf[2] == 's')
+                                       if (buf[3] == 'i' && buf[4] == 'f'
+                                           && buf[5] == 0)
                                                cx.x_token = T_ELSIF;
                                                cx.x_token = T_ELSIF;
-                                       break;
-                               }
+                                       else if (buf[3] == 'e' && buf[4] == 0)
+                                               cx.x_token = T_ELSE;
                                break;
                        }
                                break;
                        }
-                       if (cx.x_token == T_STR)
-                               if ((cx.x_val.v_str = str_cpy(buf)) == 0) {
-                                       p_memerror();
-                                       cx.x_token = T_EOF;
-                               }
+                       if (cx.x_token == T_STR
+                           && (cx.x_val.v_str = str_cpy(buf)) == 0) {
+                               p_memerror();
+                               cx.x_token = T_EOF;
+                       }
                        state = -1;
                        break;
                }
                break;
                        state = -1;
                        break;
                }
                break;
-       case 3:                         /* quoted string */
+       case 3:                         /* quoted string */
                switch (c) {
                case '\n':
                        (void) s_ungetc(c);
                case EOF:
                switch (c) {
                case '\n':
                        (void) s_ungetc(c);
                case EOF:
+               case '"':
                        state = 2;
                        break;
                case '\\':
                        state = 2;
                        break;
                case '\\':
@@ -294,17 +293,33 @@ loop:
                        }
                        break;
                default:
                        }
                        break;
                default:
-                       if (c == quote)
-                               state = 2;
-                       else if (p < buf + sizeof buf - 1)
+                       if (p < buf + sizeof buf - 1)
                                *p++ = c;
                        break;
                }
                break;
                                *p++ = c;
                        break;
                }
                break;
-       case 4:                         /* got # */
-               if (c == '\n' || c == EOF) {
+       case 4:                         /* ' quoted string */
+               switch (c) {
+               case '\n':
                        (void) s_ungetc(c);
                        (void) s_ungetc(c);
-                       state = 1;
+               case EOF:
+               case '\'':
+                       state = 2;
+                       break;
+               case '\\':
+                       switch (c = s_gettok1()) {
+                       case -1:
+                       case -2:        /* newlines are invisible */
+                               break;
+                       default:
+                               if (p < buf + sizeof buf - 1)
+                                       *p++ = c;
+                       }
+                       break;
+               default:
+                       if (p < buf + sizeof buf - 1)
+                               *p++ = c;
+                       break;
                }
                break;
        case 10:                        /* got 0 */
                }
                break;
        case 10:                        /* got 0 */
@@ -427,7 +442,7 @@ loop:
                        state = -1;
                }
                break;
                        state = -1;
                }
                break;
-       case 24:                        /* and & */
+       case 24:                        /* got & */
                switch (c) {
                case '&':
                        cx.x_token = T_ANDAND;
                switch (c) {
                case '&':
                        cx.x_token = T_ANDAND;
@@ -439,7 +454,7 @@ loop:
                        state = -1;
                }
                break;
                        state = -1;
                }
                break;
-       case 25:                        /* and | */
+       case 25:                        /* got | */
                switch (c) {
                case '|':
                        cx.x_token = T_OROR;
                switch (c) {
                case '|':
                        cx.x_token = T_OROR;
@@ -451,6 +466,18 @@ loop:
                        state = -1;
                }
                break;
                        state = -1;
                }
                break;
+       case 26:                        /* got $ */
+               switch (c) {
+               case '?':
+                       cx.x_token = T_DQ;
+                       state = -1;
+                       break;
+               default:
+                       (void) s_ungetc(c);
+                       cx.x_token = T_DOLLAR;
+                       state = -1;
+               }
+               break;
        default:
                abort();
        }
        default:
                abort();
        }