mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
[smtk-import] Apply arrays to parsing tables functions
And add a fuction to parse tables that are not "relational", meaning tables which are directly refered from Dives table. Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
This commit is contained in:
parent
856848466a
commit
650b198715
1 changed files with 48 additions and 46 deletions
|
@ -623,25 +623,26 @@ static int get_rows_num(MdbHandle *mdb, char *table_name)
|
||||||
* be using some other like Vendor (in Gear) or Latin name (in Fish). I'll take a look at this
|
* be using some other like Vendor (in Gear) or Latin name (in Fish). I'll take a look at this
|
||||||
* in the future, may be something like Buddy table...
|
* in the future, may be something like Buddy table...
|
||||||
*/
|
*/
|
||||||
static void smtk_build_list(MdbHandle *mdb, char *table_name, struct types_list **head)
|
static void smtk_build_list(MdbHandle *mdb, char *table_name, char *array[])
|
||||||
{
|
{
|
||||||
MdbTableDef *table;
|
MdbTableDef *table;
|
||||||
MdbColumn *col[MDB_MAX_COLS];
|
MdbColumn *col[MDB_MAX_COLS];
|
||||||
char *bound_values[MDB_MAX_COLS];
|
char *bound_values[MDB_MAX_COLS], *str;
|
||||||
struct types_list *p = NULL;
|
|
||||||
|
|
||||||
table = smtk_open_table(mdb, table_name, col, bound_values);
|
table = smtk_open_table(mdb, table_name, col, bound_values);
|
||||||
if (!table)
|
if (!table)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Read the table items into an structured list */
|
/* Read the table items into the array. Array size has been previously checked
|
||||||
while (mdb_fetch_row(table))
|
* and allocated, so overflow is not expected */
|
||||||
smtk_head_insert(&p, atoi(col[0]->bind_ptr), copy_string(col[1]->bind_ptr));
|
while (mdb_fetch_row(table)) {
|
||||||
*head = p;
|
str = col[1]->bind_ptr;
|
||||||
|
if (str && (!strcmp(str, "---") || !strcmp(str, "--")))
|
||||||
|
str = NULL;
|
||||||
|
array[atoi(col[0]->bind_ptr) - 1] = copy_string(str);
|
||||||
|
}
|
||||||
|
|
||||||
/* clean up and exit */
|
/* clean up and exit */
|
||||||
p = NULL;
|
|
||||||
free(p);
|
|
||||||
smtk_free(bound_values, table->num_cols);
|
smtk_free(bound_values, table->num_cols);
|
||||||
mdb_free_tabledef(table);
|
mdb_free_tabledef(table);
|
||||||
}
|
}
|
||||||
|
@ -686,11 +687,10 @@ static struct types_list *smtk_index_list(MdbHandle *mdb, char *table_name, char
|
||||||
* Buddy table format:
|
* Buddy table format:
|
||||||
* | Idx | Text (nickname) | Name | Firstname | Middlename | Title | Picture | Phone | ...
|
* | Idx | Text (nickname) | Name | Firstname | Middlename | Title | Picture | Phone | ...
|
||||||
*/
|
*/
|
||||||
static void smtk_build_buddies(MdbHandle *mdb, struct types_list **buddies_head) {
|
static void smtk_build_buddies(MdbHandle *mdb, char *array[]) {
|
||||||
MdbTableDef *table;
|
MdbTableDef *table;
|
||||||
MdbColumn *col[MDB_MAX_COLS];
|
MdbColumn *col[MDB_MAX_COLS];
|
||||||
char *bound_values[MDB_MAX_COLS], *fullname = NULL, *str = NULL;
|
char *bound_values[MDB_MAX_COLS], *fullname = NULL, *str = NULL;
|
||||||
struct types_list *p = NULL;
|
|
||||||
|
|
||||||
table = smtk_open_table(mdb, "Buddy", col, bound_values);
|
table = smtk_open_table(mdb, "Buddy", col, bound_values);
|
||||||
if (!table)
|
if (!table)
|
||||||
|
@ -704,16 +704,13 @@ static void smtk_build_buddies(MdbHandle *mdb, struct types_list **buddies_head)
|
||||||
if (!empty_string(col[2]->bind_ptr))
|
if (!empty_string(col[2]->bind_ptr))
|
||||||
fullname = smtk_concat_str(fullname, " ", "%s", col[2]->bind_ptr);
|
fullname = smtk_concat_str(fullname, " ", "%s", col[2]->bind_ptr);
|
||||||
if (fullname && !same_string(col[1]->bind_ptr, fullname))
|
if (fullname && !same_string(col[1]->bind_ptr, fullname))
|
||||||
smtk_head_insert(&p, atoi(col[0]->bind_ptr), smtk_concat_str(str, "", "%s (%s)", col[1]->bind_ptr, fullname));
|
array[atoi(col[0]->bind_ptr) - 1] = smtk_concat_str(str, "", "%s (%s)", col[1]->bind_ptr, fullname);
|
||||||
else
|
else
|
||||||
smtk_head_insert(&p, atoi(col[0]->bind_ptr), smtk_concat_str(str, "", "%s", col[1]->bind_ptr));
|
array[atoi(col[0]->bind_ptr) - 1] = smtk_concat_str(str, "", "%s", col[1]->bind_ptr);
|
||||||
free(fullname);
|
free(fullname);
|
||||||
fullname = NULL;
|
fullname = NULL;
|
||||||
}
|
}
|
||||||
*buddies_head = p;
|
|
||||||
|
|
||||||
p = NULL;
|
|
||||||
free(p);
|
|
||||||
free(str);
|
free(str);
|
||||||
smtk_free(bound_values, table->num_cols);
|
smtk_free(bound_values, table->num_cols);
|
||||||
mdb_free_tabledef(table);
|
mdb_free_tabledef(table);
|
||||||
|
@ -722,25 +719,17 @@ static void smtk_build_buddies(MdbHandle *mdb, struct types_list **buddies_head)
|
||||||
/*
|
/*
|
||||||
* Returns string with buddies names as registered in smartrak (may be a nickname).
|
* Returns string with buddies names as registered in smartrak (may be a nickname).
|
||||||
*/
|
*/
|
||||||
static char *smtk_locate_buddy(MdbHandle *mdb, char *dive_idx, struct types_list *buddies_head)
|
static char *smtk_locate_buddy(MdbHandle *mdb, char *dive_idx, char *buddies_list[])
|
||||||
{
|
{
|
||||||
char *str = NULL;
|
char *str = NULL;
|
||||||
struct types_list *rel, *rel_head, *bud;
|
struct types_list *rel, *rel_head;
|
||||||
|
|
||||||
rel_head = smtk_index_list(mdb, "BuddyRelation", dive_idx);
|
rel_head = smtk_index_list(mdb, "BuddyRelation", dive_idx);
|
||||||
if (!rel_head)
|
if (!rel_head)
|
||||||
return str;
|
return str;
|
||||||
|
|
||||||
for (rel = rel_head; rel; ) {
|
for (rel = rel_head; rel; rel = rel->next)
|
||||||
for (bud = buddies_head; bud; ) {
|
str = smtk_concat_str(str, ", ", "%s", buddies_list[rel->idx - 1]);
|
||||||
if (bud->idx == rel->idx) {
|
|
||||||
str = smtk_concat_str(str, ", ", "%s", bud->text);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
bud = bud->next;
|
|
||||||
}
|
|
||||||
rel = rel->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clean up and exit */
|
/* Clean up and exit */
|
||||||
smtk_list_free(rel_head);
|
smtk_list_free(rel_head);
|
||||||
|
@ -753,36 +742,49 @@ static char *smtk_locate_buddy(MdbHandle *mdb, char *dive_idx, struct types_list
|
||||||
* The "tag" parameter is used to mark if we want this table to be imported
|
* The "tag" parameter is used to mark if we want this table to be imported
|
||||||
* into tags or into notes.
|
* into tags or into notes.
|
||||||
*/
|
*/
|
||||||
static void smtk_parse_relations(MdbHandle *mdb, struct dive *dive, char *dive_idx, char *table_name, char *rel_table_name, struct types_list *list, bool tag)
|
static void smtk_parse_relations(MdbHandle *mdb, struct dive *dive, char *dive_idx, char *table_name, char *rel_table_name, char *list[], bool tag)
|
||||||
{
|
{
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
struct types_list *diverel_head, *d_runner, *t_runner;
|
struct types_list *diverel_head, *d_runner;
|
||||||
|
|
||||||
diverel_head = smtk_index_list(mdb, rel_table_name, dive_idx);
|
diverel_head = smtk_index_list(mdb, rel_table_name, dive_idx);
|
||||||
if (!diverel_head)
|
if (!diverel_head)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Get the text associated with the relations */
|
/* Get the text associated with the relations */
|
||||||
for (d_runner = diverel_head; d_runner; ) {
|
for (d_runner = diverel_head; d_runner; d_runner = d_runner->next) {
|
||||||
for (t_runner = list; t_runner; ) {
|
if (tag)
|
||||||
if (t_runner->idx == d_runner->idx) {
|
taglist_add_tag(&dive->tag_list, list[d_runner->idx - 1]);
|
||||||
if (tag)
|
else
|
||||||
taglist_add_tag(&dive->tag_list, t_runner->text);
|
tmp = smtk_concat_str(tmp, ", ", "%s", list[d_runner->idx - 1]);
|
||||||
else
|
if (strstr(list[d_runner->idx - 1], "SCR"))
|
||||||
tmp = smtk_concat_str(tmp, ", ", "%s", t_runner->text);
|
dive->dc.divemode = PSCR;
|
||||||
if (strstr(t_runner->text, "SCR"))
|
else if (strstr(list[d_runner->idx -1], "CCR"))
|
||||||
dive->dc.divemode = PSCR;
|
dive->dc.divemode = CCR;
|
||||||
else if (strstr(t_runner->text, "CCR"))
|
|
||||||
dive->dc.divemode = CCR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
t_runner = t_runner->next;
|
|
||||||
}
|
|
||||||
d_runner = d_runner->next;
|
|
||||||
}
|
}
|
||||||
if (tmp)
|
if (tmp)
|
||||||
dive->notes = smtk_concat_str(dive->notes, "\n", "Smartrak %s: %s", table_name, tmp);
|
dive->notes = smtk_concat_str(dive->notes, "\n", "Smartrak %s: %s", table_name, tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
smtk_list_free(diverel_head);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add data from tables related in Dives table which are not directly supported
|
||||||
|
* in Subsurface. Write them as tags or dive notes by setting true or false the
|
||||||
|
* boolean parameter "tag".
|
||||||
|
*/
|
||||||
|
static void smtk_parse_other(struct dive *dive, char *list[], char *data_name, char *idx, bool tag)
|
||||||
|
{
|
||||||
|
int i = atoi(idx) - 1;
|
||||||
|
char *str = NULL;
|
||||||
|
|
||||||
|
str = list[i];
|
||||||
|
if (str) {
|
||||||
|
if (tag)
|
||||||
|
taglist_add_tag(&dive->tag_list, str);
|
||||||
|
else
|
||||||
|
dive->notes = smtk_concat_str(dive->notes, "\n", "Smartrak %s: %s", data_name, str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Reference in a new issue