コード例 #1
0
ファイル: command_loop.c プロジェクト: GBuella/Taltos
static void
print_move_path(const struct game *original_game,
                const move *m,
                enum move_notation_type mn)
{
    char str[MOVE_STR_BUFFER_LENGTH];
    bool first = true;
    struct game *g = game_copy(original_game);

    if (g == NULL)
        INTERNAL_ERROR();
    for (; *m != 0; ++m) {
        if (!is_uci) {
            if (game_turn(g) == white || first)
                printf("%u. ", game_full_move_count(g));
            if (first && game_turn(g) == black)
                printf("... ");
        }
        first = false;
        (void) print_move(game_current_position(g),
                          *m, str, mn, game_turn(g));
        printf("%s ", str);
        if (game_append(g, *m) != 0)
            INTERNAL_ERROR();
    }
    game_destroy(g);
}
コード例 #2
0
ファイル: SRA_Statistics.c プロジェクト: ncbi/ncbi-vdb
bool SRA_StatisticsNextPath ( const SRA_Statistics * self, ctx_t ctx, const char * path, const char** next )
{
    FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing );
    const DictionaryEntry * node = NULL;
    
    assert ( self );
    
    if ( path == NULL )
        INTERNAL_ERROR ( xcParamNull, "path is NULL" );
    else if ( path[0] == 0 )
    {
        node = ( const DictionaryEntry * ) BSTreeFirst ( & self -> dictionary );
    }
    else
    {
        node = ( const DictionaryEntry * ) BSTreeFind ( & self -> dictionary, ( const void * ) path, DictionaryEntryFind );
        if ( node == NULL )
        {
            INTERNAL_ERROR ( xcUnexpected, "dictionary item '%s' is not found", path );
        }
        else
        {
            node = ( const DictionaryEntry * ) BSTNodeNext ( & node -> dad );
        }
    }
    
    if ( node == NULL )
    {
        *next = NULL;
        return false;
    }
    *next = node -> path;
    return true;
}
コード例 #3
0
ファイル: SRA_Statistics.c プロジェクト: ncbi/ncbi-vdb
uint64_t SRA_StatisticsGetAsU64 ( const SRA_Statistics * self, ctx_t ctx, const char * path )
{
    FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing );
    
    assert ( self );
    
    if ( path == NULL )
        INTERNAL_ERROR ( xcParamNull, "path is NULL" );
    else
    {
        DictionaryEntry * node = ( DictionaryEntry * ) 
            BSTreeFind ( & self -> dictionary, ( const void * ) path, DictionaryEntryFind );
        if ( node == NULL )
        {
            INTERNAL_ERROR ( xcUnexpected, "dictionary item '%s' is not found", path );
        }
        else
        {
            switch ( node -> type )
            {
            case NGS_StatisticValueType_Int64:  
                if ( node -> value . i64 < 0 )
                {
                    INTERNAL_ERROR ( xcUnexpected, "cannot convert dictionary item '%s' from in64_t to uint64_t", path );
                }
                else
                {
                    return ( uint64_t ) node -> value . i64;
                }
                break;
                
            case NGS_StatisticValueType_UInt64: 
                return node -> value . i64; 
            
            case NGS_StatisticValueType_Real:   
                if ( node -> value . real < 0 || node -> value . real > ULLONG_MAX )
                {
                    INTERNAL_ERROR ( xcUnexpected, "cannot convert dictionary item '%s' from double to uint64_t", path );
                }
                else
                {
                    return ( uint64_t ) xtrunc ( node -> value . real );
                }
                break;
            
            case NGS_StatisticValueType_String: 
                return NGS_StringToU64 ( node -> value . str, ctx );
                
            default :
                INTERNAL_ERROR ( xcUnexpected, "unexpected type %u for dictionary item '%s'", node -> type, path );
                break;
            }
        }
    }
    
    return 0;
}
コード例 #4
0
ファイル: SRA_Statistics.c プロジェクト: ncbi/ncbi-vdb
NGS_String* SRA_StatisticsGetAsString ( const SRA_Statistics * self, ctx_t ctx, const char * path )
{
    FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing );
    
    assert ( self );
    
    if ( path == NULL )
        INTERNAL_ERROR ( xcParamNull, "path is NULL" );
    else
    {
        DictionaryEntry * node = ( DictionaryEntry * ) 
            BSTreeFind ( & self -> dictionary, ( const void * ) path, DictionaryEntryFind );
        if ( node == NULL )
        {
            INTERNAL_ERROR ( xcUnexpected, "dictionary item '%s' is not found", path );
        }
        else
        {
            switch ( node -> type )
            {
            case NGS_StatisticValueType_UInt64: 
                {
                    char buf[1024];
                    size_t num_writ;
                    string_printf ( buf, sizeof(buf), &num_writ, "%lu", node -> value . u64 );
                    return NGS_StringMakeCopy ( ctx, buf, num_writ );
                }
                break;
                
            case NGS_StatisticValueType_Int64:  
                {
                    char buf[1024];
                    size_t num_writ;
                    string_printf ( buf, sizeof(buf), &num_writ, "%li", node -> value . i64 );
                    return NGS_StringMakeCopy ( ctx, buf, num_writ );
                }
                
            case NGS_StatisticValueType_Real:   
                {
                    char buf[1024];
                    size_t num_writ;
                    string_printf ( buf, sizeof(buf), &num_writ, "%f", node -> value . real );
                    return NGS_StringMakeCopy ( ctx, buf, num_writ );
                }
                
            case NGS_StatisticValueType_String: 
                return NGS_StringDuplicate ( node -> value . str, ctx );
                
            default :
                INTERNAL_ERROR ( xcUnexpected, "unexpected type %u for dictionary item '%s'", node -> type, path );
                break;
            }
        }
    }
    
    return NULL;
}
コード例 #5
0
ファイル: conn_handler.c プロジェクト: ailove-lab/bloomd
/**
 * Internal method to handle a command that relies
 * on a filter name and a single key, responses are handled using
 * handle_multi_response.
 */
