CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Sep 24 18:47:29 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent_globs.h io.c lexi.c pr_comment.c Log Message: indent: group global variables for label buffer into struct No functional change. To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/usr.bin/indent/indent.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/indent/indent_globs.h cvs rdiff -u -r1.53 -r1.54 src/usr.bin/indent/io.c cvs rdiff -u -r1.45 -r1.46 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.36 -r1.37 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Sep 24 18:37:03 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: extract parse_indent_comment from fill_buffer No functional change. To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/usr.bin/indent/io.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/io.c diff -u src/usr.bin/indent/io.c:1.52 src/usr.bin/indent/io.c:1.53 --- src/usr.bin/indent/io.c:1.52 Fri Sep 24 18:14:06 2021 +++ src/usr.bin/indent/io.c Fri Sep 24 18:37:03 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.52 2021/09/24 18:14:06 rillig Exp $ */ +/* $NetBSD: io.c,v 1.53 2021/09/24 18:37:03 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.52 2021/09/24 18:14:06 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.53 2021/09/24 18:37:03 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -330,6 +330,61 @@ compute_label_indent(void) return opt.indent_size * (ps.ind_level - label_offset); } +static void +skip_hspace(const char **pp) +{ +while (**pp == ' ' || **pp == '\t') + (*pp)++; +} + +static void +parse_indent_comment(void) +{ +int on_off = 0; /* 0 = keep, 1 = ON, 2 = OFF */ + +const char *p = in_buffer; + +skip_hspace(&p); + +if (!(*p == '/' && p[1] == '*')) + return; +p += 2; + +skip_hspace(&p); + +if (!(p[0] == 'I' && p[1] == 'N' && p[2] == 'D' + && p[3] == 'E' && p[4] == 'N' && p[5] == 'T')) + return; +p += 6; + +skip_hspace(&p); + +if (*p == '*') + on_off = 1; +else if (*p == 'O') { + if (*++p == 'N') + p++, on_off = 1; + else if (*p == 'F' && *++p == 'F') + p++, on_off = 2; +} +if (on_off == 0) + return; + +skip_hspace(&p); + +if (!(p[0] == '*' && p[1] == '/' && p[2] == '\n')) + return; + +if (com.s != com.e || s_lab != e_lab || s_code != e_code) + dump_line(); + +if (!(inhibit_formatting = on_off - 1)) { + n_real_blanklines = 0; + postfix_blankline_requested = 0; + prefix_blankline_requested = 0; + suppress_blanklines = 1; +} +} /* * Copyright (C) 1976 by the Board of Trustees of the University of Illinois @@ -380,44 +435,8 @@ fill_buffer(void) if (p - in_buffer > 2 && p[-2] == '/' && p[-3] == '*') { if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0) fill_buffer(); /* flush indent error message */ - else { - int comena = 0; /* 1 = ON, 2 = OFF */ - - p = in_buffer; - while (*p == ' ' || *p == '\t') - p++; - if (*p == '/' && p[1] == '*') { - p += 2; - while (*p == ' ' || *p == '\t') - p++; - if (p[0] == 'I' && p[1] == 'N' && p[2] == 'D' && p[3] == 'E' - && p[4] == 'N' && p[5] == 'T') { - p += 6; - while (*p == ' ' || *p == '\t') - p++; - if (*p == '*') - comena = 1; - else if (*p == 'O') { - if (*++p == 'N') - p++, comena = 1; - else if (*p == 'F' && *++p == 'F') - p++, comena = 2; - } - while (*p == ' ' || *p == '\t') - p++; - if (p[0] == '*' && p[1] == '/' && p[2] == '\n' && comena) { - if (com.s != com.e || s_lab != e_lab || s_code != e_code) - dump_line(); - if (!(inhibit_formatting = comena - 1)) { - n_real_blanklines = 0; - postfix_blankline_requested = 0; - prefix_blankline_requested = 0; - suppress_blanklines = 1; - } - } - } - } - } + else + parse_indent_comment(); } if (inhibit_formatting) { p = in_buffer;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Sep 24 18:37:03 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: extract parse_indent_comment from fill_buffer No functional change. To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Sep 24 18:14:06 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent_globs.h io.c lexi.c pr_comment.c Log Message: indent: group global variables for the comment buffer No functional change. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/usr.bin/indent/indent.c cvs rdiff -u -r1.21 -r1.22 src/usr.bin/indent/indent_globs.h cvs rdiff -u -r1.51 -r1.52 src/usr.bin/indent/io.c cvs rdiff -u -r1.44 -r1.45 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.35 -r1.36 src/usr.bin/indent/pr_comment.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.61 src/usr.bin/indent/indent.c:1.62 --- src/usr.bin/indent/indent.c:1.61 Wed Aug 25 22:26:30 2021 +++ src/usr.bin/indent/indent.c Fri Sep 24 18:14:06 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.61 2021/08/25 22:26:30 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.62 2021/09/24 18:14:06 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.61 2021/08/25 22:26:30 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.62 2021/09/24 18:14:06 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -81,10 +81,7 @@ char *s_code; char *e_code; char *l_code; -char *combuf; -char *s_com; -char *e_com; -char *l_com; +struct comment_buffer com; char *tokenbuf; char *s_token; @@ -377,8 +374,8 @@ main_init_globals(void) ps.last_nl = true; /* this is true if the last thing scanned was * a newline */ ps.last_token = semicolon; -combuf = malloc(bufsize); -if (combuf == NULL) +com.buf = malloc(bufsize); +if (com.buf == NULL) err(1, NULL); labbuf = malloc(bufsize); if (labbuf == NULL) @@ -391,17 +388,17 @@ main_init_globals(void) err(1, NULL); alloc_typenames(); init_constant_tt(); -l_com = combuf + bufsize - 5; +com.l = com.buf + 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 +com.buf[0] = codebuf[0] = labbuf[0] = ' '; /* set up code, label, and * comment buffers */ -combuf[1] = codebuf[1] = labbuf[1] = tokenbuf[1] = '\0'; +com.buf[1] = codebuf[1] = labbuf[1] = tokenbuf[1] = '\0'; opt.else_if = 1; /* Default else-if special processing to on */ s_lab = e_lab = labbuf + 1; s_code = e_code = codebuf + 1; -s_com = e_com = combuf + 1; +com.s = com.e = com.buf + 1; s_token = e_token = tokenbuf + 1; in_buffer = malloc(10); @@ -549,7 +546,7 @@ main_prepare_parsing(void) static void __attribute__((__noreturn__)) process_end_of_file(void) { -if (s_lab != e_lab || s_code != e_code || s_com != e_com) +if (s_lab != e_lab || s_code != e_code || com.s != com.e) dump_line(); if (ps.tos > 1) /* check for balanced braces */ @@ -584,18 +581,18 @@ process_comment_in_code(token_type type_ ps.in_stmt = true; /* turn on flag which causes an extra level of * indentation. this is turned off by a ; or * '}' */ -if (s_com != e_com) { /* the turkey has embedded a comment +if (com.s != com.e) { /* the turkey has embedded a comment * in a line. fix it */ - size_t len = e_com - s_com; + size_t len = com.e - com.s; check_size_code(len + 3); *e_code++ = ' '; - memcpy(e_code, s_com, len); + memcpy(e_code, com.s, len); e_code += len; *e_code++ = ' '; *e_code = '\0'; /* null terminate code sect */ ps.want_blank = false; - e_com = s_com; + com.e = com.s; } } @@ -611,7 +608,7 @@ static void process_newline(void) { if (ps.last_token != comma || ps.p_l_follow > 0 - || !opt.leave_comma || ps.block_init || !break_comma || s_com != e_com) { + || !opt.leave_comma || ps.block_init || !break_comma || com.s != com.e) { dump_line(); ps.want_blank = false; } @@ -1123,7 +1120,7 @@ process_comma(int dec_ind, int tabs_to_v static void process_preprocessing(void) { -if (s_com != e_com || s_lab != e_lab || s_code != e_code) +if (com.s != com.e || s_lab != e_lab || s_code != e_code) dump_line(); check_size_label(1); *e_lab++ = '#'; /* move whole line to 'label' buffer */ Index: src/usr.bin/indent/indent_globs.h diff -u src/usr.bin/indent/indent_globs.h:1.21 src/usr.bin/indent/indent_globs.h:1.22 --- src/usr.bin/indent/indent_globs.h:1.21 Sat Mar 13 23:36:10 2021 +++ src/usr.bin/indent/indent_globs.h Fri Sep 24 18:14:06 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_globs.h,v 1.21 2021/03/13 23:36:10 rillig Exp $ */ +/* $NetBSD: indent_globs
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Sep 24 18:14:06 UTC 2021 Modified Files: src/usr.bin/indent: indent.c indent_globs.h io.c lexi.c pr_comment.c Log Message: indent: group global variables for the comment buffer No functional change. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/usr.bin/indent/indent.c cvs rdiff -u -r1.21 -r1.22 src/usr.bin/indent/indent_globs.h cvs rdiff -u -r1.51 -r1.52 src/usr.bin/indent/io.c cvs rdiff -u -r1.44 -r1.45 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.35 -r1.36 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Sep 24 18:00:13 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: rename local variable in fill_buffer The local variable name 'com' prevented grouping the global variables combuf, s_com, e_com and l_com into a struct named 'com'. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 src/usr.bin/indent/io.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/io.c diff -u src/usr.bin/indent/io.c:1.50 src/usr.bin/indent/io.c:1.51 --- src/usr.bin/indent/io.c:1.50 Fri Sep 24 16:29:31 2021 +++ src/usr.bin/indent/io.c Fri Sep 24 18:00:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.50 2021/09/24 16:29:31 rillig Exp $ */ +/* $NetBSD: io.c,v 1.51 2021/09/24 18:00:13 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.50 2021/09/24 16:29:31 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.51 2021/09/24 18:00:13 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -381,7 +381,7 @@ fill_buffer(void) if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0) fill_buffer(); /* flush indent error message */ else { - int com = 0; + int comena = 0; /* 1 = ON, 2 = OFF */ p = in_buffer; while (*p == ' ' || *p == '\t') @@ -396,19 +396,19 @@ fill_buffer(void) while (*p == ' ' || *p == '\t') p++; if (*p == '*') - com = 1; + comena = 1; else if (*p == 'O') { if (*++p == 'N') - p++, com = 1; + p++, comena = 1; else if (*p == 'F' && *++p == 'F') - p++, com = 2; + p++, comena = 2; } while (*p == ' ' || *p == '\t') p++; - if (p[0] == '*' && p[1] == '/' && p[2] == '\n' && com) { + if (p[0] == '*' && p[1] == '/' && p[2] == '\n' && comena) { if (s_com != e_com || s_lab != e_lab || s_code != e_code) dump_line(); - if (!(inhibit_formatting = com - 1)) { + if (!(inhibit_formatting = comena - 1)) { n_real_blanklines = 0; postfix_blankline_requested = 0; prefix_blankline_requested = 0;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Sep 24 18:00:13 UTC 2021 Modified Files: src/usr.bin/indent: io.c Log Message: indent: rename local variable in fill_buffer The local variable name 'com' prevented grouping the global variables combuf, s_com, e_com and l_com into a struct named 'com'. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Sep 24 06:23:35 UTC 2021 Modified Files: src/usr.bin/indent: lexi.c Log Message: indent: fix space-tab in indentation To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/usr.bin/indent/lexi.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/lexi.c diff -u src/usr.bin/indent/lexi.c:1.43 src/usr.bin/indent/lexi.c:1.44 --- src/usr.bin/indent/lexi.c:1.43 Thu Aug 26 07:03:00 2021 +++ src/usr.bin/indent/lexi.c Fri Sep 24 06:23:35 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.43 2021/08/26 07:03:00 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.44 2021/09/24 06:23:35 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.43 2021/08/26 07:03:00 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.44 2021/09/24 06:23:35 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -516,7 +516,7 @@ lexi(struct parser_state *state) case '\'': case '"': - lex_char_or_string(); + lex_char_or_string(); code = ident; break;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Sep 24 06:23:35 UTC 2021 Modified Files: src/usr.bin/indent: lexi.c Log Message: indent: fix space-tab in indentation To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu Aug 26 07:03:00 UTC 2021 Modified Files: src/usr.bin/indent: lexi.c Log Message: indent: extract lex_number, lex_word, lex_char_or_string No functional change. To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.43 src/usr.bin/indent/lexi.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/lexi.c diff -u src/usr.bin/indent/lexi.c:1.42 src/usr.bin/indent/lexi.c:1.43 --- src/usr.bin/indent/lexi.c:1.42 Wed Aug 25 22:26:30 2021 +++ src/usr.bin/indent/lexi.c Thu Aug 26 07:03:00 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.42 2021/08/25 22:26:30 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.43 2021/08/26 07:03:00 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.42 2021/08/25 22:26:30 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.43 2021/08/26 07:03:00 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -284,13 +284,78 @@ lexi_end(token_type code) # define lexi_end(tk) (tk) #endif +static void +lex_number(void) +{ +char s; +unsigned char i; + +for (s = 'A'; s != 'f' && s != 'i' && s != 'u'; ) { + i = (unsigned char)*buf_ptr; + if (i >= nitems(table) || table[i] == NULL || + table[i][s - 'A'] == ' ') { + s = table[0][s - 'A']; + break; + } + s = table[i][s - 'A']; + check_size_token(1); + *e_token++ = inbuf_next(); +} +/* s now indicates the type: f(loating), i(integer), u(nknown) */ +} + +static void +lex_word(void) +{ +while (isalnum((unsigned char)*buf_ptr) || + *buf_ptr == '\\' || + *buf_ptr == '_' || *buf_ptr == '$') { + /* fill_buffer() terminates buffer with newline */ + if (*buf_ptr == '\\') { + if (buf_ptr[1] == '\n') { + buf_ptr += 2; + if (buf_ptr >= buf_end) + fill_buffer(); + } else + break; + } + check_size_token(1); + *e_token++ = inbuf_next(); +} +} + +static void +lex_char_or_string(void) +{ +char delim; + +delim = *token; +do { /* copy the string */ + for (;;) { /* move one character or [/] */ + if (*buf_ptr == '\n') { + diag(1, "Unterminated literal"); + return; + } + check_size_token(2); + *e_token = inbuf_next(); + if (*e_token == '\\') { /* if escape, copy extra char */ + if (*buf_ptr == '\n') /* check for escaped newline */ + ++line_no; + *++e_token = inbuf_next(); + ++e_token; /* we must increment this again because we + * copied two chars */ + } else + break; /* we copied one character */ + } /* end of while (1) */ +} while (*e_token++ != delim); +} + 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 */ -charqchar; /* the delimiter character for a string */ e_token = s_token; /* point to start of place to save token */ unary_delim = false; @@ -310,43 +375,15 @@ lexi(struct parser_state *state) *buf_ptr == '_' || *buf_ptr == '$' || (buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) { /* - * we have a character or number + * we have a letter or number */ struct templ *p; if (isdigit((unsigned char)*buf_ptr) || (buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) { - char s; - unsigned char i; - - for (s = 'A'; s != 'f' && s != 'i' && s != 'u'; ) { - i = (unsigned char)*buf_ptr; - if (i >= nitems(table) || table[i] == NULL || - table[i][s - 'A'] == ' ') { - s = table[0][s - 'A']; - break; - } - s = table[i][s - 'A']; - check_size_token(1); - *e_token++ = inbuf_next(); - } - /* s now indicates the type: f(loating), i(integer), u(nknown) */ + lex_number(); } else { - while (isalnum((unsigned char)*buf_ptr) || - *buf_ptr == '\\' || - *buf_ptr == '_' || *buf_ptr == '$') { - /* fill_buffer() terminates buffer with newline */ - if (*buf_ptr == '\\') { - if (buf_ptr[1] == '\n') { - buf_ptr += 2; - if (buf_ptr >= buf_end) - fill_buffer(); - } else - break; - } - check_size_token(1); - *e_token++ = inbuf_next(); - } + lex_word(); } *e_token = '\0'; @@ -477,28 +514,9 @@ lexi(struct parser_state *state) */ break; -case '\'': /* start of quoted character */ -case '"': /* start of string */ - qchar = *token; - do { /* copy the string */ - for (;;) { /* move one character or [/] */ - if (*buf_ptr == '\n') { - diag(1, "Unterminated literal"); - goto stop_lit; - } - check_size_token(2); - *e_token = inbuf_next(); - if (*e_token == '\\') { /* if escape, copy extra char */ - if (*buf_p
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu Aug 26 07:03:00 UTC 2021 Modified Files: src/usr.bin/indent: lexi.c Log Message: indent: extract lex_number, lex_word, lex_char_or_string No functional change. To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.43 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Wed Aug 25 22:26:30 UTC 2021 Modified Files: src/usr.bin/indent: indent.c lexi.c Log Message: indent: fix lint warnings about type conversions on ilp32 No functional change. To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/usr.bin/indent/indent.c cvs rdiff -u -r1.41 -r1.42 src/usr.bin/indent/lexi.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.60 src/usr.bin/indent/indent.c:1.61 --- src/usr.bin/indent/indent.c:1.60 Fri Mar 26 22:02:00 2021 +++ src/usr.bin/indent/indent.c Wed Aug 25 22:26:30 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.60 2021/03/26 22:02:00 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.61 2021/08/25 22:26:30 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.60 2021/03/26 22:02:00 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.61 2021/08/25 22:26:30 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -1197,7 +1197,7 @@ process_preprocessing(void) } if (sc_end - save_com + com_end - com_start > sc_size) errx(1, "input too long"); - memmove(sc_end, s_lab + com_start, com_end - com_start); + memmove(sc_end, s_lab + com_start, (size_t)(com_end - com_start)); sc_end += com_end - com_start; e_lab = s_lab + com_start; while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t')) @@ -1235,22 +1235,12 @@ process_preprocessing(void) else ifdef_level--; } else { - static const struct directives { - int size; - const char *string; - } recognized[] = { - {7, "include"}, - {6, "define"}, - {5, "undef"}, - {4, "line"}, - {5, "error"}, - {6, "pragma"} - }; - int d = nitems(recognized); - while (--d >= 0) - if (strncmp(s_lab + 1, recognized[d].string, recognized[d].size) == 0) - break; - if (d < 0) { + if (strncmp(s_lab + 1, "pragma", 6) != 0 && + strncmp(s_lab + 1, "error", 5) != 0 && + strncmp(s_lab + 1, "line", 4) != 0 && + strncmp(s_lab + 1, "undef", 5) != 0 && + strncmp(s_lab + 1, "define", 6) != 0 && + strncmp(s_lab + 1, "include", 7) != 0) { diag(1, "Unrecognized cpp directive"); return; } @@ -1538,13 +1528,13 @@ indent_declaration(int cur_dec_ind, int if (tabs_to_var) { int tpos; - check_size_code(cur_dec_ind / opt.tabsize); + check_size_code((size_t)(cur_dec_ind / opt.tabsize)); while ((tpos = opt.tabsize * (1 + pos / opt.tabsize)) <= cur_dec_ind) { *e_code++ = '\t'; pos = tpos; } } -check_size_code(cur_dec_ind - pos + 1); +check_size_code((size_t)(cur_dec_ind - pos + 1)); while (pos < cur_dec_ind) { *e_code++ = ' '; pos++; Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.41 src/usr.bin/indent/lexi.c:1.42 --- src/usr.bin/indent/lexi.c:1.41 Sun Mar 14 00:22:16 2021 +++ src/usr.bin/indent/lexi.c Wed Aug 25 22:26:30 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.41 2021/03/14 00:22:16 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.42 2021/08/25 22:26:30 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.41 2021/03/14 00:22:16 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.42 2021/08/25 22:26:30 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -377,7 +377,7 @@ lexi(struct parser_state *state) /* ... so maybe a type_t or a typedef */ if ((opt.auto_typedefs && ((u = strrchr(s_token, '_')) != NULL) && strcmp(u, "_t") == 0) || (typename_top >= 0 && - bsearch(s_token, typenames, typename_top + 1, + bsearch(s_token, typenames, (size_t)typename_top + 1, sizeof typenames[0], compare_string_array))) { state->keyword = rw_type; state->last_u_d = true;
CVS commit: src/usr.bin/indent
Module Name:src Committed By: rillig Date: Wed Aug 25 22:26:30 UTC 2021 Modified Files: src/usr.bin/indent: indent.c lexi.c Log Message: indent: fix lint warnings about type conversions on ilp32 No functional change. To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/usr.bin/indent/indent.c cvs rdiff -u -r1.41 -r1.42 src/usr.bin/indent/lexi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/indent
Module Name:src Committed By: christos Date: Sat Oct 19 15:44:31 UTC 2019 Modified Files: src/usr.bin/indent: indent.c indent.h io.c lexi.c parse.c Log Message: use stdarg, annotate function as __printflike and fix broken formats. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/indent.c cvs rdiff -u -r1.1 -r1.2 src/usr.bin/indent/indent.h cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/io.c cvs rdiff -u -r1.16 -r1.17 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.9 -r1.10 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.
CVS commit: src/usr.bin/indent
Module Name:src Committed By: christos Date: Sat Oct 19 15:44:31 UTC 2019 Modified Files: src/usr.bin/indent: indent.c indent.h io.c lexi.c parse.c Log Message: use stdarg, annotate function as __printflike and fix broken formats. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/indent.c cvs rdiff -u -r1.1 -r1.2 src/usr.bin/indent/indent.h cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/io.c cvs rdiff -u -r1.16 -r1.17 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.9 -r1.10 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.25 src/usr.bin/indent/indent.c:1.26 --- src/usr.bin/indent/indent.c:1.25 Thu Apr 4 11:22:13 2019 +++ src/usr.bin/indent/indent.c Sat Oct 19 11:44:31 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.25 2019/04/04 15:22:13 kamil Exp $ */ +/* $NetBSD: indent.c,v 1.26 2019/10/19 15:44:31 christos Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.25 2019/04/04 15:22:13 kamil Exp $"); +__RCSID("$NetBSD: indent.c,v 1.26 2019/10/19 15:44:31 christos Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -360,7 +360,7 @@ main(int argc, char **argv) break; /* we are at end of comment */ if (sc_end >= &save_com[sc_size]) { /* check for temp buffer * overflow */ - diag2(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever"); + diag(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever"); fflush(output); exit(1); } @@ -429,7 +429,7 @@ main(int argc, char **argv) *sc_end++ = ' '; if (opt.verbose) /* print error msg if the line was * not already broken */ - diag2(0, "Line broken"); + diag(0, "Line broken"); } for (t_ptr = token; *t_ptr; ++t_ptr) *sc_end++ = *t_ptr; @@ -498,7 +498,7 @@ check_type: || s_com != e_com) /* must dump end of line */ dump_line(); if (ps.tos > 1) /* check for balanced braces */ - diag2(1, "Stuff missing from end of file"); + diag(1, "Stuff missing from end of file"); if (opt.verbose) { printf("There were %d output lines and %d comments\n", @@ -519,7 +519,7 @@ check_type: (type_code != lbrace || !opt.btype_2)) { /* we should force a broken line here */ if (opt.verbose) - diag2(0, "Line broken"); + diag(0, "Line broken"); dump_line(); ps.want_blank = false; /* dont insert blank at line start */ force_nl = false; @@ -574,7 +574,7 @@ check_type: case lparen: /* got a '(' or '[' */ /* count parens to make Healy happy */ if (++ps.p_l_follow == nitems(ps.paren_indents)) { - diag3(0, "Reached internal limit of %d unclosed parens", + diag(0, "Reached internal limit of %zu unclosed parens", nitems(ps.paren_indents)); ps.p_l_follow--; } @@ -625,7 +625,7 @@ check_type: ps.not_cast_mask &= (1 << ps.p_l_follow) - 1; if (--ps.p_l_follow < 0) { ps.p_l_follow = 0; - diag3(0, "Extra %c", *token); + diag(0, "Extra %c", *token); } if (e_code == s_code) /* if the paren starts the line */ ps.paren_level = ps.p_l_follow; /* then indent it */ @@ -779,7 +779,7 @@ check_type: * stmt. It is a bit complicated, because the semicolon might * be in a for stmt */ - diag2(1, "Unbalanced parens"); + diag(1, "Unbalanced parens"); ps.p_l_follow = 0; if (sp_sw) { /* this is a check for an if, while, etc. with * unbalanced parens */ @@ -828,7 +828,7 @@ check_type: if (ps.p_l_follow > 0) { /* check for preceding unbalanced * parens */ - diag2(1, "Unbalanced parens"); + diag(1, "Unbalanced parens"); ps.p_l_follow = 0; if (sp_sw) { /* check for unclosed if, for, etc. */ sp_sw = false; @@ -843,7 +843,7 @@ check_type: * declaration or an init */ di_stack[ps.dec_nest] = dec_ind; if (++ps.dec_nest == nitems(di_stack)) { - diag3(0, "Reached internal limit of %d struct levels", + diag(0, "Reached internal limit of %zu struct levels", nitems(di_stack)); ps.dec_nest--; } @@ -876,7 +876,7 @@ check_type: * declarations */ parse(semicolon); if (ps.p_l_follow) {/* check for unclosed if, for, else. */ - diag2(1, "Unbalanced parens"); + diag(1, "Unbalanced parens"); ps.p_l_follow = 0; sp_sw = false; } @@ -885,7 +885,7 @@ check_type: if (s_code != e_code && !ps.block_init) { /* '}' must be first on * line */ if (opt.verbose) - diag2(0, "Line broken"); + diag(0, "Line broken"); dump_line(); } *e_code++ = '}'; @@ -928,7 +928,7 @@ check_t