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