home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * input.c
- * Copyright © 1992 Niklas Röjemo
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include "error.h"
- #include "global.h"
- #include "input.h"
- #include "riscos.h"
-
- #define MAX_LINE 1024
-
- FILE *asmfile;
- static char buff[MAX_LINE];
- static char *pos,*mark;
-
- int inputLineNo;
-
- char inputLook(void)
- {
- return *pos;
- }
-
- char inputLookN(int n) /* Unsafe */
- {
- return pos[n];
- }
-
- char inputGet(void)
- {
- if(*pos) return *pos++;
- else return *pos;
- }
- void inputUnGet(char c)
- {
- if(pos>buff && pos[-1] == c)
- pos--;
- else
- if(*pos || c) error(ErrorSerious,FALSE,"Internal inputUnGet: Illegal character.");
- }
-
- void inputSkip(void)
- {
- if(*pos) pos++;
- }
-
- void inputSkipN(int n)
- {
- while(*pos && n--) pos++;
- if(n>-1)
- error(ErrorSerious,FALSE,"Internal inputSkipN: Trying to skip more characters than are availible.");
- }
-
- char *inputRest(void)
- {
- char *t = pos;
- while(*pos) pos++;
- return t;
- }
- char *inputLine(void)
- {
- return buff;
- }
-
- char inputSkipLook(void)
- {
- if(*pos) return *++pos;
- else return *pos;
- }
-
- void skipblanks(void)
- {
- char c;
- while((c=*pos)!=0 && isspace(c))
- pos++;
- }
-
- void skiprest(void)
- {
- buff[0] = 0;
- pos = mark = &buff[0];
- }
-
- void inputMark(void)
- {
- mark = pos;
- }
-
- void inputRollback(void)
- {
- pos = mark;
- }
-
- void inputInit(char *infile)
- {
- if(infile && strcmp(infile,"-")) {
- if((asmfile = fopen(toriscos(infile,"s",'s'),"r")) == NULL) {
- errorLine(0,ErrorAbort,FALSE,"As can't read %s.",infile);
- }
- } else
- asmfile = stdin;
-
- inputLineNo = 0;
- skiprest();
- }
-
- void inputFinish(void)
- {
- if(asmfile != stdin)
- fclose(asmfile);
- }
-
- BOOL inputNextLine(void)
- {
- int l;
- inputLineNo++;
- if(fgets(buff,MAX_LINE,asmfile)==NULL) {
- inputLineNo = -1;
- return FALSE;
- }
- l = strlen(buff);
- if(l && buff[l-1] != '\n') {
- if((l=getc(asmfile))!= EOF && l!='\n') {
- error(ErrorSerious,TRUE,"Line truncated");
- while((l=getc(asmfile))!= EOF && l!='\n')
- ;
- }
- }
- pos = &buff[0];
- return TRUE;
- }
-
- char *inputSymbol(int *ilen, char del)
- {
- char *res = pos;
- char c;
- if(del) {
- while((c=*pos)!=0 && c != del) {
- pos++;
- if(c == '\\' && *pos)
- pos++;
- }
- } else {
- while((c=*pos)!=0 && (isalnum(c) || c == '_')) {
- pos++;
- if(c == '\\' && *pos)
- pos++;
- }
- }
- *ilen = pos-res;
- return res;
- }
-