#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "tables.h"
#include "olc.h"
Include dependency graph for string.c:

Go to the source code of this file.
Functions | |
| char * | first_arg (char *argument, char *arg_first, bool fCase) |
| char * | format_string (char *oldstring) |
| char * | getline (char *str, char *buf) |
| char * | numlines (char *) |
| void | string_add (CHAR_DATA *ch, char *argument) |
| void | string_append (CHAR_DATA *ch, char **pString) |
| void | string_edit (CHAR_DATA *ch, char **pString) |
| char * | string_lineadd (char *, char *, int) |
| char * | string_linedel (char *, int) |
| char * | string_proper (char *argument) |
| char * | string_replace (char *orig, char *old, char *new) |
| char * | string_unpad (char *argument) |
|
||||||||||||||||
|
Definition at line 583 of file string.c. References LOWER. Referenced by program_flow(), and string_add(). 00584 {
00585 char cEnd;
00586
00587 while (*argument == ' ')
00588 argument++;
00589
00590 cEnd = ' ';
00591 if (*argument == '\'' || *argument == '"'
00592 || *argument == '%' || *argument == '(')
00593 {
00594 if (*argument == '(')
00595 {
00596 cEnd = ')';
00597 argument++;
00598 }
00599 else
00600 cEnd = *argument++;
00601 }
00602
00603 while (*argument != '\0')
00604 {
00605 if (*argument == cEnd)
00606 {
00607 argument++;
00608 break;
00609 }
00610 if (fCase)
00611 *arg_first = LOWER (*argument);
00612 else
00613 *arg_first = *argument;
00614 arg_first++;
00615 argument++;
00616 }
00617 *arg_first = '\0';
00618
00619 while (*argument == ' ')
00620 argument++;
00621
00622 return argument;
00623 }
|
|
|
Definition at line 300 of file string.c. References bug(), FALSE, free_string(), MAX_STRING_LENGTH, str_dup(), TRUE, and UPPER. Referenced by OEDIT(), parse_note(), REDIT(), and string_add(). 00301 {
00302 char xbuf[MAX_STRING_LENGTH];
00303 char xbuf2[MAX_STRING_LENGTH];
00304 char *rdesc;
00305 int i = 0;
00306 int end_of_line;
00307 bool cap = TRUE;
00308 bool bFormat = TRUE;
00309
00310 xbuf[0] = xbuf2[0] = 0;
00311
00312 i = 0;
00313
00314 for (rdesc = oldstring; *rdesc; rdesc++)
00315 {
00316
00317 if (*rdesc != '`')
00318 {
00319 if (bFormat)
00320 {
00321 if (*rdesc == '\n')
00322 {
00323 if (*(rdesc + 1) == '\r' && *(rdesc + 2) == ' ' && *(rdesc + 3) == '\n' && xbuf[i - 1] != '\r')
00324 {
00325 xbuf[i] = '\n';
00326 xbuf[i + 1] = '\r';
00327 xbuf[i + 2] = '\n';
00328 xbuf[i + 3] = '\r';
00329 i += 4;
00330 rdesc += 2;
00331 }
00332 else if (*(rdesc + 1) == '\r' && *(rdesc + 2) == ' ' && *(rdesc + 2) == '\n' && xbuf[i - 1] == '\r')
00333 {
00334 xbuf[i] = '\n';
00335 xbuf[i + 1] = '\r';
00336 i += 2;
00337 }
00338 else if (*(rdesc + 1) == '\r' && *(rdesc + 2) == '\n' && xbuf[i - 1] != '\r')
00339 {
00340 xbuf[i] = '\n';
00341 xbuf[i + 1] = '\r';
00342 xbuf[i + 2] = '\n';
00343 xbuf[i + 3] = '\r';
00344 i += 4;
00345 rdesc += 1;
00346 }
00347 else if (*(rdesc + 1) == '\r' && *(rdesc + 2) == '\n' && xbuf[i - 1] == '\r')
00348 {
00349 xbuf[i] = '\n';
00350 xbuf[i + 1] = '\r';
00351 i += 2;
00352 }
00353 else if (xbuf[i - 1] != ' ' && xbuf[i - 1] != '\r')
00354 {
00355 xbuf[i] = ' ';
00356 i++;
00357 }
00358 }
00359 else if (*rdesc == '\r') ;
00360 else if (*rdesc == 'i' && *(rdesc + 1) == '.' && *(rdesc + 2) == 'e' && *(rdesc + 3) == '.')
00361 {
00362 xbuf[i] = 'i';
00363 xbuf[i + 1] = '.';
00364 xbuf[i + 2] = 'e';
00365 xbuf[i + 3] = '.';
00366 i += 4;
00367 rdesc += 3;
00368 }
00369 else if (*rdesc == ' ')
00370 {
00371 if (xbuf[i - 1] != ' ')
00372 {
00373 xbuf[i] = ' ';
00374 i++;
00375 }
00376 }
00377 else if (*rdesc == ')')
00378 {
00379 if (xbuf[i - 1] == ' ' && xbuf[i - 2] == ' '
00380 && (xbuf[i - 3] == '.' || xbuf[i - 3] == '?' || xbuf[i - 3] == '!'))
00381 {
00382 xbuf[i - 2] = *rdesc;
00383 xbuf[i - 1] = ' ';
00384 xbuf[i] = ' ';
00385 i++;
00386 }
00387 else if (xbuf[i - 1] == ' ' && (xbuf[i - 2] == ',' || xbuf[i - 2] == ';'))
00388 {
00389 xbuf[i - 1] = *rdesc;
00390 xbuf[i] = ' ';
00391 i++;
00392 }
00393 else
00394 {
00395 xbuf[i] = *rdesc;
00396 i++;
00397 }
00398 }
00399 else if (*rdesc == ',' || *rdesc == ';')
00400 {
00401 if (xbuf[i - 1] == ' ')
00402 {
00403 xbuf[i - 1] = *rdesc;
00404 xbuf[i] = ' ';
00405 i++;
00406 }
00407 else
00408 {
00409 xbuf[i] = *rdesc;
00410 if (*(rdesc + 1) != '\"')
00411 {
00412 xbuf[i + 1] = ' ';
00413 i += 2;
00414 }
00415 else
00416 {
00417 xbuf[i + 1] = '\"';
00418 xbuf[i + 2] = ' ';
00419 i += 3;
00420 rdesc++;
00421 }
00422 }
00423
00424 }
00425 else if (*rdesc == '.' || *rdesc == '?' || *rdesc == '!')
00426 {
00427 if (xbuf[i - 1] == ' ' && xbuf[i - 2] == ' '
00428 && (xbuf[i - 3] == '.' || xbuf[i - 3] == '?' || xbuf[i - 3] == '!'))
00429 {
00430 xbuf[i - 2] = *rdesc;
00431 if (*(rdesc + 1) != '\"')
00432 {
00433 xbuf[i - 1] = ' ';
00434 xbuf[i] = ' ';
00435 i++;
00436 }
00437 else
00438 {
00439 xbuf[i - 1] = '\"';
00440 xbuf[i] = ' ';
00441 xbuf[i + 1] = ' ';
00442 i += 2;
00443 rdesc++;
00444 }
00445 }
00446 else
00447 {
00448 xbuf[i] = *rdesc;
00449 if (*(rdesc + 1) != '\"')
00450 {
00451 xbuf[i + 1] = ' ';
00452 xbuf[i + 2] = ' ';
00453 i += 3;
00454 }
00455 else
00456 {
00457 xbuf[i + 1] = '\"';
00458 xbuf[i + 2] = ' ';
00459 xbuf[i + 3] = ' ';
00460 i += 4;
00461 rdesc++;
00462 }
00463 }
00464 cap = TRUE;
00465 }
00466 else
00467 {
00468 xbuf[i] = *rdesc;
00469 if (cap)
00470 {
00471 cap = FALSE;
00472 xbuf[i] = UPPER (xbuf[i]);
00473 }
00474 i++;
00475 }
00476 }
00477 else
00478 {
00479 xbuf[i] = *rdesc;
00480 i++;
00481 }
00482 }
00483 else
00484 {
00485 if (*(rdesc + 1) == 'Z')
00486 bFormat = !bFormat;
00487 xbuf[i] = *rdesc;
00488 i++;
00489 rdesc++;
00490 xbuf[i] = *rdesc;
00491 i++;
00492 }
00493 }
00494 xbuf[i] = 0;
00495 strcpy (xbuf2, xbuf);
00496
00497 rdesc = xbuf2;
00498
00499 xbuf[0] = 0;
00500
00501 for (;;)
00502 {
00503 end_of_line = 77;
00504 for (i = 0; i < end_of_line; i++)
00505 {
00506 if (*(rdesc + i) == '`')
00507 {
00508 end_of_line += 2;
00509 i++;
00510 }
00511
00512 if (!*(rdesc + i))
00513 break;
00514
00515 if (*(rdesc + i) == '\r')
00516 end_of_line = i;
00517 }
00518 if (i < end_of_line)
00519 {
00520 break;
00521 }
00522 if (*(rdesc + i - 1) != '\r')
00523 {
00524 for (i = (xbuf[0] ? (end_of_line - 1) : (end_of_line - 4)); i; i--)
00525 {
00526 if (*(rdesc + i) == ' ')
00527 break;
00528 }
00529 if (i)
00530 {
00531 *(rdesc + i) = 0;
00532 strcat (xbuf, rdesc);
00533 strcat (xbuf, "\n\r");
00534 rdesc += i + 1;
00535 while (*rdesc == ' ')
00536 rdesc++;
00537 }
00538 else
00539 {
00540 bug ("`5Wrap_string: `@No spaces``", 0);
00541 *(rdesc + (end_of_line - 2)) = 0;
00542 strcat (xbuf, rdesc);
00543 strcat (xbuf, "-\n\r");
00544 rdesc += end_of_line - 1;
00545 }
00546 }
00547 else
00548 {
00549 *(rdesc + i - 1) = 0;
00550 strcat (xbuf, rdesc);
00551 strcat (xbuf, "\r");
00552 rdesc += i;
00553 while (*rdesc == ' ')
00554 rdesc++;
00555 }
00556 }
00557 while (*(rdesc + i) && (*(rdesc + i) == ' ' ||
00558 *(rdesc + i) == '\n' ||
00559 *(rdesc + i) == '\r'))
00560 i--;
00561 *(rdesc + i + 1) = 0;
00562 strcat (xbuf, rdesc);
00563 if (xbuf[strlen (xbuf) - 2] != '\n')
00564 strcat (xbuf, "\n\r");
00565
00566 free_string (oldstring);
00567 return (str_dup (xbuf));
00568 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 763 of file string.c. Referenced by numlines(), and process_output(). 00764 {
00765 int tmp = 0;
00766 bool found = FALSE;
00767
00768 while (*str)
00769 {
00770 if (*str == '\n')
00771 {
00772 found = TRUE;
00773 break;
00774 }
00775
00776 buf[tmp++] = *(str++);
00777 }
00778
00779 if (found)
00780 {
00781 if (*(str + 1) == '\r')
00782 str += 2;
00783 else
00784 str += 1;
00785 } /* para que quedemos en el inicio de la prox linea */
00786
00787 buf[tmp] = '\0';
00788
00789 return str;
00790 }
|
|
|
Definition at line 792 of file string.c. References getline(), and MAX_STRING_LENGTH. Referenced by string_add(), and string_append(). 00793 {
00794 int cnt = 1;
00795 static char buf[MAX_STRING_LENGTH * 2];
00796 char buf2[MAX_STRING_LENGTH], tmpb[MAX_STRING_LENGTH];
00797
00798 buf[0] = '\0';
00799
00800 while (*string)
00801 {
00802 string = getline (string, tmpb);
00803 sprintf (buf2, "{W%3d{x. {x%s\n\r", cnt++, tmpb);
00804 strcat (buf, buf2);
00805 }
00806
00807 return buf;
00808 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 121 of file string.c. References mprog_code::code, mprog_list::code, ED_MPCODE, EDIT_MPCODE, FALSE, first_arg(), format_string(), free_string(), MAX_INPUT_LENGTH, MAX_KEY_HASH, MAX_STRING_LENGTH, mob_index_hash, mob_index_data::mprogs, mprog_list::next, mob_index_data::next, numlines(), one_argument(), send_to_char(), smash_tilde(), str_cmp(), str_dup(), string_lineadd(), string_linedel(), string_replace(), mob_index_data::vnum, mprog_code::vnum, and mprog_list::vnum. 00122 {
00123 char buf[MAX_STRING_LENGTH];
00124
00125 /*
00126 * Thanks to James Seng
00127 */
00128 smash_tilde (argument);
00129
00130 if (*argument == '.')
00131 {
00132 char arg1[MAX_INPUT_LENGTH];
00133 char arg2[MAX_INPUT_LENGTH];
00134 char arg3[MAX_INPUT_LENGTH];
00135 char tmparg3[MAX_INPUT_LENGTH];
00136
00137 argument = one_argument (argument, arg1);
00138 argument = first_arg (argument, arg2, FALSE);
00139 strcpy (tmparg3, argument);
00140 argument = first_arg (argument, arg3, FALSE);
00141
00142 if (!str_cmp (arg1, ".c"))
00143 {
00144 send_to_char ("String cleared.\n\r", ch);
00145 free_string (*ch->desc->pString);
00146 *ch->desc->pString = str_dup ("");
00147 return;
00148 }
00149
00150 if (!str_cmp (arg1, ".s"))
00151 {
00152 send_to_char ("String so far:\n\r", ch);
00153 send_to_char (numlines (*ch->desc->pString), ch);
00154 return;
00155 }
00156
00157 if (!str_cmp (arg1, ".r"))
00158 {
00159 if (arg2[0] == '\0')
00160 {
00161 send_to_char ("usage: .r \"old string\" \"new string\"\n\r",
00162 ch);
00163 return;
00164 }
00165
00166 *ch->desc->pString =
00167 string_replace (*ch->desc->pString, arg2, arg3);
00168 sprintf (buf, "'%s' replaced with '%s'.\n\r", arg2, arg3);
00169 send_to_char (buf, ch);
00170 return;
00171 }
00172
00173 if (!str_cmp (arg1, ".f"))
00174 {
00175 *ch->desc->pString = format_string (*ch->desc->pString);
00176 send_to_char ("String formatted.\n\r", ch);
00177 return;
00178 }
00179
00180 if (!str_cmp (arg1, ".ld"))
00181 {
00182 *ch->desc->pString =
00183 string_linedel (*ch->desc->pString, atoi (arg2));
00184 send_to_char ("Line deleted.\n\r", ch);
00185 return;
00186 }
00187
00188 if (!str_cmp (arg1, ".li"))
00189 {
00190 *ch->desc->pString =
00191 string_lineadd (*ch->desc->pString, tmparg3, atoi (arg2));
00192 send_to_char ("Line inserted.\n\r", ch);
00193 return;
00194 }
00195
00196 if (!str_cmp (arg1, ".lr"))
00197 {
00198 *ch->desc->pString =
00199 string_linedel (*ch->desc->pString, atoi (arg2));
00200 *ch->desc->pString =
00201 string_lineadd (*ch->desc->pString, tmparg3, atoi (arg2));
00202 send_to_char ("Line replaced.\n\r", ch);
00203 return;
00204 }
00205
00206 if (!str_cmp (arg1, ".h"))
00207 {
00208 send_to_char ("Sedit help (commands on blank line): \n\r", ch);
00209 send_to_char (".r 'old' 'new' - replace a substring \n\r", ch);
00210 send_to_char (" (requires '', \"\") \n\r", ch);
00211 send_to_char (".h - get help (this info)\n\r", ch);
00212 send_to_char (".s - show string so far \n\r", ch);
00213 send_to_char (".f - (word wrap) string \n\r", ch);
00214 send_to_char (".c - clear string so far \n\r", ch);
00215 send_to_char (".ld <num> - delete line number <num>\n\r",
00216 ch);
00217 send_to_char (".li <num> <str> - insert <str> at line <num>\n\r",
00218 ch);
00219 send_to_char
00220 (".lr <num> <str> - replace line <num> with <str>\n\r",
00221 ch);
00222 send_to_char ("@ - end string \n\r", ch);
00223 return;
00224 }
00225
00226 send_to_char ("SEdit: Invalid dot command.\n\r", ch);
00227 return;
00228 }
00229
00230 if (*argument == '~' || *argument == '@')
00231 {
00232 if (ch->desc->editor == ED_MPCODE)
00233 { /* for the mobprogs */
00234 MOB_INDEX_DATA *mob;
00235 int hash;
00236 MPROG_LIST *mpl;
00237 MPROG_CODE *mpc;
00238
00239 EDIT_MPCODE (ch, mpc);
00240
00241 if (mpc != NULL)
00242 for (hash = 0; hash < MAX_KEY_HASH; hash++)
00243 for (mob = mob_index_hash[hash]; mob; mob = mob->next)
00244 for (mpl = mob->mprogs; mpl; mpl = mpl->next)
00245 if (mpl->vnum == mpc->vnum)
00246 {
00247 sprintf (buf, "Editting mob %d.\n\r",
00248 mob->vnum);
00249 send_to_char (buf, ch);
00250 mpl->code = mpc->code;
00251 }
00252 }
00253
00254 ch->desc->pString = NULL;
00255 return;
00256 }
00257
00258 strcpy (buf, *ch->desc->pString);
00259
00260 /*
00261 * Truncate strings to MAX_STRING_LENGTH.
00262 * --------------------------------------
00263 * Edwin strikes again! Fixed avoid adding to a too-long
00264 * note. JR -- 10/15/00
00265 */
00266 if (strlen ( *ch->desc->pString ) + strlen (argument) >= (MAX_STRING_LENGTH - 4))
00267 {
00268 send_to_char ("String too long, last line skipped.\n\r", ch);
00269
00270 /* Force character out of editing mode. */
00271 ch->desc->pString = NULL;
00272 return;
00273 }
00274
00275 /*
00276 * Ensure no tilde's inside string.
00277 * --------------------------------
00278 */
00279 smash_tilde (argument);
00280
00281 strcat (buf, argument);
00282 strcat (buf, "\n\r");
00283 free_string (*ch->desc->pString);
00284 *ch->desc->pString = str_dup (buf);
00285 return;
00286 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 66 of file string.c. References numlines(), send_to_char(), and str_dup(). Referenced by change_exit(), HEDIT(), MEDIT(), MPEDIT(), OEDIT(), parse_note(), and REDIT(). 00067 {
00068 send_to_char ("-=======- Entering APPEND Mode -========-\n\r", ch);
00069 send_to_char (" Type .h on a new line for help\n\r", ch);
00070 send_to_char (" Terminate with a ~ or @ on a blank line.\n\r", ch);
00071 send_to_char ("-=======================================-\n\r", ch);
00072
00073 if (*pString == NULL)
00074 {
00075 *pString = str_dup ("");
00076 }
00077 send_to_char (numlines (*pString), ch);
00078
00079 /* numlines sends the string with \n\r */
00080 /* if ( *(*pString + strlen( *pString ) - 1) != '\r' )
00081 send_to_char( "\n\r", ch ); */
00082
00083 ch->desc->pString = pString;
00084
00085 return;
00086 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 38 of file string.c. References send_to_char(), and str_dup(). 00039 {
00040 send_to_char ("-========- Entering EDIT Mode -=========-\n\r", ch);
00041 send_to_char (" Type .h on a new line for help\n\r", ch);
00042 send_to_char (" Terminate with a ~ or @ on a blank line.\n\r", ch);
00043 send_to_char ("-=======================================-\n\r", ch);
00044
00045 if (*pString == NULL)
00046 {
00047 *pString = str_dup ("");
00048 }
00049 else
00050 {
00051 **pString = '\0';
00052 }
00053
00054 ch->desc->pString = pString;
00055
00056 return;
00057 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 722 of file string.c. References FALSE, free_string(), MAX_STRING_LENGTH, str_dup(), and TRUE. Referenced by string_add(). 00723 {
00724 char *strtmp = string;
00725 int cnt = 1, tmp = 0;
00726 bool done = FALSE;
00727 char buf[MAX_STRING_LENGTH];
00728
00729 buf[0] = '\0';
00730
00731 for (; *strtmp != '\0' || (!done && cnt == line); strtmp++)
00732 {
00733 if (cnt == line && !done)
00734 {
00735 strcat (buf, newstr);
00736 strcat (buf, "\n\r");
00737 tmp += strlen (newstr) + 2;
00738 cnt++;
00739 done = TRUE;
00740 }
00741
00742 buf[tmp++] = *strtmp;
00743
00744 if (done && *strtmp == '\0')
00745 break;
00746
00747 if (*strtmp == '\n')
00748 {
00749 if (*(strtmp + 1) == '\r')
00750 buf[tmp++] = *(++strtmp);
00751
00752 cnt++;
00753 }
00754
00755 buf[tmp] = '\0';
00756 }
00757
00758 free_string (string);
00759 return str_dup (buf);
00760 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 689 of file string.c. References free_string(), MAX_STRING_LENGTH, and str_dup(). Referenced by string_add(). 00690 {
00691 char *strtmp = string;
00692 char buf[MAX_STRING_LENGTH];
00693 int cnt = 1, tmp = 0;
00694
00695 buf[0] = '\0';
00696
00697 for (; *strtmp != '\0'; strtmp++)
00698 {
00699 if (cnt != line)
00700 buf[tmp++] = *strtmp;
00701
00702 if (*strtmp == '\n')
00703 {
00704 if (*(strtmp + 1) == '\r')
00705 {
00706 if (cnt != line)
00707 buf[tmp++] = *(++strtmp);
00708 else
00709 ++strtmp;
00710 }
00711
00712 cnt++;
00713 }
00714 }
00715
00716 buf[tmp] = '\0';
00717
00718 free_string (string);
00719 return str_dup (buf);
00720 }
|
Here is the call graph for this function:

|
|
Definition at line 666 of file string.c. References UPPER. Referenced by AEDIT(). 00667 {
00668 char *s;
00669
00670 s = argument;
00671
00672 while (*s != '\0')
00673 {
00674 if (*s != ' ')
00675 {
00676 *s = UPPER (*s);
00677 while (*s != ' ' && *s != '\0')
00678 s++;
00679 }
00680 else
00681 {
00682 s++;
00683 }
00684 }
00685
00686 return argument;
00687 }
|
|
||||||||||||||||
|
Definition at line 95 of file string.c. References free_string(), MAX_STRING_LENGTH, and str_dup(). Referenced by AEDIT(), and string_add(). 00096 {
00097 char xbuf[MAX_STRING_LENGTH];
00098 int i;
00099
00100 xbuf[0] = '\0';
00101 strcpy (xbuf, orig);
00102 if (strstr (orig, old) != NULL)
00103 {
00104 i = strlen (orig) - strlen (strstr (orig, old));
00105 xbuf[i] = '\0';
00106 strcat (xbuf, new);
00107 strcat (xbuf, &orig[i + strlen (old)]);
00108 free_string (orig);
00109 }
00110
00111 return str_dup (xbuf);
00112 }
|
Here is the call graph for this function:

|
|
Definition at line 631 of file string.c. References free_string(), MAX_STRING_LENGTH, and str_dup(). Referenced by AEDIT(). 00632 {
00633 char buf[MAX_STRING_LENGTH];
00634 char *s;
00635
00636 s = argument;
00637
00638 while (*s == ' ')
00639 s++;
00640
00641 strcpy (buf, s);
00642 s = buf;
00643
00644 if (*s != '\0')
00645 {
00646 while (*s != '\0')
00647 s++;
00648 s--;
00649
00650 while (*s == ' ')
00651 s--;
00652 s++;
00653 *s = '\0';
00654 }
00655
00656 free_string (argument);
00657 return str_dup (buf);
00658 }
|
Here is the call graph for this function:

1.4.0