static DocInfoDialog *
get_docinfo_dialog (PlumaWindow *window,
		    WindowData	*data)
{
	DocInfoDialog *dialog;
	gchar *data_dir;
	gchar *ui_file;
	GtkWidget *content;
	GtkWidget *error_widget;
	gboolean ret;

	pluma_debug (DEBUG_PLUGINS);

	dialog = g_new (DocInfoDialog, 1);

	data_dir = pluma_plugin_get_data_dir (data->plugin);
	ui_file = g_build_filename (data_dir, "docinfo.ui", NULL);
	ret = pluma_utils_get_ui_objects (ui_file,
					  NULL,
					  &error_widget,
					  "dialog", &dialog->dialog,
					  "docinfo_dialog_content", &content,
					  "file_name_label", &dialog->file_name_label,
					  "words_label", &dialog->words_label,
					  "bytes_label", &dialog->bytes_label,
					  "lines_label", &dialog->lines_label,
					  "chars_label", &dialog->chars_label,
					  "chars_ns_label", &dialog->chars_ns_label,
					  "selection_vbox", &dialog->selection_vbox,
					  "selected_words_label", &dialog->selected_words_label,
					  "selected_bytes_label", &dialog->selected_bytes_label,
					  "selected_lines_label", &dialog->selected_lines_label,
					  "selected_chars_label", &dialog->selected_chars_label,
					  "selected_chars_ns_label", &dialog->selected_chars_ns_label,
					  NULL);

	g_free (data_dir);
	g_free (ui_file);

	if (!ret)
	{
		const gchar *err_message;

		err_message = gtk_label_get_label (GTK_LABEL (error_widget));
		pluma_warning (GTK_WINDOW (window), "%s", err_message);

		g_free (dialog);
		gtk_widget_destroy (error_widget);

		return NULL;
	}

	gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog),
					 GTK_RESPONSE_OK);
	gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
				      GTK_WINDOW (window));
	
	g_signal_connect (dialog->dialog,
			  "destroy",
			  G_CALLBACK (docinfo_dialog_destroy_cb),
			  data);
	g_signal_connect (dialog->dialog,
			  "response",
			  G_CALLBACK (docinfo_dialog_response_cb),
			  window);

	return dialog;
}
Пример #2
0
static void sx1_init(MachineState *machine, const int version)
{
    struct omap_mpu_state_s *mpu;
    MemoryRegion *address_space = get_system_memory();
    MemoryRegion *flash = g_new(MemoryRegion, 1);
    MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
    MemoryRegion *cs = g_new(MemoryRegion, 4);
    static uint32_t cs0val = 0x00213090;
    static uint32_t cs1val = 0x00215070;
    static uint32_t cs2val = 0x00001139;
    static uint32_t cs3val = 0x00001139;
    DriveInfo *dinfo;
    int fl_idx;
    uint32_t flash_size = flash0_size;
    int be;

    if (version == 2) {
        flash_size = flash2_size;
    }

    mpu = omap310_mpu_init(address_space, sx1_binfo.ram_size,
                           machine->cpu_model);

    /* External Flash (EMIFS) */
    memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size,
                           &error_abort);
    vmstate_register_ram_global(flash);
    memory_region_set_readonly(flash, true);
    memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);

    memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
                          "sx1.cs0", OMAP_CS0_SIZE - flash_size);
    memory_region_add_subregion(address_space,
                                OMAP_CS0_BASE + flash_size, &cs[0]);


    memory_region_init_io(&cs[2], NULL, &static_ops, &cs2val,
                          "sx1.cs2", OMAP_CS2_SIZE);
    memory_region_add_subregion(address_space,
                                OMAP_CS2_BASE, &cs[2]);

    memory_region_init_io(&cs[3], NULL, &static_ops, &cs3val,
                          "sx1.cs3", OMAP_CS3_SIZE);
    memory_region_add_subregion(address_space,
                                OMAP_CS2_BASE, &cs[3]);

    fl_idx = 0;
#ifdef TARGET_WORDS_BIGENDIAN
    be = 1;
#else
    be = 0;
#endif

    if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
        if (!pflash_cfi01_register(OMAP_CS0_BASE, NULL,
                                   "omap_sx1.flash0-1", flash_size,
                                   dinfo->bdrv, sector_size,
                                   flash_size / sector_size,
                                   4, 0, 0, 0, 0, be)) {
            fprintf(stderr, "qemu: Error registering flash memory %d.\n",
                           fl_idx);
        }
        fl_idx++;
    }

    if ((version == 1) &&
            (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
        memory_region_init_ram(flash_1, NULL, "omap_sx1.flash1-0", flash1_size,
                               &error_abort);
        vmstate_register_ram_global(flash_1);
        memory_region_set_readonly(flash_1, true);
        memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);

        memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
                              "sx1.cs1", OMAP_CS1_SIZE - flash1_size);
        memory_region_add_subregion(address_space,
                                OMAP_CS1_BASE + flash1_size, &cs[1]);

        if (!pflash_cfi01_register(OMAP_CS1_BASE, NULL,
                                   "omap_sx1.flash1-1", flash1_size,
                                   dinfo->bdrv, sector_size,
                                   flash1_size / sector_size,
                                   4, 0, 0, 0, 0, be)) {
            fprintf(stderr, "qemu: Error registering flash memory %d.\n",
                           fl_idx);
        }
        fl_idx++;
    } else {
        memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
                              "sx1.cs1", OMAP_CS1_SIZE);
        memory_region_add_subregion(address_space,
                                OMAP_CS1_BASE, &cs[1]);
    }

    if (!machine->kernel_filename && !fl_idx && !qtest_enabled()) {
        fprintf(stderr, "Kernel or Flash image must be specified\n");
        exit(1);
    }

    /* Load the kernel.  */
    sx1_binfo.kernel_filename = machine->kernel_filename;
    sx1_binfo.kernel_cmdline = machine->kernel_cmdline;
    sx1_binfo.initrd_filename = machine->initrd_filename;
    arm_load_kernel(mpu->cpu, &sx1_binfo);

    /* TODO: fix next line */
    //~ qemu_console_resize(ds, 640, 480);
}
Пример #3
0
static void vexpress_common_init(MachineState *machine)
{
    VexpressMachineState *vms = VEXPRESS_MACHINE(machine);
    VexpressMachineClass *vmc = VEXPRESS_MACHINE_GET_CLASS(machine);
    VEDBoardInfo *daughterboard = vmc->daughterboard;;
    DeviceState *dev, *sysctl, *pl041;
    qemu_irq pic[64];
    uint32_t sys_id;
    DriveInfo *dinfo;
    pflash_t *pflash0;
    ram_addr_t vram_size, sram_size;
    MemoryRegion *sysmem = get_system_memory();
    MemoryRegion *vram = g_new(MemoryRegion, 1);
    MemoryRegion *sram = g_new(MemoryRegion, 1);
    MemoryRegion *flashalias = g_new(MemoryRegion, 1);
    MemoryRegion *flash0mem;
    const hwaddr *map = daughterboard->motherboard_map;
    int i;

    daughterboard->init(vms, machine->ram_size, machine->cpu_model, pic);

    /*
     * If a bios file was provided, attempt to map it into memory
     */
    if (bios_name) {
        char *fn;
        int image_size;

        if (drive_get(IF_PFLASH, 0, 0)) {
            error_report("The contents of the first flash device may be "
                         "specified with -bios or with -drive if=pflash... "
                         "but you cannot use both options at once");
            exit(1);
        }
        fn = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
        if (!fn) {
            error_report("Could not find ROM image '%s'", bios_name);
            exit(1);
        }
        image_size = load_image_targphys(fn, map[VE_NORFLASH0],
                                         VEXPRESS_FLASH_SIZE);
        g_free(fn);
        if (image_size < 0) {
            error_report("Could not load ROM image '%s'", bios_name);
            exit(1);
        }
    }

    /* Motherboard peripherals: the wiring is the same but the
     * addresses vary between the legacy and A-Series memory maps.
     */

    sys_id = 0x1190f500;

    sysctl = qdev_create(NULL, "realview_sysctl");
    qdev_prop_set_uint32(sysctl, "sys_id", sys_id);
    qdev_prop_set_uint32(sysctl, "proc_id", daughterboard->proc_id);
    qdev_prop_set_uint32(sysctl, "len-db-voltage",
                         daughterboard->num_voltage_sensors);
    for (i = 0; i < daughterboard->num_voltage_sensors; i++) {
        char *propname = g_strdup_printf("db-voltage[%d]", i);
        qdev_prop_set_uint32(sysctl, propname, daughterboard->voltages[i]);
        g_free(propname);
    }
    qdev_prop_set_uint32(sysctl, "len-db-clock",
                         daughterboard->num_clocks);
    for (i = 0; i < daughterboard->num_clocks; i++) {
        char *propname = g_strdup_printf("db-clock[%d]", i);
        qdev_prop_set_uint32(sysctl, propname, daughterboard->clocks[i]);
        g_free(propname);
    }
    qdev_init_nofail(sysctl);
    sysbus_mmio_map(SYS_BUS_DEVICE(sysctl), 0, map[VE_SYSREGS]);

    /* VE_SP810: not modelled */
    /* VE_SERIALPCI: not modelled */

    pl041 = qdev_create(NULL, "pl041");
    qdev_prop_set_uint32(pl041, "nc_fifo_depth", 512);
    qdev_init_nofail(pl041);
    sysbus_mmio_map(SYS_BUS_DEVICE(pl041), 0, map[VE_PL041]);
    sysbus_connect_irq(SYS_BUS_DEVICE(pl041), 0, pic[11]);

    dev = sysbus_create_varargs("pl181", map[VE_MMCI], pic[9], pic[10], NULL);
    /* Wire up MMC card detect and read-only signals */
    qdev_connect_gpio_out(dev, 0,
                          qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_WPROT));
    qdev_connect_gpio_out(dev, 1,
                          qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_CARDIN));

    sysbus_create_simple("pl050_keyboard", map[VE_KMI0], pic[12]);
    sysbus_create_simple("pl050_mouse", map[VE_KMI1], pic[13]);

    sysbus_create_simple("pl011", map[VE_UART0], pic[5]);
    sysbus_create_simple("pl011", map[VE_UART1], pic[6]);
    sysbus_create_simple("pl011", map[VE_UART2], pic[7]);
    sysbus_create_simple("pl011", map[VE_UART3], pic[8]);

    sysbus_create_simple("sp804", map[VE_TIMER01], pic[2]);
    sysbus_create_simple("sp804", map[VE_TIMER23], pic[3]);

    /* VE_SERIALDVI: not modelled */

    sysbus_create_simple("pl031", map[VE_RTC], pic[4]); /* RTC */

    /* VE_COMPACTFLASH: not modelled */

    sysbus_create_simple("pl111", map[VE_CLCD], pic[14]);

    dinfo = drive_get_next(IF_PFLASH);
    pflash0 = ve_pflash_cfi01_register(map[VE_NORFLASH0], "vexpress.flash0",
                                       dinfo);
    if (!pflash0) {
        fprintf(stderr, "vexpress: error registering flash 0.\n");
        exit(1);
    }

    if (map[VE_NORFLASHALIAS] != -1) {
        /* Map flash 0 as an alias into low memory */
        flash0mem = sysbus_mmio_get_region(SYS_BUS_DEVICE(pflash0), 0);
        memory_region_init_alias(flashalias, NULL, "vexpress.flashalias",
                                 flash0mem, 0, VEXPRESS_FLASH_SIZE);
        memory_region_add_subregion(sysmem, map[VE_NORFLASHALIAS], flashalias);
    }

    dinfo = drive_get_next(IF_PFLASH);
    if (!ve_pflash_cfi01_register(map[VE_NORFLASH1], "vexpress.flash1",
                                  dinfo)) {
        fprintf(stderr, "vexpress: error registering flash 1.\n");
        exit(1);
    }

    sram_size = 0x2000000;
    memory_region_init_ram(sram, NULL, "vexpress.sram", sram_size,
                           &error_abort);
    vmstate_register_ram_global(sram);
    memory_region_add_subregion(sysmem, map[VE_SRAM], sram);

    vram_size = 0x800000;
    memory_region_init_ram(vram, NULL, "vexpress.vram", vram_size,
                           &error_abort);
    vmstate_register_ram_global(vram);
    memory_region_add_subregion(sysmem, map[VE_VIDEORAM], vram);

    /* 0x4e000000 LAN9118 Ethernet */
    if (nd_table[0].used) {
        lan9118_init(&nd_table[0], map[VE_ETHERNET], pic[15]);
    }

    /* VE_USB: not modelled */

    /* VE_DAPROM: not modelled */

    /* Create mmio transports, so the user can create virtio backends
     * (which will be automatically plugged in to the transports). If
     * no backend is created the transport will just sit harmlessly idle.
     */
    for (i = 0; i < NUM_VIRTIO_TRANSPORTS; i++) {
        sysbus_create_simple("virtio-mmio", map[VE_VIRTIO] + 0x200 * i,
                             pic[40 + i]);
    }

    daughterboard->bootinfo.ram_size = machine->ram_size;
    daughterboard->bootinfo.kernel_filename = machine->kernel_filename;
    daughterboard->bootinfo.kernel_cmdline = machine->kernel_cmdline;
    daughterboard->bootinfo.initrd_filename = machine->initrd_filename;
    daughterboard->bootinfo.nb_cpus = smp_cpus;
    daughterboard->bootinfo.board_id = VEXPRESS_BOARD_ID;
    daughterboard->bootinfo.loader_start = daughterboard->loader_start;
    daughterboard->bootinfo.smp_loader_start = map[VE_SRAM];
    daughterboard->bootinfo.smp_bootreg_addr = map[VE_SYSREGS] + 0x30;
    daughterboard->bootinfo.gic_cpu_if_addr = daughterboard->gic_cpu_if_addr;
    daughterboard->bootinfo.modify_dtb = vexpress_modify_dtb;
    /* Indicate that when booting Linux we should be in secure state */
    daughterboard->bootinfo.secure_boot = true;
    arm_load_kernel(ARM_CPU(first_cpu), &daughterboard->bootinfo);
}
Пример #4
0
/*----------------------------------------------------------------------------------------------------------------------*/
void MakeAscii2d(GtkWidget *Win,gpointer Data)
{
gchar OutFName[MAX_FNAME_LENGTH+5],*BitType,Str[150];
FILE *Fp;
gshort XSize,YSize;
guint16 *Data16;
guint32 *Data32,DMax;
gint X,Y,WSize;
gboolean Error;
GtkWidget *W,*Label,*But;
                                                                                                                             
if (!Ascii2d->Ready) { Attention(0,"Error: No file selected!"); return; }
strcpy(OutFName,gtk_entry_get_text(GTK_ENTRY(Ascii2d->OutEntry)));
BitType=gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(Ascii2d->BitCombo)->entry));
                                                                                                                             
if ( !(Fp=fopen(Ascii2d->InFName,"r"))) 
   { sprintf(Str,"Could not open %s",Ascii2d->InFName); Attention(0,Str); return; }
fread(&XSize,sizeof(gshort),1,Fp); fread(&YSize,sizeof(gshort),1,Fp);
if (BitType[0]=='S') { WSize=1; Data16=g_new(guint16,XSize*YSize); InitMat16(XSize,YSize,Data16); }
else                 { WSize=2; Data32=g_new(guint32,XSize*YSize); InitMat32(XSize,YSize,Data32); }
Readz2d(WSize,XSize,YSize,Fp,Data16,Data32,&Error);
fclose(Fp);
if (Error) { sprintf(Str,"Error reading %s",Ascii2d->InFName); Attention(0,Str); return; }
                                                                                                                             
if ( !(Fp=fopen(OutFName,"w"))) { sprintf(Str,"Could not open %s",OutFName); Attention(0,Str); return; }
fprintf(Fp,"#Ascii file suitable for gnuplot: splot \"%s\"\n",OutFName);
if (WSize==1)
   {
   for (X=0,DMax=0;X<XSize;++X) 
       {
       for (Y=0;Y<YSize;++Y) 
           {
           fprintf(Fp,"%4d %6d %d\n",X,Y,Data16[X+XSize*Y]);
           if ((X>0) && (Y>0)) DMax=MAX(DMax,(guint32)Data16[X+XSize*Y]);
           }
       fprintf(Fp,"\n");
       }
   g_free(Data16);
   }
else
   {
   for (X=0,DMax=0;X<XSize;++X) 
       {
       for (Y=0;Y<YSize;++Y) 
           {
           fprintf(Fp,"%4d %6d %d\n",X,Y,Data32[X+XSize*Y]);
           if ((X>0) && (Y>0)) DMax=MAX(DMax,Data32[X+XSize*Y]);
           }
       fprintf(Fp,"\n");
       }
   g_free(Data32);
   }
