File: demo_tag_options.c

package info (click to toggle)
id3lib3.8.3 3.8.3-13
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 5,564 kB
  • ctags: 3,071
  • sloc: cpp: 12,358; sh: 9,186; ansic: 7,240; makefile: 349; php: 325
file content (316 lines) | stat: -rw-r--r-- 9,402 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
  File autogenerated by gengetopt version 2.1  
  generated with the following command:
  gengetopt --file-name=demo_tag_options --unamed-opts --input=demo_tag_options.ggo 

  The developers of gengetopt consider the fixed text that goes in all
  gengetopt output files to be in the public domain:
  we make no copyright claims on it.
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* If we use autoconf.  */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

/* Check for configure's getopt check result.  */
#ifndef HAVE_GETOPT_LONG
#include "getopt.h"
#else
#include <getopt.h>
#endif

#include "demo_tag_options.h"

/* Don't define PACKAGE and VERSION if we use automake.  */
#define GGO_PACKAGE "id3tag"
#ifndef VERSION
#  define GGO_VERSION VERSION
#else
/* ******* WRITE THE VERSION OF YOUR PROGRAM HERE ******* */
#  define GGO_VERSION ""
#endif


void
print_version (void)
{
  printf ("%s %s\n", GGO_PACKAGE, GGO_VERSION);
}

void
print_help (void)
{
  print_version ();
  printf ("Usage: %s [OPTIONS]... [FILES]...\n\
   -h         --help            Print help and exit\n\
   -V         --version         Print version and exit\n\
   -1         --v1tag           Render only the id3v1 tag (default=off)\n\
   -2         --v2tag           Render only the id3v2 tag (default=off)\n\
   -aSTRING   --artist=STRING   Set the artist information\n\
   -ASTRING   --album=STRING    Set the album title information\n\
   -sSTRING   --song=STRING     Set the title information\n\
   -cSTRING   --comment=STRING  Set the comment information\n\
   -CSTRING   --desc=STRING     Set the comment description\n\
   -ySTRING   --year=STRING     Set the year\n\
   -tSTRING   --track=STRING    Set the track number\n\
   -TSTRING   --total=STRING    Set the total number of tracks\n\
   -gSHORT    --genre=SHORT     Set the genre\n\
   -w         --warning         Turn on warnings (for debugging) (default=off)\n\
   -n         --notice          Turn on notices (for debugging) (default=off)\n\
", GGO_PACKAGE);
}


char *
gengetopt_strdup (char * s)
{
  char * n, * pn, * ps = s;
  while (*ps) ps++;
  n = (char *) malloc (1 + ps - s);
  if (n != NULL)
    {
      for (ps=s,pn=n; *ps; ps++,pn++)
        *pn = *ps;
      *pn = 0;
    }
  return n;
}


