예제 #1
0
파일: ssm.c 프로젝트: hadigsf/Assault-3.0
/*
 * Read and allocate space for a string from a file.
 * This replaces db.c fread_string
 * This is modified version of Furey's fread_string from Merc
 */
char *_fread_string(FILE * fp, const char *caller)
{
    char buf[MAX_STRING_LENGTH * 4];
    char *ptr = buf;
    char c;

    do
    {
        c = getc(fp);
    }
    while (isspace(c));

    if ((*ptr++ = c) == '~')
        return &str_empty[0];

    for (;;)
    {
        switch (*ptr = getc(fp))
        {
        default:
            ptr++;
            break;

        case EOF:
            bugf("Fread_string: EOF");
            raise(SIGSEGV);
            break;

        case '\n':
            ptr++;
            *ptr++ = '\r';
            break;

        case '\r':
            break;

        case '~':
            *ptr = '\0';
            if (fBootDb)
            {
                int len = ptr - buf;

                ptr = temp_hash_find(buf, len);
                if (ptr)
                    return _str_dup(ptr, caller);

                ptr = _str_dup(buf, caller);
                temp_hash_add(ptr, len);
                return ptr;
            }

            ptr=_str_dup(buf, caller);
            tail_chain();
            return ptr;
        }
    }
}
예제 #2
0
파일: ssm.c 프로젝트: janvandijk/muds
/*
 * Read and allocate space for a string from a file.
 * This replaces db.c fread_string
 * This is modified version of Furey's fread_string from Merc
 */
char *fread_string( FILE *fp, int *status )
{
    char buf[ MAX_STRING_LENGTH*4 ];
    char *ptr = buf;
    char  c;

    *status = 0;

    do { c = getc( fp ); }
    while( isspace( c ) );

    if( ( *ptr++ = c ) == '~' )
        return &str_empty[0];

    for ( ;; )
    {
	switch ( *ptr = getc( fp ) )
	{
	    default:
	        ptr++;
		break;

	    case EOF:
		bug( "Fread_string: EOF", 0 );
		*status = 1;
		return NULL;
		break;

	    case '\n':
		ptr++;
		*ptr++ = '\r';
		break;

	    case '\r':
		break;

	    case '~':
		*ptr = '\0';
		if( fBootDb )
		{ 
		    ptr = temp_hash_find( buf ); 
		    if( ptr )
		        return str_dup( ptr ); 
		    
		    ptr = str_dup( buf );
		    temp_hash_add( ptr );
		    return ptr;
		}

		return str_dup( buf );
	}
    }
}
예제 #3
0
/*
 * Read and allocate space for a string from a file.
 * This replaces db.c fread_string
 */
char *fread_string( FILE *fp, int *status )
{
    char  buf [ MAX_STRING_LENGTH*8 ];
    char *ptr = buf;
    char  c;
    int count;

    count = 0;

    *status = 0;

    do { c = getc( fp ); }
    while( isspace( c ) );

    if( ( *ptr++ = c ) == '~' )
        return &str_empty[0];

    for ( ;; )
    {
        count++;
        if( count > (MAX_STRING_LENGTH*8 - 2))
            log_string( "Error in fread_string: the MUD is about to crash because a string is too large." );
	switch ( *ptr = getc( fp ) )
	{
	    default:
	        ptr++;
		break;

	    case EOF:
		bug( "Fread_string: EOF", 0 );
		*status = 1;
		return NULL;
		break;

	    case '\n':
		ptr++;
		*ptr++ = '\r';
		break;

	    case '\r':
		break;

	    case '~':
		*ptr = '\0';
		if( fBootDb )
		{ 
		    int len = ptr - buf;
	
		    ptr = temp_hash_find( buf, len ); 
		    if( ptr )
			return str_dup( ptr );

		    ptr = str_dup( buf );
		    temp_hash_add( ptr, len );
		    return ptr;
		}

                if( strlen( buf ) > MAX_STRING_LENGTH*7 )
                {
                    log_string( "Warning: a string is nearing the maximum length allowed by the MUD.  The fread_string function may bomb out soon." );
                    log_string( "This is probably the news file.  Chop out the old news entries and see if this message disappears." );
                }

		return str_dup( buf );
	}
    }
}