fclose(Fp);

W=gtk_dialog_new(); gtk_grab_add(W); gtk_window_set_title(GTK_WINDOW(W),"Finished");
gtk_widget_set_uposition(GTK_WIDGET(W),350,350); gtk_widget_set_usize(GTK_WIDGET(W),300,100);
gtk_signal_connect_object(GTK_OBJECT(W),"delete_event",GTK_SIGNAL_FUNC(gtk_widget_destroy),GTK_OBJECT(W));
sprintf(Str,"File ./%s written",OutFName);
Label=gtk_label_new(Str); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(W)->vbox),Label,TRUE,FALSE,5);
sprintf(Str,"For gnuplot: splot [0:%d] [0:%d] [1:%d] \"%s\"",XSize,YSize,DMax,OutFName);
Label=gtk_label_new(Str); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(W)->vbox),Label,TRUE,FALSE,5);
Fp=fopen("work.gnu","w");
fprintf(Fp,"splot [0:%d] [0:%d] [1:%d] \"%s\"",XSize,YSize,DMax,OutFName);
fclose(Fp);
But=gtk_button_new_with_label("Show with\ngnuplot");
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(W)->action_area),But,TRUE,FALSE,0);
gtk_signal_connect(GTK_OBJECT(But),"clicked",GTK_SIGNAL_FUNC(DoGnuPlot),NULL);
gtk_signal_connect_object(GTK_OBJECT(But),"clicked",GTK_SIGNAL_FUNC(gtk_widget_destroy),GTK_OBJECT(W));
But=gtk_button_new_with_label("Dismiss");
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(W)->action_area),But,TRUE,FALSE,0);
gtk_signal_connect_object(GTK_OBJECT(But),"clicked",GTK_SIGNAL_FUNC(gtk_widget_destroy),GTK_OBJECT(W));
gtk_widget_show_all(W);
}
Пример #5
0
MetaWindowMenu*
meta_window_menu_new   (MetaFrames         *frames,
                        MetaMenuOp          ops,
                        MetaMenuOp          insensitive,
                        Window              client_xwindow,
                        unsigned long       active_workspace,
                        int                 n_workspaces,
                        MetaWindowMenuFunc  func,
                        gpointer            data)
{
  int i;
  MetaWindowMenu *menu;

  /* FIXME: Modifications to 'ops' should happen in meta_window_show_menu */
  if (n_workspaces < 2)
    ops &= ~(META_MENU_OP_STICK | META_MENU_OP_UNSTICK | META_MENU_OP_WORKSPACES);
  else if (n_workspaces == 2) 
    /* #151183: If we only have two workspaces, disable the menu listing them. */
    ops &= ~(META_MENU_OP_WORKSPACES);
  
  menu = g_new (MetaWindowMenu, 1);
  menu->frames = frames;
  menu->client_xwindow = client_xwindow;
  menu->func = func;
  menu->data = data;
  menu->ops = ops;
  menu->insensitive = insensitive;  
  
  menu->menu = gtk_menu_new ();

  gtk_menu_set_screen (GTK_MENU (menu->menu),
                       gtk_widget_get_screen (GTK_WIDGET (frames)));

  for (i = 0; i < (int) G_N_ELEMENTS (menuitems); i++)
    {
      MenuItem menuitem = menuitems[i];
      if (ops & menuitem.op || menuitem.op == 0)
        {
          GtkWidget *mi;
          MenuData *md;
          unsigned int key;
          MetaVirtualModifier mods;

          mi = menu_item_new (&menuitem, -1);

          /* Set the activeness of radiobuttons. */
          switch (menuitem.op)
            {
            case META_MENU_OP_STICK:
              gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi),
                                              active_workspace == 0xFFFFFFFF);
              break;
            case META_MENU_OP_UNSTICK:
              gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi),
                                              active_workspace != 0xFFFFFFFF);
              break;
            default:
              break;
            }

          if (menuitem.type == MENU_ITEM_WORKSPACE_LIST)
            {
              if (ops & META_MENU_OP_WORKSPACES)
                {
                  Display *display;
                  Window xroot;
                  GdkScreen *screen;
                  GtkWidget *submenu;
                  int j;

                  MenuItem to_another_workspace = {
                    0, MENU_ITEM_NORMAL,
                    NULL, FALSE,
                    N_("Move to Another _Workspace")
                  };

                  meta_verbose ("Creating %d-workspace menu current space %lu\n",
                      n_workspaces, active_workspace);

                  display = gdk_x11_drawable_get_xdisplay (GTK_WIDGET (frames)->window);

                  screen = gdk_drawable_get_screen (GTK_WIDGET (frames)->window);
                  xroot = GDK_DRAWABLE_XID (gdk_screen_get_root_window (screen));

                  submenu = gtk_menu_new ();

                  g_assert (mi==NULL);
                  mi = menu_item_new (&to_another_workspace, -1);
                  gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), submenu);

                  for (j = 0; j < n_workspaces; j++)
                    {
                      char *label;
                      MenuData *md;
                      unsigned int key;
                      MetaVirtualModifier mods;
                      MenuItem moveitem;
                      GtkWidget *submi;

                      meta_core_get_menu_accelerator (META_MENU_OP_WORKSPACES,
                          j + 1,
                          &key, &mods);

                      label = get_workspace_name_with_accel (display, xroot, j);

                      moveitem.type = MENU_ITEM_NORMAL;
                      moveitem.op = META_MENU_OP_WORKSPACES;
                      moveitem.label = label;
                      submi = menu_item_new (&moveitem, j + 1);

                      g_free (label);

                      if ((active_workspace == (unsigned)j) && (ops & META_MENU_OP_UNSTICK))
                        gtk_widget_set_sensitive (submi, FALSE);

                      md = g_new (MenuData, 1);

                      md->menu = menu;
                      md->op = META_MENU_OP_WORKSPACES;

                      g_object_set_data (G_OBJECT (submi),
                          "workspace",
                          GINT_TO_POINTER (j));

                      gtk_signal_connect_full (GTK_OBJECT (submi),
                          "activate",
                          G_CALLBACK (activate_cb),
                          NULL,
                          md,
                          g_free, FALSE, FALSE);

                      gtk_menu_shell_append (GTK_MENU_SHELL (submenu), submi);

                      gtk_widget_show (submi);
                    }
                  }
                else
                  meta_verbose ("not creating workspace menu\n");
            }
          else if (menuitem.type != MENU_ITEM_SEPARATOR)
            {
              meta_core_get_menu_accelerator (menuitems[i].op, -1,
                                              &key, &mods);

              if (insensitive & menuitem.op)
                gtk_widget_set_sensitive (mi, FALSE);
              
              md = g_new (MenuData, 1);
              
              md->menu = menu;
              md->op = menuitem.op;
              
              gtk_signal_connect_full (GTK_OBJECT (mi),
                                       "activate",
                                       GTK_SIGNAL_FUNC (activate_cb),
                                       NULL,
                                       md,
                                       g_free, FALSE, FALSE);
            }

          if (mi)
            {
              gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), mi);
          
              gtk_widget_show (mi);
            }
        }
    }

 
  g_signal_connect (menu->menu, "selection_done",
                    G_CALLBACK (menu_closed), menu);  

  return menu;
}
Пример #6
0
static inline void
vreader_unlock(VReader *reader)
{
    g_mutex_unlock(&reader->lock);
}

/*
 * vreader constructor
 */
VReader *
vreader_new(const char *name, VReaderEmul *private,
            VReaderEmulFree private_free)
{
    VReader *reader;

    reader = g_new(VReader, 1);
    g_mutex_init(&reader->lock);
    reader->reference_count = 1;
    reader->name = g_strdup(name);
    reader->card = NULL;
    reader->id = (vreader_id_t)-1;
    reader->reader_private = private;
    reader->reader_private_free = private_free;
    return reader;
}

