preproc: style cleanups
authorH. Peter Anvin <hpa@zytor.com>
Wed, 15 Jul 2009 13:16:54 +0000 (09:16 -0400)
committerH. Peter Anvin <hpa@zytor.com>
Wed, 15 Jul 2009 13:16:54 +0000 (09:16 -0400)
Fix indentation, space between if and (, and prefer (foo) and (!foo)
to (foo != NULL) and (foo == NULL).

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
preproc.c

index 13c269f..bac5a77 100644 (file)
--- a/preproc.c
+++ b/preproc.c
@@ -131,14 +131,14 @@ struct SMacro {
  */
 struct MMacro {
     MMacro *next;
-       MMacroInvocation *prev;      /* previous invocation */
+    MMacroInvocation *prev;      /* previous invocation */
     char *name;
     int nparam_min, nparam_max;
     bool casesense;
     bool plus;                   /* is the last parameter greedy? */
     bool nolist;                 /* is this macro listing-inhibited? */
     int64_t in_progress;         /* is this macro currently being expanded? */
-       int32_t max_depth;           /* maximum number of recursive expansions allowed */
+    int32_t max_depth;           /* maximum number of recursive expansions allowed */
     Token *dlist;               /* All defaults as one list */
     Token **defaults;           /* Parameter default pointers */
     int ndefs;                  /* number of default parameters */
@@ -159,9 +159,9 @@ struct MMacro {
  * previous recursive macro expansion.
  */
 struct MMacroInvocation {
-       MMacroInvocation *prev;     /* previous invocation */
-       Token **params;             /* actual parameters */
-       Token *iline;               /* invocation line */
+    MMacroInvocation *prev;     /* previous invocation */
+    Token **params;             /* actual parameters */
+    Token *iline;               /* invocation line */
     unsigned int nparam, rotate;
     int *paramlen;
     uint64_t unique;
@@ -1044,12 +1044,12 @@ static Token *tokenize(char *line)
 
         /* Handling unterminated string by UNV */
         /*if (type == -1)
-           {
-           *tail = t = new_Token(NULL, TOK_STRING, line, p-line+1);
-           t->text[p-line] = *line;
-           tail = &t->next;
-           }
-           else */
+         {
+         *tail = t = new_Token(NULL, TOK_STRING, line, p-line+1);
+         t->text[p-line] = *line;
+         tail = &t->next;
+         }
+         else */
         if (type != TOK_COMMENT) {
             *tail = t = new_Token(NULL, type, line, p - line);
             tail = &t->next;
@@ -1115,7 +1115,7 @@ static Token *new_Token(Token * next, enum pp_token_type type,
     Token *t;
     int i;
 
-    if (freeTokens == NULL) {
+    if (!freeTokens) {
         freeTokens = (Token *) new_Block(TOKEN_BLOCKSIZE * sizeof(Token));
         for (i = 0; i < TOKEN_BLOCKSIZE - 1; i++)
             freeTokens[i].next = &freeTokens[i + 1];
@@ -1126,7 +1126,7 @@ static Token *new_Token(Token * next, enum pp_token_type type,
     t->next = next;
     t->a.mac = NULL;
     t->type = type;
-    if (type == TOK_WHITESPACE || text == NULL) {
+    if (type == TOK_WHITESPACE || !text) {
         t->text = NULL;
     } else {
         if (txtlen == 0)
@@ -1685,83 +1685,83 @@ static bool if_condition(Token * tline, enum preproc_token ct)
        break;
 
     case PPC_IFMACRO:
-        {
-            bool found = false;
-            MMacro searching, *mmac;
+    {
+       bool found = false;
+       MMacro searching, *mmac;
 
-            skip_white_(tline);
-            tline = expand_id(tline);
-            if (!tok_type_(tline, TOK_ID)) {
-                error(ERR_NONFATAL,
-                      "`%s' expects a macro name", pp_directives[ct]);
-               goto fail;
-            }
-            searching.name = nasm_strdup(tline->text);
-            searching.casesense = true;
-            searching.plus = false;
-            searching.nolist = false;
-            searching.in_progress = 0;
-                       searching.max_depth = 0;
-            searching.rep_nest = NULL;
-            searching.nparam_min = 0;
-            searching.nparam_max = INT_MAX;
-            tline = expand_smacro(tline->next);
-            skip_white_(tline);
-            if (!tline) {
-            } else if (!tok_type_(tline, TOK_NUMBER)) {
-                error(ERR_NONFATAL,
-                      "`%s' expects a parameter count or nothing",
-                      pp_directives[ct]);
-            } else {
-                searching.nparam_min = searching.nparam_max =
-                    readnum(tline->text, &j);
-                if (j)
-                    error(ERR_NONFATAL,
-                          "unable to parse parameter count `%s'",
-                          tline->text);
-            }
-            if (tline && tok_is_(tline->next, "-")) {
-                tline = tline->next->next;
-                if (tok_is_(tline, "*"))
-                    searching.nparam_max = INT_MAX;
-                else if (!tok_type_(tline, TOK_NUMBER))
-                    error(ERR_NONFATAL,
-                          "`%s' expects a parameter count after `-'",
-                          pp_directives[ct]);
-                else {
-                    searching.nparam_max = readnum(tline->text, &j);
-                    if (j)
-                        error(ERR_NONFATAL,
-                              "unable to parse parameter count `%s'",
-                              tline->text);
-                    if (searching.nparam_min > searching.nparam_max)
-                        error(ERR_NONFATAL,
-                              "minimum parameter count exceeds maximum");
-                }
-            }
-            if (tline && tok_is_(tline->next, "+")) {
-                tline = tline->next;
-                searching.plus = true;
-            }
-            mmac = (MMacro *) hash_findix(&mmacros, searching.name);
-           while (mmac) {
-               if (!strcmp(mmac->name, searching.name) &&
-                   (mmac->nparam_min <= searching.nparam_max
-                    || searching.plus)
-                   && (searching.nparam_min <= mmac->nparam_max
-                       || mmac->plus)) {
-                   found = true;
-                   break;
-               }
-               mmac = mmac->next;
+       skip_white_(tline);
+       tline = expand_id(tline);
+       if (!tok_type_(tline, TOK_ID)) {
+           error(ERR_NONFATAL,
+                 "`%s' expects a macro name", pp_directives[ct]);
+           goto fail;
+       }
+       searching.name = nasm_strdup(tline->text);
+       searching.casesense = true;
+       searching.plus = false;
+       searching.nolist = false;
+       searching.in_progress = 0;
+       searching.max_depth = 0;
+       searching.rep_nest = NULL;
+       searching.nparam_min = 0;
+       searching.nparam_max = INT_MAX;
+       tline = expand_smacro(tline->next);
+       skip_white_(tline);
+       if (!tline) {
+       } else if (!tok_type_(tline, TOK_NUMBER)) {
+           error(ERR_NONFATAL,
+                 "`%s' expects a parameter count or nothing",
+                 pp_directives[ct]);
+       } else {
+           searching.nparam_min = searching.nparam_max =
+               readnum(tline->text, &j);
+           if (j)
+               error(ERR_NONFATAL,
+                     "unable to parse parameter count `%s'",
+                     tline->text);
+       }
+       if (tline && tok_is_(tline->next, "-")) {
+           tline = tline->next->next;
+           if (tok_is_(tline, "*"))
+               searching.nparam_max = INT_MAX;
+           else if (!tok_type_(tline, TOK_NUMBER))
+               error(ERR_NONFATAL,
+                     "`%s' expects a parameter count after `-'",
+                     pp_directives[ct]);
+           else {
+               searching.nparam_max = readnum(tline->text, &j);
+               if (j)
+                   error(ERR_NONFATAL,
+                         "unable to parse parameter count `%s'",
+                         tline->text);
+               if (searching.nparam_min > searching.nparam_max)
+                   error(ERR_NONFATAL,
+                         "minimum parameter count exceeds maximum");
            }
-            if(tline && tline->next)
-                error(ERR_WARNING|ERR_PASS1,
-                     "trailing garbage after %%ifmacro ignored");
-            nasm_free(searching.name);
-           j = found;
-           break;
-        }
+       }
+       if (tline && tok_is_(tline->next, "+")) {
+           tline = tline->next;
+           searching.plus = true;
+       }
+       mmac = (MMacro *) hash_findix(&mmacros, searching.name);
+       while (mmac) {
+           if (!strcmp(mmac->name, searching.name) &&
+               (mmac->nparam_min <= searching.nparam_max
+                || searching.plus)
+               && (searching.nparam_min <= mmac->nparam_max
+                   || mmac->plus)) {
+               found = true;
+               break;
+           }
+           mmac = mmac->next;
+       }
+       if (tline && tline->next)
+           error(ERR_WARNING|ERR_PASS1,
+                 "trailing garbage after %%ifmacro ignored");
+       nasm_free(searching.name);
+       j = found;
+       break;
+    }
 
     case PPC_IFID:
        needtype = TOK_ID;
@@ -1929,7 +1929,7 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive)
        return false;
     }
 
-       def->prev = NULL;
+    def->prev = NULL;
     def->name = nasm_strdup(tline->text);
     def->plus = false;
     def->nolist = false;
@@ -1990,11 +1990,10 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive)
     }
     def->expansion = NULL;
 
-        if(def->defaults &&
-           def->ndefs > def->nparam_max - def->nparam_min &&
-           !def->plus)
-         error(ERR_WARNING|ERR_PASS1|ERR_WARN_MDP,
-              "too many default macro parameters");
+    if (def->defaults && def->ndefs > def->nparam_max - def->nparam_min &&
+       !def->plus)
+       error(ERR_WARNING|ERR_PASS1|ERR_WARN_MDP,
+             "too many default macro parameters");
 
     return true;
 }
@@ -2345,7 +2344,7 @@ static int do_directive(Token * tline)
        t = tline->next = expand_smacro(tline->next);
         skip_white_(t);
         if (!t || (t->type != TOK_STRING &&
-                       t->type != TOK_INTERNAL_STRING)) {
+                  t->type != TOK_INTERNAL_STRING)) {
             error(ERR_NONFATAL, "`%%depend' expects a file name");
             free_tlist(origline);
             return DIRECTIVE_FOUND;     /* but we did _something_ */
@@ -2371,7 +2370,7 @@ static int do_directive(Token * tline)
         skip_white_(t);
 
         if (!t || (t->type != TOK_STRING &&
-                       t->type != TOK_INTERNAL_STRING)) {
+                  t->type != TOK_INTERNAL_STRING)) {
             error(ERR_NONFATAL, "`%%include' expects a file name");
             free_tlist(origline);
             return DIRECTIVE_FOUND;     /* but we did _something_ */
@@ -2500,24 +2499,24 @@ static int do_directive(Token * tline)
        /* Only error out if this is the final pass */
        if (pass != 2 && i != PP_FATAL)
            return DIRECTIVE_FOUND;
-
-        tline->next = expand_smacro(tline->next);
-        tline = tline->next;
-        skip_white_(tline);
+       
+       tline->next = expand_smacro(tline->next);
+       tline = tline->next;
+       skip_white_(tline);
        t = tline ? tline->next : NULL;
        skip_white_(t);
-        if (tok_type_(tline, TOK_STRING) && !t) {
+       if (tok_type_(tline, TOK_STRING) && !t) {
            /* The line contains only a quoted string */
            p = tline->text;
            nasm_unquote(p, NULL); /* Ignore NUL character truncation */
            error(severity, "%s",  p);
        } else {
            /* Not a quoted string, or more than a quoted string */
-            p = detoken(tline, false);
+           p = detoken(tline, false);
            error(severity, "%s",  p);
            nasm_free(p);
        }
-        free_tlist(origline);
+       free_tlist(origline);
        return DIRECTIVE_FOUND;
     }
 
@@ -2540,35 +2539,35 @@ static int do_directive(Token * tline)
         if (!istk->conds)
             error(ERR_FATAL, "`%s': no matching `%%if'", pp_directives[i]);
         switch(istk->conds->state) {
-            case COND_IF_TRUE:
-                istk->conds->state = COND_DONE;
-                break;
+       case COND_IF_TRUE:
+           istk->conds->state = COND_DONE;
+           break;
 
-            case COND_DONE:
-            case COND_NEVER:
-                break;
+       case COND_DONE:
+       case COND_NEVER:
+           break;
 
-            case COND_ELSE_TRUE:
-            case COND_ELSE_FALSE:
-                error_precond(ERR_WARNING|ERR_PASS1,
-                             "`%%elif' after `%%else' ignored");
-                istk->conds->state = COND_NEVER;
-                break;
+       case COND_ELSE_TRUE:
+       case COND_ELSE_FALSE:
+           error_precond(ERR_WARNING|ERR_PASS1,
+                         "`%%elif' after `%%else' ignored");
+           istk->conds->state = COND_NEVER;
+           break;
 
-            case COND_IF_FALSE:
-                /*
-                 * IMPORTANT: In the case of %if, we will already have
-                 * called expand_mmac_params(); however, if we're
-                 * processing an %elif we must have been in a
-                 * non-emitting mode, which would have inhibited
-                 * the normal invocation of expand_mmac_params().
-                * Therefore, we have to do it explicitly here.
-                 */
-                j = if_condition(expand_mmac_params(tline->next), i);
-                tline->next = NULL; /* it got freed */
-                istk->conds->state =
-                    j < 0 ? COND_NEVER : j ? COND_IF_TRUE : COND_IF_FALSE;
-                break;
+       case COND_IF_FALSE:
+           /*
+            * IMPORTANT: In the case of %if, we will already have
+            * called expand_mmac_params(); however, if we're
+            * processing an %elif we must have been in a
+            * non-emitting mode, which would have inhibited
+            * the normal invocation of expand_mmac_params().
+            * Therefore, we have to do it explicitly here.
+            */
+           j = if_condition(expand_mmac_params(tline->next), i);
+           tline->next = NULL; /* it got freed */
+           istk->conds->state =
+               j < 0 ? COND_NEVER : j ? COND_IF_TRUE : COND_IF_FALSE;
+           break;
         }
        free_tlist(origline);
         return DIRECTIVE_FOUND;
@@ -2580,24 +2579,24 @@ static int do_directive(Token * tline)
         if (!istk->conds)
             error(ERR_FATAL, "`%%else': no matching `%%if'");
         switch(istk->conds->state) {
-            case COND_IF_TRUE:
-            case COND_DONE:
-                istk->conds->state = COND_ELSE_FALSE;
-                break;
+       case COND_IF_TRUE:
+       case COND_DONE:
+           istk->conds->state = COND_ELSE_FALSE;
+           break;
 
-            case COND_NEVER:
-                break;
+       case COND_NEVER:
+           break;
 
-            case COND_IF_FALSE:
-                istk->conds->state = COND_ELSE_TRUE;
-                break;
+       case COND_IF_FALSE:
+           istk->conds->state = COND_ELSE_TRUE;
+           break;
 
-            case COND_ELSE_TRUE:
-            case COND_ELSE_FALSE:
-                error_precond(ERR_WARNING|ERR_PASS1,
-                             "`%%else' after `%%else' ignored.");
-                istk->conds->state = COND_NEVER;
-                break;
+       case COND_ELSE_TRUE:
+       case COND_ELSE_FALSE:
+           error_precond(ERR_WARNING|ERR_PASS1,
+                         "`%%else' after `%%else' ignored.");
+           istk->conds->state = COND_NEVER;
+           break;
         }
         free_tlist(origline);
         return DIRECTIVE_FOUND;
@@ -2662,21 +2661,21 @@ static int do_directive(Token * tline)
         free_tlist(origline);
         return DIRECTIVE_FOUND;
 
-       case PP_EXITMACRO:
+    case PP_EXITMACRO:
         /*
          * We must search along istk->expansion until we hit a
          * macro-end marker for a macro with a name. Then we set
          * its `in_progress' flag to 0.
          */
-               for (l = istk->expansion; l; l = l->next)
+       for (l = istk->expansion; l; l = l->next)
             if (l->finishes && l->finishes->name)
                break;
 
         if (l) {
-                       l->finishes->in_progress = 0;
+           l->finishes->in_progress = 0;
         } else {
             error(ERR_NONFATAL, "`%%exitmacro' not within `%%macro' block");
-               }
+       }
         free_tlist(origline);
         return DIRECTIVE_FOUND;
 
@@ -2712,7 +2711,7 @@ static int do_directive(Token * tline)
     case PP_ROTATE:
         if (tline->next && tline->next->type == TOK_WHITESPACE)
             tline = tline->next;
-        if (tline->next == NULL) {
+        if (!tline->next) {
             free_tlist(origline);
             error(ERR_NONFATAL, "`%%rotate' missing rotate count");
             return DIRECTIVE_FOUND;
@@ -2794,13 +2793,13 @@ static int do_directive(Token * tline)
 
         tmp_defining = defining;
         defining = nasm_malloc(sizeof(MMacro));
-               defining->prev = NULL;
+       defining->prev = NULL;
         defining->name = NULL;  /* flags this macro as a %rep block */
         defining->casesense = false;
         defining->plus = false;
         defining->nolist = nolist;
         defining->in_progress = count;
-               defining->max_depth = 0;
+       defining->max_depth = 0;
         defining->nparam_min = defining->nparam_max = 0;
         defining->defaults = NULL;
         defining->dlist = NULL;
@@ -3017,7 +3016,7 @@ static int do_directive(Token * tline)
     case PP_DEFTOK:
     case PP_IDEFTOK:
        casesense = (i == PP_DEFTOK);
-
+       
         tline = tline->next;
         skip_white_(tline);
         tline = expand_id(tline);
@@ -3026,7 +3025,7 @@ static int do_directive(Token * tline)
                         tline->text[1] != '$'))) {
             error(ERR_NONFATAL,
                   "`%s' expects a macro identifier as first parameter",
-                       pp_directives[i]);
+                 pp_directives[i]);
             free_tlist(origline);
             return DIRECTIVE_FOUND;
         }
@@ -3042,7 +3041,7 @@ static int do_directive(Token * tline)
         if (t->type != TOK_STRING) {
             error(ERR_NONFATAL,
                   "`%s` requires string as second parameter",
-                       pp_directives[i]);
+                 pp_directives[i]);
             free_tlist(tline);
             free_tlist(origline);
             return DIRECTIVE_FOUND;
@@ -3050,7 +3049,7 @@ static int do_directive(Token * tline)
 
        nasm_unquote_cstr(t->text, i);
        macro_start = tokenize(t->text);
-
+       
         /*
          * We now have a macro name, an implicit parameter count of
          * zero, and a numeric token to use as an expansion. Create
@@ -3442,7 +3441,7 @@ static int find_cc(Token * t)
     int i, j, k, m;
 
     if (!t)
-           return -1;          /* Probably a %+ without a space */
+       return -1;              /* Probably a %+ without a space */
 
     skip_white_(t);
     if (t->type != TOK_ID)
@@ -3841,7 +3840,7 @@ again:
                      * pain.
                      */
                     /*tline = tline->next;
-                       skip_white_(tline); */
+                     skip_white_(tline); */
                     do {
                         t = tline->next;
                         while (tok_type_(t, TOK_SMAC_END)) {
@@ -4173,15 +4172,15 @@ static MMacro *is_mmacro(Token * tline, Token *** params_array)
              * This one is right. Just check if cycle removal
              * prohibits us using it before we actually celebrate...
              */
-              if (m->in_progress > m->max_depth) {
-                             if (m->max_depth > 0) {
-                      error(ERR_WARNING,
-                                                       "reached maximum recursion depth of %i",
-                            m->max_depth);
-                  }
-                  nasm_free(params);
-                  return NULL;
-              }
+           if (m->in_progress > m->max_depth) {
+               if (m->max_depth > 0) {
+                   error(ERR_WARNING,
+                         "reached maximum recursion depth of %i",
+                         m->max_depth);
+               }
+               nasm_free(params);
+               return NULL;
+           }
             /*
              * It's right, and we can use it. Add its default
              * parameters to the end of our list if necessary.
@@ -4243,15 +4242,15 @@ static void push_mmacro(MMacro *m)
 {
     MMacroInvocation *i;
 
-       i = nasm_malloc(sizeof(MMacroInvocation));
-       i->prev = m->prev;
-       i->params = m->params;
-       i->iline = m->iline;
-       i->nparam = m->nparam;
-       i->rotate = m->rotate;
-       i->paramlen = m->paramlen;
-       i->unique = m->unique;
-       m->prev = i;
+    i = nasm_malloc(sizeof(MMacroInvocation));
+    i->prev = m->prev;
+    i->params = m->params;
+    i->iline = m->iline;
+    i->nparam = m->nparam;
+    i->rotate = m->rotate;
+    i->paramlen = m->paramlen;
+    i->unique = m->unique;
+    m->prev = i;
 }
 
 
@@ -4263,17 +4262,17 @@ static void pop_mmacro(MMacro *m)
 {
     MMacroInvocation *i;
 
-       if(m->prev != NULL){
-               i = m->prev;
-               m->prev = i->prev;
-               m->params = i->params;
-               m->iline = i->iline;
-               m->nparam = i->nparam;
-               m->rotate = i->rotate;
-               m->paramlen = i->paramlen;
-               m->unique = i->unique;
-               nasm_free(i);
-       }
+    if (m->prev) {
+       i = m->prev;
+       m->prev = i->prev;
+       m->params = i->params;
+       m->iline = i->iline;
+       m->nparam = i->nparam;
+       m->rotate = i->rotate;
+       m->paramlen = i->paramlen;
+       m->unique = i->unique;
+       nasm_free(i);
+    }
 }
 
 
@@ -4320,7 +4319,7 @@ static int expand_mmacro(Token * tline)
             if (tok_type_(t, TOK_WHITESPACE))
                 last = t, t = t->next;
         }
-        if (!tok_type_(t, TOK_ID) || (m = is_mmacro(t, &params)) == NULL)
+        if (!tok_type_(t, TOK_ID) || !(m = is_mmacro(t, &params)))
             return 0;
         last->next = NULL;
         mname = t->text;
@@ -4377,12 +4376,12 @@ static int expand_mmacro(Token * tline)
     ll->first = NULL;
     istk->expansion = ll;
        
-       /*
-        * Save the previous MMacro expansion in the case of
-        * macro recursion
-        */
-       if (m->max_depth && m->in_progress)
-           push_mmacro(m);
+    /*
+     * Save the previous MMacro expansion in the case of
+     * macro recursion
+     */
+    if (m->max_depth && m->in_progress)
+       push_mmacro(m);
 
     m->in_progress ++;
     m->params = params;
@@ -4652,15 +4651,15 @@ static char *pp_getline(void)
                          * therefore the parameter information needs to
                          * be freed.
                          */
-                                               if (m->prev != NULL) {
-                                                       pop_mmacro(m);
-                                                       l->finishes->in_progress --;
-                                               } else {
+                       if (m->prev) {
+                           pop_mmacro(m);
+                           l->finishes->in_progress --;
+                       } else {
                             nasm_free(m->params);
                             free_tlist(m->iline);
-                                                       nasm_free(m->paramlen);
-                                                       l->finishes->in_progress = 0;
-                                               }
+                           nasm_free(m->paramlen);
+                           l->finishes->in_progress = 0;
+                       }
                     } else
                         free_mmacro(m);
                 }
@@ -4788,7 +4787,7 @@ static char *pp_getline(void)
 static void pp_cleanup(int pass)
 {
     if (defining) {
-        if(defining->name) {
+        if (defining->name) {
             error(ERR_NONFATAL,
                   "end of file while still defining macro `%s'",
                   defining->name);
@@ -4832,9 +4831,9 @@ void pp_include_path(char *path)
     i->path = path ? nasm_strdup(path) : NULL;
     i->next = NULL;
 
-    if (ipath != NULL) {
+    if (ipath) {
         IncPath *j = ipath;
-        while (j->next != NULL)
+        while (j->next)
             j = j->next;
         j->next = i;
     } else {
@@ -4911,7 +4910,7 @@ void pp_runtime(char *definition)
     Token *def;
 
     def = tokenize(definition);
-    if(do_directive(def) == NO_DIRECTIVE_FOUND)
+    if (do_directive(def) == NO_DIRECTIVE_FOUND)
         free_tlist(def);
 
 }