Mercurial > hg > xemacs-beta
comparison lwlib/xlwmenu.c @ 410:de805c49cfc1 r21-2-35
Import from CVS: tag r21-2-35
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:19:21 +0200 |
parents | 2f8bb876ab1d |
children | 697ef44129c6 |
comparison
equal
deleted
inserted
replaced
409:301b9ebbdf3b | 410:de805c49cfc1 |
---|---|
514 { | 514 { |
515 { "labelString", "LabelString", XtRString, sizeof(String), | 515 { "labelString", "LabelString", XtRString, sizeof(String), |
516 0, XtRImmediate, 0 } | 516 0, XtRImmediate, 0 } |
517 }; | 517 }; |
518 | 518 |
519 /* | 519 /* This function searches STRING for parameter inserts of the form: |
520 * This function looks through string searching for parameter | 520 %[padding]1 |
521 * inserts of the form: | 521 padding is either space (' ') or dash ('-') meaning |
522 * %[padding]1 | 522 padding to the left or right of the inserted parameter. |
523 * padding is space (' ') or dash ('-') characters meaning | 523 In essence, all %1 strings are replaced by VALUE in the return value. |
524 * padding to the left or right of the inserted parameter. | 524 The caller is expected to free the return value using XtFree(). |
525 * In essence all %1 strings are replaced by value in the return | 525 %% means insert one % (like printf). |
526 * value (which the caller is expected to free). | 526 %1 means insert VALUE. |
527 * %% means insert one % (like printf). | 527 %-1 means insert VALUE followed by one space. The latter is |
528 * %1 means insert value. | 528 not inserted if VALUE is a zero length string. |
529 * %-1 means insert value followed by one space. The latter is | 529 */ |
530 * not inserted if value is a zero length string. | |
531 */ | |
532 static char* | 530 static char* |
533 parameterize_string (const char *string, const char *value) | 531 parameterize_string (const char *string, const char *value) |
534 { | 532 { |
535 char *percent; | 533 const char *percent; |
536 char *result; | 534 char *result; |
537 unsigned int done = 0; | 535 unsigned int done = 0; |
538 unsigned int ntimes; | 536 unsigned int ntimes; |
539 | 537 |
540 if (!string) | 538 if (!string) |
541 { | 539 { |
542 result = XtMalloc(1); | 540 result = XtMalloc(1); |
543 result[0] = '\0'; | 541 result[0] = '\0'; |
544 return (result); | 542 return result; |
545 } | 543 } |
546 | 544 |
547 if (!value) | 545 if (!value) |
548 value = ""; | 546 value = ""; |
549 | 547 |
550 for (ntimes = 1, result = (char *) string; (percent = strchr(result, '%')); | 548 for (ntimes = 1, percent = string; |
549 (percent = strchr (percent, '%')); | |
551 ntimes++) | 550 ntimes++) |
552 result = &percent[1]; | 551 percent++; |
553 | 552 |
554 result = XtMalloc ((ntimes * strlen(value)) + strlen(string) + 4); | 553 result = XtMalloc ((ntimes * strlen(value)) + strlen(string) + 4); |
555 result[0] = '\0'; | 554 result[0] = '\0'; |
556 | 555 |
557 while ((percent = strchr(string, '%'))) | 556 while ((percent = strchr (string, '%'))) |
558 { | 557 { |
559 unsigned int left_pad; | 558 unsigned int left_pad; |
560 unsigned int right_pad; | 559 unsigned int right_pad; |
561 char *p; | 560 const char *p; |
562 | 561 |
563 if (percent[1] == '%') | 562 if (percent[1] == '%') |
564 { /* it's a real % */ | 563 { /* it's a real % */ |
565 strncat (result, string, 1 + percent - string); /* incl % */ | 564 strncat (result, string, 1 + percent - string); /* incl % */ |
566 string = &percent[2]; /* after the second '%' */ | 565 string = &percent[2]; /* after the second '%' */ |