/* get a reference */
VReader*
vreader_reference(VReader *reader)
{
    if (reader == NULL) {
Пример #7
0
static void
process (gint      line,
	 gchar    *utf8,
	 Status    status,
	 gunichar *ucs4,
	 gint      ucs4_len)
{
  const gchar *end;
  gboolean is_valid = g_utf8_validate (utf8, -1, &end);
  GError *error = NULL;
  glong items_read, items_written;

  switch (status)
    {
    case VALID:
      if (!is_valid)
	{
	  fail ("line %d: valid but g_utf8_validate returned FALSE\n", line);
	  return;
	}
      break;
    case NOTUNICODE:
    case INCOMPLETE:
    case OVERLONG:
    case MALFORMED:
      if (is_valid)
	{
	  fail ("line %d: invalid but g_utf8_validate returned TRUE\n", line);
	  return;
	}
      break;
    }

  if (status == INCOMPLETE)
    {
      gunichar *ucs4_result;      

      ucs4_result = g_utf8_to_ucs4 (utf8, -1, NULL, NULL, &error);

      if (!error || !g_error_matches (error, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT))
	{
	  fail ("line %d: incomplete input not properly detected\n", line);
	  return;
	}
      g_clear_error (&error);

      ucs4_result = g_utf8_to_ucs4 (utf8, -1, &items_read, NULL, &error);

      if (!ucs4_result || items_read == strlen (utf8))
	{
	  fail ("line %d: incomplete input not properly detected\n", line);
	  return;
	}

      g_free (ucs4_result);
    }

  if (status == VALID || status == NOTUNICODE)
    {
      gunichar *ucs4_result;
      gchar *utf8_result;

      ucs4_result = g_utf8_to_ucs4 (utf8, -1, &items_read, &items_written, &error);
      if (!ucs4_result)
	{
	  fail ("line %d: conversion to ucs4 failed: %s\n", line, error->message);
	  return;
	}
      
      if (!ucs4_equal (ucs4_result, ucs4) ||
	  items_read != strlen (utf8) ||
	  items_written != ucs4_len)
	{
	  fail ("line %d: results of conversion to ucs4 do not match expected.\n", line);
	  return;
	}

      g_free (ucs4_result);

      ucs4_result = g_utf8_to_ucs4_fast (utf8, -1, &items_written);
      
      if (!ucs4_equal (ucs4_result, ucs4) ||
	  items_written != ucs4_len)
	{
	  fail ("line %d: results of conversion to ucs4 do not match expected.\n", line);
	  return;
	}

      utf8_result = g_ucs4_to_utf8 (ucs4_result, -1, &items_read, &items_written, &error);
      if (!utf8_result)
	{
	  fail ("line %d: conversion back to utf8 failed: %s", line, error->message);
	  return;
	}

      if (strcmp (utf8_result, utf8) != 0 ||
	  items_read != ucs4_len ||
	  items_written != strlen (utf8))
	{
	  fail ("line %d: conversion back to utf8 did not match original\n", line);
	  return;
	}

      g_free (utf8_result);
      g_free (ucs4_result);
    }

  if (status == VALID)
    {
      gunichar2 *utf16_expected_tmp;
      gunichar2 *utf16_expected;
      gunichar2 *utf16_from_utf8;
      gunichar2 *utf16_from_ucs4;
      gunichar *ucs4_result;
      gsize bytes_written;
      gint n_chars;
      gchar *utf8_result;

#if G_BYTE_ORDER == G_LITTLE_ENDIAN
#define TARGET "UTF-16LE"
#else
#define TARGET "UTF-16"
#endif

      if (!(utf16_expected_tmp = (gunichar2 *)g_convert (utf8, -1, TARGET, "UTF-8",
							 NULL, &bytes_written, NULL)))
	{
	  fail ("line %d: could not convert to UTF-16 via g_convert\n", line);
	  return;
	}

      /* zero-terminate and remove BOM
       */
      n_chars = bytes_written / 2;
      if (utf16_expected_tmp[0] == 0xfeff) /* BOM */
	{
	  n_chars--;
	  utf16_expected = g_new (gunichar2, n_chars + 1);
	  memcpy (utf16_expected, utf16_expected_tmp + 1, sizeof(gunichar2) * n_chars);
	}
      else if (utf16_expected_tmp[0] == 0xfffe) /* ANTI-BOM */
	{
	  fail ("line %d: conversion via iconv to \"UTF-16\" is not native-endian\n", line);
	  return;
	}
      else
	{
	  utf16_expected = g_new (gunichar2, n_chars + 1);
	  memcpy (utf16_expected, utf16_expected_tmp, sizeof(gunichar2) * n_chars);
	}

      utf16_expected[n_chars] = '\0';
      
      if (!(utf16_from_utf8 = g_utf8_to_utf16 (utf8, -1, &items_read, &items_written, &error)))
	{
	  fail ("line %d: conversion to ucs16 failed: %s\n", line, error->message);
	  return;
	}

      if (items_read != strlen (utf8) ||
	  utf16_count (utf16_from_utf8) != items_written)
	{
	  fail ("line %d: length error in conversion to ucs16\n", line);
	  return;
	}

      if (!(utf16_from_ucs4 = g_ucs4_to_utf16 (ucs4, -1, &items_read, &items_written, &error)))
	{
	  fail ("line %d: conversion to ucs16 failed: %s\n", line, error->message);
	  return;
	}

      if (items_read != ucs4_len ||
	  utf16_count (utf16_from_ucs4) != items_written)
	{
	  fail ("line %d: length error in conversion to ucs16\n", line);
	  return;
	}

      if (!utf16_equal (utf16_from_utf8, utf16_expected) ||
	  !utf16_equal (utf16_from_ucs4, utf16_expected))
	{
	  fail ("line %d: results of conversion to ucs16 do not match\n", line);
	  return;
	}

      if (!(utf8_result = g_utf16_to_utf8 (utf16_from_utf8, -1, &items_read, &items_written, &error)))
	{
	  fail ("line %d: conversion back to utf8 failed: %s\n", line, error->message);
	  return;
	}

      if (items_read != utf16_count (utf16_from_utf8) ||
	  items_written != strlen (utf8))
	{
	  fail ("line %d: length error in conversion from ucs16 to utf8\n", line);
	  return;
	}

      if (!(ucs4_result = g_utf16_to_ucs4 (utf16_from_ucs4, -1, &items_read, &items_written, &error)))
	{
	  fail ("line %d: conversion back to utf8/ucs4 failed\n", line);
	  return;
	}

      if (items_read != utf16_count (utf16_from_utf8) ||
	  items_written != ucs4_len)
	{
	  fail ("line %d: length error in conversion from ucs16 to ucs4\n", line);
	  return;
	}

      if (strcmp (utf8, utf8_result) != 0 ||
	  !ucs4_equal (ucs4, ucs4_result))
	{
	  fail ("line %d: conversion back to utf8/ucs4 did not match original\n", line);
	  return;
	}
      
      g_free (utf16_expected_tmp);
      g_free (utf16_expected);
      g_free (utf16_from_utf8);
      g_free (utf16_from_ucs4);
      g_free (utf8_result);
      g_free (ucs4_result);
    }
}
Пример #8
0
static void
psdflp_do(const PSDFLPArgs *args, GwyDataField *dfield, GwyDataField *lpsdf)
{
    enum { N = 4 };

    GwyDataField *reout, *imout;
    gint pxres, pyres, fxres, fyres;
    gint i, j, fi, pi;
    gdouble *ldata, *redata, *imdata;
    gdouble *cosphi, *sinphi;
    gdouble xreal, yreal, f0, f_max, b, p;

    reout = gwy_data_field_new_alike(dfield, FALSE);
    imout = gwy_data_field_new_alike(dfield, FALSE);
    gwy_data_field_2dfft(dfield, NULL, reout, imout,
                         args->window, GWY_TRANSFORM_DIRECTION_FORWARD,
                         GWY_INTERPOLATION_ROUND, /* Ignored */
                         TRUE, 1);

    pxres = reout->xres;
    pyres = reout->yres;
    redata = gwy_data_field_get_data(reout);
    imdata = gwy_data_field_get_data(imout);
    for (i = 0; i < pxres*pyres; i++)
        redata[i] = redata[i]*redata[i] + imdata[i]*imdata[i];
    gwy_data_field_2dfft_humanize(reout);
    gwy_data_field_filter_gaussian(reout, args->sigma);
    for (i = 0; i < pxres*pyres; i++)
        redata[i] = sqrt(redata[i]);

    fxres = pxres/2;
    fyres = pyres/2;
    gwy_data_field_resample(lpsdf, fxres, fyres, GWY_INTERPOLATION_NONE);
    ldata = gwy_data_field_get_data(lpsdf);

    xreal = dfield->xreal;
    yreal = dfield->yreal;
    f0 = 2.0/MIN(xreal, yreal);
    f_max = 0.5*MIN(pxres/xreal, pyres/yreal);
    if (f_max <= f0) {
        g_warning("Minimum frequency is not smaller than maximum frequency.");
    }
    b = log(f_max/f0)/fyres;

    /* Incorporate some prefactors to sinphi[] and cosphi[], knowing that
     * cosine is only ever used for x and sine for y frequencies. */
    cosphi = g_new(gdouble, (N+1)*fxres);
    sinphi = g_new(gdouble, (N+1)*fxres);
    for (j = 0; j < fxres; j++) {
        gdouble phi_from = 2.0*G_PI*j/fxres;
        gdouble phi_to = 2.0*G_PI*(j + 1.0)/fxres;

        for (pi = 0; pi <= N; pi++) {
            gdouble phi = ((pi + 0.5)*phi_from + (N - 0.5 - pi)*phi_to)/N;
            cosphi[j*(N+1) + pi] = cos(phi)*xreal;
            sinphi[j*(N+1) + pi] = sin(phi)*yreal;
        }
    }

    for (i = 0; i < fyres; i++) {
        gdouble f_from = f0*exp(b*i);
        gdouble f_to = f0*exp(b*(i + 1.0));

        for (j = 0; j < fxres; j++) {
            const gdouble *cosphi_j = cosphi + j*(N+1);
            const gdouble *sinphi_j = sinphi + j*(N+1);
            guint n = 0;
            gdouble s = 0.0;

            for (fi = 0; fi <= N; fi++) {
                gdouble f = ((fi + 0.5)*f_from + (N - 0.5 - fi)*f_to)/N;
                for (pi = 0; pi <= N; pi++) {
                    gdouble x = f*cosphi_j[pi] + pxres/2.0,
                            y = f*sinphi_j[pi] + pyres/2.0;

                    if (G_UNLIKELY(x < 0.5
                                   || y < 0.5
                                   || x > pxres - 1.5
                                   || y > pyres - 1.5))
                        continue;

                    p = gwy_data_field_get_dval(reout, x, y,
                                                GWY_INTERPOLATION_SCHAUM);
                    s += p;
                    n++;
                }
            }

            if (!n)
                n = 1;

            ldata[i*fxres + j] = 2.0*G_PI/fxres * s/n*(f_to - f_from);
        }
    }

    g_object_unref(imout);
    g_object_unref(reout);

    gwy_data_field_set_xreal(lpsdf, 2.0*G_PI);
    gwy_data_field_set_xoffset(lpsdf, 0.0);
    gwy_data_field_set_yreal(lpsdf, log(f_max/f0));
    gwy_data_field_set_yoffset(lpsdf, log(f0));
    gwy_si_unit_set_from_string(gwy_data_field_get_si_unit_xy(lpsdf), "");
    gwy_si_unit_set_from_string(gwy_data_field_get_si_unit_z(lpsdf), "");
    gwy_data_field_normalize(lpsdf);
}
Пример #9
0
/* parse "bzr status --short" output, see "bzr help status-flags" for details */
static GSList *
get_commit_files_bzr(const gchar * dir)
{
	enum
	{
		FIRST_CHAR,
		SECOND_CHAR,
		THIRD_CHAR,
		SKIP_SPACE,
		FILE_NAME,
	};

	gchar *txt = NULL;
	GSList *ret = NULL;
	gint pstatus = FIRST_CHAR;
	const gchar *p;
	gchar *base_name;
	gchar *base_dir = find_subdir_path(dir, ".bzr");
	const gchar *start = NULL;
	CommitItem *item;

	const gchar *status = NULL;
	gchar *filename;
	const char *argv[] = { "bzr", "status", "--short", NULL };

	g_return_val_if_fail(base_dir, NULL);

	execute_custom_command(base_dir, argv, NULL, &txt, NULL, base_dir, NULL, NULL);
	if (!NZV(txt))
	{
		g_free(base_dir);
		g_free(txt);
		return NULL;
	}
	p = txt;

	while (*p)
	{
		if (*p == '\r')
		{
		}
		else if (pstatus == FIRST_CHAR)
		{
			if (*p == '+')
				status = FILE_STATUS_ADDED;
			else if (*p == '-')
				status = FILE_STATUS_DELETED;
			else if (*p == '?')
				status = FILE_STATUS_UNKNOWN;
			pstatus = SECOND_CHAR;
		}
		else if (pstatus == SECOND_CHAR)
		{
			if (*p == 'N')
				status = FILE_STATUS_ADDED;
			else if (*p == 'D')
				status = FILE_STATUS_DELETED;
			else if (*p == 'M')
				status = FILE_STATUS_MODIFIED;
			pstatus = THIRD_CHAR;
		}
		else if (pstatus == THIRD_CHAR)
		{
			pstatus = SKIP_SPACE;
		}
		else if (pstatus == SKIP_SPACE)
		{
			if (*p == ' ' || *p == '\t')
			{
			}
			else
			{
				start = p;
				pstatus = FILE_NAME;
			}
		}
		else if (pstatus == FILE_NAME)
		{
			if (*p == '\n')
			{
				if (status != FILE_STATUS_UNKNOWN)
				{
					base_name = g_malloc0(p - start + 1);
					memcpy(base_name, start, p - start);
					filename = g_build_filename(base_dir, base_name, NULL);
					g_free(base_name);
					item = g_new(CommitItem, 1);
					item->status = status;
					item->path = filename;
					ret = g_slist_append(ret, item);
				}
				pstatus = FIRST_CHAR;
			}
		}
		p++;
	}
	g_free(txt);
	g_free(base_dir);
	return ret;
}
Пример #10
0
gint
gnibbles_move_worms (void)
{
  gint i, j;
  gint status = 1, nlives = 1;
  gint *dead;

  dead = g_new (gint, properties->numworms);

  for (i = 0; i < properties->numworms; i++) {
    if (!worms[i]->human) {
      gnibbles_worm_ai_move (worms[i]);
    }
  }

  if (boni->missed > MAXMISSED)
    for (i = 0; i < properties->numworms; i++)
      if (worms[i]->score)
        worms[i]->score--;

  for (i = 0; i < boni->numbonuses; i++) {
    if (!(boni->bonuses[i]->countdown--)) {
      if (boni->bonuses[i]->type == BONUSREGULAR && !boni->bonuses[i]->fake) {
        gnibbles_boni_remove_bonus (boni,
                                    boni->bonuses[i]->x,
                                    boni->bonuses[i]->y);
        boni->missed++;
        gnibbles_board_level_add_bonus (board, 1);
      } else {
        gnibbles_boni_remove_bonus (boni,
                                    boni->bonuses[i]->x,
                                    boni->bonuses[i]->y);
      }
    }
  }

  for (i = 0; i < properties->numworms; i++) {
    dead[i] = !gnibbles_worm_test_move_head (worms[i]);
    status &= !dead[i];
  }

  for (i = 0; i < properties->numworms; i++) {
    if (!dead[i] && worms[i]->lives > 0 && !worms[i]->stop)
      gnibbles_worm_move_tail (worms[i]);
  }

  for (i = 0; i < properties->numworms; i++) {
    if (!dead[i] && worms[i]->lives > 0 && !worms[i]->stop)
      gnibbles_worm_move_head (worms[i]);
  }

  for (i = 0; i < properties->numworms; i++) {
    for (j = 0; j < properties->numworms; j++) {
      if (i != j
          && worms[i]->xhead == worms[j]->xhead
          && worms[i]->yhead == worms[j]->yhead
          && worms[i]->lives > 0
          && worms[j]->lives > 0
          && !worms[i]->stop)
        dead[i] = TRUE;
    }
  }

  for (i = 0; i < properties->numworms; i++) {
    if (dead[i]) {
      if (properties->numworms > 1)
        worms[i]->score *= .7;
      if (!gnibbles_worm_lose_life (worms[i])) {
        /* One of the worms lost one life, but the round continues. */
        gnibbles_worm_reset (worms[i]);
        play_sound ("crash");
      }
    }
  }

  if (status & GAMEOVER) {
    play_sound ("crash");
    play_sound ("gameover");
    return GAMEOVER;
  }

  for (i = 0; i < properties->numworms; i++) {
    if (worms[i]->human && worms[i]->lives <= 0)
      return GAMEOVER;
  }

  for (i = 0; i < properties->numworms; i++) {
    if (worms[i]->lives > 0)
      nlives += 1;
  }

  if (nlives == 1 && (properties->ai + properties->human > 1)) {
    /* There is one player left, the other AI players are dead,
     * and that player has won! */
    return VICTORY;
  } else if (nlives == 0) {
    /* There was only one worm, and it died. */
    return GAMEOVER;
  }
   /* Noone died, so the round can continue. */

  g_free (dead);
  return CONTINUE;
}
Пример #11
0
void
dlg_prop (FrWindow *window)
{
	DialogData *data;
	GtkWidget  *content_area;
	GtkWidget  *label;
	GtkWidget  *table;
	GFile      *parent;
	char       *uri;
	char       *markup;
	char       *s;
	goffset     size, uncompressed_size;
	char       *utf8_name;
	char       *title_txt;
	double      ratio;

	data = g_new (DialogData, 1);

	data->builder = _gtk_builder_new_from_resource ("properties.ui");
	if (data->builder == NULL) {
		g_free (data);
		return;
	}

	/* Get the widgets. */
	table = _gtk_builder_get_widget (data->builder, "content");


	/* Make the dialog */

	data->dialog = gtk_widget_new (GTK_TYPE_DIALOG,
				       "transient-for", GTK_WINDOW (window),
				       "modal", TRUE,
				       "use-header-bar", _gtk_settings_get_dialogs_use_header (),
				       NULL);

	content_area = gtk_dialog_get_content_area (GTK_DIALOG (data->dialog));
	gtk_container_add (GTK_CONTAINER (content_area), table);

	/* Set widgets data. */

	label = _gtk_builder_get_widget (data->builder, "p_path_label");
	parent = g_file_get_parent (fr_window_get_archive_file (window));
	uri = g_file_get_uri (parent);
	utf8_name = g_file_get_parse_name (parent);
	markup = g_strdup_printf ("<a href=\"%s\">%s</a>", uri, utf8_name);
	gtk_label_set_markup (GTK_LABEL (label), markup);

	g_free (markup);
	g_free (utf8_name);
	g_free (uri);
	g_object_unref (parent);

	/**/

	label = _gtk_builder_get_widget (data->builder, "p_name_label");
	utf8_name = _g_file_get_display_basename (fr_window_get_archive_file (window));
	gtk_label_set_text (GTK_LABEL (label), utf8_name);

	title_txt = g_strdup_printf (_("%s Properties"), utf8_name);
	gtk_window_set_title (GTK_WINDOW (data->dialog), title_txt);
	g_free (title_txt);

	g_free (utf8_name);

	/**/

	label = _gtk_builder_get_widget (data->builder, "p_mime_type_label");
	gtk_label_set_text (GTK_LABEL (label), window->archive->mime_type);

	/**/

	label = _gtk_builder_get_widget (data->builder, "p_date_label");
	s = _g_time_to_string (_g_file_get_file_mtime (fr_window_get_archive_file (window)));
	gtk_label_set_text (GTK_LABEL (label), s);
	g_free (s);

	/**/

	label = _gtk_builder_get_widget (data->builder, "p_size_label");
	size = _g_file_get_file_size (fr_window_get_archive_file (window));
	s = g_format_size (size);
	gtk_label_set_text (GTK_LABEL (label), s);
	g_free (s);

	/**/

	uncompressed_size = 0;
	if (fr_window_archive_is_present (window)) {
		int i;

		for (i = 0; i < window->archive->files->len; i++) {
			FileData *fd = g_ptr_array_index (window->archive->files, i);
			uncompressed_size += fd->size;
		}
	}

	label = _gtk_builder_get_widget (data->builder, "p_uncomp_size_label");
	s = g_format_size (uncompressed_size);
	gtk_label_set_text (GTK_LABEL (label), s);
	g_free (s);

	/**/

	label = _gtk_builder_get_widget (data->builder, "p_cratio_label");

	if (uncompressed_size != 0)
		ratio = (double) uncompressed_size / size;
	else
		ratio = 0.0;
	s = g_strdup_printf ("%0.2f", ratio);
	gtk_label_set_text (GTK_LABEL (label), s);
	g_free (s);

	/**/

	label = _gtk_builder_get_widget (data->builder, "p_files_label");
	s = g_strdup_printf ("%d", window->archive->n_regular_files);
	gtk_label_set_text (GTK_LABEL (label), s);
	g_free (s);

	/* Set the signals handlers. */

	g_signal_connect (G_OBJECT (data->dialog),
			  "destroy",
			  G_CALLBACK (destroy_cb),
			  data);

	/* Run dialog. */
	gtk_widget_show (data->dialog);
}
Пример #12
0
static void mips_jazz_init(MemoryRegion *address_space,
                           MemoryRegion *address_space_io,
                           ram_addr_t ram_size,
                           const char *cpu_model,
                           enum jazz_model_e jazz_model)
{
    char *filename;
    int bios_size, n;
    MIPSCPU *cpu;
    CPUMIPSState *env;
    qemu_irq *rc4030, *i8259;
    rc4030_dma *dmas;
    void* rc4030_opaque;
    MemoryRegion *rtc = g_new(MemoryRegion, 1);
    MemoryRegion *i8042 = g_new(MemoryRegion, 1);
    MemoryRegion *dma_dummy = g_new(MemoryRegion, 1);
    NICInfo *nd;
    DeviceState *dev;
    SysBusDevice *sysbus;
    ISABus *isa_bus;
    ISADevice *pit;
    DriveInfo *fds[MAX_FD];
    qemu_irq esp_reset, dma_enable;
    qemu_irq *cpu_exit_irq;
    MemoryRegion *ram = g_new(MemoryRegion, 1);
    MemoryRegion *bios = g_new(MemoryRegion, 1);
    MemoryRegion *bios2 = g_new(MemoryRegion, 1);

    /* init CPUs */
    if (cpu_model == NULL) {
#ifdef TARGET_MIPS64
        cpu_model = "R4000";
#else
        /* FIXME: All wrong, this maybe should be R3000 for the older JAZZs. */
        cpu_model = "24Kf";
#endif
    }
    cpu = cpu_mips_init(cpu_model);
    if (cpu == NULL) {
        fprintf(stderr, "Unable to find CPU definition\n");
        exit(1);
    }
    env = &cpu->env;
    qemu_register_reset(main_cpu_reset, cpu);

    /* allocate RAM */
    memory_region_init_ram(ram, NULL, "mips_jazz.ram", ram_size);
    vmstate_register_ram_global(ram);
    memory_region_add_subregion(address_space, 0, ram);

    memory_region_init_ram(bios, NULL, "mips_jazz.bios", MAGNUM_BIOS_SIZE);
    vmstate_register_ram_global(bios);
    memory_region_set_readonly(bios, true);
    memory_region_init_alias(bios2, NULL, "mips_jazz.bios", bios,
                             0, MAGNUM_BIOS_SIZE);
    memory_region_add_subregion(address_space, 0x1fc00000LL, bios);
    memory_region_add_subregion(address_space, 0xfff00000LL, bios2);

    /* load the BIOS image. */
    if (bios_name == NULL)
        bios_name = BIOS_FILENAME;
    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
    if (filename) {
        bios_size = load_image_targphys(filename, 0xfff00000LL,
                                        MAGNUM_BIOS_SIZE);
        g_free(filename);
    } else {
        bios_size = -1;
    }
    if (bios_size < 0 || bios_size > MAGNUM_BIOS_SIZE) {
        fprintf(stderr, "qemu: Could not load MIPS bios '%s'\n",
                bios_name);
        exit(1);
    }

    /* Init CPU internal devices */
    cpu_mips_irq_init_cpu(env);
    cpu_mips_clock_init(env);

    /* Chipset */
    rc4030_opaque = rc4030_init(env->irq[6], env->irq[3], &rc4030, &dmas,
                                address_space);
    memory_region_init_io(dma_dummy, NULL, &dma_dummy_ops, NULL, "dummy_dma", 0x1000);
    memory_region_add_subregion(address_space, 0x8000d000, dma_dummy);

    /* ISA devices */
    isa_bus = isa_bus_new(NULL, address_space_io);
    i8259 = i8259_init(isa_bus, env->irq[4]);
    isa_bus_irqs(isa_bus, i8259);
    cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
    DMA_init(0, cpu_exit_irq);
    pit = pit_init(isa_bus, 0x40, 0, NULL);
    pcspk_init(isa_bus, pit);

    /* ISA IO space at 0x90000000 */
    isa_mmio_init(0x90000000, 0x01000000);
    isa_mem_base = 0x11000000;

    /* Video card */
    switch (jazz_model) {
    case JAZZ_MAGNUM:
        dev = qdev_create(NULL, "sysbus-g364");
        qdev_init_nofail(dev);
        sysbus = SYS_BUS_DEVICE(dev);
        sysbus_mmio_map(sysbus, 0, 0x60080000);
        sysbus_mmio_map(sysbus, 1, 0x40000000);
        sysbus_connect_irq(sysbus, 0, rc4030[3]);
        {
            /* Simple ROM, so user doesn't have to provide one */
            MemoryRegion *rom_mr = g_new(MemoryRegion, 1);
            memory_region_init_ram(rom_mr, NULL, "g364fb.rom", 0x80000);
            vmstate_register_ram_global(rom_mr);
            memory_region_set_readonly(rom_mr, true);
            uint8_t *rom = memory_region_get_ram_ptr(rom_mr);
            memory_region_add_subregion(address_space, 0x60000000, rom_mr);
            rom[0] = 0x10; /* Mips G364 */
        }
        break;
    case JAZZ_PICA61:
        isa_vga_mm_init(0x40000000, 0x60000000, 0, get_system_memory());
        break;
    default:
        break;
    }

    /* Network controller */
    for (n = 0; n < nb_nics; n++) {
        nd = &nd_table[n];
        if (!nd->model)
            nd->model = g_strdup("dp83932");
        if (strcmp(nd->model, "dp83932") == 0) {
            dp83932_init(nd, 0x80001000, 2, get_system_memory(), rc4030[4],
                         rc4030_opaque, rc4030_dma_memory_rw);
            break;
        } else if (is_help_option(nd->model)) {
            fprintf(stderr, "qemu: Supported NICs: dp83932\n");
            exit(1);
        } else {
            fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd->model);
            exit(1);
        }
    }

    /* SCSI adapter */
    esp_init(0x80002000, 0,
             rc4030_dma_read, rc4030_dma_write, dmas[0],
             rc4030[5], &esp_reset, &dma_enable);

    /* Floppy */
    if (drive_get_max_bus(IF_FLOPPY) >= MAX_FD) {
        fprintf(stderr, "qemu: too many floppy drives\n");
        exit(1);
    }
    for (n = 0; n < MAX_FD; n++) {
        fds[n] = drive_get(IF_FLOPPY, 0, n);
    }
    fdctrl_init_sysbus(rc4030[1], 0, 0x80003000, fds);

    /* Real time clock */
    rtc_init(isa_bus, 1980, NULL);
    memory_region_init_io(rtc, NULL, &rtc_ops, NULL, "rtc", 0x1000);
    memory_region_add_subregion(address_space, 0x80004000, rtc);

    /* Keyboard (i8042) */
    i8042_mm_init(rc4030[6], rc4030[7], i8042, 0x1000, 0x1);
    memory_region_add_subregion(address_space, 0x80005000, i8042);

    /* Serial ports */
    if (serial_hds[0]) {
        serial_mm_init(address_space, 0x80006000, 0, rc4030[8], 8000000/16,
                       serial_hds[0], DEVICE_NATIVE_ENDIAN);
    }
    if (serial_hds[1]) {
        serial_mm_init(address_space, 0x80007000, 0, rc4030[9], 8000000/16,
                       serial_hds[1], DEVICE_NATIVE_ENDIAN);
    }

    /* Parallel port */
    if (parallel_hds[0])
        parallel_mm_init(address_space, 0x80008000, 0, rc4030[0],
                         parallel_hds[0]);

    /* FIXME: missing Jazz sound at 0x8000c000, rc4030[2] */

    /* NVRAM */
    dev = qdev_create(NULL, "ds1225y");
    qdev_init_nofail(dev);
    sysbus = SYS_BUS_DEVICE(dev);
    sysbus_mmio_map(sysbus, 0, 0x80009000);

    /* LED indicator */
    sysbus_create_simple("jazz-led", 0x8000f000, NULL);
}
Пример #13
0
/**
 * Statistic Viewer's constructor
 *
 * This constructor is used to create StatisticViewerData data structure.
 * @return The Statistic viewer data created.
 */
StatisticViewerData *
gui_statistic(LttvPluginTab *ptab)
{
  GtkCellRenderer *renderer;
  GtkTreeViewColumn *column;

  StatisticViewerData* statistic_viewer_data = g_new(StatisticViewerData,1);
  statistic_viewer_data->live_trace_count = 0;
  Tab *tab = ptab->tab;
  statistic_viewer_data->tab  = tab;
  statistic_viewer_data->ptab  = ptab;
 // statistic_viewer_data->stats  =
 //         lttvwindow_get_traceset_stats(statistic_viewer_data->tab);
 // statistic_viewer_data->calculate_stats = 
 //   statistic_insert_traceset_stats((void *)statistic_viewer_data->stats);

  lttvwindow_register_traceset_notify(statistic_viewer_data->tab,
                                      statistic_traceset_changed,
                                      statistic_viewer_data);
  statistic_viewer_data->statistic_hash = g_hash_table_new_full(g_str_hash,
                                                  g_str_equal,
                                                  statistic_destroy_hash_key,
                                                  NULL);

  statistic_viewer_data->hpaned_v  = gtk_hpaned_new();
  statistic_viewer_data->store_m = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING);
  statistic_viewer_data->tree_v  = 
    gtk_tree_view_new_with_model (
        GTK_TREE_MODEL (statistic_viewer_data->store_m));
  g_object_unref (G_OBJECT (statistic_viewer_data->store_m));

  // Setup the selection handler
  statistic_viewer_data->select_c = gtk_tree_view_get_selection (GTK_TREE_VIEW (statistic_viewer_data->tree_v));
  gtk_tree_selection_set_mode (statistic_viewer_data->select_c, GTK_SELECTION_SINGLE);
  g_signal_connect (G_OBJECT (statistic_viewer_data->select_c), "changed",
        G_CALLBACK (tree_selection_changed_cb),
        statistic_viewer_data);

  renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes ("Statistic Name",
                 renderer,
                 "text", NAME_COLUMN,
                 NULL);
  gtk_tree_view_column_set_alignment (column, 0.0);
  //  gtk_tree_view_column_set_fixed_width (column, 45);
  gtk_tree_view_append_column (GTK_TREE_VIEW (statistic_viewer_data->tree_v), column);


  gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (statistic_viewer_data->tree_v), FALSE);

  statistic_viewer_data->scroll_win_tree = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(statistic_viewer_data->scroll_win_tree), 
         GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);

  gtk_container_add (GTK_CONTAINER (statistic_viewer_data->scroll_win_tree), statistic_viewer_data->tree_v);
  gtk_paned_pack1(GTK_PANED(statistic_viewer_data->hpaned_v),statistic_viewer_data->scroll_win_tree, TRUE, FALSE);
  gtk_paned_set_position(GTK_PANED(statistic_viewer_data->hpaned_v), 160);

  statistic_viewer_data->scroll_win_text = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(statistic_viewer_data->scroll_win_text), 
         GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);

  statistic_viewer_data->text_v = gtk_text_view_new ();
  
  gtk_text_view_set_editable(GTK_TEXT_VIEW(statistic_viewer_data->text_v),FALSE);
  gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(statistic_viewer_data->text_v),FALSE);
  gtk_container_add (GTK_CONTAINER (statistic_viewer_data->scroll_win_text), statistic_viewer_data->text_v);
  gtk_paned_pack2(GTK_PANED(statistic_viewer_data->hpaned_v), statistic_viewer_data->scroll_win_text, TRUE, FALSE);

  gtk_container_set_border_width(
      GTK_CONTAINER(statistic_viewer_data->hpaned_v), 1);
  
  gtk_widget_show(statistic_viewer_data->scroll_win_tree);
  gtk_widget_show(statistic_viewer_data->scroll_win_text);
  gtk_widget_show(statistic_viewer_data->tree_v);
  gtk_widget_show(statistic_viewer_data->text_v);
  gtk_widget_show(statistic_viewer_data->hpaned_v);

  g_object_set_data_full(
      G_OBJECT(guistatistic_get_widget(statistic_viewer_data)),
      "statistic_viewer_data",
      statistic_viewer_data,
      (GDestroyNotify)gui_statistic_destructor);

  /* Add the object's information to the module's array */
  g_statistic_viewer_data_list = g_slist_append(
      g_statistic_viewer_data_list,
      statistic_viewer_data);

  request_background_data(statistic_viewer_data);
 
  return statistic_viewer_data;
}
Пример #14
0
ArvStream *
arv_gv_stream_new (GInetAddress *device_address, guint16 port,
		   ArvStreamCallback callback, void *user_data,
		   guint64 timestamp_tick_frequency,
		   guint packet_size)
{
	ArvGvStream *gv_stream;
	ArvStream *stream;
	GInetAddress *incoming_inet_address;
	ArvGvStreamThreadData *thread_data;

	g_return_val_if_fail (G_IS_INET_ADDRESS (device_address), NULL);
	g_return_val_if_fail (packet_size > ARV_GVSP_PACKET_PROTOCOL_OVERHEAD, NULL);

	gv_stream = g_object_new (ARV_TYPE_GV_STREAM, NULL);

	stream = ARV_STREAM (gv_stream);

	gv_stream->priv->socket = g_socket_new (G_SOCKET_FAMILY_IPV4,
					  G_SOCKET_TYPE_DATAGRAM,
					  G_SOCKET_PROTOCOL_UDP, NULL);

	incoming_inet_address = g_inet_address_new_any (G_SOCKET_FAMILY_IPV4);
	gv_stream->priv->incoming_address = g_inet_socket_address_new (incoming_inet_address, port);
	g_object_unref (incoming_inet_address);

	g_socket_bind (gv_stream->priv->socket, gv_stream->priv->incoming_address, TRUE, NULL);

	thread_data = g_new (ArvGvStreamThreadData, 1);
	thread_data->stream = stream;
	thread_data->callback = callback;
	thread_data->user_data = user_data;
	thread_data->socket = gv_stream->priv->socket;
	thread_data->device_address = g_inet_socket_address_new (device_address, ARV_GVCP_PORT);
	thread_data->packet_resend = ARV_GV_STREAM_PACKET_RESEND_ALWAYS;
	thread_data->packet_timeout_us = ARV_GV_STREAM_PACKET_TIMEOUT_US_DEFAULT;
	thread_data->frame_retention_us = ARV_GV_STREAM_FRAME_RETENTION_US_DEFAULT;
	thread_data->stream_timeout_us = ARV_GV_STREAM_POLL_TIMEOUT_US;
	thread_data->timestamp_tick_frequency = timestamp_tick_frequency;
	thread_data->data_size = packet_size - ARV_GVSP_PACKET_PROTOCOL_OVERHEAD;
	thread_data->cancel = FALSE;

	thread_data->packet_id = 65300;
	thread_data->last_frame_id = 0;

	thread_data->n_completed_buffers = 0;
	thread_data->n_failures = 0;
	thread_data->n_underruns = 0;
	thread_data->n_aborteds = 0;
	thread_data->n_timeouts = 0;
	thread_data->n_missing_frames = 0;

	thread_data->n_size_mismatch_errors = 0;

	thread_data->n_received_packets = 0;
	thread_data->n_missing_packets = 0;
	thread_data->n_error_packets = 0;
	thread_data->n_ignored_packets = 0;
	thread_data->n_resent_packets = 0;
	thread_data->n_resend_requests = 0;
	thread_data->n_duplicated_packets = 0;

	thread_data->statistic = arv_statistic_new (1, 5000, 200, 0);
	thread_data->statistic_count = 0;

	arv_statistic_set_name (thread_data->statistic, 0, "Buffer reception time");

	thread_data->socket_buffer_option = ARV_GV_STREAM_SOCKET_BUFFER_FIXED;
	thread_data->socket_buffer_size = 0;
	thread_data->current_socket_buffer_size = 0;

	gv_stream->priv->thread_data = thread_data;

	gv_stream->priv->thread = arv_g_thread_new ("arv_gv_stream", arv_gv_stream_thread, gv_stream->priv->thread_data);

	return ARV_STREAM (gv_stream);
}
Пример #15
0
JNIEXPORT jintArray
JNICALL Java_GdaInputStream_readData (JNIEnv *jenv, G_GNUC_UNUSED jobject obj,
				      jlong gda_blob_pointer, jlong offset, jlong size)
{
	GdaBlob *blob = (GdaBlob*) jni_jlong_to_cpointer (gda_blob_pointer);
	jintArray jdata;
	if (!blob) {
		jclass cls;
		cls = (*jenv)->FindClass (jenv, "java/lang/IllegalArgumentException");
		if (!cls) {
			/* Unable to find the exception class */
			return NULL;
		}
		(*jenv)->ThrowNew (jenv, cls, _("Invalid argument: NULL"));
		return NULL;
	}

	guchar *raw_data;
	jint *data;
	GdaBlob *nblob = NULL;
	gint real_size;
	if (blob->op) {
		nblob = g_new0 (GdaBlob, 1);
		gda_blob_set_op (nblob, blob->op);
		real_size =  gda_blob_op_read (nblob->op, nblob, offset, size);
		if (real_size < 0) {
			/* throw an exception */
			jclass cls;
			cls = (*jenv)->FindClass (jenv, "java/sql/SQLException");
			if (!cls) {
				/* Unable to find the exception class */
				return NULL;
			}
			(*jenv)->ThrowNew (jenv, cls, _("Can't read BLOB"));
			return NULL;
		}
		raw_data = ((GdaBinary*) nblob)->data;
	}
	else {
		GdaBinary *bin = (GdaBinary *) blob;
		if (offset + size > bin->binary_length)
			real_size = bin->binary_length - offset;
		else
			real_size = size;
		raw_data = bin->data + offset;
	}

	/* convert bin->data to a jintArray */
	int i;
	data = g_new (jint, real_size);
	for (i = 0; i < real_size; i++) 
		data[i] = (jint) (raw_data[i]);

	jdata = (*jenv)->NewIntArray (jenv, real_size);
	if ((*jenv)->ExceptionCheck (jenv)) {
		jdata = NULL;
		goto out;
	}
	
	(*jenv)->SetIntArrayRegion (jenv, jdata, 0, real_size, data);
	if ((*jenv)->ExceptionCheck (jenv)) {
		jdata = NULL;
		(*jenv)->DeleteLocalRef (jenv, jdata);
		goto out;
	}

 out:
	g_free (data);
	if (nblob)
		gda_blob_free ((gpointer) nblob);

	return jdata;
}
Пример #16
0
static void labx_nios2_init(QEMUMachineInitArgs *args)
{
    MemoryRegion *address_space_mem = get_system_memory();

    int kernel_size;
    int fdt_size;
    void *fdt = get_device_tree(&fdt_size);
    hwaddr ddr_base = get_dram_base(fdt);
    MemoryRegion *phys_lmb_bram = g_new(MemoryRegion, 1);
    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
    MemoryRegion *phys_ram_alias = g_new(MemoryRegion, 1);

    /* Attach emulated BRAM through the LMB. LMB size is not specified
       in the device-tree but there must be one to hold the vector table. */
    memory_region_init_ram(phys_lmb_bram, NULL, "nios2.lmb_bram", LMB_BRAM_SIZE);
    vmstate_register_ram_global(phys_lmb_bram);
    memory_region_add_subregion(address_space_mem, 0x00000000, phys_lmb_bram);

    memory_region_init_ram(phys_ram, NULL, "nios2.ram", ram_size);
    vmstate_register_ram_global(phys_ram);
    memory_region_add_subregion(address_space_mem, ddr_base, phys_ram);
    memory_region_init_alias(phys_ram_alias, NULL, "nios2.ram.mirror",
                             phys_ram, 0, ram_size);
    memory_region_add_subregion(address_space_mem, ddr_base + 0xc0000000,
                                phys_ram_alias);

    /* Create cpus listed in the device-tree */
    add_to_force_table(cpus_probe, "cpu-probe", NULL);

    /* Create other devices listed in the device-tree */
    fdt_init_destroy_fdti(fdt_generic_create_machine(fdt, NULL));

    if (args->kernel_filename) {
        uint64_t entry = 0, low = 0, high = 0;
        uint32_t base32 = 0;

        /* Boots a kernel elf binary.  */
        kernel_size = load_elf(args->kernel_filename, NULL, NULL,
                               &entry, &low, &high,
                               0, ELF_MACHINE, 0);
        base32 = entry;
        if (base32 == 0xc0000000) {
            kernel_size = load_elf(args->kernel_filename, translate_kernel_address,
                                   NULL, &entry, NULL, NULL,
                                   0, ELF_MACHINE, 0);
        }
        /* Always boot into physical ram.  */
        boot_info.bootstrap_pc = ddr_base + 0xc0000000 + (entry & 0x07ffffff);

        /* If it wasn't an ELF image, try an u-boot image.  */
        if (kernel_size < 0) {
            hwaddr uentry, loadaddr;

            kernel_size = load_uimage(args->kernel_filename, &uentry, &loadaddr, 0);
            boot_info.bootstrap_pc = uentry;
            high = (loadaddr + kernel_size + 3) & ~3;
        }

        /* Not an ELF image nor an u-boot image, try a RAW image.  */
        if (kernel_size < 0) {
            kernel_size = load_image_targphys(args->kernel_filename, ddr_base,
                                              ram_size);
            boot_info.bootstrap_pc = ddr_base;
            high = (ddr_base + kernel_size + 3) & ~3;
        }

        if (args->initrd_filename) {
            uint32_t initrd_base = 0x88c00000;
            uint32_t initrd_size =
                load_image_targphys(args->initrd_filename, initrd_base,
                                    ram_size - initrd_base);
            if (initrd_size <= 0) {
                fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
                        args->initrd_filename);
                exit(1);
            }

            boot_info.initrd = initrd_base;
        } else {
            boot_info.initrd = 0x00000000;
        }

        boot_info.cmdline = high + 4096;
        if (args->kernel_cmdline && strlen(args->kernel_cmdline)) {
            pstrcpy_targphys("cmdline", boot_info.cmdline, 256, args->kernel_cmdline);
        }
        /* Provide a device-tree.  */
        boot_info.fdt = boot_info.cmdline + 4096;
        labx_load_device_tree(boot_info.fdt, ram_size,
                              0, 0,
                              args->kernel_cmdline);
    }
}
Пример #17
0
/**
 * g_utf8_to_ucs4_fast:
 * @str: a UTF-8 encoded string
 * @len: the maximum length of @str to use, in bytes. If @len < 0,
 *     then the string is nul-terminated.
 * @items_written: (allow-none): location to store the number of
 *     characters in the result, or %NULL.
 *
 * Convert a string from UTF-8 to a 32-bit fixed width
 * representation as UCS-4, assuming valid UTF-8 input.
 * This function is roughly twice as fast as g_utf8_to_ucs4()
 * but does no error checking on the input. A trailing 0 character
 * will be added to the string after the converted text.
 *
 * Return value: a pointer to a newly allocated UCS-4 string.
 *     This value must be freed with g_free().
 */
