Skip to content

Commit

Permalink
Add error/warning if site is missing/duplicate from sites.txt
Browse files Browse the repository at this point in the history
Previously a missing site / wrongly configured sites.txt was a common
source of frustration for me.
  • Loading branch information
kerel-fs authored and cbassa committed Jan 16, 2023
1 parent 84f526c commit 0c07ce5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions rfsites.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// Get observing site
site_t get_site(int site_id) {
int i=0,status;
int count = 0;
char line[LIM];
FILE *file;
int id;
Expand All @@ -27,12 +28,12 @@ site_t get_site(int site_id) {
if (env_sites_txt == NULL || strlen(env_sites_txt) == 0) {
sprintf(filename, "%s/data/sites.txt", env_datadir);
} else {
sprintf(filename, "%s", env_datadir);
sprintf(filename, "%s", env_sites_txt);
}

file=fopen(filename,"r");
if (file==NULL) {
printf("File with site information not found!\n");
printf("File with site information not count!\n");
exit(0);
}
while (fgets(line,LIM,file)!=NULL) {
Expand All @@ -53,6 +54,7 @@ site_t get_site(int site_id) {

// Copy site
if (id==site_id) {
count += 1;
s.lat=lat;
s.lng=lng;
s.alt=alt;
Expand All @@ -63,5 +65,12 @@ site_t get_site(int site_id) {
}
fclose(file);

if (count == 0) {
printf("Error: Site %d was not found in sites.txt!", site_id);
exit(-1);
} else if (count > 1) {
printf("Site %d was found multiple times in sites.txt, use last occurence.", site_id);
}

return s;
}

0 comments on commit 0c07ce5

Please sign in to comment.