tail_get_option()

Purpose

Reads DP4-style command tails with arguments

Old name

#define _tail_opt(option,get_value)
tail_get_option(option,get_value!=0)

Syntax

char* tail_get_option(option, flags)

Parameters

char* option

Zero-terminated name to extract from command line

 

int flags

Indicate how to treat the command tail if found

Description

The tail_get_option() function is used to read the command line passed to the program. It recognises DP4 command tails which begin with the minus (-) character. When the command tail has to pass an argument, specify a non-zero flag, for example:

dbname = tail_get_option("DB", 2);

This returns a pointer to the argument following -DB, in this case, the database name. Because flags is even, the argument is not converted to upper case. If flags is odd, the returned argument is converted to upper case. The predefined flags TAIL_UCASE and TAIL_NOUCASE can be used as well.

The parameter option is not case sensitive, and must not contain the negative sign.

(int) tail_get_option(option,0)

is equivalent to:

tail_found(option).

Whatever the flags, if the command tail is present, it is removed from the command line, so subsequent calls to the function tail_get_option() with the same parameters will fail, unless multiple copies have been passed.

Return values

Returns non-zero if command tail found

Example

/*
C Functions Reference Manual
----------------------------
Filename: TAIL_GET.C
Example: tail_get_option and tail_read
Purpose: Simple example illustrates reading a few
tails*/

/*
#db salesord
#c
#end
*/
#include "dp4.h"
#include "tail_get.h"
/* generate this file by running LIBMAKE */
char comm_cust[16];
char comm_reg[16];
void process()
{
char* p;
map_draw(1,RETAIN);
/* check for help command tail*/
if (tail_get_option("HELP",FALSE))
{
map_datamap(100);
field_help(100,1,HT_PAUSE);
}
if ((p = tail_get_option("CUSTOMER",2)) != 0)
{
WIPE(comm_cust);
memcpy(comm_cust,p,min(strlen(p),
sizeof(comm_cust)));
/* show customer passed */
map_datamap(2);
show_c(2,1,comm_cust);
askf_special(2,2,0);
map_clear_from(2);
}
if ((p = tail_get_option("REGION",TRUE)) != 0)
{
WIPE(comm_reg);
memcpy(comm_reg,p,min(strlen(p),
sizeof(comm_reg)));
/* show region passed */
map_datamap(3);
show_c(3,1,comm_reg);
askf_special(3,2,0);
map_clear_from(3);
}
/* there shouldn't be any other tails */
if ((p = tail_read(TAIL_NOUCASE)) != 0)
{
map_datamap(4);
show_c(4,1,p);
askf_special(4,2,0);
return;
}
}