From 05f239bdff4c1c55ed71ef59d4369c29c9304ea4 Mon Sep 17 00:00:00 2001
From: Jonathan Hanks <jonathan.hanks@ligo.org>
Date: Tue, 10 Nov 2020 14:09:36 -0800
Subject: [PATCH] Fix an error in the epics sequencer where a bit CA_SDF was
 not guarded by the preprocessor causing regular model builds to fail.

* Added function definitions to cut down on the #ifdef CA_SDF ...  Create an empty version for the non CA_SDF build and let the optimizer clean up instead of the pre-processor.
---
 src/epics/seq/main.c | 67 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 52 insertions(+), 15 deletions(-)

diff --git a/src/epics/seq/main.c b/src/epics/seq/main.c
index b91337a19..f604fee70 100644
--- a/src/epics/seq/main.c
+++ b/src/epics/seq/main.c
@@ -292,6 +292,9 @@ void registerFilters();
 void setupFMArrays(char *,int*,dbAddr*,dbAddr*);
 void resyncFMArrays(int *,dbAddr*);
 void processFMChanCommands(int*,dbAddr*,dbAddr*,int*,int,SET_ERR_TABLE*);
+void countDisconnectedChannels(int);
+void saveStrSetPoint(int, const char*);
+void updateStrVarSetPoint(int);
 #ifdef CA_SDF
 long countDisconnectedChans();
 
@@ -1633,11 +1636,7 @@ int spChecker(int monitorAll, SET_ERR_TABLE setErrTable[],int wcVal, char *wcstr
 					}
 				// If this is a string type, then get as string.
 				} else {
-				    if (caStringSetpointInitted[ii] == 1)
-                    {
-				        strcpy(cdTable[ii].data.strval, caStringSetpoint[ii]);
-				        caStringSetpointInitted[ii] = 2;
-                    }
+                    updateStrVarSetPoint(ii);
 					status = GET_VALUE_STR(paddr,sval,sizeof(sval),&mtime, NULL); //&(cdTable[ii].connected));
 					if(strcmp(cdTable[ii].data.strval,sval) != 0 || listAll)
 					{
@@ -2041,10 +2040,7 @@ int readConfig( char *pref,		///< EPICS channel prefix from EPICS environment.
 				   {
 					if(strcmp(cdTable[ii].chname,cdTableP[chNumP].chname) == 0)
 					{
-#if CA_SDF
-                        sprintf(caStringSetpoint[ii],"%s",s3);
-                        caStringSetpointInitted[ii] = 1;
-#endif
+					    saveStrSetPoint(ii, s3);
 						fmatch = 1;
 						if(cdTable[ii].datatype == SDF_STR || (!isdigit(s3[0]) && strncmp(s3,"-",1) != 0))
 						{
@@ -2290,6 +2286,39 @@ void processFMChanCommands(int *fMask, dbAddr *fmMaskAddr, dbAddr *fmCtrlAddr, i
 
 #ifdef CA_SDF
 
+/*!
+ * @brief count the disconnected channels if we are not on the disconnected page
+ */
+void countDisconnectedChannels(int curTable)
+{
+    if (curTable != SDF_TABLE_DISCONNECTED)
+    {
+        chDisconnectedCount = countDisconnectedChans();
+    }
+}
+
+/*!
+ * @brief store the setpoint value for a pv
+ * @note this stores the value that will be set by updateStrVarSetPoint
+ */
+void saveStrSetPoint(int index, const char* value)
+{
+    sprintf(caStringSetpoint[index],"%s",value);
+    caStringSetpointInitted[index] = 1;
+}
+
+/*!
+ * @brief Ensure that the setpoint value is set for the given str variable
+ */
+void updateStrVarSetPoint(int index)
+{
+    if (caStringSetpointInitted[index] == 1)
+    {
+        strcpy(cdTable[index].data.strval, caStringSetpoint[index]);
+        caStringSetpointInitted[index] = 2;
+    }
+}
+
 long countDisconnectedChans()
 {
     int jj = 0;
@@ -2822,6 +2851,19 @@ void cleanupCASDF()
 	pthread_mutex_destroy(&caStateMutex);
 }
 #else
+
+void countDisconnectedChannels(int curTable)
+{
+}
+
+void saveStrSetPoint(int index, const char* value)
+{
+}
+
+void updateStrVarSetPoint(int index)
+{
+}
+
 int getDbValueDouble(ADDRESS *paddr,double *dest,time_t *tp) {
 	struct buffer {
 		DBRtime
@@ -3485,12 +3527,7 @@ sleep(5);
 			if(pageNum < 0) pageNum = 0;
 			status = dbPutField(&pagereqaddr,DBR_LONG,&ropts,1);                // Init to zero.
 		}
-#ifdef CA_SDF
-		if (tsrVal != SDF_TABLE_DISCONNECTED)
-		{
-		    chDisconnectedCount = countDisconnectedChans();
-        }
-#endif
+        countDisconnectedChannels(tsrVal);
 		switch(tsrVal) {
 			case SDF_TABLE_DIFFS:
 				// Need to clear selections when moving between tables.
-- 
GitLab