summaryrefslogtreecommitdiffstats
path: root/debian/uncrustify-trinity/uncrustify-trinity-0.73.0/src/args.h
blob: 712fbd59fb0cd9104fe7c8ee5798eda7fde0426d (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
/**
 * @file args.h
 * Parses command line arguments.
 *
 * This differs from the GNU/getopt way in that:
 *  - parameters cannot mixed "-e -f" is not the same as "-ef"
 *  - knowledge of the complete set of parameters is not required
 *  - this means you can handle args in multiple spots
 *  - it is more portable
 *
 * @author  Ben Gardner
 * @license GPL v2+
 */
#ifndef ARGS_H_INCLUDED
#define ARGS_H_INCLUDED

#include "base_types.h"

class Args
{
protected:
   size_t m_count;     //! number of command line arguments
   char   **m_values;  //! pointer array to each argument
   UINT8  *m_used;     //! bit array with one flag per argument

public:
   /**
    * Initializes the argument library.
    * Store the values and allocates enough memory for the 'used' flags.
    * This keeps a reference to argv, so don't change it.
    *
    * @param argc  number of command line parameter passed to main()
    * @param argv  pointer array to command line parameters
    */
   Args(int argc, char **argv);

   //! Standard destructor
   ~Args();

   /**
    * Checks to see if an arg w/o a value is present.
    * Scans the args looking for an exact match.
    *
    * "-c" matches "-c", but not "-call" or "-ec"
    *
    * @param token  The token string to match
    *
    * @return true/false -- Whether the argument was present
    */
   bool Present(const char *token);

   /**
    * Calls Args::Params() with index 0
    *
    * @param token  The token string to match
    *
    * @return nullptr or the pointer to the string
    */
   const char *Param(const char *token);

   /**
    * Check for an arg with a value.
    * Returns only the first match.
    *
    * Assuming the token "-c"...
    *   "-call" returns "all"
    *   "-c=all" returns "all"
    *   "-c", "all" returns "all"
    *   "-c=", "all" returns ""
    *
    * @param          token  the token string to match
    * @param[in, out] index  search start position, in case that something is
    *                        found, it will get the succeeding position number
    *                        assigned
    *
    * @return nullptr or the pointer to the string
    */
   const char *Params(const char *token, size_t &index);

   /**
    * Marks an argument as being used.
    *
    * @param idx  The index of the argument
    */
   void SetUsed(size_t idx);

   /**
    * Gets whether an argument has been used, by index.
    *
    * @param idx  The index of the argument
    */
   bool GetUsed(size_t idx);

   /**
    * This function retrieves all unused parameters.
    * You must set the index before the first call.
    * Set the index to 1 to skip argv[0].
    *
    * @param idx  Pointer to the index
    *
    * @return nullptr (done) or the pointer to the string
    */
   const char *Unused(size_t &idx);

   /**
    * Takes text and splits it into arguments.
    * args is an array of char pointers that will get populated.
    * num_args is the maximum number of args split off.
    * If there are more than num_args, the remaining text is ignored.
    * Note that text is modified (zeroes are inserted)
    *
    * @param      text      the text to split (modified)
    * @param[out] args      array of pointers to be populated
    * @param      num_args  number of items in input string
    *
    * @return The number of arguments parsed (always <= num_args)
    */
   static size_t SplitLine(char *text, char *args[], size_t num_args);
};


#endif /* ARGS_H_INCLUDED */