_export int
p4_AddOptions (p4_sessionP set, int argc, char* argv[])
{
int i, optc, flag;
char ** optv;
char *t, *val;
if (! argc) return 0;
if (argc && argv[0])
set->bootname = argv[0];
if (set->argc)
{
optv = malloc (sizeof(char*) * (set->argc + argc));
if (!optv) return 2;
memcpy (&optv[0], set->argv, sizeof(char*) * set->argc);
memcpy (&optv[set->argc], &argv[1], argc-1);
optv[set->argc + argc - 1] = 0;
if (set->heap.optv) free (set->optv);
set->optv = optv; set->heap.optv = 1;
optc = set->argc + argc - 1;
} | else{
optv = argv + 1; optc = argc - 1;
} |
for (i = set->argc; i < optc; i++)
{
register int l, k, s;
const char* p;
t = optv[i];
if (*t == '-') else { set->include_file = t; i++; break; } |
if (*t == '-') {
t++; if (*t == '-')
if (!*t) {
i++; if (i < optc) { set->include_file = optv[i]; i++; } |
break; } | ;
} |
k = l = strlen(t);
p = strchr(t, '=');
if (p)
s=0;
flag = 1;
if (k == l && t[k-1] == '-')
if (l >= 4 && !strcmp (t, "no-")) { t+=3; k-=3; flag ^= 1; val=t+k; } |
else if (k != l)
else if (i == optc - 1)
else { val = optv[i+1]; s=1; } |
switch (help_opt(t, k, help_options))
{
case 'V': fprintf (stdout, "%s\n", p4_version_string ());
return 1; continue;
case 'c': set->caps_on = flag; continue;
case 'C': set->upper_case_on = ! flag; continue;
case 'l': set->find_any_case = flag; continue;
case 'F': set->lower_case_fn = flag; continue;
case 'G': set->float_input = flag; continue;
case 'L': set->license = flag; continue;
case 'W': set->warranty = flag; continue;
case 'q': set->quiet = flag; continue;
case 'v': set->verbose = flag; continue;
case 'P': set->stdio = flag; continue;
case 'y': set->bye = flag; continue;
case '!': set->debug = flag; continue;
# define set__strvar_(VAR) \
if (set->heap.VAR) free ((void*) set->VAR); \
set->heap.VAR = 0; set->VAR
case 'B': set__strvar_(prefix) = val; i+=s; continue;
case 'e': set__strvar_(bootcommand) = val; i+=s; continue;
case 'k': set->total_size = atoi (val) << 10; i+=s; continue;
case 'p': set->pockets = atoi (val); i+=s; continue;
case 'r': set->ret_stack_size = atoi (val); i+=s; continue;
case 's': set->stack_size = atoi (val); i+=s; continue;
case 'f': set->max_files = atoi (val);
if (set->max_files < 4) set->max_files = 4;
i+=s; continue;
case 'T':
if (sscanf (val, "%dx%d", &set->cols, &set->rows) != 2)
set->cols = TEXT_COLS, set->rows = TEXT_ROWS;
i+=s; continue;
case 'I':
{
char* p;
static const char delimstr[2] = { PFE_PATH_DELIMITER, '\0' } | ;
p = malloc (strlen(set->incpaths) + 1 + strlen(val) + 1);
if (p) {
strcpy (p, set->incpaths);
strcat (p, delimstr);
strcat (p, val);
if (set->heap.incpaths) free ((void*) set->incpaths);
set->incpaths = p; set->heap.incpaths = 1;
} |
p = malloc (strlen(set->blkpaths) + 1 + strlen(val) + 1);
if (p) {
strcpy (p, set->blkpaths);
strcat (p, delimstr);
strcat (p, val);
if (set->heap.blkpaths) free ((void*) set->blkpaths);
set->blkpaths = p; set->heap.blkpaths = 1;
} |
i+=s; continue;
} |
# ifdef __move_cpus_code_to_forth_vm_init
case 'C':
{
register int cpus = atoi(val);
if (0 < cpus && cpus <= P4_MP_MAX) set->cpus = cpus;
else {
P4_fail2 ("cpus=%d invalid (max %d allowed)",
cpus, P4_MP_MAX);
} |
i+=s; continue;
} |
# endif
case '?': help_print (set, stdout); return 1; continue;
default:
{
p4char path [256];
if (k > 6 && !memcmp (t + k - 6, "-value", 6))
{
p4_change_option_value (t, k-6,
p4_convsize (val, 1),
set);
i += s;
} |
else if (k > 7 && !memcmp (t + k - 7, "-string", 7))
{
p4_change_option_string (t, k - 7, val, set);
i += s;
} |
else if (k > 5 && !memcmp (t + k - 5, "-path", 5))
{
int x;
memset (path, 0, 256);
strncpy (path,
p4_search_option_string (t, k, "", set),
255);
if ((x = strlen(path)))
{ path[x] = PFE_PATH_DELIMITER; path[x+1] = '\0'; } |
strncat (path, val, 255);
p4_change_option_string (t, k, path, set);
i += s;
} |
else if (k > 5 && !memcmp (t + k - 5, "-file", 5))
{
p4_change_option_string (t, k, val, set);
i += s;
} |
else if (k > 6 && !memcmp (t + k - 6, "-image", 6))
{
p4_change_option_string (t, k, val, set);
i += s;
} |
else if (k > 8 && !memcmp (t + k - 8, "-command", 8))
{
p4_change_option_string (t, k, val, set);
i += s;
} |
else if (k > 6 && !memcmp (t + k - 6, "-cells", 6))
{
p4_change_option_value (t, k,
p4_convsize (val, 1),
set);
i += s;
} |
else if (k > 5 && !memcmp (t + k - 5, "-base", 5))
{
p4_change_option_value (t, k,
p4_convsize (val, 1),
set);
i += s;
} |
else if (k > 5 && !memcmp (t + k - 5, "-size", 5))
{
path[0] = '/'; memcpy (path+1, t, k - 5);
p4_change_option_value (path, k-4,
p4_convsize (val, 1),
set);
i += s;
} |
else if (k > 5 && !memcmp (t + k - 5, "-name", 5))
{
path[0] = '$'; memcpy (path+1, t, k - 5);
p4_change_option_string (path, k-4, val, set);
i += s;
} |
else if (k > 4 && !memcmp (t , "max-", 4))
{
path[0] = '#'; memcpy (path+1, t + 4, k - 4);
p4_change_option_value (path, k-3,
p4_convsize (val, 1),
set);
i += s;
} |
else if (k > 4 && !memcmp (t + k - 4, "-off", 4))
{
flag ^= 1;
p4_change_option_value (t, k - 4, flag, set);
} |
else if (k > 3 && !memcmp (t + k - 3, "-on", 3))
{
p4_change_option_value (t, k - 3, flag, set);
} |
else
{
help_print (set, stderr); return 2;
} |
continue;
} |
} |
} |
set->argv = &optv[i];
set->argc = optc - i;
return 0;
} |
|