00001
00032 #ifdef HAVE_CONFIG_H
00033 # include <config.h>
00034 #endif
00035
00036 #include <sys/types.h>
00037 #include <sys/stat.h>
00038 #include <unistd.h>
00039 #include <string.h>
00040 #include <stdio.h>
00041 #include <getopt.h>
00042 #include <gtk/gtk.h>
00043 #include <stdlib.h>
00044
00045
00046 #ifdef ENABLE_NLS
00047 # include <libintl.h>
00048 # undef _
00049 # define _(String) dgettext (PACKAGE, String)
00050 # define Q_(String) g_strip_context ((String), gettext (String))
00051 # ifdef gettext_noop
00052 # define N_(String) gettext_noop (String)
00053 # else
00054 # define N_(String) (String)
00055 # endif
00056 #else
00057 # define textdomain(String) (String)
00058 # define gettext(String) (String)
00059 # define dgettext(Domain,Message) (Message)
00060 # define dcgettext(Domain,Message,Type) (Message)
00061 # define bindtextdomain(Domain,Directory) (Domain)
00062 # define _(String) (String)
00063 # define Q_(String) g_strip_context ((String), (String))
00064 # define N_(String) (String)
00065 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
00066 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
00067 textdomain (GETTEXT_PACKAGE);
00068 #endif
00069
00070 #define GUI 0
00071
00072 #define CLI 1
00073
00076 #include "libfpw.c"
00077 #include "packages.h"
00078 #include "fpw.h"
00079
00080
00081 gchar *program_name = NULL;
00082 gchar *fpw_filename;
00083
00084
00090 int
00091 print_version ()
00092 {
00093 fprintf (stderr, (_("\nfpw version %s\n")), VERSION);
00094 fprintf (stderr, (_("(C) 2007, 2008, 2009, 2010, 2011 by Bert Timmerman.\n")));
00095 fprintf (stderr, (_("This free software is released under the GPL v2 license;\n")));
00096 fprintf (stderr, (_("see the source for copying conditions.\n")));
00097 fprintf (stderr, (_("There is NO warranty; not even for MERCHANTABILITY\n")));
00098 fprintf (stderr, (_("or FITNESS FOR A PARTICULAR PURPOSE.\n\n")));
00099 return (EXIT_SUCCESS);
00100 }
00101
00102
00108 int
00109 print_usage ()
00110 {
00111 fprintf (stderr, (_("\nfpw usage and options:\n")));
00112 fprintf (stderr, (_("\t --help \n")));
00113 fprintf (stderr, (_("\t -? \n")));
00114 fprintf (stderr, (_("\t -h : print this help message and exit.\n\n")));
00115 fprintf (stderr, (_("\t --verbose \n")));
00116 fprintf (stderr, (_("\t -v : log messages, be verbose.\n\n")));
00117 fprintf (stderr, (_("\t --silent \n")));
00118 fprintf (stderr, (_("\t --quiet \n")));
00119 fprintf (stderr, (_("\t -q : do not log messages, overrides --verbose.\n\n")));
00120 fprintf (stderr, (_("\t --version \n")));
00121 fprintf (stderr, (_("\t -V : print the version information and exit.\n\n")));
00122 fprintf (stderr, (_("\t --format <fpw_footprintwizard filename> \n")));
00123 fprintf (stderr, (_("\t -f <fpw_footprintwizard filename>\n\n")));
00124 fprintf (stderr, (_("\t --output <footprint name> \n")));
00125 fprintf (stderr, (_("\t -o <footprint name>\n\n")));
00126 fprintf (stderr, (_("\t --debug \n")));
00127 fprintf (stderr, (_("\t -d : turn on debugging output messages.\n\n")));
00128 return (EXIT_SUCCESS);
00129 }
00130
00131
00137 int
00138 main
00139 (
00140 int argc,
00141 char **argv
00142 )
00143 {
00144
00145 program_name = argv[0];
00146 static const struct option opts[] =
00147 {
00148 {"debug", no_argument, NULL, 'd'},
00149 {"help", no_argument, NULL, 'h'},
00150 {"version", no_argument, NULL, 'V'},
00151 {"verbose", no_argument, NULL, 'v'},
00152 {"quiet", no_argument, NULL, 'q'},
00153 {"silent", no_argument, NULL, 'q'},
00154 {"format", required_argument, NULL, 'f'},
00155 {"output", required_argument, NULL, 'o'},
00156 {0, 0, 0, 0}
00157 };
00158 int optc;
00159 while ((optc = getopt_long (argc, argv, "dhVvqqf:o:", opts, NULL)) != -1)
00160 {
00161 switch (optc)
00162 {
00163 case 'd':
00164 debug = TRUE;
00165 break;
00166 case 'h':
00167 print_usage ();
00168 exit (EXIT_SUCCESS);
00169 case 'V':
00170 print_version ();
00171 exit (EXIT_SUCCESS);
00172 case 'v':
00173 verbose = TRUE;
00174 break;
00175 case 'q':
00176 silent = TRUE;
00177 verbose = FALSE;
00178 break;
00179 case 'f':
00180 fpw_filename = strdup (optarg);
00181 if (debug)
00182 fprintf (stderr, "fpw filename = %s\n", fpw_filename);
00183 break;
00184 case 'o':
00185 footprint_name = strdup (optarg);
00186 if (debug)
00187 fprintf (stderr, "footprint name = %s\n", footprint_name);
00188 break;
00189 case '?':
00190 print_usage ();
00191 exit (EXIT_FAILURE);
00192 default:
00193 g_log ("", G_LOG_LEVEL_WARNING,
00194 _("unknown command line option encountered.\n"));
00195 print_usage ();
00196 exit (EXIT_FAILURE);
00197 }
00198 }
00199 if (optind < argc)
00200 {
00201 print_usage ();
00202 exit (EXIT_FAILURE);
00203 }
00204
00205 if (read_footprintwizard_file (fpw_filename))
00206 {
00207 if (verbose)
00208 {
00209 g_log ("", G_LOG_LEVEL_INFO,
00210 _("read footprintwizard file %s."),
00211 fpw_filename);
00212 }
00213 }
00214 else
00215 {
00216 if ((verbose) || (!silent))
00217 {
00218 g_log ("", G_LOG_LEVEL_ERROR,
00219 _("could not load footprintwizard file %s."),
00220 fpw_filename);
00221 }
00222 exit (EXIT_FAILURE);
00223 }
00224
00225
00226 if (!footprint_name)
00227 {
00228 if ((verbose) || (!silent))
00229 {
00230 g_log ("", G_LOG_LEVEL_ERROR,
00231 _("footprint name contains a null pointer."));
00232 }
00233 exit (EXIT_FAILURE);
00234 }
00235
00236
00237 if (!strcmp (footprint_name, ""))
00238 {
00239 if ((verbose) || (!silent))
00240 {
00241 g_log ("", G_LOG_LEVEL_ERROR,
00242 _("footprint name contains an empty string."));
00243 }
00244 exit (EXIT_FAILURE);
00245 }
00246
00247 if (g_str_has_suffix (footprint_name, fp_suffix))
00248 {
00249
00250 footprint_filename = g_strdup (footprint_name);
00251 }
00252 else
00253 {
00254
00255 footprint_filename = g_strconcat (footprint_name, fp_suffix, NULL);
00256 }
00257 write_footprint ();
00258 if (verbose)
00259 {
00260 g_log ("", G_LOG_LEVEL_INFO,
00261 _("Footprint %s is written successful."),
00262 footprint_name);
00263 }
00264 }
00265
00266
00267