int move(t_list *list) { t_list *link; int ret; ret = 0; link = list; clean_end(list); while (link != NULL) { if (((t_salle *)link->content)->status == END) { if (link->next != NULL) link = link->next; else break ; } if (((t_salle *)link->content)->clean == 1) { iter_path(list, TC->way_value); init_useless(list); ret = 1; } link = link->next; } move_next(list); return (ret); }
int confparser_parse(ConfParser* parser) { FILE *f; f = fopen(parser->filename, "r"); if (NULL == f) return -1; char buf[4096]; char *pstart; int lineno = 0; char key[100] = {0}; while (fgets(buf, 4096, f) != NULL) { pstart = buf; lineno++; while (isblank(*pstart)) pstart++; if (pstart[0] == '#' || pstart[0] == '\r' || pstart[0] == '\n') { continue; } if (*pstart == '=') { DERROR("config file parse error! not key at line:%d\n", lineno); fclose(f); return -1; } char *sp = strchr(pstart, '='); if (sp == NULL) { if (*key == '\0') { DERROR("config file parse error! \"=\" not found at line:%d\n", lineno); fclose(f); return -1; } } else { char *end = sp - 1; while (end > pstart && isblank(*end)) { end--; } *(end + 1) = 0; strcpy(key, pstart); pstart = sp + 1; while (isblank(*pstart)) pstart++; if (*pstart == '\r' || *pstart == '\n') continue; } clean_end(pstart); ConfParam *param = parser->params; char *tmp = NULL, *item = NULL; while (param) { if (strcmp(param->name, key) == 0) { // lastname = param->name; if (param->arraysize && param->dsti >= param->arraysize) { DERROR("config parser error, too many items: %s line:%d\n", param->name, lineno); fclose(f); return -1; } switch(param->type) { case CONF_INT: if (param->arraysize) { while ((item = find_array_item(pstart, &tmp)) != NULL) { ((int*)param->dst)[param->dsti] = atoi(item); //DERROR("%d\n", ((int*)param->dst)[param->dsti]); param->dsti++; } }else{ *(int*)param->dst = atoi(pstart); } break; case CONF_FLOAT: if (param->arraysize) { while ((item = find_array_item(pstart, &tmp)) != NULL) { ((float*)param->dst)[param->dsti] = atof(item); param->dsti++; } }else{ *(float*)param->dst = atof(pstart); } break; case CONF_STRING: if (param->arraysize) { while ((item = find_array_item(pstart, &tmp)) != NULL) { snprintf(((char**)param->dst)[param->dsti], 1024, "%s", item); param->dsti++; } }else{ snprintf((char*)param->dst, 1024, "%s", pstart); } break; case CONF_BOOL: { int v = 0; if (param->arraysize) { while ((item = find_array_item(pstart, &tmp)) != NULL) { v = bool_check(item); if (v < 0) { DERROR("conf error, %s must yes/no true/false at line:%d\n", param->name, lineno); fclose(f); return -1; } ((int*)param->dst)[param->dsti] = v; param->dsti++; } }else{ v = bool_check(pstart); if (v < 0) { DERROR("conf error, %s must yes/no true/false at line:%d\n", param->name, lineno); fclose(f); return -1; } *(int*)param->dst = v; } break; } case CONF_ENUM: { // 枚举只能是整型 int v = 0; if (param->arraysize) { while ((item = find_array_item(pstart, &tmp)) != NULL) { if (enum_check(param, pstart, &v) == FALSE) { DERROR("conf error, %s value error at line:%d\n", param->name, lineno); fclose(f); return -1; } ((int*)param->dst)[param->dsti] = v; param->dsti++; } }else{ if (enum_check(param, pstart, &v) == FALSE) { DERROR("conf error, %s value error at line:%d\n", param->name, lineno); fclose(f); return -1; } *(int*)param->dst = v; } break; } case CONF_USER: { if (param->arraysize) { while ((item = find_array_item(pstart, &tmp)) != NULL) { if (param->param.userfunc(param->dst, item, param->dsti) == FALSE) { DERROR("conf error, %s value error at line:%d\n", param->name, lineno); fclose(f); return -1; } //((int*)param->dst)[param->dsti] = v; param->dsti++; } }else{ if (param->param.userfunc(param->dst, pstart, 0) == FALSE) { DERROR("conf error, %s value error at line:%d\n", param->name, lineno); fclose(f); return -1; } //*(int*)param->dst = v; } break; } default: DERROR("conf param type error at %s with type:%d\n", param->name, param->type); fclose(f); return -1; } break; } param = param->next; } } fclose(f); return 0; }