static void handle_filt_cmd(bloom_conn_handler *handle, char *args, int args_len,
        int(*filtmgr_func)(bloom_filtmgr *, char*)) {
    // If we have no args, complain.
    if (!args) {
        handle_client_err(handle->conn, (char*)&FILT_NEEDED, FILT_NEEDED_LEN);
        return;
    }

    // Scan past the filter name
    char *key;
    int key_len;
    int after = buffer_after_terminator(args, args_len, ' ', &key, &key_len);
    if (after == 0) {
        handle_client_err(handle->conn, (char*)&UNEXPECTED_ARGS, UNEXPECTED_ARGS_LEN);
        return;
    }

    // Call into the filter manager
    int res = filtmgr_func(handle->mgr, args);
    switch (res) {
        case 0:
            handle_client_resp(handle->conn, (char*)DONE_RESP, DONE_RESP_LEN);
            break;
        case -1:
            handle_client_resp(handle->conn, (char*)FILT_NOT_EXIST, FILT_NOT_EXIST_LEN);
            break;
        case -2:
            handle_client_resp(handle->conn, (char*)FILT_NOT_PROXIED, FILT_NOT_PROXIED_LEN);
            break;
        default:
            INTERNAL_ERROR();
            break;
    }
}
コード例 #6
0
ファイル: SRA_Statistics.c プロジェクト: ncbi/ncbi-vdb
static uint64_t NGS_StringToU64( const NGS_String * str, ctx_t ctx )
{
    /* have to guarantee NUL-termination for strtou64/strtod */
    char buf[4096];
    if ( sizeof(buf) > NGS_StringSize ( str, ctx ) )
    {
        char* end;
        uint64_t value;
        string_copy ( buf, sizeof(buf), 
                      NGS_StringData ( str, ctx ), NGS_StringSize ( str, ctx ) );
                      
        errno = 0;
        value = strtou64 ( buf, &end, 10 );
        if ( *end == 0 ) 
        {
            if ( errno == 0 )   
            {   
                return value;
            }
        }
        else
        {   /* attempt to parse as a double */
            double dbl;
            errno = 0;
            dbl = strtod ( buf, &end );
            if ( *end == 0 && errno == 0 && dbl >= 0 && dbl <= ULLONG_MAX )
            {
                return ( uint64_t ) xtrunc ( dbl );
            }
        }
    }
    INTERNAL_ERROR ( xcUnexpected, "cannot convert dictionary value '%.*s' from string to uint64", 
                                    NGS_StringSize ( str, ctx ), NGS_StringData ( str, ctx ) );
    return 0;
}
コード例 #7
0
ファイル: cspeldcl.c プロジェクト: HumbleRepose/dcerpc
void CSPELL_constant_val_to_string
(
    AST_constant_n_t *cp,
    char *str
)
{
    char const *str2;

    switch (cp->kind) {
        case AST_nil_const_k:
            sprintf (str, "NULL");
            break;
        case AST_boolean_const_k:
            if (cp->value.boolean_val)
                sprintf (str, "ndr_true");
            else
                sprintf (str, "ndr_false");
            break;
        case AST_int_const_k:
            sprintf (str, "%ld", cp->value.int_val);
            break;
        case AST_string_const_k:
            STRTAB_str_to_string (cp->value.string_val, &str2);
            sprintf (str, "\"%s\"", str2);
            break;
        case AST_char_const_k:
            sprintf (str, "'%s'", mapchar(cp, FALSE));
            break;
        default:
            INTERNAL_ERROR("Unsupported tag in CSPELL_constant_val_to_string");
            break;
        }
}
コード例 #8
0
ファイル: x-monideal.cpp プロジェクト: DanGrayson/M2
static MonomialIdeal *wrapperFrobbyAlexanderDual(const MonomialIdeal *I,
                                                 const M2_arrayint top)
