bgetopt.c

Go to the documentation of this file.
00001 /****************************************************************************/
00002 /*                                                                          */
00003 /*  This file is part of QSopt_ex.                                          */
00004 /*                                                                          */
00005 /*  (c) Copyright 2006 by David Applegate, William Cook, Sanjeeb Dash,      */
00006 /*  and Daniel Espinoza                                                     */
00007 /*                                                                          */
00008 /*  Sanjeeb Dash ownership of copyright in QSopt_ex is derived from his     */
00009 /*  copyright in QSopt.                                                     */
00010 /*                                                                          */
00011 /*  This code may be used under the terms of the GNU General Public License */
00012 /*  (Version 2.1 or later) as published by the Free Software Foundation.    */
00013 /*                                                                          */
00014 /*  Alternatively, use is granted for research purposes only.               */
00015 /*                                                                          */
00016 /*  It is your choice of which of these two licenses you are operating      */
00017 /*  under.                                                                  */
00018 /*                                                                          */
00019 /*  We make no guarantees about the correctness or usefulness of this code. */
00020 /*                                                                          */
00021 /****************************************************************************/
00022 
00023 /* RCSINFO $Id: bgetopt.c,v 1.2 2003/11/05 16:47:22 meven Exp $ */
00024 /****************************************************************************/
00025 /*                                                                          */
00026 /*  This file is part of CONCORDE                                           */
00027 /*                                                                          */
00028 /*  (c) Copyright 1995--1999 by David Applegate, Robert Bixby,              */
00029 /*  Vasek Chvatal, and William Cook                                         */
00030 /*                                                                          */
00031 /*  Permission is granted for academic research use.  For other uses,       */
00032 /*  contact the authors for licensing options.                              */
00033 /*                                                                          */
00034 /*  Use at your own risk.  We make no guarantees about the                  */
00035 /*  correctness or usefulness of this code.                                 */
00036 /*                                                                          */
00037 /****************************************************************************/
00038 
00039 /****************************************************************************/
00040 /*                                                                          */
00041 /*                        PORTABLE GETOPT                                   */
00042 /*                                                                          */
00043 /*                           TSP CODE                                       */
00044 /*                                                                          */
00045 /*                                                                          */
00046 /*  Written by:  Applegate, Bixby, Chvatal, and Cook                        */
00047 /*  Date: 1993 (?) (fmfeb02)                                                */
00048 /*  Modified: 15 February 1995 (bico)  - added warning                      */
00049 /*                                                                          */
00050 /*    EXPORTED FUNCTIONS:                                                   */
00051 /*                                                                          */
00052 /*  int ILLutil_bix_getopt (int argc, char **argv, const char *def,          */
00053 /*      int *p_optind, char **p_optarg)                                     */
00054 /*     parse an argument list                                               */
00055 /*                                                                          */
00056 /****************************************************************************/
00057 
00058 #include "machdefs.h"
00059 #include "util.h"
00060 #ifdef USEDMALLOC
00061 #include "dmalloc.h"
00062 #endif
00063 
00064 
00065 int ILLutil_bix_getopt (
00066   int ac,
00067   char **av,
00068   const char *def,
00069   int *p_optind,
00070   char **p_optarg)
00071 {
00072   int c;
00073   char *sp = av[*p_optind];
00074   char bwarn[2];
00075 
00076   if (*p_optind < 1 || *p_optind >= ac)
00077   {
00078     *p_optind = ac;
00079     return (EOF);
00080   }
00081   if ((int) *sp != (int) '-')
00082     return (EOF);
00083   if ((int) *(sp + 1) == (int) '-')
00084   {
00085     (*p_optind)++;
00086     return (EOF);
00087   }
00088   (av[*p_optind])++;
00089   sp++;
00090   while ((int) *sp != (int) *def && (int) *def != (int) '\0')
00091     def++;
00092   if ((int) *def == (int) '\0')
00093   {
00094     *p_optind = ac;
00095     bwarn[0] = *sp;             /* Bico: February 8, 1995 */
00096     bwarn[1] = '\0';
00097     printf ("Illegal option: -%s\n", bwarn);
00098     return ILL_BIX_GETOPT_UNKNOWN;
00099   }
00100   if ((int) *(def + 1) != (int) ':')
00101   {
00102     c = *sp;
00103     if ((int) *(sp + 1) != (int) '\0')
00104       *sp = '-';
00105     else
00106       (*p_optind)++;
00107     return (c);
00108   }
00109   else
00110   {
00111     if ((int) *(sp + 1) != (int) '\0')
00112     {
00113       *p_optarg = sp + 1;
00114       c = *sp;
00115       (*p_optind)++;
00116       return (c);
00117     }
00118     else if (*p_optind >= ac - 1)
00119     {
00120       *p_optind = ac;
00121       return (EOF);
00122     }
00123     else
00124     {
00125       *p_optarg = av[*p_optind + 1];
00126       c = *sp;
00127       *p_optind += 2;
00128       return (c);
00129     }
00130   }
00131 }

Generated on Wed Apr 22 09:16:09 2009 for QSopt_ex by  doxygen 1.5.2