yumapro  23.10T-7
YumaPro SDK
Loading...
Searching...
No Matches
runstack.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
3 * Copyright (c) 2012 - 2021, YumaWorks, Inc., All Rights Reserved.
4 *
5 * Unless required by applicable law or agreed to in writing,
6 * software distributed under the License is distributed on an
7 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the
9 * specific language governing permissions and limitations
10 * under the License.
11 */
12#ifndef _H_runstack
13#define _H_runstack
14
15/* FILE: runstack.h
16*********************************************************************
17* *
18* P U R P O S E *
19* *
20*********************************************************************/
21
28/*********************************************************************
29* *
30* C H A N G E H I S T O R Y *
31* *
32*********************************************************************
33
34date init comment
35----------------------------------------------------------------------
3622-aug-07 abb Begun; split from ncxcli.c
3724-apr-10 abb Redesign to use dynamic memory,
38 allow recursion, and support multiple
39 concurrent contexts
4026-apr-10 abb added conditional cmd and loop support
41*/
42
43#ifndef _H_dlq
44#include "dlq.h"
45#endif
46
47#ifndef _H_status
48#include "status.h"
49#endif
50
51#ifndef _H_val
52#include "val.h"
53#endif
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
59/********************************************************************
60* *
61* C O N S T A N T S *
62* *
63*********************************************************************/
64
65
78#define RUNSTACK_MAX_PARMS 9
79
80
84#define RUNSTACK_MAX_NEST 512
85
89#define RUNSTACK_MAX_LOOP 65535
90
91
92/********************************************************************
93* *
94* T Y P E S *
95* *
96*********************************************************************/
97
99typedef enum runstack_src_t_ {
105
106
108typedef enum runstack_condtype_t_ {
113
114
116typedef enum runstack_ifstate_t_ {
122
123
125typedef enum runstack_loopstate_t_ {
130
131
133typedef enum runstack_queue_type_t_ {
140
141
143typedef struct runstack_ifcb_t_ {
145 boolean parentcond;
146 boolean startcond;
147 boolean curcond;
148 boolean ifused;
150
151
153typedef struct runstack_line_t_ {
154 dlq_hdr_t qhdr;
155 xmlChar *line;
157
158
160typedef struct runstack_loopcb_t_ {
162 uint32 maxloops;
163
166
169
171 boolean startcond;
172
174 struct xpath_pcb_t_ *xpathpcb;
175
178
182 struct runstack_loopcb_t_ *collector;
183
190
193
196
198 boolean empty_block;
199
201 dlq_hdr_t lineQ;
203
204
206typedef struct runstack_condcb_t_ {
208 dlq_hdr_t qhdr;
209
212
214 union u_ {
217 } u;
219
220
226typedef struct runstack_entry_t_ {
227 dlq_hdr_t qhdr;
230 uint32 level;
231
233 FILE *fp;
234
236 xmlChar *source;
237
239 xmlChar *buff;
240
243
245 uint32 linenum;
246 dlq_hdr_t parmQ;
247 dlq_hdr_t varQ;
248 dlq_hdr_t condcbQ;
250
251
256typedef struct runstack_context_t_ {
258 boolean cond_state;
259
262
265
268
271
273 dlq_hdr_t runstackQ;
276 dlq_hdr_t globalQ;
279 dlq_hdr_t zeroQ;
282 dlq_hdr_t zero_condcbQ;
285 dlq_hdr_t *sessionQ;
288 dlq_hdr_t *groupQ;
290
291
292/********************************************************************
293* *
294* F U N C T I O N S *
295* *
296*********************************************************************/
297
298
305extern uint32
307
308
323extern status_t
325 const xmlChar *source,
326 FILE *fp);
327
334extern void
336
337
353extern xmlChar *
355 status_t *res);
356
357
363extern void
365
366
372extern void
374
375
384extern dlq_hdr_t *
386 runstack_queue_type_t quetype);
387
388
395extern dlq_hdr_t *
397
398
404extern void
405 runstack_init (void);
406
407
413extern void
414 runstack_cleanup (void);
415
416
422extern void
424
425
431extern void
433
434
440extern void
442
443
449extern runstack_context_t *
451
452
458extern void
460
461
467extern runstack_src_t
469
470
478extern status_t
480 const xmlChar *line);
481
482
501extern xmlChar *
503 status_t *res);
504
505
513extern boolean
515
516
540extern status_t
542 uint32 maxloops,
543 struct xpath_pcb_t_ *xpathpcb,
544 val_value_t *docroot);
545
546
556extern status_t
558 boolean startcond);
559
560
570extern status_t
572 boolean startcond);
573
574
581extern status_t
583
584
591extern status_t
593
594
603extern boolean
605
606
614extern void
616 dlq_hdr_t *sessionQ);
617
618
626extern void
628 dlq_hdr_t *groupQ);
629
630
634#ifdef __cplusplus
635} /* end extern 'C' */
636#endif
637
638#endif /* _H_runstack */
dlq provides general double-linked list and queue support:
status_t
global error return code
Definition: status_enum.h:210
status_t runstack_handle_if(runstack_context_t *rcxt, boolean startcond)
Handle the if command for the specific runstack context.
Definition: runstack.c:1622
void runstack_cleanup(void)
Cleanup this module.
Definition: runstack.c:1013
runstack_queue_type_t
different queues of variables for que selection
Definition: runstack.h:133
status_t runstack_handle_else(runstack_context_t *rcxt)
Handle the elsecommand for the specific runstack context.
Definition: runstack.c:1753
xmlChar * runstack_get_loop_cmd(runstack_context_t *rcxt, status_t *res)
Get the next command during loop processing.
Definition: runstack.c:1282
void runstack_cancel(runstack_context_t *rcxt)
Cancel all running scripts.
Definition: runstack.c:870
runstack_src_t runstack_get_source(runstack_context_t *rcxt)
Get the current input source for the runstack context.
Definition: runstack.c:1176
xmlChar * runstack_get_cmd(runstack_context_t *rcxt, status_t *res)
Read the current runstack context and construct a command string for processing by do_run_script.
Definition: runstack.c:701
dlq_hdr_t * runstack_get_parm_que(runstack_context_t *rcxt)
Get the parameter queue for the current stack level.
Definition: runstack.c:967
runstack_ifstate_t
keep track of the if,elif,else,end sequence
Definition: runstack.h:116
runstack_context_t * runstack_new_context(void)
Malloc and init a new runstack context.
Definition: runstack.c:1121
void runstack_init(void)
Initialize this module.
Definition: runstack.c:997
void runstack_set_groupQ(runstack_context_t *rcxt, dlq_hdr_t *groupQ)
Set the current group-specific variable Q.
Definition: runstack.c:1971
dlq_hdr_t * runstack_get_que(runstack_context_t *rcxt, runstack_queue_type_t quetype)
Read the current runstack context and figure out which queue to get.
Definition: runstack.c:918
runstack_condtype_t
identify the runstack conditional control block type
Definition: runstack.h:108
boolean runstack_get_cond_state(runstack_context_t *rcxt)
Get the current conditional code state for the context.
Definition: runstack.c:1499
void runstack_free_context(runstack_context_t *rcxt)
Clean and free the runstack context.
Definition: runstack.c:1070
runstack_src_t
identify the runstack input source
Definition: runstack.h:99
status_t runstack_handle_elif(runstack_context_t *rcxt, boolean startcond)
Handle the elif command for the specific runstack context.
Definition: runstack.c:1669
void runstack_set_sessionQ(runstack_context_t *rcxt, dlq_hdr_t *sessionQ)
Set the current session-specific variable Q.
Definition: runstack.c:1947
status_t runstack_handle_while(runstack_context_t *rcxt, uint32 maxloops, struct xpath_pcb_t_ *xpathpcb, val_value_t *docroot)
Process the current command, which is a 'while' command.
runstack_loopstate_t
keep track of the while,end sequence
Definition: runstack.h:125
void runstack_pop(runstack_context_t *rcxt)
Remove a script nest level context from the stack Call just after script is completed.
Definition: runstack.c:632
status_t runstack_push(runstack_context_t *rcxt, const xmlChar *source, FILE *fp)
Add a script nest level context to the stack.
Definition: runstack.c:543
void runstack_clean_context(runstack_context_t *rcxt)
Clean the runstack context.
Definition: runstack.c:1030
uint32 runstack_level(runstack_context_t *rcxt)
Get the current stack level.
Definition: runstack.c:514
void runstack_init_context(runstack_context_t *rcxt)
Initialize a pre-malloced runstack context.
Definition: runstack.c:1092
status_t runstack_save_line(runstack_context_t *rcxt, const xmlChar *line)
Save the current line if needed if a loop is active.
Definition: runstack.c:1200
void runstack_session_cleanup(runstack_context_t *rcxt)
Cleanup after a yangcli session has ended.
Definition: runstack.c:1145
status_t runstack_handle_end(runstack_context_t *rcxt)
Handle the end command for the specific runstack context.
Definition: runstack.c:1823
void runstack_clear_cancel(runstack_context_t *rcxt)
Clear the cancel flags.
Definition: runstack.c:890
boolean runstack_get_if_used(runstack_context_t *rcxt)
Check if the run context, which should be inside an if-stmt now, has used the 'true' block already.
Definition: runstack.c:1913
@ RUNSTACK_QUE_GROUP
group variables
Definition: runstack.h:137
@ RUNSTACK_QUE_LOCAL
local variables
Definition: runstack.h:135
@ RUNSTACK_QUE_GLOBAL
global variables
Definition: runstack.h:138
@ RUNSTACK_QUE_SESSION
session variables
Definition: runstack.h:136
@ RUNSTACK_QUE_NONE
not set
Definition: runstack.h:134
@ RUNSTACK_IF_IF
if state
Definition: runstack.h:118
@ RUNSTACK_IF_NONE
not set
Definition: runstack.h:117
@ RUNSTACK_IF_ELSE
else state
Definition: runstack.h:120
@ RUNSTACK_IF_ELIF
elif state
Definition: runstack.h:119
@ RUNSTACK_COND_NONE
not set
Definition: runstack.h:109
@ RUNSTACK_COND_LOOP
while loop condition
Definition: runstack.h:111
@ RUNSTACK_COND_IF
if-stmt condition
Definition: runstack.h:110
@ RUNSTACK_SRC_NONE
not set
Definition: runstack.h:100
@ RUNSTACK_SRC_SCRIPT
source is a yangcli script
Definition: runstack.h:102
@ RUNSTACK_SRC_USER
source is interactive input
Definition: runstack.h:101
@ RUNSTACK_SRC_LOOP
source is captured from a loop
Definition: runstack.h:103
@ RUNSTACK_LOOP_NONE
not set
Definition: runstack.h:126
@ RUNSTACK_LOOP_COLLECTING
collecting loop commands
Definition: runstack.h:127
@ RUNSTACK_LOOP_LOOPING
playing loop commands
Definition: runstack.h:128
Global error messages for status code enumerations.
control the looping for 1 while - end sequence
Definition: runstack.h:206
runstack_condtype_t cond_type
condition type
Definition: runstack.h:211
dlq_hdr_t qhdr
queue header
Definition: runstack.h:208
Main runstact context control block used by yangcli to process script input loops and conditional sta...
Definition: runstack.h:256
boolean cond_state
current conditional state
Definition: runstack.h:258
runstack_src_t cur_src
current input source
Definition: runstack.h:270
dlq_hdr_t * groupQ
group variables for this runstack
Definition: runstack.h:288
dlq_hdr_t * sessionQ
session variables for this runstack
Definition: runstack.h:285
dlq_hdr_t runstackQ
each stack level has an entry
Definition: runstack.h:273
dlq_hdr_t globalQ
global variables for this runstack context
Definition: runstack.h:276
uint32 max_script_level
maximum script depth level
Definition: runstack.h:267
uint32 script_level
current script depth devel
Definition: runstack.h:264
dlq_hdr_t zeroQ
local variables for level 0 in the runstack
Definition: runstack.h:279
dlq_hdr_t zero_condcbQ
conditions for level zero in the runstack
Definition: runstack.h:282
boolean script_cancel
script cancel requested
Definition: runstack.h:261
one script run level context entry each time a 'run script' command is encountered,...
Definition: runstack.h:226
xmlChar * buff
buffer to store input
Definition: runstack.h:239
dlq_hdr_t condcbQ
Q of runstack_condcb_t.
Definition: runstack.h:248
xmlChar * source
filespec for input
Definition: runstack.h:236
dlq_hdr_t qhdr
queue header
Definition: runstack.h:227
int bufflen
length of buffer
Definition: runstack.h:242
dlq_hdr_t parmQ
Q of ncx_var_t.
Definition: runstack.h:246
FILE * fp
file open for input
Definition: runstack.h:233
dlq_hdr_t varQ
Q of ncx_var_t.
Definition: runstack.h:247
uint32 linenum
current line number
Definition: runstack.h:245
uint32 level
current runsack level
Definition: runstack.h:230
control the conditional state for 1 if...end sequence
Definition: runstack.h:143
boolean curcond
current condition
Definition: runstack.h:147
boolean parentcond
parent condition
Definition: runstack.h:145
runstack_ifstate_t ifstate
if state
Definition: runstack.h:144
boolean ifused
T already used up.
Definition: runstack.h:148
boolean startcond
start condition
Definition: runstack.h:146
save 1 line for looping purposes
Definition: runstack.h:153
xmlChar * line
malloced line of text
Definition: runstack.h:155
dlq_hdr_t qhdr
queue header
Definition: runstack.h:154
control the looping for 1 while - end sequence
Definition: runstack.h:160
runstack_line_t * cur_line
current line for loop processing
Definition: runstack.h:192
uint32 maxloops
max number of loops allowed
Definition: runstack.h:162
struct runstack_loopcb_t_ * collector
if the collector is non-NULL, then save lines in this outer while loop
Definition: runstack.h:182
val_value_t * docroot
document root for XPath expression
Definition: runstack.h:177
uint32 loop_count
current loop count
Definition: runstack.h:165
dlq_hdr_t lineQ
this Q will only be used if collector is NULL
Definition: runstack.h:201
struct xpath_pcb_t_ * xpathpcb
condition to evaluate before each loop iteration
Definition: runstack.h:174
boolean empty_block
true if empty command block
Definition: runstack.h:198
runstack_line_t * first_line
these may point to entries in this lineQ or the collector's lineQ; only the commands that are part of...
Definition: runstack.h:189
runstack_loopstate_t loop_state
current loop state
Definition: runstack.h:168
runstack_line_t * last_line
last line for loop processing
Definition: runstack.h:195
boolean startcond
start condition state
Definition: runstack.h:171
one value to match one type
Definition: val.h:911
loop or if-stmt condition used but not both
Definition: runstack.h:214
runstack_loopcb_t loopcb
loop control block
Definition: runstack.h:215
runstack_ifcb_t ifcb
if control block
Definition: runstack.h:216
Value Node Basic Support.