// Assumption: top is an array of at least the number of variables of I
//   whose v-th entry is at least as large as the v-th exp of any mingen of I
{
  // Create a Frobby Ideal containing I.
  int nv = I->topvar() + 1;
  if (nv == 0)
    {
      INTERNAL_ERROR("attempting to use frobby with zero variables");
      return 0;
    }

  mpz_t *topvec = 0;
  if (top->len > 0)
    {
      topvec = newarray(mpz_t, top->len);
      for (int i = 0; i < top->len; i++)
        mpz_init_set_si(topvec[i], top->array[i]);
    }

  MonomialIdeal *result = FrobbyAlexanderDual(I, topvec);

  // Clean up
  if (topvec != 0)
    {
      for (int i = 0; i < top->len; i++) mpz_clear(topvec[i]);
      deletearray(topvec);
    }

  return result;
}
コード例 #9
0
ファイル: sra-sort.c プロジェクト: DCGenomics/sra-tools
static
uint64_t ArgsGetOptU64 ( Args *self, const ctx_t *ctx, const char *optname, uint32_t *count )
{
    rc_t rc;
    uint64_t val = 0;

    uint32_t dummy;
    if ( count == NULL )
        count = & dummy;

    rc = ArgsOptionCount ( self, optname, count );
    if ( rc == 0 && * count != 0 )
    {
        const char *str;
        rc = ArgsOptionValue ( self, optname, 0, & str );
        if ( rc != 0 )
            INTERNAL_ERROR ( rc, "failed to retrieve '%s' parameter", optname );
        else
        {
            char *end;
            val = strtou64 ( str, & end, 0 );
            if ( end [ 0 ] != 0 )
            {
                rc = RC ( rcExe, rcArgv, rcParsing, rcParam, rcIncorrect );
                ERROR ( rc, "bad '%s' parameter: '%s'", optname, str );
            }
        }
    }

    return val;
}
コード例 #10
0
ファイル: string-list.c プロジェクト: T-J-Teru/notmuch
void
_notmuch_string_list_sort (notmuch_string_list_t *list)
{
    notmuch_string_node_t **nodes, *node;
    int i;

    if (list->length == 0)
	return;

    nodes = talloc_array (list, notmuch_string_node_t *, list->length);
    if (unlikely (nodes == NULL))
	INTERNAL_ERROR ("Could not allocate memory for list sort");

    for (i = 0, node = list->head; node; i++, node = node->next)
	nodes[i] = node;

    qsort (nodes, list->length, sizeof (*nodes), cmpnode);

    for (i = 0; i < list->length - 1; ++i)
	nodes[i]->next = nodes[i+1];
    nodes[i]->next = NULL;
    list->head = nodes[0];
    list->tail = &nodes[i]->next;

    talloc_free (nodes);
}
コード例 #11
0
ファイル: notmuch-search.c プロジェクト: marc1006/notmuch
/* Print the most common variant of a list of unique mailboxes, and
 * conflate the counts. */
