Declaration and Argument Syntax

A user function has the following C declaration syntax:

#include <sys/types.h>
 #include <stdlib.h>
 #include "tstone.h"
 #include "vortex.h"

char **
myfunc(arg1, arg2)
char    *arg1[];
char    *arg2[];
{
  char  **ret;

  /* ... do work with args ... */
  ret = (char **)NULL;   /* malloc value, or NULL for none */
  return(ret);
}

Each argument to a user function is passed as a NULL-terminated array of pointers to strings, from the corresponding Vortex argument variable. The user function must not modify any of its arguments in any way. After doing its work, the function returns a string list that will become the $ret variable's value. This return value is a malloc'd, NULL-terminated array of malloc'd strings. A function may also return just NULL to indicate an empty (no values) return value. The returned list is owned by Vortex and will be freed as necessary; no further reference to it is permitted.

User functions with zero to ten parameters are declared as above. If the function takes more than ten parameters, or a variable number of parameters, its arguments are given in an array:

char **
manyargfunc(argc, argv)
int     argc;
char    **argv[];
{
  /* ... */
}

The string array at argv[0] is the first argument; argv[1] is the second argument, etc. The argv[] array is NULL-terminated after the last argument, and contains argc arguments. Since variable-arg functions can have any number of arguments, it is important that they check the value of argc before indexing into the argv array, and not go past the end of it. Functions with a fixed number of arguments (first syntax) will be checked at script compile time to ensure they are always called with the right number of arguments.


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.