Lines Matching refs:es
686 static void doexpand(struct expstate *es, struct place *p,
691 expstate_init(struct expstate *es, bool tobuf, bool honordefined)
693 es->honordefined = honordefined;
694 es->state = ES_NORMAL;
695 es->curmacro = NULL;
696 stringarray_init(&es->args);
697 es->argparens = 0;
698 es->tobuf = tobuf;
699 es->buf = NULL;
700 es->bufpos = 0;
701 es->bufmax = 0;
706 expstate_cleanup(struct expstate *es)
708 assert(es->state == ES_NORMAL);
709 stringarray_cleanup(&es->args);
710 if (es->buf) {
711 dofree(es->buf, es->bufmax);
717 expstate_destroyargs(struct expstate *es)
721 num = stringarray_num(&es->args);
723 dostrfree(stringarray_get(&es->args, i));
725 stringarray_setsize(&es->args, 0);
730 expand_send(struct expstate *es, struct place *p, const char *buf, size_t len)
734 if (es->tobuf) {
735 assert(es->bufpos <= es->bufmax);
736 if (es->bufpos + len > es->bufmax) {
737 oldmax = es->bufmax;
738 if (es->bufmax == 0) {
739 es->bufmax = 64;
741 while (es->bufpos + len > es->bufmax) {
742 es->bufmax *= 2;
744 es->buf = dorealloc(es->buf, oldmax, es->bufmax);
746 memcpy(es->buf + es->bufpos, buf, len);
747 es->bufpos += len;
748 assert(es->bufpos <= es->bufmax);
756 expand_send_eof(struct expstate *es, struct place *p)
758 if (es->tobuf) {
759 expand_send(es, p, "", 1);
760 es->bufpos--;
768 expand_newarg(struct expstate *es, const char *buf, size_t len)
773 stringarray_add(&es->args, text, NULL);
778 expand_appendarg(struct expstate *es, const char *buf, size_t len)
784 num = stringarray_num(&es->args);
787 text = stringarray_get(&es->args, num - 1);
792 stringarray_set(&es->args, num - 1, text);
797 expand_substitute(struct place *p, struct expstate *es)
807 numargs = stringarray_num(&es->args);
808 numparams = stringarray_num(&es->curmacro->params);
812 stringarray_add(&es->args, dostrdup(""), NULL);
818 es->curmacro->name, numargs, numparams);
821 stringarray_add(&es->args, dostrdup(""), NULL);
827 num = expansionitemarray_num(&es->curmacro->expansion);
829 ei = expansionitemarray_get(&es->curmacro->expansion, i);
835 arg = stringarray_get(&es->args, ei->ei_param);
850 ei = expansionitemarray_get(&es->curmacro->expansion, i);
856 arg = stringarray_get(&es->args, ei->ei_param);
876 expand_domacro(struct expstate *es, struct place *p)
882 if (es->curmacro == NULL) {
884 if (stringarray_num(&es->args) != 1) {
887 expand_send(es, p, "0", 1);
890 name = stringarray_get(&es->args, 0);
894 expand_send(es, p, val, 1);
895 expstate_destroyargs(es);
899 m = es->curmacro;
904 newbuf = expand_substitute(p, es);
909 expstate_destroyargs(es);
912 doexpand(es, p, newbuf2, strlen(newbuf2));
925 expand_missingargs(struct expstate *es, struct place *p, bool needspace)
927 if (es->curmacro == NULL) {
929 expand_send(es, p, "defined", 7);
932 expand_send(es, p, es->curmacro->name, strlen(es->curmacro->name));
935 expand_send(es, p, " ", 1);
941 expand_got_ws(struct expstate *es, struct place *p,
944 switch (es->state) {
946 expand_send(es, p, buf, len);
950 //expand_send(es, p, buf, len);
953 expand_newarg(es, buf, len);
954 es->state = ES_HAVEARG;
957 expand_appendarg(es, buf, len);
964 expand_got_word(struct expstate *es, struct place *p,
969 switch (es->state) {
971 if (es->honordefined &&
973 es->curmacro = NULL;
974 es->state = ES_WANTLPAREN;
979 expand_send(es, p, buf, len);
981 es->curmacro = m;
982 expand_domacro(es, p);
984 es->curmacro = m;
985 es->state = ES_WANTLPAREN;
989 if (es->curmacro != NULL) {
990 expand_missingargs(es, p, true);
991 es->state = ES_NORMAL;
993 expand_got_word(es, p, buf, len);
996 expand_newarg(es, buf, len);
997 es->state = ES_NORMAL;
998 expand_domacro(es, p);
1002 expand_newarg(es, buf, len);
1003 es->state = ES_HAVEARG;
1006 expand_appendarg(es, buf, len);
1013 expand_got_lparen(struct expstate *es, struct place *p,
1016 switch (es->state) {
1018 expand_send(es, p, buf, len);
1021 es->state = ES_NOARG;
1024 expand_newarg(es, buf, len);
1025 es->state = ES_HAVEARG;
1026 es->argparens++;
1029 expand_appendarg(es, buf, len);
1030 es->argparens++;
1037 expand_got_rparen(struct expstate *es, struct place *p,
1040 switch (es->state) {
1042 expand_send(es, p, buf, len);
1045 expand_missingargs(es, p, false);
1046 es->state = ES_NORMAL;
1048 expand_got_rparen(es, p, buf, len);
1051 assert(es->argparens == 0);
1052 if (stringarray_num(&es->args) > 0) {
1054 expand_newarg(es, buf, 0);
1056 es->state = ES_NORMAL;
1057 expand_domacro(es, p);
1060 if (es->argparens > 0) {
1061 es->argparens--;
1062 expand_appendarg(es, buf, len);
1064 es->state = ES_NORMAL;
1065 expand_domacro(es, p);
1073 expand_got_comma(struct expstate *es, struct place *p,
1076 switch (es->state) {
1078 expand_send(es, p, buf, len);
1081 expand_missingargs(es, p, false);
1082 es->state = ES_NORMAL;
1084 expand_got_comma(es, p, buf, len);
1087 assert(es->argparens == 0);
1088 expand_newarg(es, buf, 0);
1091 if (es->argparens > 0) {
1092 expand_appendarg(es, buf, len);
1094 es->state = ES_NOARG;
1102 expand_got_other(struct expstate *es, struct place *p,
1105 switch (es->state) {
1107 expand_send(es, p, buf, len);
1110 expand_missingargs(es, p, false);
1111 es->state = ES_NORMAL;
1113 expand_got_other(es, p, buf, len);
1116 expand_newarg(es, buf, len);
1117 es->state = ES_HAVEARG;
1120 expand_appendarg(es, buf, len);
1127 expand_got_eof(struct expstate *es, struct place *p)
1129 switch (es->state) {
1133 expand_missingargs(es, p, false);
1137 if (es->curmacro) {
1139 es->curmacro->name);
1144 expstate_destroyargs(es);
1147 expand_send_eof(es, p);
1148 es->state = ES_NORMAL;
1149 es->curmacro = NULL;
1150 es->argparens = 0;
1155 doexpand(struct expstate *es, struct place *p, const char *buf, size_t len)
1170 expand_got_ws(es, p, buf, x);
1183 expand_got_word(es, p, buf, x);
1196 expand_got_ws(es, p, buf, x);
1203 expand_got_lparen(es, p, buf, 1);
1210 expand_got_rparen(es, p, buf, 1);
1217 expand_got_comma(es, p, buf, 1);
1225 expand_got_other(es, p, buf, 2);
1237 expand_got_other(es, p, buf, 1);
1246 struct expstate es;
1249 expstate_init(&es, true, honordefined);
1250 doexpand(&es, p, buf, len);
1251 expand_got_eof(&es, p);
1254 es.buf = dorealloc(es.buf, es.bufmax, strlen(es.buf) + 1);
1256 ret = es.buf;
1257 es.buf = NULL;
1258 es.bufpos = es.bufmax = 0;
1260 expstate_cleanup(&es);