MCPcopy Create free account
hub / github.com/CruiserOne/Astrolog / FileOpen

Function FileOpen

io.cpp:73–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71// various locations and directories for the file before giving up.
72
73FILE *FileOpen(CONST char *szFile, int nFileMode, char *szPath)
74{
75 FILE *file;
76 char szFileT[cchSzMax], szExe[cchSzMax], sz[cchSzMax], szMode[3], *pch;
77 CONST char *pch2;
78#ifdef ENVIRON
79 char *env;
80#endif
81 int i, j;
82
83 // Some file types we want to open as binary instead of Ascii.
84 sprintf(szMode, "r%s", nFileMode >= 2 ? "b" : "");
85 // Get directory containing Astrolog executable.
86#ifdef WIN
87 GetModuleFileName(wi.hinst, szExe, cchSzMax);
88#else
89 sprintf(szExe, "%s", is.szProgName != NULL ? is.szProgName : "");
90#endif
91 for (pch = szExe; *pch; pch++)
92 ;
93 while (pch > szExe && *pch != chDirSep)
94 pch--;
95 if (*pch == chDirSep)
96 pch++;
97 *pch = chNull;
98
99 for (i = 0; i <= 1; i++) {
100 if (i <= 0)
101 sprintf(szFileT, "%s", szFile);
102 else {
103 if (nFileMode > 1)
104 break;
105 sprintf(szFileT, "%s.as", szFile);
106 }
107
108 // First look for the file in the directory of the Astrolog executable.
109 sprintf(sz, "%s", szExe);
110 for (pch = sz; *pch; pch++)
111 ;
112 sprintf(pch, "%s", szFileT);
113 file = fopen(sz, szMode);
114 if (file != NULL)
115 goto LDone;
116
117 // Next look for the file in the current directory.
118 sprintf(sz, "%s", szFileT);
119 file = fopen(sz, szMode);
120 if (file != NULL)
121 goto LDone;
122
123 // Next look in the directories indicated by the -Yi switch.
124 for (j = 0; j < 10; j++) {
125 pch = us.rgszPath[j];
126 if (FSzSet(pch)) {
127 if ((FCapCh(*pch) || FUncapCh(*pch) || FNumCh(*pch)) &&
128 !(pch[1] == ':')) {
129 // If dir is relative path, then prepend the path to executable.
130 sprintf(sz, "%s", szExe);

Callers 15

FProcessSwitchFileFunction · 0.85
FProcessAAFFileFunction · 0.85
FProcessQuickFileFunction · 0.85
FProcessADBFileFunction · 0.85
FProcessSFTextFileFunction · 0.85
FProcessCalendarFileFunction · 0.85
FInputDataFunction · 0.85
GetJPLHorizonsFunction · 0.85
ChartExoplanetFunction · 0.85
lrz_file_positFunction · 0.85
ast_file_positFunction · 0.85
chi_file_positFunction · 0.85

Calls 1

PrintErrorFunction · 0.85

Tested by

no test coverage detected