[Gpredict-svn] SF.net SVN: gpredict:[907] trunk
Real time satellite tracking and orbit prediction
Status: Beta
Brought to you by:
csete
|
From: <aa...@us...> - 2011-09-25 13:04:59
|
Revision: 907
http://gpredict.svn.sourceforge.net/gpredict/?rev=907&view=rev
Author: aa1vs
Date: 2011-09-25 13:04:53 +0000 (Sun, 25 Sep 2011)
Log Message:
-----------
Fix bugs in tle-update for two line tle's at end of the file.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/tle-update.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2011-09-24 12:02:30 UTC (rev 906)
+++ trunk/ChangeLog 2011-09-25 13:04:53 UTC (rev 907)
@@ -1,3 +1,10 @@
+2011-09-25 Charles Suprin <hamaa1vs at gmail.com>
+
+ * ChangeLog
+ * src/tle-update.c
+ Fix bugs in tle-update for two line tle's at end of file.
+
+
2011-09-22 Charles Suprin <hamaa1vs at gmail.com>
* ChangeLog
Modified: trunk/src/tle-update.c
===================================================================
--- trunk/src/tle-update.c 2011-09-24 12:02:30 UTC (rev 906)
+++ trunk/src/tle-update.c 2011-09-25 13:04:53 UTC (rev 907)
@@ -796,8 +796,20 @@
gchar category[80];
gboolean catsync = FALSE; /* whether .cat file should be synced */
+ /*
+ Normal cases to check
+ 1. 3 line tle file as in amatuer.txt from celestrak
+ 2. 2 line tle file as in .... from celestrak
+ corner cases to check
+ 1. 3 line tle with something at the end. (nasa.all from amsat)
+ 2. 2 line tle with only one in the file
+ 3. 2 line tle file reading the last one.
+ */
+
+
+
path = g_strconcat (dir, G_DIR_SEPARATOR_S, fnam, NULL);
fp = g_fopen (path, "r");
@@ -847,6 +859,8 @@
satellite catnums will be added during update in the while loop */
}
+ /* set b to non-null as a flag */
+ b = 1;
/* read lines from tle file */
while (fgets (linetmp, 80, fp)) {
@@ -854,13 +868,31 @@
switch (linesneeded) {
case 3:
strncpy(tle_working[0],linetmp,80);
+ /* b is being used a flag here
+ if b==NULL then we only have one line read in
+ and there is no way we have a full tle as there
+ is only one line in the buffer.
+ A TLE must be two or three lines.
+ */
b = fgets (tle_working[1], 80, fp);
- b = fgets (tle_working[2], 80, fp);
+ if (b==NULL) {
+ /* make sure there is no junk in tle_working[1] */
+ tle_working[1][0]='\0';
+ break;
+ }
+ /* make sure there is no junk in tle_working[2] */
+ if (fgets (tle_working[2], 80, fp)==NULL) {
+ tle_working[2][0]='\0';
+ }
+
break;
case 2:
strncpy(tle_working[0],tle_working[2],80);
strncpy(tle_working[1],linetmp,80);
- b = fgets (tle_working[2], 80, fp);
+ /* make sure there is no junk in tle_working[2] */
+ if (fgets (tle_working[2], 80, fp)==NULL) {
+ tle_working[2][0]='\0';
+ }
break;
case 1:
strncpy(tle_working[0],tle_working[1],80);
@@ -873,6 +905,11 @@
__FILE__, __FUNCTION__, linesneeded);
break;
}
+ /* b can only be null if there is only one line in the buffer*/
+ /* a tle must be two or three */
+ if (b == NULL) {
+ break;
+ }
/* remove leading and trailing whitespace to be more forgiving */
g_strstrip(tle_working[0]);
g_strstrip(tle_working[1]);
@@ -929,6 +966,7 @@
/* we appear to have junk
read another line in and do nothing else */
linesneeded = 1;
+ /* skip back to beginning of loop */
continue;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|