swr1fuss prompt problems

Posted by Asean Novari on Fri 25 Feb 2005 12:29 AM — 18 posts, 64,970 views.

USA #0
On the default_prompt when i enter a command the command gets
either entered on the next line or after all the text on that
line..
but as soon as i enter in my own customized prompt it gets
entered a new line and it makes some of the last characters
for my prompt warp to the next line with it..

is there a way to fix this..

also is there a way to add a empty line after the prompt and
still have it be a mud feature rather than a plugin..
Canada #1
If you want someone to be able to add a line break where they want, you can use this, put it in display_prompt as one of the options, then use %_ to add a new line
                        case '_':
                                mudstrlcpy(pbuf, "\n\r", MSL);
                                break;
USA #2
I see a display_prompt in comm.c but I dont get where to put in what you said.. and does indenting matter?

*edit*
shoots self in head as he locates place to insert code..
Amended on Fri 25 Feb 2005 01:11 AM by Asean Novari
USA #3
You can add the case with all the other cases, like:
case 'h'


No indenting doesn't really matter.
USA #4
$ make
make -s swreality
Compiling o/comm.o....
comm.c: In function `display_prompt':
comm.c:2890: warning: implicit declaration of function `mudstrlcpy'
comm.c:2890: error: `MSL' undeclared (first use in this function)
comm.c:2890: error: (Each undeclared identifier is reported only once
comm.c:2890: error: for each function it appears in.)
make[1]: *** [o/comm.o] Error 1
make: *** [all] Error 2

thats what i get when its entered into the function

            switch ( *prompt )
            {
               case '_':
                  mudstrlcpy(pbuf, "\n\r", MSL);
                  break;
               case '%':
                  *pbuf++ = '%';
                  *pbuf = '\0';
                  break;


added code
Amended on Fri 25 Feb 2005 01:18 AM by Asean Novari
USA #5
Grevan was using a different codebase, so change:
mudstrlcpy(pbuf, "\n\r", MSL);

to:
        sprintf( pbuf, "\n\r" );
USA #6
Quote:
No indenting doesn't really matter.
*gasp!!* Never say that! We're doomed to have poorly indented code submitted for the rest of our lives now! :-)
USA #7
I know, but I simply meant in terms of results. ;)
Canada #8
Thats what the wonderful program called indent is for, to change peoples poorly indented code to a format that you like, heh.

And I have mine set up as such, you need to put the check below the check for the % character, with the other special values. This is what I use:
                        case 'h':
                                pstat = ch->hit;
                                break;
                        case 'H':
                                pstat = ch->max_hit;
                                break;
                        case '_':
                                mudstrlcpy(pbuf, "\n\r", MSL);
                                break;
Since I'm using mudstrlcpy, you can just use strncpy instead, and it will produce the same result for your purposes.
Amended on Fri 25 Feb 2005 01:27 AM by Greven
USA #9
Ok Thanks guys.. everythings working right now

*EDIT*
Heh.. now i see another prompt issue i would like help with..

On another mud i played you could look at your current prompt by just typing prompt.. how do i enter that in here as well?


please and thanks
Amended on Fri 25 Feb 2005 01:33 AM by Asean Novari
Canada #10
You can use something like this:
    sprintf( buf, "%s\n\r", !str_cmp( ch->pcdata->prompt, "" ) ? "(default prompt)" : ch->pcdata->prompt );
    set_char_color( AT_WHITE, ch );
    write_to_descriptor( ch->desc->descriptor, "Your current prompt string:\n\r", 0 );
    write_to_descriptor( ch->desc->descriptor, buf, 0 );
    write_to_descriptor( ch->desc->descriptor, "Set prompt to what? (try help prompt)\n\r", 0 );
Should allow you to print out a characters prompt, including the color codes.
USA #11
should i enter this in player.c where the "set prompt to what" text is currenty at?

void do_prompt( CHAR_DATA * ch, char *argument )
{
   char arg[MAX_INPUT_LENGTH];

   if( IS_NPC( ch ) )
   {
      send_to_char( "NPC's can't change their prompt..\n\r", ch );
      return;
   }
   smash_tilde( argument );
   one_argument( argument, arg );
   if( !*arg )
   {
      send_to_char( "Set prompt to what? (try help prompt)\n\r", ch );
      return;
   }
   if( ch->pcdata->prompt )
      STRFREE( ch->pcdata->prompt );

   if( strlen( argument ) > 128 )
      argument[128] = '\0';



or does it go someplace else.. like comm.c
Amended on Fri 25 Feb 2005 01:57 AM by Asean Novari
Canada #12
You would put it in do_prompt. After looking at it, I don't like filtering my code as that, so I actually changed it to such
        if (!*arg)
        {
                if ( ch->desc && ch->desc->descriptor )
                {
                    sprintf( buf, "%s\n\r", !str_cmp( ch->pcdata->prompt, "" ) ? "(default prompt)" : ch->pcdata->prompt );
                    set_char_color( AT_WHITE, ch );
                    send_to_char("Your current prompt string:\n\r", ch );
                    ch_printf(ch, "%s\n\r", full_color(ch->pcdata->prompt));
                }
                send_to_char("Set prompt to what? (try help prompt)\n\r", ch);
                return;
        }

char     *full_color(char *str)
{
        static char ret[MAX_STRING_LENGTH];
        char     *retptr;

        retptr = ret;
        for (; *str != '\0'; str++)
        {
                if (*str == '&')
                {
                        *retptr = *str;
                        retptr++;
                        *retptr = '&';
                        retptr++;
                }
                else
                {
                        *retptr = *str;
                        retptr++;
                }
        }
        *retptr = '\0';
        return ret;
}
USA #13
this dosent work with swr1fuss .. i get this error

Administrator@Home ~/swr1fuss/src
$ make
make -s swreality
  Compiling o/player.o....
player.c: In function `do_prompt':
player.c:1150: error: `buf' undeclared (first use in this function)
player.c:1150: error: (Each undeclared identifier is reported only once
player.c:1150: error: for each function it appears in.)
player.c:1153: warning: implicit declaration of function `full_color'
player.c:1160: warning: `full_color' was declared implicitly `extern' and later `static'
player.c:1153: warning: previous declaration of `full_color'
player.c:1160: warning: type mismatch with previous implicit declaration
player.c:1153: warning: previous implicit declaration of `full_color'
make[1]: *** [o/player.o] Error 1
make: *** [all] Error 2
USA #14
Out of curiosity do you understand the errors? Most of them are very basic and you should be able to figure them out on your own - trust me, it'll do you service in the long run.

