On Sunday 07 April 2013, TianMing wrote:
> hi,Hans
> let's talk about the cell exec_4th (Hcode *Object, unsigned ArgN, char
> **ArgS, unsigned VarN, …)
>
> I almost see the function arguments in c program just in two , and the
> exec_4th has 4 arguments and the optional argument,can you tell me the
> meaning of each arg? 在 2013-4-7,下午3:33,Hans Bezemer <
the...@xs4all.nl> 写道:
1. The "Object" is just what comp_4th() or load_4th() returns. That's easy.
2. ArgN and ArgS are the 4tH equivalent of argc and argv. Does that ring a
bell? E.g.
char *(Args [MAXARGS]); /* interface to ExecuteCommands() */
This is pretty much *argv[] or **argv! Now this breaks up a string to
pointers:
case ('a'): PromptFor ("Arguments: ", CmdLine, sizeof (CmdLine));
for (space = TRUE, Argn = 1, x = 0;
(Argn < MAXARGS - 1) && (CmdLine [x] != '\0'); x++)
{ /* max 14 args, scan till end of cmd */
if (CmdLine [x] == ' ')
{ /* if space, terminate and signal */
CmdLine [x] = '\0';
space = TRUE;
}
else /* if it is a character, test for */
{ /* previous space and assign */
if (space == TRUE) Args [Argn++] = CmdLine + x;
space = FALSE;
} /* signal this was not a space */
} /* terminate argument list */
Args [Argn] = NULL; break;
The resulting Argn and **Args are passed to this one:
/*
This routine executes an object. It flushes stderr and stdout since
that may cause garbled output on some platforms.
*/
#ifndef ARCHAIC
void Execute4tH (int argn, char **args)
#else
void Execute4tH (argn, args) int argn; char **args;
#endif
{
cell Result; /* holds the result from the program */
fflush (stderr); /* prevent garbled output */
Result = exec_4th (Object, argn, args, 0);
fflush (stdout); /* execute the object */
Msg4tH ("Executing;");
if (Result != CELL_MIN) ErrMsg (MRESULT, "Executing;", Result);
} /* show only significant results */
And there you see them pop up as argn and args. In other words, This:
This is a line of arguments
Is broken up in:
This (1)
is (2)
a (3)
line (4)
of (5)
arguments (6)
Passed as Argn=6 and Args, so in 4tH:
argn 0 ?do i args type cr loop
Shows:
This
is
a
line
of
arguments
3. VarN shows the number of integers you're passing to 4tH:
e.g.
exec_4th (Object, 0, NULL, 3, 6, 18, 24);
6, 18 and 24 are 3 integers (hence: 3). These are passed to 4tH so:
app 0 th ?
app 1 th ?
app 2 th ?
Shows 6, 18 and 24.