Exemplo n.º 1
0
static void build_table(BiTreeNode *node, unsigned short code, unsigned char
   size, HuffCode *table) {

if (!bitree_is_eob(node)) {

   if (!bitree_is_eob(bitree_left(node))) {

      /***********************************************************************
      *                                                                      *
      *  Move to the left and append 0 to the current code.                  *
      *                                                                      *
      ***********************************************************************/

      build_table(bitree_left(node), code << 1, size + 1, table);

   }

   if (!bitree_is_eob(bitree_right(node))) {

      /***********************************************************************
      *                                                                      *
      *  Move to the right and append 1 to the current code.                 *
      *                                                                      *
      ***********************************************************************/

      build_table(bitree_right(node), (code << 1) | 0x0001, size + 1, table);

   }

   if (bitree_is_eob(bitree_left(node))&&bitree_is_eob(bitree_right(node))) {

      /***********************************************************************
      *                                                                      *
      *  Ensure that the current code is in big-endian format.               *
      *                                                                      *
      ***********************************************************************/

      code = htons(code);

      /***********************************************************************
      *                                                                      *
      *  Assign the current code to the symbol in the leaf node.             *
      *                                                                      *
      ***********************************************************************/

      table[((HuffNode *)bitree_data(node))->symbol].used = 1;
      table[((HuffNode *)bitree_data(node))->symbol].code = code;
      table[((HuffNode *)bitree_data(node))->symbol].size = size;

   }

}

return;

}
Exemplo n.º 2
0
static void initialize(void)
{
    int attr;

    attr = doublebuffer ? RGBA_DB_attributes : RGBA_SB_attributes;
    glutInitDisplayMode(attr);
    glutInitWindowSize(300, 240);
    glutCreateWindow("Ideas");

    if (multisample) glEnable(GL_POLYGON_SMOOTH); 
    
    init_lights();
    init_materials();

    build_table();

    view_from_spline = calc_spline_params(view_from_ctl, TIME);
    view_to_spline = calc_spline_params(view_to_ctl, TIME);
    light_pos_spline = calc_spline_params(light_pos_ctl, TIME);
    logo_pos_spline = calc_spline_params(logo_pos_ctl, TIME);
    logo_rot_spline = calc_spline_params(logo_rot_ctl, TIME);

    glutReshapeFunc(resize_window);
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutKeyboardFunc(keyboard);
    glutVisibilityFunc(vis);

    glMatrixMode(GL_MODELVIEW);
}
Exemplo n.º 3
0
/// Generates the truth table.
void MainWindow::generate()
{
    delete_columns();

    get_variables();

    FunctionParser p;
    switch(m_mode)
    {
    case Function:
        char func[128];
        Edit_GetText(m_hWndFunction, func, 128);

        try {
            p = FunctionParser(m_variables, func);
        } catch(FunctionParser::FunctionParserException& e) {
            MessageBox(e.what(), "Function Parser Error", MB_OK | MB_ICONERROR);
            return;
        }

        build_table(&p);
        break;
    case Minterm:
        break;
    case Maxterm:
        break;
    }
}
Exemplo n.º 4
0
/*
 * TODO: output the table (possibly merged), in the input format 
 */
