comparison macro.c @ 25:18681e5ae6e4

fix some more bugs
author David A. Holland
date Mon, 20 Dec 2010 04:38:43 -0500
parents e3fab8f1b52c
children 01c3a2088ab4
comparison
equal deleted inserted replaced
24:daa801fe719e 25:18681e5ae6e4
491 pos += strspn(buf+pos, alnum); 491 pos += strspn(buf+pos, alnum);
492 if (isparam(m, buf+wordstart, pos-wordstart, &param)) { 492 if (isparam(m, buf+wordstart, pos-wordstart, &param)) {
493 if (pos > blockstart) { 493 if (pos > blockstart) {
494 ei = expansionitem_create_stringlen( 494 ei = expansionitem_create_stringlen(
495 buf + blockstart, 495 buf + blockstart,
496 blockstart - pos); 496 pos - blockstart);
497 expansionitemarray_add(&m->expansion, 497 expansionitemarray_add(&m->expansion,
498 ei, NULL); 498 ei, NULL);
499 } 499 }
500 ei = expansionitem_create_param(param); 500 ei = expansionitem_create_param(param);
501 expansionitemarray_add(&m->expansion, ei,NULL); 501 expansionitemarray_add(&m->expansion, ei,NULL);
506 } 506 }
507 pos++; 507 pos++;
508 } 508 }
509 if (pos > blockstart) { 509 if (pos > blockstart) {
510 ei = expansionitem_create_stringlen(buf + blockstart, 510 ei = expansionitem_create_stringlen(buf + blockstart,
511 blockstart - pos); 511 pos - blockstart);
512 expansionitemarray_add(&m->expansion, ei, NULL); 512 expansionitemarray_add(&m->expansion, ei, NULL);
513 } 513 }
514 } 514 }
515 515
516 void 516 void
532 struct place *p3, const char *expansion) 532 struct place *p3, const char *expansion)
533 { 533 {
534 struct macro *m; 534 struct macro *m;
535 535
536 m = macro_define_common_start(p1, macro, p3); 536 m = macro_define_common_start(p1, macro, p3);
537 m->hasparams = true;
537 macro_parse_parameters(m, p2, params); 538 macro_parse_parameters(m, p2, params);
538 macro_parse_expansion(m, expansion); 539 macro_parse_expansion(m, expansion);
539 macro_define_common_end(m); 540 macro_define_common_end(m);
540 } 541 }
541 542
732 expand_send(es, p, "0", 1); 733 expand_send(es, p, "0", 1);
733 return; 734 return;
734 } 735 }
735 m = macrotable_find(stringarray_get(&es->args, 0), false); 736 m = macrotable_find(stringarray_get(&es->args, 0), false);
736 expand_send(es, p, (m != NULL) ? "1" : "0", 1); 737 expand_send(es, p, (m != NULL) ? "1" : "0", 1);
738 expstate_destroyargs(es);
737 return; 739 return;
738 } 740 }
739 741
740 assert(es->curmacro->inuse == false); 742 assert(es->curmacro->inuse == false);
741 es->curmacro->inuse = true; 743 es->curmacro->inuse = true;
742 744
743 newbuf = expand_substitute(es); 745 newbuf = expand_substitute(es);
744 newbuf2 = macroexpand(p, newbuf, strlen(newbuf), false); 746 newbuf2 = macroexpand(p, newbuf, strlen(newbuf), false);
745 free(newbuf); 747 free(newbuf);
748 expstate_destroyargs(es);
746 doexpand(es, p, newbuf2, strlen(newbuf2)); 749 doexpand(es, p, newbuf2, strlen(newbuf2));
747 free(newbuf2); 750 free(newbuf2);
748 751
749 es->curmacro->inuse = false; 752 es->curmacro->inuse = false;
750 } 753 }