gunichar *
g_utf8_to_ucs4_fast (const gchar *str,
                     glong        len,
                     glong       *items_written)
{
    gunichar *result;
    gint n_chars, i;
    const gchar *p;

    g_return_val_if_fail (str != NULL, NULL);

    p = str;
    n_chars = 0;
    if (len < 0)
    {
        while (*p)
        {
            p = g_utf8_next_char (p);
            ++n_chars;
        }
    }
    else
    {
        while (p < str + len && *p)
        {
            p = g_utf8_next_char (p);
            ++n_chars;
        }
    }

    result = g_new (gunichar, n_chars + 1);

    p = str;
    for (i=0; i < n_chars; i++)
    {
        gunichar wc = (guchar)*p++;

        if (wc < 0x80)
        {
            result[i] = wc;
        }
        else
        {
            gunichar mask = 0x40;

            if (G_UNLIKELY ((wc & mask) == 0))
            {
                /* It's an out-of-sequence 10xxxxxxx byte.
                 * Rather than making an ugly hash of this and the next byte
                 * and overrunning the buffer, it's more useful to treat it
                 * with a replacement character
                 */
                result[i] = 0xfffd;
                continue;
            }

            do
            {
                wc <<= 6;
                wc |= (guchar)(*p++) & 0x3f;
                mask <<= 5;
            }
            while((wc & mask) != 0);

            wc &= mask - 1;

            result[i] = wc;
        }
    }
    result[i] = 0;

    if (items_written)
        *items_written = i;

    return result;
}
Пример #18
0
static void
gog_chart_populate_editor (GogObject *gobj,
			   GOEditor *editor,
			   G_GNUC_UNUSED GogDataAllocator *dalloc,
			   GOCmdContext *cc)
{
	static guint chart_pref_page = 0;

	GtkBuilder *gui;
	PlotAreaPrefState *state;
	gboolean is_plot_area_manual;
	GogViewAllocation plot_area;
	GtkWidget *w;
	GogChart *chart = GOG_CHART (gobj);

	g_return_if_fail (chart != NULL);

	gui = go_gtk_builder_load_internal ("res:go:graph/gog-plot-prefs.ui", GETTEXT_PACKAGE, cc);
	g_return_if_fail (gui != NULL);

	(GOG_OBJECT_CLASS(chart_parent_klass)->populate_editor) (gobj, editor, dalloc, cc);

	state = g_new  (PlotAreaPrefState, 1);
	state->chart = chart;
	state->gui = gui;

	g_object_ref (chart);
	is_plot_area_manual = gog_chart_get_plot_area (chart, &plot_area);

	state->x_spin = go_gtk_builder_get_widget (gui, "x_spin");
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->x_spin),
				   plot_area.x * 100.0);
	g_signal_connect (G_OBJECT (state->x_spin), "value-changed",
			  G_CALLBACK (cb_plot_area_changed), state);

	state->y_spin = go_gtk_builder_get_widget (gui, "y_spin");
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->y_spin),
				   plot_area.y * 100.0);
	g_signal_connect (G_OBJECT (state->y_spin), "value-changed",
			  G_CALLBACK (cb_plot_area_changed), state);

	state->w_spin = go_gtk_builder_get_widget (gui, "w_spin");
	gtk_spin_button_set_range (GTK_SPIN_BUTTON (state->w_spin),
				   0.0, (1.0 - plot_area.x) * 100.0);
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->w_spin),
				   100.0 * plot_area.w);
	state->w_spin_signal = g_signal_connect (G_OBJECT (state->w_spin), "value-changed",
						 G_CALLBACK (cb_plot_area_changed), state);

	state->h_spin = go_gtk_builder_get_widget (gui, "h_spin");
	gtk_spin_button_set_range (GTK_SPIN_BUTTON (state->h_spin),
				   0.0, (1.0 - plot_area.y) * 100.0);
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->h_spin),
				   100.0 * plot_area.h);
	state->h_spin_signal = g_signal_connect (G_OBJECT (state->h_spin), "value-changed",
						 G_CALLBACK (cb_plot_area_changed), state);

	state->position_select_combo = go_gtk_builder_get_widget (gui, "position_select_combo");
	gtk_combo_box_set_active (GTK_COMBO_BOX (state->position_select_combo),
				  is_plot_area_manual ? 1 : 0);
	state->manual_setting_grid = go_gtk_builder_get_widget (gui, "manual-setting-grid");
	if (!is_plot_area_manual)
		gtk_widget_hide (state->manual_setting_grid);

	g_signal_connect (G_OBJECT (state->position_select_combo),
			  "changed", G_CALLBACK (cb_manual_position_changed), state);

	w = go_gtk_builder_get_widget (gui, "gog-plot-prefs");
	g_signal_connect_swapped (G_OBJECT (w), "destroy", G_CALLBACK (plot_area_pref_state_free), state);
	go_editor_add_page (editor, w, _("Plot area"));

	go_editor_set_store_page (editor, &chart_pref_page);
}
Пример #19
0
static S57_geo   *_ogrLoadObject(const char *objname, void *feature, OGRGeometryH hGeomNext)
{
    S57_geo           *geoData = NULL;
    OGRGeometryH       hGeom   = NULL;
    OGRwkbGeometryType eType   = wkbNone;

    if (NULL != feature)
        hGeom = OGR_F_GetGeometryRef((OGRFeatureH)feature);
    else
        hGeom = hGeomNext;

    if (NULL != hGeom)
        eType = OGR_G_GetGeometryType(hGeom);
    else
        eType = wkbNone; // DSIS

    switch (eType) {
        // POINT
        case wkbPoint25D:
        case wkbPoint: {
            geocoord *pointxyz = g_new(geocoord, 3);

            pointxyz[0] = OGR_G_GetX(hGeom, 0);
            pointxyz[1] = OGR_G_GetY(hGeom, 0);
            pointxyz[2] = OGR_G_GetZ(hGeom, 0);

            geoData = S57_setPOINT(pointxyz);
            _setExtent(geoData, hGeom);

            break;
        }

        // LINE
        case wkbLineString25D:
        case wkbLineString: {
            int count = OGR_G_GetPointCount(hGeom);

            // NOTE: Edge might have 0 node
            //if (count < 2) {
            //    PRINTF("WARNING: a line with less than 2 points!?\n");
            //    //g_assert(0);
            //    return NULL;
            //}

            geocoord *linexyz = NULL;
            if (0 != count)
                linexyz = g_new(geocoord, 3*count);

            for (int node=0; node<count; ++node) {
            //for (idx=0, node=count-1; node>=0; --node) {
                linexyz[node*3+0] = OGR_G_GetX(hGeom, node);
                linexyz[node*3+1] = OGR_G_GetY(hGeom, node);
                linexyz[node*3+2] = OGR_G_GetZ(hGeom, node);
            }

            geoData = S57_setLINES(count, linexyz);

            _setExtent(geoData, hGeom);

            break;
        }

        // AREA
        case wkbPolygon25D:
        case wkbPolygon: {
            guint        nRingCount = OGR_G_GetGeometryCount(hGeom);
            guint       *ringxyznbr;
            geocoord   **ringxyz;

            ringxyznbr = g_new(guint,      nRingCount);
            ringxyz    = g_new(geocoord *, nRingCount);

            for (guint iRing=0; iRing<nRingCount; ++iRing) {
                OGRGeometryH hRing;
                guint vert_count = _getGeoPtCount(hGeom, iRing, &hRing);

                ringxyznbr[iRing] = vert_count;

                // skip this ring if no vertex
                if (0 == vert_count) {
                    // FIXME: what should be done here,
                    // FIX: S52 - discard this ring or the object or the layer or the whole chart (update)
                    // FIX: GDAL/OGR - is it a bug in the reader or in the chart it self (S57)
                    // FIX: or this is an empty Geo
                    PRINTF("WARNING: wkbPolygon, empty ring  (%s)\n", objname);
                    continue;
                }

                // why add a 1 !?!
                //ringxyz[iRing]    = g_new(geocoord, (vert_count+1)*3*sizeof(geocoord));
                ringxyz[iRing]    = g_new(geocoord, vert_count*3*sizeof(geocoord));

                // debug: check winding
                //for (i = n-1, j = 0; j < n; i = j, j++)
                //{
                //     ai = x[i] * y[j] - x[j] * y[i];
                //}

                double area = 0;
                //for (i=0; i<vert_count; i++) {
                for (guint i=0; i<vert_count-1; i++) {
                    double x1 = OGR_G_GetX(hRing, i);
                    double y1 = OGR_G_GetY(hRing, i);
                    double x2 = OGR_G_GetX(hRing, i+1);
                    double y2 = OGR_G_GetY(hRing, i+1);
                    area += (x1*y2) - (x2*y1);
                }

                // if last vertex is NOT the first vertex
                //for (i=vert_count-1, j=0; j<vert_count; i=j, ++j) {
                //    double x1 = OGR_G_GetX(hRing, i);
                //    double y1 = OGR_G_GetY(hRing, i);
                //    double x2 = OGR_G_GetX(hRing, j);
                //    double y2 = OGR_G_GetY(hRing, j);
                //    area += (x1*y2) - (x2*y1);
                //}

                //int close = 0;
                if ( (OGR_G_GetX(hRing, 0) == OGR_G_GetX(hRing, vert_count-1)) &&
                     (OGR_G_GetY(hRing, 0) == OGR_G_GetY(hRing, vert_count-1)) )
                    //close = 1;
                    ;
                else {
                    PRINTF("ERROR: S-57 ring (AREA) not closed (%s)\n", objname);
                    g_assert(0);
                }

                // CW = 1
                //PRINTF("AREA(%i): %s %i\n", iRing, (area >= 0.0) ? "CW" : "CCW", close);

                //if ((area<0.0) && (0==iRing)) {
                //if (area<0.0) {
                // reverse winding
                if (area > 0.0) {
                    // if first ring put winding CCW
                    if (0==iRing) {
                        for (guint node=0; node<vert_count; ++node) {
                            ringxyz[iRing][node*3+0] = OGR_G_GetX(hRing, vert_count-node-1);
                            ringxyz[iRing][node*3+1] = OGR_G_GetY(hRing, vert_count-node-1);
                            ringxyz[iRing][node*3+2] = OGR_G_GetZ(hRing, vert_count-node-1);
                        }
                    }


                    else {
                        for (guint node=0; node<vert_count; ++node) {
                            ringxyz[iRing][node*3+0] = OGR_G_GetX(hRing, node);
                            ringxyz[iRing][node*3+1] = OGR_G_GetY(hRing, node);
                            ringxyz[iRing][node*3+2] = OGR_G_GetZ(hRing, node);
                        }
                    }


                } else {

                    if (0==iRing) {
                    // if NOT first ring put winding CW
                        for (guint node=0; node<vert_count; ++node) {
                            ringxyz[iRing][node*3+0] = OGR_G_GetX(hRing, node);
                            ringxyz[iRing][node*3+1] = OGR_G_GetY(hRing, node);
                            ringxyz[iRing][node*3+2] = OGR_G_GetZ(hRing, node);
                        }


                     } else {
                        for (guint node=0; node<vert_count; ++node) {
                            ringxyz[iRing][node*3+0] = OGR_G_GetX(hRing, vert_count-node-1);
                            ringxyz[iRing][node*3+1] = OGR_G_GetY(hRing, vert_count-node-1);
                            ringxyz[iRing][node*3+2] = OGR_G_GetZ(hRing, vert_count-node-1);
                        }
                    }

                }
            }     // for loop

            geoData = S57_setAREAS(nRingCount, ringxyznbr, ringxyz);
            _setExtent(geoData, hGeom);

            if (0==strcmp(WORLD_BASENM, objname)) {
                // Note: loading shapefile as a 'marfea' use a transparent fill so NODATA
                // is still visible (seem better than 'mnufea' wich has no colour fill)
                S57_setName(geoData, "marfea");

                // pslb3_2.pdf (p. II-22): Mariners' Object Class: Manufacturers' feature
                //    Note that manufacturers' areas, whether non-chart or chart areas, should not use area colour fill.
                //S57_setName(geoData, "mnufea");
            }

            break;
        }

#ifdef S52_USE_WORLD
        // shapefile area
        case wkbMultiPolygon: {
            guint nPolyCount = OGR_G_GetGeometryCount(hGeom);
            for (guint iPoly=0; iPoly<nPolyCount; ++iPoly) {
                OGRGeometryH hGeomNext = OGR_G_GetGeometryRef(hGeom, iPoly);
                // recursion
                S57_geo *geo = _ogrLoadObject(objname, NULL, hGeomNext);
                if (NULL == geoData)
                    geoData = geo;
                else
                    S57_setNextPoly(geoData, geo);

            }
            break;
        }
#endif

        case wkbGeometryCollection:
        case wkbMultiLineString: {
            PRINTF("WARNING: wkbGeometryCollection & wkbMultiLineString not handled \n");
            g_assert(0);  // land here if GDAL/OGR was patched multi-line
            break;
        }

        case wkbNone:
            // DSID layer get here
            geoData = S57_set_META();
            break; // META_T

        case wkbMultiPoint:
            // ogr SPLIT_MULTIPOINT prob !!
            PRINTF("DEBUG: Multi-Pass!!!\n");
            //PRINTF("ERROR: set env var OGR_S57_OPTIONS to SPLIT_MULTIPOINT:ON\n");
            //PRINTF("FIXME: or wkbMultiLineString found!\n");
            //g_assert_not_reached(); // MultiLineString (need this for line removal)

            //geoData = S57_set_META();

            //GvCollectionShape *collection  = (GvCollectionShape *) shape;
            //int nCollection = gv_shape_collection_get_count(shape);
            break;

        default:
            // FIXME: find a decent default (see openev/gvshapes.h)!!!
            PRINTF("WKB type not handled  = %i %0x\n", eType, eType);
            g_assert(0); 

    }

    // debug
    //PRINTF("name: %s\n", objname);

    return geoData;
}
Пример #20
0
static void
draw_frame (TestState *state)
{
  CoglTexture *tex = create_texture_3d (test_ctx);
  CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
  typedef struct { float x, y, s, t, r; } Vert;
  CoglPrimitive *primitive;
  CoglAttributeBuffer *attribute_buffer;
  CoglAttribute *attributes[2];
  Vert *verts, *v;
  int i;

  cogl_pipeline_set_layer_texture (pipeline, 0, tex);
  cogl_object_unref (tex);
  cogl_pipeline_set_layer_filters (pipeline, 0,
                                   COGL_PIPELINE_FILTER_NEAREST,
                                   COGL_PIPELINE_FILTER_NEAREST);

  /* Render the texture repeated horizontally twice using a regular
     cogl rectangle. This should end up with the r texture coordinates
     as zero */
  cogl_framebuffer_draw_textured_rectangle (test_fb, pipeline,
                                            0.0f, 0.0f, TEX_WIDTH * 2, TEX_HEIGHT,
                                            0.0f, 0.0f, 2.0f, 1.0f);

  /* Render all of the images in the texture using coordinates from a
     CoglPrimitive */
  v = verts = g_new (Vert, 4 * TEX_DEPTH);
  for (i = 0; i < TEX_DEPTH; i++)
    {
      float r = (i + 0.5f) / TEX_DEPTH;

      v->x = i * TEX_WIDTH;
      v->y = TEX_HEIGHT;
      v->s = 0;
      v->t = 0;
      v->r = r;
      v++;

      v->x = i * TEX_WIDTH;
      v->y = TEX_HEIGHT * 2;
      v->s = 0;
      v->t = 1;
      v->r = r;
      v++;

      v->x = i * TEX_WIDTH + TEX_WIDTH;
      v->y = TEX_HEIGHT * 2;
      v->s = 1;
      v->t = 1;
      v->r = r;
      v++;

      v->x = i * TEX_WIDTH + TEX_WIDTH;
      v->y = TEX_HEIGHT;
      v->s = 1;
      v->t = 0;
      v->r = r;
      v++;
    }

  attribute_buffer = cogl_attribute_buffer_new (test_ctx,
                                                4 * TEX_DEPTH * sizeof (Vert),
                                                verts);
  attributes[0] = cogl_attribute_new (attribute_buffer,
                                      "cogl_position_in",
                                      sizeof (Vert),
                                      G_STRUCT_OFFSET (Vert, x),
                                      2, /* n_components */
                                      COGL_ATTRIBUTE_TYPE_FLOAT);
  attributes[1] = cogl_attribute_new (attribute_buffer,
                                      "cogl_tex_coord_in",
                                      sizeof (Vert),
                                      G_STRUCT_OFFSET (Vert, s),
                                      3, /* n_components */
                                      COGL_ATTRIBUTE_TYPE_FLOAT);
  primitive = cogl_primitive_new_with_attributes (COGL_VERTICES_MODE_TRIANGLES,
                                                  6 * TEX_DEPTH,
                                                  attributes,
                                                  2 /* n_attributes */);

  cogl_primitive_set_indices (primitive,
                              cogl_get_rectangle_indices (test_ctx,
                                                          TEX_DEPTH),
                              6 * TEX_DEPTH);

  cogl_primitive_draw (primitive, test_fb, pipeline);

  g_free (verts);

  cogl_object_unref (primitive);
  cogl_object_unref (attributes[0]);
  cogl_object_unref (attributes[1]);
  cogl_object_unref (attribute_buffer);
  cogl_object_unref (pipeline);
}
Пример #21
0
/* PowerPC PREP hardware initialisation */
static void ppc_prep_init(QEMUMachineInitArgs *args)
{
    ram_addr_t ram_size = args->ram_size;
    const char *cpu_model = args->cpu_model;
    const char *kernel_filename = args->kernel_filename;
    const char *kernel_cmdline = args->kernel_cmdline;
    const char *initrd_filename = args->initrd_filename;
    const char *boot_device = args->boot_order;
    MemoryRegion *sysmem = get_system_memory();
    PowerPCCPU *cpu = NULL;
    CPUPPCState *env = NULL;
    nvram_t nvram;
    M48t59State *m48t59;
#if 0
    MemoryRegion *xcsr = g_new(MemoryRegion, 1);
#endif
    int linux_boot, i, nb_nics1;
    MemoryRegion *ram = g_new(MemoryRegion, 1);
    MemoryRegion *vga = g_new(MemoryRegion, 1);
    uint32_t kernel_base, initrd_base;
    long kernel_size, initrd_size;
    DeviceState *dev;
    PCIHostState *pcihost;
    PCIBus *pci_bus;
    PCIDevice *pci;
    ISABus *isa_bus;
    ISADevice *isa;
    qemu_irq *cpu_exit_irq;
    int ppc_boot_device;
    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];

    sysctrl = g_malloc0(sizeof(sysctrl_t));

    linux_boot = (kernel_filename != NULL);

    /* init CPUs */
    if (cpu_model == NULL)
        cpu_model = "602";
    for (i = 0; i < smp_cpus; i++) {
        cpu = cpu_ppc_init(cpu_model);
        if (cpu == NULL) {
            fprintf(stderr, "Unable to find PowerPC CPU definition\n");
            exit(1);
        }
        env = &cpu->env;

        if (env->flags & POWERPC_FLAG_RTC_CLK) {
            /* POWER / PowerPC 601 RTC clock frequency is 7.8125 MHz */
            cpu_ppc_tb_init(env, 7812500UL);
        } else {
            /* Set time-base frequency to 100 Mhz */
            cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
        }
        qemu_register_reset(ppc_prep_reset, cpu);
    }

    /* allocate RAM */
    memory_region_init_ram(ram, NULL, "ppc_prep.ram", ram_size);
    vmstate_register_ram_global(ram);
    memory_region_add_subregion(sysmem, 0, ram);

    if (linux_boot) {
        kernel_base = KERNEL_LOAD_ADDR;
        /* now we can load the kernel */
        kernel_size = load_image_targphys(kernel_filename, kernel_base,
                                          ram_size - kernel_base);
        if (kernel_size < 0) {
            hw_error("qemu: could not load kernel '%s'\n", kernel_filename);
            exit(1);
        }
        /* load initrd */
        if (initrd_filename) {
            initrd_base = INITRD_LOAD_ADDR;
            initrd_size = load_image_targphys(initrd_filename, initrd_base,
                                              ram_size - initrd_base);
            if (initrd_size < 0) {
                hw_error("qemu: could not load initial ram disk '%s'\n",
                          initrd_filename);
            }
        } else {
            initrd_base = 0;
            initrd_size = 0;
        }
        ppc_boot_device = 'm';
    } else {
        kernel_base = 0;
        kernel_size = 0;
        initrd_base = 0;
        initrd_size = 0;
        ppc_boot_device = '\0';
        /* For now, OHW cannot boot from the network. */
        for (i = 0; boot_device[i] != '\0'; i++) {
            if (boot_device[i] >= 'a' && boot_device[i] <= 'f') {
                ppc_boot_device = boot_device[i];
                break;
            }
        }
        if (ppc_boot_device == '\0') {
            fprintf(stderr, "No valid boot device for Mac99 machine\n");
            exit(1);
        }
    }

    if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {
        hw_error("Only 6xx bus is supported on PREP machine\n");
    }

    dev = qdev_create(NULL, "raven-pcihost");
    if (bios_name == NULL) {
        bios_name = BIOS_FILENAME;
    }
    qdev_prop_set_string(dev, "bios-name", bios_name);
    qdev_prop_set_uint32(dev, "elf-machine", ELF_MACHINE);
    pcihost = PCI_HOST_BRIDGE(dev);
    object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev), NULL);
    qdev_init_nofail(dev);
    pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0");
    if (pci_bus == NULL) {
        fprintf(stderr, "Couldn't create PCI host controller.\n");
        exit(1);
    }
    sysctrl->contiguous_map_irq = qdev_get_gpio_in(dev, 0);

    /* PCI -> ISA bridge */
    pci = pci_create_simple(pci_bus, PCI_DEVFN(1, 0), "i82378");
    cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
    cpu = POWERPC_CPU(first_cpu);
    qdev_connect_gpio_out(&pci->qdev, 0,
                          cpu->env.irq_inputs[PPC6xx_INPUT_INT]);
    qdev_connect_gpio_out(&pci->qdev, 1, *cpu_exit_irq);
    sysbus_connect_irq(&pcihost->busdev, 0, qdev_get_gpio_in(&pci->qdev, 9));
    sysbus_connect_irq(&pcihost->busdev, 1, qdev_get_gpio_in(&pci->qdev, 11));
    sysbus_connect_irq(&pcihost->busdev, 2, qdev_get_gpio_in(&pci->qdev, 9));
    sysbus_connect_irq(&pcihost->busdev, 3, qdev_get_gpio_in(&pci->qdev, 11));
    isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(pci), "isa.0"));

    /* Super I/O (parallel + serial ports) */
    isa = isa_create(isa_bus, TYPE_PC87312);
    dev = DEVICE(isa);
    qdev_prop_set_uint8(dev, "config", 13); /* fdc, ser0, ser1, par0 */
    qdev_init_nofail(dev);

    /* init basic PC hardware */
    pci_vga_init(pci_bus);
    /* Open Hack'Ware hack: PCI BAR#0 is programmed to 0xf0000000.
     * While bios will access framebuffer at 0xf0000000, real physical
     * address is 0xf0000000 + 0xc0000000 (PCI memory base).
     * Alias the wrong memory accesses to the right place.
     */
    memory_region_init_alias(vga, NULL, "vga-alias", pci_address_space(pci),
                             0xf0000000, 0x1000000);
    memory_region_add_subregion_overlap(sysmem, 0xf0000000, vga, 10);

    nb_nics1 = nb_nics;
    if (nb_nics1 > NE2000_NB_MAX)
        nb_nics1 = NE2000_NB_MAX;
    for(i = 0; i < nb_nics1; i++) {
        if (nd_table[i].model == NULL) {
	    nd_table[i].model = g_strdup("ne2k_isa");
        }
        if (strcmp(nd_table[i].model, "ne2k_isa") == 0) {
            isa_ne2000_init(isa_bus, ne2000_io[i], ne2000_irq[i],
                            &nd_table[i]);
        } else {
            pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL);
        }
    }

    ide_drive_get(hd, MAX_IDE_BUS);
    for(i = 0; i < MAX_IDE_BUS; i++) {
        isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i], ide_irq[i],
                     hd[2 * i],
		     hd[2 * i + 1]);
    }
    isa_create_simple(isa_bus, "i8042");

    cpu = POWERPC_CPU(first_cpu);
    sysctrl->reset_irq = cpu->env.irq_inputs[PPC6xx_INPUT_HRESET];

    portio_list_init(&prep_port_list, NULL, prep_portio_list, sysctrl, "prep");
    portio_list_add(&prep_port_list, isa_address_space_io(isa), 0x0);

    /* PowerPC control and status register group */