static void
print_popular (const search_context_t *ctx, GList *list)
{
    GList *l;
    mailbox_t *mailbox = NULL, *m;
    int max = 0;
    int total = 0;

    for (l = list; l; l = l->next) {
	m = l->data;
	total += m->count;
	if (m->count > max) {
	    mailbox = m;
	    max = m->count;
	}
    }

    if (! mailbox)
	INTERNAL_ERROR("Empty list in address hash table\n");

    /* The original count is no longer needed, so overwrite. */
    mailbox->count = total;

    print_mailbox (ctx, mailbox);
}
コード例 #12
0
ファイル: bm_utils.c プロジェクト: chsc0817/DBImpl-projekt
/*
 * set_state() -- initialize the RNG so that
 * appropriate data sets can be generated.
 * For each table that is to be generated, calculate the number of rows/child, and send that to the
 * seed generation routine in speed_seed.c. Note: assumes that tables are completely independent.
 * Returns the number of rows to be generated by the named step.
 */
DSS_HUGE
set_state(int table, long sf, long procs, long step, DSS_HUGE *extra_rows)
{
    int i;
	DSS_HUGE rowcount, remainder, result;
	
    if (sf == 0 || step == 0)
        return(0);

	rowcount = tdefs[table].base / procs;
	if ((sf / procs) > (int)MAX_32B_SCALE)
		INTERNAL_ERROR("SCALE OVERFLOW. RE-RUN WITH MORE CHILDREN.");
	rowcount *= sf;
	remainder = (tdefs[table].base % procs) * sf;
	rowcount += remainder / procs;
	result = rowcount;
	for (i=0; i < step - 1; i++)
		{
		if (table == LINE)	/* special case for shared seeds */
			tdefs[table].gen_seed(1, rowcount);
		else
			tdefs[table].gen_seed(0, rowcount);
		/* need to set seeds of child in case there's a dependency */
		/* NOTE: this assumes that the parent and child have the same base row count */
			if (tdefs[table].child != NONE) 
			tdefs[tdefs[table].child].gen_seed(0,rowcount);
		}
	*extra_rows = remainder % procs;
	if (step > procs)	/* moving to the end to generate updates */
		tdefs[table].gen_seed(0, *extra_rows);

	return(result);
}
コード例 #13
0
ファイル: cspell.c プロジェクト: HumbleRepose/dcerpc
static void CSPELL_type_tail
(
 FILE *fid,
 type_tail_t *tail,
 boolean encoding_services   /* TRUE => [encode] or [decode] on operation */
)
{
	int i;

	for (i = 0; i < tail->len; i++)
		switch (tail->vec[i].kind) {
			case p_k:
				fprintf (fid, ")");
				break;
			case a_k:
				CSPELL_array_bounds (
						fid,
						tail->vec[i].content.array_info.array,
						tail->vec[i].content.array_info.in_typedef_or_struct);
				break;
			case f_k:
				CSPELL_function_sig (
						fid,
						tail->vec[i].content.function_info.param_list,
						tail->vec[i].content.function_info.function_def,
						encoding_services);
				break;
			default:
				INTERNAL_ERROR("Invalid tail kind");
		}
}
コード例 #14
0
ファイル: nametbl.c プロジェクト: HumbleRepose/dcerpc
void NAMETABLE_clear_temp_name_mode
(
    void
)
{
    NAMETABLE_temp_name_t * This,
                          * next;

/*
 * Bugcheck if not in temporary mode.
 */
    if (!NAMETABLE_names_are_temporary)
        INTERNAL_ERROR ("Not in temp name mode");

/*
 * Walk the list of temp name blocks, freeing the name and then the block.
 */
    for (This = NAMETABLE_temp_chain; This != NULL; ) {
        NAMETABLE_delete_node (This->node);
        next = This->next;
        FREE (This);
        This = next;
    }

/*
 * Balance the nametable after all these deletions.
 */
    NAMETABLE_balance_tree();

/*
 * Clear the temporary flag and the chain head.
 */
    NAMETABLE_names_are_temporary = FALSE;
    NAMETABLE_temp_chain = NULL;
}
コード例 #15
0
ファイル: SRA_Statistics.c プロジェクト: ncbi/ncbi-vdb
static
DictionaryEntry * MakeNode ( SRA_Statistics * self, ctx_t ctx, const char * path )
{
    FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing );
    
    size_t path_size = string_size ( path );
    DictionaryEntry * node = malloc ( sizeof ( * node ) + path_size );
    if ( node == NULL )
    {
        SYSTEM_ERROR ( xcNoMemory, "allocating dictionary item" );
    }
    else
    {
        rc_t rc;
        string_copy ( node -> path, path_size + 1, path, path_size );
        
        /*TODO: decide whether to allow overwriting (not allowed now) */
        rc = BSTreeInsertUnique ( & self -> dictionary, & node -> dad, NULL, DictionaryEntryCompare );
        if ( rc == 0 )
        {
            return node;
        }
        
        INTERNAL_ERROR ( xcUnexpected, "inserting dictionary item '%s' rc = %R", node -> path, rc );
        free ( node );
    }
    return NULL;
}
コード例 #16
0
ファイル: conn_handler.c プロジェクト: ailove-lab/bloomd
static void handle_flush_cmd(bloom_conn_handler *handle, char *args, int args_len) {
    
    // If we have a specfic filter, use filt_cmd
    if (args) {
        handle_filt_cmd(handle, args, args_len, filtmgr_flush_filter);
        return;
    }

    // List all the filters
    bloom_filter_list_head *head;
    int res = filtmgr_list_filters(handle->mgr, NULL, &head);
    if (res != 0) {
        INTERNAL_ERROR();
        return;
    }

    // Flush all, ignore errors since
    // filters might get deleted in the process
    bloom_filter_list *node = head->head;
    while (node) {
        filtmgr_flush_filter(handle->mgr, node->filter_name);
        node = node->next;
    }

    // Respond
    handle_client_resp(handle->conn, (char*)DONE_RESP, DONE_RESP_LEN);

    // Cleanup
    filtmgr_cleanup_list(head);
}
コード例 #17
0
ファイル: permute.c プロジェクト: YIwama/bcb
long *
permute_dist(distribution *d, long stream)
	{
	static distribution *dist = NULL;
	int i;
	
	if (d != NULL)
		{
		if (d->permute == (long *)NULL)
			{
			d->permute = (long *)malloc(sizeof(long) * (DIST_SIZE(d)));
			MALLOC_CHECK(d->permute);
			for (i=0; i < (DIST_SIZE(d)); i++) 
				*(d->permute + i) = i;
			}
		dist = d;
		return(permute(dist->permute, DIST_SIZE(dist), stream));
		}
	
	
	if (dist != NULL)
		return(permute(NULL, DIST_SIZE(dist), stream));
	else
		INTERNAL_ERROR("Bad call to permute_dist");	
	}
