home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / math / emacsfrontend.c next >
Encoding:
C/C++ Source or Header  |  1989-01-07  |  3.1 KB  |  175 lines

  1. /*
  2.  * Omega source    file
  3.  *
  4.  * Copyright 1986,1987 by Daniel R. Grayson.
  5.  *
  6.  * This    material contains trade    secrets    and may    be registered with the U.S.
  7.  * Copyright Office as an unpublished work, pursuant to    Title 17, U.S. Code,
  8.  * Section 408.     Unauthorized copying, adaptation, distribution    or display is
  9.  * prohibited.
  10.  *
  11.  */
  12.  
  13. /* emacsfrontend.c - derived from frontend.c, output sexps readable
  14.    by GNU Emacs Lisp. */
  15.  
  16. #include <stdio.h>
  17. #include "interrupts.h"
  18. #include "trace.h"
  19. #include "lib.h"
  20. #define FRONTENDVERSION
  21. #include "mathtalk.h"
  22.  
  23. #include "mathdescemacs.h"
  24.  
  25. static int column = 1;          /* counter for newline insertion */
  26.  
  27. /* end of state */
  28.  
  29. #define LINEWIDTH 80
  30. #define outc_bump(c) (outc(c), \
  31.               LINEWIDTH == ++column ? (outc('\n'), column = 1) : 0)
  32.  
  33.  
  34. inc()
  35. {
  36.   return twgetc(leftin);
  37. }
  38.  
  39. outc(c)
  40. {
  41.   return twputc(c,leftout);
  42. }
  43.  
  44. outflush()
  45. {
  46.   twfflush(leftout);
  47. }
  48.  
  49.      
  50. char *sprintf();
  51.  
  52. #define put(x) fputs(x,stdout)
  53. #define send(x) (void)twwrite(LEFTOUT,x,strlen(x))
  54.  
  55. int hadint, busywriting;
  56.  
  57. onint(){
  58. /*     if (!permissiontointerrupt) {
  59.       puts("\n$ Sorry, we can't interrupt the kernel now.");
  60.       if (permissiontospeak) userprompt();
  61.       return;
  62.       } */
  63.      if (busywriting) {
  64.       hadint = YES;
  65.       }
  66.      else {
  67.            sendinterrupt();
  68.       }
  69.      (void)signal(SIGINT,onint);
  70.      }
  71.  
  72. #define BUFSZ 4096
  73.  
  74. char indata[BUFSZ];
  75.  
  76. /* modified to wrap in double quotes and escape double quotes. */
  77. putn(s,n)
  78. char *s;
  79. {
  80.   putchar('"');
  81.   while (n-->0)
  82.     {
  83.       if (('"' == *s) || ('\\' == *s))
  84.     putchar('\\'); /* escape double quote */
  85.       putchar(*s++);
  86.     }
  87.   putchar('"'); putchar(' ');
  88. }
  89.  
  90.  
  91. char *
  92.   actionname(ac)
  93. {
  94.   if (ac >=0 && ac <= aTOTAL) return action_name[ac];
  95.   return NULL;
  96. }
  97.  
  98.  
  99. userprompt(){
  100.      switch(current_menu) { /* this needs to be changed - maybe do nothing */
  101.       case INTERRUPT_MENU: put("(interrupt) "); break;
  102.       case DEBUG_MENU: put("(debug) "); break;
  103.       case INSPECTOR_MENU: put("(inspector) "); break;
  104.       case TOPLEVEL_MENU: break;
  105.       }
  106.      }
  107.  
  108. /*ARGSUSED*/
  109. main(argc,argv)
  110. char **argv;
  111. {
  112.   int dir, c, ac, blksiz;
  113.   char *blk;
  114.   stack *user = newstack(char,256,256);
  115.   setprogname(argc,argv);
  116.   twinit(RIGHTEND);
  117.   mtinit();
  118.   (void)signal(SIGINT,onint);
  119.   sendaction(aRESPOND); /* remove this later */
  120.      
  121.   while(1)
  122.     {
  123.       c = twbigetchar(&dir);
  124.       if (c == EOF) {
  125.     twshutdown();
  126.     trace("exiting");
  127.     exit(0);
  128.       }
  129.       
  130.       if (dir == LEFTWARD) {
  131.     /* user input */
  132.     /* putchar(c); /* echo it */
  133.     outc_bump(c);
  134.     if (c == '\n') {
  135.       twfflush(rightout);
  136.       outflush();
  137.     }
  138.  
  139. /*      busywriting = YES;
  140.       senddata(stackcontents(user),stacksize(user));
  141.       emptystack(user);
  142.       busywriting = NO;
  143.       if (hadint) {
  144.         hadint = NO;
  145.         sendinterrupt();
  146.       }
  147.     }
  148.     else {
  149.       pushstack(user,c,char);
  150.     } */
  151.       }
  152.  
  153.       else            /* dir == RIGHTWARD */
  154.     {
  155.       /* kernel output */
  156.       ac = interpret(c);
  157.       if (ac != 0) {
  158.         if (withdata(ac)) {
  159.           getblock(&blk,&blksiz);
  160.           putn(blk,blksiz);
  161.           if (blksiz!=0 && blk[blksiz-1]!='\n') {
  162.         /* for readability only */
  163.         putchar('\n');
  164.           }
  165.           Free(blk);
  166.         }
  167.         puts(actionname(ac));
  168.       }
  169.       fflush(stdout);
  170.       if (permissiontospeak) /* userprompt(); */
  171.         ;
  172.     }
  173.     }
  174. }
  175.