예제 #1
0
int picolCommandSet(struct picolInterp *i, int argc, char **argv, void *pd) {
	if (argc != 3)
		return picolArityErr(i, argv[0]);
	picolSetVar(i, argv[1], argv[2]);
	picolSetResult(i, argv[2]);
	return PICOL_OK;
}
예제 #2
0
int picolCommandMath(struct picolInterp *i, int argc, char **argv, void *pd) {
	char buf[64];
	int a, b, c;
	if (argc != 3)
		return picolArityErr(i, argv[0]);
	a = atoi(argv[1]);
	b = atoi(argv[2]);
	if (argv[0][0] == '+')
		c = a + b;
	else if (argv[0][0] == '-')
		c = a - b;
	else if (argv[0][0] == '*')
		c = a * b;
	else if (argv[0][0] == '/')
		c = a / b;
	else if (argv[0][0] == '>' && argv[0][1] == '\0')
		c = a > b;
	else if (argv[0][0] == '>' && argv[0][1] == '=')
		c = a >= b;
	else if (argv[0][0] == '<' && argv[0][1] == '\0')
		c = a < b;
	else if (argv[0][0] == '<' && argv[0][1] == '=')
		c = a <= b;
	else if (argv[0][0] == '=' && argv[0][1] == '=')
		c = a == b;
	else if (argv[0][0] == '!' && argv[0][1] == '=')
		c = a != b;
	else
		c = 0; /* I hate warnings */
	sniprintf(buf, 64, "%d", c);
	picolSetResult(i, buf);
	return PICOL_OK;
}
예제 #3
0
파일: picol.c 프로젝트: fmutant/scriptorium
int picolCommandProc(struct picolInterp *i, int argc, char **argv, void *pd) {
    char **procdata = malloc(sizeof(char*)*2);
    if (argc != 4) return picolArityErr(i,argv[0]);
    procdata[0] = strdup(argv[2]); /* arguments list */
    procdata[1] = strdup(argv[3]); /* procedure body */
    return picolRegisterCommand(i,argv[1],picolCommandCallProc,procdata);
}
예제 #4
0
파일: picol.c 프로젝트: fmutant/scriptorium
int picolCommandIf(struct picolInterp *i, int argc, char **argv, void *pd) {
    int retcode;
    if (argc != 3 && argc != 5) return picolArityErr(i,argv[0]);
    if ((retcode = picolEval(i,argv[1])) != PICOL_OK) return retcode;
    if (atoi(i->result)) return picolEval(i,argv[2]);
    else if (argc == 5) return picolEval(i,argv[4]);
    return PICOL_OK;
}
예제 #5
0
int picolCommandRetCodes(struct picolInterp *i, int argc, char **argv, void *pd) {
	if (argc != 1)
		return picolArityErr(i, argv[0]);
	if (strcmp(argv[0], "break") == 0)
		return PICOL_BREAK;
	else if (strcmp(argv[0], "continue") == 0)
		return PICOL_CONTINUE;
	return PICOL_OK;
}
예제 #6
0
파일: picol.c 프로젝트: fmutant/scriptorium
int picolCommandWhile(struct picolInterp *i, int argc, char **argv, void *pd) {
    if (argc != 3) return picolArityErr(i,argv[0]);
    while(1) {
        int retcode = picolEval(i,argv[1]);
        if (retcode != PICOL_OK) return retcode;
        if (atoi(i->result)) {
            if ((retcode = picolEval(i,argv[2])) == PICOL_CONTINUE) continue;
            else if (retcode == PICOL_OK) continue;
            else if (retcode == PICOL_BREAK) return PICOL_OK;
            else return retcode;
        } else {
            return PICOL_OK;
        }
    }
}
예제 #7
0
int picolCommandReturn(struct picolInterp *i, int argc, char **argv, void *pd) {
	if (argc != 1 && argc != 2)
		return picolArityErr(i, argv[0]);
	picolSetResult(i, (argc == 2) ? argv[1] : "");
	return PICOL_RETURN;
}
예제 #8
0
int picolCommandPuts(struct picolInterp *i, int argc, char **argv, void *pd) {
	if (argc != 2)
		return picolArityErr(i, argv[0]);
	iprintf("%s\n", argv[1]);
	return PICOL_OK;
}