cleanup: Add and use macro MIN().
[cparser] / main.c
diff --git a/main.c b/main.c
index a148611..a1e4e24 100644 (file)
--- a/main.c
+++ b/main.c
@@ -46,6 +46,8 @@
 #include <libfirm/be.h>
 #include <libfirm/statev.h>
 
+#include "adt/util.h"
+#include "ast_t.h"
 #include "preprocessor.h"
 #include "token_t.h"
 #include "types.h"
@@ -61,6 +63,7 @@
 #include "adt/error.h"
 #include "adt/strutil.h"
 #include "adt/array.h"
+#include "symbol_table.h"
 #include "wrappergen/write_fluffy.h"
 #include "wrappergen/write_jna.h"
 #include "wrappergen/write_compoundsizes.h"
@@ -357,8 +360,7 @@ static bool run_external_preprocessor(compilation_unit_t *unit)
                static char dep_target[4096];
                if (outname != 0) {
                        size_t len = strlen(outname);
-                       if (len > sizeof(dep_target)-4) /* leave room for .d extension */
-                               len = sizeof(dep_target)-4;
+                       len = MIN(len, sizeof(dep_target) - 4); /* leave room for .d extension */
                        memcpy(dep_target, outname, len);
                        /* replace extension with .d if found */
                        char *dot = &dep_target[len-1];
@@ -898,9 +900,7 @@ static unsigned decide_modulo_shift(unsigned type_size)
 {
        if (architecture_modulo_shift == 0)
                return 0;
-       if (type_size < architecture_modulo_shift)
-               return architecture_modulo_shift;
-       return type_size;
+       return MAX(type_size, architecture_modulo_shift);
 }
 
 static bool is_ia32_cpu(const char *architecture)
@@ -1200,8 +1200,10 @@ static void copy_file(FILE *dest, FILE *input)
 {
        char buf[16384];
 
-       while (!feof(input) && !ferror(dest)) {
+       for (;;) {
                size_t read = fread(buf, 1, sizeof(buf), input);
+               if (read == 0)
+                       break;
                if (fwrite(buf, 1, read, dest) != read) {
                        perror("could not write output");
                }
@@ -1631,12 +1633,12 @@ int main(int argc, char **argv)
                                        errorf(NULL, "unknown language '%s'", opt);
                                        argument_errors = true;
                                }
-                       } else if (streq(option, "M")) {
+                       } else if (SINGLE_OPTION('M')) {
                                mode = PreprocessOnly;
                                add_flag(&cppflags_obst, "-M");
                        } else if (streq(option, "MMD") ||
                                   streq(option, "MD")) {
-                           construct_dep_target = true;
+                               construct_dep_target = true;
                                add_flag(&cppflags_obst, "-%s", option);
                        } else if (streq(option, "MM")  ||
                                   streq(option, "MP")) {
@@ -1822,7 +1824,7 @@ int main(int argc, char **argv)
                                           || streq(option+1, "format-security")
                                           || streq(option+1, "old-style-declaration")
                                           || streq(option+1, "type-limits")) {
-                                   /* ignore (gcc compatibility) */
+                                       /* ignore (gcc compatibility) */
                                } else {
                                        set_warning_opt(&option[1]);
                                }