static int sdwstat(Chan* c, uchar* dp, int n) { Dir *d; SDpart *pp; SDperm *perm; SDunit *unit; SDev *sdev; if(c->qid.type & QTDIR) error(Eperm); if(TYPE(c->qid) == Qtopctl){ unit = &topctlunit; sdev = nil; }else{ sdev = sdgetdev(DEV(c->qid)); if(sdev == nil) error(Enonexist); unit = sdev->unit[UNIT(c->qid)]; } qlock(&unit->ctl); d = nil; if(waserror()){ qunlock(&unit->ctl); if(sdev != nil) decref(&sdev->r); free(d); nexterror(); } switch(TYPE(c->qid)){ default: error(Eperm); case Qtopctl: case Qctl: perm = &unit->ctlperm; break; case Qraw: perm = &unit->rawperm; break; case Qpart: pp = &unit->part[PART(c->qid)]; if(unit->vers+pp->vers != c->qid.vers) error(Enonexist); perm = &pp->SDperm; break; } if(strcmp(up->user, perm->user) && !iseve()) error(Eperm); d = smalloc(sizeof(Dir)+n); n = convM2D(dp, n, &d[0], (char*)&d[1]); if(n == 0) error(Eshortstat); if(d->atime != ~0 || d->mtime != ~0 || d->length != ~0) error(Eperm); if(!emptystr(d[0].muid) || !emptystr(d[0].name)) error(Eperm); if(!emptystr(d[0].uid)) kstrdup(&perm->user, d[0].uid); if(!emptystr(d[0].gid) && strcmp(d[0].gid, eve) != 0) error(Eperm); if(d[0].mode != ~0UL) perm->perm = (perm->perm & ~0777) | (d[0].mode & 0777); poperror(); qunlock(&unit->ctl); if(sdev != nil) decref(&sdev->r); free(d); return n; }
static long sdbio(Chan* c, int write, char* a, long len, uvlong off) { int nchange; long l; uchar *b; SDpart *pp; SDunit *unit; SDev *sdev; ulong max, nb, offset; uvlong bno; sdev = sdgetdev(DEV(c->qid)); if(sdev == nil){ decref(&sdev->r); error(Enonexist); } unit = sdev->unit[UNIT(c->qid)]; if(unit == nil) error(Enonexist); nchange = 0; qlock(&unit->ctl); while(waserror()){ /* notification of media change; go around again */ if(strcmp(up->env->errstr, Eio) == 0 && unit->sectors == 0 && nchange++ == 0){ sdinitpart(unit); continue; } /* other errors; give up */ qunlock(&unit->ctl); decref(&sdev->r); nexterror(); } pp = &unit->part[PART(c->qid)]; if(unit->vers+pp->vers != c->qid.vers) error(Echange); /* * Check the request is within bounds. * Removeable drives are locked throughout the I/O * in case the media changes unexpectedly. * Non-removeable drives are not locked during the I/O * to allow the hardware to optimise if it can; this is * a little fast and loose. * It's assumed that non-removeable media parameters * (sectors, secsize) can't change once the drive has * been brought online. */ bno = (off/unit->secsize) + pp->start; nb = ((off+len+unit->secsize-1)/unit->secsize) + pp->start - bno; max = SDmaxio/unit->secsize; if(nb > max) nb = max; if(bno+nb > pp->end) nb = pp->end - bno; if(bno >= pp->end || nb == 0){ if(write) error(Eio); qunlock(&unit->ctl); decref(&sdev->r); poperror(); return 0; } if(!(unit->inquiry[1] & SDinq1removable)){ qunlock(&unit->ctl); poperror(); } b = sdmalloc(nb*unit->secsize); if(b == nil) error(Enomem); if(waserror()){ sdfree(b); if(!(unit->inquiry[1] & SDinq1removable)) decref(&sdev->r); /* gadverdamme! */ nexterror(); } offset = off%unit->secsize; if(offset+len > nb*unit->secsize) len = nb*unit->secsize - offset; if(write){ if(offset || (len%unit->secsize)){ l = unit->dev->ifc->bio(unit, 0, 0, b, nb, bno); if(l < 0) error(Eio); if(l < (nb*unit->secsize)){ nb = l/unit->secsize; l = nb*unit->secsize - offset; if(len > l) len = l; } } memmove(b+offset, a, len); l = unit->dev->ifc->bio(unit, 0, 1, b, nb, bno); if(l < 0) error(Eio); if(l < offset) len = 0; else if(len > l - offset) len = l - offset; } else{ l = unit->dev->ifc->bio(unit, 0, 0, b, nb, bno); if(l < 0) error(Eio); if(l < offset) len = 0; else if(len > l - offset) len = l - offset; memmove(a, b+offset, len); } sdfree(b); poperror(); if(unit->inquiry[1] & SDinq1removable){ qunlock(&unit->ctl); poperror(); } decref(&sdev->r); return len; }
static int part_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { struct mtd_part *part = PART(mtd); return mtd_write(part->master, to + part->offset, len, retlen, buf); }
static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len) { struct mtd_part *part = PART(mtd); return mtd_lock_user_prot_reg(part->master, from, len); }
static void part_sync(struct mtd_info *mtd) { struct mtd_part *part = PART(mtd); part->master->sync(part->master); }
static void part_resume(struct mtd_info *mtd) { struct mtd_part *part = PART(mtd); part->master->resume(part->master); }
static void part_unpoint(struct mtd_info *mtd, loff_t from, size_t len) { struct mtd_part *part = PART(mtd); part->master->unpoint(part->master, from + part->offset, len); }
static int amiga_write (const PedDisk* disk) { struct RigidDiskBlock *rdb; struct LinkedBlock *block; struct PartitionBlock *partition; PedPartition *part, *next_part; PedSector cylblocks, first_hb, last_hb; uint32_t * table; uint32_t i; uint32_t rdb_num, part_num, block_num, next_num; PED_ASSERT (disk != NULL); PED_ASSERT (disk->dev != NULL); PED_ASSERT (disk->disk_specific != NULL); if (!(rdb = ped_malloc (disk->dev->sector_size))) return 0; /* Let's read the rdb */ if ((rdb_num = _amiga_find_rdb (disk->dev, rdb)) == AMIGA_RDB_NOT_FOUND) { rdb_num = 2; size_t pb_size = sizeof (struct PartitionBlock); /* Initialize only the part that won't be copied over with a partition block in amiga_read. */ memset ((char *)(RDSK(disk->disk_specific)) + pb_size, 0, PED_SECTOR_SIZE_DEFAULT - pb_size); } else { memcpy (RDSK(disk->disk_specific), rdb, disk->dev->sector_size); } free (rdb); rdb = RDSK(disk->disk_specific); cylblocks = (PedSector) PED_BE32_TO_CPU (rdb->rdb_Heads) * (PedSector) PED_BE32_TO_CPU (rdb->rdb_Sectors); first_hb = (PedSector) PED_BE32_TO_CPU (rdb->rdb_RDBBlocksLo); last_hb = (PedSector) PED_BE32_TO_CPU (rdb->rdb_RDBBlocksHi); /* Allocate a free block table and initialize it. There must be room for at least RDB_NUM + 2 entries, since the first RDB_NUM+1 entries get IDNAME_RIGIDDISK, and the following one must have LINK_END to serve as sentinel. */ size_t tab_size = 2 + MAX (last_hb - first_hb, rdb_num); if (!(table = ped_malloc (tab_size * sizeof *table))) return 0; for (i = 0; i <= rdb_num; i++) table[i] = IDNAME_RIGIDDISK; for ( ; i < tab_size; i++) table[i] = LINK_END; /* Let's allocate a partition block */ if (!(block = ped_malloc (disk->dev->sector_size))) { free (table); return 0; } /* And fill the free block table */ if (_amiga_find_free_blocks(disk, table, block, PED_BE32_TO_CPU (rdb->rdb_BadBlockList), IDNAME_BADBLOCK) == 0) { ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, _("%s : Failed to list bad blocks."), __func__); goto error_free_table; } if (_amiga_find_free_blocks(disk, table, block, PED_BE32_TO_CPU (rdb->rdb_PartitionList), IDNAME_PARTITION) == 0) { ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, _("%s : Failed to list partition blocks."), __func__); goto error_free_table; } if (_amiga_find_free_blocks(disk, table, block, PED_BE32_TO_CPU (rdb->rdb_FileSysHeaderList), IDNAME_FILESYSHEADER) == 0) { ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, _("%s : Failed to list file system blocks."), __func__); goto error_free_table; } if (_amiga_find_free_blocks(disk, table, block, PED_BE32_TO_CPU (rdb->rdb_BootBlockList), IDNAME_BOOT) == 0) { ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, _("%s : Failed to list boot blocks."), __func__); goto error_free_table; } block_num = part_num = _amiga_next_free_block(table, rdb_num+1, IDNAME_PARTITION); part = _amiga_next_real_partition(disk, NULL); rdb->rdb_PartitionList = PED_CPU_TO_BE32(part ? part_num : LINK_END); for (; part != NULL; part = next_part, block_num = next_num) { PED_ASSERT(part->disk_specific != NULL); PED_ASSERT(part->geom.start % cylblocks == 0); PED_ASSERT((part->geom.end + 1) % cylblocks == 0); next_part = _amiga_next_real_partition(disk, part); next_num = _amiga_next_free_block(table, block_num+1, IDNAME_PARTITION); partition = PART(part->disk_specific); if (next_part == NULL) partition->pb_Next = PED_CPU_TO_BE32(LINK_END); else partition->pb_Next = PED_CPU_TO_BE32(next_num); partition->de_LowCyl = PED_CPU_TO_BE32(part->geom.start/cylblocks); partition->de_HighCyl = PED_CPU_TO_BE32((part->geom.end+1)/cylblocks-1); _amiga_calculate_checksum(AMIGA(partition)); if (!ped_device_write (disk->dev, (void*) partition, block_num, 1)) { ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, _("Failed to write partition block at %d."), block_num); goto error_free_table; /* WARNING : If we fail here, we stop everything, * and the partition table is lost. A better * solution should be found, using the second * half of the hardblocks to not overwrite the * old partition table. It becomes problematic * if we use more than half of the hardblocks. */ } } if (block_num > PED_BE32_TO_CPU (rdb->rdb_HighRDSKBlock)) rdb->rdb_HighRDSKBlock = PED_CPU_TO_BE32(block_num); _amiga_calculate_checksum(AMIGA(rdb)); if (!ped_device_write (disk->dev, (void*) disk->disk_specific, rdb_num, 1)) goto error_free_table; free (table); free (block); return ped_device_sync (disk->dev); error_free_table: free (table); free (block); return 0; }
static void edit_properties (SheetItem *object) { GSList *properties; PartItem *item; Part *part; char *internal, *msg; GtkBuilder *gui; GError *error = NULL; GtkGrid *prop_grid; GtkNotebook *notebook; gint response, y = 0; gboolean has_model; gchar *model_name = NULL; g_return_if_fail (object != NULL); g_return_if_fail (IS_PART_ITEM (object)); item = PART_ITEM (object); part = PART (sheet_item_get_data (SHEET_ITEM (item))); internal = part_get_property (part, "internal"); if (internal) { if (g_ascii_strcasecmp (internal, "ground") == 0) { g_free (internal); return; } if (g_ascii_strcasecmp (internal, "point") == 0) { edit_properties_point (item); return; } } g_free (internal); if ((gui = gtk_builder_new ()) == NULL) { oregano_error (_("Could not create part properties dialog.")); return; } else gtk_builder_set_translation_domain (gui, NULL); if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/part-properties-dialog.ui", &error) <= 0) { msg = error->message; oregano_error_with_title (_("Could not create part properties dialog."), msg); g_error_free (error); return; } prop_dialog = g_new0 (PartPropDialog, 1); prop_dialog->part_item = item; prop_dialog->dialog = GTK_DIALOG (gtk_builder_get_object (gui, "part-properties-dialog")); prop_grid = GTK_GRID (gtk_builder_get_object (gui, "prop_grid")); notebook = GTK_NOTEBOOK (gtk_builder_get_object (gui, "notebook")); g_signal_connect (prop_dialog->dialog, "destroy", G_CALLBACK (prop_dialog_destroy), prop_dialog); prop_dialog->widgets = NULL; has_model = FALSE; for (properties = part_get_properties (part); properties; properties = properties->next) { Property *prop; prop = properties->data; if (prop->name) { GtkWidget *entry; GtkWidget *label; gchar *temp=NULL; if (!g_ascii_strcasecmp (prop->name, "internal")) continue; if (!g_ascii_strcasecmp (prop->name, "model")) { has_model = TRUE; model_name = g_strdup (prop->value); } // Find the Refdes and replace by their real value temp = prop->name; if (!g_ascii_strcasecmp (temp, "Refdes")) temp = _("Designation"); if (!g_ascii_strcasecmp (temp, "Template")) temp = _("Template"); if (!g_ascii_strcasecmp (temp, "Res")) temp = _("Resistor"); if (!g_ascii_strcasecmp (temp, "Cap")) temp = _("Capacitor"); if (!g_ascii_strcasecmp (temp, "Ind")) temp = _("Inductor"); label = gtk_label_new (temp); entry = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (entry), prop->value); g_object_set_data (G_OBJECT (entry), "user", g_strdup (prop->name)); gtk_grid_attach (prop_grid, label, 0,y, 1,1); gtk_grid_attach (prop_grid, entry, 1,y, 1,1); y++; gtk_widget_show (label); gtk_widget_show (entry); prop_dialog->widgets = g_list_prepend (prop_dialog->widgets, entry); } } if (!has_model) { gtk_notebook_remove_page (notebook, 1); } else { GtkTextBuffer *txtbuffer; GtkTextView *txtmodel; gchar *filename, *str; GError *read_error = NULL; txtmodel = GTK_TEXT_VIEW (gtk_builder_get_object (gui, "txtmodel")); txtbuffer = gtk_text_buffer_new (NULL); filename = g_strdup_printf ("%s/%s.model", OREGANO_MODELDIR, model_name); if (g_file_get_contents (filename, &str, NULL, &read_error)) { gtk_text_buffer_set_text (txtbuffer, str, -1); g_free (str); } else { gtk_text_buffer_set_text (txtbuffer, read_error->message, -1); g_error_free (read_error); } g_free (filename); g_free (model_name); gtk_text_view_set_buffer (txtmodel, txtbuffer); } gtk_dialog_set_default_response (prop_dialog->dialog, 1); response = gtk_dialog_run (prop_dialog->dialog); prop_dialog_response (GTK_WIDGET (prop_dialog->dialog), response, prop_dialog); g_slist_free_full (properties, g_object_unref); gtk_widget_destroy (GTK_WIDGET (prop_dialog->dialog)); }
/** * whenever the model changes, this one gets called to update the view representation * @attention this recalculates the matrix every time, this makes sure no errors stack up * @attention further reading on matrix manipulations * @attention http://www.cairographics.org/matrix_transform/ * @param data the model item, a bare C struct derived from ItemData * @param sheet_item the view item, derived from goo_canvas_group/item */ static void part_changed_callback (ItemData *data, SheetItem *sheet_item) { //TODO add static vars in order to skip the redraw if nothing changed //TODO may happen once in a while and the check is really cheap GSList *iter; GooCanvasAnchorType anchor; GooCanvasGroup *group; GooCanvasItem *canvas_item; PartItem *item; PartItemPriv *priv; Part *part; int index = 0; Coords pos; double scale_h, scale_v; // states int rotation; IDFlip flip; g_return_if_fail (sheet_item != NULL); g_return_if_fail (IS_PART_ITEM (sheet_item)); item = PART_ITEM (sheet_item); group = GOO_CANVAS_GROUP (item); part = PART (data); priv = item->priv; // init the states flip = part_get_flip (part); rotation = part_get_rotation (part); DEGSANITY (rotation); scale_h = (flip & ID_FLIP_HORIZ) ? -1. : 1.; scale_v = (flip & ID_FLIP_VERT) ? -1. : 1.; item_data_get_pos (data, &pos); // Move the canvas item and invalidate the bbox cache. goo_canvas_item_set_simple_transform (GOO_CANVAS_ITEM (sheet_item), pos.x, pos.y, 1.0, 0.0); cairo_matrix_t morph, inv; cairo_status_t done; cairo_matrix_init_rotate (&morph, DEG2RAD (rotation)); cairo_matrix_scale (&morph, scale_h, scale_v); inv = morph; done = cairo_matrix_invert (&inv); if (done != CAIRO_STATUS_SUCCESS) { g_warning ("Failed to invert matrix. This should never happen. Never!"); return; } // rotate all items in the canvas group for (index = 0; index < group->items->len; index++) { canvas_item = GOO_CANVAS_ITEM (group->items->pdata[index]); goo_canvas_item_set_transform (GOO_CANVAS_ITEM (canvas_item), &morph); } // revert the rotation of all labels and change their anchor to not overlap too badly // this assures that the text is always horizontal and properly aligned anchor = angle_to_anchor (rotation); for (iter = priv->label_items; iter; iter = iter->next) { g_object_set (iter->data, "anchor", anchor, NULL); goo_canvas_item_set_transform (iter->data, &inv); } // same for label nodes for (iter = priv->label_nodes; iter; iter = iter->next) { g_object_set (iter->data, "anchor", anchor, NULL); goo_canvas_item_set_transform (iter->data, &inv); } // Invalidate the bounding box cache. priv->cache_valid = FALSE; }
static void edit_properties_point (PartItem *item) { GSList *properties; Part *part; GtkBuilder *gui; GError *error = NULL; GtkRadioButton *radio_v, *radio_c; GtkRadioButton *ac_r, *ac_m, *ac_i, *ac_p; GtkCheckButton *chk_db; part = PART (sheet_item_get_data (SHEET_ITEM (item))); if ((gui = gtk_builder_new ()) == NULL) { oregano_error (_("Could not create part properties dialog.")); return; } gtk_builder_set_translation_domain (gui, NULL); if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/clamp-properties-dialog.ui", &error) <= 0) { oregano_error_with_title (_("Could not create part properties dialog."), error->message); g_error_free (error); return; } prop_dialog = g_new0 (PartPropDialog, 1); prop_dialog->part_item = item; prop_dialog->dialog = GTK_DIALOG (gtk_builder_get_object (gui, "clamp-properties-dialog")); radio_v = GTK_RADIO_BUTTON (gtk_builder_get_object (gui, "radio_v")); radio_c = GTK_RADIO_BUTTON (gtk_builder_get_object (gui, "radio_c")); gtk_widget_set_sensitive (GTK_WIDGET (radio_c), FALSE); ac_r = GTK_RADIO_BUTTON (gtk_builder_get_object (gui, "radio_r")); ac_m = GTK_RADIO_BUTTON (gtk_builder_get_object (gui, "radio_m")); ac_p = GTK_RADIO_BUTTON (gtk_builder_get_object (gui, "radio_p")); ac_i = GTK_RADIO_BUTTON (gtk_builder_get_object (gui, "radio_i")); chk_db = GTK_CHECK_BUTTON (gtk_builder_get_object (gui, "check_db")); // Setup GUI from properties for (properties = part_get_properties (part); properties; properties = properties->next) { Property *prop; prop = properties->data; if (prop->name) { if (!g_ascii_strcasecmp (prop->name, "internal")) continue; if (!g_ascii_strcasecmp (prop->name, "type")) { if (!g_ascii_strcasecmp (prop->value, "v")) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_v), TRUE); } else { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_c), TRUE); } } else if (!g_ascii_strcasecmp (prop->name, "ac_type")) { if (!g_ascii_strcasecmp (prop->value, "m")) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ac_m), TRUE); } else if (!g_ascii_strcasecmp (prop->value, "i")) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ac_i), TRUE); } else if (!g_ascii_strcasecmp (prop->value, "p")) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ac_p), TRUE); } else if (!g_ascii_strcasecmp (prop->value, "r")) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ac_r), TRUE); } } else if (!g_ascii_strcasecmp (prop->name, "ac_db")) { if (!g_ascii_strcasecmp (prop->value, "true")) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chk_db), TRUE); } } } gtk_dialog_run (prop_dialog->dialog); // Save properties from GUI for (properties = part_get_properties (part); properties; properties = properties->next) { Property *prop; prop = properties->data; if (prop->name) { if (!g_ascii_strcasecmp (prop->name, "internal")) continue; if (!g_ascii_strcasecmp (prop->name, "type")) { g_free (prop->value); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_v))) { prop->value = g_strdup ("v"); } else { prop->value = g_strdup ("i"); } } else if (!g_ascii_strcasecmp (prop->name, "ac_type")) { g_free (prop->value); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ac_m))) { prop->value = g_strdup ("m"); } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ac_i))) { prop->value = g_strdup ("i"); } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ac_p))) { prop->value = g_strdup ("p"); } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ac_r))) { prop->value = g_strdup ("r"); } } else if (!g_ascii_strcasecmp (prop->name, "ac_db")) { g_free (prop->value); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (chk_db))) prop->value = g_strdup ("true"); else prop->value = g_strdup ("false"); } } } g_slist_free_full (properties, g_object_unref); gtk_widget_destroy (GTK_WIDGET (prop_dialog->dialog)); }
void game::init_vehicles() { vehicle *veh; int index = 0; int pi; vtypes.push_back(new vehicle(this, (vhtype_id)index++)); // veh_null vtypes.push_back(new vehicle(this, (vhtype_id)index++)); // veh_custom #define VEHICLE(nm) { veh = new vehicle(this, (vhtype_id)index++); veh->name = nm; vtypes.push_back(veh); } #define PART(mdx, mdy, id) { pi = veh->install_part(mdx, mdy, id); \ if (pi < 0) debugmsg("init_vehicles: '%s' part '%s'(%d) can't be installed to %d,%d", veh->name.c_str(), vpart_list[id].name, veh->parts.size(), mdx, mdy); } // name VEHICLE ("Bicycle"); // o // # // o // dx, dy, part_id PART (0, 0, vp_frame_v2); PART (0, 0, vp_seat); PART (0, 0, vp_controls); PART (0, 0, vp_engine_foot_crank); PART (1, 0, vp_wheel_bicycle); PART (-1, 0, vp_wheel_bicycle); PART (-1, 0, vp_cargo_box); // name VEHICLE ("Motorcycle Chassis"); // o // ^ // # // o // dx, dy, part_id PART (0, 0, vp_frame_v2); PART (0, 0, vp_seat); PART (1, 0, vp_frame_handle); PART (1, 0, vp_fuel_tank_gas); PART (-1, 0, vp_wheel); // name VEHICLE ("Motorcycle"); // o // ^ // # // o // dx, dy, part_id PART (0, 0, vp_frame_v2); PART (0, 0, vp_seat); PART (0, 0, vp_controls); PART (0, 0, vp_engine_gas_v2); PART (1, 0, vp_frame_handle); PART (1, 0, vp_head_light); PART (1, 0, vp_fuel_tank_gas); PART (2, 0, vp_wheel); PART (-1, 0, vp_wheel); PART (-1, 0, vp_cargo_box); // name VEHICLE ("Quad Bike"); // 0^0 // # // 0H0 // dx, dy, part_id PART (0, 0, vp_frame_v2); PART (0, 0, vp_seat); PART (0, 0, vp_controls); PART (1, 0, vp_frame_cover); PART (1, 0, vp_engine_gas_v2); PART (1, 0, vp_head_light); PART (1, 0, vp_fuel_tank_gas); PART (1, 0, vp_steel_plate); PART (-1,0, vp_frame_h); PART (-1,0, vp_cargo_trunk); PART (-1,0, vp_steel_plate); PART (1, -1, vp_wheel_motorbike); PART (1, 1, vp_wheel_motorbike); PART (-1,-1, vp_wheel_motorbike); PART (-1, 1, vp_wheel_motorbike); // name VEHICLE ("Quad Bike Chassis"); // 0^0 // # // 0H0 // dx, dy, part_id PART (0, 0, vp_frame_v2); PART (0, 0, vp_seat); PART (1, 0, vp_frame_cover); PART (-1,0, vp_frame_h); PART (1, -1, vp_wheel_motorbike); PART (-1,-1, vp_wheel_motorbike); PART (-1, 1, vp_wheel_motorbike); // name VEHICLE ("Car"); // o--o // |""| // +##+ // +##+ // |HH| // o++o // dx, dy, part_id PART (0, 0, vp_frame_v2); PART (0, 0, vp_seat); PART (0, 0, vp_seatbelt); PART (0, 0, vp_controls); PART (0, 0, vp_roof); PART (0, 1, vp_frame_v2); PART (0, 1, vp_seat); PART (0, 1, vp_seatbelt); PART (0, 1, vp_roof); PART (0, -1, vp_door); PART (0, 2, vp_door); PART (-1, 0, vp_frame_v2); PART (-1, 0, vp_seat); PART (-1, 0, vp_seatbelt); PART (-1, 0, vp_roof); PART (-1, 1, vp_frame_v2); PART (-1, 1, vp_seat); PART (-1, 1, vp_seatbelt); PART (-1, 1, vp_roof); PART (-1, -1, vp_door); PART (-1, 2, vp_door); PART (1, 0, vp_frame_h); PART (1, 0, vp_window); PART (1, 0, vp_head_light); PART (1, 1, vp_frame_h); PART (1, 1, vp_window); PART (1, 1, vp_head_light); PART (1, -1, vp_frame_v); PART (1, 2, vp_frame_v); PART (2, 0, vp_frame_h); PART (2, 0, vp_engine_gas_v6); PART (2, 1, vp_frame_h); PART (2, -1, vp_wheel); PART (2, 2, vp_wheel); PART (-2, 0, vp_frame_v); PART (-2, 0, vp_cargo_trunk); PART (-2, 0, vp_muffler); PART (-2, 0, vp_roof); PART (-2, 1, vp_frame_v); PART (-2, 1, vp_cargo_trunk); PART (-2, 1, vp_roof); PART (-2, -1, vp_board_v); PART (-2, -1, vp_fuel_tank_gas); PART (-2, 2, vp_board_v); PART (-3, -1, vp_wheel); PART (-3, 0, vp_door); PART (-3, 1, vp_door); PART (-3, 2, vp_wheel); // name VEHICLE ("Car Chassis"); // o--o // |""| // +##+ // +##+ // |HH| // o++o // dx, dy, part_id PART (0, 0, vp_frame_v2); PART (0, 0, vp_seat); PART (0, 1, vp_frame_v2); PART (-1, 0, vp_frame_v2); PART (-1, 1, vp_frame_v2); PART (1, 0, vp_frame_h); PART (1, 1, vp_frame_h); PART (1, -1, vp_frame_v); PART (1, 2, vp_frame_v); PART (2, 0, vp_frame_h); PART (2, 1, vp_frame_h); PART (2, -1, vp_wheel); PART (2, 2, vp_wheel); PART (-2, 0, vp_frame_v2); PART (-2, 1, vp_frame_v2); PART (-2, -1, vp_board_v); PART (-2, -1, vp_fuel_tank_gas); PART (-2, 2, vp_board_v); PART (-3, -1, vp_wheel); PART (-3, 2, vp_wheel); // name VEHICLE ("Flatbed Truck"); // 0-^-0 // |"""| // +###+ // |---| // |HHH| // 0HHH0 PART (0, 0, vp_frame_v); PART (0, 0, vp_cargo_box); PART (0, 0, vp_roof); // PART (0, 0, vp_seatbelt); PART (0, -1, vp_frame_v2); PART (0, -1, vp_seat); PART (0, -1, vp_seatbelt); PART (0, -1, vp_roof); PART (0, 1, vp_frame_v2); PART (0, 1, vp_seat); PART (0, 1, vp_seatbelt); PART (0, 1, vp_roof); PART (0, -2, vp_door); PART (0, 2, vp_door); PART (0, -1, vp_controls); PART (1, 0, vp_frame_h); PART (1, 0, vp_window); PART (1, -1, vp_frame_h); PART (1, -1, vp_window); PART (1, -1, vp_head_light); PART (1, 1, vp_frame_h); PART (1, 1, vp_window); PART (1, 1, vp_head_light); PART (1, -2, vp_frame_v); PART (1, 2, vp_frame_v); PART (2, -1, vp_frame_h); PART (2, 0, vp_frame_cover); PART (2, 0, vp_engine_gas_v6); PART (2, 1, vp_frame_h); PART (2, -2, vp_wheel_wide); PART (2, 2, vp_wheel_wide); PART (-1, -1, vp_board_h); PART (-1, 0, vp_board_h); PART (-1, 1, vp_board_h); PART (-1, -2, vp_board_b); PART (-1, -2, vp_fuel_tank_gas); PART (-1, 2, vp_board_n); PART (-1, 2, vp_fuel_tank_gas); PART (-2, -1, vp_frame_v); PART (-2, -1, vp_cargo_trunk); PART (-2, 0, vp_frame_v); PART (-2, 0, vp_cargo_trunk); PART (-2, 1, vp_frame_v); PART (-2, 1, vp_cargo_trunk); PART (-2, -2, vp_board_v); PART (-2, 2, vp_board_v); PART (-3, -1, vp_frame_h); PART (-3, -1, vp_cargo_trunk); PART (-3, 0, vp_frame_h); PART (-3, 0, vp_cargo_trunk); PART (-3, 1, vp_frame_h); PART (-3, 1, vp_cargo_trunk); PART (-3, -2, vp_wheel_wide); PART (-3, 2, vp_wheel_wide); VEHICLE ("Semi Truck"); // semitrucksleeper // |=^^=| // O-HH-O // |""""| // +#oo#+ // |--+-| // |#oo#| // |----| // H||H // OO++OO // OO++OO // Based loosely on a Peterbilt Semi. 6L engine and 4 fuel tanks. 2 seater. Sleeper cab has zero visibility when opaque door is closed. // dx, dy, part_id PART (0, 0, vp_frame_v2); PART (0, 0, vp_cargo_box); PART (0, 0, vp_roof); PART (0, 1, vp_frame_v2); PART (0, 1, vp_bed); PART (0, 1, vp_roof); PART (0, -1, vp_frame_v2); PART (0, -1, vp_cargo_box); PART (0, -1, vp_roof); PART (0, 2, vp_board_v); PART (0, 2, vp_fuel_tank_gas); PART (0, -2, vp_frame_v2); PART (0, -2, vp_bed); PART (0, -2, vp_roof); PART (0, -3, vp_board_v); PART (0, -3, vp_fuel_tank_gas); PART (1, 0, vp_door_i); PART (1, -1, vp_board_h); PART (1, 1, vp_board_h); PART (1, -2, vp_board_h); PART (1, 2, vp_board_v); PART (1, 2, vp_fuel_tank_gas); PART (1, -3, vp_board_v); PART (1, -3, vp_fuel_tank_gas); PART (-1, 0, vp_board_h); PART (-1, 1, vp_board_h); PART (-1, -1, vp_board_h); PART (-1, -2, vp_board_h); PART (-1, 2, vp_board_n); PART (-1, -3, vp_board_b); PART (2, -1, vp_frame_h); PART (2, -1, vp_cargo_box); PART (2, -1, vp_roof); PART (2, 1, vp_frame_v2); PART (2, 1, vp_seat); PART (2, 1, vp_seatbelt); PART (2, 1, vp_roof); PART (2, -2, vp_frame_v2); PART (2, -2, vp_seat); PART (2, -2, vp_seatbelt); PART (2, -2, vp_roof); PART (2, 0, vp_frame_h); PART (2, 0, vp_cargo_box); PART (2, 0, vp_roof); PART (2, 2, vp_door); PART (2, -3, vp_door); PART (2, -2, vp_controls); PART (-2, 0, vp_frame_v); PART (-2, -1, vp_frame_v); PART (-2, 1, vp_frame_v2); PART (-2, 1, vp_cargo_trunk); PART (-2, -2, vp_frame_v2); PART (-2, -2, vp_cargo_trunk); PART (3, 0, vp_frame_h); PART (3, 0, vp_window); PART (3, -1, vp_frame_h); PART (3, -1, vp_window); PART (3, 1, vp_frame_h); PART (3, 1, vp_window); PART (3, -2, vp_frame_h); PART (3, -2, vp_window); PART (3, 2, vp_board_v); PART (3, -3, vp_board_v); PART (-3, 0, vp_frame_c); PART (-3, -1, vp_frame_c); PART (-3, 1, vp_wheel_wide); PART (-3, -2, vp_wheel_wide); PART (-3, 2, vp_wheel_wide); PART (-3, -3, vp_wheel_wide); PART (4, 0, vp_frame_v2); PART (4, -1, vp_frame_v2); PART (4, -1, vp_engine_gas_v8); PART (4, 1, vp_frame_h); PART (4, -2, vp_frame_h); PART (4, 2, vp_wheel_wide); PART (4, -3, vp_wheel_wide); PART (-4, 0, vp_frame_c); PART (-4, -1, vp_frame_c); PART (-4, 1, vp_wheel_wide); PART (-4, -2, vp_wheel_wide); PART (-4, 2, vp_wheel_wide); PART (-4, -3, vp_wheel_wide); PART (5, 0, vp_frame_cover); PART (5, -1, vp_frame_cover); PART (5, 1, vp_frame_h2); PART (5, -2, vp_frame_h2); PART (5, 2, vp_frame_u); PART (5, -3, vp_frame_y); VEHICLE ("Truck Trailer"); // trucktrailer // |----| // |-++-| // |-++-| // |----| // |-HH-| // |----| // OO++OO // OO++OO // |----| // |-++-| // Pelletier trailer. Awaiting hitching of vehicles to each other... // dx, dy, part_id PART (0, 0, vp_frame_v2); PART (0, -1, vp_frame_v2); PART (0, 1, vp_frame_h); PART (0, -2, vp_frame_h); PART (0, 2, vp_board_v); PART (0, -3, vp_board_v); PART (1, 0, vp_frame_h); PART (1, -1, vp_frame_h); PART (1, 1, vp_frame_h); PART (1, -2, vp_frame_h); PART (1, 2, vp_board_v); PART (1, -3, vp_board_v); PART (-1, 0, vp_frame_c); PART (-1, -1, vp_frame_c); PART (-1, 1, vp_wheel_wide); PART (-1, -2, vp_wheel_wide); PART (-1, 2, vp_wheel_wide); PART (-1, -3, vp_wheel_wide); PART (2, 0, vp_frame_h); PART (2, -1, vp_frame_h); PART (2, 1, vp_frame_h); PART (2, -2, vp_frame_h); PART (2, 2, vp_board_v); PART (2, -3, vp_board_v); PART (-2, 0, vp_frame_c); PART (-2, -1, vp_frame_c); PART (-2, 1, vp_wheel_wide); PART (-2, -2, vp_wheel_wide); PART (-2, 2, vp_wheel_wide); PART (-2, -3, vp_wheel_wide); PART (3, 0, vp_frame_h); PART (3, -1, vp_frame_h); PART (3, 1, vp_frame_h); PART (3, -2, vp_frame_h); PART (3, 2, vp_board_v); PART (3, -3, vp_board_v); PART (-3, 0, vp_frame_h); PART (-3, -1, vp_frame_h); PART (-3, 1, vp_frame_h); PART (-3, -2, vp_frame_h); PART (-3, 2, vp_board_v); PART (-3, -3, vp_board_v); PART (4, 0, vp_frame_c); PART (4, -1, vp_frame_c); PART (4, 1, vp_frame_h); PART (4, -2, vp_frame_h); PART (4, 2, vp_board_v); PART (4, -3, vp_board_v); PART (-4, 0, vp_door_o); PART (-4, -1, vp_door_o); PART (-4, 1, vp_board_h); PART (-4, -2, vp_board_h); PART (-4, 2, vp_board_n); PART (-4, -3, vp_board_b); PART (5, 0, vp_board_h); PART (5, -1, vp_board_h); PART (5, 1, vp_board_h); PART (5, -2, vp_board_h); PART (5, 2, vp_board_u); PART (5, -3, vp_board_y); VEHICLE ("Wagon"); // HHH // HHH // HHH PART (0, 0, vp_frame_v2); PART (0, 1, vp_frame_v2); PART (0, -1, vp_frame_v2); PART (1, 0, vp_frame_v2); PART (1, 1, vp_frame_v2); PART (1, -1, vp_frame_v2); PART (-1, 0, vp_frame_v2); PART (-1, 1, vp_frame_v2); PART (-1, -1, vp_frame_v2); VEHICLE ("Beetle"); // vwbug // oHHo // |--| // +HH+ // o\/o //Volkswagen Bug. Removed back seats entirely to make it feel smaller. Engine in back and cargo/fuel in front. // dx, dy, part_id PART (0, 0, vp_frame_v2); PART (0, 0, vp_seat); PART (0, 0, vp_seatbelt); PART (0, 0, vp_roof); PART (0, 0, vp_controls); PART (0, 1, vp_frame_v2); PART (0, 1, vp_seat); PART (0, 1, vp_seatbelt); PART (0, 1, vp_roof); PART (0, -1, vp_door); PART (0, 2, vp_door); PART (1, 0, vp_frame_h); PART (1, 0, vp_window); PART (1, 0, vp_head_light); PART (1, 1, vp_frame_h); PART (1, 1, vp_window); PART (1, 1, vp_head_light); PART (1, -1, vp_board_v); PART (1, 2, vp_board_v); PART (-1, 0, vp_frame_u); PART (-1, 0, vp_engine_gas_i4); PART (-1, 1, vp_board_y); PART (-1, -1, vp_wheel); PART (-1, 2, vp_wheel); PART (2, 0, vp_frame_v2); PART (2, 0, vp_cargo_trunk); PART (2, 1, vp_frame_v2); PART (2, 1, vp_fuel_tank_gas); PART (2, -1, vp_wheel); PART (2, 2, vp_wheel); VEHICLE ("Bubble Car"); // |-| // |o#o| // |###| // |oHo| // +-+ // dx, dy, part_id PART (0, 0, vp_frame_v2); PART (0, 0, vp_seat); PART (0, 0, vp_engine_motor); PART (0, 0, vp_fuel_tank_plut); PART (0, 0, vp_seatbelt); PART (0, 0, vp_roof); PART (0, 1, vp_frame_v2); PART (0, 1, vp_seat); PART (0, 1, vp_seatbelt); PART (0, 1, vp_roof); PART (0, -1, vp_frame_v2); PART (0, -1, vp_seat); PART (0, -1, vp_seatbelt); PART (0, -1, vp_roof); PART (0, 2, vp_frame_v); PART (0, 2, vp_window); PART (0, -2, vp_frame_v); PART (0, -2, vp_window); PART (1, 0, vp_frame_h); PART (1, 0, vp_seat); PART (1, 0, vp_seatbelt); PART (1, 0, vp_roof); PART (1, 0, vp_controls); PART (0, 0, vp_head_light); PART (1, 1, vp_wheel); PART (1, 1, vp_window); PART (1, -1, vp_wheel); PART (1, -1, vp_window); PART (1, 2, vp_frame_u); PART (1, 2, vp_window); PART (1, -2, vp_frame_y); PART (1, -2, vp_window); PART (-1, 0, vp_frame_h); PART (-1, 0, vp_cargo_trunk); PART (-1, 1, vp_wheel); PART (-1, 1, vp_window); PART (-1, -1, vp_wheel); PART (-1, -1, vp_window); PART (-1, 2, vp_door); PART (-1, -2, vp_door); PART (2, 0, vp_frame_h); PART (2, 0, vp_window); PART (2, 1, vp_frame_u); PART (2, 1, vp_window); PART (2, -1, vp_frame_y); PART (2, -1, vp_window); PART (-2, 0, vp_frame_h); PART (-2, 0, vp_window); PART (-2, 1, vp_frame_n); PART (-2, 1, vp_window); PART (-2, -1, vp_frame_b); PART (-2, -1, vp_window); VEHICLE ("Golf Cart"); // Yamaha golf cart // oo // -- // oo // Just an electric golf cart. // dx, dy, part_id PART (0, 0, vp_frame_h); PART (0, 0, vp_seat); PART (0, 0, vp_roof); PART (0, 0, vp_engine_motor); PART (0, 0, vp_controls); PART (0, 1, vp_frame_h); PART (0, 1, vp_seat); PART (0, 1, vp_roof); PART (0, 1, vp_fuel_tank_batt); PART (1, 0, vp_wheel); PART (1, 1, vp_wheel); PART (-1, 0, vp_wheel); PART (-1, 1, vp_wheel); VEHICLE ("Scooter"); // Vespa scooter // o // ^ // o // Just an underpowered gas scooter. // dx, dy, part_id PART (0, 0, vp_frame_handle); PART (0, 0, vp_seat); PART (0, 0, vp_engine_gas_1cyl); PART (0, 0, vp_fuel_tank_gas); PART (0, 0, vp_controls); PART (1, 0, vp_wheel); PART (-1, 0, vp_wheel); VEHICLE ("Military Cargo Truck"); // Army M35A2 2.5 ton cargo truck // |^^^| // O-H-O // |"""| // +###+ // |"""| // |#-#| // OO-OO // OO-OO // |#-#| // 3 seater. 6L engine default. // dx, dy, part_id PART (0, 0, vp_frame_v2); PART (0, 0, vp_window); PART (0, -1, vp_frame_h); PART (0, -1, vp_window); PART (0, 1, vp_frame_h); PART (0, 1, vp_window); PART (0, -2, vp_board_v); PART (0, 2, vp_board_v); PART (1, 0, vp_frame_v2); PART (1, 0, vp_seat); PART (1, 0, vp_fuel_tank_gas); // PART (1, 0, vp_fuel_tank_hydrogen); PART (1, 0, vp_seatbelt); PART (1, 0, vp_roof); PART (1, -1, vp_frame_v2); PART (1, -1, vp_seat); PART (1, -1, vp_fuel_tank_gas); // PART (1, -1, vp_fuel_tank_hydrogen); PART (1, -1, vp_seatbelt); PART (1, -1, vp_roof); PART (1, -1, vp_controls); PART (1, 1, vp_frame_v2); PART (1, 1, vp_seat); PART (1, 1, vp_fuel_tank_gas); // PART (1, 1, vp_fuel_tank_hydrogen); PART (1, 1, vp_seatbelt); PART (1, 1, vp_roof); PART (1, -2, vp_door); PART (1, 2, vp_door); PART (-1, 0, vp_frame_h); PART (-1, -1, vp_frame_v2); PART (-1, -1, vp_seat); PART (-1, 1, vp_frame_v2); PART (-1, 1, vp_seat); PART (-1, -2, vp_frame_v); PART (-1, 2, vp_frame_v); PART (2, 0, vp_frame_h); PART (2, 0, vp_window); PART (2, -1, vp_frame_h); PART (2, -1, vp_window); PART (2, 1, vp_frame_h); PART (2, 1, vp_window); PART (2, -2, vp_frame_v); PART (2, 2, vp_frame_v); PART (-2, 0, vp_frame_h); PART (-2, -1, vp_wheel_wide); PART (-2, -1, vp_seat); PART (-2, -1, vp_steel_plate); PART (-2, 1, vp_wheel_wide); PART (-2, 1, vp_seat); PART (-2, 1, vp_steel_plate); PART (-2, -2, vp_wheel_wide); PART (-2, -2, vp_steel_plate); PART (-2, 2, vp_wheel_wide); PART (-2, 2, vp_steel_plate); PART (3, 0, vp_frame_v2); PART (3, -1, vp_frame_h); PART (3, 1, vp_frame_h); PART (3, 0, vp_engine_gas_v8); PART (3, 0, vp_steel_plate); // switch for hydrogen fuel or use both and change (3,0) to (3,1) and (3,-1) // PART (3, 0, vp_engine_plasma); PART (3, -2, vp_wheel_wide); PART (3, -2, vp_steel_plate); PART (3, 2, vp_wheel_wide); PART (3, 2, vp_steel_plate); PART (-3, 0, vp_frame_h); PART (-3, -1, vp_wheel_wide); PART (-3, -1, vp_seat); PART (-3, -1, vp_steel_plate); PART (-3, 1, vp_wheel_wide); PART (-3, 1, vp_seat); PART (-3, 1, vp_steel_plate); PART (-3, -2, vp_wheel_wide); PART (-3, -2, vp_steel_plate); PART (-3, 2, vp_wheel_wide); PART (-3, 2, vp_steel_plate); PART (4, 0, vp_frame_h2); PART (4, 0, vp_steel_plate); PART (4, -1, vp_frame_h2); PART (4, -1, vp_steel_plate); PART (4, 1, vp_frame_h2); PART (4, 1, vp_steel_plate); PART (4, -2, vp_frame_y); PART (4, -2, vp_steel_plate); PART (4, 2, vp_frame_u); PART (4, 2, vp_steel_plate); PART (-4, 0, vp_frame_h); PART (-4, -1, vp_frame_v2); PART (-4, -1, vp_seat); PART (-4, 1, vp_frame_v2); PART (-4, 1, vp_seat); PART (-4, -2, vp_frame_v); PART (-4, 2, vp_frame_v); VEHICLE ("Schoolbus"); // Schoolbus // O=^=O // """"" // "#..+ // "#.#" // "#.#" // "#.#" // "#.#" // "#.#" // O#.#O // "#.#" // ""+"" // dx, dy, part_id PART ( 0, 0, vp_frame_v2); PART ( 0, 0, vp_roof); PART ( 0, 1, vp_frame_v2); PART ( 0, 1, vp_roof); PART ( 0, 2, vp_door); PART ( 0, -1, vp_frame_v2); PART ( 0, -1, vp_seat); PART ( 0, -1, vp_controls); PART ( 0, -1, vp_roof); PART ( 0, -2, vp_frame_v); PART ( 0, -2, vp_window); PART ( 1, -2, vp_frame_h); PART ( 1, -2, vp_window); PART ( 1, -1, vp_frame_h); PART ( 1, -1, vp_window); PART ( 1, 0, vp_frame_h); PART ( 1, 0, vp_window); PART ( 1, 1, vp_frame_h); PART ( 1, 1, vp_window); PART ( 1, 2, vp_frame_h); PART ( 1, 2, vp_window); PART ( 2, -2, vp_wheel_wide); PART ( 2, -1, vp_frame_h2); PART ( 2, -1, vp_head_light); PART ( 2, 0, vp_frame_cover); PART ( 2, 0, vp_engine_gas_v8); PART ( 2, 1, vp_frame_h2); PART ( 2, 1, vp_head_light); PART ( 2, 2, vp_wheel_wide); PART ( -1, -2, vp_frame_v); PART ( -1, -2, vp_window); PART ( -1, -1, vp_frame_h2); PART ( -1, -1, vp_seat); PART ( -1, -1, vp_roof); PART ( -1, 0, vp_frame_v2); PART ( -1, 0, vp_roof); PART ( -1, 1, vp_frame_h2); PART ( -1, 1, vp_seat); PART ( -1, 1, vp_roof); PART ( -1, 2, vp_frame_v); PART ( -1, 2, vp_window); PART ( -1, 2, vp_fuel_tank_gas); PART ( -2, -2, vp_frame_v); PART ( -2, -2, vp_window); PART ( -2, -1, vp_frame_h2); PART ( -2, -1, vp_seat); PART ( -2, -1, vp_roof); PART ( -2, 0, vp_frame_v2); PART ( -2, 0, vp_roof); PART ( -2, 1, vp_frame_h2); PART ( -2, 1, vp_seat); PART ( -2, 1, vp_roof); PART ( -2, 2, vp_frame_v); PART ( -2, 2, vp_window); PART ( -2, 2, vp_fuel_tank_gas); PART ( -3, -2, vp_frame_v); PART ( -3, -2, vp_window); PART ( -3, -1, vp_frame_h2); PART ( -3, -1, vp_seat); PART ( -3, -1, vp_roof); PART ( -3, 0, vp_frame_v2); PART ( -3, 0, vp_roof); PART ( -3, 1, vp_frame_h2); PART ( -3, 1, vp_seat); PART ( -3, 1, vp_roof); PART ( -3, 2, vp_frame_v); PART ( -3, 2, vp_window); PART ( -4, -2, vp_frame_v); PART ( -4, -2, vp_window); PART ( -4, -1, vp_frame_h2); PART ( -4, -1, vp_seat); PART ( -4, -1, vp_roof); PART ( -4, 0, vp_frame_v2); PART ( -4, 0, vp_roof); PART ( -4, 1, vp_frame_h2); PART ( -4, 1, vp_seat); PART ( -4, 1, vp_roof); PART ( -4, 2, vp_frame_v); PART ( -4, 2, vp_window); PART ( -5, -2, vp_frame_v); PART ( -5, -2, vp_window); PART ( -5, -1, vp_frame_h2); PART ( -5, -1, vp_seat); PART ( -5, -1, vp_roof); PART ( -5, 0, vp_frame_v2); PART ( -5, 0, vp_roof); PART ( -5, 1, vp_frame_h2); PART ( -5, 1, vp_seat); PART ( -5, 1, vp_roof); PART ( -5, 2, vp_frame_v); PART ( -5, 2, vp_window); PART ( -6, -2, vp_wheel_wide); // PART ( -6, -2, vp_window); PART ( -6, -1, vp_frame_h2); PART ( -6, -1, vp_seat); PART ( -6, -1, vp_roof); PART ( -6, 0, vp_frame_v2); PART ( -6, 0, vp_roof); PART ( -6, 1, vp_frame_h2); PART ( -6, 1, vp_seat); PART ( -6, 1, vp_roof); PART ( -6, 2, vp_wheel_wide); // PART ( -6, 2, vp_window); PART ( -7, -2, vp_frame_v); PART ( -7, -2, vp_window); PART ( -7, -1, vp_frame_h2); PART ( -7, -1, vp_seat); PART ( -7, -1, vp_roof); PART ( -7, 0, vp_frame_v2); PART ( -7, 0, vp_roof); PART ( -7, 1, vp_frame_h2); PART ( -7, 1, vp_seat); PART ( -7, 1, vp_roof); PART ( -7, 2, vp_frame_v); PART ( -7, 2, vp_window); PART ( -8, -2, vp_frame_h); PART ( -8, -2, vp_window); PART ( -8, -1, vp_frame_h); PART ( -8, -1, vp_window); PART ( -8, 0, vp_door); PART ( -8, 1, vp_frame_h); PART ( -8, 1, vp_window); PART ( -8, 2, vp_frame_h); PART ( -8, 2, vp_window); if (vtypes.size() != num_vehicles) debugmsg("%d vehicles, %d types", vtypes.size(), num_vehicles); }
static int sd2gen(Chan* c, int i, Dir* dp) { Qid q; uvlong l; SDfile *e; SDpart *pp; SDperm *perm; SDunit *unit; SDev *sdev; int rv, t; sdev = sdgetdev(DEV(c->qid)); assert(sdev); unit = sdev->unit[UNIT(c->qid)]; rv = -1; switch(i){ case Qctl: mkqid(&q, QID(DEV(c->qid), UNIT(c->qid), PART(c->qid), Qctl), unit->vers, QTFILE); perm = &unit->ctlperm; if(emptystr(perm->user)){ kstrdup(&perm->user, eve); perm->perm = 0640; } devdir(c, q, "ctl", 0, perm->user, perm->perm, dp); rv = 1; break; case Qraw: mkqid(&q, QID(DEV(c->qid), UNIT(c->qid), PART(c->qid), Qraw), unit->vers, QTFILE); perm = &unit->rawperm; if(emptystr(perm->user)){ kstrdup(&perm->user, eve); perm->perm = DMEXCL|0600; } devdir(c, q, "raw", 0, perm->user, perm->perm, dp); rv = 1; break; case Qpart: pp = &unit->part[PART(c->qid)]; l = (pp->end - pp->start) * unit->secsize; mkqid(&q, QID(DEV(c->qid), UNIT(c->qid), PART(c->qid), Qpart), unit->vers+pp->vers, QTFILE); if(emptystr(pp->user)) kstrdup(&pp->user, eve); devdir(c, q, pp->name, l, pp->user, pp->perm, dp); rv = 1; break; case Qextra: t = PART(c->qid); if(t >= unit->nefile) break; mkqid(&q, QID(DEV(c->qid), UNIT(c->qid), PART(c->qid), Qextra), unit->vers, QTFILE); e = unit->efile + t; if(emptystr(e->user)) kstrdup(&e->user, eve); devdir(c, q, e->name, 0, e->user, e->perm, dp); rv = 1; break; } decref(&sdev->r); return rv; }
int main(int argc, char *argv[]) { struct disklabel *dp; int spc, def, part, layout, j, ch; uint32_t curcyl; int threshhold, numcyls[NPARTITIONS], startcyl[NPARTITIONS]; off_t totsize = 0; const char *tyname; char *lp; while ((ch = getopt(argc, argv, "pds:")) != -1) { switch (ch) { case 'd': dflag++; break; case 'p': pflag++; break; case 's': totsize = strtoul(optarg, &lp, 10); if (*lp != '\0') usage(); break; case '?': default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc != 1) { usage(); /* NOTREACHED */ } dp = getdiskbyname(*argv); if (dp == NULL) { if (isatty(0)) dp = promptfordisk(*argv); if (dp == NULL) { fprintf(stderr, "%s: unknown disk type\n", *argv); exit(1); } } if (dp->d_flags & D_REMOVABLE) tyname = "removable"; else if (dp->d_flags & D_RAMDISK) tyname = "simulated"; else tyname = "winchester"; spc = dp->d_secpercyl; /* * Bad sector table contains one track for the replicated * copies of the table and enough full tracks preceding * the last track to hold the pool of free blocks to which * bad sectors are mapped. * If disk size was specified explicitly, use specified size. */ if (dp->d_type == DKTYPE_SMD && dp->d_flags & D_BADSECT && totsize == 0) { badsecttable = dp->d_nsectors + roundup(badsecttable, dp->d_nsectors); threshhold = howmany(spc, badsecttable); } else { badsecttable = 0; threshhold = 0; } /* * If disk size was specified, recompute number of cylinders * that may be used, and set badsecttable to any remaining * fraction of the last cylinder. */ if (totsize != 0) { dp->d_ncylinders = howmany(totsize, spc); badsecttable = spc * dp->d_ncylinders - totsize; } /* * Figure out if disk is large enough for * expanded swap area and 'd', 'e', and 'f' * partitions. Otherwise, use smaller defaults * based on RK07. */ for (def = 0; def < NDEFAULTS; def++) { curcyl = 0; for (part = PART('a'); part < NPARTITIONS; part++) curcyl += howmany(defpart[def][part], spc); if (curcyl < dp->d_ncylinders - threshhold) break; } if (def >= NDEFAULTS) { fprintf(stderr, "%s: disk too small, calculate by hand\n", *argv); exit(1); } /* * Calculate number of cylinders allocated to each disk * partition. We may waste a bit of space here, but it's * in the interest of (very backward) compatibility * (for mixed disk systems). */ for (curcyl = 0, part = PART('a'); part < NPARTITIONS; part++) { numcyls[part] = 0; if (defpart[def][part] != 0) { numcyls[part] = howmany(defpart[def][part], spc); curcyl += numcyls[part]; } } numcyls[PART('f')] = dp->d_ncylinders - curcyl; numcyls[PART('g')] = numcyls[PART('d')] + numcyls[PART('e')] + numcyls[PART('f')]; numcyls[PART('c')] = dp->d_ncylinders; defpart[def][PART('f')] = numcyls[PART('f')] * spc - badsecttable; defpart[def][PART('g')] = numcyls[PART('g')] * spc - badsecttable; defpart[def][PART('c')] = numcyls[PART('c')] * spc; #ifndef for_now if (totsize || !pflag) #else if (totsize) #endif defpart[def][PART('c')] -= badsecttable; /* * Calculate starting cylinder number for each partition. * Note the 'h' partition is physically located before the * 'g' or 'd' partition. This is reflected in the layout * arrays defined above. */ for (layout = 0; layout < NLAYOUTS; layout++) { curcyl = 0; for (lp = layouts[layout]; *lp != 0; lp++) { startcyl[PART(*lp)] = curcyl; curcyl += numcyls[PART(*lp)]; } } if (pflag) { printf("}, %s_sizes[%d] = {\n", dp->d_typename, NPARTITIONS); for (part = PART('a'); part < NPARTITIONS; part++) { if (numcyls[part] == 0) { printf("\t0,\t0,\n"); continue; } if (dp->d_type != DKTYPE_MSCP) { printf("\t%d,\t%d,\t\t/* %c=cyl %d thru %d */\n", defpart[def][part], startcyl[part], 'A' + part, startcyl[part], startcyl[part] + numcyls[part] - 1); continue; } printf("\t%d,\t%d,\t\t/* %c=sectors %d thru %d */\n", defpart[def][part], spc * startcyl[part], 'A' + part, spc * startcyl[part], spc * startcyl[part] + defpart[def][part] - 1); } exit(0); } if (dflag) { int nparts; /* * In case the disk is in the ``in-between'' range * where the 'g' partition is smaller than the 'h' * partition, reverse the frag sizes so the /usr partition * is always set up with a frag size larger than the * user's partition. */ if (defpart[def][PART('g')] < defpart[def][PART('h')]) { int temp; temp = defparam[PART('h')].p_fsize; defparam[PART('h')].p_fsize = defparam[PART('g')].p_fsize; defparam[PART('g')].p_fsize = temp; } printf("%s:\\\n", dp->d_typename); printf("\t:ty=%s:ns#%d:nt#%d:nc#%d:", tyname, dp->d_nsectors, dp->d_ntracks, dp->d_ncylinders); if (dp->d_secpercyl != dp->d_nsectors * dp->d_ntracks) printf("sc#%d:", dp->d_secpercyl); if (dp->d_type == DKTYPE_SMD && dp->d_flags & D_BADSECT) printf("sf:"); printf("\\\n\t:dt=%s:", dktypenames[dp->d_type]); for (part = NDDATA - 1; part >= 0; part--) if (dp->d_drivedata[part]) break; for (j = 0; j <= part; j++) printf("d%d#%d:", j, dp->d_drivedata[j]); printf("\\\n"); for (nparts = 0, part = PART('a'); part < NPARTITIONS; part++) if (defpart[def][part] != 0) nparts++; for (part = PART('a'); part < NPARTITIONS; part++) { if (defpart[def][part] == 0) continue; printf("\t:p%c#%d:", 'a' + part, defpart[def][part]); printf("o%c#%d:b%c#%d:f%c#%d:", 'a' + part, spc * startcyl[part], 'a' + part, defparam[part].p_frag * defparam[part].p_fsize, 'a' + part, defparam[part].p_fsize); if (defparam[part].p_fstype == FS_SWAP) printf("t%c=swap:", 'a' + part); nparts--; printf("%s\n", nparts > 0 ? "\\" : ""); } #ifdef for_now defpart[def][PART('c')] -= badsecttable; part = PART('c'); printf("#\t:p%c#%d:", 'a' + part, defpart[def][part]); printf("o%c#%d:b%c#%d:f%c#%d:\n", 'a' + part, spc * startcyl[part], 'a' + part, defparam[part].p_frag * defparam[part].p_fsize, 'a' + part, defparam[part].p_fsize); #endif exit(0); } printf("%s: #sectors/track=%d, #tracks/cylinder=%d #cylinders=%d\n", dp->d_typename, dp->d_nsectors, dp->d_ntracks, dp->d_ncylinders); printf("\n Partition\t Size\t Offset\t Range\n"); for (part = PART('a'); part < NPARTITIONS; part++) { printf("\t%c\t", 'a' + part); if (numcyls[part] == 0) { printf(" unused\n"); continue; } printf("%7d\t%7d\t%4d - %d%s\n", defpart[def][part], startcyl[part] * spc, startcyl[part], startcyl[part] + numcyls[part] - 1, defpart[def][part] % spc ? "*" : ""); } exit(0); }
static gboolean part_has_properties (ItemData *item) { Part *part = PART (item); return part->priv->properties != NULL; }
/* * check_if_part_used_once -- (internal) check if the part is used only once in * the rest of the poolset */ static int check_if_part_used_once(struct pool_set *set, unsigned repn, unsigned partn) { LOG(3, "set %p, repn %u, partn %u", set, repn, partn); struct pool_replica *rep = REP(set, repn); char *path = util_part_realpath(PART(rep, partn)->path); if (path == NULL) { LOG(1, "cannot get absolute path for %s, replica %u, part %u", PART(rep, partn)->path, repn, partn); errno = 0; path = strdup(PART(rep, partn)->path); if (path == NULL) { ERR("!strdup"); return -1; } } int ret = 0; for (unsigned r = repn; r < set->nreplicas; ++r) { struct pool_replica *repr = set->replica[r]; /* skip remote replicas */ if (repr->remote != NULL) continue; /* avoid superfluous comparisons */ unsigned i = (r == repn) ? partn + 1 : 0; for (unsigned p = i; p < repr->nparts; ++p) { char *pathp = util_part_realpath(PART(repr, p)->path); if (pathp == NULL) { if (errno != ENOENT) { ERR("realpath failed for %s, errno %d", PART(repr, p)->path, errno); ret = -1; goto out; } LOG(1, "cannot get absolute path for %s," " replica %u, part %u", PART(rep, partn)->path, repn, partn); pathp = strdup(PART(repr, p)->path); errno = 0; } int result = util_compare_file_inodes(path, pathp); if (result == 0) { /* same file used multiple times */ ERR("some part file's path is" " used multiple times"); ret = -1; errno = EINVAL; free(pathp); goto out; } else if (result < 0) { ERR("comparing file inodes failed for %s and" " %s", path, pathp); ret = -1; free(pathp); goto out; } free(pathp); } } out: free(path); return ret; }
/** * \brief rotate an item by an @angle increment (may be negative) * * @angle the increment the item will be rotated (usually 90° steps) * @center_pos if rotated as part of a group, this is the center to rotate *around */ static void part_rotate (ItemData *data, int angle, Coords *center_pos) { g_return_if_fail (data); g_return_if_fail (IS_PART (data)); cairo_matrix_t morph, morph_rot, local_rot; Part *part; PartPriv *priv; gboolean handler_connected; // Coords b1, b2; part = PART (data); priv = part->priv; // FIXME store vanilla coords, apply the morph // FIXME to these and store the result in the // FIXME instance then everything will be fine // XXX also prevents rounding yiggle up downs angle /= 90; angle *= 90; cairo_matrix_init_rotate (&local_rot, (double)angle * M_PI / 180.); cairo_matrix_multiply (item_data_get_rotate (data), item_data_get_rotate (data), &local_rot); morph_rot = *(item_data_get_rotate (data)); cairo_matrix_multiply (&morph, &morph_rot, item_data_get_translate (data)); Coords delta_to_center, delta_to_center_transformed; Coords delta_to_apply, delta_bbox; Coords bbox_center, bbox_center_transformed; Coords item_pos; // get bbox #if 0 // this causes #115 to reappear item_data_get_relative_bbox (ITEM_DATA (part), &b1, &b2); bbox_center = coords_average (&b1, &b2); #endif item_data_get_pos (ITEM_DATA (part), &item_pos); Coords rotation_center; if (center_pos == NULL) { rotation_center = coords_sum (&bbox_center, &item_pos); } else { rotation_center = *center_pos; } delta_to_center_transformed = delta_to_center = coords_sub (&rotation_center, &item_pos); cairo_matrix_transform_point (&local_rot, &(delta_to_center_transformed.x), &(delta_to_center_transformed.y)); delta_to_apply = coords_sub (&delta_to_center, &delta_to_center_transformed); #define DEBUG_THIS 0 // use the cairo matrix funcs to transform the pin // positions relative to the item center // this is only indirectly related to displayin // HINT: we need to modify the actual pins to make the // pin tests work being used to detect connections gint i; gdouble x, y; // Rotate the pins. for (i = 0; i < priv->num_pins; i++) { x = priv->pins_orig[i].offset.x; y = priv->pins_orig[i].offset.y; cairo_matrix_transform_point (&morph_rot, &x, &y); if (fabs (x) < 1e-2) x = 0.0; if (fabs (y) < 1e-2) y = 0.0; priv->pins[i].offset.x = x; priv->pins[i].offset.y = y; } item_data_move (data, &delta_to_apply); handler_connected = g_signal_handler_is_connected (G_OBJECT (data), data->changed_handler_id); if (handler_connected) { g_signal_emit_by_name (G_OBJECT (data), "changed"); } else { NG_DEBUG ("handler not yet registerd."); } NG_DEBUG ("\n\n"); }
static PedPartition* amiga_partition_new (const PedDisk* disk, PedPartitionType part_type, const PedFileSystemType* fs_type, PedSector start, PedSector end) { PedPartition *part; PedDevice *dev; PedSector cyl; struct PartitionBlock *partition; struct RigidDiskBlock *rdb; PED_ASSERT(disk != NULL); PED_ASSERT(disk->dev != NULL); PED_ASSERT(disk->disk_specific != NULL); dev = disk->dev; cyl = (PedSector) (dev->hw_geom.sectors * dev->hw_geom.heads); rdb = RDSK(disk->disk_specific); if (!(part = _ped_partition_alloc (disk, part_type, fs_type, start, end))) return NULL; if (ped_partition_is_active (part)) { if (!(part->disk_specific = ped_malloc (disk->dev->sector_size))) { free (part); return NULL; } partition = PART(part->disk_specific); memset(partition, 0, sizeof(struct PartitionBlock)); partition->pb_ID = PED_CPU_TO_BE32(IDNAME_PARTITION); partition->pb_SummedLongs = PED_CPU_TO_BE32(64); partition->pb_HostID = rdb->rdb_HostID; partition->pb_Flags = PED_CPU_TO_BE32(0); /* TODO : use a scheme including the device name and the * partition number, if it is possible */ _amiga_set_bstr("dhx", partition->pb_DriveName, 32); partition->de_TableSize = PED_CPU_TO_BE32(19); partition->de_SizeBlock = PED_CPU_TO_BE32(128); partition->de_SecOrg = PED_CPU_TO_BE32(0); partition->de_Surfaces = PED_CPU_TO_BE32(dev->hw_geom.heads); partition->de_SectorPerBlock = PED_CPU_TO_BE32(1); partition->de_BlocksPerTrack = PED_CPU_TO_BE32(dev->hw_geom.sectors); partition->de_Reserved = PED_CPU_TO_BE32(2); partition->de_PreAlloc = PED_CPU_TO_BE32(0); partition->de_Interleave = PED_CPU_TO_BE32(0); partition->de_LowCyl = PED_CPU_TO_BE32(start/cyl); partition->de_HighCyl = PED_CPU_TO_BE32((end+1)/cyl-1); partition->de_NumBuffers = PED_CPU_TO_BE32(30); partition->de_BufMemType = PED_CPU_TO_BE32(0); partition->de_MaxTransfer = PED_CPU_TO_BE32(0x7fffffff); partition->de_Mask = PED_CPU_TO_BE32(0xffffffff); partition->de_BootPri = PED_CPU_TO_BE32(0); partition->de_DosType = PED_CPU_TO_BE32(0x4c4e5800); partition->de_Baud = PED_CPU_TO_BE32(0); partition->de_Control = PED_CPU_TO_BE32(0); partition->de_BootBlocks = PED_CPU_TO_BE32(0); } else { part->disk_specific = NULL; } return part; }
/** * flip a part in a given direction * @direction gives the direction the item will be flipped, end users pov! * @center the center to flip over - currently ignored FIXME */ static void part_flip (ItemData *data, IDFlip direction, Coords *center) { #if 0 Part *part; PartPriv *priv; int i; cairo_matrix_t affine; double x, y; double scale_v, scale_h; gboolean handler_connected; Coords delta; Coords pos, trans; Coords b1, b2; Coords pos_new, pos_old; //FIXME properly recenter after flipping //Coords part_center_before, part_center_after, delta; g_return_if_fail (data); g_return_if_fail (IS_PART (data)); part = PART (data); priv = part->priv; item_data_get_pos (data, &trans); // mask, just for the sake of cleanness direction &= ID_FLIP_MASK; // TODO evaluate if we really want to be able to do double flips (180* rots via flipping) g_assert (direction != ID_FLIP_MASK); // create a transformation _relativ_ to the current _state_ // reverse axis and fix the created offset by adding 2*pos.x or .y // convert the flip direction to binary, used in the matrix setup // keep in mind that we do relativ manipulations within the model // which in turn makes this valid for all rotations! scale_h = ((direction & ID_FLIP_HORIZ) != 0) ? -1. : 1.; scale_v = ((direction & ID_FLIP_VERT) != 0) ? -1. : 1.; // magic, if we are in either 270 or 90 state, we need to rotate the flip state by 90° to draw it properly // TODO maybe better put this into the rotation function if ((priv->rotation / 90) % 2 == 1) { priv->flip ^= ID_FLIP_MASK; } // toggle the direction priv->flip ^= direction; if ((priv->flip & ID_FLIP_MASK)== ID_FLIP_MASK) { priv->flip = ID_FLIP_NONE; priv->rotation += 180; priv->rotation %= 360; } cairo_matrix_init_scale (&affine, scale_h, scale_v); item_data_get_pos (data, &pos_old); pos_new = pos_old; cairo_matrix_transform_point (&affine, &pos_new.x, &pos_new.y); g_printf ("\ncenter %p [old] x=%lf,y=%lf -->", data, pos_old.x, pos_old.y); g_printf (" x=%lf, y=%lf\n", pos_new.x, pos_new.y); delta.x = - pos_new.x + pos_old.x; delta.y = - pos_new.y + pos_old.y; // flip the pins for (i = 0; i < priv->num_pins; i++) { x = priv->pins[i].offset.x; y = priv->pins[i].offset.y; cairo_matrix_transform_point (&affine, &x, &y); if (fabs (x) < 1e-2) x = 0.0; if (fabs (y) < 1e-2) y = 0.0; priv->pins[i].offset.x = x; priv->pins[i].offset.y = y; } item_data_snap (data); // tell the view handler_connected = g_signal_handler_is_connected (G_OBJECT (part), ITEM_DATA(part)->flipped_handler_id); if (handler_connected) { g_signal_emit_by_name (G_OBJECT (part), "flipped", priv->flip); // TODO - proper boundingbox center calculation item_data_get_relative_bbox (ITEM_DATA (part), &b1, &b2); // flip the bounding box. cairo_matrix_transform_point (&affine, &b1.x, &b1.y); cairo_matrix_transform_point (&affine, &b2.x, &b2.y); item_data_set_relative_bbox (ITEM_DATA (part), &b1, &b2); item_data_set_pos (ITEM_DATA (part), &pos); // FIXME - proper recenter to boundingbox center } if (g_signal_handler_is_connected (G_OBJECT (part), ITEM_DATA (part)->changed_handler_id)) { g_signal_emit_by_name (G_OBJECT (part), "changed"); } #endif }
static int part_suspend(struct mtd_info *mtd) { struct mtd_part *part = PART(mtd); return part->master->suspend(part->master); }
/** * print the part onto a physical sheet of paper or pdf, which is represented by * @cr */ static void part_print (ItemData *data, cairo_t *cr, SchematicPrintContext *ctx) { GSList *objects, *labels; SymbolObject *object; LibrarySymbol *symbol; double x0, y0; int i, rotation; Part *part; PartPriv *priv; Coords pos; IDFlip flip; GooCanvasPoints *line; g_return_if_fail (data != NULL); g_return_if_fail (IS_PART (data)); part = PART (data); priv = part->priv; symbol = library_get_symbol (priv->symbol_name); if (symbol == NULL) { return; } item_data_get_pos (ITEM_DATA (part), &pos); x0 = pos.x; y0 = pos.y; cairo_save (cr); gdk_cairo_set_source_rgba (cr, &ctx->colors.components); rotation = part_get_rotation (part); flip = part_get_flip (part); if ((flip & ID_FLIP_HORIZ) && (flip & ID_FLIP_VERT)) rotation += 180; else if (flip == ID_FLIP_HORIZ) cairo_scale (cr, -1, 1); else if (flip == ID_FLIP_VERT) cairo_scale (cr, 1, -1); if (rotation %= 360) cairo_rotate (cr, rotation * M_PI / 180); for (objects = symbol->symbol_objects; objects; objects = objects->next) { object = (SymbolObject *)(objects->data); switch (object->type) { case SYMBOL_OBJECT_LINE: line = object->u.uline.line; for (i = 0; i < line->num_points; i++) { double x, y; x = line->coords[i * 2]; y = line->coords[i * 2 + 1]; if (i == 0) cairo_move_to (cr, x0 + x, y0 + y); else cairo_line_to (cr, x0 + x, y0 + y); } break; case SYMBOL_OBJECT_ARC: { gdouble x1 = object->u.arc.x1; gdouble y1 = object->u.arc.y1; gdouble x2 = object->u.arc.x2; gdouble y2 = object->u.arc.y2; gdouble width, height, x, y; x = (x2 + x1) / 2; y = (y2 + y1) / 2; width = x2 - x1; height = y2 - y1; cairo_save (cr); cairo_translate (cr, x0 + x, y0 + y); cairo_scale (cr, width / 2.0, height / 2.0); cairo_arc (cr, 0.0, 0.0, 1.0, 0.0, 2 * M_PI); cairo_restore (cr); } break; default: g_warning ("Print part: Part %s contains unknown object.", priv->name); continue; } cairo_stroke (cr); } // We don't want to rotate labels text, only the (x,y) coordinate gdk_cairo_set_source_rgba (cr, &ctx->colors.labels); for (labels = part_get_labels (part); labels; labels = labels->next) { gdouble x, y; PartLabel *label = (PartLabel *)labels->data; gchar *text; /* gint text_width, text_height; */ x = label->pos.x + x0; y = label->pos.y + y0; text = part_property_expand_macros (part, label->text); /* Align the label. switch (rotation) { case 90: y += text_height*opc->scale; break; case 180: break; case 270: x -= text_width*opc->scale; break; case 0: default: break; } */ cairo_save (cr); cairo_move_to (cr, x, y); cairo_show_text (cr, text); cairo_restore (cr); g_free (text); } cairo_restore (cr); }
static int part_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf, size_t len) { struct mtd_part *part = PART(mtd); return mtd_get_fact_prot_info(part->master, buf, len); }
static long flashread(Chan *c, void *buf, long n, vlong offset) { Flash *f; Flashpart *fp; Flashregion *r; int i; ulong start, end; char *s, *o; if(c->qid.type & QTDIR) return devdirread(c, buf, n, nil, 0, flashgen); f = flash.card[c->dev]; fp = &f->part[PART(c->qid.path)]; if(fp->name == nil) error(Egreg); switch(TYPE(c->qid.path)){ case Qdata: offset += fp->start; if(offset >= fp->end) return 0; if(offset+n > fp->end) n = fp->end - offset; n = readflash(f, buf, offset, n); if(n < 0) error(Eio); return n; case Qctl: s = malloc(READSTR); if(s == nil) error(Enomem); if(waserror()){ free(s); nexterror(); } o = seprint(s, s+READSTR, "%#2.2ux %#4.4ux %d %q\n", f->id, f->devid, f->width, f->sort!=nil? f->sort: "nor"); for(i=0; i<f->nr; i++){ r = &f->regions[i]; if(r->start < fp->end && fp->start < r->end){ start = r->start; if(fp->start > start) start = fp->start; end = r->end; if(fp->end < end) end = fp->end; o = seprint(o, s+READSTR, "%#8.8lux %#8.8lux %#8.8lux", start, end, r->erasesize); if(r->pagesize) o = seprint(o, s+READSTR, " %#8.8lux", r->pagesize); o = seprint(o, s+READSTR, "\n"); } } n = readstr(offset, buf, n, s); poperror(); free(s); return n; } error(Egreg); return 0; /* not reached */ }
static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { struct mtd_part *part = PART(mtd); return mtd_write_user_prot_reg(part->master, from, len, retlen, buf); }
static long flashwrite(Chan *c, void *buf, long n, vlong offset) { Cmdbuf *cb; Cmdtab *ct; ulong addr, start, end; char *e; Flashpart *fp; Flashregion *r; Flash *f; f = flash.card[c->dev]; fp = &f->part[PART(c->qid.path)]; if(fp->name == nil) error(Egreg); switch(TYPE(c->qid.path)){ case Qdata: if(f->write == nil) error(Eperm); offset += fp->start; if(offset >= fp->end) return 0; if(offset+n > fp->end) n = fp->end - offset; n = writeflash(f, offset, buf, n); if(n < 0) error(Eio); return n; case Qctl: cb = parsecmd(buf, n); if(waserror()){ free(cb); nexterror(); } ct = lookupcmd(cb, flashcmds, nelem(flashcmds)); switch(ct->index){ case CMerase: if(strcmp(cb->f[1], "all") != 0){ addr = flashaddr(f, fp, cb->f[1]); r = flashregion(f, addr); if(r == nil) error("nonexistent flash region"); if(addr%r->erasesize != 0) error("invalid erase block address"); eraseflash(f, r, addr); }else if(fp->start == 0 && fp->end == f->size && f->eraseall != nil){ eraseflash(f, nil, 0); }else{ for(addr = fp->start; addr < fp->end; addr += r->erasesize){ r = flashregion(f, addr); if(r == nil) error("nonexistent flash region"); if(addr%r->erasesize != 0) error("invalid erase block address"); eraseflash(f, r, addr); } } break; case CMadd: if(cb->nf < 3) error(Ebadarg); start = flashaddr(f, fp, cb->f[2]); if(cb->nf > 3 && strcmp(cb->f[3], "end") != 0) end = flashaddr(f, fp, cb->f[3]); else end = fp->end; if(start > end || start >= fp->end || end > fp->end) error(Ebadarg); e = flashnewpart(f, cb->f[1], start, end); if(e != nil) error(e); break; case CMremove: /* TO DO */ break; case CMprotectboot: if(cb->nf > 1 && strcmp(cb->f[1], "off") == 0) f->protect = 0; else f->protect = 1; break; case CMsync: /* TO DO? */ break; default: error(Ebadarg); } poperror(); free(cb); return n; } error(Egreg); return 0; /* not reached */ }
static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { struct mtd_part *part = PART(mtd); return mtd_unlock(part->master, ofs + part->offset, len); }
/* * util_header_create -- (internal) create header of a single pool set file */ static int util_header_create(struct pool_set *set, unsigned repidx, unsigned partidx, size_t hdrsize, const char *sig, uint32_t major, uint32_t compat, uint32_t incompat, uint32_t ro_compat) { LOG(3, "set %p repidx %u partidx %u hdrsize %zu sig %.8s major %u " "compat %#x incompat %#x ro_comapt %#x", set, repidx, partidx, hdrsize, sig, major, compat, incompat, ro_compat); struct pool_replica *rep = set->replica[repidx]; /* opaque info lives at the beginning of mapped memory pool */ struct pool_hdr *hdrp = rep->part[partidx].hdr; /* check if the pool header is all zeros */ if (!util_is_zeroed(hdrp, sizeof (*hdrp))) { ERR("Non-empty file detected"); errno = EINVAL; return -1; } /* * Zero out the pool descriptor - just in case we fail right after * header checksum is stored. */ void *descp = (void *)((uintptr_t)hdrp + sizeof (*hdrp)); memset(descp, 0, hdrsize - sizeof (*hdrp)); pmem_msync(descp, hdrsize - sizeof (*hdrp)); /* create pool's header */ memcpy(hdrp->signature, sig, POOL_HDR_SIG_LEN); hdrp->major = htole32(major); hdrp->compat_features = htole32(compat); hdrp->incompat_features = htole32(incompat); hdrp->ro_compat_features = htole32(ro_compat); memcpy(hdrp->poolset_uuid, set->uuid, POOL_HDR_UUID_LEN); memcpy(hdrp->uuid, PART(rep, partidx).uuid, POOL_HDR_UUID_LEN); /* link parts */ memcpy(hdrp->prev_part_uuid, PART(rep, partidx - 1).uuid, POOL_HDR_UUID_LEN); memcpy(hdrp->next_part_uuid, PART(rep, partidx + 1).uuid, POOL_HDR_UUID_LEN); /* link replicas */ memcpy(hdrp->prev_repl_uuid, PART(REP(set, repidx - 1), 0).uuid, POOL_HDR_UUID_LEN); memcpy(hdrp->next_repl_uuid, PART(REP(set, repidx + 1), 0).uuid, POOL_HDR_UUID_LEN); hdrp->crtime = htole64((uint64_t)time(NULL)); if (util_get_arch_flags(&hdrp->arch_flags)) { ERR("Reading architecture flags failed\n"); errno = EINVAL; return -1; } hdrp->arch_flags.alignment_desc = htole64(hdrp->arch_flags.alignment_desc); hdrp->arch_flags.e_machine = htole16(hdrp->arch_flags.e_machine); util_checksum(hdrp, sizeof (*hdrp), &hdrp->checksum, 1); /* store pool's header */ pmem_msync(hdrp, sizeof (*hdrp)); return 0; }