xref: /trafficserver/include/tscore/ink_args.h (revision 079a4027)
1 /** @file
2 
3   A brief file description
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 /****************************************************************************
25 Process arguments
26 
27 ****************************************************************************/
28 
29 #pragma once
30 #include "tscore/ink_defs.h"
31 #include "tscore/ink_apidefs.h"
32 
33 #if HAVE_SYSEXITS_H
34 #include <sysexits.h>
35 #endif
36 
37 #ifndef EX_USAGE
38 #define EX_USAGE 64
39 #endif
40 
41 #define MAX_FILE_ARGUMENTS 100
42 
43 struct ArgumentDescription;
44 class AppVersionInfo;
45 
46 typedef void ArgumentFunction(const ArgumentDescription *argument_descriptions, unsigned n_argument_descriptions, const char *arg);
47 
48 struct ArgumentDescription {
49   const char *name;
50   char key; // set to '-' if no single character key.
51             /*
52                "I" = integer
53                "L" = int64_t
54                "D" = double (floating point)
55                "T" = toggle
56                "F" = set flag to TRUE (default is FALSE)
57                "f" = set flag to FALSE (default is TRUE)
58                "T" = toggle
59                "S80" = read string, 80 chars max
60                "S*" = read unbounded string, allocating
61              */
62   const char *description;
63   const char *type;
64   void *location;
65   const char *env;
66   ArgumentFunction *pfn;
67 };
68 
69 #define VERSION_ARGUMENT_DESCRIPTION()                                         \
70   {                                                                            \
71     "version", 'V', "Print version string", nullptr, nullptr, nullptr, nullptr \
72   }
73 #define HELP_ARGUMENT_DESCRIPTION()                                          \
74   {                                                                          \
75     "help", 'h', "Print usage information", nullptr, nullptr, nullptr, usage \
76   }
77 #define RUNROOT_ARGUMENT_DESCRIPTION()                                                 \
78   {                                                                                    \
79     "run-root", '-', "using TS_RUNROOT as sandbox", nullptr, nullptr, nullptr, nullptr \
80   }
81 
82 /* Global Data
83  */
84 extern const char *file_arguments[]; // exported by process_args()
85 extern unsigned n_file_arguments;    // exported by process_args()
86 extern const char *program_name;     // exported by process_args()
87 extern int cmd_disable_pfreelist;
88 
89 /* Print out arguments and values
90  */
91 void show_argument_configuration(const ArgumentDescription *argument_descriptions, unsigned n_argument_descriptions);
92 
93 void usage(const ArgumentDescription *argument_descriptions, unsigned n_argument_descriptions, const char *arg_unused) TS_NORETURN;
94 
95 /* Process all arguments
96  */
97 void process_args(const AppVersionInfo *appinfo, const ArgumentDescription *argument_descriptions, unsigned n_argument_descriptions,
98                   const char **argv, const char *usage_string = nullptr);
99 
100 bool process_args_ex(const AppVersionInfo *appinfo, const ArgumentDescription *argument_descriptions,
101                      unsigned n_argument_descriptions, const char **argv);
102