home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- *
- * G E T _ V I E W P O R T . C
- * ---------------------------
- *
- * Description:
- * Compiles a viewport statement.
- *
- * Included functions:
- * get_viewport - Does the job
- *
- * Revision:
- * Ver Date By Reason
- * --- ---- -- ------
- * 1.00 900619 Lars Berntzon Created
- *
- ******************************************************************************/
-
- #include "config.h"
-
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #ifdef STDLIB_H
- #include <stdlib.h>
- #endif
- #ifdef MALLOC_H
- #include <malloc.h>
- #endif
-
- #include "token.h"
- #include "comp.h"
-
- #define isnormal(ch) (isalnum(ch) || (ch) == '_')
-
- static int found_pos();
- static int found_size();
-
- static struct lookup_s lookup[] = {
- "POS", found_pos,
- "SIZE", found_size
- };
-
- struct viewport *get_viewport()
- {
- char token[TOKENSIZE];
- struct viewport *vp = NULL;
- int i;
-
- if (GetTokNC(token) == NULL || !isnormal(token[0])) {
- error("expected name of viewport");
- return NULL;
- }
-
- vp = memalloc(sizeof *vp);
- link_name(&vp->link, token);
-
- if(GetTokNC(token) == NULL || strcmp(token, "{")) {
- error("expected '{'");
- unget_viewport(vp);
- 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)(vp) != OK) {
- unget_viewport(vp);
- return NULL;
- }
- }
- else {
- fprintf(stderr, "line %d: unknown token '%s'\n", line, token);
- }
- }
- return vp;
- }
-
- struct viewport *unget_viewport(struct viewport *vp)
- {
- struct viewport *next;
-
- if (vp == NULL) return NULL;
-
- next = (struct viewport *)vp->link.next;
- if (vp->link.name) free(vp->link.name);
- free(vp);
- return next;
- }
-
- static int found_pos(vp)
- struct viewport *vp;
- {
- char token[TOKENSIZE];
-
- if (!GetTokNC(token) || !isdigit(token[0])) {
- error("expected column");
- return FAIL;
- }
- vp->pos.x = atoi(token);
-
- if(!GetTokNC(token) || strcmp(token, ",")) {
- error("expected ','");
- return FAIL;
- }
- if (!GetTokNC(token) || !isdigit(token[0])) {
- error("expected row");
- return FAIL;
- }
- vp->pos.y = atoi(token);
- if (!GetTokNC(token) || strcmp(token, ";")) {
- error("expected row");
- return FAIL;
- }
- return OK;
- }
-
- static int found_size(vp)
- struct viewport *vp;
- {
- char token[TOKENSIZE];
-
- if (!GetTokNC(token) || !isdigit(token[0])) {
- error("expected column");
- return FAIL;
- }
- vp->size.x = atoi(token);
-
- if(!GetTokNC(token) || strcmp(token, ",")) {
- error("expected ','");
- return FAIL;
- }
-
- if (!GetTokNC(token) || !isdigit(token[0])) {
- error("expected row");
- return FAIL;
- }
- vp->size.y = atoi(token);
- if (!GetTokNC(token) || strcmp(token, ";")) {
- error("expected row");
- return FAIL;
- }
- return OK;
- }
-
-