예제 #1
0
파일: zb_util.c 프로젝트: ig10/q2admin
int breakLine(char *buffer, char *buff1, char *buff2, int buff2size)
{
	char *cp,*dp;
	
	cp= buffer;
	dp= buff1;
	
	while( *cp && *cp!=' ' && *cp!='\t')
		{
			*dp++ = *cp++;
		}
	*dp= 0x0;
	
	if(dp== buff1 || !*cp)
		{
			return 0;
		}
		
	dp = buff2;
	
	SKIPBLANK(cp);
	
	if( *cp!='\"')
		{
			return 0;
		}
	cp++;
	
	cp = processstring(buff2, cp, buff2size,'\"');
	
	if(!buff2[0]||*cp!='\"')
		{
			return 0;
		}
		
	return 1;
}
예제 #2
0
int yylex()
{
	int r, c, c2, d;
	int radix;
    char extPath[MAXPATHLEN]; // for error reporting

	yylen = 0;
	// finite state machine to parse input stream into tokens

	if (lexCmdLine == 1) {
		lexCmdLine = 2;
		r = INTERPRET;
		goto leave;
	}
start:
	c = input();

	if (c == 0)   { r = 0; goto leave; }
	else if (c==' ' || c=='\t' || c=='\n' || c=='\r' || c=='\v' || c=='\f') {
		yylen = 0;
		goto start;
	}
	else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') goto ident;
	else if (c == '/') {
		c = input();
		if (c == '/') goto comment1;
		else if (c == '*') goto comment2;
		else { unput(c); goto binop; }
	}
	else if (c >= '0' && c <= '9') goto digits_1;
	else if (c == OPENPAREN || c == OPENSQUAR || c == OPENCURLY) {
		pushls(&brackets, (int)c);
		if (c == OPENCURLY) {
			pushls(&closedFuncCharNo, linestarts[lineno] + charno - 1);
		}
		r = c;
		goto leave;
	}
	else if (c == CLOSSQUAR) {
		if (!emptyls(&brackets)) {
			if ((d = popls(&brackets)) != OPENSQUAR) {
				fatal();
				post("opening bracket was a '%c', but found a '%c'\n",d,c);
				goto error2;
			}
		} else {
			fatal();
			post("unmatched '%c'\n",c);
			goto error2;
		}
		r = c;
		goto leave;
	}
	else if (c == CLOSPAREN) {
		if (!emptyls(&brackets)) {
			if ((d = popls(&brackets)) != OPENPAREN) {
				fatal();
				post("opening bracket was a '%c', but found a '%c'\n",d,c);
				goto error2;
			}
		} else {
			fatal();
			post("unmatched '%c'\n",c);
			goto error2;
		}
		r = c;
		goto leave;
	}
	else if (c == CLOSCURLY) {
		if (!emptyls(&brackets)) {
			if ((d = popls(&brackets)) != OPENCURLY) {
				fatal();
				post("opening bracket was a '%c', but found a '%c'\n",d,c);
				goto error2;
			}
			lastClosedFuncCharNo = popls(&closedFuncCharNo);
		} else {
			fatal();
			post("unmatched '%c'\n",c);
			goto error2;
		}
		r = c;
		goto leave;
	}
	else if (c == '^') { r = c; goto leave; }
	else if (c == '~') { r = c; goto leave; }
	else if (c == ';') { r = c; goto leave; }
	else if (c == ':') { r = c; goto leave; }
	else if (c == '`') { r = c; goto leave; }
	else if (c == '\\') goto symbol1;
	else if (c == '\'') goto symbol3;
	else if (c == '"') goto string1;
	else if (c == '.') {
		if ((c = input()) == '.') {
			if ((c = input()) == '.') {
				r = ELLIPSIS;
				goto leave;
			} else {
				r = DOTDOT;
				unput(c);
				goto leave;
			}
		} else {
			unput(c);
			r = '.';
			goto leave;
		}

	}
	else if (c == '#') {
		if ((c = input()) == OPENCURLY) {
			pushls(&brackets, OPENCURLY);
			pushls(&closedFuncCharNo, linestarts[lineno] + charno - 2);
			r = BEGINCLOSEDFUNC;
		} else {
			unput(c);
			r = '#';
		}
		goto leave;
	}
	else if (c == '$') {
		c = input();
		if (c == '\\') {
			c = input();
			switch (c) {
				case 'n' : c = '\n'; break;
				case 'r' : c = '\r'; break;
				case 't' : c = '\t'; break;
				case 'f' : c = '\f'; break;
				case 'v' : c = '\v'; break;
			}
		}
		r = processchar(c);
		goto leave;
	}
	else if (c == ',') { r = c; goto leave; }
	else if (c == '=') {
		c = input();
		if (strchr(binopchars, c)) goto binop;
		else {
			unput(c);
			r = '=';
			goto leave;
		}
	}
	else if (strchr(binopchars, c))  goto binop;
	else if(!(isprint(c) || isspace(c) || c == 0)) {
		yylen = 0;
		goto start;
	}
	else goto error1;

ident:
	c = input();

	if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
		|| c == '_' || (c >= '0' && c <= '9')) goto ident;
	else if (c == ':') {
		yytext[yylen] = 0;
		r = processkeywordbinop(yytext) ;
		goto leave;
	} else {
		unput(c);
		yytext[yylen] = 0;
		r = processident(yytext) ;
		goto leave;
	}

