1 #line 982 "../../src/builtin/snarf.m4"
2 /* -*- buffer-read-only: t -*- vi: set ro:
3    THIS FILE IS GENERATED AUTOMATICALLY.  PLEASE DO NOT EDIT.
4 */
5 #line 982
6 #ifdef HAVE_CONFIG_H
7 #line 982
8 # include <config.h>
9 #line 982
10 #endif
11 #line 982
12 #include <sys/types.h>
13 #line 982
14 
15 #line 982
16 #include "mailfromd.h"
17 #line 982
18 #include "prog.h"
19 #line 982
20 #include "builtin.h"
21 #line 982
22 
23 #line 982
24 
25 #line 1022 "../../src/builtin/snarf.m4"
26 
27 /* End of snarf.m4 */
28 #line 1 "string.bi"
29 /* This file is part of Mailfromd.             -*- c -*-
30    Copyright (C) 2006-2021 Sergey Poznyakoff
31 
32    This program is free software; you can redistribute it and/or modify
33    it under the terms of the GNU General Public License as published by
34    the Free Software Foundation; either version 3, or (at your option)
35    any later version.
36 
37    This program is distributed in the hope that it will be useful,
38    but WITHOUT ANY WARRANTY; without even the implied warranty of
39    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40    GNU General Public License for more details.
41 
42    You should have received a copy of the GNU General Public License
43    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
44 
45 
46 
47 void
48 #line 19
bi_toupper(eval_environ_t env)49 bi_toupper(eval_environ_t env)
50 #line 19
51 
52 #line 19
53 
54 #line 19 "string.bi"
55 {
56 #line 19
57 
58 #line 19
59 
60 #line 19
61 
62 #line 19
63 char * MFL_DATASEG string;
64 #line 19
65 
66 #line 19
67 get_string_arg(env, 0, &string);
68 #line 19
69 
70 #line 19
71 
72 #line 19
73         adjust_stack(env, 1);
74 #line 19
75 
76 #line 19
77 
78 #line 19
79 	if (builtin_module_trace(BUILTIN_IDX_string))
80 #line 19
81 		prog_trace(env, "toupper %s",string);;
82 #line 19
83 
84 {
85 	size_t off;
86 	char *s = strcpy((char*)env_data_ref(env, off = heap_reserve(env, strlen(string) + 1)), string);
87 	char *p;
88 	for (p = s; *p; p++)
89 		*p = toupper(*p);
90 
91 #line 26
92 do {
93 #line 26
94   push(env, (STKVAL) (mft_size) (off));
95 #line 26
96   goto endlab;
97 #line 26
98 } while (0);
99 }
100 endlab:
101 #line 28
102         env_function_cleanup_flush(env, NULL);
103 #line 28
104 	return;
105 #line 28
106 }
107 
108 void
109 #line 30
bi_tolower(eval_environ_t env)110 bi_tolower(eval_environ_t env)
111 #line 30
112 
113 #line 30
114 
115 #line 30 "string.bi"
116 {
117 #line 30
118 
119 #line 30
120 
121 #line 30
122 
123 #line 30
124 char * MFL_DATASEG string;
125 #line 30
126 
127 #line 30
128 get_string_arg(env, 0, &string);
129 #line 30
130 
131 #line 30
132 
133 #line 30
134         adjust_stack(env, 1);
135 #line 30
136 
137 #line 30
138 
139 #line 30
140 	if (builtin_module_trace(BUILTIN_IDX_string))
141 #line 30
142 		prog_trace(env, "tolower %s",string);;
143 #line 30
144 
145 {
146 	size_t off;
147 	char *s = strcpy((char*)env_data_ref(env, off = heap_reserve(env, strlen(string) + 1)), string);
148 	char *p;
149 	for (p = s; *p; p++)
150 		*p = tolower(*p);
151 
152 #line 37
153 do {
154 #line 37
155   push(env, (STKVAL) (mft_size) (off));
156 #line 37
157   goto endlab;
158 #line 37
159 } while (0);
160 }
161 endlab:
162 #line 39
163         env_function_cleanup_flush(env, NULL);
164 #line 39
165 	return;
166 #line 39
167 }
168 
169 void
170 #line 41
bi_length(eval_environ_t env)171 bi_length(eval_environ_t env)
172 #line 41
173 
174 #line 41
175 
176 #line 41 "string.bi"
177 {
178 #line 41
179 
180 #line 41
181 
182 #line 41
183 
184 #line 41
185 char *  string;
186 #line 41
187 
188 #line 41
189 get_string_arg(env, 0, &string);
190 #line 41
191 
192 #line 41
193 
194 #line 41
195         adjust_stack(env, 1);
196 #line 41
197 
198 #line 41
199 
200 #line 41
201 	if (builtin_module_trace(BUILTIN_IDX_string))
202 #line 41
203 		prog_trace(env, "length %s",string);;
204 #line 41
205 
206 {
207 
208 #line 43
209 do {
210 #line 43
211   push(env, (STKVAL)(mft_number)(strlen(string)));
212 #line 43
213   goto endlab;
214 #line 43
215 } while (0);
216 }
217 endlab:
218 #line 45
219         env_function_cleanup_flush(env, NULL);
220 #line 45
221 	return;
222 #line 45
223 }
224 
225 void
226 #line 47
bi_substring(eval_environ_t env)227 bi_substring(eval_environ_t env)
228 #line 47
229 
230 #line 47
231 
232 #line 47 "string.bi"
233 {
234 #line 47
235 
236 #line 47
237 
238 #line 47
239 
240 #line 47
241 char * MFL_DATASEG string;
242 #line 47
243         long  start;
244 #line 47
245         long  end;
246 #line 47
247 
248 #line 47
249 get_string_arg(env, 0, &string);
250 #line 47
251         get_numeric_arg(env, 1, &start);
252 #line 47
253         get_numeric_arg(env, 2, &end);
254 #line 47
255 
256 #line 47
257 
258 #line 47
259         adjust_stack(env, 3);
260 #line 47
261 
262 #line 47
263 
264 #line 47
265 	if (builtin_module_trace(BUILTIN_IDX_string))
266 #line 47
267 		prog_trace(env, "substring %s %lu %lu",string, start, end);;
268 #line 47
269 
270 {
271 	size_t off;
272 	long len = strlen(string);
273 	char *s;
274 
275 	if (end < 0)
276 		end = len + end;
277 	if (end < start) {
278 		long t = end;
279 		end = start;
280 		start = t;
281 	}
282 
283 		if (!(start < len && end < len))
284 #line 61
285 		(
286 #line 61
287 	env_throw_bi(env, mfe_range, "substring", _("argument out of range"))
288 #line 61
289 )
290 ;
291 
292 	len = end - start + 1;
293 	s = (char*) env_data_ref(env, (off = heap_reserve(env, len + 1)));
294 	memcpy(s, string + start, len);
295 	s[len] = 0;
296 
297 
298 #line 69
299 do {
300 #line 69
301   push(env, (STKVAL) (mft_size) (off));
302 #line 69
303   goto endlab;
304 #line 69
305 } while (0);
306 }
307 endlab:
308 #line 71
309         env_function_cleanup_flush(env, NULL);
310 #line 71
311 	return;
312 #line 71
313 }
314 
315 void
316 #line 73
bi_substr(eval_environ_t env)317 bi_substr(eval_environ_t env)
318 #line 73
319 
320 #line 73
321 
322 #line 73 "string.bi"
323 {
324 #line 73
325 
326 #line 73
327 
328 #line 73
329 long __bi_argcnt;
330 #line 73
331 char * MFL_DATASEG string;
332 #line 73
333         long  start;
334 #line 73
335         long  nbytes;
336 #line 73
337 
338 #line 73
339 get_string_arg(env, 1, &string);
340 #line 73
341         get_numeric_arg(env, 2, &start);
342 #line 73
343         get_numeric_arg(env, 3, &nbytes);
344 #line 73
345 
346 #line 73
347 get_numeric_arg(env, 0, &__bi_argcnt);
348 #line 73
349         adjust_stack(env, __bi_argcnt + 1);
350 #line 73
351 
352 #line 73
353 
354 #line 73
355 	if (builtin_module_trace(BUILTIN_IDX_string))
356 #line 73
357 		prog_trace(env, "substr %s %lu %lu",string, start, ((__bi_argcnt > 2) ? nbytes : 0));;
358 #line 73
359 
360 {
361 	size_t off;
362 	long len = strlen(string);
363 	char *s;
364 
365 		if (!(start >= 0))
366 #line 79
367 		(
368 #line 79
369 	env_throw_bi(env, mfe_range, "substr", _("argument out of range: start=%ld"),start)
370 #line 79
371 )
372 ;
373 	if (!(__bi_argcnt > 2))
374 		nbytes = len - start;
375 		if (!(nbytes >= 0))
376 #line 83
377 		(
378 #line 83
379 	env_throw_bi(env, mfe_range, "substr", _("argument out of range: start=%ld, len=%ld"),start,len)
380 #line 83
381 )
382 ;
383 
384 	s = (char*) env_data_ref(env, (off = heap_reserve(env, nbytes + 1)));
385 	memcpy(s, string + start, nbytes);
386 	s[nbytes] = 0;
387 
388 
389 #line 90
390 do {
391 #line 90
392   push(env, (STKVAL) (mft_size) (off));
393 #line 90
394   goto endlab;
395 #line 90
396 } while (0);
397 }
398 endlab:
399 #line 92
400         env_function_cleanup_flush(env, NULL);
401 #line 92
402 	return;
403 #line 92
404 }
405 
406 void
407 #line 94
bi_index(eval_environ_t env)408 bi_index(eval_environ_t env)
409 #line 94
410 
411 #line 94
412 
413 #line 94 "string.bi"
414 {
415 #line 94
416 
417 #line 94
418 
419 #line 94
420 long __bi_argcnt;
421 #line 94
422 char *  str;
423 #line 94
424         char *  sub;
425 #line 94
426         long  from;
427 #line 94
428 
429 #line 94
430 get_string_arg(env, 1, &str);
431 #line 94
432         get_string_arg(env, 2, &sub);
433 #line 94
434         get_numeric_arg(env, 3, &from);
435 #line 94
436 
437 #line 94
438 get_numeric_arg(env, 0, &__bi_argcnt);
439 #line 94
440         adjust_stack(env, __bi_argcnt + 1);
441 #line 94
442 
443 #line 94
444 
445 #line 94
446 	if (builtin_module_trace(BUILTIN_IDX_string))
447 #line 94
448 		prog_trace(env, "index %s %s %lu",str, sub, ((__bi_argcnt > 2) ? from : 0));;
449 #line 94
450 
451 {
452 	long start = 0;
453 	char *p;
454 
455 	if ((__bi_argcnt > 2))
456 		start = from;
457 		if (!(start >= 0 && start <= strlen(str)))
458 #line 101
459 		(
460 #line 101
461 	env_throw_bi(env, mfe_range, "index", _("argument out of range: start=%ld"),start)
462 #line 101
463 )
464 ;
465 	p = strstr(str + start, sub);
466 
467 #line 104
468 do {
469 #line 104
470   push(env, (STKVAL)(mft_number)(p ? p - str : -1));
471 #line 104
472   goto endlab;
473 #line 104
474 } while (0);
475 }
476 endlab:
477 #line 106
478         env_function_cleanup_flush(env, NULL);
479 #line 106
480 	return;
481 #line 106
482 }
483 
484 
485 void
486 #line 109
bi_rindex(eval_environ_t env)487 bi_rindex(eval_environ_t env)
488 #line 109
489 
490 #line 109
491 
492 #line 109 "string.bi"
493 {
494 #line 109
495 
496 #line 109
497 
498 #line 109
499 long __bi_argcnt;
500 #line 109
501 char * MFL_DATASEG str;
502 #line 109
503         char * MFL_DATASEG sub;
504 #line 109
505         long  from;
506 #line 109
507 
508 #line 109
509 get_string_arg(env, 1, &str);
510 #line 109
511         get_string_arg(env, 2, &sub);
512 #line 109
513         get_numeric_arg(env, 3, &from);
514 #line 109
515 
516 #line 109
517 get_numeric_arg(env, 0, &__bi_argcnt);
518 #line 109
519         adjust_stack(env, __bi_argcnt + 1);
520 #line 109
521 
522 #line 109
523 
524 #line 109
525 	if (builtin_module_trace(BUILTIN_IDX_string))
526 #line 109
527 		prog_trace(env, "rindex %s %s %lu",str, sub, ((__bi_argcnt > 2) ? from : 0));;
528 #line 109
529 
530 {
531 	size_t start = 0;
532 	int slen, xlen, rc;
533 	char *p, *s, *x;
534 	char *temp;
535 
536 	slen = strlen(str);
537 	xlen = strlen(sub);
538 	temp = mf_c_val(heap_tempspace(env, xlen + slen + 2), ptr);
539 	s = temp;
540 	x = s + slen + 1;
541 
542 	if ((__bi_argcnt > 2)) {
543 			if (!(from >=0 && from <= slen))
544 #line 123
545 		(
546 #line 123
547 	env_throw_bi(env, mfe_range, "rindex", _("argument out of range: start=%ld"),from)
548 #line 123
549 )
550 ;
551 		start = slen - from;
552 	}
553 
554 	/* Reverse str */
555 #define REV(v,s,l)                                         \
556 	l = strlen(s);                                     \
557 	v[l] = 0;                                          \
558 	for (p = v + l - 1; p >= v; p--, s++)              \
559 		*p = *s;
560 
561 	REV(s,str,slen);
562 	REV(x,sub,xlen);
563 
564 	p = strstr(s + start, x);
565 	if (p)
566 		rc = slen - (p - s + xlen);
567 	else
568 		rc = -1;
569 
570 
571 #line 144
572 do {
573 #line 144
574   push(env, (STKVAL)(mft_number)(rc));
575 #line 144
576   goto endlab;
577 #line 144
578 } while (0);
579 }
580 endlab:
581 #line 146
582         env_function_cleanup_flush(env, NULL);
583 #line 146
584 	return;
585 #line 146
586 }
587 
588 void
589 #line 148
bi_revstr(eval_environ_t env)590 bi_revstr(eval_environ_t env)
591 #line 148
592 
593 #line 148
594 
595 #line 148 "string.bi"
596 {
597 #line 148
598 
599 #line 148
600 
601 #line 148
602 
603 #line 148
604 char * MFL_DATASEG str;
605 #line 148
606 
607 #line 148
608 get_string_arg(env, 0, &str);
609 #line 148
610 
611 #line 148
612 
613 #line 148
614         adjust_stack(env, 1);
615 #line 148
616 
617 #line 148
618 
619 #line 148
620 	if (builtin_module_trace(BUILTIN_IDX_string))
621 #line 148
622 		prog_trace(env, "revstr %s",str);;
623 #line 148
624 
625 {
626 	int len = strlen(str);
627 	char *p;
628 	size_t off;
629 	char *s = (char*) env_data_ref(env, (off = heap_reserve(env, len + 1)));
630 
631 	s[len] = 0;
632 	for (p = s + len - 1; p >= s; p--, str++)
633 		*p = *str;
634 
635 #line 158
636 do {
637 #line 158
638   push(env, (STKVAL) (mft_size) (off));
639 #line 158
640   goto endlab;
641 #line 158
642 } while (0);
643 }
644 endlab:
645 #line 160
646         env_function_cleanup_flush(env, NULL);
647 #line 160
648 	return;
649 #line 160
650 }
651 
652 void
653 #line 162
bi_replstr(eval_environ_t env)654 bi_replstr(eval_environ_t env)
655 #line 162
656 
657 #line 162
658 
659 #line 162 "string.bi"
660 {
661 #line 162
662 
663 #line 162
664 
665 #line 162
666 
667 #line 162
668 char * MFL_DATASEG text;
669 #line 162
670         long  count;
671 #line 162
672 
673 #line 162
674 get_string_arg(env, 0, &text);
675 #line 162
676         get_numeric_arg(env, 1, &count);
677 #line 162
678 
679 #line 162
680 
681 #line 162
682         adjust_stack(env, 2);
683 #line 162
684 
685 #line 162
686 
687 #line 162
688 	if (builtin_module_trace(BUILTIN_IDX_string))
689 #line 162
690 		prog_trace(env, "replstr %s %lu",text, count);;
691 #line 162
692 
693 {
694 	size_t size, len, i;
695 	size_t off;
696 	char *s;
697 
698 		if (!(count >= 0))
699 #line 168
700 		(
701 #line 168
702 	env_throw_bi(env, mfe_range, "replstr", _("argument out of range: count=%ld"),count)
703 #line 168
704 )
705 ;
706 	if (count == 0)
707 
708 #line 171
709 do {
710 #line 171
711   pushs(env, "");
712 #line 171
713   goto endlab;
714 #line 171
715 } while (0);
716 
717 	len = strlen(text);
718 	size = len * count;
719 	s = (char*) env_data_ref(env, (off = heap_reserve(env, size + 1)));
720 	for (i = 0; i < count; i++, s += len)
721 		memcpy(s, text, len);
722 	*s = 0;
723 
724 #line 179
725 do {
726 #line 179
727   push(env, (STKVAL) (mft_size) (off));
728 #line 179
729   goto endlab;
730 #line 179
731 } while (0);
732 }
733 endlab:
734 #line 181
735         env_function_cleanup_flush(env, NULL);
736 #line 181
737 	return;
738 #line 181
739 }
740 
741 void
742 #line 183
bi_message_header_decode(eval_environ_t env)743 bi_message_header_decode(eval_environ_t env)
744 #line 183
745 
746 #line 183
747 
748 #line 183 "string.bi"
749 {
750 #line 183
751 
752 #line 183
753 
754 #line 183
755 long __bi_argcnt;
756 #line 183
757 char * MFL_DATASEG text;
758 #line 183
759         char * MFL_DATASEG charset;
760 #line 183
761 
762 #line 183
763 get_string_arg(env, 1, &text);
764 #line 183
765         get_string_arg(env, 2, &charset);
766 #line 183
767 
768 #line 183
769 get_numeric_arg(env, 0, &__bi_argcnt);
770 #line 183
771         adjust_stack(env, __bi_argcnt + 1);
772 #line 183
773 
774 #line 183
775 
776 #line 183
777 	if (builtin_module_trace(BUILTIN_IDX_string))
778 #line 183
779 		prog_trace(env, "message_header_decode %s %s",text, ((__bi_argcnt > 1) ? charset : ""));;
780 #line 183
781 
782 {
783 	char *p;
784 	int rc = mu_rfc2047_decode (((__bi_argcnt > 1) ? charset : "utf-8"), text, &p);
785 		if (!(rc == 0))
786 #line 187
787 		(
788 #line 187
789 	env_throw_bi(env, mfe_failure, "message_header_decode", _("error decoding string: %s"),mu_strerror(rc))
790 #line 187
791 )
792 #line 190
793 ;
794 	pushs(env, p);
795 	free(p);
796 }
797 
798 #line 194
799         env_function_cleanup_flush(env, NULL);
800 #line 194
801 	return;
802 #line 194
803 }
804 
805 void
806 #line 196
bi_message_header_encode(eval_environ_t env)807 bi_message_header_encode(eval_environ_t env)
808 #line 196
809 
810 #line 196
811 
812 #line 196 "string.bi"
813 {
814 #line 196
815 
816 #line 196
817 
818 #line 196
819 long __bi_argcnt;
820 #line 196
821 char * MFL_DATASEG text;
822 #line 196
823         char * MFL_DATASEG encoding;
824 #line 196
825         char * MFL_DATASEG charset;
826 #line 196
827 
828 #line 196
829 get_string_arg(env, 1, &text);
830 #line 196
831         get_string_arg(env, 2, &encoding);
832 #line 196
833         get_string_arg(env, 3, &charset);
834 #line 196
835 
836 #line 196
837 get_numeric_arg(env, 0, &__bi_argcnt);
838 #line 196
839         adjust_stack(env, __bi_argcnt + 1);
840 #line 196
841 
842 #line 196
843 
844 #line 196
845 	if (builtin_module_trace(BUILTIN_IDX_string))
846 #line 196
847 		prog_trace(env, "message_header_encode %s %s %s",text, ((__bi_argcnt > 1) ? encoding : ""), ((__bi_argcnt > 2) ? charset : ""));;
848 
849 {
850 	char *p;
851 	int rc = mu_rfc2047_encode (((__bi_argcnt > 2) ? charset : "utf-8"),
852 				    ((__bi_argcnt > 1) ? encoding : "quoted-printable"),
853 				    text, &p);
854 		if (!(rc == 0))
855 #line 203
856 		(
857 #line 203
858 	env_throw_bi(env, mfe_failure, "message_header_encode", _("error encoding string: %s"),mu_strerror(rc))
859 #line 203
860 )
861 #line 206
862 ;
863 	pushs(env, p);
864 	free(p);
865 }
866 
867 #line 210
868         env_function_cleanup_flush(env, NULL);
869 #line 210
870 	return;
871 #line 210
872 }
873 
874 void
875 #line 212
bi_unfold(eval_environ_t env)876 bi_unfold(eval_environ_t env)
877 #line 212
878 
879 #line 212
880 
881 #line 212 "string.bi"
882 {
883 #line 212
884 
885 #line 212
886 
887 #line 212
888 
889 #line 212
890 char * MFL_DATASEG text;
891 #line 212
892 
893 #line 212
894 get_string_arg(env, 0, &text);
895 #line 212
896 
897 #line 212
898 
899 #line 212
900         adjust_stack(env, 1);
901 #line 212
902 
903 #line 212
904 
905 #line 212
906 	if (builtin_module_trace(BUILTIN_IDX_string))
907 #line 212
908 		prog_trace(env, "unfold %s",text);;
909 #line 212
910 
911 {
912 	size_t off;
913 	char *s = strcpy((char*)env_data_ref(env, off = heap_reserve(env, strlen(text) + 1)), text);
914 	mu_string_unfold(s, NULL);
915 
916 #line 217
917 do {
918 #line 217
919   push(env, (STKVAL) (mft_size) (off));
920 #line 217
921   goto endlab;
922 #line 217
923 } while (0);
924 }
925 endlab:
926 #line 219
927         env_function_cleanup_flush(env, NULL);
928 #line 219
929 	return;
930 #line 219
931 }
932 
933 void
934 #line 221
bi_escape(eval_environ_t env)935 bi_escape(eval_environ_t env)
936 #line 221
937 
938 #line 221
939 
940 #line 221 "string.bi"
941 {
942 #line 221
943 
944 #line 221
945 
946 #line 221
947 long __bi_argcnt;
948 #line 221
949 char * MFL_DATASEG text;
950 #line 221
951         char * MFL_DATASEG chars;
952 #line 221
953 
954 #line 221
955 get_string_arg(env, 1, &text);
956 #line 221
957         get_string_arg(env, 2, &chars);
958 #line 221
959 
960 #line 221
961 get_numeric_arg(env, 0, &__bi_argcnt);
962 #line 221
963         adjust_stack(env, __bi_argcnt + 1);
964 #line 221
965 
966 #line 221
967 
968 #line 221
969 	if (builtin_module_trace(BUILTIN_IDX_string))
970 #line 221
971 		prog_trace(env, "escape %s %s",text, ((__bi_argcnt > 1) ? chars : ""));;
972 #line 221
973 
974 {
975 	char *charmap = ((__bi_argcnt > 1) ? chars : "\\\"");
976 
977 	if (text[strcspn(text, charmap)] == 0)
978 
979 #line 226
980 do {
981 #line 226
982   pushs(env, text);
983 #line 226
984   goto endlab;
985 #line 226
986 } while (0);
987 
988 	heap_obstack_begin(env);
989 	for (;;) {
990 		size_t len = strcspn(text, charmap);
991 		if (len)
992 			heap_obstack_grow(env, text, len);
993 		if (text[len]) {
994 			do { char __c = '\\'; heap_obstack_grow(env, &__c, 1); } while(0);
995 			do { char __c = text[len]; heap_obstack_grow(env, &__c, 1); } while(0);
996 			text += len + 1;
997 		} else
998 			break;
999 	}
1000 	do { char __c = 0; heap_obstack_grow(env, &__c, 1); } while(0);
1001 
1002 #line 241
1003 do {
1004 #line 241
1005   push(env, (STKVAL) (heap_obstack_finish(env)));
1006 #line 241
1007   goto endlab;
1008 #line 241
1009 } while (0);
1010 }
1011 endlab:
1012 #line 243
1013         env_function_cleanup_flush(env, NULL);
1014 #line 243
1015 	return;
1016 #line 243
1017 }
1018 
1019 void
1020 #line 245
bi_qr(eval_environ_t env)1021 bi_qr(eval_environ_t env)
1022 #line 245
1023 
1024 #line 245
1025 
1026 #line 245 "string.bi"
1027 {
1028 #line 245
1029 
1030 #line 245
1031 
1032 #line 245
1033 long __bi_argcnt;
1034 #line 245
1035 long  regex_flags;
1036 #line 245
1037         char * MFL_DATASEG text;
1038 #line 245
1039         char * MFL_DATASEG delim;
1040 #line 245
1041 
1042 #line 245
1043 get_numeric_arg(env, 1, &regex_flags);
1044 #line 245
1045         get_string_arg(env, 2, &text);
1046 #line 245
1047         get_string_arg(env, 3, &delim);
1048 #line 245
1049 
1050 #line 245
1051 get_numeric_arg(env, 0, &__bi_argcnt);
1052 #line 245
1053         adjust_stack(env, __bi_argcnt + 1);
1054 #line 245
1055 
1056 #line 245
1057 
1058 #line 245
1059 	if (builtin_module_trace(BUILTIN_IDX_string))
1060 #line 245
1061 		prog_trace(env, "qr %lu %s %s",regex_flags, text, ((__bi_argcnt > 2) ? delim : ""));;
1062 #line 245
1063 
1064 {
1065 	static char *qc[] = {
1066 		/* Basic regular expressions */
1067 		"\\+*?[]",
1068 		/* Extended regular expressions */
1069 		"\\+*?[](){}"
1070 	};
1071 	char charmap[13];
1072 
1073 	strcpy(charmap, qc[!!(regex_flags & REG_EXTENDED)]);
1074 
1075 	if ((__bi_argcnt > 2)) {
1076 		char *p = charmap + strlen(charmap);
1077 		*p++ = *delim++;
1078 		if (*delim)
1079 			*p++ = *delim;
1080 		*p = 0;
1081 	}
1082 
1083 	if (text[strcspn(text, charmap)] == 0)
1084 
1085 #line 266
1086 do {
1087 #line 266
1088   pushs(env, text);
1089 #line 266
1090   goto endlab;
1091 #line 266
1092 } while (0);
1093 	heap_obstack_begin(env);
1094 	for (;;) {
1095 		size_t len = strcspn(text, charmap);
1096 		if (len)
1097 			heap_obstack_grow(env, text, len);
1098 		if (text[len]) {
1099 			do { char __c = '\\'; heap_obstack_grow(env, &__c, 1); } while(0);
1100 			do { char __c = text[len]; heap_obstack_grow(env, &__c, 1); } while(0);
1101 			text += len + 1;
1102 		} else
1103 			break;
1104 	}
1105 	do { char __c = 0; heap_obstack_grow(env, &__c, 1); } while(0);
1106 
1107 #line 280
1108 do {
1109 #line 280
1110   push(env, (STKVAL) (heap_obstack_finish(env)));
1111 #line 280
1112   goto endlab;
1113 #line 280
1114 } while (0);
1115 }
1116 endlab:
1117 #line 282
1118         env_function_cleanup_flush(env, NULL);
1119 #line 282
1120 	return;
1121 #line 282
1122 }
1123 
1124 void
1125 #line 284
bi_unescape(eval_environ_t env)1126 bi_unescape(eval_environ_t env)
1127 #line 284
1128 
1129 #line 284
1130 
1131 #line 284 "string.bi"
1132 {
1133 #line 284
1134 
1135 #line 284
1136 
1137 #line 284
1138 
1139 #line 284
1140 char * MFL_DATASEG text;
1141 #line 284
1142 
1143 #line 284
1144 get_string_arg(env, 0, &text);
1145 #line 284
1146 
1147 #line 284
1148 
1149 #line 284
1150         adjust_stack(env, 1);
1151 #line 284
1152 
1153 #line 284
1154 
1155 #line 284
1156 	if (builtin_module_trace(BUILTIN_IDX_string))
1157 #line 284
1158 		prog_trace(env, "unescape %s",text);;
1159 #line 284
1160 
1161 {
1162 	heap_obstack_begin(env);
1163 	for (;;) {
1164 		size_t len = strcspn(text, "\\");
1165 		if (len)
1166 			heap_obstack_grow(env, text, len);
1167 		if (text[len]) {
1168 			char c = text[len + 1];
1169 			if (!c)
1170 				break;
1171 			do { char __c = text[len+1]; heap_obstack_grow(env, &__c, 1); } while(0);
1172 			text += len + 2;
1173 		} else
1174 			break;
1175 	}
1176 	do { char __c = 0; heap_obstack_grow(env, &__c, 1); } while(0);
1177 
1178 #line 301
1179 do {
1180 #line 301
1181   push(env, (STKVAL) (heap_obstack_finish(env)));
1182 #line 301
1183   goto endlab;
1184 #line 301
1185 } while (0);
1186 }
1187 endlab:
1188 #line 303
1189         env_function_cleanup_flush(env, NULL);
1190 #line 303
1191 	return;
1192 #line 303
1193 }
1194 
1195 void
1196 #line 305
bi_ltrim(eval_environ_t env)1197 bi_ltrim(eval_environ_t env)
1198 #line 305
1199 
1200 #line 305
1201 
1202 #line 305 "string.bi"
1203 {
1204 #line 305
1205 
1206 #line 305
1207 
1208 #line 305
1209 long __bi_argcnt;
1210 #line 305
1211 char * MFL_DATASEG input;
1212 #line 305
1213         char * MFL_DATASEG cset;
1214 #line 305
1215 
1216 #line 305
1217 get_string_arg(env, 1, &input);
1218 #line 305
1219         get_string_arg(env, 2, &cset);
1220 #line 305
1221 
1222 #line 305
1223 get_numeric_arg(env, 0, &__bi_argcnt);
1224 #line 305
1225         adjust_stack(env, __bi_argcnt + 1);
1226 #line 305
1227 
1228 #line 305
1229 
1230 #line 305
1231 	if (builtin_module_trace(BUILTIN_IDX_string))
1232 #line 305
1233 		prog_trace(env, "ltrim %s %s",input, ((__bi_argcnt > 1) ? cset : ""));;
1234 #line 305
1235 
1236 {
1237 	char *p = ((__bi_argcnt > 1) ? cset : " \t\r\n\f");
1238 	for (; *input && strchr(p, *input); input++);
1239 
1240 #line 309
1241 do {
1242 #line 309
1243   pushs(env, input);
1244 #line 309
1245   goto endlab;
1246 #line 309
1247 } while (0);
1248 }
1249 endlab:
1250 #line 311
1251         env_function_cleanup_flush(env, NULL);
1252 #line 311
1253 	return;
1254 #line 311
1255 }
1256 
1257 void
1258 #line 313
bi_rtrim(eval_environ_t env)1259 bi_rtrim(eval_environ_t env)
1260 #line 313
1261 
1262 #line 313
1263 
1264 #line 313 "string.bi"
1265 {
1266 #line 313
1267 
1268 #line 313
1269 
1270 #line 313
1271 long __bi_argcnt;
1272 #line 313
1273 char * MFL_DATASEG input;
1274 #line 313
1275         char * MFL_DATASEG cset;
1276 #line 313
1277 
1278 #line 313
1279 get_string_arg(env, 1, &input);
1280 #line 313
1281         get_string_arg(env, 2, &cset);
1282 #line 313
1283 
1284 #line 313
1285 get_numeric_arg(env, 0, &__bi_argcnt);
1286 #line 313
1287         adjust_stack(env, __bi_argcnt + 1);
1288 #line 313
1289 
1290 #line 313
1291 
1292 #line 313
1293 	if (builtin_module_trace(BUILTIN_IDX_string))
1294 #line 313
1295 		prog_trace(env, "rtrim %s %s",input, ((__bi_argcnt > 1) ? cset : ""));;
1296 #line 313
1297 
1298 {
1299 	char *p = ((__bi_argcnt > 1) ? cset : " \t\r\n\f");
1300 	size_t len = strlen(input);
1301 	size_t off;
1302 
1303 	for (; len > 0 && strchr(p, input[len-1]); len--);
1304 	p = (char*) env_data_ref(env, (off = heap_reserve(env, len+1)));
1305 	memcpy(p, input, len);
1306 	p[len] = 0;
1307 
1308 #line 323
1309 do {
1310 #line 323
1311   push(env, (STKVAL) (mft_size) (off));
1312 #line 323
1313   goto endlab;
1314 #line 323
1315 } while (0);
1316 }
1317 endlab:
1318 #line 325
1319         env_function_cleanup_flush(env, NULL);
1320 #line 325
1321 	return;
1322 #line 325
1323 }
1324 
1325 #line 982 "../../src/builtin/snarf.m4"
1326 
1327 #line 982
1328 
1329 #line 982
1330 
1331 #line 982
1332 void
1333 #line 982
string_init_builtin(void)1334 string_init_builtin(void)
1335 #line 982
1336 {
1337 #line 982
1338 
1339 #line 982
1340 	#line 19 "string.bi"
1341 va_builtin_install_ex("toupper", bi_toupper, 0, dtype_string, 1, 0, 0|0, dtype_string);
1342 #line 30 "string.bi"
1343 va_builtin_install_ex("tolower", bi_tolower, 0, dtype_string, 1, 0, 0|0, dtype_string);
1344 #line 41 "string.bi"
1345 va_builtin_install_ex("length", bi_length, 0, dtype_number, 1, 0, 0|0, dtype_string);
1346 #line 47 "string.bi"
1347 va_builtin_install_ex("substring", bi_substring, 0, dtype_string, 3, 0, 0|0, dtype_string, dtype_number, dtype_number);
1348 #line 73 "string.bi"
1349 va_builtin_install_ex("substr", bi_substr, 0, dtype_string, 3, 1, 0|0, dtype_string, dtype_number, dtype_number);
1350 #line 94 "string.bi"
1351 va_builtin_install_ex("index", bi_index, 0, dtype_number, 3, 1, 0|0, dtype_string, dtype_string, dtype_number);
1352 #line 109 "string.bi"
1353 va_builtin_install_ex("rindex", bi_rindex, 0, dtype_number, 3, 1, 0|0, dtype_string, dtype_string, dtype_number);
1354 #line 148 "string.bi"
1355 va_builtin_install_ex("revstr", bi_revstr, 0, dtype_string, 1, 0, 0|0, dtype_string);
1356 #line 162 "string.bi"
1357 va_builtin_install_ex("replstr", bi_replstr, 0, dtype_string, 2, 0, 0|0, dtype_string, dtype_number);
1358 #line 183 "string.bi"
1359 va_builtin_install_ex("message_header_decode", bi_message_header_decode, 0, dtype_string, 2, 1, 0|0, dtype_string, dtype_string);
1360 #line 196 "string.bi"
1361 va_builtin_install_ex("message_header_encode", bi_message_header_encode, 0, dtype_string, 3, 2, 0|0, dtype_string, dtype_string, dtype_string);
1362 #line 212 "string.bi"
1363 va_builtin_install_ex("unfold", bi_unfold, 0, dtype_string, 1, 0, 0|0, dtype_string);
1364 #line 221 "string.bi"
1365 va_builtin_install_ex("escape", bi_escape, 0, dtype_string, 2, 1, 0|0, dtype_string, dtype_string);
1366 #line 245 "string.bi"
1367 va_builtin_install_ex("qr", bi_qr, 0, dtype_string, 3, 1, MFD_BUILTIN_REGEX_FLAGS|MFD_BUILTIN_REGEX_FLAGS|0, dtype_number, dtype_string, dtype_string);
1368 #line 284 "string.bi"
1369 va_builtin_install_ex("unescape", bi_unescape, 0, dtype_string, 1, 0, 0|0, dtype_string);
1370 #line 305 "string.bi"
1371 va_builtin_install_ex("ltrim", bi_ltrim, 0, dtype_string, 2, 1, 0|0, dtype_string, dtype_string);
1372 #line 313 "string.bi"
1373 va_builtin_install_ex("rtrim", bi_rtrim, 0, dtype_string, 2, 1, 0|0, dtype_string, dtype_string);
1374 
1375 #line 982 "../../src/builtin/snarf.m4"
1376 
1377 #line 982
1378 }
1379 #line 982 "../../src/builtin/snarf.m4"
1380 
1381