Exemple #1
0
int SCHED_CONFIG::parse_file(const char* dir) {
    char path[MAXPATHLEN], path_aux[MAXPATHLEN];
    int retval;

    if (dir && strlen(dir)) {
        snprintf(path, sizeof(path), "%s/%s", dir, CONFIG_FILE);
        snprintf(path_aux, sizeof(path_aux), "%s/%s", dir, CONFIG_FILE_AUX);
    } else {
        safe_strcpy(path, project_path(CONFIG_FILE));
        safe_strcpy(path_aux, project_path(CONFIG_FILE_AUX));
    }
#ifndef _USING_FCGI_
    FILE* f = fopen(path, "r");
#else
    FCGI_FILE *f = FCGI::fopen(path, "r");
#endif
    if (!f) return ERR_FOPEN;
    retval = parse(f);
    fclose(f);
    if (retval) return retval;

#ifndef _USING_FCGI_
    FILE* f_aux = fopen(path_aux, "r");
#else
    FCGI_FILE *f_aux = FCGI::fopen(path_aux, "r");
#endif
    if (!f_aux) return 0;
    retval = parse_aux(f_aux);
    fclose(f_aux);
    return retval;
}
Exemple #2
0
static int lxp_close (lua_State *L) {
  int status = 1;
  lxp_userdata *xpu = (lxp_userdata *)luaL_checkudata(L, 1, ParserType);
  luaL_argcheck(L, xpu, 1, "expat parser expected");
  if (xpu->state != XPSfinished)
    status = parse_aux(L, xpu, NULL, 0);
  lxpclose(L, xpu);
  if (status > 1) luaL_error(L, "error closing parser: %s",
                                lua_tostring(L, -status+1));
  return 0;
}
Exemple #3
0
static int lxp_parse (lua_State *L) {
  lxp_userdata *xpu = checkparser(L, 1);
  size_t len;
  const char *s = luaL_optlstring(L, 2, NULL, &len);
  if (xpu->state == XPSfinished && s != NULL) {
    lua_pushnil(L);
    lua_pushliteral(L, "cannot parse - document is finished");
    return 2;
  }
  return parse_aux(L, xpu, s, len);
}