home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
-
- This useful hint is simply a function that looks for command line parameters
- passed to the program.
-
- The idea is that the parameter should be preceeded with an identifying
- character sequence, (refered to as the switch), that begins with either a
- dash, '-', or a forward slash, '/'.
-
- The search for the "switch is not case sensitive.
-
- If the parameter to be passed needs to have embedded spaces then the command
- line parameter should have the spaces replaced with ASCII character 254, '■'.
- This little block character can be produced by holding down the <Alt> key and
- typing the '2', then the '5' and finally the '4' numbers from the numeric
- keypad then releasing the <Alt> key, (on some older computers it may
- necessary to hold down the <Shift> key as well as the <Alt> key).
-
- If you were to run a program with command line parameters like this:--
-
- MYREP -DIVSIZ -STATEQLD -CRITC
-
- Then in the program, (with respect to DataBoss in the default values for the
- report filter variables), you could get :--
-
- Function call Return String
- ----------------------------- -------------
- lookForSwitch(_tts,"-DIV',"***") SIZ
- lookForSwitch(_tts,"-STATE","***") QLD
- lookForSwitch(_tts,"-CRIT","C") C
-
- ****************************************************************************)
-
-
-
- strptr lookForSwitch(strptr sout, strptr theSwitch, strptr thedefault)
- /***************************************************************************/
- /* This function searches for command line parameters. */
- /* */
- /* Note: If "theSwitch" is not found then "thedefault" will be returned. */
- /* */
- /* Note: "theSwitch" characters will be removed from the string returned. */
- /* */
- /* Note: The return string length will be padded/truncated to match the */
- /* length of "thedefault". */
- /***************************************************************************/
- {
- int i, len;
- bool foundIt;
- string ts;
-
- foundIt = False;
- len = strlen(theSwitch);
- upper(theSwitch,theSwitch);
- i = 1;
- while (!foundIt && (i <= paramcount())) {
- strcpy(ts,paramstr(i));
- upper(ts,ts);
- if ((ts[0] == '-') || (ts[0] == '/')) {
- ts[1] = theSwitch[1];
- foundIt = (strsearch(ts,theSwitch) == ts);
- if (foundIt) strcopy(ts,ts,len, strlen(ts)-len);
- }
- i++;
- }
- if (!foundIt)
- strcpy(sout,thedefault);
- else {
- for (i=0; i < strlen(ts); i++) {
- if (ts[i] == 254) ts[i] = ' '; /* character 254 == '■' */
- }
- len = strlen(thedefault);
- strcopy(sout,pad(ts,ts,len,Right),0,len);
- }
- return(sout);
- }
-