Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

alias.c File Reference

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "merc.h"

Include dependency graph for alias.c:

Go to the source code of this file.

Functions

void do_alia (CHAR_DATA *ch, char *argument)
void do_alias (CHAR_DATA *ch, char *argument)
void do_unalias (CHAR_DATA *ch, char *argument)
void substitute_alias (DESCRIPTOR_DATA *d, char *argument)


Function Documentation

void do_alia CHAR_DATA ch,
char *  argument
 

Definition at line 105 of file alias.c.

References send_to_char().

00106 {
00107     send_to_char ("I'm sorry, alias must be entered in full.\n\r", ch);
00108     return;
00109 }

Here is the call graph for this function:

void do_alias CHAR_DATA ch,
char *  argument
 

Definition at line 111 of file alias.c.

References pc_data::alias, pc_data::alias_sub, char_data::desc, free_string(), IS_NPC, MAX_ALIAS, MAX_INPUT_LENGTH, MAX_STRING_LENGTH, one_argument(), descriptor_data::original, char_data::pcdata, send_to_char(), smash_tilde(), str_cmp(), str_dup(), and str_prefix().

00112 {
00113     CHAR_DATA *rch;
00114     char arg[MAX_INPUT_LENGTH], buf[MAX_STRING_LENGTH];
00115     int pos;
00116 
00117     smash_tilde (argument);
00118 
00119     if (ch->desc == NULL)
00120         rch = ch;
00121     else
00122         rch = ch->desc->original ? ch->desc->original : ch;
00123 
00124     if (IS_NPC (rch))
00125         return;
00126 
00127     argument = one_argument (argument, arg);
00128 
00129 
00130     if (arg[0] == '\0')
00131     {
00132 
00133         if (rch->pcdata->alias[0] == NULL)
00134         {
00135             send_to_char ("You have no aliases defined.\n\r", ch);
00136             return;
00137         }
00138         send_to_char ("Your current aliases are:\n\r", ch);
00139 
00140         for (pos = 0; pos < MAX_ALIAS; pos++)
00141         {
00142             if (rch->pcdata->alias[pos] == NULL
00143                 || rch->pcdata->alias_sub[pos] == NULL)
00144                 break;
00145 
00146             sprintf (buf, "    %s:  %s\n\r", rch->pcdata->alias[pos],
00147                      rch->pcdata->alias_sub[pos]);
00148             send_to_char (buf, ch);
00149         }
00150         return;
00151     }
00152 
00153     if (!str_prefix ("una", arg) || !str_cmp ("alias", arg))
00154     {
00155         send_to_char ("Sorry, that word is reserved.\n\r", ch);
00156         return;
00157     }
00158 
00159     /* More Edwin-inspired fixes. JR -- 10/15/00 */
00160     if (strchr(arg,' ')||strchr(arg,'"')||strchr(arg,'\''))
00161     {
00162         send_to_char("The word to be aliased should not contain a space, "
00163             "a tick or a double-quote.\n\r",ch);
00164         return;
00165     }
00166 
00167     if (argument[0] == '\0')
00168     {
00169         for (pos = 0; pos < MAX_ALIAS; pos++)
00170         {
00171             if (rch->pcdata->alias[pos] == NULL
00172                 || rch->pcdata->alias_sub[pos] == NULL)
00173                 break;
00174 
00175             if (!str_cmp (arg, rch->pcdata->alias[pos]))
00176             {
00177                 sprintf (buf, "%s aliases to '%s'.\n\r",
00178                          rch->pcdata->alias[pos],
00179                          rch->pcdata->alias_sub[pos]);
00180                 send_to_char (buf, ch);
00181                 return;
00182             }
00183         }
00184 
00185         send_to_char ("That alias is not defined.\n\r", ch);
00186         return;
00187     }
00188 
00189     if (!str_prefix (argument, "delete") || !str_prefix (argument, "prefix"))
00190     {
00191         send_to_char ("That shall not be done!\n\r", ch);
00192         return;
00193     }
00194 
00195     for (pos = 0; pos < MAX_ALIAS; pos++)
00196     {
00197         if (rch->pcdata->alias[pos] == NULL)
00198             break;
00199 
00200         if (!str_cmp (arg, rch->pcdata->alias[pos]))
00201         {                        /* redefine an alias */
00202             free_string (rch->pcdata->alias_sub[pos]);
00203             rch->pcdata->alias_sub[pos] = str_dup (argument);
00204             sprintf (buf, "%s is now realiased to '%s'.\n\r", arg, argument);
00205             send_to_char (buf, ch);
00206             return;
00207         }
00208     }
00209 
00210     if (pos >= MAX_ALIAS)
00211     {
00212         send_to_char ("Sorry, you have reached the alias limit.\n\r", ch);
00213         return;
00214     }
00215 
00216     /* make a new alias */
00217     rch->pcdata->alias[pos] = str_dup (arg);
00218     rch->pcdata->alias_sub[pos] = str_dup (argument);
00219     sprintf (buf, "%s is now aliased to '%s'.\n\r", arg, argument);
00220     send_to_char (buf, ch);
00221 }