symbol1:
	c = input();

	if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') goto symbol2;
	else if (c >= '0' && c <= '9') goto symbol4;
	else {
		unput(c);
		yytext[yylen] = 0;
		r = processsymbol(yytext) ;
		goto leave;
	}

symbol2:
	c = input();

	if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
		|| c == '_' || (c >= '0' && c <= '9')) goto symbol2;
	else {
		unput(c);
		yytext[yylen] = 0;
		r = processsymbol(yytext) ;
		goto leave;
	}

symbol4:
	c = input();
	if (c >= '0' && c <= '9') goto symbol4;
	else {
		unput(c);
		yytext[yylen] = 0;
		r = processsymbol(yytext) ;
		goto leave;
	}



binop:

	c = input();

	if (c == 0) goto binop2;
	if (strchr(binopchars, c))  goto binop;
	else {
		binop2:
		unput(c);
		yytext[yylen] = 0;
		r = processbinop(yytext) ;
		goto leave;
	}

radix_digits_1:

	c = input();
	if (c >= '0' && c <= '0' + sc_min(10,radix) - 1) goto radix_digits_1;
	if (c >= 'a' && c <= 'a' + sc_min(36,radix) - 11) goto radix_digits_1;
	if (c >= 'A' && c <= 'A' + sc_min(36,radix) - 11) goto radix_digits_1;
	if (c == '.') {
		goto radix_digits_2;
	}
	unput(c);
	yytext[yylen] = 0;
	r = processintradix(yytext, yylen, radix);
	goto leave;

radix_digits_2:

	c = input();
	if (c >= '0' && c <= '0' + sc_min(10,radix) - 1)  goto radix_digits_2;
	if (c >= 'A' && c <= 'A' + sc_min(36,radix) - 11) goto radix_digits_2;
	// do not allow lower case after decimal point.
	unput(c);
	yytext[yylen] = 0;
	r = processfloatradix(yytext, yylen, radix);
	goto leave;

hexdigits:

	c = input();
	if (c >= '0' && c <= '9') goto hexdigits;
	if (c >= 'a' && c <= 'f') goto hexdigits;
	if (c >= 'A' && c <= 'F') goto hexdigits;
	unput(c);
	yytext[yylen] = 0;
	r = processhex(yytext);
	goto leave;