コード例 #18
0
ファイル: conn_handler.c プロジェクト: ailove-lab/bloomd
/**
 * Helper to handle sending the response to the multi commands,
 * either multi or bulk.
 * @arg handle The conn handle
 * @arg cmd_res The result of the command
 * @arg num_keys The number of keys in the result buffer. This should NOT be
 * more than MULTI_OP_SIZE.
 * @arg res_buf The result buffer
 * @arg end_of_input Should the last result include a new line
 * @return 0 on success, 1 if we should stop.
 */
static int handle_multi_response(bloom_conn_handler *handle, int cmd_res, int num_keys, char *res_buf, int end_of_input) {
    // Do nothing if we get too many keys
    if (num_keys > MULTI_OP_SIZE || num_keys <= 0) return 1;

    if (cmd_res != 0) {
        switch (cmd_res) {
            case -1:
                handle_client_resp(handle->conn, (char*)FILT_NOT_EXIST, FILT_NOT_EXIST_LEN);
                break;
            default:
                INTERNAL_ERROR();
                break;
        }
        return 1;
    }

    // Allocate buffers for our response, plus a newline
    char *resp_bufs[MULTI_OP_SIZE];
    int resp_buf_lens[MULTI_OP_SIZE];

    // Set the response buffers according to the results
    int last_key = 1;
    for (int i=0; i < num_keys; i++) {
        last_key = end_of_input && (i == (num_keys - 1));
        switch (res_buf[i]) {
            case 0:
                resp_bufs[i] = (char*)((last_key) ? NO_RESP : NO_SPACE);
                resp_buf_lens[i] = (last_key) ? NO_RESP_LEN: NO_SPACE_LEN;
                break;
            case 1:
                resp_bufs[i] = (char*)((last_key) ? YES_RESP : YES_SPACE);
                resp_buf_lens[i] = (last_key) ? YES_RESP_LEN: YES_SPACE_LEN;
                break;
            default:
                INTERNAL_ERROR();
                return 1;
        }
    }

    // Write out!
    send_client_response(handle->conn, (char**)&resp_bufs, (int*)&resp_buf_lens, num_keys);
    return 0;
}
コード例 #19
0
ファイル: SRA_Statistics.c プロジェクト: ncbi/ncbi-vdb
double SRA_StatisticsGetAsDouble ( const SRA_Statistics * self, ctx_t ctx, const char * path )
{
    FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing );
    
    assert ( self );
    
    if ( path == NULL )
        INTERNAL_ERROR ( xcParamNull, "path is NULL" );
    else
    {
        DictionaryEntry * node = ( DictionaryEntry * ) 
            BSTreeFind ( & self -> dictionary, ( const void * ) path, DictionaryEntryFind );
        if ( node == NULL )
        {
            INTERNAL_ERROR ( xcUnexpected, "dictionary item '%s' is not found", path );
        }
        else
        {
            switch ( node -> type )
            {
            case NGS_StatisticValueType_Int64:  
                return ( double ) node -> value . i64;
                
            case NGS_StatisticValueType_UInt64: 
                return ( double ) node -> value . u64;
                
            case NGS_StatisticValueType_Real:   
                return node -> value . real;
                
            case NGS_StatisticValueType_String: 
                return NGS_StringToReal ( node -> value . str, ctx );
                break;
                
            default :
                INTERNAL_ERROR ( xcUnexpected, "unexpected type %u for dictionary item '%s'", node -> type, path );
                break;
            }
        }
    }
    
    return 0;
}
コード例 #20
0
ファイル: NGS_String.c プロジェクト: ncbi/ncbi-vdb
/* Size
 *  retrieve data length
 */
