… | |
… | |
408 | { |
408 | { |
409 | result[resultlen++] = *src++; |
409 | result[resultlen++] = *src++; |
410 | } |
410 | } |
411 | } |
411 | } |
412 | result[resultlen] = '\0'; |
412 | result[resultlen] = '\0'; |
413 | } |
|
|
414 | |
|
|
415 | /** |
|
|
416 | * Taking a string as an argument, mutate it into a string that looks like a list. |
|
|
417 | * a 'list' for the purposes here, is a string of items, seperated by commas, except |
|
|
418 | * for the last entry, which has an 'and' before it, and a full stop (period) after it. |
|
|
419 | * This function will also strip all trailing non alphanumeric characters. |
|
|
420 | * It does not insert an oxford comma. |
|
|
421 | */ |
|
|
422 | void |
|
|
423 | make_list_like (char *input) |
|
|
424 | { |
|
|
425 | char *p, tmp[MAX_BUF]; |
|
|
426 | int i; |
|
|
427 | |
|
|
428 | if (!input || strlen (input) > MAX_BUF - 5) |
|
|
429 | return; |
|
|
430 | /* bad stuff would happen if we continued here, the -5 is to make space for ' and ' */ |
|
|
431 | |
|
|
432 | strncpy (tmp, input, MAX_BUF - 5); |
|
|
433 | /*trim all trailing commas, spaces etc. */ |
|
|
434 | for (i = strlen (tmp); !isalnum (tmp[i]) && i >= 0; i--) |
|
|
435 | tmp[i] = '\0'; |
|
|
436 | |
|
|
437 | strcat (tmp, "."); |
|
|
438 | |
|
|
439 | p = strrchr (tmp, ','); |
|
|
440 | if (p) |
|
|
441 | { |
|
|
442 | *p = '\0'; |
|
|
443 | strcpy (input, tmp); |
|
|
444 | p++; |
|
|
445 | strcat (input, " and"); |
|
|
446 | strcat (input, p); |
|
|
447 | } |
|
|
448 | else |
|
|
449 | strcpy (input, tmp); |
|
|
450 | |
|
|
451 | return; |
|
|
452 | } |
413 | } |
453 | |
414 | |
454 | /******************************************************************************/ |
415 | /******************************************************************************/ |
455 | |
416 | |
456 | /* Checks a player-provided string which will become the msg property of |
417 | /* Checks a player-provided string which will become the msg property of |