new version from James Gosling including various bug fixes
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 16 May 1989 08:08:02 +0000 (00:08 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 16 May 1989 08:08:02 +0000 (00:08 -0800)
SCCS-vsn: usr.bin/indent/args.c 5.8
SCCS-vsn: usr.bin/indent/indent.c 5.13
SCCS-vsn: usr.bin/indent/indent_globs.h 5.8
SCCS-vsn: usr.bin/indent/io.c 5.13
SCCS-vsn: usr.bin/indent/lexi.c 5.13

usr/src/usr.bin/indent/args.c
usr/src/usr.bin/indent/indent.c
usr/src/usr.bin/indent/indent_globs.h
usr/src/usr.bin/indent/io.c
usr/src/usr.bin/indent/lexi.c

index 56c1f6a..7ec996e 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)args.c     5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)args.c     5.8 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -48,6 +48,8 @@ char       *getenv(), *index();
 #define        STDIN           3       /* use stdin */
 #define        KEY             4       /* type (keyword) */
 
 #define        STDIN           3       /* use stdin */
 #define        KEY             4       /* type (keyword) */
 
+char *option_source = "?";
+
 /*
  * N.B.: because of the way the table here is scanned, options whose names are
  * substrings of other options must occur later; that is, with -lp vs -l, -lp
 /*
  * N.B.: because of the way the table here is scanned, options whose names are
  * substrings of other options must occur later; that is, with -lp vs -l, -lp
@@ -140,14 +142,15 @@ set_profile()
     static char prof[] = ".indent.pro";
 
     sprintf(fname, "%s/%s", getenv("HOME"), prof);
     static char prof[] = ".indent.pro";
 
     sprintf(fname, "%s/%s", getenv("HOME"), prof);
-    if ((f = fopen(fname, "r")) != NULL) {
+    if ((f = fopen(option_source = fname, "r")) != NULL) {
        scan_profile(f);
        (void) fclose(f);
     }
        scan_profile(f);
        (void) fclose(f);
     }
-    if ((f = fopen(prof, "r")) != NULL) {
+    if ((f = fopen(option_source = prof, "r")) != NULL) {
        scan_profile(f);
        (void) fclose(f);
     }
        scan_profile(f);
        (void) fclose(f);
     }
+    option_source = "Command line";
 }
 
 scan_profile(f)
 }
 
 scan_profile(f)
@@ -211,7 +214,7 @@ set_option(arg)
     for (p = pro; p->p_name; p++)
        if (*p->p_name == *arg && eqin(p->p_name, arg))
            goto found;
     for (p = pro; p->p_name; p++)
        if (*p->p_name == *arg && eqin(p->p_name, arg))
            goto found;
-    fprintf(stderr, "indent: unknown parameter \"%s\"\n", arg - 1);
+    fprintf(stderr, "indent: %s: unknown parameter \"%s\"\n", option_source, arg - 1);
     exit(1);
 found:
     switch (p->p_type) {
     exit(1);
 found:
     switch (p->p_type) {
@@ -260,10 +263,10 @@ indent: set_option: internal error: p_special %d\n", p->p_special);
        break;
 
     case PRO_INT:
        break;
 
     case PRO_INT:
-       if (*param_start == 0) {
+       if (!isdigit(*param_start)) {
     need_param:
     need_param:
-           fprintf(stderr, "indent: ``%s'' requires a parameter\n",
-                   arg - 1);
+           fprintf(stderr, "indent: %s: ``%s'' requires a parameter\n",
+                   option_source, arg - 1);
            exit(1);
        }
        *p->p_obj = atoi(param_start);
            exit(1);
        }
        *p->p_obj = atoi(param_start);
index 27693b7..c1103fb 100644 (file)
@@ -27,7 +27,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)indent.c   5.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)indent.c   5.13 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -80,9 +80,11 @@ main(argc, argv)
     combuf = (char *) malloc(bufsize);
     labbuf = (char *) malloc(bufsize);
     codebuf = (char *) malloc(bufsize);
     combuf = (char *) malloc(bufsize);
     labbuf = (char *) malloc(bufsize);
     codebuf = (char *) malloc(bufsize);
+    tokenbuf = (char *) malloc(bufsize);
     l_com = combuf + bufsize - 5;
     l_lab = labbuf + bufsize - 5;
     l_code = codebuf + bufsize - 5;
     l_com = combuf + bufsize - 5;
     l_lab = labbuf + bufsize - 5;
     l_code = codebuf + bufsize - 5;
+    l_token = tokenbuf + bufsize - 5;
     combuf[0] = codebuf[0] = labbuf[0] = ' ';  /* set up code, label, and
                                                 * comment buffers */
     combuf[1] = codebuf[1] = labbuf[1] = '\0';
     combuf[0] = codebuf[0] = labbuf[0] = ' ';  /* set up code, label, and
                                                 * comment buffers */
     combuf[1] = codebuf[1] = labbuf[1] = '\0';
