Saving case?

Posted by Zeno on Wed 21 Jul 2004 03:19 AM — 4 posts, 10,811 views.

USA #0
What function stores cases? I am making a create_weapon function, but it fails to keep the case. The function has 3 args. And I've tried different things like this:

    sprintf( buf, "%s", arg1 );
    STRFREE( weapon->name );
    weapon->name = STRALLOC( buf );


I've also used the one_argument on all args. But the case still doesn't save.

(Example, if I created a weapon that should have long desc as "The Ultimate Sword lies here" it comes out as "the ultimate sword lies here".)

Or, how would I have it store cases?

This may help to know, too:

    weapon = create_object(get_obj_index(OBJ_VNUM_CUSTOM_WEAP), 0);
Canada #1
The issue here is something that was put in for whatever reason in one_argument, it makes all characters lower case. If you look, it should be this:
/*
 * Pick off one argument from a string and return the rest.
 * Understands quotes.
 */
char *one_argument( char *argument, char *arg_first )
{
    char cEnd;
    sh_int count;

    count = 0;

    if ( !argument || argument[0] == '\0' )
    {
    	arg_first[0] = '\0';
	return argument;
    }

    while ( isspace(*argument) )
	argument++;

    cEnd = ' ';
    if ( *argument == '\'' || *argument == '"' )
	cEnd = *argument++;

    while ( *argument != '\0' || ++count >= 255 )
    {
	if ( *argument == cEnd )
	{
	    argument++;
	    break;
	}
	*arg_first = LOWER(*argument);
	arg_first++;
	argument++;
    }
    *arg_first = '\0';

    while ( isspace(*argument) )
	argument++;

    return argument;
}


This I beleive has been brought up before, but the ++count >= 255 is also rediculous and wrong. You could create another function that doesn't LOWER, or just remove it from this one.
USA #2
Well I know why does LOWER. "Kill zeno" won't work, it'd have to be "Kill Zeno", etc. I suggest not replacing that function, just add a new one.

But my new function doesn't seem to work.

char *one_argument_case( char *argument, char *arg_first )
{
    char cEnd;
    sh_int count;

    count = 0;

    if ( !argument || argument[0] == '\0' )
    {
        arg_first[0] = '\0';
        return argument;
    }

    while ( isspace(*argument) )
        argument++;

    cEnd = ' ';
    if ( *argument == '\'' || *argument == '"' )
        cEnd = *argument++;

    while ( *argument != '\0' || ++count >= 255 )
    {
        if ( *argument == cEnd )
        {
            argument++;
            break;
        }
        arg_first++;
        argument++;
    }
    *arg_first = '\0';

    while ( isspace(*argument) )
        argument++;

    return argument;
}



makeweapon 'agony' 'The Agony' 'The Agony, a sharp dagger, lies here' 'dagger'
You begin to meld many objects together...
You finish your work, and hold up the newly created [ in the air.



    one_argument_case( argument, arg1 );
    one_argument_case( argument, arg2 );
    one_argument_case( argument, arg3 );
    one_argument_case( argument, arg4 );

And whats the difference between:
one_argument_case( argument, arg1 );
and:
argument = one_argument_case( argument, arg1 );

[EDIT] I know what the above does.

[EDIT2] Whoops, I guess I shouldn't remove the whole line. Fixed.
Amended on Wed 21 Jul 2004 06:21 AM by Zeno
Canada #3
You still need that one line, it copies the character from one pointer to the other, you just don't want the LOWER part, like such:
char *one_argument_case( char *argument, char *arg_first )
{
    char cEnd;
    sh_int count;

    count = 0;

    if ( !argument || argument[0] == '\0' )
    {
        arg_first[0] = '\0';
        return argument;
    }

    while ( isspace(*argument) )
        argument++;

    cEnd = ' ';
    if ( *argument == '\'' || *argument == '"' )
        cEnd = *argument++;

    while ( *argument != '\0' || ++count >= 255 )
    {
        if ( *argument == cEnd )
        {
            argument++;
            break;
        }
        *arg_first = *argument;
        arg_first++;
        argument++;
    }
    *arg_first = '\0';

    while ( isspace(*argument) )
        argument++;

    return argument;
}