Skip to content
This repository was archived by the owner on Aug 10, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/libpiano/piano.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ PianoStation_t *PianoFindStationById (PianoStation_t *stations,
return NULL;
}

/* get station from list by name
* @param search here
* @param search for this
* @return the first station structure matching the given name
*/
PianoStation_t *PianoFindStationByName (PianoStation_t *stations,
const char *searchStation) {
while (stations != NULL) {
if (strncmp (stations->name, searchStation, sizeof(searchStation)) == 0) {
return stations;
}
stations = stations->next;
}
return NULL;
}

/* convert return value to human-readable string
* @param enum
* @return error string
Expand Down
1 change: 1 addition & 0 deletions src/libpiano/piano.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *, PianoRequest_t *);
void PianoDestroyRequest (PianoRequest_t *);

PianoStation_t *PianoFindStationById (PianoStation_t *, const char *);
PianoStation_t *PianoFindStationByName (PianoStation_t *, const char *);
const char *PianoErrorToStr (PianoReturn_t);

#endif /* _PIANO_H */
9 changes: 7 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,13 @@ static void BarMainGetInitialStation (BarApp_t *app) {
app->curStation = PianoFindStationById (app->ph.stations,
app->settings.autostartStation);
if (app->curStation == NULL) {
BarUiMsg (&app->settings, MSG_ERR,
"Error: Autostart station not found.\n");
//try by name
app->curStation = PianoFindStationByName (app->ph.stations,
app->settings.autostartStation);
if (app->curStation == NULL) {
BarUiMsg (&app->settings, MSG_ERR,
"Error: Autostart station not found. '%s'\n", app->settings.autostartStation);
}
}
}
/* no autostart? ask the user */
Expand Down