@@ -90,7 +92,10 @@ main(argc, argv)
     s_lab = e_lab = labbuf + 1;
     s_code = e_code = codebuf + 1;
     s_com = e_com = combuf + 1;
     s_lab = e_lab = labbuf + 1;
     s_code = e_code = codebuf + 1;
     s_com = e_com = combuf + 1;
+    s_token = e_token = tokenbuf + 1;
 
 
+    in_buffer = (char *) malloc(10);
+    in_buffer_limit = in_buffer + 8;
     buf_ptr = buf_end = in_buffer;
     line_no = 1;
     had_eof = ps.in_decl = ps.decl_on_line = break_comma = false;
     buf_ptr = buf_end = in_buffer;
     line_no = 1;
     had_eof = ps.in_decl = ps.decl_on_line = break_comma = false;
@@ -500,6 +505,7 @@ check_type:
            break;
 
        case rparen:            /* got a ')' or ']' */
            break;
 
        case rparen:            /* got a ')' or ']' */
+           rparen_count--;
            if (ps.cast_mask & (1 << ps.p_l_follow) & ~ps.sizeof_mask) {
                ps.last_u_d = true;
                ps.cast_mask &= (1 << ps.p_l_follow) - 1;
            if (ps.cast_mask & (1 << ps.p_l_follow) & ~ps.sizeof_mask) {
                ps.last_u_d = true;
                ps.cast_mask &= (1 << ps.p_l_follow) - 1;
@@ -656,7 +662,7 @@ check_type:
                                 * structure declaration */
            scase = false;      /* these will only need resetting in a error */
            squest = 0;
                                 * structure declaration */
            scase = false;      /* these will only need resetting in a error */
            squest = 0;
-           if (ps.last_token == rparen)
+           if (ps.last_token == rparen && rparen_count == 0)
                ps.in_parameter_declaration = 0;
            ps.cast_mask = 0;
            ps.sizeof_mask = 0;
                ps.in_parameter_declaration = 0;
            ps.cast_mask = 0;
            ps.sizeof_mask = 0;
@@ -943,7 +949,7 @@ check_type:
            if (ps.p_l_follow == 0) {
                if (ps.block_init_level <= 0)
                    ps.block_init = 0;
            if (ps.p_l_follow == 0) {
                if (ps.block_init_level <= 0)
                    ps.block_init = 0;
-               if (break_comma && !ps.leave_comma)
+               if (break_comma && (!ps.leave_comma || compute_code_target() + (e_code - s_code) > max_col - 8))
                    force_nl = true;
            }
            break;
                    force_nl = true;
            }
            break;
@@ -960,6 +966,11 @@ check_type:
                char        quote = 0;
                int         com_end = 0;
 
                char        quote = 0;
                int         com_end = 0;
 
+               while (*buf_ptr == ' ' || *buf_ptr == '\t') {
+                   buf_ptr++;
+                   if (buf_ptr >= buf_end)
+                       fill_buffer();
+               }
                while (*buf_ptr != '\n' || in_comment) {
                    check_size(lab);
                    *e_lab = *buf_ptr++;
                while (*buf_ptr != '\n' || in_comment) {
                    check_size(lab);
                    *e_lab = *buf_ptr++;
index 90c39c6..4ea80e6 100644 (file)
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)indent_globs.h      5.7 (Berkeley) %G%
+ *     @(#)indent_globs.h      5.8 (Berkeley) %G%
  */
 
 #include <stdio.h>
 
 #define BACKSLASH '\\'
 #define bufsize 200            /* size of internal buffers */
  */
 
 #include <stdio.h>
 
 #define BACKSLASH '\\'
 #define bufsize 200            /* size of internal buffers */
-#define inp_bufs 600           /* size of input buffer */
 #define sc_size 5000           /* size of save_com buffer */
 #define label_offset 2         /* number of levels a label is placed to left
                                 * of code */
 #define sc_size 5000           /* size of save_com buffer */
 #define label_offset 2         /* number of levels a label is placed to left
                                 * of code */
@@ -65,7 +64,14 @@ char       *s_com;           /* start ... */
 char       *e_com;             /* ... and end of stored comments */
 char       *l_com;             /* limit of comment buffer */
 
 char       *e_com;             /* ... and end of stored comments */
 char       *l_com;             /* limit of comment buffer */
 
-char        in_buffer[inp_bufs];/* input buffer */
+#define token s_token
+char       *tokenbuf;          /* the last token scanned */
+char      *s_token;
+char       *e_token;
+char      *l_token;
+
+char       *in_buffer;         /* input buffer */
+char      *in_buffer_limit;    /* the end of the input buffer */
 char       *buf_ptr;           /* ptr to next character to be taken from
                                 * in_buffer */
 char       *buf_end;           /* ptr to first after last char in in_buffer */
 char       *buf_ptr;           /* ptr to next character to be taken from
                                 * in_buffer */
 char       *buf_end;           /* ptr to first after last char in in_buffer */
@@ -78,8 +84,6 @@ char       *bp_save;          /* saved value of buf_ptr when taking input
                                 * from save_com */
 char       *be_save;           /* similarly saved value of buf_end */
 
                                 * from save_com */
 char       *be_save;           /* similarly saved value of buf_end */
 
-char        token[bufsize];    /* the last token scanned */
-
 
 int         pointer_as_binop;
 int         blanklines_after_declarations;
 
 int         pointer_as_binop;
 int         blanklines_after_declarations;
@@ -264,5 +268,6 @@ struct parser_state {
 }           ps;
 
 int         ifdef_level;
 }           ps;
 
 int         ifdef_level;
+int        rparen_count;
 struct parser_state state_stack[5];
 struct parser_state match_state[5];
 struct parser_state state_stack[5];
 struct parser_state match_state[5];
index 3a10ced..73cf90a 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)io.c       5.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)io.c       5.13 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "indent_globs.h"
 #endif /* not lint */
 
 #include "indent_globs.h"
@@ -90,7 +90,19 @@ dump_line()
            while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
                e_lab--;
            cur_col = pad_output(1, compute_label_target());
            while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
                e_lab--;
            cur_col = pad_output(1, compute_label_target());
-           fprintf(output, "%.*s", e_lab - s_lab, s_lab);
+           if (s_lab[0] == '#' && (strncmp(s_lab, "#else", 5) == 0
+                                   || strncmp(s_lab, "#endif", 6) == 0)) {
+               register char *s = s_lab;
+               if (e_lab[-1] == '\n') e_lab--;
+               do putc(*s++, output);
+               while (s < e_lab && 'a' <= *s && *s<='z');
+               while ((*s == ' ' || *s == '\t') && s < e_lab)
+                   s++;
+               if (s < e_lab)
+                   fprintf(output, s[0]=='/' && s[1]=='*' ? "\t%.*s" : "\t/* %.*s */",
+                           e_lab - s, s);
+           }
+           else fprintf(output, "%.*s", e_lab - s_lab, s_lab);
            cur_col = count_spaces(cur_col, s_lab);
        }
        else
            cur_col = count_spaces(cur_col, s_lab);
        }
        else
