Changeset 1117 for 1.8.3/trunk/src/funstr.c
- Timestamp:
- 10/05/07 15:36:32 (1 year ago)
- Files:
-
- 1.8.3/trunk/src/funstr.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.3/trunk/src/funstr.c
r1032 r1117 13 13 #include <limits.h> 14 14 #include <locale.h> 15 #include <stddef.h> 15 16 #include "conf.h" 16 17 #include "externs.h" … … 389 390 src = parse_ansi_string(args[2]); 390 391 391 ansi_string_insert(dst, pos, src , 0, src->len);392 ansi_string_insert(dst, pos, src); 392 393 393 394 safe_ansi_string(dst, 0, dst->len, buff, bp); … … 459 460 src = parse_ansi_string(args[3]); 460 461 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 463 464 safe_ansi_string(dst, 0, dst->len, buff, bp); 464 465 free_ansi_string(dst); … … 936 937 FUNCTION(fun_scramble) 937 938 { 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; 943 940 944 941 if (!*args[0]) 945 942 return; 946 943 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 */952 944 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); 972 952 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);977 953 } 978 954 … … 1233 1209 * the included string, such that 1234 1210 * s(decompose(str)) == str, down to the last space, tab, 1235 * and newline. Except for ansi.*/1211 * and newline. */ 1236 1212 safe_str(decompose_str(args[0]), buff, bp); 1237 1213 } … … 1276 1252 1277 1253 char sep; 1278 inttrim;1254 enum trim_style { TRIM_LEFT, TRIM_RIGHT, TRIM_BOTH } trim; 1279 1255 int trim_style_arg, trim_char_arg; 1280 1256 ansi_string *as; … … 1303 1279 /* If a trim style is provided, it must be the third argument. */ 1304 1280 if (nargs >= trim_style_arg) { 1305 switch ( DOWNCASE(*args[trim_style_arg - 1])) {1281 switch (*args[trim_style_arg - 1]) { 1306 1282 case 'l': 1307 trim = 1; 1283 case 'L': 1284 trim = TRIM_LEFT; 1308 1285 break; 1309 1286 case 'r': 1310 trim = 2; 1287 case 'R': 1288 trim = TRIM_RIGHT; 1311 1289 break; 1312 1290 default: 1313 trim = 3;1291 trim = TRIM_BOTH; 1314 1292 break; 1315 1293 } 1316 1294 } else 1317 trim = 3;1295 trim = TRIM_BOTH; 1318 1296 1319 1297 /* We will never need to check for buffer length overrunning, since … … 1324 1302 /* If necessary, skip over the leading stuff. */ 1325 1303 as = parse_ansi_string(args[0]); 1326 if (trim != 2) {1304 if (trim != TRIM_RIGHT) { 1327 1305 for (i = 0; i < as->len; i++) { 1328 1306 if (as->text[i] != sep) … … 1332 1310 } 1333 1311 /* Cut off the trailing stuff, if appropriate. */ 1334 if ((trim != 1)) {1312 if ((trim != TRIM_LEFT)) { 1335 1313 for (i = as->len - 1; i >= 0; i--) { 1336 1314 if (as->text[i] != sep) … … 1508 1486 repl = parse_ansi_string(args[i + 1]); 1509 1487 if (strcmp(needle, "$") == 0) { 1510 ansi_string_insert(orig, orig->len, repl , 0, repl->len);1488 ansi_string_insert(orig, orig->len, repl); 1511 1489 } else if (strcmp(needle, "^") == 0) { 1512 ansi_string_insert(orig, 0, repl , 0, repl->len);1490 ansi_string_insert(orig, 0, repl); 1513 1491 } else if (nlen == 0) { 1514 1492 /* Annoying. Stick repl between each character */ 1515 1493 /* Since this is inserts, we're working *backwards* */ 1516 1494 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); 1518 1496 } 1519 1497 } else { … … 1522 1500 while ((ptr = strstr(search, needle)) != NULL) { 1523 1501 /* 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); 1525 1503 search = ptr + repl->len; 1526 1504 }
