static int config_module(void) { struct module_info mi; int ret; memset(&mi, 0, sizeof(mi)); ret = csv_load("modules.csv", &mi, mi_field, mi_row_end); mi_free(&mi); return ret; }
/* load service paths */ static int config_service(void) { struct service_info si; int ret; memset(&si, 0, sizeof(si)); ret = csv_load("services.csv", &si, si_field, si_row_end); si_free(&si); return ret; }
/* load bind address and domains */ static int config_port(void) { struct port_info pi; int ret; memset(&pi, 0, sizeof(pi)); ret = csv_load("ports.csv", &pi, pi_field, pi_row_end); pi_free(&pi); return ret; }
int sp_csv_filter_load_table(sp_csv_filter_t *self) { return csv_load(self->table, self->input); }
/* Function: load_database * ----------------------- * Copies data from the given database file. * * Returns: * 0: success * 1: cannot find the given file * 2: database file is corrupted */ static int load_database(R2RDatabase *data) { int retval = 0; size_t temp_len = 3; char *temp = g_malloc(temp_len + 1); if (temp == NULL) return 1; //insufficient memory char full_path[data->filename_len + path_len + 1]; strcpy(full_path, path); strcat(full_path, data->filename); CSV_BUFFER *buffer = csv_create_buffer(); if (csv_load(buffer, full_path) != 0) { retval = 1; printf("filenotfound\n"); goto end; } /* Load header info: * Database name * Units preference * Number of entries (runs) */ data->name_len = csv_get_field_length(buffer, 0, 0); data->name = g_malloc(data->name_len + 1); csv_get_field(data->name, data->name_len, buffer, 0, 0); csv_get_field(temp, temp_len, buffer, 0, 1); data->units = strtol(temp, NULL, 10); data->nruns = csv_get_height(buffer) - 1; /* Create body space */ int i, j; data->run = g_malloc(data->nruns * sizeof(R2RRun*)); for (i = 0; i < data->nruns; i++) data->run[i] = g_malloc(sizeof(R2RRun)); /* Load body */ for (i = 1; i < data->nruns + 1; i++) { for (j = 0; j < NFIELDS; j++) { if (csv_get_field_length(buffer, i, j) > temp_len) temp_len = csv_get_field_length(buffer, i, j); if (csv_get_field_length(buffer, i, j) == 0 ) printf("%i,%i\n", i,j); } } char *temp_temp = realloc(temp, temp_len + 1); if (temp_temp == NULL) { g_free(temp); return 1; // insufficient memory } else temp = temp_temp; for (i = 0; i < data->nruns; i++) { csv_get_field(temp, temp_len, buffer, i+1, 0); data->run[i]->year = strtol(temp, NULL, 10); csv_get_field(temp, temp_len, buffer, i+1, 1); data->run[i]->month = strtol(temp, NULL, 10); csv_get_field(temp, temp_len, buffer, i+1, 2); data->run[i]->day = strtol(temp, NULL, 10); csv_get_field(temp, temp_len, buffer, i+1, 3); data->run[i]->run_n = strtol(temp, NULL, 10); csv_get_field(temp, temp_len, buffer, i+1, 4); data->run[i]->distance = strtof(temp, NULL); csv_get_field(temp, temp_len, buffer, i+1, 5); data->run[i]->duration= strtof(temp, NULL); data->run[i]->type_len = csv_get_field_length(buffer, i+1, 6); data->run[i]->type = g_malloc(data->run[i]->type_len + 1); csv_get_field(data->run[i]->type, data->run[i]->type_len, buffer, i+1, 6); csv_get_field(temp, temp_len, buffer, i+1, 7); data->run[i]->feel = strtol(temp, NULL, 10); csv_get_field(temp, temp_len, buffer, i+1, 8); data->run[i]->time = strtol(temp, NULL, 10); data->run[i]->route_len = csv_get_field_length(buffer, i+1, 9); data->run[i]->route = g_malloc(data->run[i]->route_len + 1); csv_get_field(data->run[i]->route, data->run[i]->route_len, buffer, i+1, 9); data->run[i]->notes_len = csv_get_field_length(buffer, i+1, 10); data->run[i]->notes = g_malloc(data->run[i]->notes_len + 1); csv_get_field(data->run[i]->notes, data->run[i]->notes_len, buffer, i+1, 10); } end: csv_destroy_buffer(buffer); g_free(temp); return 0; }