Skip to content

Commit

Permalink
Added error handling for reading in options.
Browse files Browse the repository at this point in the history
Forced setup.py to include VERSION.
  • Loading branch information
Rory Barnes committed Sep 5, 2024
1 parent 47ec51e commit 8450e74
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def run(self):
ext_modules=ext_modules,
cmdclass=cmdclass,
include_package_data=True,
data_files=[('', ['VERSION'])],
zip_safe=False,
entry_points={"console_scripts": ["vplanet=vplanet.wrapper:_entry_point"]},
)
Expand Down
21 changes: 18 additions & 3 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,12 @@ void AddOptionDouble(char *cFile, char *cOption, double *dInput, int *iLine,

GetLine(cFile, cOption, &cLine, iLine, iVerbose);
if (*iLine >= 0) {
sscanf(cLine, "%s %lf", cTmp, dInput);
int iNumOptionsRead = sscanf(cLine, "%s %lf", cTmp, dInput);
if (iNumOptionsRead != 2) {
printf("ERROR: %d arguments read for option %s.\n",iNumOptionsRead,cOption);
printf("\tcLine=%s, cTmp=%s, dInput=%lf\n", cLine, cTmp, *dInput );
exit(EXIT_INPUT);
}
}
free(cLine);
}
Expand All @@ -354,7 +359,12 @@ void AddOptionInt(char *cFile, char *cOption, int *iInput, int *iLine,

GetLine(cFile, cOption, &cLine, iLine, iVerbose);
if (*iLine >= 0) {
sscanf(cLine, "%s %d", cTmp, iInput);
int iNumOptionsRead = sscanf(cLine, "%s %d", cTmp, iInput);
if (iNumOptionsRead != 2) {
printf("ERROR: %d arguments read for option %s.\n",iNumOptionsRead,cOption);
printf("\tcLine=%s, cTmp=%s, dInput=%d\n", cLine, cTmp, *iInput );
exit(EXIT_INPUT);
}
}
free(cLine);
}
Expand Down Expand Up @@ -384,7 +394,12 @@ void AddOptionString(char *cFile, char *cOption, char cInput[], int *iLine,

GetLine(cFile, cOption, &cLine, iLine, iVerbose);
if (*iLine >= 0) {
sscanf(cLine, "%s %s", cTmp, cInput);
int iNumOptionsRead = sscanf(cLine, "%s %s", cTmp, cInput);
if (iNumOptionsRead != 2) {
printf("ERROR: %d arguments read for option %s.\n",iNumOptionsRead,cOption);
printf("\tcLine=%s, cTmp=%s, dInput=%s\n", cLine, cTmp, cInput );
exit(EXIT_INPUT);
}
}
free(cLine);
}
Expand Down

0 comments on commit 8450e74

Please sign in to comment.