IAnimation* LoadAnimation(const char* filename, IFileSystem& fs) { if (has_extension(filename, ".mng")) { // MNG CMNGAnimation* animation = new CMNGAnimation; if (!animation->Load(filename, fs)) { delete animation; return NULL; } return animation; } else if ( has_extension(filename, ".flic") || has_extension(filename, ".flc") || has_extension(filename, ".fli") ) { CFLICAnimation* animation = new CFLICAnimation; if (!animation->Load(filename, fs)) { delete animation; return NULL; } return animation; } return NULL; }
static int verify_one_pack(const char *path, unsigned int flags) { char arg[PATH_MAX]; int len; int verbose = flags & VERIFY_PACK_VERBOSE; int stat_only = flags & VERIFY_PACK_STAT_ONLY; struct packed_git *pack; int err; len = strlcpy(arg, path, PATH_MAX); if (len >= PATH_MAX) return error("name too long: %s", path); /* * In addition to "foo.idx" we accept "foo.pack" and "foo"; * normalize these forms to "foo.idx" for add_packed_git(). */ if (has_extension(arg, ".pack")) { strcpy(arg + len - 5, ".idx"); len--; } else if (!has_extension(arg, ".idx")) { if (len + 4 >= PATH_MAX) return error("name too long: %s.idx", arg); strcpy(arg + len, ".idx"); len += 4; } /* * add_packed_git() uses our buffer (containing "foo.idx") to * build the pack filename ("foo.pack"). Make sure it fits. */ if (len + 1 >= PATH_MAX) { arg[len - 4] = '\0'; return error("name too long: %s.pack", arg); } pack = add_packed_git(arg, len, 1); if (!pack) return error("packfile %s not found.", arg); install_packed_git(pack); if (!stat_only) err = verify_pack(pack); else err = open_pack_index(pack); if (verbose || stat_only) { if (err) printf("%s: bad\n", pack->pack_name); else { show_pack_info(pack, flags); if (!stat_only) printf("%s: ok\n", pack->pack_name); } } return err; }
void ImageLoader::load(const std::string& filename) { if (has_extension(filename, ".png")) { load_image(filename, graphics, resources->images); } else if (has_extension(filename, ".ilb")) { BOOST_LOG_TRIVIAL(warning) << "Loading images from: " << filename; load_ilb(filename, graphics, resources->images); } else if (has_extension(filename, ".hss")) { BOOST_LOG_TRIVIAL(warning) << "Loading images from: " << filename; load_hss(filename, graphics, resources->images); } else { BOOST_LOG_TRIVIAL(warning) << "Don't know how to load images from: " << filename; } }
Path FileIO::Path::Extension() const { if ( !has_extension( ) ) return ""; auto pos = _path.find_last_of( '.' ); return _path.substr( pos ); }
std::string search_executable(tstring const& filename, tstring const& path) { const bool filename_has_extension = has_extension(filename); const bool filename_is_absolute_path = is_absolute(filename); const std::vector<std::string> extensions = get_executable_extensions(); if( ! filename_is_absolute_path ) { const std::vector<std::string> dirs = split(path, PATH_SEPARATOR); for(std::vector<std::string>::const_iterator ipath = dirs.begin(); ipath != dirs.end(); ++ipath ) { const std::string path1 = tinfra::path::join(*ipath, filename); if( filename_has_extension ) { if( is_executable(path1 ,extensions) ) return path1; continue; } std::string maybe_with_ext = find_variant(path1, extensions); if( ! maybe_with_ext.empty() ) return maybe_with_ext; } } else if( ! filename_has_extension ) { return find_variant(filename.str(), extensions); } else { if( is_executable(filename, extensions) ) { return filename.str(); } } return ""; }
void ImageLoader::load_libraries(const std::string& filename) { if (has_extension(filename, ".hss")) { BOOST_LOG_TRIVIAL(warning) << "Loading image libraries from: " << filename; ImageMap hss_images; load_hss(filename, graphics, hss_images); std::unordered_map<Atom, std::unique_ptr<ImageLibraryResource> > loaded_libraries; for (auto iter = hss_images.begin(); iter != hss_images.end(); iter++) { std::vector<std::string> parts; boost::split(parts, iter->first, boost::is_any_of("/.")); std::string& name = parts[1]; std::transform(name.begin(), name.end(), name.begin(), ::tolower); if (loaded_libraries.find(name) == loaded_libraries.end()) loaded_libraries[name].reset(new ImageLibraryResource(name)); ImageLibraryResource *lib = loaded_libraries[name].get(); lib->images[lib->images.size()].reset(iter->second); lib->loaded = true; } for (auto iter = loaded_libraries.begin(); iter != loaded_libraries.end(); iter++) { BOOST_LOG_TRIVIAL(info) << boost::format("Loaded image library '%s' with %d entries") % iter->first % iter->second->images.size(); resources->image_libraries[iter->first] = std::move(iter->second); } } else { BOOST_LOG_TRIVIAL(warning) << "Don't know how to load image libraries from: " << filename; } }
static void cut_extension(char *name, const char *ext) { if (!has_extension(name, ext)) return; name[strlen(name) - strlen(ext)] = '\0'; }
static void compile() { if (!has_extension(sOutputFile, ".rsrc")) add_extension(sOutputFile, ".rsrc"); rdef_compile(sOutputFile); }
static void decompile() { if (!has_extension(sOutputFile, ".rdef")) add_extension(sOutputFile, ".rdef"); rdef_decompile(sOutputFile); }
/* * Returns TRUE if user left off file extension, allowing default. * Note that the name is misleading if multiple dots are allowed. * not_pgp_extension or something would be better. */ boolean no_extension(char *filename) { #ifdef MULTIPLE_DOTS /* filename can have more than one dot */ if (has_extension(filename, ASC_EXTENSION) || has_extension(filename, PGP_EXTENSION) || has_extension(filename, SIG_EXTENSION) || #ifdef MACTC5 has_extension(filename,".tmp") || #endif is_tempfile(filename)) return FALSE; else return TRUE; #else filename = file_tail(filename); return strrchr(filename, '.') == NULL; #endif } /* no_extension */
void ImageLoader::load_library(Atom name, const std::string& filename) { ImageMap images; if (has_extension(filename, ".ilb")) { BOOST_LOG_TRIVIAL(info) << "Loading image library: " << filename; load_ilb(filename, graphics, images); } else if (has_extension(filename, ".hss")) { BOOST_LOG_TRIVIAL(info) << "Loading image library: " << filename; load_hss(filename, graphics, images); } else { BOOST_LOG_TRIVIAL(warning) << "Don't know how to load image library: " << filename; } ImageLibraryResource *lib = resources->image_libraries[name].get(); for (auto iter = images.begin(); iter != images.end(); iter++) { Image *image = iter->second; lib->images[image->id].reset(image); } lib->loaded = true; }
int has_extension_array(char *name, char **exts, unsigned int len) { int i; for(i = 0; i < len; i++) { if(has_extension(name, exts[i])) return 1; } return 0; }
int check_ref_format(const char *ref) { int ch, level, bad_type, last; int ret = CHECK_REF_FORMAT_OK; const char *cp = ref; level = 0; while (1) { while ((ch = *cp++) == '/') ; /* tolerate duplicated slashes */ if (!ch) /* should not end with slashes */ return CHECK_REF_FORMAT_ERROR; /* we are at the beginning of the path component */ if (ch == '.') return CHECK_REF_FORMAT_ERROR; bad_type = bad_ref_char(ch); if (bad_type) { if (bad_type == 2 && (!*cp || *cp == '/') && ret == CHECK_REF_FORMAT_OK) ret = CHECK_REF_FORMAT_WILDCARD; else return CHECK_REF_FORMAT_ERROR; } last = ch; /* scan the rest of the path component */ while ((ch = *cp++) != 0) { bad_type = bad_ref_char(ch); if (bad_type) return CHECK_REF_FORMAT_ERROR; if (ch == '/') break; if (last == '.' && ch == '.') return CHECK_REF_FORMAT_ERROR; if (last == '@' && ch == '{') return CHECK_REF_FORMAT_ERROR; last = ch; } level++; if (!ch) { if (ref <= cp - 2 && cp[-2] == '.') return CHECK_REF_FORMAT_ERROR; if (level < 2) return CHECK_REF_FORMAT_ONELEVEL; if (has_extension(ref, ".lock")) return CHECK_REF_FORMAT_ERROR; return ret; } } }
static void gcf_decompress(){ char*source; char target[LTSMIN_PATHNAME_MAX]; while((source=HREnextArg())){ if (has_extension(source,".gzf")){ strncpy(target,source,strlen(source)-4); target[strlen(source)-4]=0; stream_t is=file_input(source); stream_t os=file_output(target); char *code=DSreadSA(is); is=stream_add_code(is,code); char buf[blocksize]; for(;;){ int len=stream_read_max(is,buf,blocksize); if (len) stream_write(os,buf,len); if(len<blocksize) break; } stream_close(&is); stream_close(&os); if (!keep) recursive_erase(source); } else if (has_extension(source,".gcf")||has_extension(source,".zip")){ strncpy(target,source,strlen(source)-4); target[strlen(source)-4]=0; archive_t arch_in; if (has_extension(source,".gcf")){ arch_in=arch_gcf_read(raf_unistd(source)); } else { arch_in=arch_zip_read(source,blocksize); } archive_t arch_out=arch_dir_create(target,blocksize,force?DELETE_ALL:DELETE_NONE); archive_copy(arch_in,arch_out,NULL,blocksize,NULL); arch_close(&arch_in); arch_close(&arch_out); if (!keep) recursive_erase(source); } else { Abort("source %s does not have known extension",source); } } }
std::string get_default_rpc_filepath () { boost::system::error_code err; auto running_executable_filepath = boost::dll::program_location (err); // Construct the nano_rpc excutable file path based on where the currently running executable is found. auto rpc_filepath = running_executable_filepath.parent_path () / "nano_rpc"; if (running_executable_filepath.has_extension ()) { rpc_filepath.replace_extension (running_executable_filepath.extension ()); } return rpc_filepath.string (); }
const struct extension_language_defn * get_ext_lang_of_file (const char *file) { int i; const struct extension_language_defn *extlang; ALL_EXTENSION_LANGUAGES (i, extlang) { if (has_extension (file, extlang->suffix)) return extlang; } return NULL; }
/* if user consents to it, change the filename extension. */ char *maybe_force_extension(char *filename, char *extension) { static char newname[MAX_PATH]; if (!has_extension(filename, extension)) { strcpy(newname, filename); force_extension(newname, extension); if (!file_exists(newname)) { fprintf(pgpout, LANG("\nShould '%s' be renamed to '%s' (Y/n)? "), filename, newname); if (getyesno('y')) return newname; } } return NULL; } /* maybe_force_extension */
static int do_for_each_reflog(const char *base, each_ref_fn fn, void *cb_data) { DIR *dir = opendir(git_path("logs/%s", base)); int retval = 0; if (dir) { struct dirent *de; int baselen = strlen(base); char *log = xmalloc(baselen + 257); memcpy(log, base, baselen); if (baselen && base[baselen-1] != '/') log[baselen++] = '/'; while ((de = readdir(dir)) != NULL) { struct stat st; int namelen; if (de->d_name[0] == '.') continue; namelen = strlen(de->d_name); if (namelen > 255) continue; if (has_extension(de->d_name, ".lock")) continue; memcpy(log + baselen, de->d_name, namelen+1); if (stat(git_path("logs/%s", log), &st) < 0) continue; if (S_ISDIR(st.st_mode)) { retval = do_for_each_reflog(log, fn, cb_data); } else { unsigned char sha1[20]; if (!resolve_ref(log, sha1, 0, NULL)) retval = error("bad ref for %s", log); else retval = fn(log, sha1, 0, cb_data); } if (retval) break; } free(log); closedir(dir); } else if (*base) return errno; return retval; }
static struct ref_list *get_ref_dir(const char *base, struct ref_list *list) { DIR *dir = opendir(git_path("%s", base)); if (dir) { struct dirent *de; int baselen = strlen(base); char *ref = xmalloc(baselen + 257); memcpy(ref, base, baselen); if (baselen && base[baselen-1] != '/') ref[baselen++] = '/'; while ((de = readdir(dir)) != NULL) { unsigned char sha1[20]; struct stat st; int flag; int namelen; if (de->d_name[0] == '.') continue; namelen = strlen(de->d_name); if (namelen > 255) continue; if (has_extension(de->d_name, ".lock")) continue; memcpy(ref + baselen, de->d_name, namelen+1); if (stat(git_path("%s", ref), &st) < 0) continue; if (S_ISDIR(st.st_mode)) { list = get_ref_dir(ref, list); continue; } if (!resolve_ref(ref, sha1, 1, &flag)) { hashclr(sha1); flag |= REF_BROKEN; } list = add_ref(ref, sha1, flag, list, NULL); } free(ref); closedir(dir); } return sort_ref_list(list); }
static void list_commands_in_dir(struct cmdnames *cmds, const char *path, const char *prefix) { int prefix_len; DIR *dir = opendir(path); struct dirent *de; struct strbuf buf = STRBUF_INIT; int len; if (!dir) return; if (!prefix) prefix = "git-"; prefix_len = strlen(prefix); strbuf_addf(&buf, "%s/", path); len = buf.len; while ((de = readdir(dir)) != NULL) { int entlen; if (prefixcmp(de->d_name, prefix)) continue; strbuf_setlen(&buf, len); strbuf_addstr(&buf, de->d_name); if (!is_executable(buf.buf)) continue; entlen = strlen(de->d_name) - prefix_len; if (has_extension(de->d_name, ".exe")) entlen -= 4; add_cmdname(cmds, de->d_name + prefix_len, entlen); } closedir(dir); strbuf_release(&buf); }
static int is_executable(const char *name) { struct stat st; if (stat(name, &st) || /* stat, not lstat */ !S_ISREG(st.st_mode)) return 0; #if defined(WIN32) || defined(__CYGWIN__) /* On Windows we cannot use the executable bit. The executable * state is determined by extension only. We do this first * because with virus scanners opening an executeable for * reading is potentially expensive. */ if (has_extension(name, ".exe")) return S_IXUSR; #if defined(__CYGWIN__) if ((st.st_mode & S_IXUSR) == 0) #endif { /* now that we know it does not have an executable extension, peek into the file instead */ char buf[3] = { 0 }; int n; int fd = open(name, O_RDONLY); st.st_mode &= ~S_IXUSR; if (fd >= 0) { n = read(fd, buf, 2); if (n == 2) /* look for a she-bang */ if (!strcmp(buf, "#!")) st.st_mode |= S_IXUSR; close(fd); } } #endif return st.st_mode & S_IXUSR; }
static void list_commands_in_dir(struct cmdnames *cmds, const char *path, const char *prefix) { int prefix_len; DIR *dir = opendir(path); struct dirent *de; char *buf = NULL; if (!dir) return; if (!prefix) prefix = "perf-"; prefix_len = strlen(prefix); astrcatf(&buf, "%s/", path); while ((de = readdir(dir)) != NULL) { int entlen; if (!strstarts(de->d_name, prefix)) continue; astrcat(&buf, de->d_name); if (!is_executable(buf)) continue; entlen = strlen(de->d_name) - prefix_len; if (has_extension(de->d_name, ".exe")) entlen -= 4; add_cmdname(cmds, de->d_name + prefix_len, entlen); } closedir(dir); free(buf); }
static struct ctx* create_context(void) { const char *vert_shader = "#version 100\n" "precision mediump float;\n" "uniform vec2 resolution;\n" "mat4 ortho = mat4(" " 2.0/resolution.x, 0, 0, 0," " 0, -2.0/resolution.y, 0, 0," " 0, 0, -1, 0," " -1, 1, 0, 1" ");\n" "attribute vec4 pos;\n" "attribute vec2 uv;\n" "varying vec2 v_uv;\n" "void main() {\n" " gl_Position = ortho * pos;\n" " v_uv = uv;\n" "}\n"; const char *frag_shader_dummy = "#version 100\n" "precision mediump float;\n" "void main() {\n" " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" "}\n"; const char *frag_shader_cursor = "#version 100\n" "precision highp float;\n" "uniform sampler2D texture0;\n" "varying vec2 v_uv;\n" "void main() {\n" " vec4 palette[3];\n" " palette[0] = vec4(0.0, 0.0, 0.0, 1.0);\n" " palette[1] = vec4(1.0, 1.0, 1.0, 1.0);\n" " palette[2] = vec4(0.0, 0.0, 0.0, 0.0);\n" " gl_FragColor = palette[int(texture2D(texture0, v_uv).r * 256.0)];\n" "}\n"; const char *frag_shader_bg = "#version 100\n" "precision mediump float;\n" "uniform float time;\n" "uniform vec2 resolution;\n" "varying vec2 v_uv;\n" "#define M_PI 3.1415926535897932384626433832795\n" "float impulse(float x, float k) {\n" " float h = k * x;\n" " return h * exp(1.0 - h);\n" "}\n" "void main() {\n" " vec3 color = vec3(0.0);\n" " vec2 pos = (v_uv * 4.0 - 2.0);\n" " float frame = time * M_PI * 10.0;\n" " float f = impulse(0.01, sin(frame) + 1.0) + 0.25;\n" " color += vec3(0.15, 0.3, 0.35) * (1.0 / distance(vec2(1.0, 0.0), pos) * f);\n" " for (int i = 0; i < 3; ++i) {\n" " float t = frame + (float(i) * 1.8);\n" " color += vec3(0.15, 0.18, 0.15) * float(i + 1) * (1.0 / distance(vec2(sin(t * 0.8) * 0.5 + 1.0, cos(t) * 0.5), pos) * 0.09);\n" " }\n" " gl_FragColor = vec4(color, 1.0);\n" "}\n"; const char *frag_shader_rgb = "#version 100\n" "precision mediump float;\n" "uniform sampler2D texture0;\n" "uniform float dim;\n" "varying vec2 v_uv;\n" "void main() {\n" " gl_FragColor = vec4(texture2D(texture0, v_uv).rgb * dim, 1.0);\n" "}\n"; const char *frag_shader_rgba = "#version 100\n" "precision mediump float;\n" "uniform sampler2D texture0;\n" "uniform float dim;\n" "varying vec2 v_uv;\n" "void main() {\n" " vec4 col = texture2D(texture0, v_uv);\n" " gl_FragColor = vec4(col.rgb * dim, col.a);\n" "}\n"; const char *frag_shader_egl = "#version 100\n" "#extension GL_OES_EGL_image_external : require\n" "precision mediump float;\n" "uniform samplerExternalOES texture0;\n" "uniform float dim;\n" "varying vec2 v_uv;\n" "void main()\n" "{\n" " vec4 col = texture2D(texture0, v_uv);\n" " gl_FragColor = vec4(col.rgb * dim, col.a)\n;" "}\n"; #define FRAGMENT_CONVERT_YUV \ " y *= dim;\n" \ " u *= dim;\n" \ " v *= dim;\n" \ " gl_FragColor.r = y + 1.59602678 * v;\n" \ " gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;\n" \ " gl_FragColor.b = y + 2.01723214 * u;\n" \ " gl_FragColor.a = 1.0;\n" const char *frag_shader_y_uv = "#version 100\n" "precision mediump float;\n" "uniform sampler2D texture0;\n" "uniform sampler2D texture1;\n" "uniform float dim;\n" "varying vec2 v_uv;\n" "void main() {\n" " float y = 1.16438356 * (texture2D(texture0, v_uv).x - 0.0625);\n" " float u = texture2D(texture1, v_uv).r - 0.5;\n" " float v = texture2D(texture1, v_uv).g - 0.5;\n" FRAGMENT_CONVERT_YUV "}\n"; const char *frag_shader_y_u_v = "#version 100\n" "precision mediump float;\n" "uniform sampler2D texture0;\n" "uniform sampler2D texture1;\n" "uniform sampler2D texture2;\n" "uniform float dim;\n" "varying vec2 v_uv;\n" "void main() {\n" " float y = 1.16438356 * (texture2D(texture0, v_uv).x - 0.0625);\n" " float u = texture2D(texture1, v_uv).x - 0.5;\n" " float v = texture2D(texture2, v_uv).x - 0.5;\n" FRAGMENT_CONVERT_YUV "}\n"; const char *frag_shader_y_xuxv = "#version 100\n" "precision mediump float;\n" "uniform sampler2D texture0;\n" "uniform sampler2D texture1;\n" "uniform float dim;\n" "varying vec2 v_uv;\n" "void main() {\n" " float y = 1.16438356 * (texture2D(texture0, v_uv).x - 0.0625);\n" " float u = texture2D(texture1, v_uv).g - 0.5;\n" " float v = texture2D(texture1, v_uv).a - 0.5;\n" FRAGMENT_CONVERT_YUV "}\n"; struct ctx *context; if (!(context = calloc(1, sizeof(struct ctx)))) return NULL; const char *str; str = (const char*)GL_CALL(gl.api.glGetString(GL_VERSION)); wlc_log(WLC_LOG_INFO, "GL version: %s", str ? str : "(null)"); str = (const char*)GL_CALL(gl.api.glGetString(GL_VENDOR)); wlc_log(WLC_LOG_INFO, "GL vendor: %s", str ? str : "(null)"); context->extensions = (const char*)GL_CALL(gl.api.glGetString(GL_EXTENSIONS)); if (has_extension(context, "GL_OES_EGL_image_external")) { context->api.glEGLImageTargetTexture2DOES = gl.api.glEGLImageTargetTexture2DOES; } else { wlc_log(WLC_LOG_WARN, "gles2: GL_OES_EGL_image_external not available"); frag_shader_egl = frag_shader_dummy; } const struct { const char *vert; const char *frag; } map[PROGRAM_LAST] = { { vert_shader, frag_shader_rgb }, // PROGRAM_RGB { vert_shader, frag_shader_rgba }, // PROGRAM_RGBA { vert_shader, frag_shader_egl }, // PROGRAM_EGL { vert_shader, frag_shader_y_uv }, // PROGRAM_Y_UV { vert_shader, frag_shader_y_u_v }, // PROGRAM_Y_U_V { vert_shader, frag_shader_y_xuxv }, // PROGRAM_Y_XUXV { vert_shader, frag_shader_cursor }, // PROGRAM_CURSOR { vert_shader, frag_shader_bg }, // PROGRAM_BG }; for (GLuint i = 0; i < PROGRAM_LAST; ++i) { GLuint vert = create_shader(map[i].vert, GL_VERTEX_SHADER); GLuint frag = create_shader(map[i].frag, GL_FRAGMENT_SHADER); context->programs[i].obj = gl.api.glCreateProgram(); GL_CALL(gl.api.glAttachShader(context->programs[i].obj, vert)); GL_CALL(gl.api.glAttachShader(context->programs[i].obj, frag)); GL_CALL(gl.api.glLinkProgram(context->programs[i].obj)); GL_CALL(gl.api.glDeleteShader(vert)); GL_CALL(gl.api.glDeleteShader(frag)); GLint status; GL_CALL(gl.api.glGetProgramiv(context->programs[i].obj, GL_LINK_STATUS, &status)); if (!status) { GLsizei len; char log[1024]; GL_CALL(gl.api.glGetProgramInfoLog(context->programs[i].obj, sizeof(log), &len, log)); wlc_log(WLC_LOG_ERROR, "Linking:\n%*s\n", len, log); abort(); } set_program(context, i); GL_CALL(gl.api.glBindAttribLocation(context->programs[i].obj, 0, "pos")); GL_CALL(gl.api.glBindAttribLocation(context->programs[i].obj, 1, "uv")); for (int u = 0; u < UNIFORM_LAST; ++u) { context->programs[i].uniforms[u] = GL_CALL(gl.api.glGetUniformLocation(context->programs[i].obj, uniform_names[u])); } GL_CALL(gl.api.glUniform1i(context->programs[i].uniforms[UNIFORM_TEXTURE0], 0)); GL_CALL(gl.api.glUniform1i(context->programs[i].uniforms[UNIFORM_TEXTURE1], 1)); GL_CALL(gl.api.glUniform1i(context->programs[i].uniforms[UNIFORM_TEXTURE2], 2)); } struct { GLenum format; GLuint w, h; GLenum type; const void *data; } images[TEXTURE_LAST] = { { GL_LUMINANCE, 1, 1, GL_UNSIGNED_BYTE, (GLubyte[]){ 0 } }, // TEXTURE_BLACK
int main(int argc, char **argv) { /* Platform */ int running = 1; struct XWindow win; GLXContext glContext; struct nk_context *ctx; struct nk_color background; memset(&win, 0, sizeof(win)); win.dpy = XOpenDisplay(NULL); if (!win.dpy) die("Failed to open X display\n"); { /* check glx version */ int glx_major, glx_minor; if (!glXQueryVersion(win.dpy, &glx_major, &glx_minor)) die("[X11]: Error: Failed to query OpenGL version\n"); if ((glx_major == 1 && glx_minor < 3) || (glx_major < 1)) die("[X11]: Error: Invalid GLX version!\n"); } { /* find and pick matching framebuffer visual */ int fb_count; static GLint attr[] = { GLX_X_RENDERABLE, True, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_DOUBLEBUFFER, True, None }; GLXFBConfig *fbc; fbc = glXChooseFBConfig(win.dpy, DefaultScreen(win.dpy), attr, &fb_count); if (!fbc) die("[X11]: Error: failed to retrieve framebuffer configuration\n"); { /* pick framebuffer with most samples per pixel */ int i; int fb_best = -1, best_num_samples = -1; for (i = 0; i < fb_count; ++i) { XVisualInfo *vi = glXGetVisualFromFBConfig(win.dpy, fbc[i]); if (vi) { int sample_buffer, samples; glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLE_BUFFERS, &sample_buffer); glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLES, &samples); if ((fb_best < 0) || (sample_buffer && samples > best_num_samples)) fb_best = i; best_num_samples = samples; } } win.fbc = fbc[fb_best]; XFree(fbc); win.vis = glXGetVisualFromFBConfig(win.dpy, win.fbc); } } { /* create window */ win.cmap = XCreateColormap(win.dpy, RootWindow(win.dpy, win.vis->screen), win.vis->visual, AllocNone); win.swa.colormap = win.cmap; win.swa.background_pixmap = None; win.swa.border_pixel = 0; win.swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPress | ButtonReleaseMask| ButtonMotionMask | Button1MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask| PointerMotionMask| StructureNotifyMask; win.win = XCreateWindow(win.dpy, RootWindow(win.dpy, win.vis->screen), 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, win.vis->depth, InputOutput, win.vis->visual, CWBorderPixel|CWColormap|CWEventMask, &win.swa); if (!win.win) die("[X11]: Failed to create window\n"); XFree(win.vis); XStoreName(win.dpy, win.win, "Demo"); XMapWindow(win.dpy, win.win); } { /* create opengl context */ typedef GLXContext(*glxCreateContext)(Display*, GLXFBConfig, GLXContext, Bool, const int*); int(*old_handler)(Display*, XErrorEvent*) = XSetErrorHandler(gl_error_handler); const char *extensions_str = glXQueryExtensionsString(win.dpy, DefaultScreen(win.dpy)); glxCreateContext create_context = (glxCreateContext) glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB"); gl_err = FALSE; if (!has_extension(extensions_str, "GLX_ARB_create_context") || !create_context) { fprintf(stdout, "[X11]: glXCreateContextAttribARB() not found...\n"); fprintf(stdout, "[X11]: ... using old-style GLX context\n"); glContext = glXCreateNewContext(win.dpy, win.fbc, GLX_RGBA_TYPE, 0, True); } else { GLint attr[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 0, None }; glContext = create_context(win.dpy, win.fbc, 0, True, attr); XSync(win.dpy, False); if (gl_err || !glContext) { /* Could not create GL 3.0 context. Fallback to old 2.x context. * If a version below 3.0 is requested, implementations will * return the newest context version compatible with OpenGL * version less than version 3.0.*/ attr[1] = 1; attr[3] = 0; gl_err = FALSE; fprintf(stdout, "[X11] Failed to create OpenGL 3.0 context\n"); fprintf(stdout, "[X11] ... using old-style GLX context!\n"); glContext = create_context(win.dpy, win.fbc, 0, True, attr); } } XSync(win.dpy, False); XSetErrorHandler(old_handler); if (gl_err || !glContext) die("[X11]: Failed to create an OpenGL context\n"); glXMakeCurrent(win.dpy, win.win, glContext); } ctx = nk_x11_init(win.dpy, win.win); /* Load Fonts: if none of these are loaded a default font will be used */ {struct nk_font_atlas *atlas; nk_x11_font_stash_begin(&atlas); /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/ /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ nk_x11_font_stash_end(); /*nk_style_set_font(ctx, &droid->handle);*/} /* style.c */ /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ background = nk_rgb(28,48,62); while (running) { /* Input */ XEvent evt; nk_input_begin(ctx); while (XCheckWindowEvent(win.dpy, win.win, win.swa.event_mask, &evt)){ if (XFilterEvent(&evt, win.win)) continue; nk_x11_handle_event(&evt); } nk_input_end(ctx); /* GUI */ {struct nk_panel layout; if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 200, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { enum {EASY, HARD}; static int op = EASY; static int property = 20; nk_layout_row_static(ctx, 30, 80, 1); if (nk_button_label(ctx, "button", NK_BUTTON_DEFAULT)) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); {struct nk_panel combo; nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "background:", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); if (nk_combo_begin_color(ctx, &combo, background, 400)) { nk_layout_row_dynamic(ctx, 120, 1); background = nk_color_picker(ctx, background, NK_RGBA); nk_layout_row_dynamic(ctx, 25, 1); background.r = (nk_byte)nk_propertyi(ctx, "#R:", 0, background.r, 255, 1,1); background.g = (nk_byte)nk_propertyi(ctx, "#G:", 0, background.g, 255, 1,1); background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1); background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1); nk_combo_end(ctx); }} } nk_end(ctx);} if (nk_window_is_closed(ctx, "Demo")) break; /* -------------- EXAMPLES ---------------- */ /*calculator(ctx);*/ /*overview(ctx);*/ /*node_editor(ctx);*/ /* ----------------------------------------- */ /* Draw */ {float bg[4]; nk_color_fv(bg, background); XGetWindowAttributes(win.dpy, win.win, &win.attr); glViewport(0, 0, win.width, win.height); glClear(GL_COLOR_BUFFER_BIT); glClearColor(bg[0], bg[1], bg[2], bg[3]); /* IMPORTANT: `nk_x11_render` modifies some global OpenGL state * with blending, scissor, face culling, depth test and viewport and * defaults everything back into a default state. * Make sure to either a.) save and restore or b.) reset your own state after * rendering the UI. */ nk_x11_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER); glXSwapBuffers(win.dpy, win.win);} } nk_x11_shutdown(); glXMakeCurrent(win.dpy, 0, 0); glXDestroyContext(win.dpy, glContext); XUnmapWindow(win.dpy, win.win); XFreeColormap(win.dpy, win.cmap); XDestroyWindow(win.dpy, win.win); XCloseDisplay(win.dpy); return 0; }
char * append_graphic_extension(char *s) { char *t; if (has_extension(s, ".pict") || has_extension(s, ".png") || has_extension(s, ".gif") || has_extension(s, ".emf") || has_extension(s, ".wmf") || has_extension(s, ".eps") || has_extension(s, ".pdf") || has_extension(s, ".ps") || has_extension(s, ".tiff") || has_extension(s, ".tif") || has_extension(s, ".jpg") || has_extension(s, ".jpeg")) return strdup(s); t = exists_with_extension(s,".png"); if (t) return t; t = exists_with_extension(s,".jpg"); if (t) return t; t = exists_with_extension(s,".jpeg"); if (t) return t; t = exists_with_extension(s,".tif"); if (t) return t; t = exists_with_extension(s,".tiff"); if (t) return t; t = exists_with_extension(s,".gif"); if (t) return t; t = exists_with_extension(s,".eps"); if (t) return t; t = exists_with_extension(s,".pdf"); if (t) return t; t = exists_with_extension(s,".ps"); if (t) return t; t = exists_with_extension(s,".pict"); if (t) return t; t = exists_with_extension(s,".emf"); if (t) return t; t = exists_with_extension(s,".wmf"); if (t) return t; /* failed to find any file */ return strdup(s); }
void CmdGraphics(int code) /* \includegraphics[parameters]{filename} where parameters is a comma-separated list of any of the following: bb=llx lly urx ury (bounding box), width=h_length, height=v_length, angle=angle, scale=factor, clip=true/false, draft=true/false. code=0 => includegraphics code=1 => epsffile code=2 => epsfbox code=3 => \BoxedSPSF code=4 => psfig */ { char *options,*options2; char *filename,*fullpathname, *fullname; double scale=1.0; double baseline=0.0; double x; char *p; if (code==0) { /* could be \includegraphics*[0,0][5,5]{file.pict} */ options = getBracketParam(); options2 = getBracketParam(); if (options2) free(options2); if (options) { /* \includegraphics[scale=0.5]{file.png} */ p = strstr(options,"scale"); if (p) { p = strchr(p,'='); if (p && (sscanf(p+1,"%lf", &x) == 1)) scale = x; } free(options); } filename = getBraceParam(); diagnostics(1, "image scale = %g", scale); if (g_figs_extract && g_processing_figure) { struct stat st ={0}; if (stat(g_figsdir, &st) == -1) { mkdir(g_figsdir,0755); } g_fignum++; char *name = (char *)malloc(15*sizeof(char)); snprintf(name,15,"Ris%d.png",g_fignum); char *destname = strdup_together(g_figsdir,"/"); char *pngname = strdup_together(destname,name); int cmd_len = strlen("convert -alpha off -density 300x300 ") + strlen(destname) + strlen(filename)+32; char *cmd = (char *) malloc(cmd_len); snprintf(cmd,cmd_len,"convert -density 300x300 %s -alpha off %s ",filename,pngname); system(cmd); free(cmd); free(destname); free(pngname); free(name); } } if (code==1) { /* \epsffile{filename.eps} */ filename = getBraceParam(); } if (code==2) { /* \epsfbox[0 0 30 50]{filename.ps} */ options = getBracketParam(); if (options) free(options); filename = getBraceParam(); } if (code==3) { /* \BoxedEPSF{filename [scaled nnn]} */ char *s; filename = getBraceParam(); s= strchr(filename,' '); if (s) *s='\0'; } if (code==4) { /* \psfig{figure=filename,height=hhh,width=www} */ char *s, *t; filename = getBraceParam(); s = strstr(filename,"figure="); if (!s) return; s += strlen("figure="); t = strchr(s,','); if (t) *t='\0'; t = strdup(s); free(filename); filename = t; } SetTexMode(MODE_HORIZONTAL); fullname=strdup_absolute_path(filename); fullpathname=append_graphic_extension(fullname); free(fullname); if (has_extension(fullpathname, ".pict")) PutPictFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".png")) PutPngFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".gif")) PutGifFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".emf")) PutEmfFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".wmf")) PutWmfFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".eps")) PutEpsFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".pdf")) PutPdfFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".ps")) PutEpsFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".tiff")) PutTiffFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".tif")) PutTiffFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".jpg")) PutJpegFile(fullpathname, scale, baseline, TRUE); else if (has_extension(fullpathname, ".jpeg")) PutJpegFile(fullpathname, scale, baseline, TRUE); else diagnostics(WARNING, "Conversion of '%s' not supported", filename); free(filename); free(fullpathname); }
void Filesystem::generate_image_file_list(const std::string& pathname, std::vector<URL>& file_list) { if (!exist(pathname)) { std::cout << "Filesystem::generate_jpeg_file_list(): " << pathname << " does not exist" << std::endl; } else { // generate a list of all the files in the directories std::vector<std::string> lst; if (is_directory(pathname)) { open_directory_recursivly(pathname, lst); } else { lst.push_back(pathname); } // check the file list for valid entries, if entries are archives, // get a file list from them std::vector<std::future<std::vector<URL>>> archive_tasks; for(std::vector<std::string>::iterator i = lst.begin(); i != lst.end(); ++i) { URL url = URL::from_filename(*i); try { if (ArchiveManager::current().is_archive(*i)) { archive_tasks.push_back(std::async([i, url]() -> std::vector<URL> { std::vector<URL> sub_file_list; const ArchiveLoader* loader; const auto& files = ArchiveManager::current().get_filenames(*i, &loader); for(const auto& file: files) { URL archive_url = URL::from_string(url.str() + "//" + loader->str() + ":" + file); if (SoftwareSurfaceFactory::current().has_supported_extension(archive_url)) { sub_file_list.push_back(archive_url); } } return sub_file_list; })); } else if (has_extension(*i, ".galapix")) { file_list.push_back(url); } else if (has_extension(*i, "ImageProperties.xml")) { file_list.push_back(url); } else if (url.get_protocol() == "buildin") { file_list.push_back(url); } else if (SoftwareSurfaceFactory::current().has_supported_extension(url)) { file_list.push_back(url); } else { //log_debug << "Filesystem::generate_image_file_list(): ignoring " << *i << std::endl; } } catch(const std::exception& err) { log_warning << "Warning: " << err.what() << std::endl; } } for(auto& task: archive_tasks) { try { const auto& sub_lst = task.get(); file_list.insert(file_list.end(), sub_lst.begin(), sub_lst.end()); } catch(const std::exception& err) { log_warning << "Warning: " << err.what() << std::endl; } } } }
bool FileIO::Path::has_filename() const { return has_extension( ); }
bool FileIO::Path::is_directory() const { return !has_extension( ); }
assembler_args_t parse_args(int argc, char* argv[]) { char c; int opt_index = 0; char *program_name = basename(argv[0]); assembler_args_t args; struct option long_options[] = { { "debug", no_argument, &args.debug_flag, TRUE }, // --debug or -d { "help", no_argument, NULL, 0 }, // --help or -h { 0, 0, 0, 0 } // terminating 0 item }; opterr = FALSE; args.debug_flag = FALSE; while ((c = getopt_long(argc, argv, "dh", long_options, &opt_index)) != -1) { switch (c) { case 'd': args.debug_flag = TRUE; break; case 'h': show_usage(program_name); break; case '\0': if (strcmp("help", long_options[opt_index].name) == 0) show_usage(program_name); break; case '?': if (optopt == '\0') fprintf(stderr, "Invalid option '%s'\n\n", argv[optind - 1]); else fprintf(stderr, "Invalid option '-%c'\n\n", optopt); show_usage(program_name); break; } } if (argc - optind != 1) { fprintf(stderr, "No input file specified\n\n"); show_usage(program_name); } else args.input_file = argv[optind]; if (!has_extension(args.input_file, "asm")) { fprintf(stderr, "Invalid file extension -- '.asm' expected\n"); exit(EXIT_FAILURE); } return args; }