size_t NGS_StringSize ( const NGS_String * self, ctx_t ctx )
{
    if ( self == NULL )
    {
        FUNC_ENTRY ( ctx, rcSRA, rcString, rcAccessing );
        INTERNAL_ERROR ( xcSelfNull, "attempt to access NULL NGS_String" );
        return 0;
    }

    return self -> size;
}
コード例 #21
0
ファイル: cspell.c プロジェクト: HumbleRepose/dcerpc
static void CSPELL_add_paren_to_tail
(
 type_tail_t *tail
)
{
	int i;

	i = (tail->len) ++;
	if (tail->len > MAX_TAIL_LEN) INTERNAL_ERROR("Data structure too compilicated; Tail array overflow");
	(tail->vec)[i].kind = p_k;
}
コード例 #22
0
ファイル: NGS_String.c プロジェクト: ncbi/ncbi-vdb
/* Data
 *  retrieve data pointer
 */
const char * NGS_StringData ( const NGS_String * self, ctx_t ctx )
{
    if ( self == NULL )
    {
        FUNC_ENTRY ( ctx, rcSRA, rcString, rcAccessing );
        INTERNAL_ERROR ( xcSelfNull, "attempt to access NULL NGS_String" );
        return NULL;
    }

    return self -> str;
}
コード例 #23
0
ファイル: notmuch-search.c プロジェクト: marc1006/notmuch
/* Returns TRUE iff name and addr is duplicate. If not, stores the
 * name/addr pair in order to detect subsequent duplicates. */
