in the line:
do_look(d->character, "");

I get seg faulted... this is because do_look actually tries to add color code 
to a static buffer of zero length, yes?

What's the best way to work around this?

Here's what my do_look & copyover_recover look like

==snip==
void copyover_recover ()
{
        DESCRIPTOR_DATA *d;
        FILE *fp;
        char name [100];
        char host[MSL];
        int desc;
        bool fOld;


        logf ("Copyover recovery initiated");

        fp = fopen (COPYOVER_FILE, "r");

        if (!fp) /* there are some descriptors open which will hang forever 
then ? */
        {
                perror ("copyover_recover:fopen");
                logf ("Copyover file not found. Exitting.\n\r");
                exit (1);
        }

        unlink (COPYOVER_FILE); /* In case something crashes - doesn't prevent 
reading */

        for (;;)
        {
                fscanf (fp, "%d %s %s\n", &desc, name, host);
                if (desc == -1)
                        break;

                /* Write something, and check if it goes error-free */          
                if (!write_to_descriptor (desc, "\n\rRestoring from 
copyover...\n\r",0))
                {
                        close (desc); /* nope */
                        continue;
                }
                
                d = alloc_perm (sizeof(DESCRIPTOR_DATA));
                init_descriptor (d,desc); /* set up various stuff */

                d->host = str_dup (host);
                d->next = descriptor_list;
                descriptor_list = d;
                d->connected = CON_COPYOVER_RECOVER; /* -15, so close_socket 
frees the char 
*/
                

                /* Now, find the pfile */

                fOld = load_char_obj (d, name);

                if (!fOld) /* Player file not found?! */
                {
                        write_to_descriptor (desc, "\n\rSomehow, your character 
was lost in the 
copyover. Sorry.\n\r", 0);
                        close_socket (d);
                }
                else /* ok! */
                {
                        write_to_descriptor (desc, "\n\rCopyover recovery 
complete.\n\r",0);
        
                        /* Just In Case */
                        if (!d->character->in_room)
                                d->character->in_room = get_room_index 
(ROOM_VNUM_TEMPLE);

                        /* Insert in the char_list */
                        d->character->next = char_list;
                        char_list = d->character;

                        char_to_room (d->character, d->character->in_room);
                        do_look (d->character, "");
                        act ("$n materializes!", d->character, NULL, NULL, 
TO_ROOM);
                        d->connected = CON_PLAYING;
                }
                
        }
        
        fclose (fp);
}

==snip==

void do_look( CHAR_DATA *ch, char *argument )
{
    char buf  [MAX_STRING_LENGTH];
    char arg1 [MAX_INPUT_LENGTH];
    char arg2 [MAX_INPUT_LENGTH];
    char arg3 [MAX_INPUT_LENGTH];
    EXIT_DATA *pexit;
    CHAR_DATA *victim;
    OBJ_DATA *obj;
    char *pdesc;
    int door;
    int number,count;

    if ( ch->desc == NULL )
        return;

    if ( ch->position < POS_SLEEPING )
    {
        send_to_char( "You can't see anything but stars!\n\r", ch );
        return;
    }

    if ( ch->position == POS_SLEEPING )
    {
        send_to_char( "You can't see anything, you're sleeping!\n\r", ch );
        return;
    }

    if ( !check_blind( ch ) )
        return;

    if ( !IS_NPC(ch)
    &&   !IS_SET(ch->act, PLR_HOLYLIGHT)
    &&   room_is_dark( ch->in_room ) )
    {
        send_to_char( "It is pitch black ... \n\r", ch );
        show_char_to_char( ch->in_room->people, ch );
        return;
    }

    argument = one_argument( argument, arg1 );
    argument = one_argument( argument, arg2 );
    number = number_argument(arg1,arg3);
    count = 0;

    if ( arg1[0] == '\0' || !str_cmp( arg1, "auto" ) )
    {
        /* 'look' or 'look auto' */
        send_to_char( ROOM_TITLE_COLOR, ch );
        send_to_char( ch->in_room->name, ch );
        send_to_char( "{x", ch );

       if ( (IS_IMMORTAL(ch) && (IS_NPC(ch) || IS_SET(ch->act,PLR_HOLYLIGHT)))
       ||   IS_BUILDER(ch, ch->in_room->area) )

        {
            sprintf(buf," {w[{BRoom %d{w]{x",ch->in_room->vnum);
            send_to_char(buf,ch);
        }

        send_to_char( "\n\r", ch );

        if ( arg1[0] == '\0'
        || ( !IS_NPC(ch) && !IS_SET(ch->comm, COMM_BRIEF) ) )
        {
            send_to_char( "  ",ch);
            send_to_char( ROOM_DESC_COLOR, ch );
            send_to_char( ch->in_room->description, ch );
            send_to_char( "{x", ch );
        }

        if ( !IS_NPC(ch) && IS_SET(ch->act, PLR_AUTOEXIT) )
        {
            send_to_char("\n\r",ch);
            do_exits( ch, "auto" );
        }

        show_list_to_char( ch->in_room->contents, ch, FALSE, FALSE );
        show_char_to_char( ch->in_room->people,   ch );
        return;
    }

    if ( !str_cmp( arg1, "i" ) || !str_cmp(arg1, "in")  || 
!str_cmp(arg1,"on"))
    {
        /* 'look in' */
        if ( arg2[0] == '\0' )
        {
            send_to_char( "Look in what?\n\r", ch );
            return;
        }

        if ( ( obj = get_obj_here( ch, arg2 ) ) == NULL )
        {
            send_to_char( "You do not see that here.\n\r", ch );
            return;
        }

        switch ( obj->item_type )
        {
        default:
            send_to_char( "That is not a container.\n\r", ch );
            break;

        case ITEM_DRINK_CON:
            if ( obj->value[1] <= 0 )
            {
                send_to_char( "It is empty.\n\r", ch );
                break;
            }

            sprintf( buf, "It's %sfilled with  a %s liquid.\n\r",
                obj->value[1] <     obj->value[0] / 4
                    ? "less than half-" :
                obj->value[1] < 3 * obj->value[0] / 4
                    ? "about half-"     : "more than half-",
                liq_table[obj->value[2]].liq_color
                );

            send_to_char( buf, ch );
            break;

        case ITEM_CONTAINER:
        case ITEM_CORPSE_NPC:
        case ITEM_CORPSE_PC:
            if ( IS_SET(obj->value[1], CONT_CLOSED) )
            {
                send_to_char( "It is closed.\n\r", ch );
                break;
            }

            act( "$p holds:", ch, obj, NULL, TO_CHAR );
            show_list_to_char( obj->contains, ch, TRUE, TRUE );
            break;
        }
        return;
    }

    if ( ( victim = get_char_room( ch, arg1 ) ) != NULL )
    {
        show_char_to_char_1( victim, ch );
        return;
    }

    for ( obj = ch->carrying; obj != NULL; obj = obj->next_content )
    {
        if ( can_see_obj( ch, obj ) )
        {  /* player can see object */
            pdesc = get_extra_descr( arg3, obj->extra_descr );
            if ( pdesc != NULL )
                if (++count == number)
                {
                    send_to_char( pdesc, ch );
                    return;
                }
                else continue;

            pdesc = get_extra_descr( arg3, obj->pIndexData->extra_descr );
            if ( pdesc != NULL )
                if (++count == number)
                {
                    send_to_char( pdesc, ch );
                    return;
                }
                else continue;

            if ( is_name( arg3, obj->name ) )
                if (++count == number)
                {
                    send_to_char( obj->description, ch );
                    send_to_char( "\n\r",ch);
                    return;
                  }
          }
    }

    for ( obj = ch->in_room->contents; obj != NULL; obj = obj->next_content )
    {
        if ( can_see_obj( ch, obj ) )
        {
            pdesc = get_extra_descr( arg3, obj->extra_descr );
            if ( pdesc != NULL )
                if (++count == number)
                {
                    send_to_char( pdesc, ch );
                    return;
                }

            pdesc = get_extra_descr( arg3, obj->pIndexData->extra_descr );
            if ( pdesc != NULL )
                if (++count == number)
                {
                    send_to_char( pdesc, ch );
                    return;
                }

            if ( is_name( arg3, obj->name ) )
                if (++count == number)
                {
                    send_to_char( obj->description, ch );
                    send_to_char("\n\r",ch);
                    return;
                }
        }
    }

    pdesc = get_extra_descr(arg3,ch->in_room->extra_descr);
    if (pdesc != NULL)
    {
        if (++count == number)
        {
            send_to_char(pdesc,ch);
            return;
        }
    }

    if (count > 0 && count != number)
    {
        if (count == 1)
            sprintf(buf,"You only see one %s here.\n\r",arg3);
        else
            sprintf(buf,"You only see %d of those here.\n\r",count);

        send_to_char(buf,ch);
        return;
    }

         if ( !str_cmp( arg1, "n" ) || !str_cmp( arg1, "{wnorth{x" ) ) door 
=0;
    else if ( !str_cmp( arg1, "e" ) || !str_cmp( arg1, "{weast{x"  ) ) door 
=1;
    else if ( !str_cmp( arg1, "s" ) || !str_cmp( arg1, "{wsouth{x" ) ) door 
=2;
    else if ( !str_cmp( arg1, "w" ) || !str_cmp( arg1, "{wwest{x"  ) ) door 
=3;
    else if ( !str_cmp( arg1, "u" ) || !str_cmp( arg1, "{wup{x"    ) ) door 
=4;
    else if ( !str_cmp( arg1, "d" ) || !str_cmp( arg1, "{wdown{x"  ) ) door 
=5;
    else if ( !str_cmp( arg1, "ne" ) || !str_cmp( arg1, "{wnortheast{x"  ) ) 
door =6;
    else if ( !str_cmp( arg1, "nw" ) || !str_cmp( arg1, "{wnorthwest{x"  ) ) 
door =7;
    else if ( !str_cmp( arg1, "se" ) || !str_cmp( arg1, "{wsoutheast{x"  ) ) 
door =8;
    else if ( !str_cmp( arg1, "sw" ) || !str_cmp( arg1, "{wsouthwest{x"  ) ) 
door =9;
         else
    {
        send_to_char( "You do not see that here.\n\r", ch );
        return;
    }

    /* 'look direction' */
    if ( ( pexit = ch->in_room->exit[door] ) == NULL )
    {
        send_to_char( "Nothing special there.\n\r", ch );
        return;
    }

    if ( pexit->description != NULL && pexit->description[0] != '\0' )
        send_to_char( pexit->description, ch );
    else
        send_to_char( "Nothing special there.\n\r", ch );

    if ( pexit->keyword    != NULL
    &&   pexit->keyword[0] != '\0'
    &&   pexit->keyword[0] != ' ' )
    {
        if ( IS_SET(pexit->exit_info, EX_CLOSED) )
        {
            act( "The $d is closed.", ch, NULL, pexit->keyword, TO_CHAR );
        }
        else if ( IS_SET(pexit->exit_info, EX_ISDOOR) )
        {
            act( "The $d is open.",   ch, NULL, pexit->keyword, TO_CHAR );
        }
    }

    return;
}

==snip==

Reply via email to