mark function returns collection state
[mala.git] / std / std_macros.c
blob5ea1556cb0aa658d5c809341c6b96383f22757a9
1 /*
2 std_parsers.c - MaLa standard module parsers
4 Copyright (C) 2005, Christian Thaeter <chth@gmx.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, contact me.
20 #include <stdio.h>
21 #include <string.h>
22 #include <time.h>
24 #include "mala.h"
25 #include "std.h"
27 //static void
28 //mala_macrocheck_list (LList list, int * max_arg, int argt[10]);
30 //static void
31 //mala_macrocheck_string (MalaString string, int * max_arg, int argt[10]);
34 static
35 mala_actioninit std_macros[] =
38 //MALA_PARSER_BRIEF("MACROS", "TODO"),
39 //MALA_PARSER_HELP("MACROS", ("TODO")),
42 MALA_PARSER("--", mala__parser, NULL, NULL, NULL),
43 MALA_PARSER_BRIEF("--", ""),
44 MALA_PARSER_HELP("--", ("TODO")),
45 MALA_PARSER_SIGNATURE_TYPE("--", ("")),
46 MALA_PARSER_SIGNATURE_USAGE("--", ("")),
47 MALA_PARSER_RESULT_TYPE("--", ("")),
48 MALA_PARSER_RESULT_USAGE("--", ("")),
50 MALA_PARSER("--FOREACH-WORD", mala_foreach_word_parser, NULL, NULL, NULL),
51 MALA_PARSER_BRIEF("--", ""),
52 MALA_PARSER_HELP("--", ("TODO")),
53 MALA_PARSER_SIGNATURE_TYPE("--", ("")),
54 MALA_PARSER_SIGNATURE_USAGE("--", ("")),
55 MALA_PARSER_RESULT_TYPE("--", ("")),
56 MALA_PARSER_RESULT_USAGE("--", ("")),
61 //MALA_SIMPLE_PARSER("--DEF", mala_def_parser),
62 MALA_PARSER_BRIEF("--DEF", "defines a substitution"),
63 MALA_PARSER_SIGNATURE_TYPE("--DEF", ("WORD", "WORD-OR-BLOCK")),
64 //TODO MALA_PARSER_SIGNATURE_USAGE("--DEF", ("word to be substituted",
65 // "replaced with this")),
66 //TODO MALA_PARSER_HELP("--DEF", ("The second argument can be a block of words enclosed in --BEGIN ... --END with % substitution sequences. See help for --BEGIN for details.")),
67 //TODO MALA_PARSER_EXAMPLE("--DEF", "--DEF `foo `bar\t expands foo to bar\n--DEF `--action --BEGIN foo bar --END\t --action will expand to foo bar"),
70 //MALA_PARSER("--END", mala_end_parser, NULL, NULL, NULL),
71 // TODO MALA_PARSER_BRIEF("--END", "closes a block"),
72 //TODOMALA_PARSER_HELP("--END", ("an --END without a matching --BEGIN raises an error.")),
75 MALA_SIMPLE_PARSER("--DEL", mala_delete_parser),
77 MALA_PARSER_BRIEF("--DEL", "deletes a macro"),
78 //TODO MALA_PARSER_SIGNATURE_TYPE("--DEL", ("WORD")),
79 //TODO MALA_PARSER_SIGNATURE_USAGE("--DEL", ("name of the Macro to delete")),
80 //TODO MALA_PARSER_HELP("--DEL", ("Removes the last definition of the most recent definition with the matching name and any childs which where attached to it (see --ATTACH)")),
82 MALA_SIMPLE_PARSER("--BEGIN", mala_begin_parser),
83 MALA_PARSER_BRIEF("--BEGIN", "defines a block or list"),
84 //TODO MALA_PARSER_SIGNATURE_TYPE("--BEGIN", ("SEQUENCE","END")),
85 //TODO MALA_PARSER_SIGNATURE_USAGE("--BEGIN", ("content of the block", "a --END which closes the block")),
86 //TODO MALA_PARSER_RESULT_TYPE("--BEGIN", ("BLOCK")),
87 //TODO MALA_PARSER_RESULT_USAGE("--BEGIN", ("a unique name of the block")),
88 //TODO MALA_PARSER_HELP("--BEGIN", ("Blocks can have % substitutions, Blocks are garbage collected, TODO")),
90 MALA_ACTIONS_END
95 int
96 mala_substitute_parser (MalaProgram prg, void * data)
98 MALA_SIDEEFFECT_BEGIN
99 mala_stringlistnode_substitute_string (mala_program_pos (prg), (MalaString) data);
100 MALA_SIDEEFFECT_END;
102 return MALA_CONTINUE;
106 mala_expand_parser (MalaProgram prg, void * data)
108 (void) data;
109 //MalaStringListNode itr;
110 // MalaStringListNode end;
112 MALA_SIDEEFFECT_BEGIN
115 #if 0
116 end = mala_stringlistnode_next (mala_program_pos (prg));
118 for (itr = mala_stringlist_tail ((MalaStringList) data);
119 !mala_stringlist_is_end ((MalaStringList) data, itr);
120 mala_stringlistnode_rev (&itr))
122 // TODO --PROGRAM if (!mala_stringlist_after_new (&eng->program, mala_program_pos (prg),
123 // mala_stringlistnode_string (itr)))
124 // goto ealloc_node;
126 #endif
128 MALA_SIDEEFFECT_END;
130 mala_program_action_done (prg, 0);
131 return MALA_CONTINUE;
136 mala_macro_parser (MalaProgram prg, void * data)
138 (void) prg;
139 (void) data;
140 #if 0 //TODO
141 MalaStringListNode itr;
142 MalaStringListNode last = NULL;
143 LList list;
144 const char* c;
145 int i;
146 int max_arg = 0;
147 int argt[10] = {0};
148 char *p = NULL;
149 MalaString args[10];
150 MalaString str = NULL;
151 // scan how much args are needed
152 mala_macrocheck_list ((LList) data, &max_arg, argt);
154 // evaluate args, fill arg-array
155 args[0] = mala_stringlistnode_string (mala_program_pos (prg));
157 MALA_SIDEEFFECT_BEGIN
159 for (i = 1; i <= max_arg; ++i)
161 // TODO %STATEn evaluated to STATE
162 if (!(last = mala_engine_arg_eval (eng, pptr, i,
163 argt[i] == 1 ? MALA_LITERAL : MALA_EXCEPTION))
164 || eng->state > MALA_EFAULT)
165 return eng->state;
167 args[i] = mala_stringlistnode_string (last);
170 // build list with substitutions
171 list = mala_stringlist_new ();
172 if (!list)
173 goto ealloc_list;
175 if (!mala_stringlist_tail_new (list, eng->common_string[MALA_STRING_BEGIN]))
176 goto ealloc;
178 for (itr = mala_stringlist_head ((MalaStringList) data);
179 !mala_stringlist_is_end ((MalaStringList) data, itr);
180 mala_stringlistnode_fwd (&itr))
182 size_t size = 64;
183 if (!(p = malloc (size)))
184 goto ealloc;
186 for (c = mala_string_cstr (mala_stringlistnode_string (itr)), i = 0; *c; ++c,++i)
188 if (*c == '%')
190 ++c;
191 if (*c == '%')
193 // %% -> %
194 goto normal_char;
196 else if (*c >= '0' && *c <= '9')
198 // %0..%9
199 if (size <= i+mala_string_length (args[*c-'0'])
200 && !(size = reserve_string (&p,
201 size,
202 1 + i + mala_string_length (args[*c-'0']))))
203 goto ealloc;
204 strcpy(p+i, mala_string_cstr (args[*c-'0']));
205 i += (mala_string_length (args[*c-'0']) - 1);
207 else if (*c == '-')
209 ++c;
210 if (*c >= '0' && *c <= '9')
212 // %0..%9
213 if (size <= i+mala_string_length (args[*c-'0'])
214 && !(size = reserve_string (&p,
215 size,
216 1 + i +
217 mala_string_length (args[*c-'0']))))
218 goto ealloc;
219 strcpy(p+i, mala_string_cstr (args[*c-'0']));
220 i += (mala_string_length (args[*c-'0']) - 1);
224 else
226 normal_char:
227 // normal char
228 if (size <= (size_t) i && !(size = reserve_string (&p, size, (size_t) i+1)))
229 goto ealloc;
230 p[i] = *c;
234 p[i] = '\0';
236 char* ptmp;
237 if (!(ptmp = realloc (p, size)))
238 goto ealloc;
240 str = mala_string_new_attach_cstr (ptmp, &eng->words, NULL /*TODO refs*/); // TODO review
242 if (!mala_stringlist_tail_new (list, str))
243 goto ealloc;
245 // TODO review mala_string_free (str);
248 if (!mala_stringlist_tail_new (list, eng->common_string[MALA_STRING_END]))
249 goto ealloc;
251 // insert list
252 for (itr = mala_stringlist_tail (list);
253 !mala_stringlist_is_end (list, itr);
254 mala_stringlistnode_rev (&itr))
256 // if (!mala_stringlist_after_new (&eng->program, last,
257 // mala_stringlistnode_string (itr)))
258 // goto ealloc;
261 // cleanup
262 mala_stringlist_free (list);
265 MALA_SIDEEFFECT_END;
267 mala_engine_command_done (eng, pptr, max_arg);
268 #endif
269 return MALA_CONTINUE;
274 mala_begin_parser (MalaProgram prg, void * data)
276 (void) prg;
277 (void) data;
278 #if 0 // TODO --PROGRAM
279 MalaStringListNode itr;
280 MalaStringListNode end;
281 //MalaStringList list;
282 unsigned depth = 1;
283 MalaString name = NULL;
284 int ret = 0;
287 //TODO --PROGRAM if (mala_stringlist_is_tail (&eng->program, mala_program_pos (prg)))
288 // return mala_engine_exception (eng, pptr, mala_program_pos (prg),
289 // eng->common_string[MALA_STRING_ERROR_MISSING_END]);
291 // find matching --END
292 for (end = mala_stringlistnode_next (mala_program_pos (prg));
293 !mala_stringlist_is_end (&eng->program, end);
294 mala_stringlistnode_fwd (&end))
296 //TODO if (mala_string_same(mala_stringlistnode_string (end),
297 // eng->common_string[MALA_STRING_BEGIN]))
298 // ++depth;
299 //else if (mala_string_same(mala_stringlistnode_string (end),
300 // eng->common_string[MALA_STRING_END]))
301 // --depth;
302 if (!depth)
303 break;
306 if (depth)
307 return mala_engine_exception (eng, pptr, mala_stringlistnode_prev (end),
308 eng->common_string[MALA_STRING_ERROR_MISSING_END]);
310 MALA_SIDEEFFECT_BEGIN
312 //list = mala_stringlist_new ();
313 //if (!list)
314 // return MALA_EALLOC;
316 // copy the block content to list
317 for (itr = mala_stringlistnode_next (mala_program_pos (prg)); itr != end; mala_stringlistnode_fwd (&itr))
318 if (!mala_stringlist_tail_new (list, mala_stringlistnode_string (itr)))
319 goto ealloc_node;
321 const char* templ;
322 MalaParserFunc parser;
323 int max_arg = 0;
324 int argt[10] = {0};
325 mala_macrocheck_list (list, &max_arg, argt);
327 if (max_arg == 0)
329 templ = "--L_%08X";
330 parser = mala_expand_parser;
331 ret = MALA_LIST;
333 else if (max_arg > 0)
335 templ = "--M_%08X";
336 parser = mala_macro_parser;
337 ret = MALA_MACRO;
339 else
341 mala_stringlist_free (list);
342 //TODO review mala_string_free (name);
343 return mala_engine_exception (eng, pptr, end,
344 eng->common_string[MALA_STRING_ERROR_PARAMETER_SYNTAX]);
347 // allocate new block name
348 do { /* ..while name is in use */
349 //mala_string_free (name); /*TODO review in case we need to loop*/
350 name = mala_string_new_print (&eng->words, NULL /*TODO refs*/, templ, ++eng->blockcnt);
351 if (!name)
352 goto ealloc_name;
353 } while (0); // TODO (mala_actiondesc_top ((MalaActionDesc)mala_string_user_get (name)));
355 if (MALA_SUCCESS != mala_engine_add_action (eng, name, list,
356 parser,
357 NULL, NULL/*TODO refs*/))
358 goto ealloc_action;
359 // insert new --X_nnn... in program
360 //if (!mala_stringlist_after_new (&eng->program, end, name))
361 // goto ealloc_node;
362 // TODO review mala_string_free (name);
363 // TODO review mala_string_free (name); // once more since blocks are self-deleting after used
365 else
367 //TODO --PROGRAM if (!mala_stringlist_after_new (&eng->program,
368 //end,
369 // eng->common_string[MALA_STRING_PASS]))
370 // goto ealloc_pass;
372 MALA_SIDEEFFECT_END;
374 // and remove definition
375 //TODO --PROGRAM while (mala_program_pos (prg) != end)
376 //mala_stringlist_elem_delete_fwd (&eng->program, pptr);
378 //mala_stringlist_elem_delete_fwd (&eng->program, pptr);
380 #endif
381 return 0; //ret;
386 #if 0 //old block_parser
388 mala_block_parser (MalaProgram prg,
389 void * data)
391 MalaStringListNode itr;
392 MalaStringListNode end;
394 MALA_SIDEEFFECT_BEGIN
396 end = mala_stringlistnode_next (mala_program_pos (prg));
398 for (itr = mala_stringlist_tail ((MalaStringList) data);
399 !mala_stringlist_is_end ((MalaStringList) data, itr);
400 mala_stringlistnode_rev (&itr))
402 #if 0 // TODO --PROGRAM
403 if (!mala_stringlist_after_new (&eng->program, mala_program_pos (prg),
404 mala_stringlistnode_string (itr)))
405 goto ealloc_node;
406 #endif
409 MALA_SIDEEFFECT_END;
411 mala_actiondesc_pop_delete (mala_stringlistnode_user_get (mala_program_pos (prg)));
412 mala_engine_command_done (eng, pptr, 0);
413 return MALA_CONTINUE;
415 ealloc_node:
416 /* remove already added things */
417 #if 0
418 for (itr = mala_stringlistnode_next (mala_program_pos (prg));
419 itr != end;
420 mala_stringlist_elem_delete_fwd (&eng->program, &itr));
421 #endif
422 return MALA_EALLOC;
424 #endif
426 #if 0 // old macrodelete_parser
428 mala_macrodelete_parser (MalaProgram prg, void * data)
430 (void) data;
432 mala_engine_arg_eval (eng, pptr, 1, -1, NULL, NULL);
434 MALA_SIDEEFFECT_BEGIN
436 if (mala_stringlist_is_tail (&eng->program, mala_program_pos (prg)))
437 return mala_engine_exception (eng, pptr, mala_program_pos (prg),
438 eng->common_string[MALA_STRING_ERROR_MISSING_ARGUMENT]);
440 mala_actiondesc_pop_delete (mala_stringlistnode_user_get (mala_stringlistnode_next (mala_program_pos (prg))));
442 MALA_SIDEEFFECT_END;
444 mala_engine_command_done (eng, pptr, 1);
445 return MALA_SUCCESS;
447 #endif // old macrodelete
450 mala_delete_parser (MalaProgram prg, void * data)
452 (void) data;
454 //mala_engine_arg_eval (eng, pptr, 1, MALA_LITERAL);
456 MALA_SIDEEFFECT_BEGIN
458 #if 0 // TODO --PROGRAM
459 if (mala_stringlist_is_tail (&eng->program, mala_program_pos (prg)))
460 return mala_engine_exception (eng, pptr, mala_program_pos (prg),
461 eng->common_string[MALA_STRING_ERROR_MISSING_ARGUMENT]);
462 #endif
463 // TODO mala_actiondesc_pop_delete (mala_stringlistnode_user_get (mala_stringlistnode_next (mala_program_pos (prg))));
465 MALA_SIDEEFFECT_END;
467 mala_program_action_done (prg, 1);
468 return MALA_SUCCESS;
472 #if 0
474 mala_end_parser (MalaProgram prg,
475 void * data)
477 (void) data;
479 return mala_engine_exception (eng, pptr, mala_program_pos (prg),
480 eng->common_string[MALA_STRING_ERROR_END_WITHOUT_BEGIN]);
482 #endif
484 #if 0
485 static void
486 mala_macrocheck_list (MalaStringList list, int * max_arg, int argt[10])
488 MalaStringListNode itr;
489 for (itr = mala_stringlist_head (list);
490 !mala_stringlist_is_end (list, itr);
491 mala_stringlistnode_fwd (&itr))
493 mala_macrocheck_string (mala_stringlistnode_string (itr), max_arg, argt);
494 if (*max_arg == -1)
495 return;
499 static void
500 mala_macrocheck_string (MalaString string, int * max_arg, int argt[10])
502 const char * c;
503 for (c = mala_string_cstr (string); *c; ++c)
505 // "foo%1%-2"
506 if (*c == '%')
508 // %
509 ++c;
510 if (*c == '%')
511 // %%
512 continue;
513 if (*c == '-')
515 // %-
516 ++c;
517 if (*c >= '0' && *c <= '9')
519 // %-0 .. %-9
520 if (argt[*c - '0'] == 1)
521 goto esyntax;
522 if (*c > (char) *max_arg + '0')
523 *max_arg = *c - '0';
524 argt[*c - '0'] = -1;
526 else
527 goto esyntax;
529 else if (*c >= '0' && *c <= '9')
531 // %0 .. %9
532 if (argt[*c - '0'] == -1)
533 goto esyntax;
534 if (*c > (char) *max_arg + '0')
535 *max_arg = *c - '0';
536 argt[*c - '0'] = 1;
538 else
539 goto esyntax;
542 return;
544 esyntax:
545 *max_arg = -1;
546 return;
548 #endif
550 #if 0 // old macrodef parser
552 mala_macrodef_parser (MalaProgram prg,
553 void * data)
555 int i;
556 MalaStringListNode itr;
557 MalaStringListNode arg[2];
558 MalaString name;
559 MalaAction act;
561 (void) data;
563 // evaluate both args
564 if (!mala_engine_arg_eval (eng, pptr, 1, -1, NULL, NULL))
565 return eng->state;
566 if (!mala_engine_arg_eval (eng, pptr, 2, -1, NULL, mala_block_parser))
567 return eng->state;
569 MALA_SIDEEFFECT_BEGIN
571 // test if 2 arguments left and assign them to arg[], else error
572 for (i = 0, itr = mala_program_pos (prg); i<2; ++i, mala_stringlistnode_fwd(&itr))
574 #if 0 // TODO --PROGRAM
575 if (mala_stringlist_is_tail (&eng->program, itr))
576 return mala_engine_exception (eng, pptr, itr,
577 eng->common_string[MALA_STRING_ERROR_MISSING_ARGUMENT]);
578 #endif
580 arg[i] = mala_stringlistnode_next (itr);
583 // if name is a block then error
584 name = mala_stringlistnode_string (arg[0]);
585 act = mala_actiondesc_top ((MalaActionDesc) mala_string_user_get (name));
586 if (act && act->parser == mala_block_parser)
587 return mala_engine_exception (eng, pptr, arg[0],
588 eng->common_string[MALA_STRING_ERROR_BLOCK_NOT_ALLOWED]);
590 //expansion check and optimize block
591 act = mala_actiondesc_top ((MalaActionDesc) mala_stringlistnode_user_get (arg[1]));
592 if (act && act->factory == (MalaDataFactory) mala_stringlist_factory)
594 int max_arg = 0;
595 int argt[10] = {0};
596 mala_macrocheck_list ((MalaStringList) act->data, &max_arg, argt);
597 // convert block to expansion
598 if (max_arg > 0)
600 //macro
601 MalaActionDesc desc;
602 desc = mala_actiondesc_ensure (name);
603 if (!desc)
604 return MALA_EALLOC;
606 act = mala_actiondesc_pop ((MalaActionDesc) mala_stringlistnode_user_get (arg[1]));
607 act->name = name;
608 act->parser = mala_macro_parser;
609 mala_actiondesc_push_action (desc, act);
611 else if (mala_stringlist_is_single ((MalaStringList) act->data))
613 //substitute
614 MalaString subst;
615 subst = mala_stringlist_head_string_copy ((MalaStringList) act->data);
617 if (MALA_SUCCESS != mala_engine_add_action (eng, name, subst,
618 mala_substitute_parser,
619 (MalaDataFactory) mala_string_factory,
620 NULL))
621 return MALA_EALLOC;
623 mala_action_free(act);
625 else if (max_arg == 0)
627 //expand
628 MalaActionDesc desc;
629 desc = mala_actiondesc_ensure (name);
630 if (!desc)
631 return MALA_EALLOC;
633 act = mala_actiondesc_pop ((MalaActionDesc) mala_stringlistnode_user_get (arg[1]));
634 act->name = name;
635 act->parser = mala_expand_parser;
636 mala_actiondesc_push_action (desc, act);
638 else
639 return mala_engine_exception (eng, pptr, arg[1],
640 eng->common_string[MALA_STRING_ERROR_PARAMETER_SYNTAX]);
642 else //if (act && act->factory == (MalaDataFactory)mala_string_factory)
644 // single word
645 int max_arg = 0;
646 int argt[10] = {0};
647 mala_macrocheck_string (mala_stringlistnode_string (arg[1]), &max_arg, argt);
648 if (max_arg == 0)
650 // substitute
651 if (MALA_SUCCESS != mala_engine_add_action (eng, name,
652 mala_stringlistnode_string_copy (arg[1]),
653 mala_substitute_parser,
654 (MalaDataFactory) mala_string_factory,
655 NULL))
656 return MALA_EALLOC;
658 else if (max_arg > 0)
660 // macro
661 MalaStringList list;
663 list = mala_stringlist_new ();
664 if (!list)
665 return MALA_EALLOC;
667 mala_stringlist_tail_new (list, mala_stringlistnode_string (arg[1]));
669 if (MALA_SUCCESS != mala_engine_add_action (eng, name, list,
670 mala_macro_parser,
671 (MalaDataFactory) mala_stringlist_factory,
672 NULL))
673 return MALA_EALLOC;
675 else // syntax error
676 return mala_engine_exception (eng, pptr, arg[1],
677 eng->common_string[MALA_STRING_ERROR_PARAMETER_SYNTAX]);
680 MALA_SIDEEFFECT_END;
682 mala_engine_command_done (eng, pptr, 2);
683 return MALA_SUCCESS;
685 #endif //old macordef_parser
687 #if 0
689 mala_def_parser (MalaProgram prg,
690 void * data)
692 MalaStringListNode dest;
693 MalaStringListNode subst;
694 MalaString str;
695 MalaStringList list;
697 (void) data;
699 // evaluate both args
700 dest = mala_engine_arg_eval (eng, pptr, 1, MALA_LITERAL);
701 if (!dest)
702 return eng->state;
704 subst = mala_engine_arg_eval (eng, pptr, 2, MALA_MACRO);
705 if (!subst)
706 return eng->state;
710 info bei HELP/RESULT_TYPE ob was ein PREDICATE, EXPANSION, LITERAL oder BLOCK ist
713 MALA_SIDEEFFECT_BEGIN
715 int max_arg = 0;
716 int argt[10] = {0};
718 mala_macrocheck_string (mala_stringlistnode_string (subst), &max_arg, argt);
719 if (max_arg == 0)
721 // substitute
722 str = NULL; // TODO mala_stringlistnode_string_copy (subst);
723 #if 0 // TODO
724 if (MALA_SUCCESS != mala_engine_add_action (eng,
725 mala_stringlistnode_string (dest),
726 str,
727 mala_substitute_parser,
728 NULL, //TODO (MalaDataFactory) mala_string_factory,
729 NULL))
731 goto ealloc_action;
732 #endif
734 else if (max_arg > 0)
736 // macro
737 list = mala_stringlist_new ();
738 if (!list)
739 goto ealloc_list;
741 if (! mala_stringlist_tail_new (list, mala_stringlistnode_string (subst)))
742 goto ealloc_tail;
744 #if 0 // TODO
745 if (MALA_SUCCESS != mala_engine_add_action (eng,
746 mala_stringlistnode_string (dest),
747 list,
748 mala_macro_parser,
749 NULL, NULL /*TODO refs*/))
750 goto ealloc_list_action;
751 #endif
753 else // syntax error
754 return mala_engine_exception (eng, pptr, subst,
755 eng->common_string[MALA_STRING_ERROR_PARAMETER_SYNTAX]);
757 MALA_SIDEEFFECT_END;
759 mala_engine_command_done (eng, pptr, 2);
760 return MALA_CONTINUE;
762 // ealloc_list_action:
763 ealloc_tail:
764 mala_stringlist_free (list);
765 return MALA_EALLOC;
767 // ealloc_action:
768 // TODO review mala_string_free (str);
769 ealloc_list:
770 return MALA_EALLOC;
772 #endif
775 realloc a string to at least needed size
776 return the amount really reserved or 0 on error
778 #if 0 // TODO acogc reserve!
779 static size_t
780 reserve_string (char ** s, size_t actual, size_t needed)
782 size_t n;
783 char * r;
785 for (n = actual>64?actual:64; n <= needed; n += (n>>1)); /*n = n * 1.5*/
787 r = realloc (*s, n);
788 if (!r)
790 /* that was to much, try conservatively */
791 r = realloc (*s, n = needed);
792 if (!r)
793 return 0;
795 *s = r;
796 return n;
798 #endif
801 mala_module_std_macros_init (MalaEngine self)
803 return mala_engine_actions_register (self, std_macros);
807 // Local Variables:
808 // mode: C
809 // c-file-style: "gnu"
810 // End:
811 // arch-tag: 4722e09b-a020-4206-9ecc-9442505826c5
812 // end_of_file