struct osmo_config_list *osmo_config_list_parse(void *ctx, const char *filename)
{
	struct osmo_config_list *entries;
	size_t n;
	char *line;
	FILE *file;

	file = fopen(filename, "r");
	if (!file)
		return NULL;

	entries = alloc_entries(ctx);
	if (!entries) {
		fclose(file);
		return NULL;
	}

	n = 2342;
	line = NULL;
        while (getline(&line, &n, file) != -1) {
		handle_line(entries, line);
		free(line);
		line = NULL;
	}

	fclose(file);
	return entries;
}
Esempio n. 2
0
int main(){
  int i, j, char_index, field, row, test, ntests = 10;
  Ledger *ledger = NULL;
  char **strs;

  strs = malloc(ntests * sizeof(char*));
  for(i = 0; i < ntests; ++i)
    strs[i] = calloc(2000, sizeof(char));

  strcpy(strs[0], L0);
  strcpy(strs[1], L1);
  strcpy(strs[2], L2);
  strcpy(strs[3], L3);
  strcpy(strs[4], L4);
  strcpy(strs[5], L5);
  strcpy(strs[6], L6);
  strcpy(strs[7], L7);
  strcpy(strs[8], L8);
  strcpy(strs[9], L9);
    
  for(test = 0; test < ntests; ++test){
    printf("\n--------\nTEST %d\n", test);
    new_ledger(&ledger);
    ledger->nrows = 1;
    for(i = 0; i < strlen(strs[test]); ++i)
      if(strs[test][i] == '\n' || strs[test][i] == '\r')
        ++ledger->nrows;
    alloc_entries(ledger);
    
    char_index = 0;
    field = 0;
    row = 0; 
 
    for(j = 0; j < strlen(strs[test]); ++i){
      parse_char(ledger, strs[test][j], &char_index, &field, &row);
      ++j;
    }
    
    printf("\nENTRIES BEFORE %d\n\n", test);
 
 
    for(j = 0; j < ledger->nrows; ++j){   
      for(i = 0; i < NFIELDS - 1; ++i)
        printf("%s\t", ledger->entries[i][j]);
      printf("%s", ledger->entries[NFIELDS - 1][j]); 
      printf("\n");     
    }
    
    
    printf("\nENTRIES AFTER %d\n\n", test);
    strip_ledger(ledger);
 
    for(j = 0; j < ledger->nrows; ++j){   
      for(i = 0; i < NFIELDS - 1; ++i)
        printf("%s\t", ledger->entries[i][j]);
      printf("%s", ledger->entries[NFIELDS - 1][j]); 
      printf("\n");     
    }
    
    free_ledger(&ledger);
  }  

  for(test = 0; test < ntests; ++test)
    free(strs[test]);
  free(strs);

  return 0;
}