static notmuch_bool_t
is_duplicate (const search_context_t *ctx, const char *name, const char *addr)
{
    char *key;
    GList *list, *l;
    mailbox_t *mailbox;

    list = g_hash_table_lookup (ctx->addresses, addr);
    if (list) {
	mailbox_t find = {
	    .name = name,
	    .addr = addr,
	};

	l = g_list_find_custom (list, &find, mailbox_compare);
	if (l) {
	    mailbox = l->data;
	    mailbox->count++;
	    return TRUE;
	}

	mailbox = new_mailbox (ctx->format, name, addr);
	if (! mailbox)
	    return FALSE;

	/*
	 * XXX: It would be more efficient to prepend to the list, but
	 * then we'd have to store the changed list head back to the
	 * hash table. This check is here just to avoid the compiler
	 * warning for unused result.
	 */
	if (list != g_list_append (list, mailbox))
	    INTERNAL_ERROR ("appending to list changed list head\n");

	return FALSE;
    }

    key = talloc_strdup (ctx->format, addr);
    if (! key)
	return FALSE;

    mailbox = new_mailbox (ctx->format, name, addr);
    if (! mailbox)
	return FALSE;

    list = g_list_append (NULL, mailbox);
    if (! list)
	return FALSE;

    g_hash_table_insert (ctx->addresses, key, list);

    return FALSE;
}
コード例 #24
0
iTWFactory* cGenreSwitcher::GetFactoryForGenre(cGenre::Genre g)
{
    cGenreInfoVec::const_iterator i = m_vGenres.find(g);

    if (i == m_vGenres.end())
    {
        ThrowAndAssert(INTERNAL_ERROR("Switch to invalid genre factory"));
    }

    ASSERT((*i)->m_pFactory != NULL);
    return ((*i)->m_pFactory);
}
コード例 #25
0
ファイル: notmuch-show.c プロジェクト: bgamari/notmuch
/* Print a message in "mboxrd" format as documented, for example,
 * here:
 *
 * http://qmail.org/qmail-manual-html/man5/mbox.html
 */
static notmuch_status_t
format_part_mbox (const void *ctx, unused (sprinter_t *sp), mime_node_t *node,
		  unused (int indent),
		  unused (const notmuch_show_params_t *params))
{
    notmuch_message_t *message = node->envelope_file;

    const char *filename;
    FILE *file;
    const char *from;

    time_t date;
    struct tm date_gmtime;
    char date_asctime[26];

    char *line = NULL;
    size_t line_size;
    ssize_t line_len;

    if (!message)
	INTERNAL_ERROR ("format_part_mbox requires a root part");

    filename = notmuch_message_get_filename (message);
    file = fopen (filename, "r");
    if (file == NULL) {
	fprintf (stderr, "Failed to open %s: %s\n",
		 filename, strerror (errno));
	return NOTMUCH_STATUS_FILE_ERROR;
    }

    from = notmuch_message_get_header (message, "from");
    from = _extract_email_address (ctx, from);

    date = notmuch_message_get_date (message);
    gmtime_r (&date, &date_gmtime);
    asctime_r (&date_gmtime, date_asctime);

    printf ("From %s %s", from, date_asctime);

    while ((line_len = getline (&line, &line_size, file)) != -1 ) {
	if (_is_from_line (line))
	    putchar ('>');
	printf ("%s", line);
    }

    printf ("\n");

    fclose (file);

    return NOTMUCH_STATUS_SUCCESS;
}
コード例 #26
0
ファイル: notmuch-show.c プロジェクト: briansniffen/notmuch
/* Write a MIME text part out to the given stream.
 *
 * If (flags & NOTMUCH_SHOW_TEXT_PART_REPLY), this prepends "> " to
 * each output line.
 *
 * Both line-ending conversion (CRLF->LF) and charset conversion ( ->
 * UTF-8) will be performed, so it is inappropriate to call this
 * function with a non-text part. Doing so will trigger an internal
 * error.
 */