int
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
{
  int c;	/* Character of the parsed option.  */
  int missing_required_options = 0;	

  args_info->help_given = 0 ;
  args_info->version_given = 0 ;
  args_info->v1tag_given = 0 ;
  args_info->v2tag_given = 0 ;
  args_info->artist_given = 0 ;
  args_info->album_given = 0 ;
  args_info->song_given = 0 ;
  args_info->comment_given = 0 ;
  args_info->desc_given = 0 ;
  args_info->year_given = 0 ;
  args_info->track_given = 0 ;
  args_info->total_given = 0 ;
  args_info->genre_given = 0 ;
  args_info->warning_given = 0 ;
  args_info->notice_given = 0 ;

#define clear_args()
{ \
  args_info->v1tag_flag = 0;\
  args_info->v2tag_flag = 0;\
  args_info->artist_arg = NULL; \
  args_info->album_arg = NULL; \
  args_info->song_arg = NULL; \
  args_info->comment_arg = NULL; \
  args_info->desc_arg = NULL; \
  args_info->year_arg = NULL; \
  args_info->track_arg = NULL; \
  args_info->total_arg = NULL; \
  args_info->warning_flag = 0;\
  args_info->notice_flag = 0;\
}

  clear_args();

  args_info->inputs = NULL;
  args_info->inputs_num = 0;

  while (1)
    {
      int option_index = 0;
      static struct option long_options[] = {
        { "help",	0, NULL, 'h' },
        { "version",	0, NULL, 'V' },
        { "v1tag",	0, NULL, '1' },
        { "v2tag",	0, NULL, '2' },
        { "artist",	1, NULL, 'a' },
        { "album",	1, NULL, 'A' },
        { "song",	1, NULL, 's' },
        { "comment",	1, NULL, 'c' },
        { "desc",	1, NULL, 'C' },
        { "year",	1, NULL, 'y' },
        { "track",	1, NULL, 't' },
        { "total",	1, NULL, 'T' },
        { "genre",	1, NULL, 'g' },
        { "warning",	0, NULL, 'w' },
        { "notice",	0, NULL, 'n' },
        { NULL,	0, NULL, 0 }
      };

      c = getopt_long (argc, argv, "hV12a:A:s:c:C:y:t:T:g:wn", long_options, &option_index);

      if (c == -1) break;	/* Exit from `while (1)' loop.  */

      switch (c)
        {
        case 'h':	/* Print help and exit.  */
          clear_args ();
          print_help ();
          exit (0);

        case 'V':	/* Print version and exit.  */
          clear_args ();
          print_version ();
          exit (0);

        case '1':	/* Render only the id3v1 tag.  */
          args_info->v1tag_flag = !(args_info->v1tag_flag);
          break;

        case '2':	/* Render only the id3v2 tag.  */
          args_info->v2tag_flag = !(args_info->v2tag_flag);
          break;

        case 'a':	/* Set the artist information.  */
          if (args_info->artist_given)
            {
              fprintf (stderr, "%s: `--artist' (`-a') option given more than once\n", GGO_PACKAGE);
              clear_args ();
              print_help ();
              exit (1);
            }
          args_info->artist_given = 1;
          args_info->artist_arg = gengetopt_strdup (optarg);
          break;

        case 'A':	/* Set the album title information.  */
          if (args_info->album_given)
            {
              fprintf (stderr, "%s: `--album' (`-A') option given more than once\n", GGO_PACKAGE);
              clear_args ();
              print_help ();
              exit (1);
            }
          args_info->album_given = 1;
          args_info->album_arg = gengetopt_strdup (optarg);
          break;

        case 's':	/* Set the title information.  */
          if (args_info->song_given)
            {
              fprintf (stderr, "%s: `--song' (`-s') option given more than once\n", GGO_PACKAGE);
              clear_args ();
              print_help ();
              exit (1);
            }
          args_info->song_given = 1;
          args_info->song_arg = gengetopt_strdup (optarg);
          break;

        case 'c':	/* Set the comment information.  */
          if (args_info->comment_given)
            {
              fprintf (stderr, "%s: `--comment' (`-c') option given more than once\n", GGO_PACKAGE);
              clear_args ();
              print_help ();
              exit (1);
            }
          args_info->comment_given = 1;
          args_info->comment_arg = gengetopt_strdup (optarg);
          break;

        case 'C':	/* Set the comment description.  */
          if (args_info->desc_given)
            {
              fprintf (stderr, "%s: `--desc' (`-C') option given more than once\n", GGO_PACKAGE);
              clear_args ();
              print_help ();
              exit (1);
            }
          args_info->desc_given = 1;
          args_info->desc_arg = gengetopt_strdup (optarg);
          break;

        case 'y':	/* Set the year.  */
          if (args_info->year_given)
            {
              fprintf (stderr, "%s: `--year' (`-y') option given more than once\n", GGO_PACKAGE);
              clear_args ();
              print_help ();
              exit (1);
            }
          args_info->year_given = 1;
          args_info->year_arg = gengetopt_strdup (optarg);
          break;

        case 't':	/* Set the track number.  */
          if (args_info->track_given)
            {
              fprintf (stderr, "%s: `--track' (`-t') option given more than once\n", GGO_PACKAGE);
              clear_args ();
              print_help ();
              exit (1);
            }
          args_info->track_given = 1;
          args_info->track_arg = gengetopt_strdup (optarg);
          break;

        case 'T':	/* Set the total number of tracks.  */
          if (args_info->total_given)
            {
              fprintf (stderr, "%s: `--total' (`-T') option given more than once\n", GGO_PACKAGE);
              clear_args ();
              print_help ();
              exit (1);
            }
          args_info->total_given = 1;
          args_info->total_arg = gengetopt_strdup (optarg);
          break;

        case 'g':	/* Set the genre.  */
          if (args_info->genre_given)
            {
              fprintf (stderr, "%s: `--genre' (`-g') option given more than once\n", GGO_PACKAGE);
              clear_args ();
              print_help ();
              exit (1);
            }
          args_info->genre_given = 1;
          args_info->genre_arg = (short)atoi (optarg);
          break;

        case 'w':	/* Turn on warnings (for debugging).  */
          args_info->warning_flag = !(args_info->warning_flag);
          break;

        case 'n':	/* Turn on notices (for debugging).  */
          args_info->notice_flag = !(args_info->notice_flag);
          break;

        case '?':	/* Invalid option.  */
          /* `getopt_long' already printed an error message.  */
          exit (1);

        default:	/* bug: option not considered.  */
          fprintf (stderr, "%s: option unknown: %c\n", GGO_PACKAGE, c);
          abort ();
        } /* switch */
    } /* while */

  if ( missing_required_options )
    exit (1);

  if (optind < argc)
    {
      int i = 0 ;

      args_info->inputs_num = argc - optind ;
      args_info->inputs = 
        (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
      while (optind < argc)
        args_info->inputs[ i++ ] = strdup (argv[optind++]) ; 
    }

  return 0;
}