Diff of /src/cd-drive.c [e74fc3] .. [16bdbf]  Maximize  Restore

  Switch to unified view

a/src/cd-drive.c b/src/cd-drive.c
1
/*
1
/*
2
  $Id: cd-drive.c,v 1.23 2005/04/30 10:05:11 rocky Exp $
2
  $Id: cd-drive.c,v 1.24 2005/10/05 09:48:12 rocky Exp $
3
3
4
  Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
4
  Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
5
  
5
  
6
  This program is free software; you can redistribute it and/or modify
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
7
  it under the terms of the GNU General Public License as published by
...
...
26
#include <stdio.h>
26
#include <stdio.h>
27
#endif
27
#endif
28
#ifdef HAVE_SYS_TYPES_H
28
#ifdef HAVE_SYS_TYPES_H
29
#include <sys/types.h>
29
#include <sys/types.h>
30
#endif
30
#endif
31
#include <getopt.h>
31
#include <cdio/cdio.h>
32
#include <cdio/cdio.h>
32
#include <cdio/scsi_mmc.h>
33
#include <cdio/scsi_mmc.h>
33
34
34
/* Used by `main' to communicate with `parse_opt'. And global options
35
/* Used by `main' to communicate with `parse_opt'. And global options
35
 */
36
 */
...
...
41
  source_image_t source_image;
42
  source_image_t source_image;
42
} opts;
43
} opts;
43
     
44
     
