Exemplo n.º 1
0
static xmlNodePtr seek(xmlNodePtr root, const char *elem)
{
	xmlNodePtr childNode = root;
	const char *path, *p;
	char nodename[128];
	int last = 0;

	path = elem;
	if (path[0] == '/')
		path++;
	if (path[0] == 0)
		return NULL;
	while (!last) {
		if ((p = strchr(path, '/')) == NULL) {
			p = path + strlen(path);
			last = 1;
		}
		snprintf(nodename, p - path + 1, "%s", path);
		childNode = find_child_node(childNode, nodename);
		if (childNode == NULL)
			return NULL;
		path = ++p;
	}
	return childNode;
}
Exemplo n.º 2
0
static MVMGrapheme32 lookup_synthetic(MVMThreadContext *tc, MVMCodepoint *codes, MVMint32 num_codes) {
    MVMNFGTrieNode *cur_node        = tc->instance->nfg->grapheme_lookup;
    MVMCodepoint   *cur_code        = codes;
    MVMint32        codes_remaining = num_codes;
    while (cur_node && codes_remaining) {
        cur_node = find_child_node(tc, cur_node, *cur_code);
        cur_code++;
        codes_remaining--;
    }
    return cur_node ? cur_node->graph : 0;
}
Exemplo n.º 3
0
char *argv[]
{
 int character;
 int string_code;
 unsigned int index;
 InitializeStorage();
 InitializeDictionary();
 if ( ( string_code = getc( input ) ) == EOF )
 string_code = END_OF_STREAM;
 while ( ( character = getc( input ) ) != EOF ) {
 index = find_child_node( string_code, character );
 if ( DICT( index ).code_value != -1)
 string_code = DICT( index ).code_value;
 else {
 DICT( index ).code_value = next_code++;
 DICT( index ).parent_code = string_code;
 DICT( index ).character = (char) character;
 OutputBits( output,
 (unsigned long) string_code, current_code_bits );
 string_code = character;
 if ( next_code > MAX_CODE ) {
 OutputBits( output,
 (unsigned long) FLUSH_CODE, current_code_bits );
 InitializeDictionary();
 } else if ( next_code > next_bump_code ) {
 OutputBits( output,
 (unsigned long) BUMP_CODE, current_code_bits );
 current_code_bits++;
 next_bump_code <<= 1;
 next_bump_code |= 1;
 putc( 'B', stdout );
 }
 }
 }
 OutputBits( output, (unsigned long) string_code, current_code_bits );
 OutputBits( output, (unsigned long) END_OF_STREAM, current_code_bits);
 while ( argc— > 0 )
 printf( "Unknown argument: %s\n", *argv++ );
}
Exemplo n.º 4
0
ubyte *lzw_compress( ubyte *inputbuf, ubyte *outputbuf, int input_size, int *output_size )
{
	BIT_BUF *output;
	int character;
	int string_code;
	unsigned int index;
	int i;

	output = OpenOutputBitBuf();

	if ( outputbuf == NULL )
	{
		output->buf = (ubyte *)malloc(input_size*sizeof(ubyte));
		if (output->buf == NULL)
		{
			//printf("    ERROR : OpenOutputBitBuf - Not enough memory to read buffer.\n");
			//exit(1);
			return NULL;
		}
		outputbuf = output->buf;
	}
	else
	{
		output->buf = outputbuf;
	}

	InitializeStorage();
	InitializeDictionary();
	string_code = ( *inputbuf++ );
	for ( i=0 ; i<input_size ; i++ )
	{

		if (output->current_byte+4 >= input_size)
		{
			CloseOutputBitBuf( output );
			FreeStorage();
			free( outputbuf );
			*output_size = -1;
			return NULL;
		}

		character = ( *inputbuf++ );
		index = find_child_node( string_code, character );
		if ( dict[ index ].code_value != - 1 )
		{
			string_code = dict[ index ].code_value;
		}
		else
		{
			dict[ index ].code_value = next_code++;
			dict[ index ].parent_code = string_code;
			dict[ index ].character = (char) character;
			OutputBits( output,(unsigned long) string_code, current_code_bits );
			string_code = character;

			if ( next_code > MAX_CODE )
			{
				OutputBits( output,(unsigned long) FLUSH_CODE, current_code_bits );
				InitializeDictionary();
			}
			else if ( next_code > next_bump_code )
			{
				OutputBits( output,(unsigned long) BUMP_CODE, current_code_bits );
				current_code_bits++;
				next_bump_code <<= 1;
				next_bump_code |= 1;
			}
		}
	}
	OutputBits( output, (unsigned long) string_code, current_code_bits );
	OutputBits( output, (unsigned long) END_OF_STREAM, current_code_bits);

	*output_size = output->current_byte + 1;

	CloseOutputBitBuf( output );
	FreeStorage();

	return outputbuf;
}