home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- *
- * G E T _ P I C T U R E . C
- * -------------------------
- *
- * Description:
- * Compiles a picture statement.
- *
- * Included functions:
- * get_picture - Does the job
- *
- * Revision:
- * Ver Date By Reason
- * --- ---- -- ------
- * 1.00 900621 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_field();
- static int found_event();
- static int found_literal();
-
- static struct lookup_s lookup[] = {
- "FIELD", found_field,
- "LITERAL", found_literal,
- "EVENT", found_event
- };
-
- struct picture *get_picture()
- {
- char token[TOKENSIZE];
- struct link *lp;
- struct picture *pp = NULL;
- int i;
-
- if(GetTokNC(token) == NULL || !isnormal(token[0])) {
- error("expected nam of picture");
- return NULL;
- }
-
- pp = memalloc(sizeof *pp);
- link_name(&pp->link, token);
-
- /* Check that viewport is specified */
- if (GetTokNC(token) == NULL || strequ(token, "viewport")) {
- error("expected viewport");
- unget_picture(pp);
- return NULL;
- }
-
- if (GetTokNC(token) == NULL || !isnormal(token[0])) {
- error("expected name of viewport");
- unget_picture(pp);
- return NULL;
- }
-
- if ((lp = find_name((struct link *)list.viewport, token)) == NULL) {
- error("unknown viewport");
- unget_picture(pp);
- return NULL;
- }
-
- pp->viewport = (struct viewport *)lp;
-
- if (GetTokNC(token) == NULL || strcmp(token, "{")) {
- error("expected '{'");
- unget_picture(pp);
- return NULL;
- }
-
- 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)(pp) != OK) {
- unget_picture(pp);
- return NULL;
- }
- }
- else {
- fprintf(stderr, "line %d: unknown token '%s' for picture\n",
- line, token);
- }
- }
- return pp;
- }
-
- struct picture *unget_picture(struct picture *pp)
- {
- struct picture *next;
- struct field *fp;
- struct literal *lp;
- struct event *ep;
-
- if (pp == NULL) return NULL;
-
- next = (struct picture *)pp->link.next;
-
- for(fp = pp->field; fp != NULL; fp = unget_field(fp))
- ;
-
- for(lp = pp->literal; lp != NULL; lp = unget_literal(lp))
- ;
-
- for(ep = pp->event; ep != NULL; ep = unget_event(ep))
- ;
-
- if (pp->link.name) free(pp->link.name);
-
- free(pp);
-
- return next;
- }
-
- static int found_field(pp)
- struct picture *pp;
- {
- struct field *fp;
-
- if ((fp = get_field()) == NULL) return FAIL;
-
- link((struct link **)&pp->field, &fp->link, TYPE_FIELD);
-
- return OK;
- }
-
- static int found_literal(pp)
- struct picture *pp;
- {
- struct literal *lp;
-
- if ((lp = get_literal()) == NULL) return FAIL;
-
- link((struct link **)&pp->literal, &lp->link, TYPE_LITERAL);
-
- return OK;
- }
-
- static int found_event(pp)
- struct picture *pp;
- {
- struct event *ep;
-
- if ((ep = get_event()) == NULL) return FAIL;
-
- link((struct link **)&pp->event, &ep->link, TYPE_EVENT);
-
- return OK;
- }
-
-