digits_1:	/* number started with digits */

	c = input();

	if (c >= '0' && c <= '9') goto digits_1;
	else if (c == 'r') {
		radix = sc_strtoi(yytext, yylen-1, 10);
		yylen = 0;
		goto radix_digits_1;
	}
	else if (c == 'e' || c == 'E') goto expon_1;
	else if (c == '.') {
		c2 = input();
		if (c2 >= '0' && c2 <= '9') goto digits_2;
		else {
			unput(c2);
			unput(c);
			yytext[yylen] = 0;
			r = processint(yytext);
			goto leave;
		}
	}
	else if (c == 'b' || c == 's') {
		d = input();
		if (d >= '0' && d <= '9') goto accidental1;
		if (d == c) goto accidental2;
		goto accidental3;
accidental1:
		d = input();
		if (d >= '0' && d <= '9') goto accidental1;
		unput(d);
		yytext[yylen] = 0;
		r = processaccidental1(yytext);
		goto leave;
accidental2:
		d = input();
		if (d == c) goto accidental2;
accidental3:
		unput(d);
		yytext[yylen] = 0;
		r = processaccidental2(yytext);
		goto leave;
	}
	else if (c == 'x') {
		yylen = 0;
		goto hexdigits;
	} else {
		unput(c);
		yytext[yylen] = 0;
		r = processint(yytext);
		goto leave;
	}

digits_2:

	c = input();

	if (c >= '0' && c <= '9') goto digits_2;
	else if (c == 'e' || c == 'E') goto expon_1;
//	else if (c == 'π' || c == '∏') {
//		--yylen;
//		yytext[yylen] = 0;
//		r = processfloat(yytext, 1);
//		goto leave;
//	}
	else {
		unput(c);
		yytext[yylen] = 0;
		r = processfloat(yytext, 0);
		goto leave;
	}

expon_1:	/* e has been seen, need digits */
	c = input();

	if (c >= '0' && c <= '9') goto expon_3;
	else if (c == '+' || c == '-') goto expon_2;
	else goto error1;

expon_2:	/* + or - seen but still need digits */
	c = input();

	if (c >= '0' && c <= '9') goto expon_3;
	else goto error1;

expon_3:
	c = input();

	if (c >= '0' && c <= '9') goto expon_3;
//	else if (c == 'π' || c == '∏') {
//		--yylen;
//		yytext[yylen] = 0;
//		r = processfloat(yytext, 1);
//		goto leave;
//	}
	else {
		unput(c);
		yytext[yylen] = 0;
		r = processfloat(yytext, 0);
		goto leave;
	}

symbol3 : {
		int startline, endchar;
		startline = lineno;
		endchar = '\'';

		/*do {
			c = input();
		} while (c != endchar && c != 0);*/
		for (;yylen<MAXYYLEN;) {
			c = input();
			if (c == '\n' || c == '\r') {
                asRelativePath(curfilename,extPath);
				post("Symbol open at end of line on line %d in file '%s'\n",
					startline+errLineOffset, extPath);
				yylen = 0;
				r = 0;
				goto leave;
			}
			if (c == '\\') {
				yylen--;
				c = input();
			} else if (c == endchar) break;
			if (c == 0) break;
		}
		if (c == 0) {
            asRelativePath(curfilename,extPath);
			post("Open ended symbol ... started on line %d in file '%s'\n",
				startline+errLineOffset, extPath);
			yylen = 0;
			r = 0;
			goto leave;
		}
		yytext[yylen] = 0;
		yytext[yylen-1] = 0;
		r = processsymbol(yytext);
		goto leave;
	}

string1 : {
		int startline, endchar;
		startline = lineno;
		endchar = '"';

		for (;yylen<MAXYYLEN;) {
			c = input();
			if (c == '\\') {
				yylen--;
				c = input();
				switch (c) {
					case 'n' : yytext[yylen-1] = '\n'; break;
					case 'r' : yytext[yylen-1] = '\r'; break;
					case 't' : yytext[yylen-1] = '\t'; break;
					case 'f' : yytext[yylen-1] = '\f'; break;
					case 'v' : yytext[yylen-1] = '\v'; break;
				}
			} else if (c == '\r') c = '\n';
			else if (c == endchar) break;
			if (c == 0) break;
		}
		if (c == 0) {
            asRelativePath(curfilename,extPath);
			post("Open ended string ... started on line %d in file '%s'\n",
				startline+errLineOffset, extPath);
			yylen = 0;
			r = 0;
			goto leave;
		}
		yylen--;

		do {
			c = input0();
		} while (c && isspace(c));

		if (c == '"') goto string1;
		else if (c) unput0(c);

		yytext[yylen] = 0;
		r = processstring(yytext);
		goto leave;
	}

