comparison macro.c @ 21:e3fab8f1b52c

strip comments.
author David A. Holland
date Mon, 20 Dec 2010 04:15:02 -0500
parents f9792a9ec704
children 18681e5ae6e4
comparison
equal deleted inserted replaced
20:40748b097655 21:e3fab8f1b52c
618 stringarray_setsize(&es->args, 0); 618 stringarray_setsize(&es->args, 0);
619 } 619 }
620 620
621 static 621 static
622 void 622 void
623 expand_send(struct expstate *es, const char *buf, size_t len) 623 expand_send(struct expstate *es, struct place *p, const char *buf, size_t len)
624 { 624 {
625 if (es->tobuf) { 625 if (es->tobuf) {
626 if (es->bufpos + len > es->bufmax) { 626 if (es->bufpos + len > es->bufmax) {
627 if (es->bufmax == 0) { 627 if (es->bufmax == 0) {
628 es->bufmax = 64; 628 es->bufmax = 64;
633 es->buf = dorealloc(es->buf, es->bufmax); 633 es->buf = dorealloc(es->buf, es->bufmax);
634 } 634 }
635 memcpy(es->buf + es->bufpos, buf, len); 635 memcpy(es->buf + es->bufpos, buf, len);
636 es->bufpos += len; 636 es->bufpos += len;
637 } else { 637 } else {
638 output(buf, len); 638 output(p, buf, len);
639 } 639 }
640 } 640 }
641 641
642 static 642 static
643 void 643 void
644 expand_send_eof(struct expstate *es) 644 expand_send_eof(struct expstate *es, struct place *p)
645 { 645 {
646 if (es->tobuf) { 646 if (es->tobuf) {
647 expand_send(es, "", 1); 647 expand_send(es, p, "", 1);
648 es->bufpos--; 648 es->bufpos--;
649 } else { 649 } else {
650 output_eof(); 650 output_eof();
651 } 651 }
652 } 652 }
727 if (es->curmacro == NULL) { 727 if (es->curmacro == NULL) {
728 /* defined() */ 728 /* defined() */
729 if (stringarray_num(&es->args) != 1) { 729 if (stringarray_num(&es->args) != 1) {
730 complain(p, "Too many arguments for defined()"); 730 complain(p, "Too many arguments for defined()");
731 complain_fail(); 731 complain_fail();
732 expand_send(es, "0", 1); 732 expand_send(es, p, "0", 1);
733 return; 733 return;
734 } 734 }
735 m = macrotable_find(stringarray_get(&es->args, 0), false); 735 m = macrotable_find(stringarray_get(&es->args, 0), false);
736 expand_send(es, (m != NULL) ? "1" : "0", 1); 736 expand_send(es, p, (m != NULL) ? "1" : "0", 1);
737 return; 737 return;
738 } 738 }
739 739
740 assert(es->curmacro->inuse == false); 740 assert(es->curmacro->inuse == false);
741 es->curmacro->inuse = true; 741 es->curmacro->inuse = true;
753 void 753 void
754 expand_got_ws(struct expstate *es, struct place *p, char *buf, size_t len) 754 expand_got_ws(struct expstate *es, struct place *p, char *buf, size_t len)
755 { 755 {
756 switch (es->state) { 756 switch (es->state) {
757 case ES_NORMAL: 757 case ES_NORMAL:
758 expand_send(es, buf, len); 758 expand_send(es, p, buf, len);
759 break;
760 break; 759 break;
761 case ES_WANTLPAREN: 760 case ES_WANTLPAREN:
762 break; 761 break;
763 case ES_NOARG: 762 case ES_NOARG:
764 break; 763 break;
784 es->state = ES_WANTLPAREN; 783 es->state = ES_WANTLPAREN;
785 break; 784 break;
786 } 785 }
787 m = macrotable_findlen(buf, len, false); 786 m = macrotable_findlen(buf, len, false);
788 if (m == NULL) { 787 if (m == NULL) {
789 expand_send(es, buf, len); 788 expand_send(es, p, buf, len);
790 } else if (!m->hasparams) { 789 } else if (!m->hasparams) {
791 m->inuse = true; 790 m->inuse = true;
792 assert(expansionitemarray_num(&m->expansion) == 1); 791 assert(expansionitemarray_num(&m->expansion) == 1);
793 ei = expansionitemarray_get(&m->expansion, 0); 792 ei = expansionitemarray_get(&m->expansion, 0);
794 assert(ei->isstring); 793 assert(ei->isstring);
829 void 828 void
830 expand_got_lparen(struct expstate *es, struct place *p, char *buf, size_t len) 829 expand_got_lparen(struct expstate *es, struct place *p, char *buf, size_t len)
831 { 830 {
832 switch (es->state) { 831 switch (es->state) {
833 case ES_NORMAL: 832 case ES_NORMAL:
834 expand_send(es, buf, len); 833 expand_send(es, p, buf, len);
835 break; 834 break;
836 case ES_WANTLPAREN: 835 case ES_WANTLPAREN:
837 es->state = ES_NOARG; 836 es->state = ES_NOARG;
838 break; 837 break;
839 case ES_NOARG: 838 case ES_NOARG:
852 void 851 void
853 expand_got_rparen(struct expstate *es, struct place *p, char *buf, size_t len) 852 expand_got_rparen(struct expstate *es, struct place *p, char *buf, size_t len)
854 { 853 {
855 switch (es->state) { 854 switch (es->state) {
856 case ES_NORMAL: 855 case ES_NORMAL:
857 expand_send(es, buf, len); 856 expand_send(es, p, buf, len);
858 break; 857 break;
859 case ES_WANTLPAREN: 858 case ES_WANTLPAREN:
860 if (es->curmacro) { 859 if (es->curmacro) {
861 complain(p, "Expected arguments for macro %s", 860 complain(p, "Expected arguments for macro %s",
862 es->curmacro->name); 861 es->curmacro->name);
886 void 885 void
887 expand_got_comma(struct expstate *es, struct place *p, char *buf, size_t len) 886 expand_got_comma(struct expstate *es, struct place *p, char *buf, size_t len)
888 { 887 {
889 switch (es->state) { 888 switch (es->state) {
890 case ES_NORMAL: 889 case ES_NORMAL:
891 expand_send(es, buf, len); 890 expand_send(es, p, buf, len);
892 break; 891 break;
893 case ES_WANTLPAREN: 892 case ES_WANTLPAREN:
894 if (es->curmacro) { 893 if (es->curmacro) {
895 complain(p, "Expected arguments for macro %s", 894 complain(p, "Expected arguments for macro %s",
896 es->curmacro->name); 895 es->curmacro->name);
917 void 916 void
918 expand_got_other(struct expstate *es, struct place *p, char *buf, size_t len) 917 expand_got_other(struct expstate *es, struct place *p, char *buf, size_t len)
919 { 918 {
920 switch (es->state) { 919 switch (es->state) {
921 case ES_NORMAL: 920 case ES_NORMAL:
922 expand_send(es, buf, len); 921 expand_send(es, p, buf, len);
923 break; 922 break;
924 case ES_WANTLPAREN: 923 case ES_WANTLPAREN:
925 if (es->curmacro) { 924 if (es->curmacro) {
926 complain(p, "Expected arguments for macro %s", 925 complain(p, "Expected arguments for macro %s",
927 es->curmacro->name); 926 es->curmacro->name);
944 void 943 void
945 expand_got_eof(struct expstate *es, struct place *p) 944 expand_got_eof(struct expstate *es, struct place *p)
946 { 945 {
947 switch (es->state) { 946 switch (es->state) {
948 case ES_NORMAL: 947 case ES_NORMAL:
949 expand_send_eof(es); 948 expand_send_eof(es, p);
950 break; 949 break;
951 case ES_WANTLPAREN: 950 case ES_WANTLPAREN:
952 if (es->curmacro) { 951 if (es->curmacro) {
953 complain(p, "Expected arguments for macro %s", 952 complain(p, "Expected arguments for macro %s",
954 es->curmacro->name); 953 es->curmacro->name);
1041 1040
1042 void 1041 void
1043 macro_sendline(struct place *p, char *buf, size_t len) 1042 macro_sendline(struct place *p, char *buf, size_t len)
1044 { 1043 {
1045 doexpand(&mainstate, p, buf, len); 1044 doexpand(&mainstate, p, buf, len);
1045 output(p, "\n", 1);
1046 } 1046 }
1047 1047
1048 void 1048 void
1049 macro_sendeof(struct place *p) 1049 macro_sendeof(struct place *p)
1050 { 1050 {