@@ -296,7 +308,7 @@ compute_label_target()
  * Willcox of CAC      Added check for switch back to partly full input
  * buffer from temporary buffer
  * 
  * Willcox of CAC      Added check for switch back to partly full input
  * buffer from temporary buffer
  * 
- */\f
+ */
 int
 fill_buffer()
 {                              /* this routine reads stuff from the input */
 int
 fill_buffer()
 {                              /* this routine reads stuff from the input */
@@ -312,7 +324,16 @@ fill_buffer()
            return;             /* only return if there is really something in
                                 * this buffer */
     }
            return;             /* only return if there is really something in
                                 * this buffer */
     }
-    for (p = buf_ptr = in_buffer;;) {
+    for (p = in_buffer;;) {
+       if (p >= in_buffer_limit) {
+           register size = (in_buffer_limit - in_buffer) * 2 + 10;
+           register offset = p - in_buffer;
+           in_buffer = (char *) realloc(in_buffer, size);
+           if (in_buffer == 0)
+               err("input line too long");
+           p = in_buffer + offset;
+           in_buffer_limit = in_buffer + size - 2;
+       }
        if ((i = getc(f)) == EOF) {
                *p++ = ' ';
                *p++ = '\n';
        if ((i = getc(f)) == EOF) {
                *p++ = ' ';
                *p++ = '\n';
@@ -323,6 +344,7 @@ fill_buffer()
        if (i == '\n')
                break;
     }
        if (i == '\n')
                break;
     }
+    buf_ptr = in_buffer;
     buf_end = p;
     if (p[-2] == '/' && p[-3] == '*') {
        if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0)
     buf_end = p;
     if (p[-2] == '/' && p[-3] == '*') {
        if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0)
@@ -401,7 +423,7 @@ fill_buffer()
  * 
  * HISTORY: initial coding     November 1976   D A Willcox of CAC
  * 
  * 
  * HISTORY: initial coding     November 1976   D A Willcox of CAC
  * 
- */\f
+ */
 pad_output(current, target)    /* writes tabs and blanks (if necessary) to
                                 * get the current output position up to the
                                 * target column */
 pad_output(current, target)    /* writes tabs and blanks (if necessary) to
                                 * get the current output position up to the
                                 * target column */
@@ -446,7 +468,7 @@ pad_output(current, target) /* writes tabs and blanks (if necessary) to
  * 
  * HISTORY: initial coding     November 1976   D A Willcox of CAC
  * 
  * 
  * HISTORY: initial coding     November 1976   D A Willcox of CAC
  * 
- */\f
+ */
 int
 count_spaces(current, buffer)
 /*
 int
 count_spaces(current, buffer)
 /*
index 250df81..1f0341a 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)lexi.c     5.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)lexi.c     5.13 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -101,7 +101,6 @@ char        chartype[128] =
 int
 lexi()
 {
 int
 lexi()
 {
-    register char *tok;                /* local pointer to next char in token */
     int         unary_delim;   /* this is set to 1 if the current token
                                 * 
                                 * forces a following operator to be unary */
     int         unary_delim;   /* this is set to 1 if the current token
                                 * 
                                 * forces a following operator to be unary */
@@ -110,7 +109,7 @@ lexi()
     int         code;          /* internal code to be returned */
     char        qchar;         /* the delimiter character for a string */
 
     int         code;          /* internal code to be returned */
     char        qchar;         /* the delimiter character for a string */
 
-    tok = token;               /* point to start of place to save token */
+    e_token = s_token;         /* point to start of place to save token */
     unary_delim = false;
     ps.col_1 = ps.last_nl;     /* tell world that this token started in
                                 * column 1 iff the last thing scanned was nl */
     unary_delim = false;
     ps.col_1 = ps.last_nl;     /* tell world that this token started in
                                 * column 1 iff the last thing scanned was nl */
@@ -138,10 +137,12 @@ lexi()
                        seenexp = 0;
            if (*buf_ptr == '0' &&
                    (buf_ptr[1] == 'x' || buf_ptr[1] == 'X')) {
                        seenexp = 0;
            if (*buf_ptr == '0' &&
                    (buf_ptr[1] == 'x' || buf_ptr[1] == 'X')) {
-               *tok++ = *buf_ptr++;
-               *tok++ = *buf_ptr++;
-               while (isxdigit(*buf_ptr))
-                   *tok++ = *buf_ptr++;
+               *e_token++ = *buf_ptr++;
+               *e_token++ = *buf_ptr++;
+               while (isxdigit(*buf_ptr)) {
+                   check_size(token);
+                   *e_token++ = *buf_ptr++;
+               }
            }
            else
                while (1) {
            }
            else
                while (1) {
@@ -150,28 +151,31 @@ lexi()
                            break;
                        else
                            seendot++;
                            break;
                        else
                            seendot++;
-                   *tok++ = *buf_ptr++;
+                   check_size(token);
+                   *e_token++ = *buf_ptr++;
                    if (!isdigit(*buf_ptr) && *buf_ptr != '.')
                        if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp)
                            break;
                        else {
                            seenexp++;
                            seendot++;
                    if (!isdigit(*buf_ptr) && *buf_ptr != '.')
                        if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp)
                            break;
                        else {
                            seenexp++;
                            seendot++;
-                           *tok++ = *buf_ptr++;
+                           check_size(token);
+                           *e_token++ = *buf_ptr++;
                            if (*buf_ptr == '+' || *buf_ptr == '-')
                            if (*buf_ptr == '+' || *buf_ptr == '-')
-                               *tok++ = *buf_ptr++;
+                               *e_token++ = *buf_ptr++;
                        }
                }
            if (*buf_ptr == 'L' || *buf_ptr == 'l')
                        }
                }
            if (*buf_ptr == 'L' || *buf_ptr == 'l')
-               *tok++ = *buf_ptr++;
+               *e_token++ = *buf_ptr++;
        }
        else
            while (chartype[*buf_ptr] == alphanum) {    /* copy it over */
        }
        else
            while (chartype[*buf_ptr] == alphanum) {    /* copy it over */
-               *tok++ = *buf_ptr++;
+               check_size(token);
+               *e_token++ = *buf_ptr++;
                if (buf_ptr >= buf_end)
                    fill_buffer();
            }
                if (buf_ptr >= buf_end)
                    fill_buffer();
            }
-       *tok++ = '\0';
+       *e_token++ = '\0';
        while (*buf_ptr == ' ' || *buf_ptr == '\t') {   /* get rid of blanks */
            if (++buf_ptr >= buf_end)
                fill_buffer();
        while (*buf_ptr == ' ' || *buf_ptr == '\t') {   /* get rid of blanks */
            if (++buf_ptr >= buf_end)
                fill_buffer();
@@ -193,15 +197,15 @@ lexi()
         * This loop will check if the token is a keyword.
         */
        for (p = specials; (j = p->rwd) != 0; p++) {
         * This loop will check if the token is a keyword.
         */
        for (p = specials; (j = p->rwd) != 0; p++) {
-           tok = token;        /* point at scanned token */
-           if (*j++ != *tok++ || *j++ != *tok++)
+           register char *p = s_token; /* point at scanned token */
+           if (*j++ != *p++ || *j++ != *p++)
                continue;       /* This test depends on the fact that
                                 * identifiers are always at least 1 character
                                 * long (ie. the first two bytes of the
                                 * identifier are always meaningful) */
                continue;       /* This test depends on the fact that
                                 * identifiers are always at least 1 character
                                 * long (ie. the first two bytes of the
                                 * identifier are always meaningful) */
-           if (tok[-1] == 0)
+           if (p[-1] == 0)
                break;          /* If its a one-character identifier */
                break;          /* If its a one-character identifier */
-           while (*tok++ == *j)
+           while (*p++ == *j)
                if (*j++ == 0)
                    goto found_keyword; /* I wish that C had a multi-level
                                         * break... */
                if (*j++ == 0)
                    goto found_keyword; /* I wish that C had a multi-level
                                         * break... */
@@ -249,10 +253,11 @@ lexi()
        if (*buf_ptr == '(' && ps.tos <= 1 && ps.ind_level == 0) {
            register char *tp = buf_ptr;
            while (tp < buf_end)
        if (*buf_ptr == '(' && ps.tos <= 1 && ps.ind_level == 0) {
            register char *tp = buf_ptr;
            while (tp < buf_end)
-               if (*tp++ == ')' && *tp == ';')
+               if (*tp++ == ')' && (*tp == ';' || *tp == ','))
                    goto not_proc;
            strncpy(ps.procname, token, sizeof ps.procname - 1);
            ps.in_parameter_declaration = 1;
                    goto not_proc;
            strncpy(ps.procname, token, sizeof ps.procname - 1);
            ps.in_parameter_declaration = 1;
+           rparen_count = 1;
     not_proc:;
        }
        /*
     not_proc:;
        }
        /*
@@ -277,11 +282,12 @@ lexi()
        last_code = ident;
        return (ident);         /* the ident is not in the list */
     }                          /* end of procesing for alpanum character */
        last_code = ident;
        return (ident);         /* the ident is not in the list */
     }                          /* end of procesing for alpanum character */
-    /* l l l Scan a non-alphanumeric token */
 
 
-    *tok++ = *buf_ptr;         /* if it is only a one-character token, it is
+    /* Scan a non-alphanumeric token */
+
+    *e_token++ = *buf_ptr;             /* if it is only a one-character token, it is
                                 * moved here */
                                 * moved here */
-    *tok = '\0';
+    *e_token = '\0';
     if (++buf_ptr >= buf_end)
        fill_buffer();
 
     if (++buf_ptr >= buf_end)
        fill_buffer();
 
@@ -301,10 +307,10 @@ lexi()
     case '"':                  /* start of string */
        qchar = *token;
        if (troff) {
     case '"':                  /* start of string */
        qchar = *token;
        if (troff) {
-           tok[-1] = '`';
+           e_token[-1] = '`';
            if (qchar == '"')
            if (qchar == '"')
-               *tok++ = '`';
-           tok = chfont(&bodyf, &stringf, tok);
+               *e_token++ = '`';
+           e_token = chfont(&bodyf, &stringf, e_token);
        }
        do {                    /* copy the string */
            while (1) {         /* move one character or [/<char>]<char> */
        }
        do {                    /* copy the string */
            while (1) {         /* move one character or [/<char>]<char> */
@@ -312,25 +318,22 @@ lexi()
                    printf("%d: Unterminated literal\n", line_no);
                    goto stop_lit;
                }
                    printf("%d: Unterminated literal\n", line_no);
                    goto stop_lit;
                }
-               *tok = *buf_ptr++;
+               check_size(token);      /* Only have to do this once in this loop,
+                                        * since check_size guarantees that there
+                                        * are at least 5 entries left */
+               *e_token = *buf_ptr++;
                if (buf_ptr >= buf_end)
                    fill_buffer();
                if (buf_ptr >= buf_end)
                    fill_buffer();
-               if (had_eof || ((tok - token) > (bufsize - 2))) {
-                   printf("Unterminated literal\n");
-                   ++tok;
-                   goto stop_lit;
-                   /* get outof literal copying loop */
-               }
-               if (*tok == BACKSLASH) {        /* if escape, copy extra char */
+               if (*e_token == BACKSLASH) {    /* if escape, copy extra char */
                    if (*buf_ptr == '\n')       /* check for escaped newline */
                        ++line_no;
                    if (troff) {
                    if (*buf_ptr == '\n')       /* check for escaped newline */
                        ++line_no;
                    if (troff) {
-                       *++tok = BACKSLASH;
+                       *++e_token = BACKSLASH;
                        if (*buf_ptr == BACKSLASH)
                        if (*buf_ptr == BACKSLASH)
-                           *++tok = BACKSLASH;
+                           *++e_token = BACKSLASH;
                    }
                    }
-                   *++tok = *buf_ptr++;
-                   ++tok;      /* we must increment this again because we
+                   *++e_token = *buf_ptr++;
+                   ++e_token;  /* we must increment this again because we
                                 * copied two chars */
                    if (buf_ptr >= buf_end)
                        fill_buffer();
                                 * copied two chars */
                    if (buf_ptr >= buf_end)
                        fill_buffer();
@@ -338,11 +341,11 @@ lexi()
                else
                    break;      /* we copied one character */
            }                   /* end of while (1) */
                else
                    break;      /* we copied one character */
            }                   /* end of while (1) */
-       } while (*tok++ != qchar);
+       } while (*e_token++ != qchar);
        if (troff) {
        if (troff) {
-           tok = chfont(&stringf, &bodyf, tok - 1);
+           e_token = chfont(&stringf, &bodyf, e_token - 1);
            if (qchar == '"')
            if (qchar == '"')
-               *tok++ = '\'';
+               *e_token++ = '\'';
        }
 stop_lit:
        code = ident;
        }
 stop_lit:
        code = ident;
@@ -419,7 +422,7 @@ stop_lit:
 
        if (*buf_ptr == token[0]) {
            /* check for doubled character */
 
        if (*buf_ptr == token[0]) {
            /* check for doubled character */
-           *tok++ = *buf_ptr++;
+           *e_token++ = *buf_ptr++;
            /* buffer overflow will be checked at end of loop */
            if (last_code == ident || last_code == rparen) {
                code = (ps.last_u_d ? unary_op : postop);
            /* buffer overflow will be checked at end of loop */
            if (last_code == ident || last_code == rparen) {
                code = (ps.last_u_d ? unary_op : postop);
@@ -429,10 +432,10 @@ stop_lit:
        }
        else if (*buf_ptr == '=')
            /* check for operator += */
        }
        else if (*buf_ptr == '=')
            /* check for operator += */
-           *tok++ = *buf_ptr++;
+           *e_token++ = *buf_ptr++;
        else if (*buf_ptr == '>') {
            /* check for operator -> */
        else if (*buf_ptr == '>') {
            /* check for operator -> */
-           *tok++ = *buf_ptr++;
+           *e_token++ = *buf_ptr++;
            if (!pointer_as_binop) {
                unary_delim = false;
                code = unary_op;
            if (!pointer_as_binop) {
                unary_delim = false;
                code = unary_op;
@@ -447,17 +450,17 @@ stop_lit:
            ps.block_init = 1;
 #ifdef undef
        if (chartype[*buf_ptr] == opchar) {     /* we have two char assignment */
            ps.block_init = 1;
 #ifdef undef
        if (chartype[*buf_ptr] == opchar) {     /* we have two char assignment */
-           tok[-1] = *buf_ptr++;
-           if ((tok[-1] == '<' || tok[-1] == '>') && tok[-1] == *buf_ptr)
-               *tok++ = *buf_ptr++;
-           *tok++ = '=';       /* Flip =+ to += */
-           *tok = 0;
+           e_token[-1] = *buf_ptr++;
+           if ((e_token[-1] == '<' || e_token[-1] == '>') && e_token[-1] == *buf_ptr)
+               *e_token++ = *buf_ptr++;
+           *e_token++ = '=';   /* Flip =+ to += */
+           *e_token = 0;
        }
 #else
        if (*buf_ptr == '=') {/* == */
        }
 #else
        if (*buf_ptr == '=') {/* == */
-           *tok++ = '=';       /* Flip =+ to += */
+           *e_token++ = '=';   /* Flip =+ to += */
            buf_ptr++;
            buf_ptr++;
-           *tok = 0;
+           *e_token = 0;
        }
 #endif
        code = binary_op;
        }
 #endif
        code = binary_op;
@@ -469,12 +472,12 @@ stop_lit:
     case '<':
     case '!':                  /* ops like <, <<, <=, !=, etc */
        if (*buf_ptr == '>' || *buf_ptr == '<' || *buf_ptr == '=') {
     case '<':
     case '!':                  /* ops like <, <<, <=, !=, etc */
        if (*buf_ptr == '>' || *buf_ptr == '<' || *buf_ptr == '=') {
-           *tok++ = *buf_ptr;
+           *e_token++ = *buf_ptr;
            if (++buf_ptr >= buf_end)
                fill_buffer();
        }
        if (*buf_ptr == '=')
            if (++buf_ptr >= buf_end)
                fill_buffer();
        }
        if (*buf_ptr == '=')
-           *tok++ = *buf_ptr++;
+           *e_token++ = *buf_ptr++;
        code = (ps.last_u_d ? unary_op : binary_op);
        unary_delim = true;
        break;
        code = (ps.last_u_d ? unary_op : binary_op);
        unary_delim = true;
        break;
@@ -482,7 +485,7 @@ stop_lit:
     default:
        if (token[0] == '/' && *buf_ptr == '*') {
            /* it is start of comment */
     default:
        if (token[0] == '/' && *buf_ptr == '*') {
            /* it is start of comment */
-           *tok++ = '*';
+           *e_token++ = '*';
 
            if (++buf_ptr >= buf_end)
                fill_buffer();
 
            if (++buf_ptr >= buf_end)
                fill_buffer();
@@ -491,11 +494,11 @@ stop_lit:
            unary_delim = ps.last_u_d;
            break;
        }
            unary_delim = ps.last_u_d;
            break;
        }
-       while (*(tok - 1) == *buf_ptr || *buf_ptr == '=') {
+       while (*(e_token - 1) == *buf_ptr || *buf_ptr == '=') {
            /*
             * handle ||, &&, etc, and also things as in int *****i
             */
            /*
             * handle ||, &&, etc, and also things as in int *****i
             */
-           *tok++ = *buf_ptr;
+           *e_token++ = *buf_ptr;
            if (++buf_ptr >= buf_end)
                fill_buffer();
        }
            if (++buf_ptr >= buf_end)
                fill_buffer();
        }
@@ -511,7 +514,7 @@ stop_lit:
     if (buf_ptr >= buf_end)    /* check for input buffer empty */
        fill_buffer();
     ps.last_u_d = unary_delim;
     if (buf_ptr >= buf_end)    /* check for input buffer empty */
        fill_buffer();
     ps.last_u_d = unary_delim;
-    *tok = '\0';               /* null terminate the token */
+    *e_token = '\0';           /* null terminate the token */
     return (code);
 }
 
     return (code);
 }