SL_ParseArg -- parses argc,argv into an array via a template.

success = SL_ParseArg(apphandle, argc, argv, array, template);
D0 A0 D0 A1 A2 A3


This function parses an argc,argv combination via a templated into an
array of SLTAGDATAs. The input argv array need not be in the same order as
the template. The function first places all keyworded args and then goes
back and fills in all non-keyworded args.

The array is not modified for entries that are not in argv. This enables
the programmer to create defaults for entries that are optional by
filling in the array with the defaults then making the call. Any args
that were specified would override the defaults, the others would be left

The template is made up of the keywords followed by the argument
specifiers for that keyword. Keywords are separated from their argument
specifiers by either a forward slash (/) or a plus sign (+). A forward
slash indictaes the keyword is optional. A plus sign indictaes the keyword
is required. Each keyword "group" is separated by a comma.

The valid argument specifiers are:
S - string, 9 - number, B - boolean (true,false, yes,no, on,off).

For example, a template might contain: "NAME/S,SIZE/99,REDRAW/B".
If given the following argv array:

argv[] = {"name", "cheetah", "redraw", "true", "size", "320", "200"};

the resulting array would contain:

SLTAGDATA array[4] = {"cheetah", 320, 200, TRUE};

Note the 9 args are converted to their numeric value and the B args are
turned into TRUE (1) or FALSE (0).

apphandle - as returned by SL_AppInitA.
argc - the number of entries in the argv array.
argv - the argument array.
array - the array to hold the parsed values.
template - the template used to parse argv into array.

success - TRUE if argv could be parsed into array.
FALSE - This function may fail if it cannot obtain memory to
hold the temporary buffers it needs.

CALLBACK SLFLAG macro_close(UWORD argc, SLCHAR **argv)
struct proj *p;
SLTAGDATA array[3]={0,1,0};

if(SL_ParseArg(apphandle, argc, argv, array, "NAME/S,ASK,FORCE"))
//default to the current project
p = curproj;

//was a name given?
//yes, so use it to find the project to close

1. SLCHAR *)array[0]);<br>}</p> <p>//force a close?<br>if(!array[2])<br>{<br>//no, so has it changed?<br>if(p-&gt;flags&amp;PRJFLG_MODIFIED)<br>{<br>//yes, so ask the user if they really want to close it<br>......<br>}<br>}<br>return(closeproj(p


SL_ParseArg  Command Section By Type  url:SL_ParseArg
  created:2008-03-01 23:36:35   last updated:2008-03-01 23:36:35
  Copyright © 1985-2021 GrasshopperLLC. All Rights Reserved.

User Contributed Comments For SL_ParseArg
There are no user contributed comments for this page.