comment1:	/* comment -- to end of line */
	do {
		c = input0();
	} while (c != '\n' && c != '\r' && c != 0);
	yylen = 0;
	if (c == 0) { r = 0; goto leave; }
	else goto start;

comment2 : {
		int startline, clevel, prevc;
		startline = lineno;
		prevc = 0;
		clevel = 1;
		do {
			c = input0();
			if (c == '/' && prevc == '*') {
				if (--clevel <= 0) break;
			} else if (c == '*' && prevc == '/') clevel++;
			prevc = c;
		} while (c != 0);
		yylen = 0;
		if (c == 0) {
            asRelativePath(curfilename,extPath);
			post("Open ended comment ... started on line %d in file '%s'\n",
				startline+errLineOffset, extPath);
			r = 0;
			goto leave;
		}
		goto start;
	}


error1:

	yytext[yylen] = 0;

    asRelativePath(curfilename, extPath);
	post("illegal input string '%s' \n   at '%s' line %d char %d\n",
		yytext, extPath, lineno+errLineOffset, charno);
	post("code %d\n", c);
	//postfl(" '%c' '%s'\n", c, binopchars);
	//postfl("%d\n", strchr(binopchars, c));

error2:
    asRelativePath(curfilename, extPath);
	post("  in file '%s' line %d char %d\n", extPath, lineno+errLineOffset, charno);
	r = BADTOKEN;
	goto leave;

leave:
	yytext[yylen] = 0;

#if DEBUGLEX
	if (gDebugLexer) postfl("yylex: %d  '%s'\n",r,yytext);
