Different is different from the same (fix silly bug in nickname handling)

Trying to simplify the API for nickname handling I went a bit too far. We
indeed need to different API calls, one that returns an entry in the
nicknamelist for the deviceid that we have. And one that looks if there is
an entry for a different deviceid but the same model that we have.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2012-12-23 09:06:23 -08:00
parent 06cd494a2f
commit 1bd6f72d31

View file

@ -2063,7 +2063,7 @@ const char *get_dc_nickname(uint32_t deviceid)
} }
/* do we have a DIFFERENT divecomputer of the same model? */ /* do we have a DIFFERENT divecomputer of the same model? */
static struct dcnicknamelist *get_dc_nicknameentry(const char *model, int deviceid) static struct dcnicknamelist *get_different_dc_nicknameentry(const char *model, int deviceid)
{ {
struct dcnicknamelist *known = nicknamelist; struct dcnicknamelist *known = nicknamelist;
while (known) { while (known) {
@ -2075,6 +2075,18 @@ static struct dcnicknamelist *get_dc_nicknameentry(const char *model, int device
return NULL; return NULL;
} }
/* just fine the entry for this divecomputer */
static struct dcnicknamelist *get_dc_nicknameentry(int deviceid)
{
struct dcnicknamelist *known = nicknamelist;
while (known) {
if (known->deviceid == deviceid)
return known;
known = known->next;
}
return NULL;
}
/* no curly braces or commas, please */ /* no curly braces or commas, please */
static char *cleanedup_nickname(const char *nickname, int len) static char *cleanedup_nickname(const char *nickname, int len)
{ {
@ -2168,7 +2180,7 @@ void remember_dc(uint32_t deviceid, const char *model, const char *nickname, gbo
subsurface_set_conf("dc_nicknames", PREF_STRING, nicknamestring); subsurface_set_conf("dc_nicknames", PREF_STRING, nicknamestring);
} else { } else {
/* modify existing entry */ /* modify existing entry */
struct dcnicknamelist *nn_entry = get_dc_nicknameentry(model, deviceid); struct dcnicknamelist *nn_entry = get_dc_nicknameentry(deviceid);
if (!nn_entry->model || !*nn_entry->model) if (!nn_entry->model || !*nn_entry->model)
nn_entry->model = model; nn_entry->model = model;
nn_entry->nickname = nickname; nn_entry->nickname = nickname;
@ -2201,7 +2213,7 @@ void set_dc_nickname(struct dive *dive)
fprintf(debugfile, "set_dc_nickname for model %s deviceid %8x\n", dc->model ? : "", dc->deviceid); fprintf(debugfile, "set_dc_nickname for model %s deviceid %8x\n", dc->model ? : "", dc->deviceid);
#endif #endif
if (get_dc_nickname(dc->deviceid) == NULL) { if (get_dc_nickname(dc->deviceid) == NULL) {
struct dcnicknamelist *nn_entry = get_dc_nicknameentry(dc->model, dc->deviceid); struct dcnicknamelist *nn_entry = get_different_dc_nicknameentry(dc->model, dc->deviceid);
if (!nn_entry) { if (!nn_entry) {
/* just remember the dive computer without setting a nickname */ /* just remember the dive computer without setting a nickname */
if (dc->model) if (dc->model)