summaryrefslogtreecommitdiff
path: root/support/ligatex/common.c
blob: c1c6c2c1f88eb90eab0e811723a046b123e5150e (plain)
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
/* GNU TalkFilters - common command line parsing code
   Copyright (C) 1998 Free Software Foundation, Inc.

   This file is part of GNU Talkfilters

   GNU Talkfilters is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   GNU Talkfilters is distributed in the hope that it will be amusing,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GNU Talkfilters; see the file COPYING.  If not, write to
   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/

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

#include "getopt.h"

#define HELP_OPTION 0
#define VERSION_OPTION 1

static const struct option options[] = { { "help", 0, NULL, 0  },
                                          { "version", 0, NULL, 0 },
                                          { NULL, 0, NULL, 0 } };

void parse_args(int argc, char **argv, char *help, char *version)
{
   int c, option_index;

   while((c = getopt_long(argc, argv, "", options, &option_index)) != EOF)
   {
      switch(c)
      {
      case 0:
         if(option_index == HELP_OPTION)
            fprintf(stderr, help, *argv);
         else if(option_index == VERSION_OPTION)
         {
            fputs(version, stderr);
            fputc('\n', stderr);
         }
         exit(EXIT_SUCCESS);
         break;

       default:
         fprintf(stderr, help, *argv);
         exit(EXIT_FAILURE);
         break;
      }
   }
}