int osd_create_directory(int pathtype, int pathindex, const char *dirname) { char fullpath[1024]; /* compose the full path */ compose_path(fullpath, sizeof(fullpath), pathtype, pathindex, dirname); return create_path(fullpath, FALSE); }
static int handle_RRQ(ctrl_t *ctrl) { char *path = compose_path(ctrl, ctrl->file); ctrl->fp = fopen(path, "r"); if (!ctrl->fp) { ERR(errno, "Failed opening %s", path); return send_ERROR(ctrl, ENOTFOUND); } return !send_DATA(ctrl, 0); }
osd_file *osd_fopen(int pathtype, int pathindex, const char *filename, const char *mode, osd_file_error *error) { char fullpath[1024]; osd_file *file; int i; /* find an empty file pointer */ for (i = 0; i < MAX_OPEN_FILES; i++) if (openfile[i].fileptr == NULL) break; if (i == MAX_OPEN_FILES) goto error; /* zap the file record */ file = &openfile[i]; memset(file, 0, sizeof(*file)); /* compose the full path */ compose_path(fullpath, sizeof(fullpath), pathtype, pathindex, filename); /* attempt to open the file */ file->fileptr = fopen(fullpath, mode); if (file->fileptr == NULL) { /* if it's read-only, or if the path exists, then that's final */ if (!(strchr(mode, 'w')) || errno != EACCES) goto error; /* create the path and try again */ create_path(fullpath, TRUE); file->fileptr = fopen(fullpath, mode); /* if that doesn't work, we give up */ if (file->fileptr == NULL) goto error; } /* get the file size */ FSEEK(file->fileptr, 0, SEEK_END); file->end = FTELL(file->fileptr); rewind(file->fileptr); *error = FILEERR_SUCCESS; return file; error: *error = get_last_fileerror(); return NULL; }
int osd_get_path_info(int pathtype, int pathindex, const char *filename) { struct stat buf; char fullpath[1024]; /* compose the full path */ compose_path(fullpath, sizeof(fullpath), pathtype, pathindex, filename); /* get the file attributes */ if (stat(fullpath, &buf)) return PATH_NOT_FOUND; #ifdef BSD43 else if (S_IFDIR & buf.st_mode) #else else if (S_ISDIR(buf.st_mode)) #endif return PATH_IS_DIRECTORY; else return PATH_IS_FILE; }
virtual void on_draw() { typedef agg::renderer_base<agg::pixfmt_bgr24> ren_base; agg::pixfmt_bgr24 pixf(rbuf_window()); ren_base renb(pixf); renb.clear(agg::rgba(1, 1, 1)); agg::rasterizer_scanline_aa<> ras; agg::scanline_p8 sl; agg::trans_affine mtx; mtx *= agg::trans_affine_scaling(4.0); mtx *= agg::trans_affine_translation(150, 100); agg::conv_transform<agg::path_storage> trans(m_path, mtx); agg::conv_curve<agg::conv_transform<agg::path_storage> > curve(trans); agg::conv_contour <agg::conv_curve <agg::conv_transform <agg::path_storage> > > contour(curve); contour.width(m_width.value()); //contour.inner_join(agg::inner_bevel); //contour.line_join(agg::miter_join); //contour.inner_line_join(agg::miter_join); //contour.inner_miter_limit(4.0); contour.auto_detect_orientation(m_auto_detect.status()); compose_path(); ras.add_path(contour); agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba(0,0,0)); agg::render_ctrl(ras, sl, renb, m_close); agg::render_ctrl(ras, sl, renb, m_width); agg::render_ctrl(ras, sl, renb, m_auto_detect); }
int plxr_render_dir_html(char *dest, size_t size, char *path, DIR *dir, char *host) { const char *page_template = "<!doctype html>" "<html><head></head>" "<body><ul>%s</ul></body></html>" ; const char *li_template = "<li><a href=\"http://%s/%s\">%s</a></li>" ; struct dirent *ent; char li_buffer[4096] = {0}; size_t count = 0; while (( ent = readdir(dir) )) { count += snprintf( &li_buffer[count], sizeof(li_buffer) - count, li_template, host, compose_path(path, ent->d_name), ent->d_name); if (count > sizeof(li_buffer)) { WARN("out of memory"); return -1; } } return snprintf(dest, size, page_template, li_buffer); }
virtual void on_draw() { typedef agg::renderer_base<agg::pixfmt_bgra32> ren_base; typedef agg::renderer_base<agg::pixfmt_bgra32_pre> ren_base_pre; agg::gamma_lut<agg::int8u, agg::int8u> lut(2.0); agg::pixfmt_bgra32 pixf(rbuf_window()); ren_base renb(pixf); agg::pixfmt_bgra32_pre pixf_pre(rbuf_window()); ren_base_pre renb_pre(pixf_pre); // Clear the window with a gradient agg::pod_vector<agg::rgba8> gr(pixf_pre.width()); unsigned i; for(i = 0; i < pixf.width(); i++) { gr.add(agg::rgba8(255, 255, 0).gradient(agg::rgba8(0, 255, 255), double(i) / pixf.width())); } for(i = 0; i < pixf.height(); i++) { renb.copy_color_hspan(0, i, pixf.width(), &gr[0]); } pixf.apply_gamma_dir(lut); agg::rasterizer_scanline_aa<> ras; agg::rasterizer_compound_aa<agg::rasterizer_sl_clip_dbl> rasc; agg::scanline_u8 sl; agg::span_allocator<agg::rgba8> alloc; // Draw two triangles ras.move_to_d(0, 0); ras.line_to_d(width(), 0); ras.line_to_d(width(), height()); agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba8(lut.dir(0), lut.dir(100), lut.dir(0))); ras.move_to_d(0, 0); ras.line_to_d(0, height()); ras.line_to_d(width(), 0); agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba8(lut.dir(0), lut.dir(100), lut.dir(100))); agg::trans_affine mtx; mtx *= agg::trans_affine_scaling(4.0); mtx *= agg::trans_affine_translation(150, 100); agg::conv_transform<agg::path_storage> trans(m_path, mtx); agg::conv_curve<agg::conv_transform<agg::path_storage> > curve(trans); agg::conv_stroke <agg::conv_curve <agg::conv_transform <agg::path_storage> > > stroke(curve); compose_path(); agg::rgba8 styles[4]; if(m_invert_order.status()) { rasc.layer_order(agg::layer_inverse); } else { rasc.layer_order(agg::layer_direct); } styles[3] = agg::rgba8(lut.dir(255), lut.dir(0), lut.dir(108), 200).premultiply(); styles[2] = agg::rgba8(lut.dir(51), lut.dir(0), lut.dir(151), 180).premultiply(); styles[1] = agg::rgba8(lut.dir(143), lut.dir(90), lut.dir(6), 200).premultiply(); styles[0] = agg::rgba8(lut.dir(0), lut.dir(0), lut.dir(255), 220).premultiply(); style_handler sh(styles, 4); stroke.width(m_width.value()); rasc.reset(); rasc.master_alpha(3, m_alpha1.value()); rasc.master_alpha(2, m_alpha2.value()); rasc.master_alpha(1, m_alpha3.value()); rasc.master_alpha(0, m_alpha4.value()); agg::ellipse ell(220.0, 180.0, 120.0, 10.0, 128, false); agg::conv_stroke<agg::ellipse> str_ell(ell); str_ell.width(m_width.value() / 2); rasc.styles(3, -1); rasc.add_path(str_ell); rasc.styles(2, -1); rasc.add_path(ell); rasc.styles(1, -1); rasc.add_path(stroke); rasc.styles(0, -1); rasc.add_path(curve); agg::render_scanlines_compound_layered(rasc, sl, renb_pre, alloc, sh); agg::render_ctrl(ras, sl, renb, m_width); agg::render_ctrl(ras, sl, renb, m_alpha1); agg::render_ctrl(ras, sl, renb, m_alpha2); agg::render_ctrl(ras, sl, renb, m_alpha3); agg::render_ctrl(ras, sl, renb, m_alpha4); agg::render_ctrl(ras, sl, renb, m_invert_order); pixf.apply_gamma_inv(lut); }
static mame_file *generic_fopen(int pathtype, const char *gamename, const char *filename, const char* hash, UINT32 flags) { static const char *access_modes[] = { "rb", "rb", "wb", "r+b" }; const char *extension = get_extension_for_filetype(pathtype); int pathcount = osd_get_path_count(pathtype); int pathindex, pathstart, pathstop, pathinc; mame_file file, *newfile; char tempname[256]; LOG(("generic_fopen(%d, %s, %s, %s, %X)\n", pathc, gamename, filename, extension, flags)); /* reset the file handle */ memset(&file, 0, sizeof(file)); /* check for incompatible flags */ if ((flags & FILEFLAG_OPENWRITE) && (flags & FILEFLAG_HASH)) fprintf(stderr, "Can't use HASH option with WRITE option in generic_fopen!\n"); /* determine start/stop based on reverse search flag */ if (!(flags & FILEFLAG_REVERSE_SEARCH)) { pathstart = 0; pathstop = pathcount; pathinc = 1; } else { pathstart = pathcount - 1; pathstop = -1; pathinc = -1; } /* loop over paths */ for (pathindex = pathstart; pathindex != pathstop; pathindex += pathinc) { char name[1024]; /* ----------------- STEP 1: OPEN THE FILE RAW -------------------- */ /* first look for path/gamename as a directory */ compose_path(name, gamename, NULL, NULL); LOG(("Trying %s\n", name)); /* if the directory exists, proceed */ if (*name == 0 || osd_get_path_info(pathtype, pathindex, name) == PATH_IS_DIRECTORY) { /* now look for path/gamename/filename.ext */ compose_path(name, gamename, filename, extension); /* if we need checksums, load it into RAM and compute it along the way */ if (flags & FILEFLAG_HASH) { if (checksum_file(pathtype, pathindex, name, &file.data, &file.length, file.hash) == 0) { file.type = RAM_FILE; break; } } /* otherwise, just open it straight */ else { file.type = PLAIN_FILE; file.file = osd_fopen(pathtype, pathindex, name, access_modes[flags & 3]); if (file.file == NULL && (flags & 3) == 3) file.file = osd_fopen(pathtype, pathindex, name, "w+b"); if (file.file != NULL) break; } } /* ----------------- STEP 2: OPEN THE FILE IN A ZIP -------------------- */ /* now look for it within a ZIP file */ if (!(flags & (FILEFLAG_OPENWRITE | FILEFLAG_NOZIP))) { /* first look for path/gamename.zip */ compose_path(name, gamename, NULL, "zip"); LOG(("Trying %s file\n", name)); /* if the ZIP file exists, proceed */ if (osd_get_path_info(pathtype, pathindex, name) == PATH_IS_FILE) { UINT32 ziplength; /* if the file was able to be extracted from the ZIP, continue */ compose_path(tempname, NULL, filename, extension); /* verify-only case */ if (flags & FILEFLAG_VERIFY_ONLY) { UINT8 crcs[4]; UINT32 crc = 0; /* Since this is a .ZIP file, we extract the CRC from the expected hash (if any), so that we can load by CRC if needed. We must check that the hash really contains a CRC, because it could be a NO_DUMP rom for which we do not know the CRC yet. */ if (hash && hash_data_extract_binary_checksum(hash, HASH_CRC, crcs) != 0) { /* Store the CRC in a single DWORD */ crc = ((unsigned long)crcs[0] << 24) | ((unsigned long)crcs[1] << 16) | ((unsigned long)crcs[2] << 8) | ((unsigned long)crcs[3] << 0); } hash_data_clear(file.hash); if (checksum_zipped_file(pathtype, pathindex, name, tempname, &ziplength, &crc) == 0) { file.length = ziplength; file.type = UNLOADED_ZIPPED_FILE; crcs[0] = (UINT8)(crc >> 24); crcs[1] = (UINT8)(crc >> 16); crcs[2] = (UINT8)(crc >> 8); crcs[3] = (UINT8)(crc >> 0); hash_data_insert_binary_checksum(file.hash, HASH_CRC, crcs); break; } }