The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

newstr.c File Reference

#include "jam.h"
#include "newstr.h"
#include "hash.h"
#include <stddef.h>
#include <stdlib.h>

Include dependency graph for newstr.c:

Include dependency graph

Go to the source code of this file.

Classes

struct  strblock

Defines

#define STRING_BLOCK   4096

Typedefs

typedef strblock strblock
typedef char * STRING

Functions

char * allocate (size_t n)
char * copystr (char *s)
void donestr ()
void freestr (char *s)
char * newstr (char *string)

Variables

char * storage_finish = 0
char * storage_start = 0
strblockstrblock_chain = 0
hashstrhash = 0
int strtotal = 0


Define Documentation

#define STRING_BLOCK   4096
 

Definition at line 43 of file newstr.c.


Typedef Documentation

typedef struct strblock strblock
 

typedef char* STRING
 

Definition at line 33 of file newstr.c.


Function Documentation

char* allocate size_t  n  )  [static]
 

Definition at line 59 of file newstr.c.

References strblock::data, data, strblock::next, storage_finish, storage_start, and strblock_chain.

Referenced by newstr().

00060 {
00061     /* See if we can grab storage from an existing block */
00062     size_t remaining = storage_finish - storage_start;
00063     if ( remaining >= n )
00064     {
00065         char* result = storage_start;
00066         storage_start += n;
00067         return result;
00068     }
00069     else /* Must allocate a new block */
00070     {
00071         strblock* new_block;
00072         size_t nalloc = n;
00073         if ( nalloc < STRING_BLOCK )
00074             nalloc = STRING_BLOCK;
00075 
00076         /* allocate a new block and link into the chain */
00077         new_block = (strblock*)malloc( offsetof( strblock, data[0] ) + nalloc * sizeof(new_block->data[0]) );
00078         if ( new_block == 0 )
00079             return 0;
00080         new_block->next = strblock_chain;
00081         strblock_chain = new_block;
00082 
00083         /* Take future allocations out of the larger remaining space */
00084         if ( remaining < nalloc - n )
00085         {
00086             storage_start = new_block->data + n;
00087             storage_finish = new_block->data + nalloc;
00088         }
00089         return new_block->data;
00090     }
00091 }

char* copystr char *  s  ) 
 

Definition at line 125 of file newstr.c.

Referenced by actions_new(), add_hash_key(), add_module_name(), add_rule_name(), call_bind_rule(), compile_foreach(), copytarget(), list_copy(), list_sublist(), make1list(), make1settings(), and var_expand().

00126 {
00127         return s;
00128 }

void donestr  ) 
 

Definition at line 144 of file newstr.c.

References hashdone(), n, strblock::next, strblock_chain, strhash, and strtotal.

Referenced by main().

00145 {
00146     /* Reclaim string blocks */
00147     while ( strblock_chain != 0 )
00148     {
00149         strblock* n = strblock_chain->next;
00150         free(strblock_chain);
00151         strblock_chain = n;
00152     }
00153     
00154     hashdone( strhash );
00155     
00156     if( DEBUG_MEM )
00157         printf( "%dK in strings\n", strtotal / 1024 );
00158 }

Here is the call graph for this function:

void freestr char *  s  ) 
 

Definition at line 135 of file newstr.c.

Referenced by actions_free(), call_bind_rule(), delete_var_(), freesettings(), global_rule(), list_new(), parse_free(), and rule_free().

00136 {
00137 }

char* newstr char *  string  ) 
 

Definition at line 98 of file newstr.c.

References allocate(), HASHDATA, hashenter, hashinit(), m, s, strhash, STRING, string, and strtotal.

Referenced by addsettings(), bindmodule(), bindtarget(), builtin_backtrace(), builtin_calc(), builtin_caller_module(), builtin_glob_back(), builtin_match(), builtin_normalize_path(), builtin_subst(), builtin_update(), class_module_name(), compile_eval(), downcase_list(), enter_rule(), global_rule_name(), headers1(), lol_build(), macro_headers(), main(), make1cmds(), new_module_str(), pwd(), search(), search_for_target(), time_enter(), timestamp(), var_defines(), var_enter(), var_expand(), and var_expand_unit_test().

00099 {
00100         STRING str, *s = &str;
00101 
00102         if( !strhash )
00103             strhash = hashinit( sizeof( STRING ), "strings" );
00104 
00105         *s = string;
00106 
00107         if( hashenter( strhash, (HASHDATA **)&s ) )
00108         {
00109             int l = strlen( string );
00110             char *m = (char *)allocate( l + 1 );
00111 
00112             strtotal += l + 1;
00113             memcpy( m, string, l + 1 );
00114             *s = m;
00115         }
00116 
00117         return *s;
00118 }

Here is the call graph for this function:


Variable Documentation

char* storage_finish = 0 [static]
 

Definition at line 54 of file newstr.c.

Referenced by allocate().

char* storage_start = 0 [static]
 

Definition at line 53 of file newstr.c.

Referenced by allocate().

strblock* strblock_chain = 0 [static]
 

Definition at line 50 of file newstr.c.

Referenced by allocate(), and donestr().

struct hash* strhash = 0 [static]
 

Definition at line 35 of file newstr.c.

Referenced by donestr(), and newstr().

int strtotal = 0 [static]
 

Definition at line 36 of file newstr.c.

Referenced by donestr(), and newstr().


Generated on Mon Nov 8 17:08:15 2004 for MPT by  doxygen 1.3.9.1