Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
argv.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/* $Header: /VSS_Sync/wwlib/argv.h 7 8/29/01 10:25p Vss_sync $ */
20/***********************************************************************************************
21 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Library *
25 * *
26 * $Archive:: /VSS_Sync/wwlib/argv.h $*
27 * *
28 * $Author:: Vss_sync $*
29 * *
30 * $Modtime:: 8/29/01 10:24p $*
31 * *
32 * $Revision:: 7 $*
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37
38#if defined(_MSC_VER)
39#pragma once
40#endif
41
42
43#ifndef ARGV_H
44#define ARGV_H
45
46#ifndef ALWAYS_H
47#include "always.h"
48#endif
49
50#ifdef _UNIX
51#include "osdep.h"
52#endif
53
54// Used to parse command line that is passed into WinMain.
55// It also has the ability to load a file with values to append to the command line.
56// Normally in WinMain() there would be a call Argv::Init(lpCmdLine, fileprefix).
57// Once this is done, user can create an ArgvClass object (say argv) then argv.Find() can be called.
58// If there is a arguement <fileprefix><fname> (for example @file.arg) then the fname is loaded up,
59// parsed, and put into the command line. The format of the parameter file is as follows:
60// 1. a semicolon (;) at the start of the line is a comment and will be ignored.
61// 2. Each line is a seperate parameter. This enables white space to be embeded.
62// In typical Argv implementation, the first argument is the name of the application. This
63// is not the case with this.
65{
66 public:
67 // As passed into WinMain.
68 // Should be called before any objects are created.
69 // This can be called multible times.
70 static int Init(char *lpCmdLine, char *fileprefix = "@");
71 static bool Load_File(const char *fname);
72 static void Free();
73
74 // Create an object that can search the args.
75 ArgvClass(bool case_sensitive = false, bool exact_size = false);
77
78 // Functions to find a value.
79 const char *Find(const char *arg) {
80 CurrentPos = -1;
81 return(Find_Again(arg));
82 }
83 // If NULL passed, original string will be used.
84 const char *Find_Again(const char *arg = 0L);
85
86 // Return pointer to data after 'arg'.
87 // White space is skipped.
88 // So give a line '-Pdata' or '-P data' and arg==-P, 'data' would be returned in
89 // both cases.
90 const char *Find_Value(const char *arg);
91
92 // Similar to Find_Value, only gets value of current arg. User needs to pass
93 // in the strlen of the prefix (2 for -P example above) to skip.
94 // Val_in_next is set if the value was extracted from the next Argv,
95 // this way the programmer can know if he needs to call an extra Next().
96 const char *Get_Cur_Value(unsigned prefixlen, bool * val_in_next = 0);
97
98 // Update an existing attrib to use this new value
99 void Update_Value(const char *attrib, const char *value);
100
101 // Add a new attrib value pair (or just an option)
102 void Add_Value(const char *attrib, const char *value=NULL);
103
104 // Remove an option (and its value)
105 bool Remove_Value(const char *attrib);
106
107
108 // First parameter.
109 const char *First() {
110 CurrentPos = 0;
111 return(Argv[0]);
112 }
113
114 // Next works after a Find() call also.
115 const char *Next() {
116 CurrentPos++;
117 if (CurrentPos < Argc) {
118 return(Argv[CurrentPos]);
119 }
120 return(0L);
121 }
122 // Can be called so Next() will return First()...
123 void Reset() {
124 CurrentPos = -1;
125 }
126
127 const char *Cur() {
128 if (CurrentPos < Argc) {
129 return(Argv[CurrentPos]);
130 }
131 return(0L);
132 }
133
134 // Allow user to change states.
135 void Case_Sensitive(bool on) {Flag.CaseSensitive = on;}
136 bool Is_Case_Sensitive() {return (Flag.CaseSensitive);}
137
138 // Allow user to change states.
139 void Exact_Size(bool on) {Flag.ExactSize = on;}
140 bool Is_Exact_Size() {return (Flag.ExactSize);}
141
142 protected:
143 // Current position to be used when Next or Find_Again are called.
145
146 // Last arg that we are searching for.
147 const char *LastArg;
148
149 union {
150 unsigned Flags;
151 struct {
152 unsigned CaseSensitive:1;
153 unsigned ExactSize:1;
155 };
156
157 // Number of args.
158 static int Argc;
159
160 // The actual data.
161 enum {MAX_ARGC = 256};
162 static char *Argv[MAX_ARGC];
163};
164
165
166#endif
#define NULL
Definition BaseType.h:92
void const char * value
void Exact_Size(bool on)
Definition argv.h:139
static int Init(char *lpCmdLine, char *fileprefix="@")
Definition argv.cpp:162
unsigned Flags
Definition argv.h:150
static int Argc
Definition argv.h:158
static bool Load_File(const char *fname)
Definition argv.cpp:245
const char * Get_Cur_Value(unsigned prefixlen, bool *val_in_next=0)
Definition argv.cpp:346
int CurrentPos
Definition argv.h:144
void Case_Sensitive(bool on)
Definition argv.h:135
bool Is_Case_Sensitive()
Definition argv.h:136
void Update_Value(const char *attrib, const char *value)
Definition argv.cpp:401
unsigned CaseSensitive
Definition argv.h:152
static void Free()
Definition argv.cpp:300
const char * LastArg
Definition argv.h:147
const char * Find_Value(const char *arg)
Definition argv.cpp:322
const char * Cur()
Definition argv.h:127
const char * First()
Definition argv.h:109
static char * Argv[MAX_ARGC]
Definition argv.h:162
void Reset()
Definition argv.h:123
const char * Next()
Definition argv.h:115
@ MAX_ARGC
Definition argv.h:161
bool Is_Exact_Size()
Definition argv.h:140
bool Remove_Value(const char *attrib)
Definition argv.cpp:471
const char * Find(const char *arg)
Definition argv.h:79
void Add_Value(const char *attrib, const char *value=NULL)
Definition argv.cpp:437
const char * Find_Again(const char *arg=0L)
Definition argv.cpp:91
struct ArgvClass::@271206056367152314201013322120260056015256342073::@025354072163367077373121227120317343060251353273 Flag
ArgvClass(bool case_sensitive=false, bool exact_size=false)
Definition argv.cpp:68
unsigned ExactSize
Definition argv.h:153
~ArgvClass()
Definition argv.h:76