Mercurial > ~dholland > hg > tradcpp > index.cgi
comparison macro.c @ 199:1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
Intended to be used when debugging imake templates and other complex
input, not for debugging tradcpp itself.
author | David A. Holland |
---|---|
date | Sun, 04 Sep 2016 17:14:42 -0400 (2016-09-04) |
parents | 255db24bc29b |
children | 3a25180d3a5c |
comparison
equal
deleted
inserted
replaced
198:4158b974e23f | 199:1d2bad7151f9 |
---|---|
874 static | 874 static |
875 void | 875 void |
876 expand_domacro(struct expstate *es, struct place *p) | 876 expand_domacro(struct expstate *es, struct place *p) |
877 { | 877 { |
878 struct macro *m; | 878 struct macro *m; |
879 const char *name, *val; | |
879 char *newbuf, *newbuf2; | 880 char *newbuf, *newbuf2; |
880 | 881 |
881 if (es->curmacro == NULL) { | 882 if (es->curmacro == NULL) { |
882 /* defined() */ | 883 /* defined() */ |
883 if (stringarray_num(&es->args) != 1) { | 884 if (stringarray_num(&es->args) != 1) { |
884 complain(p, "Too many arguments for defined()"); | 885 complain(p, "Too many arguments for defined()"); |
885 complain_fail(); | 886 complain_fail(); |
886 expand_send(es, p, "0", 1); | 887 expand_send(es, p, "0", 1); |
887 return; | 888 return; |
888 } | 889 } |
889 m = macrotable_find(stringarray_get(&es->args, 0), false); | 890 name = stringarray_get(&es->args, 0); |
890 expand_send(es, p, (m != NULL) ? "1" : "0", 1); | 891 m = macrotable_find(name, false); |
892 val = (m != NULL) ? "1" : "0"; | |
893 debuglog(p, "defined(%s): %s", name, val); | |
894 expand_send(es, p, val, 1); | |
891 expstate_destroyargs(es); | 895 expstate_destroyargs(es); |
892 return; | 896 return; |
893 } | 897 } |
894 | 898 |
895 m = es->curmacro; | 899 m = es->curmacro; |
896 assert(m->inuse == false); | 900 assert(m->inuse == false); |
897 m->inuse = true; | 901 m->inuse = true; |
898 | 902 |
903 debuglog(p, "Expanding macro %s", m->name); | |
899 newbuf = expand_substitute(p, es); | 904 newbuf = expand_substitute(p, es); |
905 debuglog(p, "Substituting for %s: %s", m->name, newbuf); | |
906 | |
900 newbuf2 = macroexpand(p, newbuf, strlen(newbuf), false); | 907 newbuf2 = macroexpand(p, newbuf, strlen(newbuf), false); |
901 dostrfree(newbuf); | 908 dostrfree(newbuf); |
902 expstate_destroyargs(es); | 909 expstate_destroyargs(es); |
910 debuglog(p, "Complete expansion for %s: %s", m->name, newbuf2); | |
911 | |
903 doexpand(es, p, newbuf2, strlen(newbuf2)); | 912 doexpand(es, p, newbuf2, strlen(newbuf2)); |
904 dostrfree(newbuf2); | 913 dostrfree(newbuf2); |
905 | 914 |
906 m->inuse = false; | 915 m->inuse = false; |
907 } | 916 } |