int 
main (int argc, char* argv [])
{
	init_table ();
	if (argc == 2) {
		/* useful to get a new file when some opcodes are added: looses the comments, though */
		load_file (argv [1]);
		dump ();
	} else if (argc < 4) {
		g_print ("Usage: genmdesc arguments\n");
		g_print ("\tgenmdesc desc     Output to stdout the description file.\n");
		g_print ("\tgenmdesc [--nacl] output name desc [desc1...]\n"
			"                     Write to output the description in a table named 'name',\n"
			"                     use --nacl to generate Google NativeClient code\n");
		return 1;
	} else {
		int i = 3;
		if (strcmp (argv [1], "--nacl") == 0) {
			nacl = 1;
			i++;
		}
		
		for (; i < argc; ++i)
			load_file (argv [i]);
		
		build_table (argv [1 + nacl], argv [2 + nacl]);
	}
	return 0;
}
Exemplo n.º 5
0
int main()  
{
	char str[max]={'\0'};
	//printf("Enter the string :");
	strcat(str,"(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)");
	strcat(str,"(A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z)");
	strcat(str,"(1|2|3|4|5|6|7|8|9)");
	//strcat(str,"(!|@|#|$|%|^|&|&|*)");
	//strcat(str,"(A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z)");
	//gets(str);
	//printf("You entered :%s\n",input_str);
	int len=0,i=0;
	//compute length
	while(str[i]!='\0'){
		if(str[i]==')')
			len++;
		i++;
	}
	//printf("Number of sequences :%d\n",len);
	struct str_table table[len],*ptr;
	ptr=table;
	build_table(str,ptr);
	ptr=table;
	//print_str(ptr,len);
	ptr=table;
	build_combinations(ptr,len);
   return 0;
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
	int i;
	prog=argv[0];
	argv++;
	/*
	 *	Load user set keyvals
	 */
	while(argv[0] && strcmp(argv[0],"-p")==0)
	{
		int o,n;
		argv++;
		if(argv[0]==NULL || sscanf(argv[0], "%d=%d", &o, &n)!=2)
			usage();
		if(o < TABLE_SIZE)
			table[o]=n;
		argv++;
	}
	
	if(argv[0]==NULL)
		usage();
	load_map(&def,argv[1] ? argv[0] : NULL);
	load_map(&kbd,argv[1] ? argv[1] : argv[0]);
	
	build_table(map_names);
	for (i = 0; i < 256; i++) {
		printf("%c",table[i] ? table[i] : i);
	}
	return 0;
}
Exemplo n.º 7
0
void
populate_menu (charpick_data *curr_data)
{
	GList *list = curr_data->chartable;
	GSList *group = NULL;
	GtkMenu *menu;
	GtkWidget *menuitem;

	if (curr_data->menu)
		gtk_widget_destroy (curr_data->menu);

	curr_data->menu = gtk_menu_new ();
	menu  = GTK_MENU (curr_data->menu);
	
	while (list) {
		gchar *string = list->data;
		menuitem = gtk_radio_menu_item_new_with_label (group, string);
		group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
		gtk_widget_show (menuitem);
		g_object_set_data (G_OBJECT (menuitem), "string", string);
		g_signal_connect (G_OBJECT (menuitem), "activate",
				   G_CALLBACK (menuitem_activated), curr_data);
		gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
		if (g_ascii_strcasecmp (curr_data->charlist, string) == 0)
			gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), TRUE);
		list = g_list_next (list);
	}
	build_table(curr_data);
}
Exemplo n.º 8
0
static int cleanup_table_and_chains(void)
{
	struct nftnl_table *table;
	struct mnl_socket *nl;
	int err;

	DBG("");

        err = socket_open_and_bind(&nl);
        if (err < 0)
		return -ENOMEM;

	/*
	 * Cleanup everythying in one go. There is little point in
	 * step-by-step removal of rules and chains if you can get it
	 * as simple as this.
	 */
	/*
	 * # nft delete table connman
	 */
	table = build_table(CONNMAN_TABLE, NFPROTO_IPV4);
	err = table_cmd(nl, table, NFT_MSG_DELTABLE, NFPROTO_IPV4, NLM_F_ACK);

	mnl_socket_close(nl);
	return err;
}
Exemplo n.º 9
0
bool SQLite3DB::check_and_build_table(char *table_name, char *table_def) {
	int rci;
	bool rcb;
	rci=check_table_structure(table_name,table_def);
	if (rci) return true;
	rcb=build_table(table_name,table_def,true);
	return rcb;
}
Exemplo n.º 10
0
void
set_goal(char* goal)
{
  int i;

  build_table();
  
  for (i=0; i<20; ++i)
    sscanf(goal+(2*i), "%02x", (unsigned int *) &GOAL[i]);
}
Exemplo n.º 11
0
void config_parser_t::initialize()
{
	if(initialized)
		return;

	init();
	set_defaults();
	build_table();
	initialized = 1;
}
Exemplo n.º 12
0
int main(int argc, char* argv[]){
    int n;
    float **table;
    
    while(scanf("%d", &n) != -1){
        table = build_table(n);
        solve(table, n);
    }
    return 0;
}
Exemplo n.º 13
0
static void applet_change_orient(MatePanelApplet *applet, MatePanelAppletOrient o, gpointer data)
{
  charpick_data *curr_data = data;
  if (o == MATE_PANEL_APPLET_ORIENT_UP ||
      o == MATE_PANEL_APPLET_ORIENT_DOWN)
    curr_data->panel_vertical = FALSE;
  else
    curr_data->panel_vertical = TRUE;
  build_table (curr_data);
  return;
}
Exemplo n.º 14
0
void tree_item_selected( GtkWidget* item )
{
    gchar* current_path = context.current_path;
    memset( current_path, 0, PAKFile::MAX_FILENAMESIZE );

    if( GTK_TREE( item->parent )->level != 0 ) {
	walk_up_tree( item );
    }

    build_table( );
}
Exemplo n.º 15
0
/* Name:
 * Description:
 * Inputs:
 * Outputs:
 */
