OSDN Git Service

print usage when file not specified.
authortsutsumi <>
Wed, 17 Sep 2003 21:17:34 +0000 (21:17 +0000)
committertsutsumi <>
Wed, 17 Sep 2003 21:17:34 +0000 (21:17 +0000)
src/ccunit/CCUnitMakeSuite.c

index 9198aff..2258bef 100644 (file)
@@ -53,7 +53,7 @@
 #endif
 
 #if CCUNIT_HAVE_GETOPT_LONG
-#  define LONGOPTNAME(LO) "--" #LO " | "       /**< long name option */
+#  define LONGOPTNAME(LO) "      --" #LO "\n"        /**< long name option */
 #else
 #  define LONGOPTNAME(LO) /* -- LO | */                /**< long name option */
 #endif
  * @{
  */
 
+/**
+ * print help massage.
+ * @param progname program name.
+ */
+static void usage (const char* progname)
+{
+  fprintf (stdout,
+          "%s\n"
+          "  USAGE: %s [OPTIONS] FILES...\n"
+          "    OPTION:\n"
+          LONGOPTNAME(output OUTFILE)
+          "      -o OUTFILE\n"
+          "          output file name (default stdout)\n"
+          LONGOPTNAME(function FUNCTION)
+          "      -f FUNCTION\n"
+          "          created function name\n"
+          LONGOPTNAME(verbose)
+          "      -v\n"
+          "          output verbose message\n"
+          LONGOPTNAME(debug)
+          "      -d\n"
+          "          output debug message\n"
+          LONGOPTNAME(version)
+          "      -V\n"
+          "          print version\n"
+          LONGOPTNAME(help)
+          "      -h\n"
+          "          print this message\n"
+          , CCUNIT_PACKAGE_STRING, progname);
+}
+
 int ccunit_makeSuite (int ac, char** av)
 {
   CCUnitTestSuiteDef* suite;
@@ -129,24 +160,8 @@ int ccunit_makeSuite (int ac, char** av)
          fprintf (stdout, "%s - %s\n", CCUNIT_PACKAGE_STRING, progname);
          return 0;
        case 'h':
-         fprintf (stdout,
-                  "%s\n"
-                  "  USAGE: %s [OPTIONS] FILES...\n"
-                  "    OPTION:\n"
-                  "      " LONGOPTNAME(output) "-o OUTFILE\n"
-                  "          output file name (default stdout)\n"
-                  "      " LONGOPTNAME(function) "-f FUNCTION\n"
-                  "          created function name\n"
-                  "      " LONGOPTNAME(verbose) "-v\n"
-                  "          output verbose message\n"
-                  "      " LONGOPTNAME(debug) "-d\n"
-                  "          output debug message\n"
-                  "      " LONGOPTNAME(version) "-V\n"
-                  "          print version\n"
-                  "      " LONGOPTNAME(help) "-h\n"
-                  "          print this message\n"
-                  , CCUNIT_PACKAGE_STRING, progname);
-         return 1;
+         usage (progname);
+         return 0;
        case '?':
          fprintf (stderr, "unknown option %s\n", av[optind]);
          return 1;
@@ -155,6 +170,11 @@ int ccunit_makeSuite (int ac, char** av)
          return 1;
        }
     }
+  if (optind >= ac)
+    {
+      usage (progname);
+      return 0;
+    }
   suite = ccunit_newTestSuiteDef (NULL);
   if (!suite)
     {
@@ -176,11 +196,8 @@ int ccunit_makeSuite (int ac, char** av)
   SETVBUF(ofp, NULL, _IONBF, 0);
   SETVBUF(stderr, NULL, _IONBF, 0);
   /* process source files */
-  if (optind >= ac)
-    ccunit_readSuite ("-", suite);
-  else
-    for (; optind < ac; optind ++)
-      ccunit_readSuite (av[optind], suite);
+  for (; optind < ac; optind ++)
+    ccunit_readSuite (av[optind], suite);
   ccunit_writeSuite (ofp, functionName, suite);
   if (ofp != stdout)
     fclose (ofp);