home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / cforms / part01 / src / get_literal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-18  |  2.2 KB  |  117 lines

  1. /*******************************************************************************
  2.  *
  3.  *        G E T _ L I T E R A L . C
  4.  *        -------------------------
  5.  *
  6.  * Description:
  7.  *    Compiles a literal statemnent.
  8.  *
  9.  * Included functions:
  10.  *    get_literal    - Does the job
  11.  *
  12.  * Revision:
  13.  *    Ver    Date    By        Reason
  14.  *    ---    ----    --        ------
  15.  *    1.00    900627    Lars Berntzon    Created
  16.  *
  17.  ******************************************************************************/
  18.  
  19. #include <stdio.h>
  20. #include <ctype.h>
  21. #include <string.h>
  22.  
  23. #include "token.h"
  24. #include "comp.h"
  25.  
  26. #define isnormal(ch) (isalnum(ch) || (ch) == '_')
  27.  
  28. static int found_display();
  29.  
  30. static struct lookup_s lookup[] = {
  31.     "DISPLAY",    found_display
  32. };
  33.  
  34. struct literal *get_literal()
  35. {
  36.     char token[TOKENSIZE];
  37.     struct literal *lp = NULL;
  38.     int i;
  39.     int x, y;
  40.     
  41.     if (GetPos(&x, &y) != OK) {
  42.         error("expected a coordinate");
  43.         return NULL;
  44.     }
  45.     
  46.     if (GetTokNC(token) == NULL || strcmp(token, ",")) {
  47.         error("expected a ',' after row");
  48.         return NULL;
  49.     }
  50.     
  51.     if (GetTokNC(token) == NULL || token[0] != '"') {
  52.         error("expected literal text");
  53.         return NULL;
  54.     }
  55.     
  56.     token[strlen(token) - 1] = 0;
  57.     
  58.     lp = memalloc(sizeof *lp);
  59.     link_name(&lp->link, token + 1);
  60.     
  61.     if(GetTokNC(token) == NULL ||
  62.        (strcmp(token, "{") != 0 &&
  63.         strcmp(token, ";") != 0) ) {
  64.         error("expected '{' ot ';'");
  65.         unget_literal(lp);
  66.         return NULL;
  67.     }
  68.     
  69.     lp->pos.x = x;
  70.     lp->pos.y = y;
  71.     
  72.     if(strcmp(token, ";") == 0) {
  73.         return lp;
  74.     }
  75.     
  76.     while(GetTokNC(token) != NULL) {
  77.         if (strcmp(token, "}") == 0) break;
  78.         
  79.     for(i = 0; i < N_CMDS; i++) {
  80.         if (strequ(token, lookup[i].cmd) == 0) break;
  81.     }
  82.     if (i < N_CMDS) {
  83.         if ((*lookup[i].func)(lp) != OK) {
  84.         unget_literal(lp);
  85.         return NULL;
  86.         }
  87.     }
  88.     else {
  89.         fprintf(stderr, "line %d: unknown token '%s' for literal\n",
  90.             line, token);
  91.     }
  92.     }
  93.  
  94.     return lp;
  95. }
  96.  
  97. struct literal *unget_literal(struct literal *lp)
  98. {
  99.     struct literal *next;
  100.     
  101.     if (lp == NULL) return NULL;
  102.     
  103.     next = (struct literal *)lp->link.next;
  104.     
  105.     if (lp->link.name) free(lp->link.name);
  106.     free(lp);
  107.  
  108.     return next;
  109. }
  110.  
  111. static int found_display(lp)
  112.     struct literal *lp;
  113. {
  114.  
  115.     return OK;
  116. }
  117.