Skip to content

Commit 2311449

Browse files
committed
[RFTraces] Switch to libc's getline() to parse frequencies.txt, resolving some weird issues with long lines in the file.
Also empty lines are now skipped instead of making the abort the parsing. Signed-off-by: Martin Herren (HB9FXX) <[email protected]>
1 parent ca8952e commit 2311449

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

rftrace.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <stdio.h>
22
#include <string.h>
33
#include <math.h>
4+
#include <stdio.h>
45
#include <stdlib.h>
56
#include "sgdp4h.h"
67
#include "satutl.h"
@@ -516,7 +517,8 @@ struct trace *compute_trace(char *tlefile,double *mjd,int n,int site_id,float fr
516517
xyz_t satpos,satvel;
517518
double dx,dy,dz,dvx,dvy,dvz,r,v,za,vg;
518519
double freq0,dfreq;
519-
char line[LIM];
520+
char * line = NULL;
521+
size_t line_size = 0;
520522
struct trace *t;
521523
float fmin,fmax;
522524
double ra,de,azi,alt;
@@ -540,10 +542,12 @@ struct trace *compute_trace(char *tlefile,double *mjd,int n,int site_id,float fr
540542
return NULL;
541543
} else {
542544
for (i=0;;) {
543-
if (fgetline(infile,line,LIM)<=0)
544-
break;
545-
if (line[0]=='#')
546-
continue;
545+
if (getline(&line, &line_size, infile) < 0)
546+
break;
547+
548+
if ((line[0] == '\n') || (line[0] == '#'))
549+
continue;
550+
547551
status=sscanf(line,"%d %lf",&satno,&freq0);
548552

549553
if (status != 2) {
@@ -560,6 +564,12 @@ struct trace *compute_trace(char *tlefile,double *mjd,int n,int site_id,float fr
560564
fclose(infile);
561565
*nsat=i;
562566
}
567+
568+
// Free allocated buffer by getline() as we might return NULL
569+
// before next call to to getline()
570+
free(line);
571+
line = NULL;
572+
563573
// Break out
564574
if (i==0)
565575
{
@@ -603,10 +613,10 @@ struct trace *compute_trace(char *tlefile,double *mjd,int n,int site_id,float fr
603613

604614
infile=fopen(freqlist,"r");
605615
for (j=0;;) {
606-
if (fgetline(infile,line,LIM)<=0)
616+
if (getline(&line, &line_size, infile) < 0)
607617
break;
608618

609-
if (line[0] == '#')
619+
if ((line[0] == '\n') || (line[0] == '#'))
610620
continue;
611621

612622
status=sscanf(line,"%d %lf",&satno,&freq0);
@@ -702,6 +712,8 @@ struct trace *compute_trace(char *tlefile,double *mjd,int n,int site_id,float fr
702712
fclose(stderr);
703713

704714
// Free
715+
free(line);
716+
line = NULL;
705717

706718
free_tles(tle_array);
707719
free(p);

0 commit comments

Comments
 (0)