indent: fix the -fno-common build

Spread the globals far and wide, hopefully to the files that make the most
sense.

-fno-common will become the default in GCC10/LLVM11.

MFC after:	3 days
This commit is contained in:
kevans 2020-04-06 23:20:20 +00:00
parent 008e530970
commit e08f7da384
4 changed files with 88 additions and 46 deletions

View File

@ -59,6 +59,30 @@ __FBSDID("$FreeBSD$");
#include "indent_codes.h" #include "indent_codes.h"
#include "indent.h" #include "indent.h"
/* Globals */
FILE *input, *output;
char *labbuf, *s_lab, *e_lab, *l_lab;
char *codebuf, *s_code, *e_code, *l_code;
char *combuf, *s_com, *e_com, *l_com;
char *tokenbuf, *s_token, *e_token, *l_token;
char *in_buffer, *in_buffer_limit;
char *buf_ptr, *buf_end;
char sc_buf[sc_size];
char *save_com, *sc_end;
char *bp_save;
char *be_save;
struct options opt;
int line_no;
struct parser_state ps;
int ifdef_level;
struct parser_state state_stack[5];
struct parser_state match_state[5];
static void bakcopy(void); static void bakcopy(void);
static void indent_declaration(int, int); static void indent_declaration(int, int);

View File

@ -49,8 +49,8 @@
#define true 1 #define true 1
FILE *input; /* the fid for the input file */ extern FILE *input; /* the fid for the input file */
FILE *output; /* the output file */ extern FILE *output; /* the output file */
#define CHECK_SIZE_CODE(desired_size) \ #define CHECK_SIZE_CODE(desired_size) \
if (e_code + (desired_size) >= l_code) { \ if (e_code + (desired_size) >= l_code) { \
@ -104,41 +104,43 @@ FILE *output; /* the output file */
s_token = tokenbuf + 1; \ s_token = tokenbuf + 1; \
} }
char *labbuf; /* buffer for label */ extern char *labbuf; /* buffer for label */
char *s_lab; /* start ... */ extern char *s_lab; /* start ... */
char *e_lab; /* .. and end of stored label */ extern char *e_lab; /* .. and end of stored label */
char *l_lab; /* limit of label buffer */ extern char *l_lab; /* limit of label buffer */
char *codebuf; /* buffer for code section */ extern char *codebuf; /* buffer for code section */
char *s_code; /* start ... */ extern char *s_code; /* start ... */
char *e_code; /* .. and end of stored code */ extern char *e_code; /* .. and end of stored code */
char *l_code; /* limit of code section */ extern char *l_code; /* limit of code section */
char *combuf; /* buffer for comments */ extern char *combuf; /* buffer for comments */
char *s_com; /* start ... */ extern char *s_com; /* start ... */
char *e_com; /* ... and end of stored comments */ extern char *e_com; /* ... and end of stored comments */
char *l_com; /* limit of comment buffer */ extern char *l_com; /* limit of comment buffer */
#define token s_token #define token s_token
char *tokenbuf; /* the last token scanned */ extern char *tokenbuf; /* the last token scanned */
char *s_token; extern char *s_token;
char *e_token; extern char *e_token;
char *l_token; extern char *l_token;
char *in_buffer; /* input buffer */ extern char *in_buffer; /* input buffer */
char *in_buffer_limit; /* the end of the input buffer */ extern char *in_buffer_limit; /* the end of the input buffer */
char *buf_ptr; /* ptr to next character to be taken from extern char *buf_ptr; /* ptr to next character to be taken
* in_buffer */ * from in_buffer */
char *buf_end; /* ptr to first after last char in in_buffer */ extern char *buf_end; /* ptr to first after last char in
* in_buffer */
char sc_buf[sc_size]; /* input text is saved here when looking for extern char sc_buf[sc_size]; /* input text is saved here when looking
* the brace after an if, while, etc */ * for the brace after an if, while, etc */
char *save_com; /* start of the comment stored in sc_buf */ extern char *save_com; /* start of the comment stored in
char *sc_end; /* pointer into save_com buffer */ * sc_buf */
extern char *sc_end; /* pointer into save_com buffer */
char *bp_save; /* saved value of buf_ptr when taking input extern char *bp_save; /* saved value of buf_ptr when taking
* from save_com */ * input from save_com */
char *be_save; /* similarly saved value of buf_end */ extern char *be_save; /* similarly saved value of buf_end */
struct options { struct options {
@ -217,21 +219,22 @@ struct options {
* uses all spaces */ * uses all spaces */
int verbose; /* when true, non-essential error messages int verbose; /* when true, non-essential error messages
* are printed */ * are printed */
} opt; };
extern struct options opt;
int found_err; extern int found_err;
int n_real_blanklines; extern int n_real_blanklines;
int prefix_blankline_requested; extern int prefix_blankline_requested;
int postfix_blankline_requested; extern int postfix_blankline_requested;
int break_comma; /* when true and not in parens, break after a extern int break_comma; /* when true and not in parens, break after a
* comma */ * comma */
float case_ind; /* indentation level to be used for a "case extern float case_ind; /* indentation level to be used for a "case
* n:" */ * n:" */
int code_lines; /* count of lines with code */ extern int code_lines; /* count of lines with code */
int had_eof; /* set to true when input is exhausted */ extern int had_eof; /* set to true when input is exhausted */
int line_no; /* the current line number. */ extern int line_no; /* the current line number. */
int inhibit_formatting; /* true if INDENT OFF is in effect */ extern int inhibit_formatting; /* true if INDENT OFF is in effect */
int suppress_blanklines;/* set iff following blanklines should be extern int suppress_blanklines;/* set iff following blanklines should be
* suppressed */ * suppressed */
#define STACKSIZE 256 #define STACKSIZE 256
@ -312,8 +315,10 @@ struct parser_state {
int tos; /* pointer to top of stack */ int tos; /* pointer to top of stack */
char procname[100]; /* The name of the current procedure */ char procname[100]; /* The name of the current procedure */
int just_saw_decl; int just_saw_decl;
} ps; };
int ifdef_level; extern struct parser_state ps;
struct parser_state state_stack[5];
struct parser_state match_state[5]; extern int ifdef_level;
extern struct parser_state state_stack[5];
extern struct parser_state match_state[5];

View File

@ -52,6 +52,15 @@ __FBSDID("$FreeBSD$");
#include "indent_globs.h" #include "indent_globs.h"
#include "indent.h" #include "indent.h"
/* Globals */
int found_err;
int n_real_blanklines;
int prefix_blankline_requested, postfix_blankline_requested;
int code_lines;
int had_eof;
int inhibit_formatting;
int suppress_blanklines;
int comment_open; int comment_open;
static int paren_target; static int paren_target;
static int pad_output(int current, int target); static int pad_output(int current, int target);

View File

@ -50,6 +50,10 @@ __FBSDID("$FreeBSD$");
#include "indent_codes.h" #include "indent_codes.h"
#include "indent.h" #include "indent.h"
/* Globals */
int break_comma;
float case_ind;
static void reduce(void); static void reduce(void);
void void