home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rximc175.zip / functions.h < prev    next >
Text File  |  2002-08-06  |  18KB  |  231 lines

  1. /* The functions of REXX/imc            This is a 132 column file            (C) Ian Collier 1992 */
  2.  
  3. #ifndef _functions_h
  4. #define _functions_h
  5.  
  6. #ifdef __STDC__     /* define Args macro so that the arguments of each */
  7. #define Args(a) a   /* function can be stated without confusing the */
  8. #else               /* compiler */
  9. #define Args(a) ()
  10. #define volatile    /* Ignore "volatile" for traditional C compiler */
  11. #endif
  12.  
  13. /* Protection against things not having been included... */
  14. #ifndef putchar
  15. #include<stdio.h>
  16. #endif
  17. #ifndef Einit
  18. #include"const.h"
  19. #endif
  20.  
  21.  
  22. #ifdef DEBUG /* Debugging mtest routines */
  23. int mtest_debug Args((char **memptr,unsigned *alloc,unsigned length,unsigned extend,long *diff));
  24. #define mtest(memptr,alloc,length,extend) (mtest_debug(&memptr,&alloc,length,extend,(long *)0))
  25. #define dtest(memptr,alloc,length,extend) (mtest_debug(&memptr,&alloc,length,extend,&mtest_diff))
  26. #else /* not defined DEBUG */
  27. /* Usually the mem test routines use inline code for greater efficiency.
  28.    mtest: reallocate an area only if it is too small
  29.    dtest: the same, but also return 1 if the area moved and set mtest_diff to
  30.           the difference
  31.    Recently fixed to save the old value when realloc fails
  32. */
  33. #define mtest(memptr,alloc,length,extend) {char *old;         \
  34.         (alloc<(length))&&(                                   \
  35.         old=memptr,                                           \
  36.         (memptr=realloc(memptr,(unsigned)(alloc+=(extend))))||(memptr=old,alloc-=(extend),die(Emem),1)  \
  37.         );}
  38. #define dtest(memptr,alloc,length,extend) (                   \
  39.         (alloc<(length))&&(                                   \
  40.         mtest_old=memptr,                                     \
  41.         (memptr=realloc(memptr,(unsigned)(alloc+=(extend))))||(memptr=mtest_old,alloc-=(extend),die(Emem),1), \
  42.         mtest_diff=memptr-mtest_old ))                      
  43. #endif /* DEBUG */
  44.  
  45. #define whattype(c)      (types[(unsigned char)(c)])
  46. #define alphanum(c)      (alphs[(unsigned char)(c)])
  47. #define rexxsymboldot(c) (whattype(c)>0)
  48. #define rexxsymbol(c)    (symbs[(unsigned char)(c)])
  49.  
  50. #ifdef NO_LDL                                                                   /* Declare the dynamic load functions */
  51. void *dlopen Args((char*,int));                                                 /* either in situ or from the system header file */
  52. void *dlsym Args((void *,char*));
  53. char *dlerror Args((void));
  54. int dlclose Args((void*));
  55. #else
  56. #include<dlfcn.h>
  57. #endif /* NO_LDL */
  58.  
  59. /* In ANSI C, you can take the address of any object and the result is of type pointer to that object.  In K&R C, this
  60.    fails when the object is an array.  The following kludge takes the address of a jmp_buf, which is likely to be an
  61.    array.  On systems where it isn't, this macro has to be changed... */
  62. #ifdef __STDC__
  63. #define addressof(x) (&(x))
  64. #else
  65. #define addressof(x) ((jmp_buf*)(x))
  66. #endif
  67.  
  68. #ifdef __hpux /* HP-UX doesn't have srandom, random or siginterrupt */
  69. #define srandom srand48
  70. #define random lrand48
  71. #define siginterrupt(arg1,arg2) (0)
  72. #endif
  73.  
  74. #ifdef sgi /* IRIX doesn't have siginterrupt or vfork */
  75. #define siginterrupt(arg1,arg2) (0)
  76. #define vfork fork
  77. #endif
  78.  
  79. #ifdef Solaris /* Solaris doesn't have siginterrupt */
  80. #define siginterrupt(arg1,arg2) (0)
  81. #endif
  82.  
  83. #if (defined(sun) || defined(__sun__)) && !defined(Solaris) /* SunOS4 does not provide strerror */
  84.   extern int errno;
  85.   extern int sys_nerr;
  86.   extern char *sys_errlist[];
  87. # define strerror(x) ((x)>=0 && (x)<sys_nerr ? sys_errlist[x] : (char*)NULL)
  88.   /* SunOS 4 is the only system to recommend getwd above getcwd. */
  89. # define getcwd(name,len) getwd(name)
  90. #endif
  91.  
  92. #ifdef RENAME_UNDELETE /* FreeBSD has undelete() defined in unistd.h so REXX/imc's will be renamed */
  93. # define undelete rx_undelete
  94. #endif
  95.  
  96. /* in rexx.c */
  97. int main Args((int argc, char *argv[]));
  98. char *allocm Args((unsigned size));
  99. void die Args((int rc));
  100. char *interpreter Args((int *anslen,int start,                                  /* Interpret program lines */
  101.                         char *callname,long calltype,char *args[],int arglen[],int inherit,int delay));
  102. static void doaddress Args((char **line,int env));                              /* Address a command to an environment */
  103. static void parse Args((char *list[],int len[],int up,char *line,int *ptr));    /* PARSE strings with a template */
  104. static char uc1 Args((int c,int up));                                           /* Uppercase c, if up */
  105. static void pset1 Args((char *list,int listlen,char *val,int len,int up));      /* Tokenise a string into variables */
  106. static void pset Args((char *varname,int namelen,char *val,int len,int up));    /* Assign a PARSE result to a variable */
  107. static int findsigl Args((int *level));                                         /* Find most recent line number */
  108. static void getcallargs Args((char *args[],int arglen[],int argc));             /* Unstack parameters in a CALL instruc */
  109. int rxcall Args((int stmt,char *name,int argc,int lit,long calltype));          /* Call a procedure */
  110. char *rxinterp Args((char *exp,int len,int *rlen,char *name,long calltype,      /* INTERPRET a string */
  111.                      char *args[],int arglen[]));
  112. static void doconds Args((void));                                               /* Check for delayed conditions and trap them */
  113. void settrace Args((char *));                                                   /* Set trace according to the given option */
  114. int setoption Args((char *option,int len));                                     /* Set an option from the OPTIONS instruction */
  115. static int gettrap Args((char **lineptr,int on,int *stmt));                     /* Get a trap name after "call/signal on" */
  116. static void testvarname Args((char **line,char *var,int len));                  /* Test the symbol against a stored name */
  117. static void skipstmt Args((void));                                              /* Skip the current instruction */
  118. static void stepdo Args((void));                                                /* Step past the current DO */
  119. static void stepselect Args((void));                                            /* Step past the current SELECT */
  120. static void stepif Args((void));                                                /* Step past the current IF */
  121. static void stepwhen Args((void));                                              /* Step past the current WHEN */
  122. static void findend Args((void));                                               /* Find the next END */
  123. void on_halt Args((void));                                                      /* Find the line number at which halt occurred */
  124.  
  125. /* in calc.c */
  126.  
  127. char *scanning Args((char *line,int *ptr,int *len));                            /* Evaluate an expression */
  128. void tracelast Args((char *type));                                              /* Trace the last value on the stack */
  129. void traceline Args((char *type,char *exp,int len));                            /* Trace any string */
  130. void stack Args((char *exp,int len));                                           /* Stack a string literally */
  131. void stackq Args((char *exp,int len,int quote));                                /* Stack a string, collapsing quotes */
  132. void stackx Args((char *exp,int len));                                          /* Stack a hex constant */
  133. void stackb Args((char *exp,int len));                                          /* Stack a binary constant */
  134. void stackint Args((int i));                                                    /* Stack an integer */
  135. void stacknull Args((void));                                                    /* Stack a null parameter */
  136. void binplus Args((int op));                                                    /* Add the last two values */
  137. void binmin Args((int op));                                                     /* Subtract the last value from the previous */
  138. void binmul Args((int op));                                                     /* Multiply the last two values */
  139. void bindiv Args((int op));                                                     /* Divide the previous value by the last */
  140. void binexp Args((int op));                                                     /* Raise the previous value to the last-th power */
  141. void rxdup Args((void));                                                        /* Duplicate the last value */
  142. void binrel Args((int op));                                                     /* Compare the last two values */
  143. void binbool Args((int op));                                                    /* Combine the last two logical values */
  144. void bincat Args((int op));                                                     /* Concatenate the last two values */
  145. void unnot Args((int op));                                                      /* Negate logically the last value */
  146. void unmin Args((int op));                                                      /* Negate arithmetically the last value */
  147. void unplus Args((int op));                                                     /* Reformat the last numeric value */
  148. void strip Args((void));                                                        /* Strip surrounding space from the last value */
  149. int num Args((int *minus,int *exp,int *zero,int *len));                         /* Get the last value as a number */
  150. int getint Args((int flg));                                                     /* Get the last value as an integer */
  151. int isint Args((int num,int len,int exp));                                      /* Is the last value an integer? */
  152. char *delete Args((int *len));                                                  /* Delete and return the last value */
  153. int isnull Args((void));                                                        /* Is the last value null? */
  154. void stacknum Args((char *num,int len,int exp,int minus));                      /* Stack a number */
  155. void getvarname Args((char *line,int *ptr,char *varname,int *namelen,int maxlen)); /* Get a symbol from a program line */
  156. void skipvarname Args((char *line,int *ptr));                                   /* Skip a symbol in a program line */
  157. int gettoken Args((char *line,int *ptr,char *varname,int maxlen,int ex));       /* Get a token from a program line */
  158.  
  159. /* in util.c */
  160. char *message Args((int rc));                                                       /* Return an error message string */
  161. void rcset Args((int i,int type,char *desc));                                       /* Set the variable rc to the given value */
  162. void rcstringset Args((int rc,char *rcval, int rclen,int type,char *desc));         /* Set the variable rc to the given string */
  163. void printrc Args((int i));                                                         /* Print a return code */
  164. int exitcall (/*(long main, long sub, PEXIT parm)*/);                               /* call an exit */
  165. char *varsearch Args((char *name,int len,int *level,int *exist));                   /* Search for a simple symbol or stem */
  166. char *tailsearch Args((char *stem,char *name,int len,int *exist));                  /* Search for a tail within a stem */
  167. char *valuesearch Args((char *name,int namelen,int *level,int *exist,char **stem)); /* Search for any variable */
  168. void printtree Args((int lev));                                                     /* Print the entire variable table */
  169. void update Args((int value,int amount,int level));                                 /* Update the pointers for a variable level */
  170. void varcreate Args((char *varptr,char *name,char *value,int namelen,int len,int lev));/* Create a simple symbol */
  171. void stemcreate Args((char *varptr,char *name,char *value,int namelen,int len,int lev));/* Create a stem */
  172. void tailcreate Args((char *stem,char *tailptr,char *name,char *value,int namelen,int len,int level));/* Create a tail in a stem */
  173. void varset Args((char *name,int varlen,char *value,int len));                      /* Assign any value to any variable */
  174. char *varget Args((char *name,int varlen,int *len));                                /* Get any variable's value */
  175. void newlevel Args((void));                                                         /* Make a new level in the variable table */
  176. void varcopy Args((char *name,int varlen));                                         /* Expose a variable from the previous level */
  177. void vardup Args((void));                                                           /* Duplicate the entire variables level */
  178. void vardel Args((char *name,int len));                                             /* Remove one of the duplicate variables */
  179. char uc Args((int c));                                                              /* Uppercase a character */
  180. void *pstack Args((int type,int len));                                              /* Make a new program stack entry */
  181. int unpstack Args((void));                                                          /* Examine the top program stack entry */
  182. void *delpstack Args((void));                                                       /* Delete and return the top p-stack entry */
  183. int strcmpi Args((char *s1,char *s2));                                              /* Is s1 an initial substring of s2? */
  184. void printstmt Args((int stmt,int after,int error));                                /* Print a source statement */
  185. void freestack Args((void *ptr,int i));                                             /* Clean up after deleting a p-stack entry */
  186. void traceput Args((char *str,int len));                                            /* Print a counted string of trace output */
  187. void tracestr Args((char *str));                                                    /* Print a string of trace output */
  188. void tracechar Args((int ch));                                                      /* Print a character of trace output */
  189. void tracenum Args((int num,int len));                                              /* Print a number to trace output */
  190. void traceprefix Args((int num, char*prefix));                                      /* Print a number and 3-character prefix */
  191. void interactive Args((void));                                                      /* Pause execution, if in interactive trace */
  192. void tokenise Args((char *input,int ilen,int dolabels,int line1));                  /* Preprocess source code */
  193. char *load Args((char *name,int *sourcelen));                                       /* Load a program from disk */
  194. void process Args((int c));                                                         /* Tokenise characters */
  195. void expand Args((int c));                                                          /* Expand a token */
  196. void display Args((int line,int ptr));                                              /* Display a program line */
  197. char *rexxext Args((void));                                                         /* Return the default filetype */
  198. int which Args((char *gn,int opt,char *fn));                                        /* Search for a program or subroutine */
  199. char *hashsearch Args((int hash,char *name,int *exist));                            /* Search for a hash table entry */
  200. void *hashget Args((int hash,char *name,int *exist));                               /* Return the value associated with a key */
  201. void **hashfind Args((int hash,char *name,int *exist));                             /* Return a pointer to a key's value element */
  202. struct fileinfo *fileinit Args((char *name,char *filename,FILE *fp));               /* Store an open file's details */
  203. void funcinit Args((char *name,void *handle,int (*address)(),int saa));             /* Store an external function's details */
  204. void libsearch Args((void));                                                        /* Ssearch for *.rxlib files */
  205. int fileclose Args((char *name));                                                   /* Free a file's hash table entry */
  206.  
  207. /* in rxfn.c */
  208. int rxfn Args((char *name,int argc));                                               /* Try to call a builtin function */
  209. int rxseterr Args((struct fileinfo *f));                                 /* Set rc to indicate a file's status */
  210. char *undelete Args((int *l));                                                      /* Get last value without deleting it */
  211.  
  212. /* in shell.c */
  213. int shell Args((char *command));                                                    /* Interpret a shell command */
  214. void hashclear Args((void));                                                        /* Clear the shell's hashed path table */
  215.  
  216. /* in interface.c */
  217. void envinit Args((void));                                                          /* Initialise the environment table */
  218. int envsearch Args((char *name));                                                   /* Search for an environment name */
  219. int envcall Args((int num,char *cmd, int len, char **ans, int *anslen));            /* call an environment */
  220. int funccall Args((unsigned long (*func)(),char *name,int argc));                   /* call a function by SAA calling sequence */
  221. int unixcall Args((char *name,char *callname,int argc));                            /* call a function by Unix calling sequence */
  222. void hashfree Args((void));                                                         /* Free all memory used by hash tables */
  223. static void halt_handler();                                                         /* handle halt signals */
  224. static void pipe_handler();                                                         /* handle broken pipe signals */
  225. static void error_handler();                                                        /* handle error signals */
  226. static void sigtrace();                                                             /* Go into trace mode, or exit */
  227.  
  228. #undef Args
  229.  
  230. #endif /* !_functions_h */
  231.