19 #include "epicsStdlib.h"
20 #include "epicsString.h"
22 #include "epicsMutex.h"
24 #include "dbStaticLib.h"
25 #include "dbFldTypes.h"
27 #include "dbAccessDefs.h"
28 #include <epicsTypes.h>
29 #include <epicsTime.h>
30 #include <epicsThread.h>
31 #include <epicsString.h>
32 #include <epicsTimer.h>
33 #include <epicsMutex.h>
42 #include <boost/scoped_array.hpp>
45 #include <registryFunction.h>
47 #include <epicsExport.h>
56 static void ioccalc(
const char* resultvar,
const char* expression,
int options,
int length)
58 if (resultvar == NULL || expression == NULL)
60 errlogPrintf(
"ioccalc: ERROR: NULL args");
63 bool verbose = (options & 0x1);
64 bool zero_pad = (options & 0x2);
65 bool hash_mode = (options & 0x4);
66 char* expr_expand = macEnvExpand(expression);
67 if (expr_expand == NULL)
69 errlogPrintf(
"ioccalc: ERROR: NULL expanded expression arg");
74 printf(
"ioccalc: expanded expression=\"%s\"\n", expr_expand);
77 static const int CALC_NARGS = 12;
78 std::vector<double> parg(CALC_NARGS);
79 for(
int i=0; i<CALC_NARGS; ++i)
85 boost::scoped_array<char> ppostfix(
new char[INFIX_TO_POSTFIX_SIZE(strlen(expr_expand)) + 100]);
86 if ( postfix(expr_expand, ppostfix.get(), &calc_error) != 0 )
88 errlogPrintf(
"ioccalc: ERROR: postfix: %s\n", calcErrorStr(calc_error));
91 if ( calcPerform(&(parg[0]), &result, ppostfix.get()) != 0 )
93 errlogPrintf(
"ioccalc: ERROR: calcPerform: %s\n",
"");
96 long long_result =
static_cast<long>(floor(result + 0.5));
98 std::ostringstream format_str;
101 if ( sprintf(result_str,
"%s", (long_result != 0 ?
" " :
"#")) < 0 )
103 errlogPrintf(
"ioccalc: ERROR: sprintf (hash mode)\n");
116 format_str << length;
119 if ( sprintf(result_str, format_str.str().c_str(), long_result) < 0 )
121 errlogPrintf(
"ioccalc: ERROR: sprintf: %s\n", format_str.str().c_str());
127 printf(
"ioccalc: setting %s=\"%s\" (%g)\n", resultvar, result_str, result);
130 epicsEnvSet(resultvar, result_str);
149 ioccalc(args[0].sval, args[1].sval, args[2].ival, args[3].ival);
static void ioccalcRegister(void)
static const iocshFuncDef calcInitFuncDef
static const iocshArg *const calcInitArgs[]
static const iocshArg calcInitArg0
static void ioccalc(const char *resultvar, const char *expression, int options, int length)
static const iocshArg calcInitArg3
static const iocshArg calcInitArg2
static void calcInitCallFunc(const iocshArgBuf *args)
static const iocshArg calcInitArg1
epicsExportRegistrar(dbLoadRecordsFuncsRegister)