Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove conditionally compiled code #95

Closed
3 tasks done
jphickey opened this issue Mar 20, 2023 · 0 comments · Fixed by #124
Closed
3 tasks done

Remove conditionally compiled code #95

jphickey opened this issue Mar 20, 2023 · 0 comments · Fixed by #124

Comments

@jphickey
Copy link
Contributor

jphickey commented Mar 20, 2023

Checklist (Please check before submitting)

  • I reviewed the Contributing Guide.
  • I reviewed the README file to see if the feature is in the major future work.
  • I performed a cursory search to see if the feature request is relevant, not redundant, nor in conflict with other tickets.

Is your feature request related to a problem? Please describe.
Conditionally-compiled code is a maintenance problem because code then needs to be validated both ways, with the condition on and off, and it is easy for the lesser-used/non-default option to become stale or broken, particularly with respect to the coverage testing.

Describe the solution you'd like
Remove conditional compilation, replace with runtime conditional checks, which can be constant-value in FSW context, but can be coverage test both ways via a single binary build.

Additional context
In general conditional compilation of large chunks of code should be avoided, per 582 coding standards.
Example here of a block that is 84 lines long:

DS/fsw/src/ds_file.c

Lines 804 to 893 in ce98853

#if (DS_MOVE_FILES == true)
/*
** Move file from working directory to downlink directory...
*/
int32 OS_result;
int32 PathLength;
char *FileName;
char PathName[DS_TOTAL_FNAME_BUFSIZE];
/*
** First, close the file...
*/
OS_close(FileStatus->FileHandle);
/*
** Move file only if table has a downlink directory name...
*/
if (DS_AppData.DestFileTblPtr->File[FileIndex].Movename[0] != '\0')
{
/*
** Make sure directory name does not end with slash character...
*/
CFE_SB_MessageStringGet(PathName, DS_AppData.DestFileTblPtr->File[FileIndex].Movename, NULL, sizeof(PathName),
sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Movename));
PathLength = strlen(PathName);
if (PathName[PathLength - 1] == '/')
{
PathName[PathLength - 1] = '\0';
PathLength--;
}
/*
** Get a pointer to slash character before the filename...
*/
FileName = strrchr(FileStatus->FileName, '/');
if (FileName != NULL)
{
/*
** Verify that directory name plus filename is not too large...
*/
if ((PathLength + strlen(FileName)) < DS_TOTAL_FNAME_BUFSIZE)
{
/*
** Append the filename (with slash) to the directory name...
*/
strcat(PathName, FileName);
/*
** Use OS function to move/rename the file...
*/
OS_result = OS_mv(FileStatus->FileName, PathName);
if (OS_result != OS_SUCCESS)
{
/*
** Error - send event but leave destination enabled...
*/
CFE_EVS_SendEvent(DS_MOVE_FILE_ERR_EID, CFE_EVS_EventType_ERROR,
"FILE MOVE error: src = '%s', tgt = '%s', result = %d", FileStatus->FileName,
PathName, OS_result);
}
}
else
{
/*
** Error - send event but leave destination enabled...
*/
CFE_EVS_SendEvent(DS_MOVE_FILE_ERR_EID, CFE_EVS_EventType_ERROR,
"FILE MOVE error: dir name = '%s', filename = '%s'", PathName, FileName);
}
}
else
{
/*
** Error - send event but leave destination enabled...
*/
CFE_EVS_SendEvent(DS_MOVE_FILE_ERR_EID, CFE_EVS_EventType_ERROR,
"FILE MOVE error: dir name = '%s', filename = 'NULL'", PathName);
}
/* Update the path name for reporting */
strncpy(FileStatus->FileName, PathName, sizeof(PathName));
}
#else
/*
** Close the file...
*/
OS_close(FileStatus->FileHandle);
#endif

Requester Info
Joseph Hickey, Vantage Systems, Inc.

chillfig pushed a commit to chillfig/DS that referenced this issue Feb 15, 2024
chillfig pushed a commit to chillfig/DS that referenced this issue Feb 15, 2024
chillfig pushed a commit to chillfig/DS that referenced this issue Feb 27, 2024
chillfig pushed a commit to chillfig/DS that referenced this issue Feb 29, 2024
chillfig pushed a commit to chillfig/DS that referenced this issue Mar 26, 2024
dzbaker added a commit that referenced this issue Mar 28, 2024
Fix #95, Replaces conditionally compiled code with runtime conditional logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant