OverlaplessUnion::OverlaplessUnion() { add_opt("ou-move", "Move blocks from other to target", false); add_opt("ou-filter", "Do not copy good blocks to target, " "but remove bad blocks from other", false); add_opt_check(boost::bind(check_ou, this, _1)); declare_bs("target", "Destination of blocks addition"); declare_bs("other", "Source of blocks addition"); }
static int create_cmd(int argc, char *argv[]) { struct option opts[toc_entries_len + 1]; unsigned long long toc_flags = 0; int i; if (argc < 2) usage(); i = fill_common_opts(opts, required_argument); add_opt(opts, i, "plat-toc-flags", required_argument, OPT_PLAT_TOC_FLAGS); add_opt(opts, ++i, NULL, 0, 0); while (1) { int c, opt_index; c = getopt_long(argc, argv, "o:", opts, &opt_index); if (c == -1) break; switch (c) { case OPT_TOC_ENTRY: { toc_entry_t *toc_entry; toc_entry = &toc_entries[opt_index]; toc_entry->action = DO_PACK; toc_entry->action_arg = strdup(optarg); if (toc_entry->action_arg == NULL) log_err("strdup"); break; } case OPT_PLAT_TOC_FLAGS: parse_plat_toc_flags(optarg, &toc_flags); break; default: usage(); } } argc -= optind; argv += optind; if (argc == 0) usage(); update_fip(); pack_images(argv[0], toc_flags); free_images(); return 0; }
void FeConfigContext::add_optl( int t, const std::string &s, const std::string &v, const std::string &h ) { std::string ss; fe_settings.get_resource( s, ss ); add_opt( t, ss, v, h ); }
static struct option *fill_common_opts(struct option *opts, size_t *nr_opts, int has_arg) { image_desc_t *desc; for (desc = image_desc_head; desc != NULL; desc = desc->next) opts = add_opt(opts, nr_opts, desc->cmdline_name, has_arg, OPT_TOC_ENTRY); return opts; }
int fuse_opt_add_opt(char **opts, const char *opt) { int ret; if (opt == NULL || opt[0] == '\0') return (-1); ret = add_opt(opts, opt); return (ret); }
void opt_register_table(const struct opt_table entry[], const char *desc) { unsigned int i, start = opt_count; if (desc) { struct opt_table heading = OPT_SUBTABLE(NULL, desc); add_opt(&heading); } for (i = 0; entry[i].type != OPT_END; i++) { if (entry[i].type == OPT_SUBTABLE) opt_register_table(subtable_of(&entry[i]), entry[i].desc); else { check_opt(&entry[i]); add_opt(&entry[i]); } } /* We store the table length in arg ptr. */ if (desc) opt_table[start].arg = (void *)(intptr_t)(opt_count - start); }
int main(int argc, char *argv[]) { int mntflags = 0; int ch; char *opts = NULL; int rv = 0; while ((ch = getopt(argc, argv, "o:")) != -1) { switch (ch) { case 'o': for (char *opt = optarg; (opt = strtok(opt, ",")) != NULL; opt = NULL) { if (strcmp(opt, "getargs") == 0) { mntflags |= MNT_GETARGS; break; /* No need to parse it any further. */ } else { add_opt(&opts, opt); } } break; default: rv = usage(); goto free_opts; } } argc -= optind; argv += optind; if (argc != 2) { rv = usage(); goto free_opts; } if (mntflags & MNT_GETARGS) { /* Special case for -o getargs: retrieve kernel arguments for * an already mounted filesystem. */ rv = show_puffs_mount_args(argv[1]); } else { /* Split the program name and source. This is to allow * filesystems to be mounted via "mount -a" i.e. /etc/fstab */ char *source = argv[0]; char *program = strsep(&source, "#"); rv = mount_puffs_filesystem(program, opts, source, argv[1]); } free_opts: free(opts); return rv; }
int fuse_opt_add_opt_escaped(char **opts, const char *opt) { size_t size = 0, escaped = 0; const char *s = opt; char *escaped_opt, *p; int ret; if (opt == NULL || opt[0] == '\0') return (-1); while (*s) { /* malloc(size + escaped) overflow check */ if (size >= (SIZE_T_MAX / 2)) return (-1); if (*s == ',' || *s == '\\') escaped++; s++; size++; } if (escaped > 0) { escaped_opt = malloc(size + escaped); if (escaped_opt == NULL) return (-1); s = opt; p = escaped_opt; while (*s) { switch (*s) { case ',': case '\\': *p++ = '\\'; /* FALLTHROUGH */ default: *p++ = *s++; } } *p = '\0'; } else { escaped_opt = strdup(opt); if (escaped_opt == NULL) return (-1); } ret = add_opt(opts, escaped_opt); free(escaped_opt); return (ret); }
static int call_proc(struct fuse_opt_context *ctx, const char *arg, int key, int iso) { if (key == FUSE_OPT_KEY_DISCARD) return 0; if (key != FUSE_OPT_KEY_KEEP && ctx->proc) { int res = ctx->proc(ctx->data, arg, key, &ctx->outargs); if (res == -1 || !res) return res; } if (iso) return add_opt(ctx, arg); else return add_arg(ctx, arg); }
void _opt_register(const char *names, enum opt_type type, char *(*cb)(void *arg), char *(*cb_arg)(const char *optarg, void *arg), void (*show)(char buf[OPT_SHOW_LEN], const void *arg), void *arg, const char *desc) { struct opt_table opt; opt.names = names; opt.type = type; opt.cb = cb; opt.cb_arg = cb_arg; opt.show = show; opt.arg = arg; opt.desc = desc; check_opt(&opt); add_opt(&opt); }
int get_opt(char **av, char *l_opt) { int opt; int i; int j; i = -1; opt = 0; while (av[++i]) { j = 0; if (av[i][0] == '-' && av[i][1] != '\0' && !ft_isdigit(av[i][1])) { while (av[i][++j]) opt = add_opt(position_in_opt(l_opt, av[i][j]), opt); } } return (opt); }
static int update_cmd(int argc, char *argv[]) { struct option opts[toc_entries_len + 2]; char outfile[FILENAME_MAX] = { 0 }; fip_toc_header_t toc_header = { 0 }; unsigned long long toc_flags = 0; int pflag = 0; int i; if (argc < 2) usage(); i = fill_common_opts(opts, required_argument); add_opt(opts, i, "out", required_argument, 'o'); add_opt(opts, ++i, "plat-toc-flags", required_argument, OPT_PLAT_TOC_FLAGS); add_opt(opts, ++i, NULL, 0, 0); while (1) { int c, opt_index; c = getopt_long(argc, argv, "o:", opts, &opt_index); if (c == -1) break; switch (c) { case OPT_TOC_ENTRY: { toc_entry_t *toc_entry; toc_entry = &toc_entries[opt_index]; toc_entry->action = DO_PACK; toc_entry->action_arg = strdup(optarg); if (toc_entry->action_arg == NULL) log_err("strdup"); break; } case OPT_PLAT_TOC_FLAGS: { parse_plat_toc_flags(optarg, &toc_flags); pflag = 1; break; } case 'o': snprintf(outfile, sizeof(outfile), "%s", optarg); break; default: usage(); } } argc -= optind; argv += optind; if (argc == 0) usage(); if (outfile[0] == '\0') snprintf(outfile, sizeof(outfile), "%s", argv[0]); if (access(outfile, F_OK) == 0) parse_fip(argv[0], &toc_header); if (pflag) toc_header.flags &= ~(0xffffULL << 32); toc_flags = (toc_header.flags |= toc_flags); update_fip(); pack_images(outfile, toc_flags); free_images(); return 0; }
ExternalAligner::ExternalAligner() { add_opt("aligner-cmd", "Template of command for external aligner", std::string(), true); }
static int update_cmd(int argc, char *argv[]) { struct option *opts = NULL; size_t nr_opts = 0; char outfile[PATH_MAX] = { 0 }; fip_toc_header_t toc_header = { 0 }; unsigned long long toc_flags = 0; unsigned long align = 1; int pflag = 0; if (argc < 2) update_usage(); opts = fill_common_opts(opts, &nr_opts, required_argument); opts = add_opt(opts, &nr_opts, "align", required_argument, OPT_ALIGN); opts = add_opt(opts, &nr_opts, "blob", required_argument, 'b'); opts = add_opt(opts, &nr_opts, "out", required_argument, 'o'); opts = add_opt(opts, &nr_opts, "plat-toc-flags", required_argument, OPT_PLAT_TOC_FLAGS); opts = add_opt(opts, &nr_opts, NULL, 0, 0); while (1) { int c, opt_index = 0; c = getopt_long(argc, argv, "b:o:", opts, &opt_index); if (c == -1) break; switch (c) { case OPT_TOC_ENTRY: { image_desc_t *desc; desc = lookup_image_desc_from_opt(opts[opt_index].name); set_image_desc_action(desc, DO_PACK, optarg); break; } case OPT_PLAT_TOC_FLAGS: parse_plat_toc_flags(optarg, &toc_flags); pflag = 1; break; case 'b': { char name[_UUID_STR_LEN + 1]; char filename[PATH_MAX] = { 0 }; uuid_t uuid = { 0 }; image_desc_t *desc; parse_blob_opt(optarg, &uuid, filename, sizeof(filename)); if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 || filename[0] == '\0') update_usage(); desc = lookup_image_desc_from_uuid(&uuid); if (desc == NULL) { uuid_to_str(name, sizeof(name), &uuid); desc = new_image_desc(&uuid, name, "blob"); add_image_desc(desc); } set_image_desc_action(desc, DO_PACK, filename); break; } case OPT_ALIGN: align = get_image_align(optarg); break; case 'o': snprintf(outfile, sizeof(outfile), "%s", optarg); break; default: update_usage(); } } argc -= optind; argv += optind; free(opts); if (argc == 0) update_usage(); if (outfile[0] == '\0') snprintf(outfile, sizeof(outfile), "%s", argv[0]); if (access(argv[0], F_OK) == 0) parse_fip(argv[0], &toc_header); if (pflag) toc_header.flags &= ~(0xffffULL << 32); toc_flags = (toc_header.flags |= toc_flags); update_fip(); pack_images(outfile, toc_flags, align); return 0; }
static int unpack_cmd(int argc, char *argv[]) { struct option *opts = NULL; size_t nr_opts = 0; char outdir[PATH_MAX] = { 0 }; image_desc_t *desc; int fflag = 0; int unpack_all = 1; if (argc < 2) unpack_usage(); opts = fill_common_opts(opts, &nr_opts, required_argument); opts = add_opt(opts, &nr_opts, "blob", required_argument, 'b'); opts = add_opt(opts, &nr_opts, "force", no_argument, 'f'); opts = add_opt(opts, &nr_opts, "out", required_argument, 'o'); opts = add_opt(opts, &nr_opts, NULL, 0, 0); while (1) { int c, opt_index = 0; c = getopt_long(argc, argv, "b:fo:", opts, &opt_index); if (c == -1) break; switch (c) { case OPT_TOC_ENTRY: { image_desc_t *desc; desc = lookup_image_desc_from_opt(opts[opt_index].name); set_image_desc_action(desc, DO_UNPACK, optarg); unpack_all = 0; break; } case 'b': { char name[_UUID_STR_LEN + 1]; char filename[PATH_MAX] = { 0 }; uuid_t uuid = { 0 }; image_desc_t *desc; parse_blob_opt(optarg, &uuid, filename, sizeof(filename)); if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 || filename[0] == '\0') unpack_usage(); desc = lookup_image_desc_from_uuid(&uuid); if (desc == NULL) { uuid_to_str(name, sizeof(name), &uuid); desc = new_image_desc(&uuid, name, "blob"); add_image_desc(desc); } set_image_desc_action(desc, DO_UNPACK, filename); unpack_all = 0; break; } case 'f': fflag = 1; break; case 'o': snprintf(outdir, sizeof(outdir), "%s", optarg); break; default: unpack_usage(); } } argc -= optind; argv += optind; free(opts); if (argc == 0) unpack_usage(); parse_fip(argv[0], NULL); if (outdir[0] != '\0') if (chdir(outdir) == -1) log_err("chdir %s", outdir); /* Unpack all specified images. */ for (desc = image_desc_head; desc != NULL; desc = desc->next) { char file[PATH_MAX]; image_t *image = desc->image; if (!unpack_all && desc->action != DO_UNPACK) continue; /* Build filename. */ if (desc->action_arg == NULL) snprintf(file, sizeof(file), "%s.bin", desc->cmdline_name); else snprintf(file, sizeof(file), "%s", desc->action_arg); if (image == NULL) { if (!unpack_all) log_warnx("%s does not exist in %s", file, argv[0]); continue; } if (access(file, F_OK) != 0 || fflag) { if (verbose) log_dbgx("Unpacking %s", file); write_image_to_file(image, file); } else { log_warnx("File %s already exists, use --force to overwrite it", file); } } return 0; }
static int remove_cmd(int argc, char *argv[]) { struct option opts[toc_entries_len + 2]; char outfile[FILENAME_MAX] = { 0 }; fip_toc_header_t toc_header; toc_entry_t *toc_entry; int fflag = 0; int i; if (argc < 2) usage(); i = fill_common_opts(opts, no_argument); add_opt(opts, i, "force", no_argument, 'f'); add_opt(opts, ++i, "out", required_argument, 'o'); add_opt(opts, ++i, NULL, 0, 0); while (1) { int c, opt_index; c = getopt_long(argc, argv, "fo:", opts, &opt_index); if (c == -1) break; switch (c) { case OPT_TOC_ENTRY: toc_entry = &toc_entries[opt_index]; toc_entry->action = DO_REMOVE; break; case 'f': fflag = 1; break; case 'o': snprintf(outfile, sizeof(outfile), "%s", optarg); break; default: usage(); } } argc -= optind; argv += optind; if (argc == 0) usage(); if (outfile[0] != '\0' && access(outfile, F_OK) == 0 && !fflag) log_errx("File %s already exists, use --force to overwrite it", outfile); if (outfile[0] == '\0') snprintf(outfile, sizeof(outfile), "%s", argv[0]); parse_fip(argv[0], &toc_header); for (toc_entry = toc_entries; toc_entry->cmdline_name != NULL; toc_entry++) { if (toc_entry->action != DO_REMOVE) continue; if (toc_entry->image != NULL) { if (verbose) log_dbgx("Removing %s.bin", toc_entry->cmdline_name); remove_image(toc_entry->image); } else { log_warnx("Requested image %s.bin is not in %s", toc_entry->cmdline_name, argv[0]); } } pack_images(outfile, toc_header.flags); free_images(); return 0; }
static int remove_cmd(int argc, char *argv[]) { struct option *opts = NULL; size_t nr_opts = 0; char outfile[PATH_MAX] = { 0 }; fip_toc_header_t toc_header; image_desc_t *desc; unsigned long align = 1; int fflag = 0; if (argc < 2) remove_usage(); opts = fill_common_opts(opts, &nr_opts, no_argument); opts = add_opt(opts, &nr_opts, "align", required_argument, OPT_ALIGN); opts = add_opt(opts, &nr_opts, "blob", required_argument, 'b'); opts = add_opt(opts, &nr_opts, "force", no_argument, 'f'); opts = add_opt(opts, &nr_opts, "out", required_argument, 'o'); opts = add_opt(opts, &nr_opts, NULL, 0, 0); while (1) { int c, opt_index = 0; c = getopt_long(argc, argv, "b:fo:", opts, &opt_index); if (c == -1) break; switch (c) { case OPT_TOC_ENTRY: { image_desc_t *desc; desc = lookup_image_desc_from_opt(opts[opt_index].name); set_image_desc_action(desc, DO_REMOVE, NULL); break; } case OPT_ALIGN: align = get_image_align(optarg); break; case 'b': { char name[_UUID_STR_LEN + 1], filename[PATH_MAX]; uuid_t uuid = { 0 }; image_desc_t *desc; parse_blob_opt(optarg, &uuid, filename, sizeof(filename)); if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0) remove_usage(); desc = lookup_image_desc_from_uuid(&uuid); if (desc == NULL) { uuid_to_str(name, sizeof(name), &uuid); desc = new_image_desc(&uuid, name, "blob"); add_image_desc(desc); } set_image_desc_action(desc, DO_REMOVE, NULL); break; } case 'f': fflag = 1; break; case 'o': snprintf(outfile, sizeof(outfile), "%s", optarg); break; default: remove_usage(); } } argc -= optind; argv += optind; free(opts); if (argc == 0) remove_usage(); if (outfile[0] != '\0' && access(outfile, F_OK) == 0 && !fflag) log_errx("File %s already exists, use --force to overwrite it", outfile); if (outfile[0] == '\0') snprintf(outfile, sizeof(outfile), "%s", argv[0]); parse_fip(argv[0], &toc_header); for (desc = image_desc_head; desc != NULL; desc = desc->next) { if (desc->action != DO_REMOVE) continue; if (desc->image != NULL) { if (verbose) log_dbgx("Removing %s", desc->cmdline_name); free(desc->image); desc->image = NULL; } else { log_warnx("%s does not exist in %s", desc->cmdline_name, argv[0]); } } pack_images(outfile, toc_header.flags, align); return 0; }
/* return the encoded data in *pbuf and the size. Return < 0 if error */ int jctvc_encode_picture(uint8_t **pbuf, Image *img, const HEVCEncodeParams *params) { TAppEncTop cTAppEncTop; int argc; char *argv[ARGV_MAX + 1]; char buf[1024], infilename[1024], outfilename[1024]; const char *str; FILE *f; uint8_t *out_buf; int out_buf_len, i; #ifdef WIN32 if (GetTempPath(sizeof(buf), buf) > sizeof(buf) - 1) { fprintf(stderr, "Temporary path too long\n"); return -1; } #else strcpy(buf, "/tmp/"); #endif snprintf(infilename, sizeof(infilename), "%sout%d.yuv", buf, getpid()); snprintf(outfilename, sizeof(outfilename), "%sout%d.bin", buf, getpid()); save_yuv(img, infilename); m_gcAnalyzeAll.clear(); m_gcAnalyzeI.clear(); m_gcAnalyzeP.clear(); m_gcAnalyzeB.clear(); m_gcAnalyzeAll_in.clear(); cTAppEncTop.create(); argc = 0; add_opt(&argc, argv, "jctvc"); /* dummy executable name */ snprintf(buf, sizeof(buf),"--InputFile=%s", infilename); add_opt(&argc, argv, buf); snprintf(buf, sizeof(buf),"--BitstreamFile=%s", outfilename); add_opt(&argc, argv, buf); snprintf(buf, sizeof(buf),"--SourceWidth=%d", img->w); add_opt(&argc, argv, buf); snprintf(buf, sizeof(buf),"--SourceWidth=%d", img->w); add_opt(&argc, argv, buf); snprintf(buf, sizeof(buf),"--SourceHeight=%d", img->h); add_opt(&argc, argv, buf); snprintf(buf, sizeof(buf),"--InputBitDepth=%d", img->bit_depth); add_opt(&argc, argv, buf); switch(img->format) { case BPG_FORMAT_GRAY: str = "400"; break; case BPG_FORMAT_420: str = "420"; break; case BPG_FORMAT_422: str = "422"; break; case BPG_FORMAT_444: str = "444"; break; default: abort(); } snprintf(buf, sizeof(buf),"--InputChromaFormat=%s", str); add_opt(&argc, argv, buf); snprintf(buf, sizeof(buf),"--QP=%d", params->qp); add_opt(&argc, argv, buf); snprintf(buf, sizeof(buf),"--SEIDecodedPictureHash=%d", params->sei_decoded_picture_hash); add_opt(&argc, argv, buf); if (!params->verbose) add_opt(&argc, argv, "--Verbose=0"); /* single frame */ add_opt(&argc, argv, "--FramesToBeEncoded=1"); /* no padding necessary (it is done before) */ add_opt(&argc, argv, "--ConformanceWindowMode=0"); /* dummy frame rate */ add_opt(&argc, argv, "--FrameRate=25"); /* general config */ add_opt(&argc, argv, "--Profile=main_444_16_intra"); add_opt(&argc, argv, "--QuadtreeTULog2MaxSize=5"); add_opt(&argc, argv, "--QuadtreeTUMaxDepthIntra=3"); add_opt(&argc, argv, "--IntraPeriod=1"); add_opt(&argc, argv, "--GOPSize=1"); add_opt(&argc, argv, "--TransformSkip=1"); add_opt(&argc, argv, "--TransformSkipFast=1"); /* Note: Format Range extension */ if (img->format == BPG_FORMAT_444) { add_opt(&argc, argv, "--CrossComponentPrediction=1"); } if (params->lossless) { add_opt(&argc, argv, "--CostMode=lossless"); add_opt(&argc, argv, "--SAO=0"); add_opt(&argc, argv, "--LoopFilterDisable"); add_opt(&argc, argv, "--TransquantBypassEnableFlag"); add_opt(&argc, argv, "--CUTransquantBypassFlagForce"); add_opt(&argc, argv, "--ImplicitResidualDPCM"); add_opt(&argc, argv, "--GolombRiceParameterAdaptation"); add_opt(&argc, argv, "--HadamardME=0"); } /* trailing NULL */ argv[argc] = NULL; if (params->verbose >= 2) { int i; printf("Encode options:"); for(i = 0; i < argc; i++) { printf(" %s", argv[i]); } printf("\n"); } if(!cTAppEncTop.parseCfg( argc, argv )) { fprintf(stderr, "Error while parsing options\n"); cTAppEncTop.destroy(); return -1; } cTAppEncTop.encode(); cTAppEncTop.destroy(); for(i = 0; i < argc; i++) free(argv[i]); unlink(infilename); /* read output bitstream */ f = fopen(outfilename, "rb"); if (!f) { fprintf(stderr, "Could not open '%s'\n", outfilename); return -1; } fseek(f, 0, SEEK_END); out_buf_len = ftell(f); fseek(f, 0, SEEK_SET); out_buf = (uint8_t *)malloc(out_buf_len); if (fread(out_buf, 1, out_buf_len, f) != out_buf_len) { fprintf(stderr, "read error\n"); fclose(f); free(out_buf); return -1; } fclose(f); unlink(outfilename); *pbuf = out_buf; return out_buf_len; }
void rdp_connect(GtkButton *connect, gpointer erdp) { /*get the string info*/ GtkEntry *rip = (GtkEntry *) find_child(erdp, "address"); GtkEntry *ruser = (GtkEntry *) find_child(erdp, "user"); GtkEntry *rpass = (GtkEntry *) find_child(erdp, "pass"); GtkEntry *arguments = (GtkEntry *) find_child(erdp, "arguments"); GtkCheckButton *fullscreen = (GtkCheckButton *) find_child(erdp, "fullscreen"); GtkCheckButton *decorations = (GtkCheckButton *) find_child(erdp, "decorations"); GtkCheckButton *smartscaling = (GtkCheckButton *) find_child(erdp, "smartscaling"); GtkCheckButton *sound = (GtkCheckButton *) find_child(erdp, "sound"); GtkCheckButton *clipboard = (GtkCheckButton *) find_child(erdp, "clipboard"); GtkCheckButton *homedir = (GtkCheckButton *) find_child(erdp, "homedir"); char *xfreerdp = find_executable("xfreerdp"); printf("Xfreerdp path: %s\n", xfreerdp); /*format my strings correctly*/ char *fip = g_strconcat("/v:", gtk_entry_get_text(rip), NULL); char *fuser = g_strconcat("/u:", gtk_entry_get_text(ruser), NULL); char *fpass = g_strconcat("/p:", gtk_entry_get_text(rpass), NULL); /*check to see if the connection is valid*/ if(check_connect(fip, fuser, fpass) != TRUE) { return; } /*check what options to add to rdp from the options tickboxes*/ char **opts = malloc(sizeof(char *)); opts[0] = NULL; opts = add_opt(&opts, xfreerdp); opts = add_opt(&opts, "/cert-ignore"); opts = add_opt(&opts, "/auto-reconnect"); opts = add_opt(&opts, fip); opts = add_opt(&opts, fuser); opts = add_opt(&opts, fpass); if(gtk_toggle_button_get_active((GtkToggleButton*)fullscreen) == TRUE) { opts = add_opt(&opts, "/f"); } if(gtk_toggle_button_get_active((GtkToggleButton*)decorations) == TRUE) { opts = add_opt(&opts, "/disp"); opts = add_opt(&opts, "/fonts"); opts = add_opt(&opts, "/aero"); opts = add_opt(&opts, "/window-drag"); opts = add_opt(&opts, "/menu-anims"); } if(gtk_toggle_button_get_active((GtkToggleButton*)smartscaling) == TRUE) { GdkRectangle *workarea = g_new(GdkRectangle, 1); GdkScreen *screen = gdk_screen_get_default(); gint monitor = gdk_screen_get_primary_monitor(screen); gdk_screen_get_monitor_workarea(screen, monitor, workarea); int width = workarea->width; int height = workarea->height; char sizebuff[32]; snprintf(sizebuff, 31, "/size:%dx%d", width, height); opts = add_opt(&opts, sizebuff); snprintf(sizebuff, 31, "/smart-sizing:%dx%d", width, height); opts = add_opt(&opts, sizebuff); } if(gtk_toggle_button_get_active((GtkToggleButton*)sound) == TRUE) { opts = add_opt(&opts, "/sound"); } if(gtk_toggle_button_get_active((GtkToggleButton*)clipboard) == TRUE) { opts = add_opt(&opts, "/clipboard"); } if(gtk_toggle_button_get_active((GtkToggleButton*)homedir) == TRUE) { opts = add_opt(&opts, "/home-drive"); } /* add the user specified options. We do no error checking */ char *argtext = strdup(gtk_entry_get_text(arguments)); char *argbuff = strtok(argtext, " "); while(argbuff != NULL) { opts = add_opt(&opts, argbuff); strtok(NULL, " "); } /*and call xfreerdp*/ int i; printf("Calling: "); for(i=0; opts[i] != NULL; i++) { if(strncmp(opts[i], "/p:", 3) == 0) { printf("/p:**** "); continue; } printf("%s ", opts[i]); } printf("\n"); execv(xfreerdp, opts); /*code never gets here*/ return; }
int fuse_opt_add_opt_escaped(char **opts, const char *opt) { DPRINTF(("%s: arguments passed: [opts=%s] [opt=%s]\n", __func__, *opts, opt)); return add_opt(opts, opt, true); }
static int unpack_cmd(int argc, char *argv[]) { struct option opts[toc_entries_len + 3]; char file[FILENAME_MAX], outdir[PATH_MAX] = { 0 }; toc_entry_t *toc_entry; int fflag = 0; int unpack_all = 1; int i; if (argc < 2) usage(); i = fill_common_opts(opts, required_argument); add_opt(opts, i, "force", no_argument, 'f'); add_opt(opts, ++i, "out", required_argument, 'o'); add_opt(opts, ++i, NULL, 0, 0); while (1) { int c, opt_index; c = getopt_long(argc, argv, "fo:", opts, &opt_index); if (c == -1) break; switch (c) { case OPT_TOC_ENTRY: unpack_all = 0; toc_entry = &toc_entries[opt_index]; toc_entry->action = DO_UNPACK; toc_entry->action_arg = strdup(optarg); if (toc_entry->action_arg == NULL) log_err("strdup"); break; case 'f': fflag = 1; break; case 'o': snprintf(outdir, sizeof(outdir), "%s", optarg); break; default: usage(); } } argc -= optind; argv += optind; if (argc == 0) usage(); parse_fip(argv[0], NULL); if (outdir[0] != '\0') if (chdir(outdir) == -1) log_err("chdir %s", outdir); /* Mark all images to be unpacked. */ if (unpack_all) { for (toc_entry = toc_entries; toc_entry->cmdline_name != NULL; toc_entry++) { if (toc_entry->image != NULL) { toc_entry->action = DO_UNPACK; toc_entry->action_arg = NULL; } } } /* Unpack all specified images. */ for (toc_entry = toc_entries; toc_entry->cmdline_name != NULL; toc_entry++) { if (toc_entry->action != DO_UNPACK) continue; /* Build filename. */ if (toc_entry->action_arg == NULL) snprintf(file, sizeof(file), "%s.bin", toc_entry->cmdline_name); else snprintf(file, sizeof(file), "%s", toc_entry->action_arg); if (toc_entry->image == NULL) { log_warnx("Requested image %s is not in %s", file, argv[0]); free(toc_entry->action_arg); toc_entry->action_arg = NULL; continue; } if (access(file, F_OK) != 0 || fflag) { if (verbose) log_dbgx("Unpacking %s", file); write_image_to_file(toc_entry->image, file); } else { log_warnx("File %s already exists, use --force to overwrite it", file); } free(toc_entry->action_arg); toc_entry->action_arg = NULL; } free_images(); return 0; }
/* create or wait for an NFS-safe lockfile and fetch url with curl or wget */ int fetch(char *url, const char *destdir) { int lockfd, status=0; char outfile[PATH_MAX], partfile[PATH_MAX]; char *name, *p; struct flock fl = { .l_type = F_WRLCK, .l_whence = SEEK_SET, .l_start = 1, .l_len = 0, }; struct cmdarray curlcmd = { .argc = 5, .argv = { "curl", "-L", "-f", "-o", partfile, NULL } }; struct cmdarray wgetcmd = { .argc = 3, .argv = { "wget", "-O", partfile, NULL } }; name = strrchr(url, '/'); if (name == NULL) errx(1, "%s: no '/' in url", url); p = strstr(url, "::"); if (p != NULL) { name = url; *p = '\0'; url = p + 2; } else { name++; } snprintf(outfile, sizeof(outfile), "%s/%s", destdir, name); snprintf(lockfile, sizeof(lockfile), "%s.lock", outfile); snprintf(partfile, sizeof(partfile), "%s.part", outfile); lockfd = open(lockfile, O_WRONLY|O_CREAT, 0660); if (lockfd < 0) err(1, "%s", lockfile); if (fcntl(lockfd, F_SETLK, &fl) < 0) { int i; printf("Waiting for %s ...\n", lockfile); for (i=0; i<10; i++) { int r = fcntl(lockfd, F_SETLKW, &fl); if (r == 0) break; if (r == -1 && errno != ESTALE) err(1, "fcntl(F_SETLKW)"); sleep(1); } } if (access(outfile, F_OK) == 0) goto fetch_done; if (access(partfile, F_OK) == 0) { printf("Partial download found. Trying to resume.\n"); add_opt(&curlcmd, "-C"); add_opt(&curlcmd, "-"); add_opt(&wgetcmd, "-c"); } add_opt(&curlcmd, url); add_opt(&wgetcmd, url); status = fork_exec(curlcmd.argv, 0); /* CURLE_RANGE_ERROR (33) The server does not support or accept range requests. */ if (status == 33) unlink(partfile); /* is we failed execute curl, then fallback to wget */ if (status == 201) status = fork_exec(wgetcmd.argv, 1); /* only rename completed downloads */ if (status == 0) rename(partfile, outfile); fetch_done: unlink(lockfile); close(lockfd); lockfile[0] = '\0'; return status; } void sighandler(int sig) { switch(sig) { case SIGABRT: case SIGINT: case SIGQUIT: case SIGTERM: unlink(lockfile); exit(0); break; default: break; } } /* exit codes get passed through from curl/wget (so we can check in abuild whether the server does not support resuming). Additional exit codes: 200: fork failed 201: curl/wget could not be started 202: curl/wget did not terminate normally 203: usage displayed */ int main(int argc, char *argv[]) { int opt; char *destdir = "/var/cache/distfiles"; program = argv[0]; while ((opt = getopt(argc, argv, "hd:")) != -1) { switch (opt) { case 'h': return usage(0); break; case 'd': destdir = optarg; break; default: printf("Unknown option '%c'\n", opt); return usage(1); break; } } argv += optind; argc -= optind; if (argc != 1) return usage(203); signal(SIGABRT, sighandler); signal(SIGINT, sighandler); signal(SIGQUIT, sighandler); signal(SIGTERM, sighandler); return fetch(argv[0], destdir); }