void Stepper::NewAccelTable()
{
	my_accel_tbl = new unsigned short [table_size];
	build_table(GetStartPeriod(), GetSlewPeriod());

	fs_etpu_sm_table(master_channel, my_accel_tbl);

	if(my_output_mode != ECE315_ETPU_SM_FULL_STEP_MODE)
		fs_etpu_sm_table(master_channel+2, my_accel_tbl);

	delete 	my_accel_tbl;
}
Exemplo n.º 16
0
void SPHSystem::animation()
{
	if(sys_running == 0)
	{
		return;
	}

	build_table();
	comp_dens_pres();
	comp_force_adv();
	advection();
}
Exemplo n.º 17
0
static void
create_page (GnomeDesktopItem *item, GtkWidget *box)
{
	GtkWidget *table;
	GList *entries;
	GnomeDesktopItemType item_type;
	GtkLabel *label;
	
	entries = NULL;

	label = g_object_get_data (G_OBJECT (box), "label");

	item_type = gnome_desktop_item_get_entry_type (item);
	
	if (item_type == GNOME_DESKTOP_ITEM_TYPE_LINK) {
		entries = g_list_prepend (entries,
					  item_entry_new (GNOME_DESKTOP_ITEM_COMMENT,
							  _("Comment"), TRUE, FALSE));
		entries = g_list_prepend (entries,
					  item_entry_new (GNOME_DESKTOP_ITEM_URL,
							  _("URL"), FALSE, TRUE));
		entries = g_list_prepend (entries,
					  item_entry_new (GNOME_DESKTOP_ITEM_GENERIC_NAME,
							  _("Description"), TRUE, FALSE));
		gtk_label_set_text (label, _("Link"));
	} else if (item_type == GNOME_DESKTOP_ITEM_TYPE_APPLICATION) {
		entries = g_list_prepend (entries,
					  item_entry_new (GNOME_DESKTOP_ITEM_COMMENT,
							  _("Comment"), TRUE, FALSE));
		entries = g_list_prepend (entries,
					  item_entry_new (GNOME_DESKTOP_ITEM_EXEC,
							  _("Command"), FALSE, FALSE));
		entries = g_list_prepend (entries,
					  item_entry_new (GNOME_DESKTOP_ITEM_GENERIC_NAME,
							  _("Description"), TRUE, FALSE));
		gtk_label_set_text (label, _("Launcher"));		
	} else {
		/* we only handle launchers and links */
		return;
	}

	gnome_desktop_item_ref (item);

	g_object_weak_ref (G_OBJECT (box),
			   box_weak_cb, item);

	table = build_table (item, entries, 2);
	g_list_free (entries);
	
	gtk_box_pack_start (GTK_BOX (box), table, FALSE, TRUE, 0);
	gtk_widget_show_all (GTK_WIDGET (box));
}
Exemplo n.º 18
0
std::string Director::create_html(Entries entries, const std::string& path) {
  std::ostringstream ss;
  ss << HTML_HEADER;
  ss << "<div class=\"container\">";
  ss << "<h1 class=\"page-header\">" << path << "</h1>";
  ss << "<div class=\"panel panel-default\">";
  build_table(ss, entries, path);
  ss << "</div>"; // panel
  ss << "<hr/><h6 class=\"small\">Powered by <strong>IncludeOS</strong></h6>";
  ss << "</div>"; // container

  ss << HTML_FOOTER;
  return ss.str();
}
Exemplo n.º 19
0
static void
create_page (GKeyFile *key_file, GtkWidget *box)
{
	GtkWidget *table;
	GList *entries;
	GtkSizeGroup *label_size_group;
	char *type;
	
	entries = NULL;

	type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
	
	if (g_strcmp0 (type, "Link") == 0) {
		entries = g_list_prepend (entries,
					  item_entry_new ("Comment",
							  _("Comment"), TRUE, FALSE));
		entries = g_list_prepend (entries,
					  item_entry_new ("URL",
							  _("URL"), FALSE, TRUE));
		entries = g_list_prepend (entries,
					  item_entry_new ("GenericName",
							  _("Description"), TRUE, FALSE));
	} else if (g_strcmp0 (type, "Application") == 0) {
		entries = g_list_prepend (entries,
					  item_entry_new ("Comment",
							  _("Comment"), TRUE, FALSE));
		entries = g_list_prepend (entries,
					  item_entry_new ("Exec", 
							  _("Command"), FALSE, FALSE));
		entries = g_list_prepend (entries,
					  item_entry_new ("GenericName",
							  _("Description"), TRUE, FALSE));
	} else {
		/* we only handle launchers and links */

		/* ensure that we build an empty table with a dummy row at the end */
		goto build_table;
	}
	g_free (type);

build_table:
	label_size_group = g_object_get_data (G_OBJECT (box), "label-size-group");

	table = build_table (box, key_file, label_size_group, entries);
	g_list_free (entries);
	
	gtk_box_pack_start (GTK_BOX (box), table, FALSE, TRUE, 0);
	gtk_widget_show_all (GTK_WIDGET (box));
}
Exemplo n.º 20
0
static void
menuitem_activated (GtkMenuItem *menuitem, charpick_data *curr_data)
{
	gchar *string;
	MatePanelApplet *applet = MATE_PANEL_APPLET (curr_data->applet);
	
	string = g_object_get_data (G_OBJECT (menuitem), "string");
	if (g_ascii_strcasecmp (curr_data->charlist, string) == 0)
		return;
	
	curr_data->charlist = string;
	build_table (curr_data);
	if (g_settings_is_writable (curr_data->settings, "current-list"))
		g_settings_set_string (curr_data->settings, "current-list", curr_data->charlist);
}
Exemplo n.º 21
0
int		get_median_partition(t_list *lst, int size_partition)
{
	int		min;
	int		max;
	int		*t;
	int		size;
	int		median;

	size = build_table(lst, &t); //penser au pattern singleton
	hidden_quicksort(t, 0, size - 1);
	get_max_partition(lst, size_partition, &max);
	get_min_partition(lst, size_partition, &min);
	median = get_median(t, get_index_array(t, min, size), get_index_array(t, max, size));
	return (median);
}
Exemplo n.º 22
0
static void applet_size_allocate(MatePanelApplet *applet, GtkAllocation *allocation, gpointer data)
{
  charpick_data *curr_data = data;
  if (curr_data->panel_vertical) {
    if (curr_data->panel_size == allocation->width)
      return;
    curr_data->panel_size = allocation->width;
  } else {
    if (curr_data->panel_size == allocation->height)
      return;
    curr_data->panel_size = allocation->height;
  }

  build_table (curr_data);
  return;
}
Exemplo n.º 23
0
void
populate_menu (charpick_data *curr_data)
{
	GList *list = curr_data->chartable;
	GSList *group = NULL;
	GtkMenu *menu;
	GtkWidget *menuitem;

	if (curr_data->menu)
		gtk_widget_destroy (curr_data->menu);

	curr_data->menu = gtk_menu_new ();
	menu  = GTK_MENU (curr_data->menu);
	
	while (list) {
		gchar *string = list->data;
		menuitem = gtk_radio_menu_item_new_with_label (group, string);
		group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
		gtk_widget_show (menuitem);
		g_object_set_data (G_OBJECT (menuitem), "string", string);
		g_signal_connect (G_OBJECT (menuitem), "activate",
				   G_CALLBACK (menuitem_activated), curr_data);
		gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
		if (g_ascii_strcasecmp (curr_data->charlist, string) == 0)
			gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), TRUE);
		list = g_list_next (list);
	}
	build_table(curr_data);
	
	/*Set up custom theme and transparency support*/
	GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu));
	/* Fix any failures of compiz/other wm's to communicate with gtk for transparency */
	GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(toplevel));
	GdkVisual *visual = gdk_screen_get_rgba_visual(screen);
	gtk_widget_set_visual(GTK_WIDGET(toplevel), visual);
	/* Set menu and it's toplevel window to follow panel theme */
	GtkStyleContext *context;
	context = gtk_widget_get_style_context (GTK_WIDGET(toplevel));
	gtk_style_context_add_class(context,"gnome-panel-menu-bar");
	gtk_style_context_add_class(context,"mate-panel-menu-bar");
}
Exemplo n.º 24
0
/*
 * TODO: output the table (possibly merged), in the input format 
 */
