]> git.refcnt.org Git - colorize.git/blobdiff - colorize.c
colorize 0.60
[colorize.git] / colorize.c
index 70de8488614cd2c2cbb24a8b8740b5c245f2584c..3c96a29e960d0ab7e29aaa3a32ae3116f8e73db7 100644 (file)
@@ -2,7 +2,7 @@
  * colorize - Read text from standard input stream or file and print
  *            it colorized through use of ANSI escape sequences
  *
- * Copyright (c) 2011-2016 Steven Schubiger
+ * Copyright (c) 2011-2017 Steven Schubiger
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
  *
  */
 
+#define _DEFAULT_SOURCE
 #define _BSD_SOURCE
 #define _XOPEN_SOURCE 700
 #define _FILE_OFFSET_BITS 64
 
 #define DEBUG_FILE "debug.txt"
 
-#define VERSION "0.59"
+#define VERSION "0.60"
 
 typedef enum { false, true } bool;
 
@@ -339,10 +340,13 @@ main (int argc, char **argv)
     exit (EXIT_SUCCESS);
 }
 
-#define SET_OPT_TYPE(type) \
-    opt_type = type;       \
-    opt = 0;               \
-    goto PARSE_OPT;        \
+#define PRINT_HELP_EXIT() \
+    print_help ();        \
+    exit (EXIT_SUCCESS);  \
+
+#define PRINT_VERSION_EXIT() \
+    print_version ();        \
+    exit (EXIT_SUCCESS);     \
 
 extern char *optarg;
 
@@ -352,7 +356,6 @@ process_opts (int argc, char **argv)
     int opt;
     while ((opt = getopt_long (argc, argv, "hV", long_opts, NULL)) != -1)
       {
-        PARSE_OPT:
         switch (opt)
           {
             case 0: /* long opts */
@@ -383,19 +386,17 @@ process_opts (int argc, char **argv)
                     break;
                   }
                   case OPT_HELP:
-                    print_help ();
-                    exit (EXIT_SUCCESS);
+                    PRINT_HELP_EXIT ();
                   case OPT_VERSION:
-                    print_version ();
-                    exit (EXIT_SUCCESS);
+                    PRINT_VERSION_EXIT ();
                   default: /* never reached */
                     ABORT_TRACE ();
                 }
               break;
             case 'h':
-              SET_OPT_TYPE (OPT_HELP);
+              PRINT_HELP_EXIT ();
             case 'V':
-              SET_OPT_TYPE (OPT_VERSION);
+              PRINT_VERSION_EXIT ();
             case '?':
               print_hint ();
               exit (EXIT_FAILURE);
@@ -473,7 +474,7 @@ print_version (void)
     const char *version = NULL;
 #endif
     const char *version_prefix, *version_string;
-    const char *c_flags;
+    const char *c_flags, *ld_flags, *cpp_flags;
     struct bytes_size bytes_size;
     bool debug;
 #ifdef CFLAGS
@@ -481,6 +482,16 @@ print_version (void)
 #else
     c_flags = "unknown";
 #endif
+#ifdef LDFLAGS
+    ld_flags = to_str (LDFLAGS);
+#else
+    ld_flags = "unknown";
+#endif
+#ifdef CPPFLAGS
+    cpp_flags = to_str (CPPFLAGS);
+#else
+    cpp_flags = "unknown";
+#endif
 #if DEBUG
     debug = true;
 #else
@@ -491,6 +502,8 @@ print_version (void)
     printf ("colorize %s%s (compiled at %s, %s)\n", version_prefix, version_string, __DATE__, __TIME__);
 
     printf ("Compiler flags: %s\n", c_flags);
+    printf ("Linker flags: %s\n", ld_flags);
+    printf ("Preprocessor flags: %s\n", cpp_flags);
     if (get_bytes_size (BUF_SIZE, &bytes_size))
       {
         if (BUF_SIZE % 1024 == 0)
@@ -773,7 +786,7 @@ read_print_stream (bool bold, const struct color **colors, const char *file, FIL
         line = buf;
         while ((eol = strpbrk (line, "\n\r")))
           {
-            char *p;
+            const char *p;
             flags &= ~(CR|LF);
             if (*eol == '\r')
               {