-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrfopen.c
91 lines (81 loc) · 3.4 KB
/
rfopen.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
Copyright 2004-2005,2009 Ronald S. Burkey <[email protected]>
This file is part of yaAGC.
yaAGC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
yaAGC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with yaAGC; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
In addition, as a special exception, Ronald S. Burkey gives permission to
link the code of this program with the Orbiter SDK library (or with
modified versions of the Orbiter SDK library that use the same license as
the Orbiter SDK library), and distribute linked combinations including
the two. You must obey the GNU General Public License in all respects for
all of the code used other than the Orbiter SDK library. If you modify
this file, you may extend this exception to your version of the file,
but you are not obligated to do so. If you do not wish to do so, delete
this exception statement from your version.
Filename: rfopen.c
Purpose: A replacement for fopen which looks in the installation
directory if the file isn't in the current directory.
Compiler: GNU gcc.
Contact: Ron Burkey <[email protected]>
Reference: http://www.ibiblio.org/apollo/index.html
Mods: 05/06/04 RSB. Began.
05/14/04 RSB. Added INSTALLDIR.
05/30/04 RSB Added some missing header files.
08/11/04 RSB Default install dir in Win32 changed
(from /usr/local/bin) to c:/mingw/bin.
02/27/05 RSB Added the license exception, as required by
the GPL, for linking to Orbiter SDK libraries.
05/14/05 RSB Corrected website references
03/12/09 RSB Change of initializer for InstallationPath
to avoid a compiler warning.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "agc_engine.h"
//---------------------------------------------------------------------------
// My feeble attempt at looking for stuff like Luminary131.bin or LM.ini in
// the installation directory if not found in the current directory.
// This default probably looks right only for *nix, and not for Win32,
// we also use this directory in Win32 because the build-instructions
// assume the use of Msys (which is the mingw32 compiler's cygwin-like
// environment), so there actually is a /usr/local/bin directory in
// both cases.
#ifndef INSTALLDIR
#ifdef WIN32
#define INSTALLDIR "c:/mingw/bin"
#else
#define INSTALLDIR "/usr/local/bin"
#endif
#endif
static char DefaultInstallationPath[] = INSTALLDIR;
char *InstallationPath = DefaultInstallationPath;
FILE *
rfopen (const char *Filename, const char *mode)
{
char *NewFilename;
FILE *fp;
//printf ("\'%s\'\n", INSTALLDIR);
fp = fopen (Filename, mode);
if (fp != NULL)
return (fp);
NewFilename =
(char *) malloc (2 + strlen (Filename) + strlen (InstallationPath));
if (NewFilename == NULL)
return (NULL);
strcpy (NewFilename, InstallationPath);
strcat (NewFilename, "/");
strcat (NewFilename, Filename);
fp = fopen (NewFilename, mode);
free (NewFilename);
return (fp);
}