Skip to content

Commit

Permalink
Update g2ccsv.c
Browse files Browse the repository at this point in the history
  • Loading branch information
AlysonStahl-NOAA committed Aug 7, 2024
1 parent 99c9eeb commit cca3294
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions src/g2ccsv.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ g2c_find_entry(char *desc, G2C_CODE_TABLE_T *table)
int
g2c_csv_init()
{
size_t max_line_size = 500;
const int num_columns = 9;
int i,j;
char *buf, *tmp, *key;
char line[max_line_size];
const int max_line_size = 500;
const int num_columns = 9;
int i,j;
char *buf, *tmp, *key;
char line[max_line_size];
G2C_CODE_TABLE_T *my_table = NULL;
G2C_CODE_ENTRY_T *new_entry = NULL;

Expand Down Expand Up @@ -233,18 +233,41 @@ g2c_csv_init()

if (i==0)
{
if (strlen(key) > G2C_MAX_GRIB_TITLE_LEN)
return G2C_ENAMETOOLONG;
if (!(my_table = g2c_find_table(key)))
{
if (!(new_table = calloc(1,sizeof(G2C_CODE_TABLE_T))))
return G2C_ENOMEM;
strncpy(new_table->title, key,G2C_MAX_GRIB_TITLE_LEN);
my_table = new_table;
}
if (strlen(key) > G2C_MAX_GRIB_TITLE_LEN)
return G2C_ENAMETOOLONG;
if (!(my_table = g2c_find_table(key)))
{
if (!(new_table = calloc(1,sizeof(G2C_CODE_TABLE_T))))
return G2C_ENOMEM;
strncpy(new_table->title, key,G2C_MAX_GRIB_TITLE_LEN);
my_table = new_table;
}
}

free(key);

if (my_table)
{
if (i==2)
{
G2C_CODE_ENTRY_T *e;

if (!(new_entry = calloc(1,sizeof(G2C_CODE_ENTRY_T))))
return G2C_ENOMEM;
if (strlen(key) > G2C_MAX_GRIB_CODE_LEN)
return G2C_ENAMETOOLONG;
strncpy(new_entry->code,key,G2C_MAX_GRIB_CODE_LEN);

/* Add entry at end of list. */
if (my_table->entry)
{
for (e = my_table->entry; e->next; e = e->next);
e->next = new_entry;
}
else
my_table->entry = new_entry;
}
}

free(key);
i++;
}

Expand Down

0 comments on commit cca3294

Please sign in to comment.