Commit 2476e22e 2476e22e5535bed056ef8ef317eef317a43894d2 by Sergey Poznyakoff

Builtin functions return their values in arg_num,arg_str.

Compress whitespace only in component escapes.
1 parent 6f630cf0
...@@ -70,10 +70,19 @@ strobj_free (strobj_t *obj) ...@@ -70,10 +70,19 @@ strobj_free (strobj_t *obj)
70 static void 70 static void
71 strobj_create (strobj_t *lvalue, char *str) 71 strobj_create (strobj_t *lvalue, char *str)
72 { 72 {
73 int len = strlen (str); 73 int len;
74 lvalue->size = len+1; 74
75 lvalue->ptr = xmalloc (lvalue->size); 75 if (!str)
76 memcpy (lvalue->ptr, str, lvalue->size); 76 {
77 lvalue->size = 0;
78 lvalue->ptr = NULL;
79 }
80 else
81 {
82 lvalue->size = strlen (str) + 1;
83 lvalue->ptr = xmalloc (lvalue->size);
84 memcpy (lvalue->ptr, str, lvalue->size);
85 }
77 } 86 }
78 87
79 static void 88 static void
...@@ -127,6 +136,7 @@ compress_ws (char *str, size_t *size) ...@@ -127,6 +136,7 @@ compress_ws (char *str, size_t *size)
127 if (isprint (*q)) 136 if (isprint (*q))
128 *p++ = *q; 137 *p++ = *q;
129 } 138 }
139 *p = 0;
130 *size = p - (unsigned char*) str; 140 *size = p - (unsigned char*) str;
131 } 141 }
132 142
...@@ -142,7 +152,6 @@ print_string (struct mh_machine *mach, char *str, size_t len) ...@@ -142,7 +152,6 @@ print_string (struct mh_machine *mach, char *str, size_t len)
142 if (len > rest) 152 if (len > rest)
143 len = rest; 153 len = rest;
144 memcpy (mach->outbuf + mach->ind, str, len); 154 memcpy (mach->outbuf + mach->ind, str, len);
145 compress_ws (mach->outbuf + mach->ind, &len);
146 mach->ind += len; 155 mach->ind += len;
147 } 156 }
148 157
...@@ -207,14 +216,14 @@ mh_format (mh_format_t *fmt, message_t msg, size_t msgno, ...@@ -207,14 +216,14 @@ mh_format (mh_format_t *fmt, message_t msg, size_t msgno,
207 break; 216 break;
208 217
209 case mhop_num_branch: 218 case mhop_num_branch:
210 if (!mach.reg_num) 219 if (!mach.arg_num)
211 mach.pc += mach.prog[mach.pc]; 220 mach.pc += mach.prog[mach.pc];
212 else 221 else
213 mach.pc++; 222 mach.pc++;
214 break; 223 break;
215 224
216 case mhop_str_branch: 225 case mhop_str_branch:
217 if (!*strobj_ptr (&mach.reg_str)) 226 if (!*strobj_ptr (&mach.arg_str))
218 mach.pc += mach.prog[mach.pc]; 227 mach.pc += mach.prog[mach.pc];
219 else 228 else
220 mach.pc++; 229 mach.pc++;
...@@ -230,11 +239,13 @@ mh_format (mh_format_t *fmt, message_t msg, size_t msgno, ...@@ -230,11 +239,13 @@ mh_format (mh_format_t *fmt, message_t msg, size_t msgno,
230 char *value = NULL; 239 char *value = NULL;
231 message_get_header (mach.message, &hdr); 240 message_get_header (mach.message, &hdr);
232 header_aget_value (hdr, strobj_ptr (&mach.arg_str), &value); 241 header_aget_value (hdr, strobj_ptr (&mach.arg_str), &value);
233 strobj_free (&mach.reg_str); 242 strobj_free (&mach.arg_str);
234 if (value) 243 if (value)
235 { 244 {
236 mach.reg_str.size = strlen (value) + 1; 245 int len = strlen (value);
237 mach.reg_str.ptr = value; 246 mach.arg_str.size = len + 1;
247 compress_ws (value, &len);
248 mach.arg_str.ptr = value;
238 } 249 }
239 } 250 }
240 break; 251 break;
...@@ -246,7 +257,7 @@ mh_format (mh_format_t *fmt, message_t msg, size_t msgno, ...@@ -246,7 +257,7 @@ mh_format (mh_format_t *fmt, message_t msg, size_t msgno,
246 size_t size = 0, off, str_off, nread; 257 size_t size = 0, off, str_off, nread;
247 size_t rest = mach.width - mach.ind; 258 size_t rest = mach.width - mach.ind;
248 259
249 strobj_free (&mach.reg_str); 260 strobj_free (&mach.arg_str);
250 message_get_body (mach.message, &body); 261 message_get_body (mach.message, &body);
251 body_size (body, &size); 262 body_size (body, &size);
252 body_get_stream (body, &stream); 263 body_get_stream (body, &stream);
...@@ -255,22 +266,22 @@ mh_format (mh_format_t *fmt, message_t msg, size_t msgno, ...@@ -255,22 +266,22 @@ mh_format (mh_format_t *fmt, message_t msg, size_t msgno,
255 if (size > rest) 266 if (size > rest)
256 size = rest; 267 size = rest;
257 268
258 mach.reg_str.ptr = xmalloc (size+1); 269 mach.arg_str.ptr = xmalloc (size+1);
259 mach.reg_str.size = size; 270 mach.arg_str.size = size;
260 271
261 off = 0; 272 off = 0;
262 str_off = 0; 273 str_off = 0;
263 while (!stream_read (stream, mach.reg_str.ptr + str_off, 274 while (!stream_read (stream, mach.arg_str.ptr + str_off,
264 mach.reg_str.size - str_off, off, &nread) 275 mach.arg_str.size - str_off, off, &nread)
265 && nread != 0 276 && nread != 0
266 && str_off < size) 277 && str_off < size)
267 { 278 {
268 off += nread; 279 off += nread;
269 compress_ws (mach.reg_str.ptr + str_off, &nread); 280 compress_ws (mach.arg_str.ptr + str_off, &nread);
270 if (nread) 281 if (nread)
271 str_off += nread; 282 str_off += nread;
272 } 283 }
273 mach.reg_str.ptr[str_off] = 0; 284 mach.arg_str.ptr[str_off] = 0;
274 } 285 }
275 break; 286 break;
276 287
...@@ -398,7 +409,7 @@ builtin_msg (struct mh_machine *mach) ...@@ -398,7 +409,7 @@ builtin_msg (struct mh_machine *mach)
398 { 409 {
399 size_t msgno = mach->msgno; 410 size_t msgno = mach->msgno;
400 mh_message_number (mach->message, &msgno); 411 mh_message_number (mach->message, &msgno);
401 mach->reg_num = msgno; 412 mach->arg_num = msgno;
402 } 413 }
403 414
404 static void 415 static void
...@@ -406,31 +417,31 @@ builtin_cur (struct mh_machine *mach) ...@@ -406,31 +417,31 @@ builtin_cur (struct mh_machine *mach)
406 { 417 {
407 size_t msgno = mach->msgno; 418 size_t msgno = mach->msgno;
408 mh_message_number (mach->message, &msgno); 419 mh_message_number (mach->message, &msgno);
409 mach->reg_num = msgno == current_message; 420 mach->arg_num = msgno == current_message;
410 } 421 }
411 422
412 static void 423 static void
413 builtin_size (struct mh_machine *mach) 424 builtin_size (struct mh_machine *mach)
414 { 425 {
415 message_size (mach->message, &mach->reg_num); 426 message_size (mach->message, &mach->arg_num);
416 } 427 }
417 428
418 static void 429 static void
419 builtin_strlen (struct mh_machine *mach) 430 builtin_strlen (struct mh_machine *mach)
420 { 431 {
421 mach->reg_num = strlen (strobj_ptr (&mach->reg_str)); 432 mach->arg_num = strlen (strobj_ptr (&mach->arg_str));
422 } 433 }
423 434
424 static void 435 static void
425 builtin_width (struct mh_machine *mach) 436 builtin_width (struct mh_machine *mach)
426 { 437 {
427 mach->reg_num = mach->width; 438 mach->arg_num = mach->width;
428 } 439 }
429 440
430 static void 441 static void
431 builtin_charleft (struct mh_machine *mach) 442 builtin_charleft (struct mh_machine *mach)
432 { 443 {
433 mach->reg_num = mach->width - mach->ind; 444 mach->arg_num = mach->width - mach->ind;
434 } 445 }
435 446
436 static void 447 static void
...@@ -439,38 +450,38 @@ builtin_timenow (struct mh_machine *mach) ...@@ -439,38 +450,38 @@ builtin_timenow (struct mh_machine *mach)
439 time_t t; 450 time_t t;
440 451
441 time (&t); 452 time (&t);
442 mach->reg_num = t; 453 mach->arg_num = t;
443 } 454 }
444 455
445 static void 456 static void
446 builtin_me (struct mh_machine *mach) 457 builtin_me (struct mh_machine *mach)
447 { 458 {
448 /*FIXME*/ 459 /*FIXME*/
449 /* mach->reg_str = "me";*/ 460 /* mach->arg_str = "me";*/
450 } 461 }
451 462
452 static void 463 static void
453 builtin_eq (struct mh_machine *mach) 464 builtin_eq (struct mh_machine *mach)
454 { 465 {
455 mach->reg_num = mach->reg_num == mach->arg_num; 466 mach->arg_num = mach->reg_num == mach->arg_num;
456 } 467 }
457 468
458 static void 469 static void
459 builtin_ne (struct mh_machine *mach) 470 builtin_ne (struct mh_machine *mach)
460 { 471 {
461 mach->reg_num = mach->reg_num != mach->arg_num; 472 mach->arg_num = mach->reg_num != mach->arg_num;
462 } 473 }
463 474
464 static void 475 static void
465 builtin_gt (struct mh_machine *mach) 476 builtin_gt (struct mh_machine *mach)
466 { 477 {
467 mach->reg_num = mach->reg_num > mach->arg_num; 478 mach->arg_num = mach->reg_num > mach->arg_num;
468 } 479 }
469 480
470 static void 481 static void
471 builtin_match (struct mh_machine *mach) 482 builtin_match (struct mh_machine *mach)
472 { 483 {
473 mach->reg_num = strstr (strobj_ptr (&mach->reg_str), 484 mach->arg_num = strstr (strobj_ptr (&mach->reg_str),
474 strobj_ptr (&mach->arg_str)); 485 strobj_ptr (&mach->arg_str));
475 } 486 }
476 487
...@@ -478,20 +489,20 @@ static void ...@@ -478,20 +489,20 @@ static void
478 builtin_amatch (struct mh_machine *mach) 489 builtin_amatch (struct mh_machine *mach)
479 { 490 {
480 int len = strobj_len (&mach->arg_str); 491 int len = strobj_len (&mach->arg_str);
481 mach->reg_num = strncmp (strobj_ptr (&mach->reg_str), 492 mach->arg_num = strncmp (strobj_ptr (&mach->reg_str),
482 strobj_ptr (&mach->arg_str), len); 493 strobj_ptr (&mach->arg_str), len);
483 } 494 }
484 495
485 static void 496 static void
486 builtin_plus (struct mh_machine *mach) 497 builtin_plus (struct mh_machine *mach)
487 { 498 {
488 mach->reg_num += mach->arg_num; 499 mach->arg_num += mach->reg_num;
489 } 500 }
490 501
491 static void 502 static void
492 builtin_minus (struct mh_machine *mach) 503 builtin_minus (struct mh_machine *mach)
493 { 504 {
494 mach->reg_num -= mach->arg_num; 505 mach->arg_num -= mach->reg_num;
495 } 506 }
496 507
497 static void 508 static void
...@@ -503,7 +514,7 @@ builtin_divide (struct mh_machine *mach) ...@@ -503,7 +514,7 @@ builtin_divide (struct mh_machine *mach)
503 mach->stop = 1; 514 mach->stop = 1;
504 } 515 }
505 else 516 else
506 mach->reg_num /= mach->arg_num; 517 mach->arg_num = mach->reg_num / mach->arg_num;
507 } 518 }
508 519
509 static void 520 static void
...@@ -515,7 +526,7 @@ builtin_modulo (struct mh_machine *mach) ...@@ -515,7 +526,7 @@ builtin_modulo (struct mh_machine *mach)
515 mach->stop = 1; 526 mach->stop = 1;
516 } 527 }
517 else 528 else
518 mach->reg_num %= mach->arg_num; 529 mach->arg_num = mach->reg_num % mach->arg_num;
519 } 530 }
520 531
521 static void 532 static void
...@@ -533,41 +544,42 @@ builtin_lit (struct mh_machine *mach) ...@@ -533,41 +544,42 @@ builtin_lit (struct mh_machine *mach)
533 static void 544 static void
534 builtin_getenv (struct mh_machine *mach) 545 builtin_getenv (struct mh_machine *mach)
535 { 546 {
536 strobj_free (&mach->reg_str); 547 char *val = getenv (strobj_ptr (&mach->arg_str));
537 strobj_create (&mach->reg_str, getenv (strobj_ptr (&mach->arg_str))); 548 strobj_free (&mach->arg_str);
549 strobj_create (&mach->arg_str, val);
538 } 550 }
539 551
540 static void 552 static void
541 builtin_profile (struct mh_machine *mach) 553 builtin_profile (struct mh_machine *mach)
542 { 554 {
543 /*FIXME*/ 555 /*FIXME*/
544 /*mach->reg_str = "profile";*/ 556 /*mach->arg_str = "profile";*/
545 } 557 }
546 558
547 static void 559 static void
548 builtin_nonzero (struct mh_machine *mach) 560 builtin_nonzero (struct mh_machine *mach)
549 { 561 {
550 /*nothing*/ 562 mach->arg_num = mach->reg_num;
551 } 563 }
552 564
553 static void 565 static void
554 builtin_zero (struct mh_machine *mach) 566 builtin_zero (struct mh_machine *mach)
555 { 567 {
556 mach->reg_num = !mach->reg_num; 568 mach->arg_num = !mach->reg_num;
557 } 569 }
558 570
559 static void 571 static void
560 builtin_null (struct mh_machine *mach) 572 builtin_null (struct mh_machine *mach)
561 { 573 {
562 char *s = strobj_ptr (&mach->reg_str); 574 char *s = strobj_ptr (&mach->reg_str);
563 mach->reg_num = !s && !s[0]; 575 mach->arg_num = !s && !s[0];
564 } 576 }
565 577
566 static void 578 static void
567 builtin_nonnull (struct mh_machine *mach) 579 builtin_nonnull (struct mh_machine *mach)
568 { 580 {
569 char *s = strobj_ptr (&mach->reg_str); 581 char *s = strobj_ptr (&mach->reg_str);
570 mach->reg_num = s && s[0]; 582 mach->arg_num = s && s[0];
571 } 583 }
572 584
573 /* comp comp string Set str to component text*/ 585 /* comp comp string Set str to component text*/
...@@ -601,7 +613,6 @@ builtin_trim (struct mh_machine *mach) ...@@ -601,7 +613,6 @@ builtin_trim (struct mh_machine *mach)
601 for (p = start + len - 1; p >= start && isspace (*p); p--) 613 for (p = start + len - 1; p >= start && isspace (*p); p--)
602 ; 614 ;
603 p[1] = 0; 615 p[1] = 0;
604 strobj_copy (&mach->reg_str, &mach->arg_str);
605 } 616 }
606 617
607 /* putstr expr print str*/ 618 /* putstr expr print str*/
...@@ -656,7 +667,7 @@ builtin_sec (struct mh_machine *mach) ...@@ -656,7 +667,7 @@ builtin_sec (struct mh_machine *mach)
656 if (_parse_date (mach, &tm, &tz)) 667 if (_parse_date (mach, &tm, &tz))
657 return; 668 return;
658 669
659 mach->reg_num = tm.tm_sec; 670 mach->arg_num = tm.tm_sec;
660 } 671 }
661 672
662 /* min date integer minutes of the hour*/ 673 /* min date integer minutes of the hour*/
...@@ -669,7 +680,7 @@ builtin_min (struct mh_machine *mach) ...@@ -669,7 +680,7 @@ builtin_min (struct mh_machine *mach)
669 if (_parse_date (mach, &tm, &tz)) 680 if (_parse_date (mach, &tm, &tz))
670 return; 681 return;
671 682
672 mach->reg_num = tm.tm_min; 683 mach->arg_num = tm.tm_min;
673 } 684 }
674 685
675 /* hour date integer hours of the day (0-23)*/ 686 /* hour date integer hours of the day (0-23)*/
...@@ -682,7 +693,7 @@ builtin_hour (struct mh_machine *mach) ...@@ -682,7 +693,7 @@ builtin_hour (struct mh_machine *mach)
682 if (_parse_date (mach, &tm, &tz)) 693 if (_parse_date (mach, &tm, &tz))
683 return; 694 return;
684 695
685 mach->reg_num = tm.tm_hour; 696 mach->arg_num = tm.tm_hour;
686 } 697 }
687 698
688 /* wday date integer day of the week (Sun=0)*/ 699 /* wday date integer day of the week (Sun=0)*/
...@@ -695,7 +706,7 @@ builtin_wday (struct mh_machine *mach) ...@@ -695,7 +706,7 @@ builtin_wday (struct mh_machine *mach)
695 if (_parse_date (mach, &tm, &tz)) 706 if (_parse_date (mach, &tm, &tz))
696 return; 707 return;
697 708
698 mach->reg_num = tm.tm_wday; 709 mach->arg_num = tm.tm_wday;
699 } 710 }
700 711
701 /* day date string day of the week (abbrev.)*/ 712 /* day date string day of the week (abbrev.)*/
...@@ -740,9 +751,9 @@ builtin_sday (struct mh_machine *mach) ...@@ -740,9 +751,9 @@ builtin_sday (struct mh_machine *mach)
740 751
741 /*FIXME: more elaborate check needed */ 752 /*FIXME: more elaborate check needed */
742 if (_parse_date (mach, &tm, &tz)) 753 if (_parse_date (mach, &tm, &tz))
743 mach->reg_num = -1; 754 mach->arg_num = -1;
744 else 755 else
745 mach->reg_num = 1; 756 mach->arg_num = 1;
746 } 757 }
747 758
748 /* mday date integer day of the month*/ 759 /* mday date integer day of the month*/
...@@ -755,7 +766,7 @@ builtin_mday (struct mh_machine *mach) ...@@ -755,7 +766,7 @@ builtin_mday (struct mh_machine *mach)
755 if (_parse_date (mach, &tm, &tz)) 766 if (_parse_date (mach, &tm, &tz))
756 return; 767 return;
757 768
758 mach->reg_num = tm.tm_mday; 769 mach->arg_num = tm.tm_mday;
759 } 770 }
760 771
761 /* yday date integer day of the year */ 772 /* yday date integer day of the year */
...@@ -768,7 +779,7 @@ builtin_yday (struct mh_machine *mach) ...@@ -768,7 +779,7 @@ builtin_yday (struct mh_machine *mach)
768 if (_parse_date (mach, &tm, &tz)) 779 if (_parse_date (mach, &tm, &tz))
769 return; 780 return;
770 781
771 mach->reg_num = tm.tm_yday; 782 mach->arg_num = tm.tm_yday;
772 } 783 }
773 784
774 /* mon date integer month of the year*/ 785 /* mon date integer month of the year*/
...@@ -781,7 +792,7 @@ builtin_mon (struct mh_machine *mach) ...@@ -781,7 +792,7 @@ builtin_mon (struct mh_machine *mach)
781 if (_parse_date (mach, &tm, &tz)) 792 if (_parse_date (mach, &tm, &tz))
782 return; 793 return;
783 794
784 mach->reg_num = tm.tm_mon+1; 795 mach->arg_num = tm.tm_mon+1;
785 } 796 }
786 797
787 /* month date string month of the year (abbrev.) */ 798 /* month date string month of the year (abbrev.) */
...@@ -826,7 +837,7 @@ builtin_year (struct mh_machine *mach) ...@@ -826,7 +837,7 @@ builtin_year (struct mh_machine *mach)
826 if (_parse_date (mach, &tm, &tz)) 837 if (_parse_date (mach, &tm, &tz))
827 return; 838 return;
828 839
829 mach->reg_num = tm.tm_year + 1900; 840 mach->arg_num = tm.tm_year + 1900;
830 } 841 }
831 842
832 /* zone date integer timezone in hours*/ 843 /* zone date integer timezone in hours*/
...@@ -839,7 +850,7 @@ builtin_zone (struct mh_machine *mach) ...@@ -839,7 +850,7 @@ builtin_zone (struct mh_machine *mach)
839 if (_parse_date (mach, &tm, &tz)) 850 if (_parse_date (mach, &tm, &tz))
840 return; 851 return;
841 852
842 mach->reg_num = tz.utc_offset; 853 mach->arg_num = tz.utc_offset;
843 } 854 }
844 855
845 /* tzone date string timezone string */ 856 /* tzone date string timezone string */
...@@ -851,8 +862,25 @@ builtin_tzone (struct mh_machine *mach) ...@@ -851,8 +862,25 @@ builtin_tzone (struct mh_machine *mach)
851 862
852 if (_parse_date (mach, &tm, &tz)) 863 if (_parse_date (mach, &tm, &tz))
853 return; 864 return;
865
854 strobj_free (&mach->arg_str); 866 strobj_free (&mach->arg_str);
855 strobj_create (&mach->arg_str, (char*) tz.tz_name); 867 if (tz.tz_name)
868 strobj_create (&mach->arg_str, (char*) tz.tz_name);
869 else
870 {
871 char buf[6];
872 int s;
873 if (tz.utc_offset < 0)
874 {
875 s = '-';
876 tz.utc_offset = - tz.utc_offset;
877 }
878 else
879 s = '+';
880 snprintf (buf, sizeof buf, "%c%02d%02d", s,
881 tz.utc_offset/3600, tz.utc_offset/60);
882 strobj_create (&mach->arg_str, buf);
883 }
856 } 884 }
857 885
858 /* szone date integer timezone explicit? 886 /* szone date integer timezone explicit?
...@@ -865,9 +893,9 @@ builtin_szone (struct mh_machine *mach) ...@@ -865,9 +893,9 @@ builtin_szone (struct mh_machine *mach)
865 893
866 /*FIXME: more elaborate check needed */ 894 /*FIXME: more elaborate check needed */
867 if (_parse_date (mach, &tm, &tz)) 895 if (_parse_date (mach, &tm, &tz))
868 mach->reg_num = -1; 896 mach->arg_num = -1;
869 else 897 else
870 mach->reg_num = 1; 898 mach->arg_num = 1;
871 } 899 }
872 900
873 /* date2local date coerce date to local timezone*/ 901 /* date2local date coerce date to local timezone*/
...@@ -894,9 +922,9 @@ builtin_dst (struct mh_machine *mach) ...@@ -894,9 +922,9 @@ builtin_dst (struct mh_machine *mach)
894 if (_parse_date (mach, &tm, &tz)) 922 if (_parse_date (mach, &tm, &tz))
895 return; 923 return;
896 #ifdef HAVE_TM_ISDST 924 #ifdef HAVE_TM_ISDST
897 mach->reg_num = tm.tm_isdst; 925 mach->arg_num = tm.tm_isdst;
898 #else 926 #else
899 mach->reg_num = 0; 927 mach->arg_num = 0;
900 #endif 928 #endif
901 } 929 }
902 930
...@@ -909,7 +937,7 @@ builtin_clock (struct mh_machine *mach) ...@@ -909,7 +937,7 @@ builtin_clock (struct mh_machine *mach)
909 937
910 if (_parse_date (mach, &tm, &tz)) 938 if (_parse_date (mach, &tm, &tz))
911 return; 939 return;
912 mach->reg_num = mu_tm2time (&tm, &tz); 940 mach->arg_num = mu_tm2time (&tm, &tz);
913 } 941 }
914 942
915 /* rclock date integer seconds prior to current time*/ 943 /* rclock date integer seconds prior to current time*/
...@@ -922,7 +950,7 @@ builtin_rclock (struct mh_machine *mach) ...@@ -922,7 +950,7 @@ builtin_rclock (struct mh_machine *mach)
922 950
923 if (_parse_date (mach, &tm, &tz)) 951 if (_parse_date (mach, &tm, &tz))
924 return; 952 return;
925 mach->reg_num = now - mu_tm2time (&tm, &tz); 953 mach->arg_num = now - mu_tm2time (&tm, &tz);
926 } 954 }
927 955
928 /* tws date string official 822 rendering */ 956 /* tws date string official 822 rendering */
...@@ -930,7 +958,6 @@ static void ...@@ -930,7 +958,6 @@ static void
930 builtin_tws (struct mh_machine *mach) 958 builtin_tws (struct mh_machine *mach)
931 { 959 {
932 /*FIXME: noop*/ 960 /*FIXME: noop*/
933 strobj_copy (&mach->reg_str, &mach->arg_str);
934 } 961 }
935 962
936 /* pretty date string user-friendly rendering*/ 963 /* pretty date string user-friendly rendering*/
...@@ -938,7 +965,6 @@ static void ...@@ -938,7 +965,6 @@ static void
938 builtin_pretty (struct mh_machine *mach) 965 builtin_pretty (struct mh_machine *mach)
939 { 966 {
940 /*FIXME: noop*/ 967 /*FIXME: noop*/
941 strobj_copy (&mach->reg_str, &mach->arg_str);
942 } 968 }
943 969
944 /* nodate date integer str not a date string */ 970 /* nodate date integer str not a date string */
...@@ -948,7 +974,7 @@ builtin_nodate (struct mh_machine *mach) ...@@ -948,7 +974,7 @@ builtin_nodate (struct mh_machine *mach)
948 struct tm tm; 974 struct tm tm;
949 mu_timezone tz; 975 mu_timezone tz;
950 976
951 mach->reg_num = _parse_date (mach, &tm, &tz); 977 mach->arg_num = _parse_date (mach, &tm, &tz);
952 } 978 }
953 979
954 /* proper addr string official 822 rendering */ 980 /* proper addr string official 822 rendering */
...@@ -956,7 +982,6 @@ static void ...@@ -956,7 +982,6 @@ static void
956 builtin_proper (struct mh_machine *mach) 982 builtin_proper (struct mh_machine *mach)
957 { 983 {
958 /*FIXME: noop*/ 984 /*FIXME: noop*/
959 strobj_copy (&mach->reg_str, &mach->arg_str);
960 } 985 }
961 986
962 /* friendly addr string user-friendly rendering*/ 987 /* friendly addr string user-friendly rendering*/
...@@ -964,7 +989,6 @@ static void ...@@ -964,7 +989,6 @@ static void
964 builtin_friendly (struct mh_machine *mach) 989 builtin_friendly (struct mh_machine *mach)
965 { 990 {
966 /*FIXME: noop*/ 991 /*FIXME: noop*/
967 strobj_copy (&mach->reg_str, &mach->arg_str);
968 } 992 }
969 993
970 /* addr addr string mbox@host or host!mbox rendering*/ 994 /* addr addr string mbox@host or host!mbox rendering*/
...@@ -974,13 +998,15 @@ builtin_addr (struct mh_machine *mach) ...@@ -974,13 +998,15 @@ builtin_addr (struct mh_machine *mach)
974 address_t addr; 998 address_t addr;
975 size_t n; 999 size_t n;
976 char buf[80]; 1000 char buf[80];
1001 int rc;
977 1002
978 strobj_free (&mach->reg_str); 1003 rc = address_create (&addr, strobj_ptr (&mach->arg_str));
979 if (address_create (&addr, strobj_ptr (&mach->arg_str))) 1004 strobj_free (&mach->arg_str);
1005 if (rc)
980 return; 1006 return;
981 1007
982 if (address_get_email (addr, 1, buf, sizeof buf, &n) == 0) 1008 if (address_get_email (addr, 1, buf, sizeof buf, &n) == 0)
983 strobj_create (&mach->reg_str, buf); 1009 strobj_create (&mach->arg_str, buf);
984 address_destroy (&addr); 1010 address_destroy (&addr);
985 } 1011 }
986 1012
...@@ -991,13 +1017,15 @@ builtin_pers (struct mh_machine *mach) ...@@ -991,13 +1017,15 @@ builtin_pers (struct mh_machine *mach)
991 address_t addr; 1017 address_t addr;
992 size_t n; 1018 size_t n;
993 char buf[80]; 1019 char buf[80];
1020 int rc;
994 1021
995 strobj_free (&mach->reg_str); 1022 rc = address_create (&addr, strobj_ptr (&mach->arg_str));
996 if (address_create (&addr, strobj_ptr (&mach->arg_str))) 1023 strobj_free (&mach->arg_str);
1024 if (rc)
997 return; 1025 return;
998 1026
999 if (address_get_personal (addr, 1, buf, sizeof buf, &n) == 0) 1027 if (address_get_personal (addr, 1, buf, sizeof buf, &n) == 0)
1000 strobj_create (&mach->reg_str, buf); 1028 strobj_create (&mach->arg_str, buf);
1001 address_destroy (&addr); 1029 address_destroy (&addr);
1002 } 1030 }
1003 1031
...@@ -1008,13 +1036,15 @@ builtin_note (struct mh_machine *mach) ...@@ -1008,13 +1036,15 @@ builtin_note (struct mh_machine *mach)
1008 address_t addr; 1036 address_t addr;
1009 size_t n; 1037 size_t n;
1010 char buf[80]; 1038 char buf[80];
1039 int rc;
1011 1040
1012 strobj_free (&mach->reg_str); 1041 rc = address_create (&addr, strobj_ptr (&mach->arg_str));
1013 if (address_create (&addr, strobj_ptr (&mach->arg_str))) 1042 strobj_free (&mach->arg_str);
1043 if (rc)
1014 return; 1044 return;
1015 1045
1016 if (address_get_comments (addr, 1, buf, sizeof buf, &n) == 0) 1046 if (address_get_comments (addr, 1, buf, sizeof buf, &n) == 0)
1017 strobj_create (&mach->reg_str, buf); 1047 strobj_create (&mach->arg_str, buf);
1018 address_destroy (&addr); 1048 address_destroy (&addr);
1019 } 1049 }
1020 1050
...@@ -1025,9 +1055,11 @@ builtin_mbox (struct mh_machine *mach) ...@@ -1025,9 +1055,11 @@ builtin_mbox (struct mh_machine *mach)
1025 address_t addr; 1055 address_t addr;
1026 size_t n; 1056 size_t n;
1027 char buf[80]; 1057 char buf[80];
1058 int rc;
1028 1059
1029 strobj_free (&mach->reg_str); 1060 rc = address_create (&addr, strobj_ptr (&mach->arg_str));
1030 if (address_create (&addr, strobj_ptr (&mach->arg_str))) 1061 strobj_free (&mach->arg_str);
1062 if (rc)
1031 return; 1063 return;
1032 1064
1033 if (address_get_email (addr, 1, buf, sizeof buf, &n) == 0) 1065 if (address_get_email (addr, 1, buf, sizeof buf, &n) == 0)
...@@ -1035,7 +1067,7 @@ builtin_mbox (struct mh_machine *mach) ...@@ -1035,7 +1067,7 @@ builtin_mbox (struct mh_machine *mach)
1035 char *p = strchr (buf, '@'); 1067 char *p = strchr (buf, '@');
1036 if (p) 1068 if (p)
1037 *p = NULL; 1069 *p = NULL;
1038 strobj_create (&mach->reg_str, p); 1070 strobj_create (&mach->arg_str, p);
1039 } 1071 }
1040 address_destroy (&addr); 1072 address_destroy (&addr);
1041 } 1073 }
...@@ -1048,12 +1080,12 @@ builtin_mymbox (struct mh_machine *mach) ...@@ -1048,12 +1080,12 @@ builtin_mymbox (struct mh_machine *mach)
1048 size_t n; 1080 size_t n;
1049 char buf[80]; 1081 char buf[80];
1050 1082
1051 mach->reg_num = 0; 1083 mach->arg_num = 0;
1052 if (address_create (&addr, strobj_ptr (&mach->arg_str))) 1084 if (address_create (&addr, strobj_ptr (&mach->arg_str)))
1053 return; 1085 return;
1054 1086
1055 if (address_get_email (addr, 1, buf, sizeof buf, &n) == 0) 1087 if (address_get_email (addr, 1, buf, sizeof buf, &n) == 0)
1056 mach->reg_num = mh_is_my_name (buf); 1088 mach->arg_num = mh_is_my_name (buf);
1057 address_destroy (&addr); 1089 address_destroy (&addr);
1058 } 1090 }
1059 1091
...@@ -1064,16 +1096,18 @@ builtin_host (struct mh_machine *mach) ...@@ -1064,16 +1096,18 @@ builtin_host (struct mh_machine *mach)
1064 address_t addr; 1096 address_t addr;
1065 size_t n; 1097 size_t n;
1066 char buf[80]; 1098 char buf[80];
1099 int rc;
1067 1100
1068 strobj_free (&mach->reg_str); 1101 rc = address_create (&addr, strobj_ptr (&mach->arg_str));
1069 if (address_create (&addr, strobj_ptr (&mach->arg_str))) 1102 strobj_free (&mach->arg_str);
1103 if (rc)
1070 return; 1104 return;
1071 1105
1072 if (address_get_email (addr, 1, buf, sizeof buf, &n) == 0) 1106 if (address_get_email (addr, 1, buf, sizeof buf, &n) == 0)
1073 { 1107 {
1074 char *p = strchr (buf, '@'); 1108 char *p = strchr (buf, '@');
1075 if (p) 1109 if (p)
1076 strobj_create (&mach->reg_str, p+1); 1110 strobj_create (&mach->arg_str, p+1);
1077 } 1111 }
1078 address_destroy (&addr); 1112 address_destroy (&addr);
1079 } 1113 }
...@@ -1085,15 +1119,17 @@ builtin_nohost (struct mh_machine *mach) ...@@ -1085,15 +1119,17 @@ builtin_nohost (struct mh_machine *mach)
1085 address_t addr; 1119 address_t addr;
1086 size_t n; 1120 size_t n;
1087 char buf[80]; 1121 char buf[80];
1122 int rc;
1088 1123
1089 strobj_free (&mach->reg_str); 1124 rc = address_create (&addr, strobj_ptr (&mach->arg_str));
1090 if (address_create (&addr, strobj_ptr (&mach->arg_str))) 1125 strobj_free (&mach->arg_str);
1126 if (rc)
1091 return; 1127 return;
1092 1128
1093 if (address_get_email (addr, 1, buf, sizeof buf, &n) == 0) 1129 if (address_get_email (addr, 1, buf, sizeof buf, &n) == 0)
1094 mach->reg_num = strchr (buf, '@') != NULL; 1130 mach->arg_num = strchr (buf, '@') != NULL;
1095 else 1131 else
1096 mach->reg_num = 0; 1132 mach->arg_num = 0;
1097 address_destroy (&addr); 1133 address_destroy (&addr);
1098 } 1134 }
1099 1135
...@@ -1105,22 +1141,24 @@ builtin_type (struct mh_machine *mach) ...@@ -1105,22 +1141,24 @@ builtin_type (struct mh_machine *mach)
1105 address_t addr; 1141 address_t addr;
1106 size_t n; 1142 size_t n;
1107 char buf[80]; 1143 char buf[80];
1108 1144 int rc;
1109 strobj_free (&mach->reg_str); 1145
1110 if (address_create (&addr, strobj_ptr (&mach->arg_str))) 1146 rc = address_create (&addr, strobj_ptr (&mach->arg_str));
1147 strobj_free (&mach->arg_str);
1148 if (rc)
1111 return; 1149 return;
1112 1150
1113 if (address_get_email (addr, 1, buf, sizeof buf, &n) == 0) 1151 if (address_get_email (addr, 1, buf, sizeof buf, &n) == 0)
1114 { 1152 {
1115 if (strchr (buf, '@')) 1153 if (strchr (buf, '@'))
1116 mach->reg_num = 1; 1154 mach->arg_num = 1;
1117 else if (strchr (buf, '@')) 1155 else if (strchr (buf, '@'))
1118 mach->reg_num = -1; 1156 mach->arg_num = -1;
1119 else 1157 else
1120 mach->reg_num = 0; /* assume local */ 1158 mach->arg_num = 0; /* assume local */
1121 } 1159 }
1122 else 1160 else
1123 mach->reg_num = 2; 1161 mach->arg_num = 2;
1124 address_destroy (&addr); 1162 address_destroy (&addr);
1125 } 1163 }
1126 1164
...@@ -1131,12 +1169,14 @@ builtin_path (struct mh_machine *mach) ...@@ -1131,12 +1169,14 @@ builtin_path (struct mh_machine *mach)
1131 address_t addr; 1169 address_t addr;
1132 size_t n; 1170 size_t n;
1133 char buf[80]; 1171 char buf[80];
1172 int rc;
1134 1173
1135 strobj_free (&mach->reg_str); 1174 rc = address_create (&addr, strobj_ptr (&mach->arg_str));
1136 if (address_create (&addr, strobj_ptr (&mach->arg_str))) 1175 strobj_free (&mach->arg_str);
1176 if (rc)
1137 return; 1177 return;
1138 if (address_get_route (addr, 1, buf, sizeof buf, &n)) 1178 if (address_get_route (addr, 1, buf, sizeof buf, &n))
1139 strobj_create (&mach->reg_str, buf); 1179 strobj_create (&mach->arg_str, buf);
1140 address_destroy (&addr); 1180 address_destroy (&addr);
1141 } 1181 }
1142 1182
......