Commit | Line | Data |
---|---|---|
e952523a LM |
1 | #include <malloc.h> |
2 | #include <stdio.h> | |
3 | ||
e952523a LM |
4 | #include "debug.h" |
5 | #include "element.h" | |
6 | #include "parser.h" | |
7 | #include "stack.h" | |
8 | #include "storage.h" | |
9 | #include "tabular.h" | |
10 | ||
11 | #include "workspace.h" | |
12 | ||
13 | /* allocate workspace*/ | |
14 | ||
15 | workspace_t *alloc_ws () | |
16 | { | |
17 | return (workspace_t *) callocordie (1, sizeof (workspace_t)); | |
18 | } | |
19 | ||
20 | /* backup workspace*/ | |
21 | ||
22 | workspace_t *backup_ws (workspace_t *ws) | |
23 | { | |
24 | ws->answer = answer; | |
a3f2e6cf LM |
25 | if (ws->stack) { |
26 | free_tab (ws->stack); | |
27 | } | |
e952523a | 28 | ws->stack = copy_tab (stack); |
a3f2e6cf LM |
29 | if (ws->storage) { |
30 | free_tab (ws->storage); | |
31 | } | |
e952523a LM |
32 | ws->storage = copy_tab (storage); |
33 | return ws; | |
34 | } | |
35 | ||
36 | /* clean workspace */ | |
37 | ||
38 | workspace_t *clean_ws (workspace_t *ws) | |
39 | { | |
40 | ws->answer = 0; | |
41 | ||
e952523a LM |
42 | ws->id = 0; |
43 | ||
44 | if (ws->root) { | |
45 | delelement (ws->root); | |
46 | ws->root = NULL; | |
47 | } | |
48 | ||
49 | if (ws->stack) { | |
50 | free_tab (ws->stack); | |
51 | ws->stack = NULL; | |
52 | } | |
53 | ||
54 | if (ws->string) { | |
55 | free (ws->string); | |
56 | ws->string = NULL; | |
57 | } | |
58 | ||
59 | if (ws->storage) { | |
60 | free_tab (ws->storage); | |
61 | ws->storage = NULL; | |
62 | } | |
63 | ||
64 | return ws; | |
65 | } | |
66 | ||
67 | /* free workspace */ | |
68 | ||
69 | void free_ws (workspace_t *ws) | |
70 | { | |
71 | if (ws) { | |
72 | clean_ws (ws); | |
73 | free (ws); | |
74 | } | |
75 | } | |
76 | ||
77 | /* restore workspace*/ | |
78 | ||
79 | void restore_ws (workspace_t *ws) | |
80 | { | |
81 | answer = ws->answer; | |
82 | ||
e952523a LM |
83 | if (stack) { |
84 | free_tab (stack); | |
85 | } | |
86 | stack = copy_tab (ws->stack); | |
87 | ||
88 | if (storage) { | |
89 | free_tab (storage); | |
90 | } | |
91 | storage = copy_tab (ws->storage); | |
92 | } | |
93 | ||
94 | /* vim: set ts=4 sw=4 et: */ |