Skip to content

Commit

Permalink
Cleanup coding style consistency.
Browse files Browse the repository at this point in the history
Add space after reserved words if/while/switch/for/return/do
  • Loading branch information
James Parkinson committed Jul 17, 2021
1 parent 4c137a4 commit 09c53ce
Show file tree
Hide file tree
Showing 20 changed files with 1,994 additions and 1,413 deletions.
20 changes: 10 additions & 10 deletions awka/awka.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ isarray(char *var)
-----------------------------------------------------------------------------
*/

static char* tmpfile_prefix(const char *pattern){
static char* tmpfile_prefix(const char *pattern) {
char tmp_file[512];
strcpy(tmp_file, pattern);
int fd = mkstemp(tmp_file);
Expand All @@ -158,7 +158,7 @@ static char* tmpfile_prefix(const char *pattern){
return file_path;
}

static int awka_output_file(int awka_tmp, char *uoutfile, char **c_file, char **outfile){
static int awka_output_file(int awka_tmp, char *uoutfile, char **c_file, char **outfile) {
char *outfile_prefix = NULL;
char *outfile_suffix;

Expand Down Expand Up @@ -194,7 +194,7 @@ static int awka_output_file(int awka_tmp, char *uoutfile, char **c_file, char **
return 1;
}

static char* awka_build_compile_command(char *c_file, char *outfile){
static char* awka_build_compile_command(char *c_file, char *outfile) {
char *cmd;
int incd_len=0, libd_len=0, libf_len=0;

Expand Down Expand Up @@ -235,7 +235,7 @@ static char* awka_build_compile_command(char *c_file, char *outfile){
return cmd;
}

static int awka_do_compile(char *c_file, char *outfile){
static int awka_do_compile(char *c_file, char *outfile) {
char *cmd;
cmd = awka_build_compile_command(c_file, outfile);

Expand All @@ -258,7 +258,7 @@ static int awka_do_compile(char *c_file, char *outfile){
return 1;
}

static int awka_do_exec(char *outfile){
static int awka_do_exec(char *outfile) {
int len = strlen(outfile);
for (int i=0; i<exe_argc; i++)
len += strlen(exe_argv[i]) + 2;
Expand Down Expand Up @@ -291,7 +291,7 @@ int main(int argc, char *argv[])

parse();

if (!prog_no){
if (!prog_no) {
awka_error("Sorry, program was not parsed successfully.\n");
return -1;
}
Expand All @@ -308,7 +308,7 @@ int main(int argc, char *argv[])
if (do_compile) {
awka_output_file(awka_tmp, uoutfile, &c_file, &outfile);
outfp = fopen(c_file, "w");
if (!outfp){
if (!outfp) {
awka_error("Failed to open %s to write.\n", c_file);
return -1;
}
Expand All @@ -319,18 +319,18 @@ int main(int argc, char *argv[])

if (do_compile) {
int compile_succ = awka_do_compile(c_file, outfile);
if(!compile_succ){
if (!compile_succ) {
awka_error("Awka error: compile failed.\n");
return -1;
}
}

if (do_exec){
if (do_exec) {
awka_do_exec(outfile);
}

if ( do_compile || do_exec ) {
if(awka_tmp){
if (awka_tmp) {
remove(outfile);
}
remove(c_file);
Expand Down
2 changes: 1 addition & 1 deletion awka/bi_funct.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ bi_funct_init()
for (p = bi_funct + 1; p->name; p++)
{
stp = insert(p->name) ;
if(strcmp(p->name, "length") == 0)
if (strcmp(p->name, "length") == 0)
stp->type = ST_LENGTH ;
else
stp->type = ST_BUILTIN ;
Expand Down
2 changes: 1 addition & 1 deletion awka/da.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ fixbackslashes(char *str, int which)
r = q - 1;
do {
*(q--) = *(r--);
} while(r >= p);
} while (r >= p);
*(p++) = '\\';
}
p++;
Expand Down
18 changes: 9 additions & 9 deletions awka/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ void yyerror(s)
if ( s )
{
if ( paren_cnt )
for( ip = missing_rparen ; *ip ; ip++)
for ( ip = missing_rparen ; *ip ; ip++)
if ( *ip == current_token )
{ missing(')', s, token_lineno) ;
paren_cnt = 0 ;
goto done ;
}

if ( brace_cnt )
for( ip = missing_rbrace ; *ip ; ip++)
for ( ip = missing_rbrace ; *ip ; ip++)
if ( *ip == current_token )
{ missing('}', s, token_lineno) ;
brace_cnt = 0 ;
Expand Down Expand Up @@ -244,7 +244,7 @@ get_source_line()
if (!(fp = fopen(pfile_name, "r")))
return (buffer) ;

while(fgets(buffer, bufferLength, fp)) {
while (fgets(buffer, bufferLength, fp)) {
if ( !linecount-- )
break ;
}
Expand All @@ -263,11 +263,11 @@ update_source_pos(char *src)

end = (src + len - 1) ;

if(line_pos >= len)
if (line_pos >= len)
return ;

p = src ;
while(p < end) {
while (p < end) {
if (*p == '\t') *p = ' ' ; // so tab treated as one char
if (*p++ == c && p > (src + line_pos)) {
line_pos = (int) (p - src) ;
Expand Down Expand Up @@ -374,12 +374,12 @@ unexpected_char( void )
sprintf(lnstr, "%s: %s%sline %d: ",progname, s0, s1, token_lineno) ;

sc = get_source_line() ;
if(sc)
if (sc)
fprintf(stderr, "%s%s", lnstr, sc) ;

/* point to error location then show the error message */
fill = char_repeat((int) line_pos-1,' ') ;
if(sc)
if (sc)
fprintf(stderr, "%s%s^ ", lnstr, fill) ;
else
fprintf(stderr, "%s ", lnstr) ;
Expand All @@ -398,7 +398,7 @@ static char *type_to_str( type )
int type ;
{ char *retval ;

switch( type )
switch ( type )
{
case ST_VAR : retval = "variable" ; break ;
case ST_ARRAY : retval = "array" ; break ;
Expand Down Expand Up @@ -460,7 +460,7 @@ int simple_vfprintf( fp, format, argp)

*t = *q++ ; t[1] = 0 ;

switch( *t )
switch ( *t )
{
case 'c' :
case 'd' :
Expand Down
4 changes: 3 additions & 1 deletion awka/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ build_field0()
cp_limit = cp + FBANK_SZ ;
}
/* add the separator */
q = ofs->str ; while( *q ) *p++ = *q++ ;
q = ofs->str ;
while ( *q )
*p++ = *q++ ;
}
/* tack tail on the end */
memcpy(p, tail->str, tail->len) ;
Expand Down
8 changes: 4 additions & 4 deletions awka/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ _add_pfile(
pf->link = (PFILE *) 0 ;

tpf = &dummy ;
while(tpf->link) {
while (tpf->link) {
tpf = tpf->link ;
}
tpf->link = pf ;
Expand Down Expand Up @@ -447,19 +447,19 @@ _process_cmdline(argc, argv)
if (argv[i][0] != '-') /* inline script */
{
/* if ends in ".awk" then is missing the -f */
if(strcmp(argv[i] + strlen(argv[i]) - 4, ".awk") == 0)
if (strcmp(argv[i] + strlen(argv[i]) - 4, ".awk") == 0)
{
errmsg(0, "expected a quoted inline script, or -f %s.", argv[i]) ;
exit(EXIT_ERR_NOf) ;
}

if(!*awk_input_text)
if (!*awk_input_text)
sprintf(awk_input_text, "%s", argv[i]) ;
else
sprintf(awk_input_text, "%s %s", awk_input_text, argv[i]) ;

nextarg = i + 1 ;
if(i >= argc)
if (i >= argc)
goto no_more_opts ;

continue ;
Expand Down
7 changes: 3 additions & 4 deletions awka/init.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/********************************************
init.h
copyright 1991, Michael D. Brennan
Expand Down Expand Up @@ -79,12 +78,12 @@ quote_escape(char *s) {

strncpy(tstr, s, i);
p = tstr;
while(*p) {
if(*p == '\\') {
while (*p) {
if (*p == '\\') {
memmove(p+1, p, strlen(p));
*(p++) = '\\';
}
if(*p++ == '"') {
if (*p++ == '"') {
memmove(p, p-1, strlen(p-1));
*((p++)-1) = '\\';
}
Expand Down
Loading

0 comments on commit 09c53ce

Please sign in to comment.