Here is the call graph for this function:

void do_unalias CHAR_DATA ch,
char *  argument
 

Definition at line 224 of file alias.c.

References pc_data::alias, pc_data::alias_sub, char_data::desc, FALSE, free_string(), IS_NPC, MAX_ALIAS, MAX_INPUT_LENGTH, one_argument(), descriptor_data::original, char_data::pcdata, send_to_char(), and TRUE.

00225 {
00226     CHAR_DATA *rch;
00227     char arg[MAX_INPUT_LENGTH];
00228     int pos;
00229     bool found = FALSE;
00230 
00231     if (ch->desc == NULL)
00232         rch = ch;
00233     else
00234         rch = ch->desc->original ? ch->desc->original : ch;
00235 
00236     if (IS_NPC (rch))
00237         return;
00238 
00239     argument = one_argument (argument, arg);
00240 
00241     if (arg[0] == '\0')
00242     {
00243         send_to_char ("Unalias what?\n\r", ch);
00244         return;
00245     }
00246 
00247     for (pos = 0; pos < MAX_ALIAS; pos++)
00248     {
00249         if (rch->pcdata->alias[pos] == NULL)
00250             break;
00251 
00252         if (found)
00253         {
00254             rch->pcdata->alias[pos - 1] = rch->pcdata->alias[pos];
00255             rch->pcdata->alias_sub[pos - 1] = rch->pcdata->alias_sub[pos];
00256             rch->pcdata->alias[pos] = NULL;
00257             rch->pcdata->alias_sub[pos] = NULL;
00258             continue;
00259         }
00260 
00261         if (!strcmp (arg, rch->pcdata->alias[pos]))
00262         {
00263             send_to_char ("Alias removed.\n\r", ch);
00264             free_string (rch->pcdata->alias[pos]);
00265             free_string (rch->pcdata->alias_sub[pos]);
00266             rch->pcdata->alias[pos] = NULL;
00267             rch->pcdata->alias_sub[pos] = NULL;
00268             found = TRUE;
00269         }
00270     }
00271 
00272     if (!found)
00273         send_to_char ("No alias of that name to remove.\n\r", ch);
00274 }

Here is the call graph for this function:

void substitute_alias DESCRIPTOR_DATA d,
char *  argument
 

Definition at line 41 of file alias.c.

References interpret(), IS_NPC, MAX_ALIAS, MAX_INPUT_LENGTH, MAX_STRING_LENGTH, one_argument(), char_data::prefix, send_to_char(), and str_prefix().

00042 {
00043     CHAR_DATA *ch;
00044     char buf[MAX_STRING_LENGTH], prefix[MAX_INPUT_LENGTH],
00045         name[MAX_INPUT_LENGTH];
00046     char *point;
00047     int alias;
00048 
00049     ch = d->original ? d->original : d->character;
00050 
00051     /* check for prefix */
00052     if (ch->prefix[0] != '\0' && str_prefix ("prefix", argument))
00053     {
00054         if (strlen (ch->prefix) + strlen (argument) > MAX_INPUT_LENGTH - 2)
00055             send_to_char ("Line to long, prefix not processed.\r\n", ch);
00056         else
00057         {
00058             sprintf (prefix, "%s %s", ch->prefix, argument);
00059             argument = prefix;
00060         }
00061     }
00062 
00063     if (IS_NPC (ch) || ch->pcdata->alias[0] == NULL
00064         || !str_prefix ("alias", argument) || !str_prefix ("una", argument)
00065         || !str_prefix ("prefix", argument))
00066     {
00067         interpret (d->character, argument);
00068         return;
00069     }
00070 
00071     strcpy (buf, argument);
00072 
00073     for (alias = 0; alias < MAX_ALIAS; alias++)
00074     {                            /* go through the aliases */
00075         if (ch->pcdata->alias[alias] == NULL)
00076             break;
00077 
00078         if (!str_prefix (ch->pcdata->alias[alias], argument))
00079         {
00080             point = one_argument (argument, name);
00081             if (!strcmp (ch->pcdata->alias[alias], name))
00082             {
00083                 /* More Edwin inspired fixes. JR -- 10/15/00 */
00084                 buf[0] = '\0';
00085                 strcat(buf,ch->pcdata->alias_sub[alias]);
00086                 if (point[0])
00087                 {
00088                     strcat(buf," ");
00089                     strcat(buf,point);
00090                 }
00091 
00092                 if (strlen (buf) > MAX_INPUT_LENGTH - 1)
00093                 {
00094                     send_to_char
00095                         ("Alias substitution too long. Truncated.\r\n", ch);
00096                     buf[MAX_INPUT_LENGTH - 1] = '\0';
00097                 }
00098                 break;
00099             }
00100         }
00101     }
00102     interpret (d->character, buf);
00103 }

Here is the call graph for this function:


Generated on Thu Jan 13 21:54:44 2005 for Beyond the Shadows by  doxygen 1.4.0