Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
e3-require
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Lindh Olsson
e3-require
Commits
f30b52bb
Commit
f30b52bb
authored
8 years ago
by
Dirk Zimoch
Browse files
Options
Downloads
Patches
Plain Diff
improve usability of afterInit command
parent
945a05a3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
runScript.c
+70
-24
70 additions, 24 deletions
runScript.c
with
70 additions
and
24 deletions
runScript.c
+
70
−
24
View file @
f30b52bb
...
...
@@ -2,6 +2,7 @@
#include
<stdio.h>
#include
<string.h>
#include
<stdlib.h>
#include
<stdarg.h>
#include
<ctype.h>
#include
<errno.h>
#include
<macLib.h>
...
...
@@ -9,7 +10,7 @@
#include
<epicsVersion.h>
#ifdef vxWorks
#include
"asprintf
.h
"
#include
<sysSymTbl
.h
>
#ifdef _WRS_VXWORKS_MAJOR
/* vxWorks 6+ */
#include
<private/shellLibP.h>
...
...
@@ -18,6 +19,7 @@
#include
<shellLib.h>
#include
"strdup.h"
#endif
#include
<symLib.h>
#endif
#ifdef BASE_VERSION
...
...
@@ -360,7 +362,11 @@ end:
struct
cmditem
{
struct
cmditem
*
next
;
char
cmd
[
1
];
int
type
;
union
{
char
*
a
[
12
];
char
cmd
[
256
];
}
x
;
}
*
cmdlist
,
**
cmdlast
=&
cmdlist
;
void
afterInitHook
(
initHookState
state
)
...
...
@@ -378,43 +384,72 @@ void afterInitHook(initHookState state)
)
return
;
for
(
item
=
cmdlist
;
item
!=
NULL
;
item
=
item
->
next
)
{
#ifdef
_WRS_VXWORKS_MAJOR
SHELL_EVAL_VALUE
result
;
shellInterpEvaluate
(
line_exp
,
"C"
,
&
result
);
#elif defined(vxWorks)
execute
(
item
->
cmd
);
#else
iocshCmd
(
item
->
cmd
);
#if
n
def
EPICS_3_13
if
(
item
->
type
==
1
)
{
printf
(
"%s
\n
"
,
item
->
x
.
cmd
);
iocshCmd
(
item
->
x
.
cmd
);
}
else
#endif
((
void
(
*
)())
item
->
x
.
a
[
0
])(
item
->
x
.
a
[
1
],
item
->
x
.
a
[
2
],
item
->
x
.
a
[
3
],
item
->
x
.
a
[
4
],
item
->
x
.
a
[
5
],
item
->
x
.
a
[
6
],
item
->
x
.
a
[
7
],
item
->
x
.
a
[
8
],
item
->
x
.
a
[
9
],
item
->
x
.
a
[
10
],
item
->
x
.
a
[
11
]);
}
}
int
afterInit
(
const
char
*
command
)
extern
volatile
int
interruptAccept
;
static
int
first_time
=
1
;
static
struct
cmditem
*
newItem
(
char
*
cmd
,
int
type
)
{
struct
cmditem
*
item
;
static
int
first_time
=
1
;
if
(
!
command
)
if
(
!
cmd
)
{
fprintf
(
stderr
,
"usage: afterInit
\"
command
line
\"
\n
"
);
return
-
1
;
fprintf
(
stderr
,
"usage: afterInit command
, args...
\n
"
);
return
NULL
;
}
if
(
interruptAccept
)
{
fprintf
(
stderr
,
"afterInit can only be used before iocInit
\n
"
);
return
NULL
;
}
if
(
first_time
)
{
first_time
=
0
;
initHookRegister
(
afterInitHook
);
}
item
=
malloc
(
sizeof
(
struct
cmditem
)
+
strlen
(
command
)
);
item
=
malloc
(
sizeof
(
struct
cmditem
));
if
(
item
==
NULL
)
{
perror
(
"afterInit"
);
return
-
1
;
return
NULL
;
}
item
->
next
=
0
;
strcpy
(
item
->
cmd
,
command
)
;
item
->
type
=
type
;
item
->
next
=
NULL
;
*
cmdlast
=
item
;
cmdlast
=
&
item
->
next
;
return
item
;
}
int
afterInit
(
char
*
cmd
,
char
*
a1
,
char
*
a2
,
char
*
a3
,
char
*
a4
,
char
*
a5
,
char
*
a6
,
char
*
a7
,
char
*
a8
,
char
*
a9
,
char
*
a10
,
char
*
a11
)
{
struct
cmditem
*
item
=
newItem
(
cmd
,
0
);
if
(
!
item
)
return
-
1
;
item
->
x
.
a
[
0
]
=
cmd
;
item
->
x
.
a
[
1
]
=
a1
;
item
->
x
.
a
[
2
]
=
a2
;
item
->
x
.
a
[
3
]
=
a3
;
item
->
x
.
a
[
4
]
=
a4
;
item
->
x
.
a
[
5
]
=
a5
;
item
->
x
.
a
[
6
]
=
a6
;
item
->
x
.
a
[
7
]
=
a7
;
item
->
x
.
a
[
8
]
=
a8
;
item
->
x
.
a
[
9
]
=
a9
;
item
->
x
.
a
[
10
]
=
a10
;
item
->
x
.
a
[
11
]
=
a11
;
return
0
;
}
...
...
@@ -427,19 +462,30 @@ static const iocshFuncDef runScriptDef = {
&
(
iocshArg
)
{
"substitutions"
,
iocshArgString
},
}};
static
void
runScriptFunc
(
const
iocshArgBuf
*
args
)
static
void
runScriptFunc
(
const
iocshArgBuf
*
args
)
{
runScript
(
args
[
0
].
sval
,
args
[
1
].
sval
);
}
static
const
iocshFuncDef
afterInitDef
=
{
"afterInit"
,
1
,
(
const
iocshArg
*
[])
{
&
(
iocshArg
)
{
"commandline"
,
iocshArg
String
},
&
(
iocshArg
)
{
"commandline"
,
iocshArg
Argv
},
}};
static
void
afterInitFunc
(
const
iocshArgBuf
*
args
)
static
void
afterInitFunc
(
const
iocshArgBuf
*
args
)
{
afterInit
(
args
[
0
].
sval
);
int
i
,
n
;
struct
cmditem
*
item
=
newItem
(
args
[
0
].
aval
.
av
[
1
],
1
);
if
(
!
item
)
return
;
n
=
sprintf
(
item
->
x
.
cmd
,
"%.255s"
,
args
[
0
].
aval
.
av
[
1
]);
for
(
i
=
2
;
i
<
args
[
0
].
aval
.
ac
;
i
++
)
{
if
(
strpbrk
(
args
[
0
].
aval
.
av
[
i
],
" ,
\"\\
"
))
n
+=
sprintf
(
item
->
x
.
cmd
+
n
,
" '%.*s'"
,
255
-
3
-
n
,
args
[
0
].
aval
.
av
[
i
]);
else
n
+=
sprintf
(
item
->
x
.
cmd
+
n
,
" %.*s"
,
255
-
1
-
n
,
args
[
0
].
aval
.
av
[
i
]);
}
}
static
void
runScriptRegister
(
void
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment