コード例 #1
0
ファイル: hash_table.c プロジェクト: lobachevzky/95
/*
 * this function allows the user to double the # of buckets at run time
 * -returns pointer to the hash_table - or NULL if error
 */
hash_table* double_table_size (hash_table* table, int num_of_buckets)
{

  /* allocate memory for a new hash table - double the size */

  /* students may use "realloc()" if they understand it properly! - not required */
    hash_table* new_table = create_hash_table(num_of_buckets * 2);
    if (new_table) {
    
        int i;
        for (i=0; i<table->num_of_buckets; i++) {
            while (table->table[i]) {
                char * name = table->table[i]->value;
                add_to_table(new_table, name);
                delete_from_table(table, name);
            }
        }
        delete_table(table);
        return new_table;
    } else {
        return NULL;
    }

  /* move data from old hash table to new hash table - if necessary */

  /* don't forget to free old hash table memory before returning */

}
コード例 #2
0
static void add_trait_table(lua_State *L, Girl *girl, int table)
{
/*
 *	push the string "traits" onto the stack - this is going to be the key
 *	when we add the trait table
 */
	lua_pushstring(L, "traits");
/*
 *	now we need a new empty table on the stack
 */
 	lua_newtable(L);
	int trait_table = lua_gettop(L);
/*
 *	now loop over the trait list
 */
	for(unsigned int i = 0; i < girl->m_NumTraits; i++) {
		sTrait *trait = girl->m_Traits[i];
/*
 *		store the description keyed under the trait name
 */
		add_to_table(L, trait_table, trait->m_Name, trait->m_Desc);
	}
/*
 *	and now add the trait table to the girl table
 */
 	lua_settable(L, table);
}
コード例 #3
0
ファイル: assembler.c プロジェクト: plee831/mips_assembler
/* First pass of the assembler. You should implement pass_two() first.

   This function should read each line, strip all comments, scan for labels,
   and pass instructions to write_pass_one(). The input file may or may not
   be valid. Here are some guidelines:

    1. Only one label may be present per line. It must be the first token present.
        Once you see a label, regardless of whether it is a valid label or invalid
        label, treat the NEXT token as the beginning of an instruction.
    2. If the first token is not a label, treat it as the name of an instruction.
    3. Everything after the instruction name should be treated as arguments to
        that instruction. If there are more than MAX_ARGS arguments, call
        raise_extra_arg_error() and pass in the first extra argument. Do not 
        write that instruction to the output file (eg. don't call write_pass_one())
    4. Only one instruction should be present per line. You do not need to do 
        anything extra to detect this - it should be handled by guideline 3. 
    5. A line containing only a label is valid. The address of the label should
        be the byte offset of the next instruction, regardless of whether there
        is a next instruction or not.

   Just like in pass_two(), if the function encounters an error it should NOT
   exit, but process the entire file and return -1. If no errors were encountered, 
   it should return 0.
 */
int pass_one(FILE* input, FILE* output, SymbolTable* symtbl) {
    //my own: setting the buffer and putting the input into it
    char buf[BUF_SIZE];
    fgets(buf, BUF_SIZE, input);

    //my own: lines start at 1, and the byte offset at 0
    uint32_t byte_offset = 0;
    int line_number = 1;

    //my own: tokenize by lines first
    strtok(buf, "\n");
    while (strcmp(buf, "") == 0) {
	line_number++;
	strtok(buf, "\n");
    }
    int errored = 0;
    while (buf != NULL) {
	skip_comment(buf); //myown: gets rid of comments for every line
	//my own: tokenize now by the args in each line
	char* args[50];
	int num_args = 0;
	//my own: set it to 50, because... whos stupid enough to put in 50 args in MIPS... only idiots
	//my own: just have to do this because if the num_args > args size, GG. NO FIT.
	strtok(buf, " :,\n"); //myown: all the delimiters that could in MIPScode " :, and an new line"
	num_args = sizeof(args)/sizeof(args[0]);
	if (num_args > MAX_ARGS) {
	    raise_extra_arg_error(line_number, args[1]);
	    errored++;
	}
	int label1 = add_if_label(line_number, args[0], byte_offset, symtbl);
	int label2 = add_if_label(line_number, args[1], byte_offset, symtbl);
	if (label1 == -1) {
	    errored++;
	    line_number++;
	    strtok(buf, "\n");
	} else if (label2 == 1) {
	    raise_extra_arg_error(line_number, args[1]);
	    errored++;
	    line_number++;
	    strtok(buf, "\n");
	} else if (label1 == 0) { //Myown:It's not a label. Treat like a reg instruction
	    //Myown: pass in instructions into write_pass_one
	    write_pass_one(output, args[0], args, num_args);
	    byte_offset += 4;
	} else if (label1 == 1) {
	    //My own: Adding label to the symbol table
	    add_to_table(symtbl, args[0], byte_offset);
	    byte_offset += 4;
	}
	line_number++;
	strtok(buf, "\n");
    }
    if (errored > 0) {
	return -1;
    } else {
	return 0;
    }
}
コード例 #4
0
/*
 * really this needs a LuaGirl class and a lot more thought
 * for now, this is enough to add the girl to the current brothel
 */
