refactor: Format change

* 4 space indentation
* epicsStdoutPrintf to printf
This commit is contained in:
Jerzy Jamroz
2025-02-05 09:57:40 +01:00
committed by Andrew Johnson
parent 82994d600f
commit 1468319f31

View File

@@ -14,20 +14,16 @@
#include "atInit.h"
#define __AT_INIT_LOG(svr) svr " atInit: "
// Version within the message
static const char helpMessage[] =
"atInit version 2.1.1\n"
"Allows you to define commands to be run after the iocInit\n"
"Example commands:\n"
" atInit \"dbpf <PV> <VAL>\"\n"
" atInit \"date\"\n";
"Allows you to define commands to be run after the iocInit\n"
"Example commands:\n"
" atInit \"dbpf <PV> <VAL>\"\n"
" atInit \"date\"\n";
struct cmditem
{
ELLNODE node;
char* cmd;
struct cmditem {
ELLNODE node;
char* cmd;
};
static ELLLIST s_cmdlist = {};
@@ -35,90 +31,90 @@ static int s_initendflag = 0; // Defines the end of the initialization
static void atInitHook(initHookState state)
{
if(state != initHookAfterIocRunning)
return;
if (state != initHookAfterIocRunning)
return;
struct cmditem* item = NULL;
struct cmditem* item = NULL;
while(item = (struct cmditem*)ellGet(&s_cmdlist))
{
epicsStdoutPrintf("%s\n", item->cmd);
while (item = (struct cmditem*)ellGet(&s_cmdlist)) {
printf("%s\n", item->cmd);
if(iocshCmd(item->cmd))
epicsStdoutPrintf(__AT_INIT_LOG(ERL_ERROR) "command '%s' failed to run\n", item->cmd);
if (iocshCmd(item->cmd))
printf(ERL_ERROR " atInit: "
"command '%s' failed to run\n",
item->cmd);
free(item);
}
free(item);
}
s_initendflag = 1;
s_initendflag = 1;
}
static struct cmditem* newItem(char* cmd)
{
struct cmditem* item = mallocMustSucceed(sizeof(struct cmditem) + strlen(cmd) + 1,
__AT_INIT_LOG(ERL_ERROR) "failed to allocate memory for cmditem");
item->cmd = (char*)(item + 1);
memcpy(item->cmd, cmd, strlen(cmd) + 1);
struct cmditem* item = mallocMustSucceed(sizeof(struct cmditem) + strlen(cmd) + 1,
ERL_ERROR " atInit: "
"failed to allocate memory for cmditem");
item->cmd = (char*)(item + 1);
memcpy(item->cmd, cmd, strlen(cmd) + 1);
if(item->cmd == NULL)
{
free(item);
errno = ENOMEM;
return NULL;
}
if (item->cmd == NULL) {
free(item);
errno = ENOMEM;
return NULL;
}
ellAdd(&s_cmdlist, &item->node);
ellAdd(&s_cmdlist, &item->node);
return item;
return item;
}
static const iocshFuncDef atInitDef = {
"atInit",
1,
(const iocshArg*[]){&(iocshArg){"command (before iocInit)", iocshArgString}},
helpMessage};
"atInit",
1,
(const iocshArg*[]){&(iocshArg){"command (before iocInit)", iocshArgString}},
helpMessage};
static void atInitFunc(const iocshArgBuf* args)
{
static int first_time = 1;
char* cmd = args[0].sval;
static int first_time = 1;
char* cmd = args[0].sval;
if(s_initendflag)
{
epicsStdoutPrintf(__AT_INIT_LOG(ERL_WARNING) "can only be used before iocInit (check help)\n");
return;
}
if(!cmd || !cmd[0])
{
epicsStdoutPrintf(__AT_INIT_LOG(ERL_WARNING) "received an empty argument (check help)\n");
return;
}
if(first_time)
{
first_time = 0;
if(initHookRegister(atInitHook) < 0)
{
errno = ENOMEM;
epicsStdoutPrintf(__AT_INIT_LOG(ERL_ERROR) "initHookRegister memory allocation failure %s\n", strerror(errno));
if (s_initendflag) {
printf(ERL_WARNING " atInit: "
"can only be used before iocInit (check help)\n");
return;
}
}
struct cmditem* item = newItem(cmd);
if (!cmd || !cmd[0]) {
printf(ERL_WARNING " atInit: "
"received an empty argument (check help)\n");
return;
}
if(!item)
epicsStdoutPrintf(__AT_INIT_LOG(ERL_ERROR) "failed to add the command '%s' %s\n", cmd, strerror(errno));
if (first_time) {
first_time = 0;
if (initHookRegister(atInitHook) < 0) {
errno = ENOMEM;
printf(ERL_ERROR " atInit: "
"initHookRegister memory allocation failure %s\n",
strerror(errno));
}
}
struct cmditem* item = newItem(cmd);
if (!item)
printf(ERL_ERROR " atInit: "
"failed to add the command '%s' %s\n",
cmd, strerror(errno));
}
void atInitRegister(void)
{
static int first_time = 1;
if(first_time)
{
first_time = 0;
iocshRegister(&atInitDef, atInitFunc);
}
static int first_time = 1;
if (first_time) {
first_time = 0;
iocshRegister(&atInitDef, atInitFunc);
}
}
#undef __AT_INIT_LOG