#if 0
    memory_region_init_io(xcsr, NULL, &PPC_XCSR_ops, NULL, "ppc-xcsr", 0x1000);
    memory_region_add_subregion(sysmem, 0xFEFF0000, xcsr);
#endif

    if (usb_enabled(false)) {
        pci_create_simple(pci_bus, -1, "pci-ohci");
    }

    m48t59 = m48t59_init_isa(isa_bus, 0x0074, NVRAM_SIZE, 59);
    if (m48t59 == NULL)
        return;
    sysctrl->nvram = m48t59;

    /* Initialise NVRAM */
    nvram.opaque = m48t59;
    nvram.read_fn = &m48t59_read;
    nvram.write_fn = &m48t59_write;
    PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "PREP", ram_size, ppc_boot_device,
                         kernel_base, kernel_size,
                         kernel_cmdline,
                         initrd_base, initrd_size,
                         /* XXX: need an option to load a NVRAM image */
                         0,
                         graphic_width, graphic_height, graphic_depth);
}
Пример #22
0
static GwyContainer*
csmfile_load(const gchar *filename,
             G_GNUC_UNUSED GwyRunType mode,
             GError **error)
{
    GwyContainer *meta, *container = NULL;
    GHashTable *hash = NULL;
    guchar *d24, *buffer = NULL;
    gsize size = 0;
    GError *err = NULL;
    GwyDataField *dfield = NULL;
    guint xres, yres, hxres, hyres, bmpsize, header_size, maxval, i, j;
    gdouble real, zmin, zmax, q, z0;
    GwyTextHeaderParser parser;
    GwySIUnit *unit = NULL;
    gchar *value, *end, *header = NULL;
    gdouble *data;
    gint power10;

    if (!gwy_file_get_contents(filename, &buffer, &size, &err)) {
        err_GET_FILE_CONTENTS(error, &err);
        return NULL;
    }

    if (size < BMP_HEADER_SIZE) {
        err_TOO_SHORT(error);
        goto fail;
    }
    if (!read_bmp_header(buffer, &xres, &yres, &bmpsize)
        || size <= bmpsize) {
        err_FILE_TYPE(error, "CSM");
        goto fail;
    }

    header_size = size - bmpsize;
    header = g_new(gchar, header_size + 1);
    memcpy(header, buffer + bmpsize, header_size);
    header[header_size] = '\0';

    gwy_clear(&parser, 1);
    parser.key_value_separator = "=";
    hash = gwy_text_header_parse(header, &parser, NULL, NULL);

    if (!(value = g_hash_table_lookup(hash, "Image width"))) {
        err_MISSING_FIELD(error, "Image width");
        goto fail;
    }
    hxres = atoi(value);
    if (hxres != xres) {
        g_set_error(error, GWY_MODULE_FILE_ERROR, GWY_MODULE_FILE_ERROR_DATA,
                    _("Header image width field does not match BMP width."));
        goto fail;
    }
    if (err_DIMENSION(error, xres))
        goto fail;

    if (!(value = g_hash_table_lookup(hash, "Image height"))) {
        err_MISSING_FIELD(error, "Image height");
        goto fail;
    }
    hyres = atoi(value);
    if (hyres != yres) {
        g_set_error(error, GWY_MODULE_FILE_ERROR, GWY_MODULE_FILE_ERROR_DATA,
                    _("Header image height field does not match BMP height."));
        goto fail;
    }
    if (err_DIMENSION(error, yres))
        goto fail;

    if (!(value = g_hash_table_lookup(hash, "ScanSize"))) {
        err_MISSING_FIELD(error, "ScanSize");
        goto fail;
    }
    real = g_ascii_strtod(value, NULL);
    /* Use negated positive conditions to catch NaNs */
    if (!((real = fabs(real)) > 0)) {
        g_warning("Real size is 0.0, fixing to 1.0");
        real = 1.0;
    }

    if (!(value = g_hash_table_lookup(hash, "HeightScale"))) {
        err_MISSING_FIELD(error, "HeightScale");
        goto fail;
    }
    zmax = g_ascii_strtod(value, &end);
    unit = gwy_si_unit_new_parse(end, &power10);

    /* Optional stuff for which we try to fall back. */
    if (!(value = g_hash_table_lookup(hash, "StartHeightScale")))
        zmin = 0.0;
    else
        zmin = g_ascii_strtod(value, NULL);

    if (!(value = g_hash_table_lookup(hash, "MaxValue")))
        maxval = 0xffff;
    else
        maxval = MAX(atoi(value), 1);


    dfield = gwy_data_field_new(xres, yres, real*Nanometre, real*Nanometre,
                                FALSE);
    data = gwy_data_field_get_data(dfield);

    d24 = buffer + BMP_HEADER_SIZE;
    q = pow10(power10)*(zmax - zmin)/maxval;
    z0 = pow10(power10)*zmin;
    for (i = 0; i < yres; i++) {
        gdouble *row = data + (yres-1 - i)*xres;
        for (j = 0; j < xres; j++, row++, d24 += 3)
            *row = (d24[0] + 256.0*d24[1])*q + z0;
    }

    gwy_si_unit_set_from_string(gwy_data_field_get_si_unit_xy(dfield), "m");
    gwy_data_field_set_si_unit_z(dfield, unit);

    container = gwy_container_new();
    gwy_container_set_object_by_name(container, "/0/data", dfield);
    g_object_unref(dfield);

    meta = gwy_container_new();
    g_hash_table_foreach(hash, store_meta, meta);
    gwy_container_set_object_by_name(container, "/0/meta", meta);
    g_object_unref(meta);

    if ((value = g_hash_table_lookup(hash, "sTitle"))
        && g_utf8_validate(value, -1, NULL)) {
        gwy_container_set_string_by_name(container, "/0/data/title",
                                         g_strdup(value));
    }
    else
        gwy_app_channel_title_fall_back(container, 0);

    gwy_file_channel_import_log_add(container, 0, NULL, filename);

fail:
    gwy_file_abandon_contents(buffer, size, NULL);
    gwy_object_unref(unit);
    if (header)
        g_free(header);
    if (hash)
        g_hash_table_destroy(hash);

    return container;
}
Пример #23
0
END_TEST