static void make_lua_girl(lua_State *L, Girl *girl)
{
	const char *pt;
/*
 *	If girl is null, push a nil on the stack and return
 *	that way we null out any pre-existing girl to show that
 *	there is no target girl for the current event
 */
	if(girl == nullptr) {
		lua_pushnil(L);
		return;
	}
/*
 *	OK, we don't get off that easy. We need an empty table, then.
 */
 	lua_newtable(L);
	int table = lua_gettop(L);
/*
 *	let's add the girl's name and so forth
 */
 	add_to_table(L, table, "name", girl->m_Name);
 	add_to_table(L, table, "real_name", girl->m_Realname);
 	add_to_table(L, table, "desc", girl->m_Desc);
/*
 *	let's add the Girl pointer as light userdata
 */
 	add_to_table(L, table, "pointer", (void *)girl);
/*
 *	let's add the stats in, keyed by stat name in lower case
 */
	for(unsigned int i = 0; (pt = stats[i]); i++) {
		int val = girl->get_stat(i);
/*
 *		push the key, then they value
 */
		add_to_table(L, table, pt, val);
	}
/*
 *	same for skills
 */
	for(unsigned int i = 0; (pt = skills[i]); i++) {
		int val = girl->get_skill(i);
/*
 *		push the key, then they value
 */
		add_to_table(L, table, pt, val);
	}
/*
 *	add a subtable called traits containing the girl's traits
 */
	add_trait_table(L, girl, table);
/*
 *	add an update function
 */
	add_to_table(L, table, "update", update_girl);
/*
 *	and return leaving the new table on the stack
 */
 	return;
}
コード例 #5
0
ファイル: ffi_offset_table.c プロジェクト: forflo/zshffi
int gentbl(struct ffi_instruction_obj *ops, struct offset_table **table){
    struct offset_table *result;
    struct offset_table *temp;
    struct offset_table *temp2;
    struct offset_stack *ostack;
    struct ffi_instruction cur;
    int i;

    if (table_init(&result) != 0)
        return 1;

    if(stack_init(&ostack) != 0)
        return 1;

    table_init(&temp);
    push(temp, ostack);
    
    for (i=0; i<ops->instruction_count; cur = ops->instructions[i++]){
        switch (cur.operation){
            case START_STRUCT_PTR:
#ifdef DEBUG
                printf("gentbl(): PTR\n");
#endif
                table_init(&temp);
                push(temp, ostack);
                break;
            case END_STRUCT_PTR:
#ifdef DEBUG
                printf("gentbl(): END-STRUPTR\n");
#endif
                pop(&temp, ostack);
                top(&temp2, ostack);
                add_to_table_otable(temp, temp2);
                break;

            case MEMBER:
#ifdef DEBUG
                printf("gentbl(): MMEMBER\n");
#endif
                top(&temp2, ostack);
                add_to_table(&cur, temp2);
                break;
            case MEMBER_PTR:
#ifdef DEBUG
                printf("gentbl(): MEMBER-PTR\n");
#endif
                top(&temp2, ostack);
                add_to_table_sptr(temp2, &cur);
                break;
        }
    }

    top(&result, ostack);
    *table = result;

    return 0;
}
コード例 #6
0
ファイル: sokoban.c プロジェクト: Anatolt/RosettaCodeData
bool queue_move(state_t *s)
{
	if (!s || !add_to_table(s))
		return false;

	if (success(s)) {
		puts("\nSuccess!");
		done = s;
		return true;
	}

	s->qnext = next_level;
	next_level = s;
	return false;
}
コード例 #7
0
ファイル: pre.c プロジェクト: tiwanari/pro_exce
void make_indices(DOC *head)
{
    DOC *p;
    char *body;
    char *word;
    
    for (p = head->next; p != NULL; p = p->next)
    {
        body = (char *)malloc(sizeof(p->body));
        strcpy(body, p->body);
        
        word = strtok(body, " ");
        while (word != NULL)
        {
            add_to_table(head, word);
            word = strtok(NULL, " ");
        }
    }
}
コード例 #8
0
ファイル: assembler.c プロジェクト: harshmujoo/proj2
/* Reads STR and determines whether it is a label (ends in ':'), and if so,
   whether it is a valid label, and then tries to add it to the symbol table.

   INPUT_LINE is which line of the input file we are currently processing. Note
   that the first line is line 1 and that empty lines are included in this count.

   BYTE_OFFSET is the offset of the NEXT instruction (should it exist). 

   Four scenarios can happen:
    1. STR is not a label (does not end in ':'). Returns 0.
    2. STR ends in ':', but is not a valid label. Returns -1.
    3a. STR ends in ':' and is a valid label. Addition to symbol table fails.
        Returns -1.
    3b. STR ends in ':' and is a valid label. Addition to symbol table succeeds.
        Returns 1.
 */
static int add_if_label(uint32_t input_line, char* str, uint32_t byte_offset,
    SymbolTable* symtbl) {
    
    size_t len = strlen(str);
    if (str[len - 1] == ':') {
        str[len - 1] = '\0';
        if (is_valid_label(str)) {
            if (add_to_table(symtbl, str, byte_offset) == 0) {
                return 1;
            } else {
                return -1;
            }
        } else {
            raise_label_error(input_line, str);
            return -1;
        }
    } else {
        return 0;
    }
}
コード例 #9
0
ファイル: code_gen_new.c プロジェクト: sanketh95/compilers
char    *factor(void)
{
    char *tempvar=NULL;
    char *temp;
    if( match(ID) )
    {
	/* Print the assignment instruction. The %0.*s conversion is a form of
	 * %X.Ys, where X is the field width and Y is the maximum number of
	 * characters that will be printed (even if the string is longer). I'm
	 * using the %0.*s to print the string because it's not \0 terminated.
	 * The field has a default width of 0, but it will grow the size needed
	 * to print the string. The ".*" tells printf() to take the maximum-
	 * number-of-characters count from the next argument (yyleng).
	 */
        //printf("MOV %0.*s, %s\n",  yyleng, yytext ,tempvar=newname());
        fprintf(f,"MOVB %0.*s, %s \n",  yyleng, yytext ,tempvar=newname());
        temp = current_lexeme();
        add_to_table(temp);
        free(temp);
        advance();
    }
    else if (match(NUM)){
    	//printf("MOV $%0.*s, %s\n",  yyleng, yytext ,tempvar=newname());
        fprintf(f,"MOVB $%0.*s, %s\n",  yyleng, yytext ,tempvar=newname());
        advance();
    }
    else if( match(LP) )
    {
        advance();
        tempvar = expression();
        if( match(RP) )
            advance();
        else
            fprintf(stderr, "%d: Mismatched parenthesis\n", yylineno );
    }
    else
	fprintf( stderr, "%d: Number or identifier expected\n", yylineno );

    return tempvar;
}
コード例 #10
0
ファイル: tables.c プロジェクト: rstallman/sdust
int main()
{
     
     SymbolTable* tb1 = create_table(SYMTBL_UNIQUE_NAME);
     SymbolTable* tb2 = create_table(SYMTBL_UNIQUE_NAME);

     
     add_to_table(tb1, "Loop1", 0x400000);
     add_to_table(tb1, "Loop2", 0xF00000);
     add_to_table(tb1, "Loop3", 0xFF0000);
     add_to_table(tb1, "Loop4", 0xEF0000);
     add_to_table(tb1, "Done:", 0xEE0000);

     char str[255];
     strcpy(str, "Label0");
     
     for(int i = 0; i < 100; i++) {
	  str[5] = i;
	  add_to_table(tb1, str, 0xEFFF00);
	  add_to_table(tb2, str, 0xFFFFFF00);
     }
     
     write_table(tb1, stdout);
     
     int64_t res = get_addr_for_symbol(tb1, "Done:");

     if(res != -1) {
	  printf("Find symbol: addr: %lld\n", res);
     }
     else {
	  printf("No symbol in Table\n");	  
     }
     
     
     free_table(tb1);
     free_table(tb2);
     
     return 0;
}
コード例 #11
0
/*
 * sort out the player data
 */
static void make_lua_player(lua_State *L, cPlayer *player)
{
	const char *pt;
/*
 *	We need an empty table.
 */
 	lua_newtable(L);
	int table = lua_gettop(L);
/*
 *	let's add the girl's name and so forth
 */
 	add_to_table(L, table, "win_flag", player->m_WinGame);
 	add_to_table(L, table, "suspicion", player->suspicion());
 	add_to_table(L, table, "disposition", player->disposition());
 	add_to_table(L, table, "customer_fear", player->customerfear());
/*
 *	let's add the stats in, keyed by stat name in lower case
 */
	for(unsigned int i = 0; (pt = stats[i]); i++) {
		int val = player->m_Stats[i];
/*
 *		push the key, then they value
 */
		add_to_table(L, table, pt, val);
	}
/*
 *	same for skills
 */
	for(unsigned int i = 0; (pt = skills[i]); i++) {
		int val = player->m_Skills[i];
/*
 *		push the key, then they value
 */
		add_to_table(L, table, pt, val);
	}
 	return;
}
コード例 #12
0
ファイル: fdt_generic.c プロジェクト: Biamp-Systems/mb-qemu
void add_to_inst_bind_table(FDTInitFn fdt_init, const char *name, void *opaque)
{
    add_to_table(fdt_init, name, opaque, &inst_bind_list_head);
}
コード例 #13
0
ファイル: code_gen_new.c プロジェクト: sanketh95/compilers
statement()
{

    /*  statement -> expression SEMI
     *             |  expression SEMI statement
     */

/*
    expression();

    if( match( SEMI ) )
	advance();
    else
        fprintf( stderr, "%d: Inserting missing semicolon\n", yylineno );

    if( !match(EOI) )   
        statements();			// Do another statement.

*/
    if(match(ID)){
    	char *var1 = current_lexeme(), *var2;
        add_to_table(var1);
        advance();
        if(match(ASSIGN)){  
            advance();
            var2 = expression();
            if(!var2){
            	printf("%d: Expression expected\n", yylineno);
            	return;
            }
            //printf("%s = %s \n", var1,var2);
            //printf("MOV %s,%s\n", var2,var1);
            fprintf(f,"MOVB %s,%s\n", var2,var1);


            freename(var2);
            free(var1);	
        }
        else
            fprintf(stderr, "%d: Not a valid assignment\n",yylineno);
        
    }

    else if(match(IF)){
    	char *var1;
    	if_count++;
    	int temp_if_count = if_count;
        advance();
        var1 = expression();
        if(!var1){
        	fprintf(stderr, "%d: Invalid Expression\n",yylineno);
        	return;
        }
        //printf("CMP %s, $0\n",var1 );
        //printf("JLE Else%d\n",if_count);
        fprintf(f, "MOVB $0, %s \n", ACCUMULATOR);
        fprintf(f,"CMP %s, %s \n",ACCUMULATOR,var1);
        fprintf(f,"JLE Else%d\n",temp_if_count);
        if(match(THEN)){
        	//printf("if(%s){\n", var1);
        	
        	
        	freename(var1);

            advance();
            statement();
            //printf("Else%d:\n",if_count);
            fprintf(f,"Else%d:\n",temp_if_count);
            //printf("}\n");
        }
        else
            fprintf(stderr, "%d: Then expected after if\n", yylineno);
        
    }
    else if(match(WHILE)){
    	char *var;
    	while_count++;
    	int temp_while_count = while_count;
        advance();
        var = expression();
        if(!var){
        	fprintf(stderr, "%d: Invalid Expression\n",yylineno);
        	return;
        }
       // printf("While%d:\n",while_count);
       // printf("CMP %s, $0\n", var);
       // printf("JLE Exit%d\n", while_count);

        fprintf(f, "MOVB $0, %s \n", ACCUMULATOR);
        fprintf(f,"While%d:\n",temp_while_count);
        fprintf(f,"CMP %s, %s\n", ACCUMULATOR,var);
        fprintf(f,"JLE Exit%d\n", temp_while_count);

        if(match(DO)){
        	//printf("while\t(%s)\n", var);
        	//printf("do{\n");

            advance();
            statement();
            //printf("}\n");
            freename(var);
           // printf("JMP While%d\n",while_count);
           // printf("Exit%d:\n",while_count);
            fprintf(f,"JMP While%d\n",temp_while_count);
            fprintf(f,"Exit%d:\n",temp_while_count);
        }
        else
            fprintf(stderr, "%d: Do expected after while\n", yylineno);
    }

    else if(match(BEGIN)){
    	printf("begin\n");
        advance();
        opt_statements();
        if(match(END)){
            printf("end\n");
            advance();
        }
        else 
            fprintf(stderr, "%d End expected begin\n", yylineno);
    }
    
    else if(match(EOI)){
    //	printf("thu\n");
    	return;
    }

    else{
    	fprintf(stderr, "%d: Statement Expected\n", yylineno);
    	exit(1);
    }
    

}
コード例 #14
0
ファイル: fdt_generic.c プロジェクト: Biamp-Systems/mb-qemu
void add_to_compat_table(FDTInitFn fdt_init, const char *compat, void *opaque)
{
    add_to_table(fdt_init, compat, opaque, &compat_list_head);
}
コード例 #15
0
void pressed_preferences( GtkMenuItem *menu_item, gpointer user_data )
{
	int i;
#ifdef U_NLS
	int j;
	GSList *radio_group;
#endif


	GtkWidget *vbox3, *hbox4, *table3, *table4, *table5, *drawingarea_tablet, *frame;
	GtkWidget *button1, *button2, *notebook1, *vbox_1, *vbox_2, *vbox_3, *label;
	GtkAccelGroup* ag = gtk_accel_group_new();

	char *tab_tex[] = { _("Max memory used for undo (MB)"), _("Greyscale backdrop"),
		_("Selection nudge pixels"), _("Max Pan Window Size") };
	char *tab_tex2[] = { _("XPM/PNG transparency index"), _("XBM X hotspot"), _("XBM Y hotspot"),
		_("JPEG Save Quality (100=High)   "), _("Recently Used Files") };
	char *tab_tex3[] = { _("Minimum grid zoom"), _("Grid colour RGB") };
	char *stat_tex[] = { _("Colour A & B"), _("Canvas Geometry"), _("Cursor X,Y"),
		_("Pixel [I] {RGB}"), _("Zoom %"), _("Selection Geometry"), _("Continuous Mode"),
		_("Undo / Redo"), _("Opacity %"), _("Opacity Mode") },
		*tablet_txt[] = { _("Size"), _("Flow"), _("Opacity") };
	char txt[64];


	men_item_state( menu_prefs, FALSE );	// Make sure the user can only open 1 prefs window

	prefs_window = add_a_window( GTK_WINDOW_TOPLEVEL, _("Preferences"), GTK_WIN_POS_CENTER, FALSE );

	vbox3 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox3);
	gtk_container_add (GTK_CONTAINER (prefs_window), vbox3);

///	SETUP NOTEBOOK

	notebook1 = gtk_notebook_new ();
	gtk_box_pack_start (GTK_BOX (vbox3), notebook1, TRUE, TRUE, 0);
	gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook1), GTK_POS_TOP);
	gtk_widget_show (notebook1);

///	---- TAB1 - GENERAL

	vbox_1 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox_1);
	gtk_container_add (GTK_CONTAINER (notebook1), vbox_1);

	label = gtk_label_new( _("General") );
	gtk_widget_show (label);
	gtk_notebook_set_tab_label(GTK_NOTEBOOK (notebook1),
		gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 0), label);


	table3 = add_a_table( 3, 2, 10, vbox_1 );

///	TABLE TEXT
	for ( i=0; i<4; i++ ) add_to_table( tab_tex[i], table3, i, 0, 0, GTK_JUSTIFY_LEFT, 0, 0.5 );

///	TABLE SPINBUTTONS
	spin_to_table( table3, &spinbutton_maxmem, 0, 1, 5, inifile_get_gint32("undoMBlimit", 32 ), 1, 1000 );
	spin_to_table( table3, &spinbutton_greys, 1, 1, 5, inifile_get_gint32("backgroundGrey", 180 ), 0, 255 );
	spin_to_table( table3, &spinbutton_nudge, 2, 1, 5, inifile_get_gint32("pixelNudge", 8 ), 2, 512 );
	spin_to_table( table3, &spinbutton_pan, 3, 1, 5, inifile_get_gint32("panSize", 128 ), 64, 256 );

	checkbutton_paste = add_a_toggle( _("Display clipboard while pasting"),
		vbox_1, inifile_get_gboolean("pasteToggle", TRUE) );
	checkbutton_cursor = add_a_toggle( _("Mouse cursor = Tool"),
		vbox_1, inifile_get_gboolean("cursorToggle", TRUE) );
	checkbutton_exit = add_a_toggle( _("Confirm Exit"),
		vbox_1, inifile_get_gboolean("exitToggle", FALSE) );
	checkbutton_quit = add_a_toggle( _("Q key quits mtPaint"),
		vbox_1, inifile_get_gboolean("quitToggle", TRUE) );
	checkbutton_commit = add_a_toggle( _("Changing tool commits paste"),
		vbox_1, inifile_get_gboolean("pasteCommit", FALSE) );


///	---- TAB2 - FILES

	vbox_2 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox_2);
	gtk_container_add (GTK_CONTAINER (notebook1), vbox_2);

	label = gtk_label_new( _("Files") );
	gtk_widget_show (label);
	gtk_notebook_set_tab_label(GTK_NOTEBOOK (notebook1),
		gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 1), label);

	table4 = add_a_table( 5, 2, 10, vbox_2 );

	for ( i=0; i<5; i++ ) add_to_table( tab_tex2[i], table4, i, 0, 0, GTK_JUSTIFY_LEFT, 0, 0.5 );

	spin_to_table( table4, &spinbutton_trans, 0, 1, 5, mem_xpm_trans, -1, mem_cols-1 );
	spin_to_table( table4, &spinbutton_hotx, 1, 1, 5, mem_xbm_hot_x, -1, mem_width-1 );
	spin_to_table( table4, &spinbutton_hoty, 2, 1, 5, mem_xbm_hot_y, -1, mem_height-1 );
	spin_to_table( table4, &spinbutton_jpeg, 3, 1, 5, mem_jpeg_quality, 0, 100 );
	spin_to_table( table4, &spinbutton_recent, 4, 1, 5, recent_files, 0, MAX_RECENT );

	add_hseparator( vbox_2, -2, 10 );
	label = gtk_label_new( _("Clipboard Files") );
	gtk_widget_show( label );
	gtk_box_pack_start( GTK_BOX(vbox_2), label, FALSE, FALSE, 0 );

	clipboard_entry = gtk_entry_new();
	gtk_widget_show( clipboard_entry );
	gtk_box_pack_start( GTK_BOX(vbox_2), clipboard_entry, FALSE, FALSE, 0 );
	gtk_entry_set_text( GTK_ENTRY(clipboard_entry), mem_clip_file[0] );
	strncpy( mem_clip_file[1], mem_clip_file[0], 250 );

	button1 = add_a_button( _("Browse"), 4, vbox_2, FALSE );
	gtk_signal_connect(GTK_OBJECT(button1), "clicked",
		GTK_SIGNAL_FUNC(clip_file_browse), NULL);

///	---- TAB3 - STATUS BAR

	hbox4 = gtk_hbox_new (FALSE, 0);
	gtk_widget_show (hbox4);
	gtk_container_add (GTK_CONTAINER (notebook1), hbox4);

	vbox_3 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox_3);
	gtk_box_pack_start (GTK_BOX (hbox4), vbox_3, FALSE, FALSE, 0);

	label = gtk_label_new( _("Status Bar") );
	gtk_widget_show (label);
	gtk_notebook_set_tab_label(GTK_NOTEBOOK (notebook1),
		gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 2), label);

	for ( i=0; i<STATUS_ITEMS; i++ )
	{
		if (i==5)
		{
			vbox_3 = gtk_vbox_new (FALSE, 0);
			gtk_widget_show (vbox_3);
			gtk_box_pack_start (GTK_BOX (hbox4), vbox_3, FALSE, FALSE, 0);
		}
		sprintf(txt, "status%iToggle", i);
		prefs_status[i] = add_a_toggle( stat_tex[i], vbox_3, inifile_get_gboolean(txt, TRUE) );
	}

///	---- TAB4 - ZOOM

	hbox4 = gtk_hbox_new (FALSE, 0);
	gtk_widget_show (hbox4);
	gtk_container_add (GTK_CONTAINER (notebook1), hbox4);

	vbox_3 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox_3);
	gtk_box_pack_start (GTK_BOX (hbox4), vbox_3, FALSE, FALSE, 0);

	label = gtk_label_new( _("Zoom") );
	gtk_widget_show (label);
	gtk_notebook_set_tab_label(GTK_NOTEBOOK (notebook1),
		gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 3), label);
	table5 = add_a_table( 2, 4, 10, vbox_3 );

///	TABLE TEXT
	for ( i=0; i<2; i++ ) add_to_table( tab_tex3[i], table5, i, 0, 0, GTK_JUSTIFY_LEFT, 0, 0.5 );

///	TABLE SPINBUTTONS
	spin_to_table( table5, &spinbutton_grid[0], 0, 1, 5, mem_grid_min, 2, 12 );
	spin_to_table( table5, &spinbutton_grid[1], 1, 1, 5, mem_grid_rgb[0], 0, 255 );
	spin_to_table( table5, &spinbutton_grid[2], 1, 2, 5, mem_grid_rgb[1], 0, 255 );
	spin_to_table( table5, &spinbutton_grid[3], 1, 3, 5, mem_grid_rgb[2], 0, 255 );

	checkbutton_zoom = add_a_toggle( _("New image sets zoom to 100%"),
		vbox_3, inifile_get_gboolean("zoomToggle", FALSE) );
#if GTK_MAJOR_VERSION == 2
	checkbutton_wheel = add_a_toggle( _("Mouse Scroll Wheel = Zoom"),
		vbox_3, inifile_get_gboolean("scrollwheelZOOM", TRUE) );
#endif



///	---- TAB5 - TABLET

	hbox4 = gtk_hbox_new (FALSE, 0);
	gtk_widget_show (hbox4);
	gtk_container_add (GTK_CONTAINER (notebook1), hbox4);

	vbox_3 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox_3);
	gtk_box_pack_start (GTK_BOX (hbox4), vbox_3, FALSE, FALSE, 0);

	label = gtk_label_new( _("Tablet") );
	gtk_widget_show (label);
	gtk_notebook_set_tab_label(GTK_NOTEBOOK (notebook1),
		gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 4), label);



	frame = gtk_frame_new (_("Device Settings"));
	gtk_widget_show (frame);
	gtk_box_pack_start (GTK_BOX (vbox_3), frame, FALSE, FALSE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (frame), 5);

	vbox_2 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox_2);
	gtk_container_add (GTK_CONTAINER (frame), vbox_2);
	gtk_container_set_border_width (GTK_CONTAINER (vbox_2), 5);

	label_tablet_device = gtk_label_new ("");
	gtk_widget_show (label_tablet_device);
	gtk_box_pack_start (GTK_BOX (vbox_2), label_tablet_device, FALSE, FALSE, 0);
	gtk_misc_set_alignment (GTK_MISC (label_tablet_device), 0, 0.5);
	gtk_misc_set_padding (GTK_MISC (label_tablet_device), 5, 5);

	button1 = add_a_button( _("Configure Device"), 0, vbox_2, FALSE );
	gtk_signal_connect(GTK_OBJECT(button1), "clicked", GTK_SIGNAL_FUNC(conf_tablet), NULL);

	table3 = gtk_table_new (4, 2, FALSE);
	gtk_widget_show (table3);
	gtk_box_pack_start (GTK_BOX (vbox_2), table3, TRUE, TRUE, 0);

	label = add_to_table( _("Tool Variable"), table3, 0, 0, 0, 0, 0, 0 );
	gtk_misc_set_padding (GTK_MISC (label), 5, 5);
	label = add_to_table( _("Factor"), table3, 0, 1, 0, 0, 0, 0 );
	gtk_misc_set_padding (GTK_MISC (label), 5, 5);
	gtk_misc_set_alignment (GTK_MISC (label), 0.4, 0.5);

	for ( i=0; i<3; i++ )
	{
		check_tablet[i] = gtk_check_button_new_with_label (tablet_txt[i]);
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_tablet[i]),
			tablet_tool_use[i] );
		gtk_widget_show (check_tablet[i]);
		gtk_table_attach (GTK_TABLE (table3), check_tablet[i], 0, 1, i+1, i+2,
			(GtkAttachOptions) (GTK_FILL),
			(GtkAttachOptions) (0), 0, 0);

//	Size/Flow/Opacity sliders

		hscale_tablet[i] = add_slider2table( 0, -1, 1, table3, 1+i, 1, 200, -2 );
		gtk_adjustment_set_value( GTK_HSCALE(hscale_tablet[i])->scale.range.adjustment,
			tablet_tool_factor[i] );
		gtk_scale_set_value_pos (GTK_SCALE (hscale_tablet[i]), GTK_POS_RIGHT);
		gtk_scale_set_digits (GTK_SCALE (hscale_tablet[i]), 2);
		gtk_scale_set_draw_value (GTK_SCALE (hscale_tablet[i]), TRUE);
	}


	frame = gtk_frame_new (_("Test Area"));
	gtk_widget_show (frame);
	gtk_box_pack_start (GTK_BOX (vbox_3), frame, FALSE, FALSE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (frame), 5);

	vbox_2 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox_2);
	gtk_container_add (GTK_CONTAINER (frame), vbox_2);
	gtk_container_set_border_width (GTK_CONTAINER (vbox_2), 5);

	drawingarea_tablet = gtk_drawing_area_new ();
	gtk_widget_show (drawingarea_tablet);
	gtk_box_pack_start (GTK_BOX (vbox_2), drawingarea_tablet, TRUE, TRUE, 0);
	gtk_widget_set_usize (drawingarea_tablet, 128, 64);
	gtk_signal_connect( GTK_OBJECT(drawingarea_tablet), "expose_event",
		GTK_SIGNAL_FUNC (expose_tablet_preview), (gpointer) drawingarea_tablet );

	gtk_signal_connect (GTK_OBJECT (drawingarea_tablet), "motion_notify_event",
		GTK_SIGNAL_FUNC (tablet_preview_motion), NULL);
	gtk_signal_connect (GTK_OBJECT (drawingarea_tablet), "button_press_event",
		GTK_SIGNAL_FUNC (tablet_preview_button), NULL);

	gtk_widget_set_events (drawingarea_tablet, GDK_EXPOSURE_MASK
		| GDK_LEAVE_NOTIFY_MASK
		| GDK_BUTTON_PRESS_MASK
		| GDK_POINTER_MOTION_MASK
		| GDK_POINTER_MOTION_HINT_MASK);

	gtk_widget_set_extension_events (drawingarea_tablet, GDK_EXTENSION_EVENTS_CURSOR);



	label_tablet_pressure = gtk_label_new ("");
	gtk_widget_show (label_tablet_pressure);
	gtk_box_pack_start (GTK_BOX (vbox_2), label_tablet_pressure, FALSE, FALSE, 0);
	gtk_misc_set_alignment (GTK_MISC (label_tablet_pressure), 0, 0.5);



///	---- TAB6 - LANGUAGE

#ifdef U_NLS

	pref_lang_ini[1] = _("Default System Language");
	pref_lang_ini[3] = _("Czech");
	pref_lang_ini[5] = _("English (UK)");
	pref_lang_ini[7] = _("French");
	pref_lang_ini[9] = _("Portuguese");
	pref_lang_ini[11] = _("Portuguese (Brazilian)");
	pref_lang_ini[13] = _("Spanish");

	vbox_2 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox_2);
	gtk_container_add (GTK_CONTAINER (notebook1), vbox_2);
	gtk_container_set_border_width( GTK_CONTAINER(vbox_2), 10 );

	label = gtk_label_new( _("Language") );
	gtk_widget_show (label);
	gtk_notebook_set_tab_label(GTK_NOTEBOOK (notebook1),
		gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 5), label);

	add_hseparator( vbox_2, 200, 10 );
	label = gtk_label_new( _("Select preferred language translation\n\n"
				"You will need to restart mtPaint\nfor this to take full effect") );
	pref_lang_label = label;
	gtk_widget_show (label);
	gtk_box_pack_start( GTK_BOX(vbox_2), label, FALSE, FALSE, 0 );
	add_hseparator( vbox_2, 200, 10 );

	pref_lang_radio[0] = add_radio_button( pref_lang_ini[1], NULL,  NULL, vbox_2, 0 );
	radio_group = gtk_radio_button_group( GTK_RADIO_BUTTON(pref_lang_radio[0]) );
	pref_lang_radio[1] = add_radio_button( pref_lang_ini[3], radio_group, NULL, vbox_2, 1 );
	for ( i=2; i<PREF_LANGS; i++ )
		pref_lang_radio[i] = add_radio_button(
					pref_lang_ini[i*2+1], NULL, pref_lang_radio[1], vbox_2, i );

	for ( i=0; i<PREF_LANGS; i++ )
		gtk_container_set_border_width( GTK_CONTAINER(pref_lang_radio[i]), 5 );

	j = 0;
	for ( i = PREF_LANGS - 1; i>0; i-- )
	{
		if ( strcmp( pref_lang_ini[i*2], inifile_get( "languageSETTING", "system" ) ) == 0 )
			j = i;
	}
	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(pref_lang_radio[j]), TRUE );

#endif



///	Bottom of Prefs window

	hbox4 = gtk_hbox_new (FALSE, 0);
	gtk_widget_show (hbox4);
	gtk_box_pack_start (GTK_BOX (vbox3), hbox4, FALSE, FALSE, 0);

	button1 = add_a_button(_("Cancel"), 5, hbox4, TRUE);
	gtk_signal_connect(GTK_OBJECT(button1), "clicked", GTK_SIGNAL_FUNC(delete_prefs), NULL);
	gtk_widget_add_accelerator (button1, "clicked", ag, GDK_Escape, 0, (GtkAccelFlags) 0);

	button1 = add_a_button(_("Apply"), 5, hbox4, TRUE);
	gtk_signal_connect(GTK_OBJECT(button1), "clicked", GTK_SIGNAL_FUNC(prefs_apply), NULL);

	button2 = add_a_button(_("OK"), 5, hbox4, TRUE);
	gtk_signal_connect(GTK_OBJECT(button2), "clicked", GTK_SIGNAL_FUNC(prefs_ok), NULL);
	gtk_widget_add_accelerator (button2, "clicked", ag, GDK_Return, 0, (GtkAccelFlags) 0);
	gtk_widget_add_accelerator (button2, "clicked", ag, GDK_KP_Enter, 0, (GtkAccelFlags) 0);


	gtk_signal_connect_object (GTK_OBJECT (prefs_window), "delete_event",
		GTK_SIGNAL_FUNC (delete_prefs), NULL);

	gtk_window_set_transient_for( GTK_WINDOW(prefs_window), GTK_WINDOW(main_window) );
	gtk_widget_show (prefs_window);
	gtk_window_add_accel_group(GTK_WINDOW (prefs_window), ag);

	if ( tablet_working )
	{
		tablet_update_device( tablet_device->name );
	} else	tablet_update_device( "NONE" );
}
コード例 #16
0
ファイル: shifter.c プロジェクト: UIKit0/mtPaint
void pressed_shifter()
{
	GtkWidget *vbox, *hbox, *table, *button, *label;
	GtkAccelGroup* ag = gtk_accel_group_new();
	int i, j, max;
	char txt[32];


	shifter_window = add_a_window(GTK_WINDOW_TOPLEVEL, _("Palette Shifter"),
		GTK_WIN_POS_CENTER, TRUE);
	vbox = add_vbox(shifter_window);
	gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);

	table = add_a_table(9, 4, 5, vbox);

	label = add_to_table( _("Start"),  table, 0, 1, 1 );
	gtk_misc_set_alignment( GTK_MISC(label), 0.5, 0.5 );
	label = add_to_table( _("Finish"), table, 0, 2, 1 );
	gtk_misc_set_alignment( GTK_MISC(label), 0.5, 0.5 );
	label = add_to_table( _("Delay"),  table, 0, 3, 1 );
	gtk_misc_set_alignment( GTK_MISC(label), 0.5, 0.5 );

	for ( i=0; i<8; i++ )
	{
		sprintf(txt, "%i", i);
		add_to_table( txt, table, i+1, 0, 5 );

		for ( j=0; j<3; j++ )
		{
			if ( j==2 ) max=255; else max=mem_cols-1;
			shifter_spin[i][j] = spin_to_table( table, i+1, j+1, 2,
						shifter_in[i][j], 0, max );
			spin_connect(shifter_spin[i][j],
				GTK_SIGNAL_FUNC(shifter_moved), NULL);
		}
	}


	hbox = pack(vbox, gtk_hbox_new(FALSE, 0));
	gtk_widget_show (hbox);

	button = pack(hbox, sig_toggle_button(_("Play"), FALSE, NULL,
		GTK_SIGNAL_FUNC(shift_but_playstop)));
	shift_play_state = FALSE;			// Stopped

	shifter_label = xpack(hbox, gtk_label_new(""));
	gtk_widget_show( shifter_label );
	gtk_misc_set_alignment( GTK_MISC(shifter_label), 0.5, 0.5 );


	shifter_slider = xpack5(vbox, mt_spinslide_new(-1, -1));
	mt_spinslide_set_range(shifter_slider, 0, 0);
	mt_spinslide_set_value(shifter_slider, 0);
	mt_spinslide_connect(shifter_slider, GTK_SIGNAL_FUNC(shifter_slider_moved), NULL);


	add_hseparator( vbox, -2, 10 );

	hbox = pack(vbox, gtk_hbox_new(FALSE, 0));
	gtk_widget_show (hbox);

	button = xpack5(hbox, gtk_button_new_with_label(_("Clear")));
	gtk_widget_show(button);
	gtk_signal_connect(GTK_OBJECT(button), "clicked",
		GTK_SIGNAL_FUNC(click_shift_clear), NULL);

	button = xpack5(hbox, gtk_button_new_with_label(_("Fix Palette")));
	gtk_widget_show(button);
	gtk_signal_connect(GTK_OBJECT(button), "clicked",
		GTK_SIGNAL_FUNC(click_shift_fix), NULL);

	button = xpack5(hbox, gtk_button_new_with_label(_("Create Frames")));
	gtk_widget_show(button);
	gtk_signal_connect(GTK_OBJECT(button), "clicked",
		GTK_SIGNAL_FUNC(click_shift_create), NULL);

	button = xpack5(hbox, gtk_button_new_with_label(_("Close")));
	gtk_widget_show(button);
	gtk_signal_connect(GTK_OBJECT(button), "clicked",
		GTK_SIGNAL_FUNC(click_shift_close), NULL );
	gtk_widget_add_accelerator (button, "clicked", ag, GDK_Escape, 0, (GtkAccelFlags) 0);
	delete_to_click(shifter_window, button);

	gtk_window_add_accel_group(GTK_WINDOW (shifter_window), ag);