int 
main (int argc, char* argv [])
{
	init_table ();
	if (argc == 2) {
		/* useful to get a new file when some opcodes are added: looses the comments, though */
		load_file (argv [1]);
		dump ();
	} else if (argc < 4) {
		g_print ("Usage: genmdesc arguments\n");
		g_print ("\tgenmdesc desc                        Output to stdout the description file.\n");
		g_print ("\tgenmdesc output name desc [desc1...] Write to output the description in a table named 'name'.\n");
		return 1;
	} else {
		int i;
		for (i = 3; i < argc; ++i)
			load_file (argv [i]);
		build_table (argv [1], argv [2]);
	}
	return 0;
}
Exemplo n.º 25
0
void SPHSystem::animation()
{
	if(sys_running == 0)
	{
		return;
	}

	build_table();
	if(sys_render == 1)
	{
		interp_scalar();
	}

	if(enable_split == 1 && tick == 0 || enable_merge == 1 && tick == 1)
	{
		comp_scalar();
		find_surface();
		comp_dist();
		//comp_energy();
	}

	comp_dens_pres();
	comp_force_adv();

	if(enable_split == 1 && tick == 0)
	{
		comp_split();
	}

	if(enable_merge == 1 && tick == 1)
	{
		comp_merge();
	}

	advection();

	tick=1-tick;
}
Exemplo n.º 26
0
int main()
{
    build_table();
    std::string input;
    while ( std::cin >> input )
    {
        int n = std::stoi( input );
        if ( table[ n ] > 0 )
        {
            auto rev = input;
            std::reverse( rev.begin(), rev.end() );
            n = std::stoi( rev );
            if( rev != input && table[ n ] > 0 )
                std::cout << input << " is emirp." << std::endl;
            else 
                std::cout << input << " is prime." << std::endl;
        }
        else
        {
            std::cout << input << " is not prime." << std::endl;
        }
    }
    return 0;
}
Exemplo n.º 27
0
/* hash some C/C++ code after unifying */
static void unify(unsigned char *p, size_t size)
{
	size_t ofs;
	unsigned char q;
	int i;

	build_table();

	for (ofs=0; ofs<size;) {
		if (p[ofs] == '#') {
			if ((size-ofs) > 2 && p[ofs+1] == ' ' && isdigit(p[ofs+2])) {
				do {
					ofs++;
				} while (ofs < size && p[ofs] != '\n');
				ofs++;
			} else {
				do {
					pushchar(p[ofs]);
					ofs++;
				} while (ofs < size && p[ofs] != '\n');
				pushchar('\n');
				ofs++;
			}
			continue;
		}

		if (tokens[p[ofs]].type & C_ALPHA) {
			do {
				pushchar(p[ofs]);
				ofs++;
			} while (ofs < size && 
				 (tokens[p[ofs]].type & (C_ALPHA|C_DIGIT)));
			pushchar('\n');
			continue;
		}

		if (tokens[p[ofs]].type & C_DIGIT) {
			do {
				pushchar(p[ofs]);
				ofs++;
			} while (ofs < size && 
				 ((tokens[p[ofs]].type & C_DIGIT) || p[ofs] == '.'));
			if (ofs < size && (p[ofs] == 'x' || p[ofs] == 'X')) {
				do {
					pushchar(p[ofs]);
					ofs++;
				} while (ofs < size && (tokens[p[ofs]].type & C_HEX));
			}
			if (ofs < size && (p[ofs] == 'E' || p[ofs] == 'e')) {
				pushchar(p[ofs]);
				ofs++;
				while (ofs < size && 
				       (tokens[p[ofs]].type & (C_DIGIT|C_SIGN))) {
					pushchar(p[ofs]);
					ofs++;
				}
			}
			while (ofs < size && (tokens[p[ofs]].type & C_FLOAT)) {
				pushchar(p[ofs]);
				ofs++;
			}
			pushchar('\n');
			continue;
		}

		if (tokens[p[ofs]].type & C_SPACE) {
			do {
				ofs++;
			} while (ofs < size && (tokens[p[ofs]].type & C_SPACE));
			continue;
		}
			
		if (tokens[p[ofs]].type & C_QUOTE) {
			q = p[ofs];
			pushchar(p[ofs]);
			do {
				ofs++;
				while (ofs < size-1 && p[ofs] == '\\') {
					pushchar(p[ofs]);
					pushchar(p[ofs+1]);
					ofs+=2;
				}
				pushchar(p[ofs]);
			} while (ofs < size && p[ofs] != q);
			pushchar('\n');
			ofs++;
			continue;
		}

		if (tokens[p[ofs]].type & C_TOKEN) {
			q = p[ofs];
			for (i=0;i<tokens[q].num_toks;i++) {
				unsigned char *s = (unsigned char *)tokens[q].toks[i];
				int len = strlen((char *)s);
				if (size >= ofs+len && memcmp(&p[ofs], s, len) == 0) {
					int j;
					for (j=0;s[j];j++) {
						pushchar(s[j]);
						ofs++;
					}
					pushchar('\n');
					break;
				}
			}
			if (i < tokens[q].num_toks) {
				continue;
			}
		}

		pushchar(p[ofs]);
		pushchar('\n');
		ofs++;
	}
	pushchar(0);
}
Exemplo n.º 28
0
 constexpr constexpr_hashtable(const std::initializer_list<std::pair<Key,Value>> ls)
   : constexpr_hashtable(build_table(std::forward<decltype(ls)>(ls))) {}
void
_initialize_mi_cmds (void)
{
  build_table (mi_cmds);
  memset (&stats, 0, sizeof (stats));
}
Exemplo n.º 30
0
 void init(int cut, int alpha_) {
     alpha = alpha_;
     build_table(next[0], next[1], 4096, alpha_, 4096-cut);
 }