Also isn't the ability to display the prompt by just typing 'prompt' in by default?
Canada #15
It is in SMAUG, but not in SWR, I beleive SWR was based on SMAUG 1.2a, though I can't be certain.
USA #16
no i dont really understand all of the errors.. if i did then i wouldnt be posting them.. and for swr1fuss it appears that no its not installed
Canada #17
player.c:1150: error: `buf' undeclared (first use in this function)
player.c:1150: error: (Each undeclared identifier is reported only once
player.c:1150: error: for each function it appears in.)
This means that the variable used in that section of code, in this specific circumstance "buf", is not declared at the begining of the function, and its either a typo (which its not in this circumstance), or that its not declared, so you need to declare it.

player.c:1153: warning: implicit declaration of function `full_color'
player.c:1160: warning: `full_color' was declared implicitly `extern' and later `static'
player.c:1153: warning: previous declaration of `full_color'
player.c:1160: warning: type mismatch with previous implicit declaration
player.c:1153: warning: previous implicit declaration of `full_color'
These are all togeher, the implicit line means that you do not this defined or declared anywhere above it, so it needs to be, either through a function prototype or having the function above it in the file. Because its not defined/declared, it defaults to something and then when the compiler finds it below that, it gets type mismatching. A prototype will fix those last bit of errors.


Check this for more information:
http://vergil.chemistry.gatech.edu/resources/programming/c-tutorial/basic2.html