home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / logo / part01 / unix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-23  |  3.9 KB  |  273 lines

  1.  
  2. #include "logo.h"
  3. #include <setjmp.h>
  4. #include <signal.h>
  5.  
  6. char *ostring;
  7. FILE *ofile;
  8. #ifdef DEBUG
  9. int memtrace=0;
  10. extern int yydebug;
  11. #endif
  12.  
  13. #ifdef PAUSE
  14.  
  15. int errpause=0;
  16.  
  17. seterrpause() {
  18.     errpause++;
  19. }
  20.  
  21. clrerrpause() {
  22.     errpause = 0;
  23. }
  24. #endif
  25.  
  26. struct object *stringform(arg)
  27. register struct object *arg;
  28. {
  29.     char str[IBUFSIZ];
  30.     struct object *bigsave();
  31. #ifdef DEBUG
  32.     int omemt;
  33.  
  34.     omemt = memtrace;
  35.     memtrace = 0;
  36. #endif
  37.     ostring = &str[0];
  38.     str[0] = '\0';    /* in case of empty */
  39.     tyobj(arg);
  40.     ostring = 0;
  41. #ifdef DEBUG
  42.     memtrace = omemt;
  43. #endif
  44.     return (bigsave(str));
  45. }
  46.  
  47. putch(ch)
  48. register ch;
  49. {
  50.     if (ch != -1) {
  51.         putchar(ch);
  52.     }
  53.     return (ch);
  54. }
  55.  
  56. /* VARARGS */
  57. char *cpystr(to,f1,f2,f3,f4,f5,f6,f7,f8,f9,f0)
  58. register char *to;
  59. char *f1,*f2,*f3,*f4,*f5,*f6,*f7,*f8,*f9,*f0;
  60. {
  61.     char *out,**in;
  62.  
  63.     out = to;
  64.     in = &f1;
  65.     while (*in) {
  66.         strcpy(out,*in);
  67.         out += strlen(*in);
  68.         in++;
  69.     }
  70.     return (out);
  71. }
  72.  
  73. jmp_buf env;
  74.  
  75. extern errrec();
  76.  
  77. int floflo() {
  78.     signal(SIGFPE,floflo);
  79.     puts("Arithmetic overflow.");
  80.     errhand();
  81. }
  82.  
  83. enter()
  84. {
  85.     register x;
  86.  
  87.     if (x=setjmp(env)) {
  88.         return(x);
  89.     } else {
  90.         onintr(errrec,1);
  91.         signal(SIGFPE,floflo);
  92.         return (yyparse());
  93.     }
  94. }
  95.  
  96. leave(val)
  97. {
  98.     putchar('\n');
  99.     longjmp(env,val);
  100. }
  101.  
  102. int sigarg;
  103. int (*intfun)();
  104. extern sigquit();
  105. #ifdef PAUSE
  106. int pausesig = PAUSESIG;
  107. int othersig = OTHERSIG;
  108. int psigflag = 0;
  109.  
  110. sigpaws() {    /* User signals a pause request */
  111.     signal(pausesig,sigpaws);
  112.     psigflag++;
  113. }
  114. #endif
  115.  
  116. onintr(inttf,val)
  117. register int (*inttf)(),val;
  118. {
  119.     sigarg = val;
  120. #ifdef PAUSE
  121.     signal(othersig,sigquit);
  122.     signal(pausesig,sigpaws);
  123. #else
  124.     signal(SIGINT,sigquit);
  125.     signal(SIGQUIT,sigquit);
  126. #endif
  127.     intfun = inttf;
  128. }
  129.  
  130. #ifdef DEBUG
  131. int deb_quit=0;
  132. #endif
  133.  
  134. sigquit()
  135. {
  136. #ifdef DEBUG
  137.     if(deb_quit) abort();
  138. #endif
  139.     alarm(0);
  140. #ifdef PAUSE
  141.     signal(othersig,sigquit);
  142. #else
  143.     signal(SIGINT,sigquit);
  144.     signal(SIGQUIT,sigquit);
  145. #endif
  146.     (*intfun)(sigarg);
  147. }
  148.  
  149. #ifdef DEBUG
  150. setdebquit() {
  151.     deb_quit++;
  152. }
  153.  
  154. setmemtrace() {
  155.     memtrace++;
  156. }
  157.  
  158. setyaccdebug() {
  159.     yydebug++;
  160. }
  161. #endif
  162.  
  163. #ifdef PAUSE
  164. setipause() {
  165.     pausesig = SIGINT;
  166.     othersig = SIGQUIT;
  167. }
  168.  
  169. setqpause() {
  170.     pausesig = SIGQUIT;
  171.     othersig = SIGINT;
  172. }
  173. #endif
  174.  
  175. putc1(cha)
  176. register cha;
  177. {
  178.     if(ostring)
  179.     {
  180.         *ostring++=cha;
  181.         *ostring=0;
  182.     }
  183.     else if(ofile)fputc(cha,ofile);
  184.     else putchar(cha);
  185. }
  186. sputs(str)
  187. register char *str;
  188. {
  189.     register char c;
  190.  
  191.     if(ofile)
  192.         while (c = *str++) fputc(c&0177,ofile);
  193.     else if(ostring){
  194.         while (c = *str++) {
  195.             if (c & 0200) *ostring++ = '\\';
  196.             *ostring++ = c & 0177 ;
  197.         }
  198.         *ostring = '\0';
  199.     }
  200.     else
  201.         while (c = *str++) fputc(c&0177,stdout);
  202. }
  203. nputs(str)
  204. register char *str;
  205. {
  206.     register char c;
  207.  
  208.     while (c = *str++) fputc(c,stdout);
  209. }
  210.  
  211. /*VARARGS*/
  212. pf1(str,a1,a2,a3,a4)
  213. register char *str;
  214. struct object *a1,*a2,*a3,*a4;
  215. {
  216.     register c;
  217.     register struct object **arg;
  218. #ifdef DEBUG
  219.     int omemt;
  220.  
  221.     omemt = memtrace;
  222.     memtrace = 0;
  223. #endif
  224.     arg= &a1;
  225.     while(c= *str++){
  226.         if(c=='%'){
  227.             c= *str++;
  228.             if(c=='d'){
  229.                 if(ostring){
  230.                     sprintf(ostring,"%d",(int)(*arg++));
  231.                     ostring+=strlen(ostring);
  232.                 }else if(ofile)
  233.                     fprintf(ofile,"%d",(int)(*arg++));
  234.                 else printf("%d",(int)(*arg++));
  235.             } else if(c=='o'){
  236.                 if(ostring){
  237.                     sprintf(ostring,"%o",(int)(*arg++));
  238.                     ostring+=strlen(ostring);
  239.                 }else if(ofile)
  240.                     fprintf(ofile,"%o",(int)(*arg++));
  241.                 else printf("%o",(int)(*arg++));
  242.             } else if(c=='s'){
  243.                 if(ostring){
  244.                     strcpy(ostring,(char *)(*arg++));
  245.                     ostring += strlen(ostring);
  246.                 } else if (ofile)
  247.                     fprintf(ofile,"%s",(char *)(*arg++));
  248.                 else printf("%s",(char *)(*arg++));
  249.             } else if(c=='l'){
  250.                 if(!listp(*arg)){
  251.                     if(emptyp(*arg)) sputs("empty");
  252.                     else if(stringp(*arg) && !nump(*arg))
  253.                         putc1('\"');
  254.                 }
  255.                 fty1(*arg++);
  256.             } else if(c=='p') {
  257.                 if(!stringp(*arg)) {
  258.                     *arg=stringform(*arg);
  259.                     sputs((*arg)->obstr);
  260.                     mfree(*arg);
  261.                 } else sputs((*arg)->obstr);
  262.                 arg++;
  263.             }
  264.             else putc1(c);
  265.         }
  266.         else putc1(c);
  267.     }
  268. #ifdef DEBUG
  269.     memtrace = omemt;
  270. #endif
  271. }
  272.  
  273.