home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gle / gle / drawit.c < prev    next >
C/C++ Source or Header  |  1992-11-29  |  5KB  |  261 lines

  1. #include "all.h"
  2. #include <math.h>
  3. #include <time.h>
  4.  
  5. #define true (!false)
  6. #define false 0
  7. #define dbg if (gle_debug>0)
  8. extern int done_open;
  9. extern int gle_debug;
  10. extern int trace_on;
  11. extern int netxt;
  12. extern int this_line;
  13. long *(*gpcode)[];   /* gpcode is a pointer to an array of poiter to long */
  14. long (*gplen)[];   /* gpcode is a pointer to an array of long */
  15. int ngpcode=0;
  16. extern int ngtxt;
  17. extern char *(*gtxt)[];
  18. int ngerror;
  19. extern int last_line;
  20. char *line(int i);
  21. int pass_checkmode(void);
  22. int expand_pcode(int i, int *j);
  23. char *dr_nextline(int *srclin);
  24. int dr_init(void);
  25. int getch(void);
  26. int fner(char *s);
  27. int abort_flag;
  28. static char inbuff[300];
  29. int var_def(char *s, double x);
  30. /*---------------------------------------------------------------------------*/
  31. gle_redraw()
  32. {
  33. static char xinbuff[200];
  34. char source[20];
  35. static char *tk[500];
  36. static char tkbuff[500];
  37. int ntok,f;
  38. long time1,time2;
  39. static long pcode[500];
  40. double oval;
  41. int maxpcode=0;
  42. int plen,cp,otyp,ii,i,j,al,endp;
  43. FILE *fptr;
  44. char space_str[] = " ";
  45. char fname[80],*s;
  46.     ngpcode = 0;
  47.     expand_pcode(ngtxt,&maxpcode);
  48.  
  49.     token_space();
  50.     /* Now compile the file into pcode */
  51.     for (i=0;i<500;i++) tk[i] = space_str;
  52.     abort_flag = false;
  53.     ngerror = 0;
  54.     netxt = 0;
  55.     last_line = 0;
  56.     fner("CGLE V3.3b,  Compiling...");
  57.  
  58.     mark_clear();
  59.     sub_clear();
  60.     for_init();
  61.     f_init();
  62.     dr_init();
  63.     var_def("PI",3.14159265);
  64.     done_open = false;
  65.     for (;(s = dr_nextline(&i)) != NULL;) {
  66.         strcpy(xinbuff,s);
  67.         al = strlen(xinbuff);
  68.         if (xinbuff[al-1]=='&') {
  69.             xinbuff[al-1] = 0;
  70.             strcat(xinbuff, dr_nextline(&i));
  71.         }
  72.         if (xinbuff[0]==26) xinbuff[0] = 0;
  73.         strcpy(inbuff,xinbuff);
  74.         this_line = i;
  75.         if (trace_on) gprint("Source | %s \n",xinbuff);
  76.         token(xinbuff,&tk,&ntok,tkbuff);
  77.         plen = 0;
  78.         passt(ngpcode+1,inbuff,&tk,&ntok,pcode,&plen);
  79. /*
  80.                 for (ii=0;ii<plen;ii++) {
  81.         printf("%x ",pcode[ii]);
  82.         }
  83.         printf("\n");
  84. */
  85.         if (ngpcode > maxpcode) expand_pcode(ngpcode*2,&maxpcode);
  86.         (*gpcode)[++ngpcode] = myallocz(plen*4);
  87.         (*gplen)[ngpcode] = plen;
  88.         memcpy((*gpcode)[ngpcode],&pcode,plen*4);
  89.         if (abort_key()) goto do_abort;
  90.     }
  91.     pass_checkmode();
  92.  
  93.     time(&time2);
  94.     fner("CGLE V3.3b,  Running...");
  95.     if (ngerror>0) {
  96.         gprint("Abort (Y/N)  [Y] \n");
  97.         if (tolower(text_inkey())!='n') return;
  98.     }
  99.     for (i=1;i<=ngpcode;i++) {
  100.         if (abort_key()) goto do_abort;
  101.         this_line = i;
  102.         if (trace_on) gprint("Trace |%s\n",line(i));
  103.         dbg gprint("Call do_pcode[%d] \n",i);
  104. /*        printf("Pcode pointer %p %d \n",(*gpcode)[i],i);*/
  105.         do_pcode(&i,(*gpcode)[i],(*gplen)[i],&endp);
  106.     }
  107. do_abort:
  108.     g_close();
  109.  
  110.     for (i=1;i<=ngpcode;i++) {
  111.         this_line = i;
  112.         if ( (*gpcode)[i] != NULL) myfrees( (*gpcode)[i] ,"gpcode");
  113.     }
  114.  
  115. }
  116. /*--------------------------------------------------------------------------*/
  117. glezzz()
  118. {
  119.     printf("~~~~~~~~~~~~~~~~~~Pcode pointer %p 2 \n",(*gpcode)[2]);
  120. }
  121. gle_include(char *s)
  122. {
  123.     gprint("include file (not implemented ) {%s} \n",s);
  124. }
  125. /*--------------------------------------------------------------------------*/
  126. extern char gleroot[];
  127. char *gle_top()
  128. {
  129.     char *s;
  130. #ifdef unix
  131.     return gleroot;
  132. #endif
  133. #ifdef __TURBOC__
  134.     return gleroot;
  135. #else
  136.     return "cgle_top:";
  137. #endif
  138. }
  139. char *gledir(char *s);
  140. char *bgidir()
  141. {
  142. #ifdef __TURBOC__
  143.     char *s;
  144.     s = getenv("GLE_BGI");
  145.     if (s==NULL) {
  146.         s = gledir("");
  147.     }
  148.     return s;
  149. #endif
  150. }
  151.  
  152. char *fontdir(char *fname)
  153. {
  154.     static char fbuff[80];
  155. #ifdef __TURBOC__
  156.     strcpy(fbuff,gle_top());
  157.     strcat(fbuff,"font\\");
  158. #else
  159.     strcpy(fbuff,"cgle_top:");
  160. #endif
  161. #ifdef unix
  162.     strcpy(fbuff,gle_top());
  163.     strcat(fbuff,"font/");
  164. #endif
  165.     strcat(fbuff,fname);
  166.     return &fbuff[0];
  167. }
  168. char *gledir(char *fname)
  169. {
  170.     static char fbuff[80];
  171. #ifdef __TURBOC__
  172.     strcpy(fbuff,gle_top());
  173.     strcat(fbuff,"exe\\");
  174. #else
  175.     strcpy(fbuff,"cgle_top:");
  176. #endif
  177. #ifdef unix
  178.     strcpy(fbuff,gle_top());
  179. #endif
  180.     strcat(fbuff,fname);
  181.     return &fbuff[0];
  182. }
  183. static int dri;
  184. static ninc=0;
  185. static FILE *incptr[10];
  186. include_file(char *fname)
  187. {
  188.     incptr[++ninc] = fopen(fname,"r");
  189.     if (incptr[ninc]==NULL) {
  190.         gprint("Unable to open input file {%s} \n",fname);
  191.         perror("Reason"); ninc--;
  192.     }
  193. }
  194. dr_init()
  195. {
  196.     dri = 1;
  197. }
  198. char *dr_nextline(int *srclin)
  199. {
  200.     int i;
  201. try_again:;
  202.     if (ninc==0) {
  203.         if (dri>ngtxt) return NULL;
  204.         *srclin = dri;
  205.         return (*gtxt)[dri++];
  206.     } else {
  207.         if (feof(incptr[ninc])) goto close_file;
  208.         if (fgets(inbuff,190,incptr[ninc])==NULL) goto close_file;
  209.         i = strlen(inbuff);
  210.         if (inbuff[i-1]=='\n') inbuff[i-1] = 0;
  211.         return inbuff;
  212.     }
  213. close_file:
  214.     fclose(incptr[ninc--]);
  215.     goto try_again;
  216. }
  217. expand_pcode(int ngtxt,int *maxpcode)
  218. {
  219.     long *a,*b;
  220.     a = myallocz((ngtxt+10)*4);
  221.     b = myallocz((ngtxt+10)*4);
  222.     if (gpcode!=0) {
  223.         memcpy(a,gpcode,(*maxpcode + 4)*4);
  224.         memcpy(b,gplen,(*maxpcode + 4)*4);
  225.         myfrees(gpcode,"gpcode2");
  226.         myfrees(gplen,"gplen");
  227.     }
  228.     gpcode = (long *(*)[]) a;
  229.     gplen = (long (*)[]) b;
  230.     *maxpcode = ngtxt+1;
  231. }
  232. run_bigfile(char *fname)
  233. {
  234.     FILE *fptr;
  235.     char inbuff[200],s[200];
  236.     char *tk[300];
  237.     char tkbuff[300];
  238.     long pcode[300];
  239.     int plen,ntok,i,endp;
  240.  
  241.     fptr = fopen(fname,"r");
  242.     if (fptr==NULL) {
  243.         gprint("Unable to open bigfile {%s} \n",fname);
  244.         perror("Reason");
  245.         return;
  246.     }
  247.     for (;!feof(fptr);) {
  248.      if (fgets(inbuff,190,fptr)!=NULL) {
  249.         strcpy(s,inbuff);
  250.         i = strlen(inbuff);
  251.         if (inbuff[i-1]=='\n') inbuff[i-1] = 0;
  252.         if (trace_on) gprint("Source | %s \n",inbuff);
  253.         token(inbuff,&tk,&ntok,tkbuff);
  254.         plen = 0;
  255.         passt(ngpcode+1,s,&tk,&ntok,pcode,&plen);
  256.         do_pcode(&i,pcode,plen,&endp);
  257.      }
  258.     }
  259.     fclose(fptr);
  260. }
  261.