new macro expansion (in progress)
[mala.git] / std / std_macros.c
blob64cb65c89f7149f23ccf87cbbd526ccf0dce1f73
1 /*
2 std_macros.c - MaLa standard module macros
4 Copyright (C) 2005, 2006, Christian Thaeter <ct@pipapo.org>
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_macros.h"
27 static void
28 mala_stringlist_macrocheck (MalaStringList list, int * max_arg, mala_state argt[10]);
30 static void
31 mala_string_macrocheck (MalaString string, int * max_arg, mala_state argt[10]);
33 static MalaString
34 mala_string_new_macrosubst (MalaString src, MalaString args[10], MalaEngine eng);
36 static MalaStringList
37 mala_stringlist_new_macrosubst (MalaStringList src, MalaString args[10], MalaEngine eng);
41 static
42 mala_actioninit std_macros[] =
45 //MALA_PARSER_BRIEF("MACROS", "TODO"),
46 //MALA_PARSER_HELP("MACROS", ("TODO")),
49 MALA_PARSER("--", mala__parser, NULL, NULL, NULL),
50 MALA_PARSER_BRIEF("--", ""),
51 MALA_PARSER_HELP("--", ("TODO")),
52 MALA_PARSER_SIGNATURE_TYPE("--", ("")),
53 MALA_PARSER_SIGNATURE_USAGE("--", ("")),
54 MALA_PARSER_RESULT_TYPE("--", ("")),
55 MALA_PARSER_RESULT_USAGE("--", ("")),
57 MALA_PARSER("--FOREACH-WORD", mala_foreach_word_parser, NULL, NULL, NULL),
58 MALA_PARSER_BRIEF("--", ""),
59 MALA_PARSER_HELP("--", ("TODO")),
60 MALA_PARSER_SIGNATURE_TYPE("--", ("")),
61 MALA_PARSER_SIGNATURE_USAGE("--", ("")),
62 MALA_PARSER_RESULT_TYPE("--", ("")),
63 MALA_PARSER_RESULT_USAGE("--", ("")),
68 //MALA_SIMPLE_PARSER("--DEF", mala_def_parser),
69 //MALA_PARSER_BRIEF("--DEF", "defines a substitution"),
70 //MALA_PARSER_SIGNATURE_TYPE("--DEF", ("WORD", "WORD-OR-BLOCK")),
71 //TODO MALA_PARSER_SIGNATURE_USAGE("--DEF", ("word to be substituted",
72 // "replaced with this")),
73 //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.")),
74 //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"),
77 //MALA_PARSER("--END", mala_end_parser, NULL, NULL, NULL),
78 // TODO MALA_PARSER_BRIEF("--END", "closes a block"),
79 //TODOMALA_PARSER_HELP("--END", ("an --END without a matching --BEGIN raises an error.")),
82 MALA_PARSER_SIMPLE("--DEL", mala_delete_parser),
84 //MALA_PARSER_BRIEF("--DEL", "deletes a macro"),
85 //TODO MALA_PARSER_SIGNATURE_TYPE("--DEL", ("WORD")),
86 //TODO MALA_PARSER_SIGNATURE_USAGE("--DEL", ("name of the Macro to delete")),
87 //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)")),
89 MALA_PARSER_SIMPLE("--BEGIN", mala_begin_parser),
90 // MALA_PARSER_BRIEF("--BEGIN", "defines a block or list"),
91 //TODO MALA_PARSER_SIGNATURE_TYPE("--BEGIN", ("SEQUENCE","END")),
92 //TODO MALA_PARSER_SIGNATURE_USAGE("--BEGIN", ("content of the block", "a --END which closes the block")),
93 //TODO MALA_PARSER_RESULT_TYPE("--BEGIN", ("BLOCK")),
94 //TODO MALA_PARSER_RESULT_USAGE("--BEGIN", ("a unique name of the block")),
95 //TODO MALA_PARSER_HELP("--BEGIN", ("Blocks can have % substitutions, Blocks are garbage collected, TODO")),
97 MALA_ACTIONS_END
103 mala_substitute_parser (MalaProgram prg)
105 MALA_MUTATOR_BEGIN
107 TODO("treat data_alloc_type");
109 mala_stringlist_next (prg->pptr)->string = (MalaString) mala_program_pptr_action (prg)->string;
111 MALA_MUTATOR_END;
113 return MALA_CONTINUE;
117 mala_expand_parser (MalaProgram prg)
119 MALA_MUTATOR_BEGIN
121 MalaAction act = mala_program_pptr_action (prg);
122 MalaStringList pos = mala_stringlist_next (prg->pptr);
123 MalaStringList itr;
125 for (itr = mala_stringlist_tail_get ((MalaStringList) act->data);
126 !mala_stringlist_is_end ((MalaStringList) act->data, itr);
127 mala_stringlist_rev (&itr))
129 MalaStringList node = mala_stringlist_node_new (mala_stringlist_string (itr), prg->engine);
130 mala_stringlist_insert_after (pos, node);
133 MALA_MUTATOR_END;
135 mala_program_action_done (prg, 0);
136 return MALA_CONTINUE;
141 mala_macro_parser (MalaProgram prg)
143 NOTICE (mala_module_std_macros, "macro parser");
144 int max_arg = -1;
146 /* How much to eveluate the argument (for now, likely extended in future):
147 MALA_REMOVE is used as pseudo tag for unused arguments/initialization
148 MALA_START doesn't evaluate the argument
149 MALA_LITERAL will evaluate fully
150 .. other destination states are reserved for future
152 mala_state argt[10] = {[0 ... 9] = MALA_REMOVE};
153 MalaAction act = mala_program_pptr_action (prg);
155 // scan for arguments
156 AcogcFactory type = mala_action_data_type (act);
157 if (type == &prg->engine->gcfactory_strings)
159 mala_string_macrocheck (mala_action_string (act), &max_arg, argt);
161 else if (type == &prg->engine->gcfactory_stringlists)
163 mala_stringlist_macrocheck (mala_action_stringlist (act), &max_arg, argt);
165 else
166 NOTREACHED;
168 BUG ("if (max_arg == INT_MAX) syntax error");
170 if (max_arg == -1)
171 return mala_expand_parser (prg);
173 MALA_MUTATOR_BEGIN
175 ACOGC_STACK_ENTER (&prg->engine->gcroot);
176 // evaluate args
177 for (int i=1; i <= max_arg; ++i)
179 if (argt[i] < MALA_START)
181 mala_program_eval_arg (prg, i, argt[i]);
182 TODO (" return / error handlen");
186 // construct result list
187 MalaString args[10];
188 MalaStringList p = mala_stringlist_next (prg->pptr);
189 for (int i=1; i <= max_arg; ++i)
191 mala_stringlist_fwd (&p);
192 args[i] = mala_stringlist_string (p);
195 // constructing list
196 if (type == &prg->engine->gcfactory_strings)
198 ACOGC_STACK_PTR (MalaString, string);
199 string.ptr = mala_string_new_macrosubst (mala_action_string (act),
200 args, prg->engine);
202 MalaStringList n = mala_stringlist_node_new (string.ptr, prg->engine);
203 mala_stringlist_insert_after (p, n);
205 else if (type == &prg->engine->gcfactory_stringlists)
207 ACOGC_STACK_PTR (MalaStringList, list);
208 list.ptr = mala_stringlist_new_macrosubst (mala_action_stringlist (act),
209 args, prg->engine);
210 mala_stringlist_insert_after_stringlist (p, list.ptr);
212 else
213 NOTREACHED;
215 ACOGC_STACK_LEAVE;
217 MALA_MUTATOR_END;
219 mala_program_action_done (prg, max_arg);
220 return MALA_CONTINUE;
223 static void
224 mala_stringlist_macrocheck (MalaStringList list, int * max_arg, mala_state argt[10])
226 LLIST_FOREACH (&list->node, itr)
228 MalaStringList l = LLIST_TO_STRUCTP(itr, mala_stringlist, node);
229 mala_string_macrocheck (mala_stringlist_string (l), max_arg, argt);
230 if (*max_arg == INT_MAX)
231 return;
235 static void
236 mala_string_macrocheck (MalaString string, int * max_arg, mala_state argt[10])
238 const char * c;
239 for (c = mala_string_cstr (string); *c; ++c)
241 if (*c == '%')
243 ++c;
244 if (*c == '%')
245 continue;
246 if (*c == '-')
248 ++c;
249 if (*c >= '0' && *c <= '9')
251 if (argt[*c - '0'] < MALA_REMOVE && argt[*c - '0'] != MALA_START)
252 goto esyntax;
253 if (*c > (char) *max_arg + '0')
254 *max_arg = *c - '0';
255 argt[*c - '0'] = MALA_START;
257 else
258 goto esyntax;
260 else if (*c >= '0' && *c <= '9')
262 if (argt[*c - '0'] != MALA_REMOVE && argt[*c - '0'] != MALA_LITERAL)
263 goto esyntax;
264 if (*c > (char) *max_arg + '0')
265 *max_arg = *c - '0';
266 argt[*c - '0'] = MALA_LITERAL;
268 else
269 goto esyntax;
272 return;
274 esyntax:
275 *max_arg = INT_MAX;
276 return;
280 static MalaString
281 mala_string_new_macrosubst (MalaString src, MalaString args[10], MalaEngine eng)
283 // 1st pass get size
284 size_t size = mala_string_length (src);
285 for (const char *c = mala_string_cstr (src); *c; ++c)
287 if (*c == '%')
289 ++c;
290 --size;
291 if (*c == '%')
292 continue;
293 if (*c == '-')
295 ++c;
296 --size;
298 --size;
299 TODO ("Handle %%-0");
300 size += mala_string_length (args[*c - '0']);
304 // 2nd pass create string
305 char* cstr = NULL;
306 acogc_alloc (&cstr, size+1, &eng->gcroot);
308 char* p = cstr;
310 for (const char *c = mala_string_cstr (src); *c; ++c)
312 if (*c == '%')
314 ++c;
315 if (*c == '%')
317 *p++ = *c;
318 continue;
320 if (*c == '-')
321 ++c;
323 TODO ("Handle %%-0");
325 strcpy (p, mala_string_cstr (args[*c - '0']));
326 p += mala_string_length (args[*c - '0']);
328 else
329 *p++ = *c;
331 *p = '\0';
333 return mala_string_new_attach_cstr (cstr, eng->words);
336 static MalaStringList
337 mala_stringlist_new_macrosubst (MalaStringList src, MalaString args[10], MalaEngine eng)
339 ACOGC_STACK_ENTER (&eng->gcroot);
340 ACOGC_STACK_PTR (MalaStringList, ret);
342 ret.ptr = mala_stringlist_new (eng);
344 LLIST_FOREACH (&src->node, node)
346 ACOGC_STACK_PTR (MalaString, str);
347 str.ptr = mala_string_new_macrosubst (mala_stringlist_string_from_llist(node), args, eng);
348 MalaStringList n = mala_stringlist_node_new (str.ptr, eng);
349 mala_stringlist_insert_tail (ret.ptr, n);
352 ACOGC_STACK_LEAVE;
353 return ret.ptr;
359 mala_begin_parser (MalaProgram prg)
361 (void) prg;
362 #if 0 // TODO --PROGRAM
363 MalaStringList itr;
364 MalaStringList end;
365 //MalaStringList list;
366 unsigned depth = 1;
367 MalaString name = NULL;
368 int ret = 0;
371 //TODO --PROGRAM if (mala_stringlist_is_tail (&eng->program, mala_program_pos (prg)))
372 // return mala_engine_exception (eng, pptr, mala_program_pos (prg),
373 // eng->common_string[MALA_STRING_ERROR_MISSING_END]);
375 // find matching --END
376 for (end = mala_stringlist_next (mala_program_pos (prg));
377 !mala_stringlist_is_end (&eng->program, end);
378 mala_stringlist_fwd (&end))
380 //TODO if (mala_string_same(mala_stringlist_string (end),
381 // eng->common_string[MALA_STRING_BEGIN]))
382 // ++depth;
383 //else if (mala_string_same(mala_stringlist_string (end),
384 // eng->common_string[MALA_STRING_END]))
385 // --depth;
386 if (!depth)
387 break;
390 if (depth)
391 return mala_engine_exception (eng, pptr, mala_stringlist_prev (end),
392 eng->common_string[MALA_STRING_ERROR_MISSING_END]);
394 MALA_MUTATOR_BEGIN
396 //list = mala_stringlist_new ();
397 //if (!list)
398 // return MALA_EALLOC;
400 // copy the block content to list
401 for (itr = mala_stringlist_next (mala_program_pos (prg)); itr != end; mala_stringlist_fwd (&itr))
402 if (!mala_stringlist_tail_new (list, mala_stringlist_string (itr)))
403 goto ealloc_node;
405 const char* templ;
406 MalaParserFunc parser;
407 int max_arg = 0;
408 int argt[10] = {0};
409 mala_macrocheck_list (list, &max_arg, argt);
411 if (max_arg == 0)
413 templ = "--L_%08X";
414 parser = mala_expand_parser;
415 ret = MALA_LIST;
417 else if (max_arg > 0)
419 templ = "--M_%08X";
420 parser = mala_macro_parser;
421 ret = MALA_MACRO;
423 else
425 mala_stringlist_free (list);
426 //TODO review mala_string_free (name);
427 return mala_engine_exception (eng, pptr, end,
428 eng->common_string[MALA_STRING_ERROR_PARAMETER_SYNTAX]);
431 // allocate new block name
432 do { /* ..while name is in use */
433 //mala_string_free (name); /*TODO review in case we need to loop*/
434 name = mala_string_new_print (&eng->words, NULL /*TODO refs*/, templ, ++eng->blockcnt);
435 if (!name)
436 goto ealloc_name;
437 } while (0); // TODO (mala_actiondesc_top ((MalaActionDesc)mala_string_user_get (name)));
439 if (MALA_SUCCESS != mala_engine_add_action (eng, name, list,
440 parser,
441 NULL, NULL/*TODO refs*/))
442 goto ealloc_action;
443 // insert new --X_nnn... in program
444 //if (!mala_stringlist_after_new (&eng->program, end, name))
445 // goto ealloc_node;
446 // TODO review mala_string_free (name);
447 // TODO review mala_string_free (name); // once more since blocks are self-deleting after used
449 else
451 //TODO --PROGRAM if (!mala_stringlist_after_new (&eng->program,
452 //end,
453 // eng->common_string[MALA_STRING_PASS]))
454 // goto ealloc_pass;
456 MALA_MUTATOR_END;
458 // and remove definition
459 //TODO --PROGRAM while (mala_program_pos (prg) != end)
460 //mala_stringlist_elem_delete_fwd (&eng->program, pptr);
462 //mala_stringlist_elem_delete_fwd (&eng->program, pptr);
464 #endif
465 return 0; //ret;
470 #if 0 //old block_parser
472 mala_block_parser (MalaProgram prg,
473 void * data)
475 MalaStringList itr;
476 MalaStringList end;
478 MALA_MUTATOR_BEGIN
480 end = mala_stringlist_next (mala_program_pos (prg));
482 for (itr = mala_stringlist_tail ((MalaStringList) data);
483 !mala_stringlist_is_end ((MalaStringList) data, itr);
484 mala_stringlist_rev (&itr))
486 #if 0 // TODO --PROGRAM
487 if (!mala_stringlist_after_new (&eng->program, mala_program_pos (prg),
488 mala_stringlist_string (itr)))
489 goto ealloc_node;
490 #endif
493 MALA_MUTATOR_END;
495 mala_actiondesc_pop_delete (mala_stringlist_user_get (mala_program_pos (prg)));
496 mala_engine_command_done (eng, pptr, 0);
497 return MALA_CONTINUE;
499 ealloc_node:
500 /* remove already added things */
501 #if 0
502 for (itr = mala_stringlist_next (mala_program_pos (prg));
503 itr != end;
504 mala_stringlist_elem_delete_fwd (&eng->program, &itr));
505 #endif
506 return MALA_EALLOC;
508 #endif
510 #if 0 // old macrodelete_parser
512 mala_macrodelete_parser (MalaProgram prg, void * data)
514 (void) data;
516 mala_engine_arg_eval (eng, pptr, 1, -1, NULL, NULL);
518 MALA_MUTATOR_BEGIN
520 if (mala_stringlist_is_tail (&eng->program, mala_program_pos (prg)))
521 return mala_engine_exception (eng, pptr, mala_program_pos (prg),
522 eng->common_string[MALA_STRING_ERROR_MISSING_ARGUMENT]);
524 mala_actiondesc_pop_delete (mala_stringlist_user_get (mala_stringlist_next (mala_program_pos (prg))));
526 MALA_MUTATOR_END;
528 mala_engine_command_done (eng, pptr, 1);
529 return MALA_SUCCESS;
531 #endif // old macrodelete
534 mala_delete_parser (MalaProgram prg)
536 //mala_engine_arg_eval (eng, pptr, 1, MALA_LITERAL);
538 MALA_MUTATOR_BEGIN
540 #if 0 // TODO --PROGRAM
541 if (mala_stringlist_is_tail (&eng->program, mala_program_pos (prg)))
542 return mala_engine_exception (eng, pptr, mala_program_pos (prg),
543 eng->common_string[MALA_STRING_ERROR_MISSING_ARGUMENT]);
544 #endif
545 // TODO mala_actiondesc_pop_delete (mala_stringlist_user_get (mala_stringlist_next (mala_program_pos (prg))));
547 MALA_MUTATOR_END;
549 // mala_program_action_done (prg, 1);
550 return MALA_SUCCESS;
554 #if 0
556 mala_end_parser (MalaProgram prg,
557 void * data)
559 (void) data;
561 return mala_engine_exception (eng, pptr, mala_program_pos (prg),
562 eng->common_string[MALA_STRING_ERROR_END_WITHOUT_BEGIN]);
564 #endif
568 #if 0 // old macrodef parser
570 mala_macrodef_parser (MalaProgram prg,
571 void * data)
573 int i;
574 MalaStringList itr;
575 MalaStringList arg[2];
576 MalaString name;
577 MalaAction act;
579 (void) data;
581 // evaluate both args
582 if (!mala_engine_arg_eval (eng, pptr, 1, -1, NULL, NULL))
583 return eng->state;
584 if (!mala_engine_arg_eval (eng, pptr, 2, -1, NULL, mala_block_parser))
585 return eng->state;
587 MALA_MUTATOR_BEGIN
589 // test if 2 arguments left and assign them to arg[], else error
590 for (i = 0, itr = mala_program_pos (prg); i<2; ++i, mala_stringlist_fwd(&itr))
592 #if 0 // TODO --PROGRAM
593 if (mala_stringlist_is_tail (&eng->program, itr))
594 return mala_engine_exception (eng, pptr, itr,
595 eng->common_string[MALA_STRING_ERROR_MISSING_ARGUMENT]);
596 #endif
598 arg[i] = mala_stringlist_next (itr);
601 // if name is a block then error
602 name = mala_stringlist_string (arg[0]);
603 act = mala_actiondesc_top ((MalaActionDesc) mala_string_user_get (name));
604 if (act && act->parser == mala_block_parser)
605 return mala_engine_exception (eng, pptr, arg[0],
606 eng->common_string[MALA_STRING_ERROR_BLOCK_NOT_ALLOWED]);
608 //expansion check and optimize block
609 act = mala_actiondesc_top ((MalaActionDesc) mala_stringlist_user_get (arg[1]));
610 if (act && act->factory == (MalaDataFactory) mala_stringlist_factory)
612 int max_arg = 0;
613 int argt[10] = {0};
614 mala_macrocheck_list ((MalaStringList) act->data, &max_arg, argt);
615 // convert block to expansion
616 if (max_arg > 0)
618 //macro
619 MalaActionDesc desc;
620 desc = mala_actiondesc_ensure (name);
621 if (!desc)
622 return MALA_EALLOC;
624 act = mala_actiondesc_pop ((MalaActionDesc) mala_stringlist_user_get (arg[1]));
625 act->name = name;
626 act->parser = mala_macro_parser;
627 mala_actiondesc_push_action (desc, act);
629 else if (mala_stringlist_is_single ((MalaStringList) act->data))
631 //substitute
632 MalaString subst;
633 subst = mala_stringlist_head_string_copy ((MalaStringList) act->data);
635 if (MALA_SUCCESS != mala_engine_add_action (eng, name, subst,
636 mala_substitute_parser,
637 (MalaDataFactory) mala_string_factory,
638 NULL))
639 return MALA_EALLOC;
641 mala_action_free(act);
643 else if (max_arg == 0)
645 //expand
646 MalaActionDesc desc;
647 desc = mala_actiondesc_ensure (name);
648 if (!desc)
649 return MALA_EALLOC;
651 act = mala_actiondesc_pop ((MalaActionDesc) mala_stringlist_user_get (arg[1]));
652 act->name = name;
653 act->parser = mala_expand_parser;
654 mala_actiondesc_push_action (desc, act);
656 else
657 return mala_engine_exception (eng, pptr, arg[1],
658 eng->common_string[MALA_STRING_ERROR_PARAMETER_SYNTAX]);
660 else //if (act && act->factory == (MalaDataFactory)mala_string_factory)
662 // single word
663 int max_arg = 0;
664 int argt[10] = {0};
665 mala_macrocheck_string (mala_stringlist_string (arg[1]), &max_arg, argt);
666 if (max_arg == 0)
668 // substitute
669 if (MALA_SUCCESS != mala_engine_add_action (eng, name,
670 mala_stringlist_string_copy (arg[1]),
671 mala_substitute_parser,
672 (MalaDataFactory) mala_string_factory,
673 NULL))
674 return MALA_EALLOC;
676 else if (max_arg > 0)
678 // macro
679 MalaStringList list;
681 list = mala_stringlist_new ();
682 if (!list)
683 return MALA_EALLOC;
685 mala_stringlist_tail_new (list, mala_stringlist_string (arg[1]));
687 if (MALA_SUCCESS != mala_engine_add_action (eng, name, list,
688 mala_macro_parser,
689 (MalaDataFactory) mala_stringlist_factory,
690 NULL))
691 return MALA_EALLOC;
693 else // syntax error
694 return mala_engine_exception (eng, pptr, arg[1],
695 eng->common_string[MALA_STRING_ERROR_PARAMETER_SYNTAX]);
698 MALA_MUTATOR_END;
700 mala_engine_command_done (eng, pptr, 2);
701 return MALA_SUCCESS;
703 #endif //old macordef_parser
705 #if 0
707 mala_def_parser (MalaProgram prg,
708 void * data)
710 MalaStringList dest;
711 MalaStringList subst;
712 MalaString str;
713 MalaStringList list;
715 (void) data;
717 // evaluate both args
718 dest = mala_engine_arg_eval (eng, pptr, 1, MALA_LITERAL);
719 if (!dest)
720 return eng->state;
722 subst = mala_engine_arg_eval (eng, pptr, 2, MALA_MACRO);
723 if (!subst)
724 return eng->state;
728 info bei HELP/RESULT_TYPE ob was ein PREDICATE, EXPANSION, LITERAL oder BLOCK ist
731 MALA_MUTATOR_BEGIN
733 int max_arg = 0;
734 int argt[10] = {0};
736 mala_macrocheck_string (mala_stringlist_string (subst), &max_arg, argt);
737 if (max_arg == 0)
739 // substitute
740 str = NULL; // TODO mala_stringlist_string_copy (subst);
741 #if 0 // TODO
742 if (MALA_SUCCESS != mala_engine_add_action (eng,
743 mala_stringlist_string (dest),
744 str,
745 mala_substitute_parser,
746 NULL, //TODO (MalaDataFactory) mala_string_factory,
747 NULL))
749 goto ealloc_action;
750 #endif
752 else if (max_arg > 0)
754 // macro
755 list = mala_stringlist_new ();
756 if (!list)
757 goto ealloc_list;
759 if (! mala_stringlist_tail_new (list, mala_stringlist_string (subst)))
760 goto ealloc_tail;
762 #if 0 // TODO
763 if (MALA_SUCCESS != mala_engine_add_action (eng,
764 mala_stringlist_string (dest),
765 list,
766 mala_macro_parser,
767 NULL, NULL /*TODO refs*/))
768 goto ealloc_list_action;
769 #endif
771 else // syntax error
772 return mala_engine_exception (eng, pptr, subst,
773 eng->common_string[MALA_STRING_ERROR_PARAMETER_SYNTAX]);
775 MALA_MUTATOR_END;
777 mala_engine_command_done (eng, pptr, 2);
778 return MALA_CONTINUE;
780 // ealloc_list_action:
781 ealloc_tail:
782 mala_stringlist_free (list);
783 return MALA_EALLOC;
785 // ealloc_action:
786 // TODO review mala_string_free (str);
787 ealloc_list:
788 return MALA_EALLOC;
790 #endif
793 realloc a string to at least needed size
794 return the amount really reserved or 0 on error
796 #if 0 // TODO acogc reserve!
797 static size_t
798 reserve_string (char ** s, size_t actual, size_t needed)
800 size_t n;
801 char * r;
803 for (n = actual>64?actual:64; n <= needed; n += (n>>1)); /*n = n * 1.5*/
805 r = realloc (*s, n);
806 if (!r)
808 /* that was to much, try conservatively */
809 r = realloc (*s, n = needed);
810 if (!r)
811 return 0;
813 *s = r;
814 return n;
816 #endif
818 NOBUG_DEFINE_FLAG (mala_module_std_macros);
821 mala_module_std_macros_init (MalaEngine self)
823 NOBUG_INIT_FLAG (mala_module_std_macros);
824 return mala_engine_actions_register (self, std_macros);
828 // Local Variables:
829 // mode: C
830 // c-file-style: "gnu"
831 // End:
832 // arch-tag: 4722e09b-a020-4206-9ecc-9442505826c5
833 // end_of_file