4 /* Copyright (C) 2003 TSUTSUMI Kikuo.
5 This file is part of the CCUnit Library.
7 The CCUnit Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public License
9 as published by the Free Software Foundation; either version 2.1 of
10 the License, or (at your option) any later version.
12 The CCUnit Library is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the CCUnit Library; see the file COPYING.LESSER.
19 If not, write to the Free Software Foundation, Inc., 59 Temple
20 Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <ccunit/CCUnitMakeSuite.h>
25 #include <ccunit/CCUnitLogMessage.h>
30 #ifndef AC_FUNC_SETVBUF_REVERSED
31 # define SETVBUF(FP,PTR,TYP,SZ) setvbuf(FP,PTR,TYP,SZ)
33 # define SETVBUF(FP,PTR,TYP,SZ) setvbuf(FP,TYP,PTR,SZ)
36 #if defined(unix) || defined(__MACH__) || defined(__CYGWIN__)
38 #elif defined (__WIN32__) || defined (__MSDOS__)
45 # define LONGOPTNAME(LO) "--" #LO " | "
47 # define LONGOPTNAME(LO) /* -- LO | */
51 * The main function. launch genregsuite function.
53 * @param ac number of arguments.
55 * @param av input source files.
57 * @return zero when successfuly generated. non-zero when error occurred.
59 int ccunit_makeSuite (int ac, char** av)
61 CCUnitTestSuiteDef* suite;
62 char* outputFile = "-";
63 const char* functionName = "ccunit_suite";
66 char* progname = NULL;
67 #ifdef HAVE_GETOPT_LONG
69 static struct option long_options[] = {
70 { "output", required_argument, NULL, 'o' },
71 { "function", required_argument, NULL, 'f' },
72 { "verbose", no_argument, NULL, 'v' },
73 { "debug", no_argument, NULL, 'd' },
74 { "version", no_argument, NULL, 'V' },
75 { "help", no_argument, NULL, 'h' },
81 progname = strrchr (av[0], DIRSEP);
85 # if defined (__WIN32__) || defined (__MSDOS__)
86 if (progname[2] == ':')
95 #ifdef HAVE_GETOPT_LONG
96 opt = getopt_long (ac, av, "o:f:vdVh", long_options, &option_index);
98 opt = getopt (ac, av, "o:f:vdVh");
105 #ifdef HAVE_GETOPT_LONG
106 puts (long_options[option_index].name);
113 functionName = optarg;
116 _ccunit_verbose_message = !_ccunit_verbose_message;
119 _ccunit_debug_message = !_ccunit_debug_message;
122 fprintf (stdout, "%s - %s\n", PACKAGE_STRING, progname);
127 " USAGE: %s [OPTIONS] FILES...\n"
129 " " LONGOPTNAME(output) "-o OUTFILE\n"
130 " output file name (default stdout)\n"
131 " " LONGOPTNAME(function) "-f FUNCTION\n"
132 " created function name\n"
133 " " LONGOPTNAME(verbose) "-v\n"
134 " output verbose message\n"
135 " " LONGOPTNAME(debug) "-d\n"
136 " output debug message\n"
137 " " LONGOPTNAME(version) "-V\n"
139 " " LONGOPTNAME(help) "-h\n"
140 " print this message\n"
141 , PACKAGE_STRING, progname);
144 fprintf (stderr, "unknown option %s\n", av[optind]);
147 fprintf (stderr, "bad option argument: %s\n", av[optind]);
151 if (strcmp (outputFile, "-") == 0)
155 ofp = fopen (outputFile, "w");
158 fprintf (stderr, "can't open file '%s': %s.\n",
159 outputFile, strerror (errno));
163 SETVBUF(ofp, NULL, _IONBF, 0);
164 SETVBUF(stderr, NULL, _IONBF, 0);
165 suite = ccunit_newTestSuiteDef (NULL);
166 /* process source files */
168 ccunit_readTestDef ("-", suite);
170 for (; optind < ac; optind ++)
172 ccunit_readTestDef (av[optind], suite);
174 ccunit_writeTestAdd (ofp, functionName, suite);
177 ccunit_deleteTestSuiteDef (suite);
182 * The main function. launch genregsuite function.
184 * @param arg input source files.
186 * @return zero when successfuly generated. non-zero when error occurred.
188 int ccunit_va_makeSuite (const char* prg, ...)
191 size_t capacity = 10;
192 char** av = calloc (10, sizeof (char*));
195 va_start (args, prg);
202 av = realloc (av, capacity * sizeof (char*));
204 av[ac] = va_arg (args, char*);
207 return ccunit_makeSuite (ac, av);