summaryrefslogtreecommitdiff
path: root/src/main/ProcessCommandLine.c
blob: 62fd8c234364fb8e3fcb4c1cf212e0777384a45f (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
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
 /*@@
   @file      ProcessCommandLine.c
   @date      Thu Sep 24 10:32:28 1998
   @author    Tom Goodale
   @desc 
   Routines to deal with the command line arguments.
   @enddesc 
 @@*/
#include <stdio.h>
#include <stdlib.h>

#include "CommandLine.h"
#include "cctk_Flesh.h"
#include "getopt.h"

static char *rcsid = "$Header$";

static int argc;

static char **argv;

 /*@@
   @routine    CCTKi_ProcessCommandLine
   @date       Thu Sep 24 10:33:31 1998
   @author     Tom Goodale
   @desc 
   Processes the command line arguments.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
int CCTKi_ProcessCommandLine(int *inargc, char ***inargv, tFleshConfig *ConfigData)
{

  int option_index = 0;
  int c;

  /* Store the command line */
  argc = *inargc;

  argv = *inargv;

  /* Process the command line - needs some work !*/

  if(argc>1)
  {
    while (1)
    {
      struct option long_options[] =
      {
        {"help", no_argument, NULL, 'h'},
        {"describe-all-parameters", optional_argument, NULL, 'O'},
        {"describe-parameter",      required_argument, NULL, 'o'},
        {"test-parameters",         optional_argument, NULL, 'x'},
        {"warning-level",           required_argument, NULL, 'W'},
        {"error-level",             required_argument, NULL, 'E'},
        {"redirect-stdout",         no_argument,       NULL, 'r'},
        {"list-thorns",             no_argument,       NULL, 'T'},
        {"test-thorn-compiled",     required_argument, NULL, 't'},
        {"version", no_argument, NULL, 'v'},
        {0, 0, 0, 0}
      };
      
      c = getopt_long_only (argc, argv, "hO::o:x::W:E:rTt:v",
                            long_options, &option_index);
      if (c == -1)
        break;
  
      switch (c)
      {
        case 't': CCTKi_CommandLineTestThornCompiled(optarg); break;
        case 'O': CCTKi_CommandLineDescribeAllParameters(optarg); break;
        case 'o': CCTKi_CommandLineDescribeParameter(optarg); break;
        case 'x': CCTKi_CommandLineTestParameters(optarg); break;
        case 'W': CCTKi_CommandLineWarningLevel(optarg); break;
        case 'E': CCTKi_CommandLineErrorLevel(optarg); break;
        case 'r': CCTKi_CommandLineRedirectStdout(); break;
        case 'T': CCTKi_CommandLineListThorns(); break;
        case 'v': CCTKi_CommandLineVersion(); break;
        case 'h': 
        case '?':
          CCTKi_CommandLineHelp(); break;
        default:
          printf ("?? getopt returned character code 0%o ??\n", c);
      }
    }

    if(argc > optind)
    {
      ConfigData->parameter_file_name = argv[optind];
    }
    else
    {
      CCTKi_CommandLineUsage();
    }
  }
  else
  {
    CCTKi_CommandLineUsage();
  }

  CCTKi_CommandLineFinished();

  return 0;
}


 /*@@
   @routine    CCTK_CommandLine
   @date       Wed Feb 17 00:19:30 1999
   @author     Tom Goodale
   @desc 
   Gets the command line arguments.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
int CCTK_CommandLine(char ***outargv)
{
  *outargv = argv;

  return argc;
}