PennMUSH Community
Show
Ignore:
Timestamp:
10/05/07 15:36:32 (1 year ago)
Author:
shawnw
Message:

Merge with devel

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/trunk/src/funstr.c

    r1032 r1117  
    1313#include <limits.h> 
    1414#include <locale.h> 
     15#include <stddef.h> 
    1516#include "conf.h" 
    1617#include "externs.h" 
     
    389390  src = parse_ansi_string(args[2]); 
    390391 
    391   ansi_string_insert(dst, pos, src, 0, src->len); 
     392  ansi_string_insert(dst, pos, src); 
    392393 
    393394  safe_ansi_string(dst, 0, dst->len, buff, bp); 
     
    459460  src = parse_ansi_string(args[3]); 
    460461 
    461   ansi_string_delete(dst, start, len); 
    462   ansi_string_insert(dst, start, src, 0, src->len); 
     462  ansi_string_replace(dst, start, len, src); 
     463 
    463464  safe_ansi_string(dst, 0, dst->len, buff, bp); 
    464465  free_ansi_string(dst); 
     
    936937FUNCTION(fun_scramble) 
    937938{ 
    938   int n, i, j; 
    939   ansi_string *as; 
    940   ansi_string *dst; 
    941   int pos[BUFFER_LEN]; 
    942   char tmp[BUFFER_LEN]; 
     939  ansi_string *as, *dst; 
    943940 
    944941  if (!*args[0]) 
    945942    return; 
    946943 
    947   /* Set up the new ansi_string */ 
    948   memset(tmp, 0, BUFFER_LEN); 
    949   dst = parse_ansi_string(tmp); 
    950  
    951   /* Read the current one */ 
    952944  as = parse_ansi_string(args[0]); 
    953  
    954   for (i = 0; i < as->len; i++) 
    955     pos[i] = i; 
    956  
    957   n = as->len; 
    958   for (i = 0; i < n; i++) { 
    959     int t; 
    960     j = get_random_long(0, n - 1); 
    961     t = pos[i]; 
    962     pos[i] = pos[j]; 
    963     pos[j] = t; 
    964   } 
    965  
    966   for (i = 0; i < n; i++) { 
    967     ansi_string_insert(dst, dst->len, as, pos[i], 1); 
    968     if ((i % 100) == 99) { 
    969       optimize_ansi_string(dst); 
    970     } 
    971   } 
     945  dst = scramble_ansi_string(as); 
     946  if (dst) { 
     947    free_ansi_string(as); 
     948    as = dst; 
     949  } 
     950 
     951  safe_ansi_string(as, 0, as->len, buff, bp); 
    972952  free_ansi_string(as); 
    973  
    974   /* Now optimize the ansi string */ 
    975   safe_ansi_string(dst, 0, dst->len, buff, bp); 
    976   free_ansi_string(dst); 
    977953} 
    978954 
     
    12331209   * the included string, such that 
    12341210   * s(decompose(str)) == str, down to the last space, tab, 
    1235    * and newline. Except for ansi. */ 
     1211   * and newline. */ 
    12361212  safe_str(decompose_str(args[0]), buff, bp); 
    12371213} 
     
    12761252 
    12771253  char sep; 
    1278   int trim; 
     1254  enum trim_style { TRIM_LEFT, TRIM_RIGHT, TRIM_BOTH } trim; 
    12791255  int trim_style_arg, trim_char_arg; 
    12801256  ansi_string *as; 
     
    13031279  /* If a trim style is provided, it must be the third argument. */ 
    13041280  if (nargs >= trim_style_arg) { 
    1305     switch (DOWNCASE(*args[trim_style_arg - 1])) { 
     1281    switch (*args[trim_style_arg - 1]) { 
    13061282    case 'l': 
    1307       trim = 1; 
     1283    case 'L': 
     1284      trim = TRIM_LEFT; 
    13081285      break; 
    13091286    case 'r': 
    1310       trim = 2; 
     1287    case 'R': 
     1288      trim = TRIM_RIGHT; 
    13111289      break; 
    13121290    default: 
    1313       trim = 3
     1291      trim = TRIM_BOTH
    13141292      break; 
    13151293    } 
    13161294  } else 
    1317     trim = 3
     1295    trim = TRIM_BOTH
    13181296 
    13191297  /* We will never need to check for buffer length overrunning, since 
     
    13241302  /* If necessary, skip over the leading stuff. */ 
    13251303  as = parse_ansi_string(args[0]); 
    1326   if (trim != 2) { 
     1304  if (trim != TRIM_RIGHT) { 
    13271305    for (i = 0; i < as->len; i++) { 
    13281306      if (as->text[i] != sep) 
     
    13321310  } 
    13331311  /* Cut off the trailing stuff, if appropriate. */ 
    1334   if ((trim != 1)) { 
     1312  if ((trim != TRIM_LEFT)) { 
    13351313    for (i = as->len - 1; i >= 0; i--) { 
    13361314      if (as->text[i] != sep) 
     
    15081486    repl = parse_ansi_string(args[i + 1]); 
    15091487    if (strcmp(needle, "$") == 0) { 
    1510       ansi_string_insert(orig, orig->len, repl, 0, repl->len); 
     1488      ansi_string_insert(orig, orig->len, repl); 
    15111489    } else if (strcmp(needle, "^") == 0) { 
    1512       ansi_string_insert(orig, 0, repl, 0, repl->len); 
     1490      ansi_string_insert(orig, 0, repl); 
    15131491    } else if (nlen == 0) { 
    15141492      /* Annoying. Stick repl between each character */ 
    15151493      /* Since this is inserts, we're working *backwards* */ 
    15161494      for (j = orig->len - 1; j > 0; j--) { 
    1517         ansi_string_insert(orig, j, repl, 0, repl->len); 
     1495        ansi_string_insert(orig, j, repl); 
    15181496      } 
    15191497    } else { 
     
    15221500      while ((ptr = strstr(search, needle)) != NULL) { 
    15231501        /* Perform the replacement */ 
    1524         ansi_string_replace(orig, ptr - orig->text, nlen, repl, 0, repl->len); 
     1502        ansi_string_replace(orig, ptr - orig->text, nlen, repl); 
    15251503        search = ptr + repl->len; 
    15261504      }