START_TEST(test_atree_minmax)
{
    ATree *at;
    gint   result;
    gint   *key;
    gint   *data;
    gint   limit;
    gint   index;
    gint   min;
    gint   max;
    gint   *min_from_tree;
    gint   *max_from_tree;
    GRand  *random;
    
    at = a_tree_new();
    
    if (at == NULL)
    {
        ck_abort_msg ("Failed to create ATree\n");
    }
    else
    {
        limit  = 100;
        random = g_rand_new_with_seed( (guint32) at );
        min    = 0;
        max    = 0;
         
        for (index = 0; index < limit; index++)
        {
            key  = g_new(gint, 1);
            data = g_new(gint, 1);
            
            *key  = g_rand_int( random );
            *data = *key;
            
            if (*key >= max)
            {
                max = *data;
            }
            else
            {
                if (*key <= min)
                {
                    min = *data;
                }
                else
                {
                    /* Do nothing */
                }
            }
            
            result = atree_insert( at, GINT_TO_POINTER(key), GINT_TO_POINTER(data) );
            ck_assert_int_eq( result, 0 );
        }
        
        max_from_tree = atree_max_value( at );
        min_from_tree = atree_min_value( at );
        
        ck_assert_int_eq( *max_from_tree, max );
        ck_assert_int_eq( *min_from_tree, min );
        
        a_tree_destroy( at );
    }
}
Пример #24
0
GtkIconData  *
_gtk_icon_cache_get_icon_data  (GtkIconCache *cache,
				const gchar  *icon_name,
				gint          directory_index)
{
  guint32 offset, image_data_offset, meta_data_offset;
  GtkIconData *data;
  int i;

  offset = find_image_offset (cache, icon_name, directory_index);
  if (!offset)
    return NULL;

  image_data_offset = GET_UINT32 (cache->buffer, offset + 4);
  if (!image_data_offset)
    return NULL;

  meta_data_offset = GET_UINT32 (cache->buffer, image_data_offset + 4);
  
  if (!meta_data_offset)
    return NULL;

  data = g_slice_new0 (GtkIconData);

  offset = GET_UINT32 (cache->buffer, meta_data_offset);
  if (offset)
    {
      data->has_embedded_rect = TRUE;
      data->x0 = GET_UINT16 (cache->buffer, offset);
      data->y0 = GET_UINT16 (cache->buffer, offset + 2);
      data->x1 = GET_UINT16 (cache->buffer, offset + 4);
      data->y1 = GET_UINT16 (cache->buffer, offset + 6);
    }

  offset = GET_UINT32 (cache->buffer, meta_data_offset + 4);
  if (offset)
    {
      data->n_attach_points = GET_UINT32 (cache->buffer, offset);
      data->attach_points = g_new (GdkPoint, data->n_attach_points);
      for (i = 0; i < data->n_attach_points; i++)
	{
	  data->attach_points[i].x = GET_UINT16 (cache->buffer, offset + 4 + 4 * i); 
	  data->attach_points[i].y = GET_UINT16 (cache->buffer, offset + 4 + 4 * i + 2); 
	}
    }

  offset = GET_UINT32 (cache->buffer, meta_data_offset + 8);
  if (offset)
    {
      gint n_names;
      gchar *lang, *name;
      gchar **langs;
      GHashTable *table = g_hash_table_new (g_str_hash, g_str_equal);

      n_names = GET_UINT32 (cache->buffer, offset);
      
      for (i = 0; i < n_names; i++)
	{
	  lang = cache->buffer + GET_UINT32 (cache->buffer, offset + 4 + 8 * i);
	  name = cache->buffer + GET_UINT32 (cache->buffer, offset + 4 + 8 * i + 4);
	  
	  g_hash_table_insert (table, lang, name);
	}
      
      langs = (gchar **)g_get_language_names ();
      for (i = 0; langs[i]; i++)
	{
	  name = g_hash_table_lookup (table, langs[i]);
	  if (name)
	    {
	      data->display_name = g_strdup (name);
	      break;
	    }
	}

      g_hash_table_destroy (table);
    }

  return data;
}
Пример #25
0
Файл: learn.c Проект: CTU-OSP/mc
static void
init_learn (void)
{
    const int dlg_width = 78;
    const int dlg_height = 23;

    /* buttons */
    int bx0, bx1;
    const char *b0 = N_("&Save");
    const char *b1 = N_("&Cancel");
    int bl0, bl1;

    int x, y, i;
    const key_code_name_t *key;

#ifdef ENABLE_NLS
    static gboolean i18n_flag = FALSE;
    if (!i18n_flag)
    {
        learn_title = _(learn_title);
        i18n_flag = TRUE;
    }

    b0 = _(b0);
    b1 = _(b1);
#endif /* ENABLE_NLS */

    do_refresh ();

    learn_dlg =
        dlg_create (TRUE, 0, 0, dlg_height, dlg_width, dialog_colors, learn_callback, NULL,
                    "[Learn keys]", learn_title, DLG_CENTER);

    /* find first unshown button */
    for (key = key_name_conv_tab, learn_total = 0;
         key->name != NULL && strcmp (key->name, "kpleft") != 0; key++, learn_total++)
        ;

    learnok = 0;
    learnchanged = FALSE;

    learnkeys = g_new (learnkey_t, learn_total);

    x = UX;
    y = UY;

    /* add buttons and "OK" labels */
    for (i = 0; i < learn_total; i++)
    {
        char buffer[BUF_TINY];
        const char *label;
        int padding;

        learnkeys[i].ok = FALSE;
        learnkeys[i].sequence = NULL;

        label = _(key_name_conv_tab[i].longname);
        padding = 16 - str_term_width1 (label);
        padding = max (0, padding);
        g_snprintf (buffer, sizeof (buffer), "%s%*s", label, padding, "");

        learnkeys[i].button =
            WIDGET (button_new (y, x, B_USER + i, NARROW_BUTTON, buffer, learn_button));
        learnkeys[i].label = WIDGET (label_new (y, x + 19, ""));
        add_widget (learn_dlg, learnkeys[i].button);
        add_widget (learn_dlg, learnkeys[i].label);

        y++;
        if (y == UY + ROWS)
        {
            x += COLSHIFT;
            y = UY;
        }
    }

    add_widget (learn_dlg, hline_new (dlg_height - 8, -1, -1));
    add_widget (learn_dlg,
                label_new (dlg_height - 7, 5,
                           _("Press all the keys mentioned here. After you have done it, check\n"
                             "which keys are not marked with OK. Press space on the missing\n"
                             "key, or click with the mouse to define it. Move around with Tab.")));
    add_widget (learn_dlg, hline_new (dlg_height - 4, -1, -1));
    /* buttons */
    bl0 = str_term_width1 (b0) + 5;     /* default button */
    bl1 = str_term_width1 (b1) + 3;     /* normal button */
    bx0 = (dlg_width - (bl0 + bl1 + 1)) / 2;
    bx1 = bx0 + bl0 + 1;
    add_widget (learn_dlg, button_new (dlg_height - 3, bx0, B_ENTER, DEFPUSH_BUTTON, b0, NULL));
    add_widget (learn_dlg, button_new (dlg_height - 3, bx1, B_CANCEL, NORMAL_BUTTON, b1, NULL));
}
int main(int argc, char **argv)
{
  unsigned i;
  GError *error = NULL;
  GOptionContext *op_context;
  unsigned line_no = 0;
  GHashTable *contexts_by_str;
  GPtrArray *all_contexts;
  GHashTable *code_points_by_line;
  GPtrArray *all_code_points;
  char *tmp_fname;
  char **files;
  guint n_files;
  AllocInfo *total_by_time;
  op_context = g_option_context_new (NULL);
  g_option_context_set_summary (op_context, "gsk-analyze-successive-memdumps");
  g_option_context_add_main_entries (op_context, op_entries, NULL);
  if (!g_option_context_parse (op_context, &argc, &argv, &error))
    gsk_fatal_user_error ("error parsing command-line options: %s", error->message);
  g_option_context_free (op_context);

  contexts_by_str = g_hash_table_new (g_str_hash, g_str_equal);
  code_points_by_line = g_hash_table_new (g_str_hash, g_str_equal);
  all_contexts = g_ptr_array_new ();
  all_code_points = g_ptr_array_new ();

  if (dir_name == NULL)
    g_error ("missing argument directory");

  n_files = argc - 1;
  files = argv + 1;
  g_printerr ("Scanning %u input files... ", n_files);
  total_by_time = g_new0 (AllocInfo, n_files);
  for (i = 0; i < n_files; i++)
    {
      FILE *fp = fopen (files[i], "r");
      char buf[4096];
      GString *context_str = g_string_new ("");
      AllocInfo ai;
      Context *context;
      update_percent_bar (i, n_files);
      if (fp == NULL)
        gsk_fatal_user_error ("opening %s failed: %s",
	                      files[i], g_strerror (errno));
      do
        {
          if (!fgets (buf, sizeof (buf), fp))
            gsk_fatal_user_error ("file %s: unexpected eof", files[i]);
          line_no++;
        }
      while (is_preamble_line (buf));
next_block_start:
      if (g_str_has_prefix (buf, "Summary: "))
        goto done_file;
      if (sscanf (buf, "%u bytes allocated in %u blocks from:",
                      &ai.n_bytes, &ai.n_blocks) != 2)
        gsk_fatal_user_error ("error parsing line %u from %s",
                              line_no, files[i]);
      g_string_set_size (context_str, 0);
      for (;;)
        {
          if (fgets (buf, sizeof (buf), fp) == NULL)
            gsk_fatal_user_error ("file %s: unexpected eof", files[i]);
          line_no++;
          if (buf[0] != ' ')
            break;
          g_string_append (context_str, buf + 2);
        }

      /* find or create context */
      context = g_hash_table_lookup (contexts_by_str, context_str->str);
      if (context == NULL)
        {
          context = g_new (Context, 1);
          context->str = g_strdup (context_str->str);
          context->alloc_infos = g_new0 (AllocInfo, n_files);
          g_hash_table_insert (contexts_by_str, context->str, context);
          context->total_bytes = 0;
          g_ptr_array_add (all_contexts, context);
        }
      context->alloc_infos[i] = ai;
      context->total_bytes += ai.n_bytes;
      total_by_time[i].n_bytes += ai.n_bytes;
      total_by_time[i].n_blocks += ai.n_blocks;
      goto next_block_start;

done_file:
      fclose (fp);
    }
  update_percent_bar (i, n_files);

  g_ptr_array_sort (all_contexts, compare_p_context_by_total_bytes_descending);
  if (!gsk_mkdir_p (dir_name, 0755, &error))
    gsk_fatal_user_error ("error making directory %s: %s", dir_name, error->message);
  static const char *subdirs[] = { "data", "images", "code-points" };
  for (i = 0; i < G_N_ELEMENTS (subdirs); i++)
    {
      tmp_fname = g_strdup_printf ("%s/%s", dir_name, subdirs[i]);
      if (!gsk_mkdir_p (tmp_fname, 0755, &error))
        g_error ("error mkdir(%s): %s", tmp_fname, error->message);
      g_free (tmp_fname);
    }
  FILE *gnuplot_script_fp, *index_html_fp, *main_html_fp;
  tmp_fname = g_strdup_printf ("%s/gnuplot.input", dir_name);
  gnuplot_script_fp = fopen (tmp_fname, "w");
  if (gnuplot_script_fp == NULL)
    g_error ("error creating %s: %s", tmp_fname, g_strerror (errno));
  g_free (tmp_fname);
  fprintf (gnuplot_script_fp,
           "set terminal png\n\n");
  index_html_fp = NULL;

  {
    FILE *fp;
    tmp_fname = g_strdup_printf ("%s/data/total.data", dir_name);
    fp = fopen (tmp_fname, "w");
    if (fp == NULL)
      g_error ("creating %s failed", tmp_fname);
    g_free (tmp_fname);
    for (i = 0; i < n_files; i++)
      fprintf (fp, "%u %u %u\n", i,
               total_by_time[i].n_bytes,
               total_by_time[i].n_blocks);
    fclose (fp);

    fprintf (gnuplot_script_fp,
             "set output \"%s/images/total.png\"\n", dir_name);
    fprintf (gnuplot_script_fp,
             "plot \"%s/data/total.data\" using 1:2 title \"bytes\", \"%s/data/total.data\" using 1:3 title \"blocks\"\n",
             dir_name, dir_name);
  }

  tmp_fname = g_strdup_printf ("%s/index.html", dir_name);
  main_html_fp = fopen (tmp_fname, "w");
  if (main_html_fp == NULL)
    g_error ("error creating %s: %s", tmp_fname, g_strerror (errno));
  fprintf (main_html_fp, "<html><body>\n"
                         "Total:\n<br/><img src=\"images/total.png\" /><br/>\n"
                         "<ul>\n");

  g_printerr ("Writing data files for %u contexts... ", all_contexts->len);
  for (i = 0; i < all_contexts->len; i++)
    {
      FILE *fp;
      Context *context = all_contexts->pdata[i];
      guint j;
      update_percent_bar (i, all_contexts->len);
      if (i % 100 == 0)
        {
          if (index_html_fp != NULL)
            {
              fprintf (index_html_fp, "</body></html>\n");
              fclose (index_html_fp);
            }
          tmp_fname = g_strdup_printf ("%s/index-%03u.html", dir_name, i / 100);
          index_html_fp = fopen (tmp_fname, "w");
          if (index_html_fp == NULL)
            g_error ("error creating %s: %s", tmp_fname, g_strerror (errno));
          g_free (tmp_fname);
          fprintf (index_html_fp, "<html><body>\n");
          fprintf (index_html_fp, "<h1>Contexts %u .. %u</h1>\n", i, MIN (i + 99, all_contexts->len - 1));

          fprintf (main_html_fp, "<li><a href=\"index-%03u.html\">Contexts %u .. %u</a></li>\n",
                   i / 100,  i, MIN (i + 99, all_contexts->len - 1));
        }

      tmp_fname = g_strdup_printf ("%s/data/context-%05u.data", dir_name, i);
      fp = fopen (tmp_fname, "w");
      if (fp == NULL)
        g_error ("error creating %s: %s", tmp_fname, g_strerror (errno));
      for (j = 0; j < n_files; j++)
        fprintf (fp, "%u %u %u\n", j,
                 context->alloc_infos[j].n_bytes,
                 context->alloc_infos[j].n_blocks);
      fclose (fp);
      fprintf (gnuplot_script_fp,
               "set output \"%s/images/context-%05u.png\"\n", dir_name, i);
      fprintf (gnuplot_script_fp,
               "plot \"%s/data/context-%05u.data\" using 1:2 title \"bytes\", \"%s/data/context-%05u.data\" using 1:3 title \"blocks\"\n",
               dir_name, i,
               dir_name, i);

      pr_context (index_html_fp, i, context, "images");
    }
  update_percent_bar (i, all_contexts->len);
  fprintf (main_html_fp, "</ul>\n"
                         "<h1>Code Point Index</h1>\n"
                          "<a href=\"index-by-code-point.html\">here</a>\n");
  if (index_html_fp != NULL)
    {
      fprintf (index_html_fp, "</body></html>\n");
      fclose (index_html_fp);
    }
  fprintf (main_html_fp, "</body></html>\n");
  fclose (main_html_fp);

  g_printerr ("Calculating code-points... ");
  for (i = 0; i < all_contexts->len; i++)
    {
      Context *context = all_contexts->pdata[i];
      CodePoint *cp;
      char **strs = g_strsplit (context->str, "\n", 0);
      unsigned j;
      for (j = 0; strs[j] != NULL; j++)
        {
          g_strstrip (strs[j]);
          if (strs[j][0] != 0)
            {
              cp = g_hash_table_lookup (code_points_by_line, strs[j]);
              if (cp == NULL)
                {
                  cp = g_new (CodePoint, 1);
                  cp->line = g_strdup (strs[j]);
                  cp->context_indices = g_array_new (FALSE, FALSE, sizeof (guint));
                  g_hash_table_insert (code_points_by_line, cp->line, cp);
                  g_ptr_array_add (all_code_points, cp);
                }
              if (cp->context_indices->len == 0
               || g_array_index (cp->context_indices, guint, cp->context_indices->len - 1) != i)
                g_array_append_val (cp->context_indices, i);
            }
        }
      g_strfreev (strs);
    }
  g_printerr (" done [%u code points].\n", all_code_points->len);
  g_ptr_array_sort (all_code_points, compare_p_code_point_by_line);
  tmp_fname = g_strdup_printf ("%s/index-by-code-point.html", dir_name);
  main_html_fp = fopen (tmp_fname, "w");
  if (main_html_fp == NULL)
    g_error ("error creating %s: %s", tmp_fname, g_strerror (errno));
  g_free (tmp_fname);
  fprintf (main_html_fp,
           "<html><body><h1>Code Points</h1>\n");
  fprintf (main_html_fp,
           "<ul>\n");
  AllocInfo *totals;
  totals = g_new (AllocInfo, n_files);
  g_printerr ("Creating code-point data... ");
  for (i = 0; i < all_code_points->len; i++)
    {
      CodePoint *cp = all_code_points->pdata[i];
      FILE *fp;
      unsigned j;
      update_percent_bar (i, all_code_points->len);
      memset (totals, 0, sizeof (AllocInfo) * n_files);
      for (j = 0; j < cp->context_indices->len; j++)
        {
          guint context_index = g_array_index (cp->context_indices, guint, j);
          Context *context = all_contexts->pdata[context_index];
          guint k;
          for (k = 0; k < n_files; k++)
            {
              totals[k].n_bytes += context->alloc_infos[k].n_bytes;
              totals[k].n_blocks += context->alloc_infos[k].n_blocks;
            }
        }
      tmp_fname = g_strdup_printf ("%s/data/codepoint-%05u.data", dir_name, i);
      fp = fopen (tmp_fname, "w");
      for (j = 0; j < n_files; j++)
        fprintf (fp, "%u %u %u\n", j,
                 totals[j].n_bytes,
                 totals[j].n_blocks);
      fclose (fp);

      fprintf (gnuplot_script_fp,
               "set output \"%s/images/codepoint-%05u.png\"\n", dir_name, i);
      fprintf (gnuplot_script_fp,
               "plot \"%s/data/codepoint-%05u.data\" using 1:2 title \"bytes\", \"%s/data/codepoint-%05u.data\" using 1:3 title \"blocks\"\n",
               dir_name, i,
               dir_name, i);

      fprintf (main_html_fp, "<li>Code point %05u: <a href=\"code-points/%05u.html\">%s</a> (%u contexts)</li>\n",
               i, i, cp->line, cp->context_indices->len);
      tmp_fname = g_strdup_printf ("%s/code-points/%05u.html", dir_name, i);
      fp = fopen (tmp_fname, "w");
      if (fp == NULL)
        g_error ("error creating %s: %s", tmp_fname, g_strerror (errno));
      g_free (tmp_fname);



      fprintf (fp, "<html><body><h1>Code Point %u</h1>\n"
               "<b><pre>\n"
               "%s\n"
               "</pre>\n"
               "</b>\n", i, cp->line);
      fprintf (fp, "<p>Summary<br /><img src=\"../images/codepoint-%05u.png\" /></p>\n", i);
      for (j = 0; j < MIN (cp->context_indices->len, 100); j++)
        pr_context (fp, g_array_index (cp->context_indices, guint, j),
                    all_contexts->pdata[g_array_index (cp->context_indices, guint, j)],
                    "../images");
      if (j < cp->context_indices->len)
        fprintf (fp, "<p><b>%u Contexts omitted</b></p>\n",
                 (guint)(cp->context_indices->len - j));
      fprintf (fp,
               "</body></html>\n");
      fclose (fp);
    }
  update_percent_bar (i, all_code_points->len);
  fprintf (main_html_fp,
           "</ul>\n"
           "</body></html>\n");
  fclose (main_html_fp);

  fclose (gnuplot_script_fp);

  g_printerr ("Running gnuplot... ");
  tmp_fname = g_strdup_printf ("gnuplot < %s/gnuplot.input", dir_name);
  if (system (tmp_fname) != 0)
    gsk_fatal_user_error ("error running gnuplot");
  g_free (tmp_fname);
  g_printerr (" done.\n");

  return 0;
}
Пример #27
0
static guint
gtk_application_impl_dbus_inhibit (GtkApplicationImpl         *impl,
                                   GtkWindow                  *window,
                                   GtkApplicationInhibitFlags  flags,
                                   const gchar                *reason)
{
  GtkApplicationImplDBus *dbus = (GtkApplicationImplDBus *) impl;
  GVariant *res;
  GError *error = NULL;
  guint cookie;
  static gboolean warned = FALSE;

  if (dbus->sm_proxy)
    {
      res = g_dbus_proxy_call_sync (dbus->sm_proxy,
                                    "Inhibit",
                                    g_variant_new ("(s@usu)",
                                                   dbus->application_id,
                                                   window ? gtk_application_impl_dbus_get_window_system_id (dbus, window) : g_variant_new_uint32 (0),
                                                   reason,
                                                   flags),
                                    G_DBUS_CALL_FLAGS_NONE,
                                    G_MAXINT,
                                    NULL,
                                    &error);

      if (res)
        {
          g_variant_get (res, "(u)", &cookie);
          g_variant_unref (res);
          return cookie;
        }

      if (error)
        {
          if (!warned)
            {
              g_warning ("Calling %s.Inhibit failed: %s",
                         g_dbus_proxy_get_interface_name (dbus->sm_proxy),
                         error->message);
              warned = TRUE;
            }
          g_clear_error (&error);
        }
    }
  else if (dbus->inhibit_proxy)
    {
      GVariantBuilder options;

      g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT);
      g_variant_builder_add (&options, "{sv}", "reason", g_variant_new_string (reason));
      res = g_dbus_proxy_call_sync (dbus->inhibit_proxy,
                                    "Inhibit",
                                    g_variant_new ("(su@a{sv})",
                                                   "", /* window */
                                                   flags,
                                                   g_variant_builder_end (&options)),
                                    G_DBUS_CALL_FLAGS_NONE,
                                    G_MAXINT,
                                    NULL,
                                    &error);
      if (res)
        {
          InhibitHandle *handle;

          handle = g_new (InhibitHandle, 1);
          handle->cookie = ++next_cookie;

          g_variant_get (res, "(o)", &handle->handle);
          g_variant_unref (res);

          dbus->inhibit_handles = g_slist_prepend (dbus->inhibit_handles, handle);

          return handle->cookie;
        }

      if (error)
        {
          if (!warned)
            {
              g_warning ("Calling %s.Inhibit failed: %s",
                         g_dbus_proxy_get_interface_name (dbus->inhibit_proxy),
                         error->message);
              warned = TRUE;
            }
          g_clear_error (&error);
        }
    }

  return 0;
}
Пример #28
0
static void
set_clone_restart_commands (void)
{
  char *restartv[10];
  char *clonev[10];
  char *discardv[10];
  int i;
  SmProp prop1, prop2, prop3, *props[3];
  
  /* Restart (use same client ID) */
  
  prop1.name = SmRestartCommand;
  prop1.type = SmLISTofARRAY8;
  
  g_return_if_fail (client_id);
  
  i = 0;
  restartv[i] = "metacity";
  ++i;
  restartv[i] = "--sm-client-id";
  ++i;
  restartv[i] = client_id;
  ++i;
  restartv[i] = NULL;

  prop1.vals = g_new (SmPropValue, i);
  i = 0;
  while (restartv[i])
    {
      prop1.vals[i].value = restartv[i];
      prop1.vals[i].length = strlen (restartv[i]);
      ++i;
    }
  prop1.num_vals = i;

  /* Clone (no client ID) */
  
  i = 0;
  clonev[i] = "metacity";
  ++i;
  clonev[i] = NULL;

  prop2.name = SmCloneCommand;
  prop2.type = SmLISTofARRAY8;
  
  prop2.vals = g_new (SmPropValue, i);
  i = 0;
  while (clonev[i])
    {
      prop2.vals[i].value = clonev[i];
      prop2.vals[i].length = strlen (clonev[i]);
      ++i;
    }
  prop2.num_vals = i;

  /* Discard */
  
  i = 0;
  discardv[i] = "rm";
  ++i;
  discardv[i] = "-f";
  ++i;
  discardv[i] = (char*) full_save_file ();
  ++i;
  discardv[i] = NULL;
  
  prop3.name = SmDiscardCommand;
  prop3.type = SmLISTofARRAY8;
  
  prop3.vals = g_new (SmPropValue, i);
  i = 0;
  while (discardv[i])
    {
      prop3.vals[i].value = discardv[i];
      prop3.vals[i].length = strlen (discardv[i]);
      ++i;
    }
  prop3.num_vals = i;

  
  props[0] = &prop1;
  props[1] = &prop2;
  props[2] = &prop3;
  
  SmcSetProperties (session_connection, 3, props);

  g_free (prop1.vals);
  g_free (prop2.vals);
  g_free (prop3.vals);
}
Пример #29
0
static void virtex_init(MachineState *machine)
{
    ram_addr_t ram_size = machine->ram_size;
    const char *kernel_filename = machine->kernel_filename;
    const char *kernel_cmdline = machine->kernel_cmdline;
    hwaddr initrd_base = 0;
    int initrd_size = 0;
    MemoryRegion *address_space_mem = get_system_memory();
    DeviceState *dev;
    PowerPCCPU *cpu;
    CPUPPCState *env;
    hwaddr ram_base = 0;
    DriveInfo *dinfo;
    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
    qemu_irq irq[32], *cpu_irq;
    int kernel_size;
    int i;

    /* init CPUs */
    if (machine->cpu_model == NULL) {
        machine->cpu_model = "440-Xilinx";
    }

    cpu = ppc440_init_xilinx(&ram_size, 1, machine->cpu_model, 400000000);
    env = &cpu->env;
    qemu_register_reset(main_cpu_reset, cpu);

    memory_region_allocate_system_memory(phys_ram, NULL, "ram", ram_size);
    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);

    dinfo = drive_get(IF_PFLASH, 0, 0);
    pflash_cfi01_register(PFLASH_BASEADDR, NULL, "virtex.flash", FLASH_SIZE,
                          dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                          (64 * 1024), FLASH_SIZE >> 16,
                          1, 0x89, 0x18, 0x0000, 0x0, 1);

    cpu_irq = (qemu_irq *) &env->irq_inputs[PPC40x_INPUT_INT];
    dev = qdev_create(NULL, "xlnx.xps-intc");
    qdev_prop_set_uint32(dev, "kind-of-intr", 0);
    qdev_init_nofail(dev);
    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, INTC_BASEADDR);
    sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, cpu_irq[0]);
    for (i = 0; i < 32; i++) {
        irq[i] = qdev_get_gpio_in(dev, i);
    }

    serial_mm_init(address_space_mem, UART16550_BASEADDR, 2, irq[UART16550_IRQ],
                   115200, serial_hds[0], DEVICE_LITTLE_ENDIAN);

    /* 2 timers at irq 2 @ 62 Mhz.  */
    dev = qdev_create(NULL, "xlnx.xps-timer");
    qdev_prop_set_uint32(dev, "one-timer-only", 0);
    qdev_prop_set_uint32(dev, "clock-frequency", 62 * 1000000);
    qdev_init_nofail(dev);
    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, TIMER_BASEADDR);
    sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[TIMER_IRQ]);

    if (kernel_filename) {
        uint64_t entry, low, high;
        hwaddr boot_offset;

        /* Boots a kernel elf binary.  */
        kernel_size = load_elf(kernel_filename, NULL, NULL,
                               &entry, &low, &high, 1, ELF_MACHINE, 0);
        boot_info.bootstrap_pc = entry & 0x00ffffff;

        if (kernel_size < 0) {
            boot_offset = 0x1200000;
            /* If we failed loading ELF's try a raw image.  */
            kernel_size = load_image_targphys(kernel_filename,
                                              boot_offset,
                                              ram_size);
            boot_info.bootstrap_pc = boot_offset;
            high = boot_info.bootstrap_pc + kernel_size + 8192;
        }

        boot_info.ima_size = kernel_size;

        /* Load initrd. */
        if (machine->initrd_filename) {
            initrd_base = high = ROUND_UP(high, 4);
            initrd_size = load_image_targphys(machine->initrd_filename,
                                              high, ram_size - high);

            if (initrd_size < 0) {
                error_report("couldn't load ram disk '%s'",
                             machine->initrd_filename);
                exit(1);
            }
            high = ROUND_UP(high + initrd_size, 4);
        }

        /* Provide a device-tree.  */
        boot_info.fdt = high + (8192 * 2);
        boot_info.fdt &= ~8191;

        xilinx_load_device_tree(boot_info.fdt, ram_size,
                                initrd_base, initrd_size,
                                kernel_cmdline);
    }
    env->load_info = &boot_info;
}
Пример #30
0
void
pointalism_generate_grid (RutPointalismGridSlice *slice,
                          int tex_width,
                          int tex_height,
                          float size)
{
  int columns = abs (tex_width / size);
  int rows = abs (tex_height / size);
  int i, j, k, l;
  float cell_s = 1.0 / columns;
  float cell_t = 1.0 / rows;
  float start_x = -1.0 * ((size * columns) / 2.0);
  float start_y = -1.0 * ((size * rows) / 2.0);
  GridVertex *vertices = g_new (GridVertex, (columns * rows) * 4);
  unsigned int *indices = g_new (unsigned int, (columns * rows) * 6);

  k = 0;
  l = 0;

  for (i = 0; i < rows; i++)
  {
    for (j = 0; j < columns; j++)
    {
      float x = start_x + (size / 2);
      float y = start_y + (size / 2);

      vertices[k].x0 = -1 * (size / 2);
      vertices[k].y0 = -1 * (size / 2);
      vertices[k].s0 = 0;
      vertices[k].t0 = 0;
      vertices[k].x1 = x;
      vertices[k].y1 = y;
      vertices[k].s1 = j * cell_s;
      vertices[k].t1 = i * cell_t;
      vertices[k].s2 = (j + 1) * cell_s;
      vertices[k].t2 = (i + 1) * cell_t;
      vertices[k].s3 = j * cell_s;
      vertices[k].t3 = i * cell_t;
      vertices[k].nx = 0;
      vertices[k].ny = 0;
      vertices[k].nz = 1;
      vertices[k].tx = 1;
      vertices[k].ty = 0;
      vertices[k].tz = 0;
      k++;

      vertices[k].x0 = size / 2;
      vertices[k].y0 = -1 * (size / 2);
      vertices[k].s0 = 1;
      vertices[k].t0 = 0;
      vertices[k].x1 = x;
      vertices[k].y1 = y;
      vertices[k].s1 = j * cell_s;
      vertices[k].t1 = i * cell_t;
      vertices[k].s2 = (j + 1) * cell_s;
      vertices[k].t2 = (i + 1) * cell_t;
      vertices[k].s3 = (j + 1) * cell_s;
      vertices[k].t3 = i * cell_t;
      vertices[k].nx = 0;
      vertices[k].ny = 0;
      vertices[k].nz = 1;
      vertices[k].tx = 1;
      vertices[k].ty = 0;
      vertices[k].tz = 0;
      k++;

      vertices[k].x0 = size / 2;
      vertices[k].y0 = size / 2;
      vertices[k].s0 = 1;
      vertices[k].t0 = 1;
      vertices[k].x1 = x;
      vertices[k].y1 = y;
      vertices[k].s1 = j * cell_s;
      vertices[k].t1 = i * cell_t;
      vertices[k].s2 = (j + 1) * cell_s;
      vertices[k].t2 = (i + 1) * cell_t;
      vertices[k].s3 = (j + 1) * cell_s;
      vertices[k].t3 = (i + 1) * cell_t;
      vertices[k].nx = 0;
      vertices[k].ny = 0;
      vertices[k].nz = 1;
      vertices[k].tx = 1;
      vertices[k].ty = 0;
      vertices[k].tz = 0;
      k++;

      vertices[k].x0 = -1 * (size / 2);
      vertices[k].y0 = size / 2;
      vertices[k].s0 = 0;
      vertices[k].t0 = 1;
      vertices[k].x1 = x;
      vertices[k].y1 = y;
      vertices[k].s1 = j * cell_s;
      vertices[k].t1 = i * cell_t;
      vertices[k].s2 = (j + 1) * cell_s;
      vertices[k].t2 = (i + 1) * cell_t;
      vertices[k].s3 = j * cell_s;
      vertices[k].t3 = (i + 1) * cell_t;
      vertices[k].nx = 0;
      vertices[k].ny = 0;
      vertices[k].nz = 1;
      vertices[k].tx = 1;
      vertices[k].ty = 0;
      vertices[k].tz = 0;
      k++;

      indices[l] = k;
      indices[l + 1] = k + 1;
      indices[l + 2] = k + 2;
      indices[l + 3] = k + 2;
      indices[l + 4] = k + 3;
      indices[l + 5] = k;

      l += 6;
      start_x += size;
    }
    start_x = -1.0 * ((size * columns) / 2.0);
    start_y += size;
  }

  if (slice->mesh)
    rut_refable_unref (slice->mesh);

  slice->mesh = mesh_new_grid (COGL_VERTICES_MODE_TRIANGLES,
                               (columns * rows) * 4,
                               (columns * rows) * 6,
                               vertices, indices);
}