// !!! Transient windows cannot be minimized; don't know if that's desirable here
//	gtk_window_set_transient_for(GTK_WINDOW(shifter_window), GTK_WINDOW(main_window));
	gtk_widget_show(shifter_window);

#if GTK_MAJOR_VERSION == 1
	gtk_widget_queue_resize(shifter_window); /* Re-render sliders */
#endif

	mem_pal_copy( sh_old_pal, mem_pal );			// Backup the current palette
	shifter_pos = 0;
	shifter_max = 0;
	shifter_moved();					// Initialize the input array
}
コード例 #17
0
ファイル: protobuf.c プロジェクト: maniacs-ops/protobuf
void add_def_obj(const void* def, zval* value) {
  Z_ADDREF_P(value);
  add_to_table(upb_def_to_php_obj_map, def, value);
}
コード例 #18
0
ファイル: mytest.c プロジェクト: timkchan/mipsAssemblerLinker
int main(int argc, char **argv) {

	freopen("null", "w", stderr); //Uncomment to show stderr.

//TEST translate_num
	char num[] = "0x6fffff";
	long int result = 0;
	int flag;

	//nornmal test.
	flag = translate_num(&result, num, 0, 999999999);
	assert(7340031 == result);
	assert(flag == 0);

	//out of bound.
	flag = translate_num(&result, num, 1, 2);
	assert(7340031 == result);
	assert(flag == -1);

	//invalid output pointer.
	flag = translate_num(NULL, num, 0, 999999999);
	assert(flag == -1);
	printf("PASSED: translate_num.\n");

//TEST add_to_table
	//uniqueTable:
	//tim1 4
	//tim2 8
	//tim3 12
	//tim4 16
	//tim5 20
	//tim6 24

	char* tim1 = "tim1";
	char* tim2 = "tim2";
	char* tim3 = "tim3";
	char* tim4 = "tim4";
	char* tim5 = "tim5";
	char* tim6 = "tim6";

	SymbolTable * uniqueTable = create_table(SYMTBL_UNIQUE_NAME);
	add_to_table(uniqueTable, tim1, 4);
	add_to_table(uniqueTable, tim2, 8);
	add_to_table(uniqueTable, tim3, 12);
	add_to_table(uniqueTable, tim4, 16);
	//normal.
	flag = add_to_table(uniqueTable, tim5, 20);
	assert(uniqueTable->len == 5);
	//name duplicate.
	flag = add_to_table(uniqueTable, tim5, 20);
	assert(flag == -1);
	//address not aligned.
	flag = add_to_table(uniqueTable, tim6, 1);
	assert(flag == -1);
	printf("2 expected errors are supressed above.\n");
	printf("Uncomment line 19 to see error msg.\n");

	flag = add_to_table(uniqueTable, tim6, 24);
	assert(uniqueTable->len == 6);
	assert(uniqueTable->cap == 10);

	//RUNNING valGrind here to expect a memory leak.
	//	./run-valgrind ./mytest
	printf("PASSED: add_to_table.\n");

//TEST free_table
	free_table(uniqueTable);
	//RUNNING valGrind here to expect the memory leak is fixed.
	//	./run-valgrind ./mytest
	printf("PASSED: free_table.\n");

//
	long int output;
	printf("%d\n", translate_num(&output, "35x", -100, 100));
	printf("%ld\n", output);

return 0;
}
コード例 #19
0
ファイル: fdt_generic.c プロジェクト: Biamp-Systems/mb-qemu
void add_to_force_table(FDTInitFn fdt_init, const char *name, void *opaque)
{
    add_to_table(fdt_init, name, opaque, &force_list_head);
}
コード例 #20
0
ファイル: protobuf.c プロジェクト: maniacs-ops/protobuf
void add_ce_obj(const void* ce, zval* value) {
  Z_ADDREF_P(value);
  add_to_table(ce_to_php_obj_map, ce, value);
}