void
show_text_part_content (GMimeObject *part, GMimeStream *stream_out,
                        notmuch_show_text_part_flags flags)
{
    GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
    GMimeStream *stream_filter = NULL;
    GMimeDataWrapper *wrapper;
    const char *charset;

    if (! g_mime_content_type_is_type (content_type, "text", "*"))
        INTERNAL_ERROR ("Illegal request to format non-text part (%s) as text.",
                        g_mime_content_type_to_string (content_type));

    if (stream_out == NULL)
        return;

    stream_filter = g_mime_stream_filter_new (stream_out);
    g_mime_stream_filter_add(GMIME_STREAM_FILTER (stream_filter),
                             g_mime_filter_crlf_new (FALSE, FALSE));

    charset = g_mime_object_get_content_type_parameter (part, "charset");
    if (charset) {
        GMimeFilter *charset_filter;
        charset_filter = g_mime_filter_charset_new (charset, "UTF-8");
        /* This result can be NULL for things like "unknown-8bit".
         * Don't set a NULL filter as that makes GMime print
         * annoying assertion-failure messages on stderr. */
        if (charset_filter) {
            g_mime_stream_filter_add (GMIME_STREAM_FILTER (stream_filter),
                                      charset_filter);
            g_object_unref (charset_filter);
        }

    }

    if (flags & NOTMUCH_SHOW_TEXT_PART_REPLY) {
        GMimeFilter *reply_filter;
        reply_filter = g_mime_filter_reply_new (TRUE);
        if (reply_filter) {
            g_mime_stream_filter_add (GMIME_STREAM_FILTER (stream_filter),
                                      reply_filter);
            g_object_unref (reply_filter);
        }
    }

    wrapper = g_mime_part_get_content_object (GMIME_PART (part));
    if (wrapper && stream_filter)
        g_mime_data_wrapper_write_to_stream (wrapper, stream_filter);
    if (stream_filter)
        g_object_unref(stream_filter);
}
コード例 #27
0
ファイル: rnd.c プロジェクト: onlyindreams/dbt1
long
tpc_random(long lower, long upper, long stream)
{
	long res;

	if (upper < 0 || lower < 0 || upper < lower)
		{
		INTERNAL_ERROR("invalid RNG range");
		}
	res = UnifInt((long)lower, (long)upper, (long)stream);
	Seed[stream].usage += 1;

	return(res);
}
コード例 #28
0
ファイル: cspell.c プロジェクト: HumbleRepose/dcerpc
/*
 * s p e l l _ i d l _ s c a l a r _ t y p e _ n a m e
 */
static void spell_idl_scalar_type_name
(
 FILE *fid,
 AST_type_n_t *tp
)
{

	fprintf(fid, "idl_");

	if (CSPELL_scalar_type_suffix(fid, tp))
		fprintf(fid, " ");
	else
		INTERNAL_ERROR("Invalid type kind");
}
コード例 #29
0
/*static*/
iFCOProp::CmpResult DefaultCompare(const TYPE* lhs, const iFCOProp* rhs, iFCOProp::Op op)
{
    // compares with undefined props are not equal
    if (rhs->GetType() == cFCOUndefinedProp::GetInstance()->GetType())
    {
        return (op == iFCOProp::OP_EQ) ? iFCOProp::CMP_FALSE : 
               (op == iFCOProp::OP_NE) ? iFCOProp::CMP_TRUE :  
               iFCOProp::CMP_WRONG_PROP_TYPE;
    }

    // first, make sure we are the right type...
    if(rhs->GetType() != lhs->GetType())
    {
        return iFCOProp::CMP_WRONG_PROP_TYPE;
    }

    // do the down cast
    const TYPE* newRhs = static_cast<const TYPE*>(rhs);
    ASSERT(newRhs != 0);

    // finally, do the comparison...
    bool bResult;
    switch(op)
    {
    case iFCOProp::OP_EQ:
        bResult = (lhs->GetValue() == newRhs->GetValue());
        break;
    case iFCOProp::OP_NE:
        bResult = (lhs->GetValue() != newRhs->GetValue());
        break;
    case iFCOProp::OP_GT:
        bResult = (lhs->GetValue() > newRhs->GetValue());
        break;
    case iFCOProp::OP_LT:
        bResult = (lhs->GetValue() < newRhs->GetValue());
        break;
    case iFCOProp::OP_GE:
        bResult = (lhs->GetValue() >= newRhs->GetValue());
        break;
    case iFCOProp::OP_LE:
        bResult = (lhs->GetValue() <= newRhs->GetValue());
        break;
    default:
        // we have exhausted all the possibilities
        ASSERT(false);
        throw INTERNAL_ERROR("fcopropimpl.cpp");
    }

    return bResult? iFCOProp::CMP_TRUE : iFCOProp::CMP_FALSE;
}
コード例 #30
0
ファイル: cspell.c プロジェクト: HumbleRepose/dcerpc
static void CSPELL_add_func_to_tail
(
 type_tail_t *tail,
 AST_parameter_n_t *pl,
 boolean function_def
)
{
	int i;

	i = (tail->len) ++;
	if (tail->len > MAX_TAIL_LEN) INTERNAL_ERROR("Data structure too compilicated; Tail array overflow");
	(tail->vec)[i].kind = f_k;
	(tail->vec)[i].content.function_info.param_list = pl;
	(tail->vec)[i].content.function_info.function_def = function_def;
}