int32 Interp::runFile(char* filename, uint32 linesz, void* context) { DataBuf dbLine; FILE* fin = NULL; char* param_string = NULL; char* token = NULL; char* line = NULL; uint32 current_line = 1; int32 ret = 0, out = 0, k = 0; ret = dbLine.init(linesz); if (ret == FAILURE) return FAILURE; dbLine.set(0); dbLine.setCount(0); dbLine.setLimit(2 * 1024 * 1024); line = dbLine.toString(); fin = fopen(filename, "r"); if (!fin) return FAILURE; while (1) { /* get a line */ out = Utils::getDelim(line, linesz, '\n', fin); if (out < 0) break; /* remove '\n' and blanks */ while (--out && isspace(toascii(line[out]))) line[out] = 0; /* remove blanks */ k = (int32) strlen(line); while (k && isspace(toascii(*line))) { k--; line++; } /* remove empty lines and comments */ if (line[0] == '#' || line[0] == '\0') { current_line++; continue; } /* execute instruction */ param_string = line; token = Utils::getToken(¶m_string, " \t"); if (token) { ret = run(token, param_string, context); switch (ret) { case BADCOMMAND: case PARAMPARSINGERROR: case WRONGPARAMCOUNT: case PERMISSIONDENIED: sysHandler(token, current_line, ret, context); return FAILURE; default: usrHandler(token, current_line, ret, context); } current_line++; } else { current_line++; continue; } } fclose(fin); return SUCCESS; }