utils

parsecmd.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschlas - gEDA Load and Save
00003  * Copyright (C) 2002-2010 Ales Hvezda
00004  * Copyright (C) 2002-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <stdio.h>
00024 #ifdef HAVE_STRING_H
00025 #include <string.h>
00026 #endif
00027 #ifdef HAVE_UNISTD_H
00028 #include <unistd.h>
00029 #endif
00030 
00031 #include <libgeda/libgeda.h>
00032 
00033 #include "../include/globals.h"
00034 #include "../include/prototype.h"
00035 
00036 #ifdef HAVE_LIBDMALLOC
00037 #include <dmalloc.h>
00038 #endif
00039 
00040 #define OPTIONS "hqveu"
00041 
00042 #ifndef OPTARG_IN_UNISTD
00043 extern char *optarg;
00044 extern int optind;
00045 #endif
00046 
00047 
00048 void usage(char *cmd)
00049 {
00050     printf("Usage: %s [OPTIONS] filename1 ... filenameN\n", cmd);
00051     printf("  -e        Embed all components/pictures\n");
00052     printf("  -u        Unembed all components/pictures\n");
00053     printf("  -q        Quiet mode\n");
00054     printf("  -v        Verbose mode on\n");
00055     printf("  -h        This message\n");
00056     printf("\n");
00057     exit(0);
00058 }
00059 
00060 int parse_commandline(int argc, char *argv[])
00061 {
00062     int ch;
00063 
00064     while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
00065     switch (ch) {
00066 
00067     case 'v':
00068         verbose_mode = TRUE;
00069         break;
00070 
00071     case 'q':
00072         quiet_mode = TRUE;
00073         break;
00074 
00075     case 'e':
00076         embed_mode = TRUE;
00077         break;
00078 
00079     case 'u':
00080         unembed_mode = TRUE;
00081         break;
00082 
00083     case 'h':
00084         usage(argv[0]);
00085         break;
00086 
00087     case '?':
00088     default:
00089         usage(argv[0]);
00090         break;
00091     }
00092     }
00093 
00094     if (quiet_mode) {
00095     verbose_mode = FALSE;
00096     }
00097 
00098     if (embed_mode && unembed_mode) {
00099     fprintf(stderr, 
00100             "Cannot specify both -e and -u at the same time (ignoring both flags)\n");  
00101     embed_mode = FALSE;
00102     unembed_mode = FALSE;
00103     }
00104 
00105     return (optind);
00106 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines