home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / msh21.zip / TOOLKIT.ZIP / MSH.H < prev    next >
C/C++ Source or Header  |  1992-07-29  |  3KB  |  61 lines

  1. /* below are the necessary declarations for people who want to define their
  2. own actions. The basic type on the MSH stack is a refobj, i.e. a pointer to an
  3. obj. An obj is basically a character string, excepted a reference count has
  4. been added for efficiency of memory management. All values (including numeric
  5. values) are represented as character strings.
  6.    The routines Free and Push take care of management of that reference count,
  7. so to manage it you only have to call them, mimicking the examples given
  8. in userdefs.c */
  9.  
  10. #define OVERHEAD 10
  11. typedef struct{int rc;char val[OVERHEAD];}obj;
  12. /* actually val is any length: 10+sizeof(int)=12 which is the smallest size
  13.    which may be allocated in BC's compact model */
  14. typedef obj *refobj;
  15.  
  16. typedef enum{FALSE,TRUE} bool;
  17.  
  18. #define ERROR_ 0x1
  19. #define WARNING_ 0x2
  20. #define FILE_ 0x20
  21. extern void (cdecl *efns)(int /* errcode */,char *,...);
  22. /* This is the function to call to signal an error. The arguments from the
  23.    second onwards are the same as in the printf family of functions, which
  24.    gives you a lot of flexibility in building your error message.
  25.    The default value given to efns is a function which pops a window for
  26.    errcode=WARNING_ and aborts MSH for ERROR_ .
  27.    You can define your own function and assign a pointer to it to efns:
  28.    then your function will get called in case of any error */
  29.  
  30.  
  31. void _fastcall Free(refobj s);
  32.  
  33. void _fastcall Push(refobj s);
  34. refobj _fastcall Pop(void);
  35.  
  36. void _fastcall Pushstring(char *s); /* makes a refobj from s and Pushes it */
  37.  
  38. void _fastcall Pushlong(long l); /* Pushes a refobj holding the long's representation */
  39. long _fastcall Poplong(void);    /* Pops one refobj, Frees it; returns the long it held */
  40.  
  41. void _fastcall Pushbool(bool b); /* same as Pushstring(b?"true":"") ; saves mallocs
  42.               as it uses pre-allocated strings */
  43. bool _fastcall Popbool(void);    /* returns FALSE for "" and TRUE for any other string */
  44.  
  45. /* The basic template for an action which pops 2 things and pushes one is:
  46.  
  47.     void foo(void)
  48.     { refobj a1=Pop(),a2=Pop(),res;
  49.       ... do your stuff, using a1->val and a2->val and
  50.           building res along the way ...
  51.       Push(res);Free(a1);Free(a2);
  52.     }
  53.  
  54. The functions Pushstring, Pushlong, Poplong, Pushbool, Popbool take care of
  55. much of the details of management.
  56. */
  57.  
  58. void _fastcall testalloc(void *w);
  59. /* a routine which tests the result of malloc;
  60.                             see example of use in userdefs.c */
  61.