home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- *
- * G E T _ L I T E R A L . C
- * -------------------------
- *
- * Description:
- * Compiles a literal statemnent.
- *
- * Included functions:
- * get_literal - Does the job
- *
- * Revision:
- * Ver Date By Reason
- * --- ---- -- ------
- * 1.00 900627 Lars Berntzon Created
- *
- ******************************************************************************/
-
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
-
- #include "token.h"
- #include "comp.h"
-
- #define isnormal(ch) (isalnum(ch) || (ch) == '_')
-
- static int found_display();
-
- static struct lookup_s lookup[] = {
- "DISPLAY", found_display
- };
-
- struct literal *get_literal()
- {
- char token[TOKENSIZE];
- struct literal *lp = NULL;
- int i;
- int x, y;
-
- if (GetPos(&x, &y) != OK) {
- error("expected a coordinate");
- return NULL;
- }
-
- if (GetTokNC(token) == NULL || strcmp(token, ",")) {
- error("expected a ',' after row");
- return NULL;
- }
-
- if (GetTokNC(token) == NULL || token[0] != '"') {
- error("expected literal text");
- return NULL;
- }
-
- token[strlen(token) - 1] = 0;
-
- lp = memalloc(sizeof *lp);
- link_name(&lp->link, token + 1);
-
- if(GetTokNC(token) == NULL ||
- (strcmp(token, "{") != 0 &&
- strcmp(token, ";") != 0) ) {
- error("expected '{' ot ';'");
- unget_literal(lp);
- return NULL;
- }
-
- lp->pos.x = x;
- lp->pos.y = y;
-
- if(strcmp(token, ";") == 0) {
- return lp;
- }
-
- while(GetTokNC(token) != NULL) {
- if (strcmp(token, "}") == 0) break;
-
- for(i = 0; i < N_CMDS; i++) {
- if (strequ(token, lookup[i].cmd) == 0) break;
- }
- if (i < N_CMDS) {
- if ((*lookup[i].func)(lp) != OK) {
- unget_literal(lp);
- return NULL;
- }
- }
- else {
- fprintf(stderr, "line %d: unknown token '%s' for literal\n",
- line, token);
- }
- }
-
- return lp;
- }
-
- struct literal *unget_literal(struct literal *lp)
- {
- struct literal *next;
-
- if (lp == NULL) return NULL;
-
- next = (struct literal *)lp->link.next;
-
- if (lp->link.name) free(lp->link.name);
- free(lp);
-
- return next;
- }
-
- static int found_display(lp)
- struct literal *lp;
- {
-
- return OK;
- }
-