static int dash_server_onvod(void* /*dash*/, http_session_t* session, const char* /*method*/, const char* path) { char fullpath[PATH_MAX]; int r = path_concat(path + 5 /* /vod/ */, LOCALPATH, fullpath); printf("vod: %s\n", fullpath); if (0 == r && path_testfile(fullpath)) { // MIME if (strendswith(fullpath, ".mpd")) http_server_set_content_type(session, "application/xml+dash"); else if (strendswith(fullpath, ".mp4") || strendswith(fullpath, ".m4v")) http_server_set_header(session, "content-type", "video/mp4"); else if (strendswith(fullpath, ".m4a")) http_server_set_header(session, "content-type", "audio/mp4"); //http_server_set_header(session, "Transfer-Encoding", "chunked"); // cross domain http_server_set_header(session, "Access-Control-Allow-Origin", "*"); http_server_set_header(session, "Access-Control-Allow-Methods", "GET, POST, PUT"); return http_server_sendfile(session, fullpath, NULL, NULL); } return http_server_send(session, 404, "", 0, NULL, NULL); }
file_type get_file_type(const char* filename) { /* see tools/winebuild/res32.c: check_header for details */ static const char res_sig[] = { 0,0,0,0, 32,0,0,0, 0xff,0xff, 0,0, 0xff,0xff, 0,0, 0,0,0,0, 0,0, 0,0, 0,0,0,0, 0,0,0,0 }; char buf[sizeof(res_sig)]; int fd, cnt; fd = open( filename, O_RDONLY ); if (fd == -1) return file_na; cnt = read(fd, buf, sizeof(buf)); close( fd ); if (cnt == -1) return file_na; if (cnt == sizeof(res_sig) && !memcmp(buf, res_sig, sizeof(res_sig))) return file_res; if (strendswith(filename, ".o")) return file_obj; if (strendswith(filename, ".a")) return file_arh; if (strendswith(filename, ".res")) return file_res; if (strendswith(filename, ".so")) return file_so; if (strendswith(filename, ".dylib")) return file_so; if (strendswith(filename, ".def")) return file_def; if (strendswith(filename, ".spec")) return file_spec; if (strendswith(filename, ".rc")) return file_rc; return file_other; }
void test_strendswith (void) { CU_ASSERT (strendswith (WORD_A, WORD_A_BAD_SUFFIX) == false); CU_ASSERT (strendswith (WORD_A, WORD_A_GOOD_SUFFIX) == true); CU_ASSERT (strendswith (WORD_A_GOOD_SUFFIX, WORD_A) == true); CU_ASSERT (strendswith (WORD_A_BAD_SUFFIX, WORD_A) == false); CU_ASSERT (strendswith (WORD_A, WORD_A) == true); CU_ASSERT (strendswith (WORD_B, WORD_B_BAD_SUFFIX) == false); CU_ASSERT (strendswith (WORD_B, WORD_B_GOOD_SUFFIX) == true); CU_ASSERT (strendswith (WORD_B_GOOD_SUFFIX, WORD_B) == true); CU_ASSERT (strendswith (WORD_B_BAD_SUFFIX, WORD_B) == false); CU_ASSERT (strendswith (WORD_B, WORD_B) == true); }
static int hls_server_onhttp(void* http, void* session, const char* method, const char* path) { // decode request uri void* url = url_parse(path); std::string s = url_getpath(url); url_free(url); path = s.c_str(); if (0 == strncmp(path, "/live/", 6)) { std::vector<std::string> paths; Split(path + 6, "/", paths); if (strendswith(path, ".m3u8") && 1 == paths.size()) { std::string app = paths[0].substr(0, paths[0].length() - 5); if (s_playlists.find(app) == s_playlists.end()) { hls_playlist_t* playlist = new hls_playlist_t(); playlist->file = app; playlist->m3u8 = hls_m3u8_create(HLS_LIVE_NUM); playlist->hls = hls_media_create(HLS_DURATION * 1000, hls_handler, playlist); playlist->i = 0; s_playlists[app] = playlist; thread_create(&playlist->t, hls_server_worker, playlist); } return hls_server_m3u8(session, app); } else if (strendswith(path, ".ts") && 2 == paths.size()) { if (s_playlists.find(paths[0]) != s_playlists.end()) { return hls_server_ts(session, paths[0], paths[1]); } } } else if (0 == strncmp(path, "/vod/", 5)) { if (path_testfile(path+5)) { return hls_server_reply_file(session, path + 5); } } return hls_server_reply(session, 404, ""); }
int fill_replayview_menu(MenuData *m) { DIR *dir = opendir(get_replays_path()); struct dirent *e; int rpys = 0; if(!dir) { printf("Could't read %s\n", get_replays_path()); return -1; } char ext[5]; snprintf(ext, 5, ".%s", REPLAY_EXTENSION); while((e = readdir(dir))) { if(!strendswith(e->d_name, ext)) continue; Replay *rpy = malloc(sizeof(Replay)); if(!replay_load(rpy, e->d_name)) { free(rpy); continue; } add_menu_entry(m, " ", replayview_run, rpy); m->entries[m->ecount-1].freearg = replayview_freearg; m->entries[m->ecount-1].draw = replayview_drawitem; ++rpys; } closedir(dir); qsort(m->entries, m->ecount, sizeof(MenuEntry), replayview_cmp); return rpys; }
/* Get varid of variable with name using nested group syntax * "gp1/gp2/var" or "/gp1/gp2/var". In the former case, grpname of * grp corresponding to grpid must end in "gp1/gp2". In the latter * case, grpname for grpid must be exactly "/gp1/gp2". If variable * named "var" is not in group grpid, returns NC_ENOTVAR, else sets * varid and returns NC_NOERR. */ int nc_inq_gvarid(int grpid, const char *varname, int *varidp) { /* if varname has no "/" chars, then return varidp from nc_inq_varid(grpid, varname, varidp) if varname begins with "/" else get groupname corresponding to grpid get vargroup = substring of varname up to last "/" get relname = substring of varname after last "/" if (varname starts with "/" and groupname == vargroup) || (groupname ends with vargroup) return nc_inq_varid(grpid, relname, varidp) else return NC_ENOTVAR */ #ifdef USE_NETCDF4 char *vargroup; char *relname; char *groupname; int status; if (varname[0] == '\0') return NC_ENOTVAR; vargroup = strdup(varname); if (vargroup == NULL) return NC_ENOMEM; relname = strrchr(vargroup, NC_GRP_DELIM); if (relname != NULL) { /* name has a "/" in it */ size_t len; /* length of full group name for grpid */ *relname++ = '\0'; /* split vargroup string in two, * vargroup and relname */ if ( (status = nc_inq_grpname_full(grpid, &len, NULL)) != NC_NOERR ) { free(vargroup); return status; } groupname = (char *)emalloc(len + 1); if ( (status = nc_inq_grpname_full(grpid, &len, groupname)) == NC_NOERR ) { if(varname[0] == NC_GRP_DELIM) { if( strcmp(groupname, vargroup) == 0) status = nc_inq_varid(grpid, relname, varidp); else status = NC_ENOTVAR; } else { if(strendswith(groupname, vargroup)) status = nc_inq_varid(grpid, relname, varidp); else status = NC_ENOTVAR; } } free(vargroup); free(groupname); return status; } free(vargroup); #endif /* USE_NETCDF4 */ return nc_inq_varid(grpid, varname, varidp); }
gdImagePtr imagefilter_readFile( char *n ) { if(!n) return NULL; FILE *f = fopen(n,"r"); if(!f) return NULL; gdImagePtr img = NULL; if( strendswith(n,".gd")) img = gdImageCreateFromGd(f); if( strendswith(n,".gd2")) img = gdImageCreateFromGd2(f); if( strendswith(n,".gif")) img = gdImageCreateFromGif(f); if( strendswith(n,".jpg")) img = gdImageCreateFromJpeg(f); if( strendswith(n,".png")) img = gdImageCreateFromPng(f); if( strendswith(n,".bmp")) img = gdImageCreateFromWBMP(f); if( strendswith(n,".xbm")) img = gdImageCreateFromXbm(f); fclose(f); return img; }
static void inject_file_contexts_bin(void) { // temporary fix till we inject the file_contexts.bin DIR *d = opendir("/"); if(d) { struct dirent *dt; char path[128]; while((dt = readdir(d))) { if(dt->d_type != DT_REG) continue; if(strendswith(dt->d_name, ".rc")) { snprintf(path, sizeof(path), "/%s", dt->d_name); char line[512]; char *tmp_name = NULL; FILE *f_in, *f_out; f_in = fopen(path, "re"); if(!f_in) return; const int size = strlen(path) + 5; tmp_name = malloc(size); snprintf(tmp_name, size, "%s-new", path); f_out = fopen(tmp_name, "we"); if(!f_out) { fclose(f_in); free(tmp_name); return; } while(fgets(line, sizeof(line), f_in)) { if(strstr(line, "restorecon_recursive ") && (strstr(line, "/data") || strstr(line, "/system") || strstr(line, "/cache") || strstr(line, "/mnt"))) fputc('#', f_out); fputs(line, f_out); } fclose(f_in); fclose(f_out); rename(tmp_name, path); free(tmp_name); chmod(path, 0750); } } closedir(d); } }
static int dash_mpd_onsegment(void* param, int /*track*/, const void* data, size_t bytes, int64_t /*pts*/, int64_t /*dts*/, int64_t /*duration*/, const char* name) { app_log(LOG_DEBUG, "dash_mpd_onsegment %s\n", name); FILE* fp = fopen(name, "wb"); fwrite(data, 1, bytes, fp); fclose(fp); dash_playlist_t* dash = (dash_playlist_t*)param; if(!strendswith(name, "-init.m4v") && !strendswith(name, "-init.m4a")) dash->files.push_back(name); while (dash->files.size() > 20) { app_log(LOG_DEBUG, "Delete %s\n", dash->files.front().c_str()); path_rmfile(dash->files.front().c_str()); dash->files.pop_front(); } AutoThreadLocker locker(s_locker); dash_mpd_playlist(dash->mpd, dash->playlist, sizeof(dash->playlist)); return 0; }
/* add input files that look like import libs to the import list */ static void load_import_libs( char *argv[] ) { char **ptr, **last; for (ptr = last = argv; *ptr; ptr++) { if (strendswith( *ptr, ".def" )) add_import_dll( NULL, *ptr ); else *last++ = *ptr; /* not an import dll, keep it in the list */ } *last = NULL; }
void rom_quirks_on_initrd_finalized(void) { // walk over all _regular_ files in / DIR *d = opendir("/"); if(d) { struct dirent *dt; char buff[128]; while((dt = readdir(d))) { if(dt->d_type != DT_REG) continue; // The Android L and later releases have SELinux // set to "enforcing" and "restorecon_recursive /data" line in init.rc. // Restorecon on /data goes into /data/media/0/multirom/roms/ and changes // context of all secondary ROMs files to that of /data, including the files // in secondary ROMs /system dirs. We need to prevent that. // Right now, we do that by adding entries into /file_contexts that say // MultiROM folders don't have any context if(strcmp(dt->d_name, "file_contexts") == 0) inject_file_contexts(); // "/data/.layout_version" is created without proper SELinux // context during "multirom_create_media_link" function // add a "restorecon /data/.layout_version" to init.rc if(strcmp(dt->d_name, "init.rc") == 0) inject_initrc_restorecon_layoutversion(); // Android N is using the binary format of file_contexts, until we have // and inject for it, like for the above text format of file_contexts // we'll go back to the old method and remove // * restorecon_recursive /data // * restorecon_recursive /mnt // TODO: check format of file_context by checking the magic if(strcmp(dt->d_name, "file_contexts.bin") == 0) inject_file_contexts_bin(); // franco.Kernel includes script init.fk.sh which remounts /system as read only // comment out lines with mount and /system in all .sh scripts in / if(strendswith(dt->d_name, ".sh")) { snprintf(buff, sizeof(buff), "/%s", dt->d_name); workaround_mount_in_sh(buff); } } closedir(d); } }
static struct pkg_loader_t* find_loader(const char *str) { char buf[strlen(str) + 1]; memset(buf, 0, sizeof(buf)); for(char *p = buf; *str; ++p, ++str) { *p = tolower(*str); } for(struct pkg_loader_t *l = pkg_loaders; l->ext; ++l) { if(strendswith(buf, l->ext)) { return l; } } return NULL; }
int replay_load(Replay *rpy, char *name) { char *p = replay_getpath(name, !strendswith(name, REPLAY_EXTENSION)); printf("replay_load(): loading %s\n", p); FILE *fp = fopen(p, "r"); free(p); if(!fp) { printf("replay_load(): fopen() failed\n"); return False; } int result = replay_read(rpy, fp); fclose(fp); return result; }
bool replay_save(Replay *rpy, const char *name) { char *p = replay_getpath(name, !strendswith(name, REPLAY_EXTENSION)); char *sp = vfs_repr(p, true); log_info("Saving %s", sp); free(sp); SDL_RWops *file = vfs_open(p, VFS_MODE_WRITE); free(p); if(!file) { log_warn("VFS error: %s", vfs_get_error()); return false; } bool result = replay_write(rpy, file, REPLAY_STRUCT_VERSION_WRITE); SDL_RWclose(file); return result; }
int replay_save(Replay *rpy, char *name) { char *p = replay_getpath(name, !strendswith(name, REPLAY_EXTENSION)); printf("replay_save(): saving %s\n", p); FILE *fp = fopen(p, "w"); free(p); if(!fp) { printf("replay_save(): fopen() failed\n"); return False; } int result = replay_write(rpy, fp); fflush(fp); fclose(fp); return result; }
static int dash_server_onlive(void* dash, http_session_t* session, const char* /*method*/, const char* path) { char fullpath[PATH_MAX]; int r = path_concat(path + 6 /* /live/ */, LOCALPATH, fullpath); printf("live: %s\n", fullpath); const char* name = path_basename(fullpath); if (strendswith(name, ".mpd")) { return dash_server_mpd(session, (dash_playlist_t*)dash); } else if (path_testfile(name)) { // cross domain http_server_set_header(session, "Access-Control-Allow-Origin", "*"); http_server_set_header(session, "Access-Control-Allow-Methods", "GET, POST, PUT"); return http_server_sendfile(session, name, NULL, NULL); } return http_server_send(session, 404, "", 0, NULL, NULL); }
/* build the dll exported name from the import lib name or path */ static char *get_dll_name( const char *name, const char *filename ) { char *ret; if (filename) { const char *basename = strrchr( filename, '/' ); if (!basename) basename = filename; else basename++; if (!strncmp( basename, "lib", 3 )) basename += 3; ret = xmalloc( strlen(basename) + 5 ); strcpy( ret, basename ); if (strendswith( ret, ".def" )) ret[strlen(ret)-4] = 0; } else { ret = xmalloc( strlen(name) + 5 ); strcpy( ret, name ); } if (!strchr( ret, '.' )) strcat( ret, ".dll" ); return ret; }
bool replay_load(Replay *rpy, const char *name, ReplayReadMode mode) { char *p = replay_getpath(name, !strendswith(name, REPLAY_EXTENSION)); char *sp = vfs_repr(p, true); log_info("Loading %s (%s)", sp, replay_mode_string(mode)); SDL_RWops *file = vfs_open(p, VFS_MODE_READ); free(p); if(!file) { log_warn("VFS error: %s", vfs_get_error()); free(sp); return false; } bool result = replay_read(rpy, file, mode, sp); if(!result) { replay_destroy(rpy); } free(sp); SDL_RWclose(file); return result; }
static bool check_shader_program_path(const char *path) { return strendswith(path, SHPROG_EXT) && strstartswith(path, SHPROG_PATH_PREFIX); }
/* output the resources into a .o file */ void output_res_o_file( DLLSPEC *spec ) { unsigned int i; char *res_file = NULL; int fd, err; if (!spec->nb_resources) fatal_error( "--resources mode needs at least one resource file as input\n" ); if (!output_file_name) fatal_error( "No output file name specified\n" ); byte_swapped = 0; init_output_buffer(); put_dword( 0 ); /* ResSize */ put_dword( 32 ); /* HeaderSize */ put_word( 0xffff ); /* ResType */ put_word( 0x0000 ); put_word( 0xffff ); /* ResName */ put_word( 0x0000 ); put_dword( 0 ); /* DataVersion */ put_word( 0 ); /* Memory options */ put_word( 0 ); /* Language */ put_dword( 0 ); /* Version */ put_dword( 0 ); /* Characteristics */ for (i = 0; i < spec->nb_resources; i++) { unsigned int header_size = get_resource_header_size( &spec->resources[i] ); put_dword( spec->resources[i].data_size ); put_dword( (header_size + 3) & ~3 ); put_string( &spec->resources[i].type ); put_string( &spec->resources[i].name ); align_output( 4 ); put_dword( 0 ); put_word( spec->resources[i].mem_options ); put_word( spec->resources[i].lang ); put_dword( 0 ); put_dword( 0 ); put_data( spec->resources[i].data, spec->resources[i].data_size ); align_output( 4 ); } /* if the output file name is a .res too, don't run the results through windres */ if (strendswith( output_file_name, ".res")) { flush_output_buffer(); return; } res_file = get_temp_file_name( output_file_name, ".res" ); if ((fd = open( res_file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600 )) == -1) fatal_error( "Cannot create %s\n", res_file ); if (write( fd, output_buffer, output_buffer_pos ) != output_buffer_pos) fatal_error( "Error writing to %s\n", res_file ); close( fd ); free( output_buffer ); if (res_file) { char *prog = find_tool( "windres", NULL ); char *cmd = xmalloc( strlen(prog) + strlen(res_file) + strlen(output_file_name) + 9 ); sprintf( cmd, "%s -i %s -o %s", prog, res_file, output_file_name ); if (verbose) fprintf( stderr, "%s\n", cmd ); err = system( cmd ); if (err) fatal_error( "%s failed with status %d\n", prog, err ); free( cmd ); free( prog ); } output_file_name = NULL; /* so we don't try to assemble it */ }
static bool check_bgm_meta_path(const char *path) { return strendswith(path, ".bgm") && strstartswith(path, BGM_PATH_PREFIX); }
int main(int argc, char **argv) { int i, c, next_is_arg = 0, linking = 1; int raw_compiler_arg, raw_linker_arg; const char* option_arg; struct options opts; char* lang = 0; char* str; #ifdef SIGHUP signal( SIGHUP, exit_on_signal ); #endif signal( SIGTERM, exit_on_signal ); signal( SIGINT, exit_on_signal ); #ifdef HAVE_SIGADDSET sigemptyset( &signal_mask ); sigaddset( &signal_mask, SIGHUP ); sigaddset( &signal_mask, SIGTERM ); sigaddset( &signal_mask, SIGINT ); #endif /* setup tmp file removal at exit */ tmp_files = strarray_alloc(); atexit(clean_temp_files); /* initialize options */ memset(&opts, 0, sizeof(opts)); opts.lib_dirs = strarray_alloc(); opts.files = strarray_alloc(); opts.linker_args = strarray_alloc(); opts.compiler_args = strarray_alloc(); opts.winebuild_args = strarray_alloc(); /* determine the processor type */ if (strendswith(argv[0], "winecpp")) opts.processor = proc_cpp; else if (strendswith(argv[0], "++")) opts.processor = proc_cxx; /* parse options */ for ( i = 1 ; i < argc ; i++ ) { if (argv[i][0] == '-') /* option */ { /* determine if tihs switch is followed by a separate argument */ next_is_arg = 0; option_arg = 0; switch(argv[i][1]) { case 'x': case 'o': case 'D': case 'U': case 'I': case 'A': case 'l': case 'u': case 'b': case 'V': case 'G': case 'L': case 'B': case 'R': case 'z': if (argv[i][2]) option_arg = &argv[i][2]; else next_is_arg = 1; break; case 'i': next_is_arg = 1; break; case 'a': if (strcmp("-aux-info", argv[i]) == 0) next_is_arg = 1; break; case 'X': if (strcmp("-Xlinker", argv[i]) == 0) next_is_arg = 1; break; case 'M': c = argv[i][2]; if (c == 'F' || c == 'T' || c == 'Q') { if (argv[i][3]) option_arg = &argv[i][3]; else next_is_arg = 1; } break; case 'f': if (strcmp("-framework", argv[i]) == 0) next_is_arg = 1; break; } if (next_is_arg) option_arg = argv[i+1]; /* determine what options go 'as is' to the linker & the compiler */ raw_compiler_arg = raw_linker_arg = 0; if (is_linker_arg(argv[i])) { raw_linker_arg = 1; } else { if (is_directory_arg(argv[i]) || is_target_arg(argv[i])) raw_linker_arg = 1; raw_compiler_arg = !is_mingw_arg(argv[i]); } /* these things we handle explicitly so we don't pass them 'as is' */ if (argv[i][1] == 'l' || argv[i][1] == 'I' || argv[i][1] == 'L') raw_linker_arg = 0; if (argv[i][1] == 'c' || argv[i][1] == 'L') raw_compiler_arg = 0; if (argv[i][1] == 'o') raw_compiler_arg = raw_linker_arg = 0; /* do a bit of semantic analysis */ switch (argv[i][1]) { case 'B': str = strdup(option_arg); if (strendswith(str, "/tools/winebuild")) { char *objdir = strdup(str); objdir[strlen(objdir) - sizeof("/tools/winebuild") + 1] = 0; opts.wine_objdir = objdir; /* don't pass it to the compiler, this generates warnings */ raw_compiler_arg = raw_linker_arg = 0; } if (strendswith(str, "/")) str[strlen(str) - 1] = 0; if (!opts.prefix) opts.prefix = strarray_alloc(); strarray_add(opts.prefix, str); break; case 'c': /* compile or assemble */ if (argv[i][2] == 0) opts.compile_only = 1; /* fall through */ case 'S': /* generate assembler code */ case 'E': /* preprocess only */ if (argv[i][2] == 0) linking = 0; break; case 'f': if (strcmp("-fno-short-wchar", argv[i]) == 0) opts.noshortwchar = 1; break; case 'l': strarray_add(opts.files, strmake("-l%s", option_arg)); break; case 'L': strarray_add(opts.lib_dirs, option_arg); break; case 'M': /* map file generation */ linking = 0; break; case 'm': if (strcmp("-mno-cygwin", argv[i]) == 0) opts.use_msvcrt = 1; else if (strcmp("-mwindows", argv[i]) == 0) opts.gui_app = 1; else if (strcmp("-mconsole", argv[i]) == 0) opts.gui_app = 0; else if (strcmp("-municode", argv[i]) == 0) opts.unicode_app = 1; else if (strcmp("-m32", argv[i]) == 0 || strcmp("-m64", argv[i]) == 0) raw_linker_arg = 1; break; case 'n': if (strcmp("-nostdinc", argv[i]) == 0) opts.nostdinc = 1; else if (strcmp("-nodefaultlibs", argv[i]) == 0) opts.nodefaultlibs = 1; else if (strcmp("-nostdlib", argv[i]) == 0) opts.nostdlib = 1; else if (strcmp("-nostartfiles", argv[i]) == 0) opts.nostartfiles = 1; break; case 'o': opts.output_name = option_arg; break; case 's': if (strcmp("-static", argv[i]) == 0) linking = -1; else if(strcmp("-save-temps", argv[i]) == 0) keep_generated = 1; else if(strcmp("-shared", argv[i]) == 0) { opts.shared = 1; raw_compiler_arg = raw_linker_arg = 0; } break; case 'v': if (argv[i][2] == 0) verbose++; break; case 'W': if (strncmp("-Wl,", argv[i], 4) == 0) { unsigned int j; strarray* Wl = strarray_fromstring(argv[i] + 4, ","); for (j = 0; j < Wl->size; j++) { if (!strcmp(Wl->base[j], "--image-base") && j < Wl->size - 1) { opts.image_base = strdup( Wl->base[++j] ); continue; } if (!strcmp(Wl->base[j], "-static")) linking = -1; strarray_add(opts.linker_args, strmake("-Wl,%s",Wl->base[j])); } strarray_free(Wl); raw_compiler_arg = raw_linker_arg = 0; } else if (strncmp("-Wb,", argv[i], 4) == 0) { strarray* Wb = strarray_fromstring(argv[i] + 4, ","); strarray_addall(opts.winebuild_args, Wb); strarray_free(Wb); /* don't pass it to the compiler, it generates errors */ raw_compiler_arg = raw_linker_arg = 0; } break; case 'x': lang = strmake("-x%s", option_arg); strarray_add(opts.files, lang); /* we'll pass these flags ourselves, explicitly */ raw_compiler_arg = raw_linker_arg = 0; break; case '-': if (strcmp("-static", argv[i]+1) == 0) linking = -1; break; } /* put the arg into the appropriate bucket */ if (raw_linker_arg) { strarray_add(opts.linker_args, argv[i]); if (next_is_arg && (i + 1 < argc)) strarray_add(opts.linker_args, argv[i + 1]); } if (raw_compiler_arg) { strarray_add(opts.compiler_args, argv[i]); if (next_is_arg && (i + 1 < argc)) strarray_add(opts.compiler_args, argv[i + 1]); } /* skip the next token if it's an argument */ if (next_is_arg) i++; } else { strarray_add(opts.files, argv[i]); } } if (opts.processor == proc_cpp) linking = 0; if (linking == -1) error("Static linking is not supported\n"); if (opts.files->size == 0) forward(argc, argv, &opts); else if (linking) build(&opts); else compile(&opts, lang); return 0; }
static void build(struct options* opts) { static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" }; strarray *lib_dirs, *files; strarray *spec_args, *link_args; char *output_file; const char *spec_o_name; const char *output_name, *spec_file, *lang; const char* winebuild = getenv("WINEBUILD"); int generate_app_loader = 1; unsigned int j; /* NOTE: for the files array we'll use the following convention: * -axxx: xxx is an archive (.a) * -dxxx: xxx is a DLL (.def) * -lxxx: xxx is an unsorted library * -oxxx: xxx is an object (.o) * -rxxx: xxx is a resource (.res) * -sxxx: xxx is a shared lib (.so) * -xlll: lll is the language (c, c++, etc.) */ if (!winebuild) winebuild = "winebuild"; output_file = strdup( opts->output_name ? opts->output_name : "a.out" ); /* 'winegcc -o app xxx.exe.so' only creates the load script */ if (opts->files->size == 1 && strendswith(opts->files->base[0], ".exe.so")) { create_file(output_file, 0755, app_loader_template, opts->files->base[0]); return; } /* generate app loader only for .exe */ if (opts->shared || strendswith(output_file, ".exe.so")) generate_app_loader = 0; /* normalize the filename a bit: strip .so, ensure it has proper ext */ if (strendswith(output_file, ".so")) output_file[strlen(output_file) - 3] = 0; if (opts->shared) { if ((output_name = strrchr(output_file, '/'))) output_name++; else output_name = output_file; if (!strchr(output_name, '.')) output_file = strmake("%s.dll", output_file); } else if (!strendswith(output_file, ".exe")) output_file = strmake("%s.exe", output_file); /* get the filename from the path */ if ((output_name = strrchr(output_file, '/'))) output_name++; else output_name = output_file; /* prepare the linking path */ if (!opts->wine_objdir) { lib_dirs = strarray_dup(opts->lib_dirs); for ( j = 0; j < sizeof(stdlibpath)/sizeof(stdlibpath[0]); j++ ) strarray_add(lib_dirs, stdlibpath[j]); } else { lib_dirs = strarray_alloc(); strarray_add(lib_dirs, strmake("%s/dlls", opts->wine_objdir)); strarray_add(lib_dirs, strmake("%s/libs/wine", opts->wine_objdir)); strarray_addall(lib_dirs, opts->lib_dirs); } /* mark the files with their appropriate type */ spec_file = lang = 0; files = strarray_alloc(); for ( j = 0; j < opts->files->size; j++ ) { const char* file = opts->files->base[j]; if (file[0] != '-') { switch(get_file_type(file)) { case file_def: case file_spec: if (spec_file) error("Only one spec file can be specified\n"); spec_file = file; break; case file_rc: /* FIXME: invoke wrc to build it */ error("Can't compile .rc file at the moment: %s\n", file); break; case file_res: strarray_add(files, strmake("-r%s", file)); break; case file_obj: strarray_add(files, strmake("-o%s", file)); break; case file_arh: strarray_add(files, strmake("-a%s", file)); break; case file_so: strarray_add(files, strmake("-s%s", file)); break; case file_na: error("File does not exist: %s\n", file); break; default: file = compile_to_object(opts, file, lang); strarray_add(files, strmake("-o%s", file)); break; } } else if (file[1] == 'l') add_library( lib_dirs, files, file + 2 ); else if (file[1] == 'x') lang = file; } if (opts->shared && !spec_file) error("A spec file is currently needed in shared mode\n"); /* add the default libraries, if needed */ if (!opts->nostdlib && opts->use_msvcrt) add_library(lib_dirs, files, "msvcrt"); if (!opts->wine_objdir && !opts->nodefaultlibs) { if (opts->gui_app) { add_library(lib_dirs, files, "shell32"); add_library(lib_dirs, files, "comdlg32"); add_library(lib_dirs, files, "gdi32"); } add_library(lib_dirs, files, "advapi32"); add_library(lib_dirs, files, "user32"); add_library(lib_dirs, files, "kernel32"); } if (!opts->nostartfiles) add_library(lib_dirs, files, "winecrt0"); if (!opts->nostdlib) add_library(lib_dirs, files, "wine"); /* run winebuild to generate the .spec.o file */ spec_args = strarray_alloc(); spec_o_name = get_temp_file(output_name, ".spec.o"); strarray_add(spec_args, winebuild); if (verbose) strarray_add(spec_args, "-v"); if (keep_generated) strarray_add(spec_args, "--save-temps"); strarray_add(spec_args, "--as-cmd"); strarray_add(spec_args, AS); strarray_add(spec_args, "--ld-cmd"); strarray_add(spec_args, LD); strarray_addall(spec_args, strarray_fromstring(DLLFLAGS, " ")); strarray_add(spec_args, opts->shared ? "--dll" : "--exe"); strarray_add(spec_args, "-o"); strarray_add(spec_args, spec_o_name); if (spec_file) { strarray_add(spec_args, "-E"); strarray_add(spec_args, spec_file); } if (!opts->shared) { strarray_add(spec_args, "-F"); strarray_add(spec_args, output_name); strarray_add(spec_args, "--subsystem"); strarray_add(spec_args, opts->gui_app ? "windows" : "console"); if (opts->unicode_app) { strarray_add(spec_args, "--entry"); strarray_add(spec_args, "__wine_spec_exe_wentry"); } } for ( j = 0; j < lib_dirs->size; j++ ) strarray_add(spec_args, strmake("-L%s", lib_dirs->base[j])); for ( j = 0 ; j < opts->winebuild_args->size ; j++ ) strarray_add(spec_args, opts->winebuild_args->base[j]); for ( j = 0; j < files->size; j++ ) { const char* name = files->base[j] + 2; switch(files->base[j][1]) { case 'r': strarray_add(spec_args, files->base[j]); break; case 'd': case 'a': case 'o': strarray_add(spec_args, name); break; } } spawn(opts->prefix, spec_args, 0); /* link everything together now */ link_args = strarray_alloc(); strarray_addall(link_args, get_translator(opts->processor)); strarray_addall(link_args, strarray_fromstring(LDDLLFLAGS, " ")); strarray_add(link_args, "-o"); strarray_add(link_args, strmake("%s.so", output_file)); for ( j = 0 ; j < opts->linker_args->size ; j++ ) strarray_add(link_args, opts->linker_args->base[j]); #ifdef __APPLE__ if (opts->image_base) { strarray_add(link_args, "-image_base"); strarray_add(link_args, opts->image_base); } #endif for ( j = 0; j < lib_dirs->size; j++ ) strarray_add(link_args, strmake("-L%s", lib_dirs->base[j])); strarray_add(link_args, spec_o_name); for ( j = 0; j < files->size; j++ ) { const char* name = files->base[j] + 2; switch(files->base[j][1]) { case 'l': case 's': strarray_add(link_args, strmake("-l%s", name)); break; case 'a': case 'o': strarray_add(link_args, name); break; } } if (!opts->nostdlib) { strarray_add(link_args, "-lm"); strarray_add(link_args, "-lc"); } spawn(opts->prefix, link_args, 0); /* set the base address */ if (opts->image_base) { const char *prelink = PRELINK; if (prelink[0] && strcmp(prelink,"false")) { strarray *prelink_args = strarray_alloc(); strarray_add(prelink_args, prelink); strarray_add(prelink_args, "--reloc-only"); strarray_add(prelink_args, opts->image_base); strarray_add(prelink_args, strmake("%s.so", output_file)); spawn(opts->prefix, prelink_args, 1); strarray_free(prelink_args); } } /* create the loader script */ if (generate_app_loader) { if (strendswith(output_file, ".exe")) output_file[strlen(output_file) - 4] = 0; create_file(output_file, 0755, app_loader_template, strmake("%s.exe.so", output_name)); } }
fz_error pdf_load_windows_font(pdf_xref *xref, pdf_font_desc *font, char *fontname) { fz_error error; pdf_windows_fontmap *found = NULL; char *comma; if (xref->win_fontlist->len == 0) pdf_create_windows_fontlist(xref); if (xref->win_fontlist->len == 0) return !fz_okay; if (getenv("MULOG")) printf("pdf_load_windows_font: looking for font '%s'\n", fontname); // work on a normalized copy of the font name fontname = fz_strdup(xref->ctx, fontname); removespaces(fontname); // first, try to find the exact font name (including appended style information) comma = strchr(fontname, ','); if (comma) { *comma = '-'; found = pdf_find_windows_font_path(xref, fontname); *comma = ','; } // second, substitute the font name with a known PostScript name else { int i; for (i = 0; i < _countof(baseSubstitutes) && !found; i++) if (!strcmp(fontname, baseSubstitutes[i].name)) found = pdf_find_windows_font_path(xref, baseSubstitutes[i].pattern); } // third, search for the font name without additional style information if (!found) found = pdf_find_windows_font_path(xref, fontname); // fourth, try to separate style from basename for prestyled fonts (e.g. "ArialBold") if (!found && !comma && (strendswith(fontname, "Bold") || strendswith(fontname, "Italic"))) { int styleLen = strendswith(fontname, "Bold") ? 4 : strendswith(fontname, "BoldItalic") ? 10 : 6; fontname = fz_realloc(xref->ctx, fontname, (strlen(fontname) + 2) * sizeof(char)); comma = fontname + strlen(fontname) - styleLen; memmove(comma + 1, comma, styleLen + 1); *comma = '-'; found = pdf_find_windows_font_path(xref, fontname); *comma = ','; if (!found) found = pdf_find_windows_font_path(xref, fontname); } if (found && (!strcmp(fontname, "Symbol") || !strcmp(fontname, "ZapfDingbats"))) font->flags |= PDF_FD_SYMBOLIC; fz_free(xref->ctx, fontname); if (!found) return !fz_okay; error = fz_new_font_from_file(xref->ctx, &font->font, found->fontpath, found->index); if (error) return fz_error_note(xref->ctx, error, "cannot load freetype font from a file %s", found->fontpath); font->font->ft_file = fz_strdup(xref->ctx, found->fontpath); if (getenv("MULOG")) printf("pdf_load_windows_font: loading font from '%s'\n", found->fontpath); return fz_okay; }
/* output the resources into a .o file */ void output_res_o_file( DLLSPEC *spec ) { unsigned int i; char *res_file = NULL; int fd; struct strarray *args; if (!spec->nb_resources) fatal_error( "--resources mode needs at least one resource file as input\n" ); if (!output_file_name) fatal_error( "No output file name specified\n" ); qsort( spec->resources, spec->nb_resources, sizeof(*spec->resources), cmp_res ); remove_duplicate_resources( spec ); byte_swapped = 0; init_output_buffer(); put_dword( 0 ); /* ResSize */ put_dword( 32 ); /* HeaderSize */ put_word( 0xffff ); /* ResType */ put_word( 0x0000 ); put_word( 0xffff ); /* ResName */ put_word( 0x0000 ); put_dword( 0 ); /* DataVersion */ put_word( 0 ); /* Memory options */ put_word( 0 ); /* Language */ put_dword( 0 ); /* Version */ put_dword( 0 ); /* Characteristics */ for (i = 0; i < spec->nb_resources; i++) { unsigned int header_size = get_resource_header_size( &spec->resources[i] ); put_dword( spec->resources[i].data_size ); put_dword( (header_size + 3) & ~3 ); put_string( &spec->resources[i].type ); put_string( &spec->resources[i].name ); align_output( 4 ); put_dword( 0 ); put_word( spec->resources[i].mem_options ); put_word( spec->resources[i].lang ); put_dword( spec->resources[i].version ); put_dword( 0 ); put_data( spec->resources[i].data, spec->resources[i].data_size ); align_output( 4 ); } /* if the output file name is a .res too, don't run the results through windres */ if (strendswith( output_file_name, ".res")) { flush_output_buffer(); return; } res_file = get_temp_file_name( output_file_name, ".res" ); if ((fd = open( res_file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600 )) == -1) fatal_error( "Cannot create %s\n", res_file ); if (write( fd, output_buffer, output_buffer_pos ) != output_buffer_pos) fatal_error( "Error writing to %s\n", res_file ); close( fd ); free( output_buffer ); args = find_tool( "windres", NULL ); strarray_add( args, "-i", res_file, "-o", output_file_name, NULL ); spawn( args ); strarray_free( args ); output_file_name = NULL; /* so we don't try to assemble it */ }
bool check_model_path(const char *path) { return strendswith(path, MDL_EXTENSION); }