44
/* Configuration option codes */
45
/* Configuration option codes */
45
enum {
46
enum {
47
  OP_HANDLED,
48
46
  OP_SOURCE_DEVICE,
49
  OP_SOURCE_DEVICE,
47
  
50
51
  OP_USAGE,
52
48
  /* These are the remaining configuration options */
53
  /* These are the remaining configuration options */
49
  OP_VERSION,  
54
  OP_VERSION,  
50
  
55
  
51
};
56
};
52
57
53
/* Parse a all options. */
58
/* Parse all options. */
54
static bool
59
static bool
55
parse_options (int argc, const char *argv[])
60
parse_options (int argc, char *argv[])
56
{
61
{
57
  int opt;
62
  int opt;
58
63
64
  const char* helpText =
65
    "Usage: %s [OPTION...]\n" 
66
    "  -d, --debug=INT                 Set debugging to LEVEL\n"
67
    "  -i, --cdrom-device[=DEVICE]     show only info about CD-ROM device\n"
68
    "  -q, --quiet                     Don't produce warning output\n"
69
    "  -V, --version                   display version and copyright information\n"
70
    "                                  and exit\n"
71
    "\n"
72
    "Help options:\n"
73
    "  -?, --help                      Show this help message\n"
74
    "  --usage                         Display brief usage message\n";
75
  
76
  const char* usageText =
77
    "Usage: %s [-d|--debug INT] [-i|--cdrom-device DEVICE] [-q|--quiet]\n"
78
    "        [-V|--version] [-?|--help] [--usage]\n";
79
80
  const char* optionsString = "d:i::qV?";
59
  struct poptOption optionsTable[] = {
81
  struct option optionsTable[] = {
60
    {"debug",       'd', POPT_ARG_INT, &opts.debug_level, 0,
82
    {"debug", required_argument, NULL, 'd' },
61
     "Set debugging to LEVEL"},
83
    {"cdrom-device", optional_argument, NULL, 'i' },
62
    
84
    {"quiet", no_argument, NULL, 'q' },
63
    {"cdrom-device", 'i', POPT_ARG_STRING|POPT_ARGFLAG_OPTIONAL, 
85
    {"version", no_argument, NULL, 'V' },
64
     &source_name, OP_SOURCE_DEVICE,
86
    {"help", no_argument, NULL, '?' },
65
     "show only info about CD-ROM device", "DEVICE"},
87
    {"usage", no_argument, NULL, OP_USAGE },
66
    
88
    {NULL, 0, NULL, 0 }
67
    {"quiet",       'q', POPT_ARG_NONE, &opts.silent, 0,
68
     "Don't produce warning output" },
69
    
70
    {"version", 'V', POPT_ARG_NONE, &opts.version_only, 0,
71
     "display version and copyright information and exit"},
72
    POPT_AUTOHELP {NULL, 0, 0, NULL, 0}
73
  };
89
  };
74
  poptContext optCon = poptGetContext (NULL, argc, argv, optionsTable, 0);
75
90
76
  program_name = strrchr(argv[0],'/');
91
  program_name = strrchr(argv[0],'/');
77
  program_name = program_name ? strdup(program_name+1) : strdup(argv[0]);
92
  program_name = program_name ? strdup(program_name+1) : strdup(argv[0]);
78
93
79
  while ((opt = poptGetNextOpt (optCon)) != -1) {
94
  while ((opt = getopt_long(argc, argv, optionsString, optionsTable, NULL)) != -1) {
80
    switch (opt) {
95
    switch (opt) {
81
      
96
    case 'd':
82
    case OP_SOURCE_DEVICE: 
97
      opts.debug_level = atoi(optarg);
98
      break;
99
100
    case 'i': 
83
      if (opts.source_image != DRIVER_UNKNOWN) {
101
      if (opts.source_image != DRIVER_UNKNOWN) {
102
  /* NOTE: The libpopt version already set source_name by this time.
103
     To restore this behavior, fall through to the else{} block.
104
  */
84
    report( stderr, "%s: another source type option given before.\n", 
105
    report( stderr, "%s: another source type option given before.\n", 
85
        program_name );
106
        program_name );
86
    report( stderr, "%s: give only one source type option.\n", 
107
    report( stderr, "%s: give only one source type option.\n", 
87
        program_name );
108
        program_name );
88
    break;
109
    break;
89
      } else {
110
      } else {
90
    opts.source_image  = DRIVER_DEVICE;
111
    opts.source_image  = DRIVER_DEVICE;
112
  if (optarg != NULL) {
91
    source_name = fillout_device_name(source_name);
113
      source_name = fillout_device_name(optarg);
114
  }
92
    break;
115
    break;
93
      }
116
      }
94
      break;
117
      break;
118
119
    case 'q':
120
      opts.silent = 1;
121
      break;
122
123
    case 'V':
124
      opts.version_only = 1;
125
      break;
126
127
    case '?':
128
      fprintf(stderr, helpText, program_name);
129
      free(program_name);
130
      exit(EXIT_FAILURE);
131
      break;
132
133
    case OP_USAGE:
134
      fprintf(stderr, usageText, program_name);
135
      free(program_name);
136
      exit(EXIT_FAILURE);
137
      break;
138
139
    case OP_HANDLED:
140
      break;
141
142
    default:
143
      return false;
144
    }
145
  }
146
  if (optind < argc) {
147
    const char *remaining_arg = argv[optind++];
148
149
    /* NOTE: A bug in the libpopt version checked source_image, which
150
       rendered the subsequent source_image test useless.
151
    */
152
    if (source_name != NULL) {
153
      report( stderr, "%s: Source specified in option %s and as %s\n", 
154
        program_name, source_name, remaining_arg);
155
      free(program_name);
156
      exit (EXIT_FAILURE);
157
    }
95
      
158
      
96
    default:
97
      poptFreeContext(optCon);
98
      return false;
99
    }
100
  }
101
  {
102
    const char *remaining_arg = poptGetArg(optCon);
103
    if ( remaining_arg != NULL) {
104
      if (opts.source_image != DRIVER_UNKNOWN) {
105
  report( stderr, "%s: Source specified in option %s and as %s\n", 
106
      program_name, source_name, remaining_arg);
107
  poptFreeContext(optCon);
108
  free(program_name);
109
  exit (EXIT_FAILURE);
110
      }
111
      
112
      if (opts.source_image == DRIVER_DEVICE)
159
    if (opts.source_image == DRIVER_DEVICE)
113
  source_name = fillout_device_name(remaining_arg);
160
      source_name = fillout_device_name(remaining_arg);
114
      else 
161
    else 
115
  source_name = strdup(remaining_arg);
162
      source_name = strdup(remaining_arg);
116
      
163
117
      if ( (poptGetArgs(optCon)) != NULL) {
164
    if (optind < argc) {
118
  report( stderr, "%s: Source specified in previously %s and %s\n", 
165
      report( stderr, "%s: Source specified in previously %s and %s\n", 
119
      program_name, source_name, remaining_arg);
166
          program_name, source_name, remaining_arg);
120
  poptFreeContext(optCon);
121
  free(program_name);
167
      free(program_name);
122
  exit (EXIT_FAILURE);
168
      exit (EXIT_FAILURE);
123
  
124
      }
169
    }
125
    }
126
  }
127
  
170
  }
128
  poptFreeContext(optCon);
171
  
129
  return true;
172
  return true;
130
}
173
}
131
174
132
/* CDIO logging routines */
175
/* CDIO logging routines */
133
176
...
...
185
  opts.debug_level   = 0;
228
  opts.debug_level   = 0;
186
  opts.source_image  = DRIVER_UNKNOWN;
229
  opts.source_image  = DRIVER_UNKNOWN;
187
}
230
}
188
231
189
int
232
int
190
main(int argc, const char *argv[])
233
main(int argc, char *argv[])
191
{
234
{
192
  CdIo_t *p_cdio=NULL;
235
  CdIo_t *p_cdio=NULL;
193
  
236
  
194
  init();
237
  init();
195
238

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks