Module Name:    src
Committed By:   rillig
Date:           Sat Sep 25 07:46:41 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c lexi.c parse.c

Log Message:
indent: rename variables of type token_type

The previous variable name 'code' conflicts with the buffer of the same
name.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/indent/parse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.63 src/usr.bin/indent/indent.c:1.64
--- src/usr.bin/indent/indent.c:1.63	Fri Sep 24 18:47:29 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 07:46:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.63 2021/09/24 18:47:29 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.64 2021/09/25 07:46:41 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.63 2021/09/24 18:47:29 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.64 2021/09/25 07:46:41 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -178,11 +178,11 @@ init_capsicum(void)
 #endif
 
 static void
-search_brace(token_type *inout_type_code, int *inout_force_nl,
+search_brace(token_type *inout_ttype, int *inout_force_nl,
 	     int *inout_comment_buffered, int *inout_last_else)
 {
     while (ps.search_brace) {
-	switch (*inout_type_code) {
+	switch (*inout_ttype) {
 	case newline:
 	    if (sc_end == NULL) {
 		save_com = sc_buf;
@@ -264,10 +264,10 @@ search_brace(token_type *inout_type_code
 
 	    remove_newlines =
 		    /* "} else" */
-		    (*inout_type_code == keyword_do_else && *token == 'e' &&
+		    (*inout_ttype == keyword_do_else && *token == 'e' &&
 		     e_code != s_code && e_code[-1] == '}')
 		    /* "else if" */
-		    || (*inout_type_code == keyword_for_if_while &&
+		    || (*inout_ttype == keyword_for_if_while &&
 			*token == 'i' && *inout_last_else && opt.else_if);
 	    if (remove_newlines)
 		*inout_force_nl = false;
@@ -317,7 +317,7 @@ search_brace(token_type *inout_type_code
 	 * We must make this check, just in case there was an unexpected
 	 * EOF.
 	 */
-	if (*inout_type_code != end_of_file) {
+	if (*inout_ttype != end_of_file) {
 	    /*
 	     * The only intended purpose of calling lexi() below is to
 	     * categorize the next token in order to decide whether to
@@ -351,9 +351,9 @@ search_brace(token_type *inout_type_code
 
 	    struct parser_state transient_state;
 	    transient_state = ps;
-	    *inout_type_code = lexi(&transient_state);	/* read another token */
-	    if (*inout_type_code != newline && *inout_type_code != form_feed &&
-		*inout_type_code != comment && !transient_state.search_brace) {
+	    *inout_ttype = lexi(&transient_state);	/* read another token */
+	    if (*inout_ttype != newline && *inout_ttype != form_feed &&
+		*inout_ttype != comment && !transient_state.search_brace) {
 		ps = transient_state;
 	    }
 	}
@@ -561,11 +561,11 @@ process_end_of_file(void)
 }
 
 static void
-process_comment_in_code(token_type type_code, int *inout_force_nl)
+process_comment_in_code(token_type ttype, int *inout_force_nl)
 {
     if (*inout_force_nl &&
-	type_code != semicolon &&
-	(type_code != lbrace || !opt.btype_2)) {
+	ttype != semicolon &&
+	(ttype != lbrace || !opt.btype_2)) {
 
 	/* we should force a broken line here */
 	if (opt.verbose)
@@ -587,7 +587,7 @@ process_comment_in_code(token_type type_
 	memcpy(e_code, com.s, len);
 	e_code += len;
 	*e_code++ = ' ';
-	*e_code = '\0';		/* null terminate code sect */
+	*e_code = '\0';
 	ps.want_blank = false;
 	com.e = com.s;
     }
@@ -1029,11 +1029,11 @@ process_decl(int *out_dec_ind, int *out_
 }
 
 static void
-process_ident(token_type type_code, int dec_ind, int tabs_to_var,
+process_ident(token_type ttype, int dec_ind, int tabs_to_var,
 	      int *inout_sp_sw, int *inout_force_nl, token_type hd_type)
 {
     if (ps.in_decl) {
-	if (type_code == funcname) {
+	if (ttype == funcname) {
 	    ps.in_decl = false;
 	    if (opt.procnames_start_line && s_code != e_code) {
 		*e_code = '\0';
@@ -1256,7 +1256,7 @@ process_preprocessing(void)
 static void __attribute__((__noreturn__))
 main_loop(void)
 {
-    token_type type_code;
+    token_type ttype;
     int force_nl;		/* when true, code must be broken */
     int last_else = false;	/* true iff last keyword was an else */
     int         dec_ind;	/* current indentation for declarations */
@@ -1283,9 +1283,8 @@ main_loop(void)
 				 * reach eof */
 	int comment_buffered = false;
 
-	type_code = lexi(&ps);	/* lexi reads one token.  The actual
-				 * characters read are stored in "token". lexi
-				 * returns a code indicating the type of token */
+	ttype = lexi(&ps);	/* Read the next token.  The actual characters
+				 * read are stored in "token". */
 
 	/*
 	 * The following code moves newlines and comments following an if (),
@@ -1293,21 +1292,21 @@ main_loop(void)
 	 * a buffer. This allows proper handling of both kinds of brace
 	 * placement (-br, -bl) and cuddling "else" (-ce).
 	 */
-	search_brace(&type_code, &force_nl, &comment_buffered, &last_else);
+	search_brace(&ttype, &force_nl, &comment_buffered, &last_else);
 
-	if (type_code == end_of_file) {
+	if (ttype == end_of_file) {
 	    process_end_of_file();
 	    /* NOTREACHED */
 	}
 
 	if (
-		type_code != comment &&
-		type_code != newline &&
-		type_code != preprocessing &&
-		type_code != form_feed) {
-	    process_comment_in_code(type_code, &force_nl);
+		ttype != comment &&
+		ttype != newline &&
+		ttype != preprocessing &&
+		ttype != form_feed) {
+	    process_comment_in_code(ttype, &force_nl);
 
-	} else if (type_code != comment) /* preserve force_nl thru a comment */
+	} else if (ttype != comment) /* preserve force_nl through a comment */
 	    force_nl = false;	/* cancel forced newline after newline, form
 				 * feed, etc */
 
@@ -1320,9 +1319,9 @@ main_loop(void)
 				 * before the next check_size_code or
 				 * dump_line() is 2. After that there's the
 				 * final increment for the null character. */
-	switch (type_code) {	/* now, decide what to do with the token */
+	switch (ttype) {
 
-	case form_feed:		/* found a form feed in line */
+	case form_feed:
 	    process_form_feed();
 	    break;
 
@@ -1410,11 +1409,11 @@ main_loop(void)
 
 	case funcname:
 	case ident:		/* got an identifier or constant */
-	    process_ident(type_code, dec_ind, tabs_to_var, &sp_sw, &force_nl,
-		hd_type);
+	    process_ident(ttype, dec_ind, tabs_to_var, &sp_sw, &force_nl,
+			  hd_type);
     copy_id:
 	    copy_id();
-	    if (type_code != funcname)
+	    if (ttype != funcname)
 		ps.want_blank = true;
 	    break;
 
@@ -1439,13 +1438,13 @@ main_loop(void)
 
 	default:
 	    break;
-	}			/* end of big switch stmt */
+	}
 
-	*e_code = '\0';		/* make sure code section is null terminated */
-	if (type_code != comment &&
-	    type_code != newline &&
-	    type_code != preprocessing)
-	    ps.last_token = type_code;
+	*e_code = '\0';
+	if (ttype != comment &&
+	    ttype != newline &&
+	    ttype != preprocessing)
+	    ps.last_token = ttype;
     }
 }
 

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.46 src/usr.bin/indent/lexi.c:1.47
--- src/usr.bin/indent/lexi.c:1.46	Fri Sep 24 18:47:29 2021
+++ src/usr.bin/indent/lexi.c	Sat Sep 25 07:46:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.46 2021/09/24 18:47:29 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.47 2021/09/25 07:46:41 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,18 +46,12 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.46 2021/09/24 18:47:29 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.47 2021/09/25 07:46:41 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
 #endif
 
-/*
- * Here we have the token scanner for indent.  It scans off one token and puts
- * it in the global variable "token".  It returns a code, indicating the type
- * of token scanned.
- */
-
 #include <assert.h>
 #include <err.h>
 #include <stdio.h>
@@ -239,7 +233,7 @@ compare_string_array(const void *key, co
 
 #ifdef debug
 const char *
-token_type_name(token_type tk)
+token_type_name(token_type ttype)
 {
     static const char *const name[] = {
 	"end_of_file", "newline", "lparen", "rparen", "unary_op",
@@ -253,9 +247,9 @@ token_type_name(token_type tk)
 	"storage_class", "funcname", "type_def", "keyword_struct_union_enum"
     };
 
-    assert(0 <= tk && tk < sizeof name / sizeof name[0]);
+    assert(0 <= ttype && ttype < sizeof name / sizeof name[0]);
 
-    return name[tk];
+    return name[ttype];
 }
 
 static void
@@ -268,17 +262,17 @@ print_buf(const char *name, const char *
 }
 
 static token_type
-lexi_end(token_type code)
+lexi_end(token_type ttype)
 {
     debug_printf("in line %d, lexi returns '%s'",
-	line_no, token_type_name(code));
+	line_no, token_type_name(ttype));
     print_buf("token", s_token, e_token);
     print_buf("label", lab.s, lab.e);
     print_buf("code", s_code, e_code);
     print_buf("comment", com.s, com.e);
     debug_printf("\n");
 
-    return code;
+    return ttype;
 }
 #else
 #  define lexi_end(tk) (tk)
@@ -350,12 +344,13 @@ lex_char_or_string(void)
     } while (*e_token++ != delim);
 }
 
+/* Reads the next token, placing it in the global variable "token". */
 token_type
 lexi(struct parser_state *state)
 {
     int         unary_delim;	/* this is set to 1 if the current token
 				 * forces a following operator to be unary */
-    token_type  code;		/* internal code to be returned */
+    token_type  ttype;
 
     e_token = s_token;		/* point to start of place to save token */
     unary_delim = false;
@@ -506,87 +501,77 @@ lexi(struct parser_state *state)
     case '\n':
 	unary_delim = state->last_u_d;
 	state->last_nl = true;	/* remember that we just had a newline */
-	code = (had_eof ? end_of_file : newline);
-
-	/*
-	 * if data has been exhausted, the newline is a dummy, and we should
-	 * return code to stop
-	 */
+	/* if data has been exhausted, the newline is a dummy. */
+	ttype = had_eof ? end_of_file : newline;
 	break;
 
     case '\'':
     case '"':
 	lex_char_or_string();
-	code = ident;
+	ttype = ident;
 	break;
 
     case '(':
     case '[':
 	unary_delim = true;
-	code = lparen;
+	ttype = lparen;
 	break;
 
     case ')':
     case ']':
-	code = rparen;
+	ttype = rparen;
 	break;
 
     case '#':
 	unary_delim = state->last_u_d;
-	code = preprocessing;
+	ttype = preprocessing;
 	break;
 
     case '?':
 	unary_delim = true;
-	code = question;
+	ttype = question;
 	break;
 
     case ':':
-	code = colon;
+	ttype = colon;
 	unary_delim = true;
 	break;
 
     case ';':
 	unary_delim = true;
-	code = semicolon;
+	ttype = semicolon;
 	break;
 
     case '{':
 	unary_delim = true;
-
-	/*
-	 * if (state->in_or_st) state->block_init = 1;
-	 */
-	/* ?	code = state->block_init ? lparen : lbrace; */
-	code = lbrace;
+	ttype = lbrace;
 	break;
 
     case '}':
 	unary_delim = true;
-	/* ?	code = state->block_init ? rparen : rbrace; */
-	code = rbrace;
+	ttype = rbrace;
 	break;
 
     case 014:			/* a form feed */
 	unary_delim = state->last_u_d;
 	state->last_nl = true;	/* remember this so we can set 'state->col_1'
 				 * right */
-	code = form_feed;
+	ttype = form_feed;
 	break;
 
     case ',':
 	unary_delim = true;
-	code = comma;
+	ttype = comma;
 	break;
 
     case '.':
 	unary_delim = false;
-	code = period;
+	ttype = period;
 	break;
 
     case '-':
     case '+':			/* check for -, +, --, ++ */
-	code = (state->last_u_d ? unary_op : binary_op);
+	ttype = state->last_u_d ? unary_op : binary_op;
 	unary_delim = true;
 
 	if (*buf_ptr == token[0]) {
@@ -594,7 +579,7 @@ lexi(struct parser_state *state)
 	    *e_token++ = *buf_ptr++;
 	    /* buffer overflow will be checked at end of loop */
 	    if (state->last_token == ident || state->last_token == rparen) {
-		code = (state->last_u_d ? unary_op : postfix_op);
+		ttype = state->last_u_d ? unary_op : postfix_op;
 		/* check for following ++ or -- */
 		unary_delim = false;
 	    }
@@ -605,7 +590,7 @@ lexi(struct parser_state *state)
 	    /* check for operator -> */
 	    *e_token++ = *buf_ptr++;
 	    unary_delim = false;
-	    code = unary_op;
+	    ttype = unary_op;
 	    state->want_blank = false;
 	}
 	break;			/* buffer overflow will be checked at end of
@@ -619,7 +604,7 @@ lexi(struct parser_state *state)
 	    buf_ptr++;
 	    *e_token = 0;
 	}
-	code = binary_op;
+	ttype = binary_op;
 	unary_delim = true;
 	break;
 	/* can drop thru!!! */
@@ -631,7 +616,7 @@ lexi(struct parser_state *state)
 	    *e_token++ = inbuf_next();
 	if (*buf_ptr == '=')
 	    *e_token++ = *buf_ptr++;
-	code = (state->last_u_d ? unary_op : binary_op);
+	ttype = state->last_u_d ? unary_op : binary_op;
 	unary_delim = true;
 	break;
 
@@ -640,7 +625,7 @@ lexi(struct parser_state *state)
 	if (!state->last_u_d) {
 	    if (*buf_ptr == '=')
 		*e_token++ = *buf_ptr++;
-	    code = binary_op;
+	    ttype = binary_op;
 	    break;
 	}
 	while (*buf_ptr == '*' || isspace((unsigned char)*buf_ptr)) {
@@ -661,7 +646,7 @@ lexi(struct parser_state *state)
 	    if (*tp == '(')
 		ps.procname[0] = ' ';
 	}
-	code = unary_op;
+	ttype = unary_op;
 	break;
 
     default:
@@ -669,7 +654,7 @@ lexi(struct parser_state *state)
 	    /* it is start of comment */
 	    *e_token++ = inbuf_next();
 
-	    code = comment;
+	    ttype = comment;
 	    unary_delim = state->last_u_d;
 	    break;
 	}
@@ -680,17 +665,16 @@ lexi(struct parser_state *state)
 	    check_size_token(1);
 	    *e_token++ = inbuf_next();
 	}
-	code = (state->last_u_d ? unary_op : binary_op);
+	ttype = state->last_u_d ? unary_op : binary_op;
 	unary_delim = true;
+    }
 
-
-    }				/* end of switch */
     if (buf_ptr >= buf_end)	/* check for input buffer empty */
 	fill_buffer();
     state->last_u_d = unary_delim;
     check_size_token(1);
-    *e_token = '\0';		/* null terminate the token */
-    return lexi_end(code);
+    *e_token = '\0';
+    return lexi_end(ttype);
 }
 
 void

Index: src/usr.bin/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.18 src/usr.bin/indent/parse.c:1.19
--- src/usr.bin/indent/parse.c:1.18	Fri Mar 12 23:10:18 2021
+++ src/usr.bin/indent/parse.c	Sat Sep 25 07:46:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.18 2021/03/12 23:10:18 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.19 2021/09/25 07:46:41 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -60,15 +60,15 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 static void reduce(void);
 
 void
-parse(token_type tk)		/* tk: the code for the construct scanned */
+parse(token_type ttype)
 {
     int         i;
 
 #ifdef debug
-    printf("parse token: '%s' \"%s\"\n", token_type_name(tk), token);
+    printf("parse token: '%s' \"%s\"\n", token_type_name(ttype), token);
 #endif
 
-    while (ps.p_stack[ps.tos] == if_expr_stmt && tk != keyword_else) {
+    while (ps.p_stack[ps.tos] == if_expr_stmt && ttype != keyword_else) {
 	/* true if we have an if without an else */
 	ps.p_stack[ps.tos] = stmt;	/* apply the if(..) stmt ::= stmt
 					 * reduction */
@@ -76,7 +76,7 @@ parse(token_type tk)		/* tk: the code fo
     }
 
 
-    switch (tk) {		/* go on and figure out what to do with the
+    switch (ttype) {		/* go on and figure out what to do with the
 				 * input */
 
     case decl:			/* scanned a declaration word */
@@ -114,7 +114,7 @@ parse(token_type tk)		/* tk: the code fo
 	/* FALLTHROUGH */
     case keyword_do:		/* 'do' */
     case for_exprs:		/* 'for' (...) */
-	ps.p_stack[++ps.tos] = tk;
+	ps.p_stack[++ps.tos] = ttype;
 	ps.il[ps.tos] = ps.ind_level = ps.i_l_follow;
 	++ps.i_l_follow;	/* subsequent statements should be indented 1 */
 	ps.search_brace = opt.btype_2;

Reply via email to