-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathsat_util.c
61 lines (53 loc) · 1.23 KB
/
sat_util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "sat_util.h"
char *fgets_trimmed( char *buff, const int buffsize, FILE *ifile)
{
char *rval = fgets( buff, buffsize, ifile);
if( rval)
{
size_t i = 0;
while( rval[i] != 10 && rval[i] != 13 && rval[i])
i++;
while( i && rval[i - 1] == ' ')
i--; /* drop trailing spaces */
rval[i] = '\0';
}
return( rval);
}
#if !defined( _WIN32)
void make_config_dir_name( char *oname, const char *iname)
{
#ifdef ON_LINE_VERSION
strcpy( oname, getenv( "DOCUMENT_ROOT"));
strcat( oname, "/");
#else
const char *home_dir = getenv( "HOME");
if( home_dir)
{
strcpy( oname, home_dir);
strcat( oname, "/.find_orb/");
}
else
*oname = '\0';
#endif
strcat( oname, iname);
}
FILE *local_then_config_fopen( const char *filename, const char *permits)
{
FILE *rval = fopen( filename, permits);
if( !rval)
{
char ext_filename[255];
make_config_dir_name( ext_filename, filename);
rval = fopen( ext_filename, "rb");
}
return( rval);
}
#else
FILE *local_then_config_fopen( const char *filename, const char *permits)
{
return( fopen( filename, permits));
}
#endif