home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gtak212.zip / 1.10 / getoldop.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  3KB  |  111 lines

  1. /*****************************************************************************
  2.  * $Id: getoldop.c,v 1.2 1992/09/02 20:09:04 ak Exp $
  3.  *****************************************************************************
  4.  * $Log: getoldop.c,v $
  5.  * Revision 1.2  1992/09/02  20:09:04  ak
  6.  * Version AK200
  7.  * - Tape access
  8.  * - Quick file access
  9.  * - OS/2 extended attributes
  10.  * - Some OS/2 fixes
  11.  * - Some fixes of Kai Uwe Rommel
  12.  *
  13.  * Revision 1.1.1.1  1992/09/02  19:21:28  ak
  14.  * Original GNU Tar 1.10 with some filenames changed for FAT compatibility.
  15.  *
  16.  * Revision 1.1  1992/09/02  19:21:26  ak
  17.  * Initial revision
  18.  *
  19.  *****************************************************************************/
  20.  
  21. static char *rcsid = "$Id: getoldop.c,v 1.2 1992/09/02 20:09:04 ak Exp $";
  22.  
  23. /* Replacement for getopt() that can be used by tar.
  24.    Copyright (C) 1988 Free Software Foundation
  25.  
  26. This file is part of GNU Tar.
  27.  
  28. GNU Tar is free software; you can redistribute it and/or modify
  29. it under the terms of the GNU General Public License as published by
  30. the Free Software Foundation; either version 1, or (at your option)
  31. any later version.
  32.  
  33. GNU Tar is distributed in the hope that it will be useful,
  34. but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  36. GNU General Public License for more details.
  37.  
  38. You should have received a copy of the GNU General Public License
  39. along with GNU Tar; see the file COPYING.  If not, write to
  40. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  41.  
  42. /*
  43.  * Plug-compatible replacement for getopt() for parsing tar-like
  44.  * arguments.  If the first argument begins with "-", it uses getopt;
  45.  * otherwise, it uses the old rules used by tar, dump, and ps.
  46.  *
  47.  * Written 25 August 1985 by John Gilmore (ihnp4!hoptoad!gnu)
  48.  *
  49.  * @(#)getoldopt.c 1.4 2/4/86 - gnu
  50.  */
  51.  
  52. #include <stdio.h>
  53. #include "getopt.h"
  54.  
  55. int
  56. getoldopt(argc, argv, optstring, long_options, opt_index)
  57.     int    argc;
  58.     char    **argv;
  59.     char    *optstring;
  60.     struct option *long_options;
  61.     int     *opt_index;
  62. {
  63.     extern char    *optarg;    /* Points to next arg */
  64.     extern int    optind;        /* Global argv index */
  65.     static char    *key;        /* Points to next keyletter */
  66.     static char    use_getopt;    /* !=0 if argv[1][0] was '-' */
  67.     extern char    *index();
  68.     char        c;
  69.     char        *place;
  70.  
  71.     optarg = NULL;
  72.     
  73.     if (key == NULL) {        /* First time */
  74.         if (argc < 2) return EOF;
  75.         key = argv[1];
  76.         if ((*key == '-') || (*key == '+'))
  77.             use_getopt++;
  78.         else
  79.             optind = 2;
  80.     }
  81.  
  82.     if (use_getopt)
  83.         return getopt_long(argc, argv, optstring, 
  84.                    long_options, opt_index);
  85.  
  86.     c = *key++;
  87.     if (c == '\0') {
  88.         key--;
  89.         return EOF;
  90.     }
  91.     place = index(optstring, c);
  92.  
  93.     if (place == NULL || c == ':') {
  94.         msg("unknown option %c", c);
  95.         return('?');
  96.     }
  97.  
  98.     place++;
  99.     if (*place == ':') {
  100.         if (optind < argc) {
  101.             optarg = argv[optind];
  102.             optind++;
  103.         } else {
  104.             msg("%c argument missing", c);
  105.             return('?');
  106.         }
  107.     }
  108.  
  109.     return(c);
  110. }
  111.