home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / online / source / c / compilers / C_Interp.sit.hqx / C_Interp / Script.c < prev    next >
Text File  |  1993-05-14  |  4KB  |  158 lines

  1. /*
  2.     Terminal 2.2
  3.     "Script.c"
  4. */
  5.  
  6. #include "Compatibility.h"
  7. #include "Interp.h"
  8. #include "File.h"
  9. #include "FormatStr.h"
  10. /*#include "PubTools.h"*/
  11.  
  12. /* ----- beep() -------------------------------------------------------- */
  13.  
  14. static INTEGER SI_beep(INTEGER params[])
  15. {
  16. #pragma unused(params)
  17.     Sys_Beep(1);
  18.     return 0;
  19. }
  20.  
  21.  
  22. /* ----- string = new(size) -------------------------------------------- */
  23.  
  24. static INTEGER SI_new(INTEGER params[])
  25. {
  26.     return (INTEGER)malloc(params[0]);
  27. }
  28.  
  29. /* ----- free(string) -------------------------------------------------- */
  30.  
  31. static INTEGER SI_free(INTEGER params[])
  32. {
  33.     free((char *)params[0]);
  34.     return 0;
  35. }
  36.  
  37. /* ----- result = strcat(s1, s2) --------------------------------------- */
  38.  
  39. static INTEGER SI_strcat(INTEGER params[])
  40. {
  41.     register Byte *s1 = (Byte *)params[0];
  42.     register Byte *s2 = (Byte *)params[1];
  43.     
  44.     strcat((char *) s1, (char *) s2);
  45.     return (INTEGER) s1;
  46. }
  47.  
  48. /* ----- result = strcmp(s1, s2) --------------------------------------- */
  49.  
  50. static INTEGER SI_strcmp(INTEGER params[])
  51. {
  52.     register Byte *s1 = (Byte *)params[0];
  53.     register Byte *s2 = (Byte *)params[1];
  54.  
  55.     while (tolower(*s1) == tolower(*s2)) {
  56.         if (!*s1)
  57.             break;
  58.         s1++;
  59.         s2++;
  60.     }
  61.     return (INTEGER)(tolower(*s1) - tolower(*s2));
  62. }
  63.  
  64. /* ----- result = strcpy(s1, s2) --------------------------------------- */
  65.  
  66. static INTEGER SI_strcpy(INTEGER params[])
  67. {
  68.     register Byte *s1 = (Byte *)params[0];
  69.     register Byte *s2 = (Byte *)params[1];
  70.  
  71.     strcpy((char *) s1, (char *) s2);
  72.     return (INTEGER) s1;
  73. }
  74.  
  75. /* ----- puts(s1) --------------------------------------- */
  76.  
  77. static INTEGER SI_puts(INTEGER params[])
  78. {
  79.     register Byte *s1 = (Byte *)params[0];
  80.     puts((char *) s1);
  81.     return 0;
  82. }
  83.  
  84. /* ----- i = val(str) -------------------------------------------------- */
  85.  
  86. static INTEGER SI_val(INTEGER params[])    /* Convert string to integer */
  87. {
  88.     return atoi((char *) params[0]);
  89. }
  90.  
  91. /* ----- str = itoa(i) -------------------------------------------------- */
  92.  
  93. static INTEGER SI_itoa(INTEGER params[])    /* Convert string to integer */
  94. {
  95. static char s[256];
  96.     sprintf(s, "%ld", params[0]);
  97.     return (INTEGER) s;
  98. }
  99.  
  100. /* ----- result = display(template, ...) ------------------------------- */
  101.  
  102. static INTEGER SI_display(INTEGER params[])
  103. {
  104.     register INTEGER result;
  105.     Byte s[256];
  106.  
  107.     if (params[0]) {
  108.         SFormatStr(s, (Byte *)params[0], ¶ms[1]);
  109.         result = Display(s);
  110.     } else {            /* No formatting */
  111.         result = Display((Byte *)params[1]);
  112.     }
  113.     return result;
  114. }
  115.  
  116. /* ----- format(string, template, ...) --------------------------------- */
  117.  
  118. static INTEGER SI_format(INTEGER params[])
  119. {
  120.     SFormatStr((Byte *)params[0], (Byte *)params[1], ¶ms[2]);
  121.     return 0;
  122. }
  123.  
  124. /* ----- view(string) --------------------------------- */
  125.  
  126. /*static INTEGER SI_view(INTEGER params[])*/
  127. /*{*/
  128. /*PubTypePtr p;*/
  129. /*INTEGER ret;*/
  130. /*    if (!PubGet(&p, "\0", (char *) params[0])) {*/
  131. /*        ret = PubView(p);*/
  132. /*        free (p);*/
  133. /*        return ret;*/
  134. /*    }*/
  135. /*    else return PE_PUBINFO_NOT_FOUND;*/
  136. /*}*/
  137.  
  138. /* ----- Script intrinsic functions ------------------------------------ */
  139.  
  140. INTRINSIC Intrinsics[] = {
  141.     (Byte *)"beep",        SI_beep,
  142.     (Byte *)"display",    SI_display,
  143.     (Byte *)"format",    SI_format,
  144.     (Byte *)"printf",    SI_display,
  145.     (Byte *)"sprintf",    SI_format,
  146.     (Byte *)"free",        SI_free,
  147.     (Byte *)"itoa",        SI_itoa,
  148.     (Byte *)"new",        SI_new,
  149.     (Byte *)"puts",        SI_puts,
  150.     (Byte *)"stack",    SI_stack,        /* Defined in Interp.c */
  151.     (Byte *)"strcat",    SI_strcat,
  152.     (Byte *)"strcmp",    SI_strcmp,
  153.     (Byte *)"strcpy",    SI_strcpy,
  154.     (Byte *)"val",        SI_val,
  155. /*    (Byte *)"view",        SI_view,*/
  156.     0,            0
  157. };
  158.