PennMUSH Community

Changeset 1262

Show
Ignore:
Timestamp:
09/12/08 18:57:32 (3 months ago)
Author:
shawnw
Message:

#7575: ljust() and rjust() take fill strings

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/devel/CHANGES.183

    r1260 r1262  
    6161   Allows for @chan/recall on an @chat that's been overridden. 
    6262 * Rewrote the internals of round() to avoid some nasty kludges. [SW] 
     63 * ljust() and rjust() take fill strings now, not just single 
     64   characters. Suggested by Nyssa, patch by Talvo. 
    6365 
    6466Fixes: 
  • 1.8.3/branches/devel/src/funstr.c

    r1097 r1262  
    959959 
    960960  size_t spaces, len; 
    961   char sep; 
     961  ansi_string *as; 
     962  int fillq, fillr, i; 
     963  char fillstr[BUFFER_LEN], *fp; 
    962964 
    963965  if (!is_uinteger(args[1])) { 
     
    976978  spaces -= len; 
    977979 
    978   if (!delim_check(buff, bp, nargs, args, 3, &sep)) 
    979     return; 
    980  
     980  if (!args[2] || !*args[2]) { 
     981    /* Fill with spaces */ 
     982    safe_strl(args[0], arglens[0], buff, bp); 
     983    safe_fill(' ', spaces, buff, bp); 
     984    return; 
     985  } 
     986  len = ansi_strlen(args[2]); 
     987  if (!len) { 
     988    safe_str(T("#-1 FILL ARGUMENT MAY NOT BE ZERO-LENGTH"), buff, bp); 
     989    return; 
     990  } 
    981991  safe_strl(args[0], arglens[0], buff, bp); 
    982   safe_fill(sep, spaces, buff, bp); 
     992  as = parse_ansi_string(args[2]); 
     993  fillq = spaces / len; 
     994  fillr = spaces % len; 
     995  fp = fillstr; 
     996  for (i = 0; i < fillq; i++) 
     997    safe_ansi_string(as, 0, as->len, fillstr, &fp); 
     998  safe_ansi_string(as, 0, fillr, fillstr, &fp); 
     999  *fp = '\0'; 
     1000  free_ansi_string(as); 
     1001  safe_str(fillstr, buff, bp); 
     1002 
    9831003} 
    9841004 
     
    9891009 
    9901010  size_t spaces, len; 
    991   char sep; 
     1011  ansi_string *as; 
     1012  int fillq, fillr, i; 
     1013  char fillstr[BUFFER_LEN], *fp; 
     1014 
    9921015 
    9931016  if (!is_uinteger(args[1])) { 
     
    10061029  spaces -= len; 
    10071030 
    1008   if (!delim_check(buff, bp, nargs, args, 3, &sep)) 
    1009     return; 
    1010  
    1011   safe_fill(sep, spaces, buff, bp); 
     1031  if (!args[2] || !*args[2]) { 
     1032    /* Fill with spaces */ 
     1033    safe_fill(' ', spaces, buff, bp); 
     1034    safe_strl(args[0], arglens[0], buff, bp); 
     1035    return; 
     1036  } 
     1037  len = ansi_strlen(args[2]); 
     1038  if (!len) { 
     1039    safe_str(T("#-1 FILL ARGUMENT MAY NOT BE ZERO-LENGTH"), buff, bp); 
     1040    return; 
     1041  } 
     1042  as = parse_ansi_string(args[2]); 
     1043  fillq = spaces / len; 
     1044  fillr = spaces % len; 
     1045  fp = fillstr; 
     1046  for (i = 0; i < fillq; i++) 
     1047    safe_ansi_string(as, 0, as->len, fillstr, &fp); 
     1048  safe_ansi_string(as, 0, fillr, fillstr, &fp); 
     1049  *fp = '\0'; 
     1050  free_ansi_string(as); 
     1051  safe_str(fillstr, buff, bp); 
    10121052  safe_strl(args[0], arglens[0], buff, bp); 
     1053 
    10131054} 
    10141055