X-Git-Url: https://secure.softndesign.org/git/?a=blobdiff_plain;f=workspace.c;fp=workspace.c;h=26bbe8abcbcd70fb2f30d79a2e1f9d06249fbc85;hb=e952523a06b81e8915751bdcb01ca87aad06ce1c;hp=0000000000000000000000000000000000000000;hpb=e4c7b5133d7af32573567e4e639f03c8fb11bc79;p=calc.git diff --git a/workspace.c b/workspace.c new file mode 100644 index 0000000..26bbe8a --- /dev/null +++ b/workspace.c @@ -0,0 +1,100 @@ +#include +#include + +#include "argument.h" +#include "debug.h" +#include "element.h" +#include "parser.h" +#include "stack.h" +#include "storage.h" +#include "tabular.h" + +#include "workspace.h" + +/* allocate workspace*/ + +workspace_t *alloc_ws () +{ + return (workspace_t *) callocordie (1, sizeof (workspace_t)); +} + +/* backup workspace*/ + +workspace_t *backup_ws (workspace_t *ws) +{ + ws->answer = answer; + ws->argument = copy_tab (argument); + ws->stack = copy_tab (stack); + ws->storage = copy_tab (storage); + return ws; +} + +/* clean workspace */ + +workspace_t *clean_ws (workspace_t *ws) +{ + ws->answer = 0; + + if (ws->argument) { + free_tab (ws->argument); + ws->argument = NULL; + } + + ws->id = 0; + + if (ws->root) { + delelement (ws->root); + ws->root = NULL; + } + + if (ws->stack) { + free_tab (ws->stack); + ws->stack = NULL; + } + + if (ws->string) { + free (ws->string); + ws->string = NULL; + } + + if (ws->storage) { + free_tab (ws->storage); + ws->storage = NULL; + } + + return ws; +} + +/* free workspace */ + +void free_ws (workspace_t *ws) +{ + if (ws) { + clean_ws (ws); + free (ws); + } +} + +/* restore workspace*/ + +void restore_ws (workspace_t *ws) +{ + answer = ws->answer; + + if (argument) { + free_tab (argument); + } + argument = copy_tab (ws->argument); + + if (stack) { + free_tab (stack); + } + stack = copy_tab (ws->stack); + + if (storage) { + free_tab (storage); + } + storage = copy_tab (ws->storage); +} + +/* vim: set ts=4 sw=4 et: */