#endif
	//if (lexCmdLine>0) postfl("yylex: %d  '%s'\n",r,yytext);
	return r;
}
예제 #3
0
qboolean ReadCheckVarFile(char *checkvarname) {
    FILE *checkvarfile;
    unsigned int uptoLine = 0;

    if (maxcheckvars >= CHECKVAR_MAX) {
        return FALSE;
    }

    checkvarfile = fopen(checkvarname, "rt");
    if (!checkvarfile) {
        return FALSE;
    }

    while (fgets(buffer, 256, checkvarfile)) {
        char *cp = buffer;
        int len;

        // remove '\n'
        len = q2a_strlen(buffer);
        len -= 1;
        if (buffer[len] == '\n') {
            buffer[len] = 0x0;
        }

        SKIPBLANK(cp);

        uptoLine++;

        if (startContains(cp, "CT:") || startContains(cp, "RG:")) {
            // looks ok, add...
            if (*cp == 'C') {
                checkvarList[maxcheckvars].type = CV_CONSTANT;
                continue;
            } else if (*cp == 'R') {
                checkvarList[maxcheckvars].type = CV_RANGE;
                continue;
            }

            cp += 3;
            SKIPBLANK(cp);

            if (*cp != '\"') {
                gi.dprintf("Error loading CHECKVAR from line %d in file %s, \" not found\n", uptoLine, checkvarname);
                continue;
            }

            cp++;
            cp = processstring(checkvarList[maxcheckvars].variablename, cp, sizeof (checkvarList[maxcheckvars].variablename) - 1, '\"');

            // make sure you are at the end quote
            while (*cp && *cp != '\"') {
                cp++;
            }

            if (*cp == 0) {
                gi.dprintf("Error loading CHECKVAR from line %d in file %s, unexcepted end of line\n", uptoLine, checkvarname);
                continue;
            }

            cp++;

            if (isBlank(checkvarList[maxcheckvars].variablename)) {
                gi.dprintf("Error loading CHECKVAR from line %d in file %s, blank variable name\n", uptoLine, checkvarname);
                continue;
            }


            SKIPBLANK(cp);

            if (checkvarList[maxcheckvars].type == CV_CONSTANT) {
                if (*cp != '\"') {
                    gi.dprintf("Error loading CHECKVAR from line %d in file %s, \" not found\n", uptoLine, checkvarname);
                    continue;
                }

                cp++;
                cp = processstring(checkvarList[maxcheckvars].value, cp, sizeof (checkvarList[maxcheckvars].value) - 1, '\"');
                continue;
            }
            else if (checkvarList[maxcheckvars].type == CV_RANGE) {
                char rangevalue[50];

                if (*cp != '\"') {
                    gi.dprintf("Error loading CHECKVAR from line %d in file %s, \" not found\n", uptoLine, checkvarname);
                    continue;
                }

                cp++;
                cp = processstring(rangevalue, cp, sizeof (rangevalue) - 1, '\"');

                checkvarList[maxcheckvars].lower = q2a_atof(rangevalue);

                while (*cp && *cp != '\"') {
                    cp++;
                }

                if (*cp == 0) {
                    gi.dprintf("Error loading CHECKVAR from line %d in file %s, unexcepted end of line\n", uptoLine, checkvarname);
                    continue;
                }

                cp++;
                SKIPBLANK(cp);

                if (*cp != '\"') {
                    gi.dprintf("Error loading CHECKVAR from line %d in file %s, \" not found\n", uptoLine, checkvarname);
                    continue;
                }

                cp++;
                cp = processstring(rangevalue, cp, sizeof (rangevalue) - 1, '\"');

                checkvarList[maxcheckvars].upper = q2a_atof(rangevalue);

                continue;
            }

            maxcheckvars++;

            if (maxcheckvars >= CHECKVAR_MAX) {
                break;
            }
        } else if (!(cp[0] == ';' || cp[0] == '\n' || isBlank(cp))) {
            gi.dprintf("Error loading CHECKVAR from line %d in file %s\n", uptoLine, checkvarname);
        }
    }

    fclose(checkvarfile);

    return TRUE;
}
예제 #4
0
void checkvarcmdRun(int startarg, edict_t *ent, int client) {
    char *cmd;

    if (maxcheckvars >= CHECKVAR_MAX) {
        gi.cprintf(ent, PRINT_HIGH, "Sorry, maximum number of variables to check has been reached.\n");
        return;
    }

    if (gi.argc() <= startarg + 2) {
        gi.cprintf(ent, PRINT_HIGH, CHECKVARCMD);
        return;
    }

    cmd = gi.argv(startarg);
    startarg++;

    if (Q_stricmp(cmd, "CT") == 0) {
        checkvarList[maxcheckvars].type = CV_CONSTANT;
    } else if (Q_stricmp(cmd, "RG") == 0) {
        checkvarList[maxcheckvars].type = CV_RANGE;
    } else {
        gi.cprintf(ent, PRINT_HIGH, CHECKVARCMD);
        return;
    }

    cmd = gi.argv(startarg);
    startarg++;

    if (isBlank(cmd)) {
        gi.cprintf(ent, PRINT_HIGH, CHECKVARCMD);
        return;
    }

    processstring(checkvarList[maxcheckvars].variablename, cmd, sizeof (checkvarList[maxcheckvars].variablename) - 1, 0);

    switch (checkvarList[maxcheckvars].type) {
        case CV_CONSTANT:
            cmd = gi.argv(startarg);
            processstring(checkvarList[maxcheckvars].value, cmd, sizeof (checkvarList[maxcheckvars].value) - 1, 0);
            break;

        case CV_RANGE:
            cmd = gi.argv(startarg);
            startarg++;
            checkvarList[maxcheckvars].lower = q2a_atof(cmd);

            if (gi.argc() <= startarg) {
                gi.cprintf(ent, PRINT_HIGH, CHECKVARCMD);
                return;
            }

            cmd = gi.argv(startarg);
            checkvarList[maxcheckvars].upper = q2a_atof(cmd);
            break;
    }

    switch (checkvarList[maxcheckvars].type) {
        case CV_CONSTANT:
            gi.cprintf(ent, PRINT_HIGH, "%4d CT: %s = \"%s\"\n", maxcheckvars + 1, checkvarList[maxcheckvars].variablename, checkvarList[maxcheckvars].value);
            break;

        case CV_RANGE:
            gi.cprintf(ent, PRINT_HIGH, "%4d RG: %s = %g to %g\n", maxcheckvars + 1, checkvarList[maxcheckvars].variablename, checkvarList[maxcheckvars].lower, checkvarList[maxcheckvars].upper);
            break;
    }

    maxcheckvars++;
}