Esempio n. 1
0
File: edit.c Progetto: jff/mathspad
static void handle_view_filename(void *data, Char *name)
{
    EDITINFO *einf = (EDITINFO *) data;

    if (name) {
	FILE *f;
	int i;

	if (!(f = fopen((char*)UstrtoFilename(name),"rb"))) {
	    message2(MP_CLICKREMARK, translate("Unable to open file "), name);
	    free(name);
	    failure=MP_True;
	    return;
	}
	i=test_file(f);
	set_wait_cursor(einf->win_id);
	switch (i) {
	case BINDOC:
	    message(MP_MESSAGE, translate("Viewing ascii file."));
	    read_file(f,BINARYFILE);
	    unset_file();
	    load_editwindow(einf->info);
	    break;
	case OLDDOC:
	    i = edit_fnr;
	    edit_fnr = 0;
	    view_notation_filenames(f);
	    old_load_editwindow(einf->info,f);
	    edit_fnr = i;
	    break;
	case NEWDOC:
	    i = edit_fnr;
	    edit_fnr = 0;
	    read_file(f,DOCUMENTFILE);
	    unset_file();
	    load_editwindow(einf->info);
	    edit_fnr = i;
	    break;
	default: break;
	}
	fclose(f);
	cleanup_filestack();
	cleanup_stencilstack();
	cleanup_nodestack();
	einf->saved = MP_True;
	einf->auto_saved = MP_True;
	einf->view_mode = MP_True;
	set_name(einf, name);
	set_output_name(einf);
	remove_wait_cursor();
	return;
    }
    free(name);
}
Esempio n. 2
0
template_t::template_t(environment_t &env, const char *name, const char *output_name)
 :  env_(env),
    stdin_fp_(0),
    stdin_sb_(0),
    stdin_stream_(0),
    yaml_(0)
{
    if (name)
	set_template_name(name);
    if (output_name)
	set_output_name(output_name);
}
Esempio n. 3
0
void
do_rename(GtkTreeModel *model, GtkTreeIter *iter, const gchar *new_name)
{
    const gchar * ext;
    gchar *user_ext, *basename, *name_without_path, *p, *fixed_name,
      *file_name, *path, *polsarpro_aux_info;
    Settings * user_settings;

    user_settings = settings_get_from_gui();
    ext = settings_get_output_format_extension(user_settings);

    gtk_tree_model_get(model, iter, 
		       COL_INPUT_FILE, &file_name, 
		       COL_POLSARPRO_INFO, &polsarpro_aux_info, -1);
    int image_data_type = extract_image_data_type(polsarpro_aux_info);

    if (output_directory)
    {
        path = g_strdup(output_directory);
    }
    else
    {
        path = g_path_get_dirname(file_name);
        if (strcmp(path, ".") == 0)
        {
            *path = '\0';
        }
        else
        {
            int len = strlen(path);
            path = (gchar *) g_realloc(path, sizeof(gchar) * (len + 2));
            *(path + len) = DIR_SEPARATOR;
            *(path + len + 1) = '\0';
        }
    }

    g_free(file_name);
    g_free(polsarpro_aux_info);

    /* do not allow user to move output file to a different location */
    name_without_path = g_path_get_basename(new_name);

    /* replace illegal characters with _ */
    p = name_without_path;
    do
    {
        /* figure out a better way here */
        if (*p == '?' || isspace(*p) || *p == '>' || *p == '<' || *p == '|')
            *p = '_';
    }
    while (*p++);

    /* add appropriate extension if was not given by user */
    basename = g_strdup(name_without_path);
    p = findExt(basename);
    if (p)
    {
        *p = '\0';
        user_ext = p + 1;
    }
    else
    {
        user_ext = NULL;
    }

    if (user_ext == NULL)
    {
        int len = strlen(path) + strlen(basename) + strlen(ext) + 2;
        fixed_name = (gchar *) g_malloc( sizeof(gchar) * len );

	if (image_data_type == SELECT_POLARIMETRIC_MATRIX ||
	    image_data_type == SELECT_POLARIMETRIC_DECOMPOSITION)
	  g_snprintf(fixed_name, len, "%s%s", path, basename);
	else
	  g_snprintf(fixed_name, len, "%s%s.%s", path, basename, ext);
    }
    else if (strcmp(user_ext, ext) != 0)
    {
        int len = strlen(path) + strlen(name_without_path) + strlen(ext) + 2;
        fixed_name = (gchar *) g_malloc( sizeof(gchar) * len );

	if (image_data_type == SELECT_POLARIMETRIC_MATRIX ||
	    image_data_type == SELECT_POLARIMETRIC_DECOMPOSITION)
	  g_snprintf(fixed_name, len, "%s%s", path, name_without_path);
	else
	  g_snprintf(fixed_name, len, "%s%s.%s", path, name_without_path, ext);
    }
    else
    {
        int len = strlen(path) + strlen(name_without_path) + 2;
        fixed_name = (gchar *) g_malloc( sizeof(gchar) * len );

        g_snprintf(fixed_name, len, "%s%s", path, name_without_path);
    }

    g_free(basename);
    g_free(name_without_path);
    g_free(path);

    set_output_name(iter, fixed_name);

    g_free(fixed_name);
    settings_delete(user_settings);
}
Esempio n. 4
0
static int do_option(int optc, const char *arg)
{
    int i = 0;

    switch (optc)
    {
#if 0
    // FIXME: to_stdout doesn't work because of console code mess
    //case 'c':
    case 517:
        opt->to_stdout = true;
        break;
#endif
    case 'd':
        set_cmd(CMD_DECOMPRESS);
        break;
    case 'D':
        opt->debug.debug_level++;
        break;
    case 'f':
        opt->force++;
        break;
    case 909:
        set_cmd(CMD_FILEINFO);
        break;
    case 'h':
    case 'H':
    case '?':
        set_cmd(CMD_HELP);
        break;
    case 'h'+256:
#if 1
        if (!acc_isatty(STDOUT_FILENO))
        {
            /* according to GNU standards */
            set_term(stdout);
            opt->console = CON_FILE;
        }
#endif
        show_help(1);
        e_exit(EXIT_OK);
        break;
    case 'i':
        opt->info_mode++;
        break;
    case 'l':
        set_cmd(CMD_LIST);
        break;
    case 'L':
        set_cmd(CMD_LICENSE);
        break;
    case 'o':
        set_output_name(mfx_optarg,1);
        break;
    case 'q':
        opt->verbose = (opt->verbose > 1 ? 1 : opt->verbose - 1);
        break;
    case 't':
        set_cmd(CMD_TEST);
        break;
    case 'v':
        opt->verbose = (opt->verbose < 3 ? 3 : opt->verbose + 1);
        break;
    case 'V':
        set_cmd(CMD_VERSION);
        break;
    case 'V'+256:
        /* according to GNU standards */
        set_term(stdout);
        opt->console = CON_FILE;
        show_version(0);
        e_exit(EXIT_OK);
        break;

    // method
    case 702:
        opt->method_nrv2b_seen = true;
        if (!set_method(M_NRV2B_LE32, -1))
            e_method(M_NRV2B_LE32, opt->level);
        break;
    case 704:
        opt->method_nrv2d_seen = true;
        if (!set_method(M_NRV2D_LE32, -1))
            e_method(M_NRV2D_LE32, opt->level);
        break;
    case 705:
        opt->method_nrv2e_seen = true;
        if (!set_method(M_NRV2E_LE32, -1))
            e_method(M_NRV2E_LE32, opt->level);
        break;
    case 721:
        opt->method_lzma_seen = true;
        opt->all_methods_use_lzma = true;
        if (!set_method(M_LZMA, -1))
            e_method(M_LZMA, opt->level);
        break;
    case 722:
        opt->method_lzma_seen = false;
        opt->all_methods_use_lzma = false;
        if (M_IS_LZMA(opt->method))
            opt->method = -1;
        break;

    // compression level
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
        if (!set_method(-1, optc - '0'))
            e_method(opt->method, optc);
        break;

    case 902:                               // --ultra-brute
        opt->ultra_brute = true;
        /* fallthrough */
    case 901:                               // --brute
        opt->all_methods = true;
        opt->all_methods_use_lzma = true;
        opt->method = -1;
        opt->all_filters = true;
        opt->filter = -1;
        opt->crp.crp_ucl.m_size = 999999;
        /* fallthrough */
    case 900:                               // --best
        if (!set_method(-1, 10))
            e_method(opt->method, 10);
        break;

    // debug
    case 542:
        if (!mfx_optarg || strlen(mfx_optarg) != 4)
            e_optarg(arg);
        memcpy(opt->debug.fake_stub_version, mfx_optarg, 4);
        break;
    case 543:
        if (!mfx_optarg || strlen(mfx_optarg) != 4)
            e_optarg(arg);
        memcpy(opt->debug.fake_stub_year, mfx_optarg, 4);
        break;
    case 544:
        if (!mfx_optarg || !mfx_optarg[0])
            e_optarg(arg);
        opt->debug.dump_stub_loader = mfx_optarg;
        break;
    case 545:
        opt->debug.disable_random_id = true;
        break;

    // mp (meta)
    case 501:
        getoptvar(&opt->mp_compress_task, 1, 999999, arg);
        break;
    case 502:
        opt->mp_query_format = true;
        break;
    case 503:
        opt->mp_query_num_tasks = true;
        break;

    // misc
    case 512:
        opt->console = CON_FILE;
        break;
    case 513:
        opt->console = CON_ANSI_MONO;
        break;
    case 514:
        opt->console = CON_ANSI_COLOR;
        break;
    case 516:
        opt->no_progress = true;
        break;
    case 519:
        opt->no_env = true;
        break;
    case 526:
        opt->preserve_mode = false;
        break;
    case 527:
        opt->preserve_ownership = false;
        break;
    case 528:
        opt->preserve_timestamp = false;
        break;
    // compression settings
    case 520:                               // --small
        if (opt->small < 0)
            opt->small = 0;
        opt->small++;
        break;
    case 521:                               // --filter=
        getoptvar(&opt->filter, 0, 255, arg);
        opt->all_filters = false;
        break;
    case 522:                               // --no-filter
        opt->filter = 0;
        opt->all_filters = false;
        opt->no_filter = true;
        break;
    case 523:                               // --all-filters
        opt->all_filters = true;
        opt->filter = -1;
        break;
    case 524:                               // --all-methods
        opt->all_methods = true;
        opt->all_methods_use_lzma = true;
        opt->method = -1;
        break;
    case 525:                               // --exact
        opt->exact = true;
        break;
    // compression runtime parameters
    case 801:
        getoptvar(&opt->crp.crp_ucl.c_flags, 0, 3, arg);
        break;
    case 802:
        getoptvar(&opt->crp.crp_ucl.s_level, 0, 2, arg);
        break;
    case 803:
        getoptvar(&opt->crp.crp_ucl.h_level, 0, 1, arg);
        break;
    case 804:
        getoptvar(&opt->crp.crp_ucl.p_level, 0, 7, arg);
        break;
    case 805:
        getoptvar(&opt->crp.crp_ucl.max_offset, 256u, ~0u, arg);
        break;
    case 806:
        getoptvar(&opt->crp.crp_ucl.max_match, 16u, ~0u, arg);
        break;
    case 807:
        getoptvar(&opt->crp.crp_ucl.m_size, 10000u, 999999u, arg);
        break;
    case 811:
        getoptvar(&opt->crp.crp_lzma.pos_bits, arg);
        break;
    case 812:
        getoptvar(&opt->crp.crp_lzma.lit_pos_bits, arg);
        break;
    case 813:
        getoptvar(&opt->crp.crp_lzma.lit_context_bits, arg);
        break;
    case 814:
        getoptvar(&opt->crp.crp_lzma.dict_size, arg);
        break;
    case 816:
        getoptvar(&opt->crp.crp_lzma.num_fast_bytes, arg);
        break;
    case 821:
        getoptvar(&opt->crp.crp_zlib.mem_level, arg);
        break;
    case 822:
        getoptvar(&opt->crp.crp_zlib.window_bits, arg);
        break;
    case 823:
        getoptvar(&opt->crp.crp_zlib.strategy, arg);
        break;
    // backup
    case 'k':
        opt->backup = 1;
        break;
    case 541:
        if (opt->backup != 1)           // do not overide '--backup'
            opt->backup = 0;
        break;
    // overlay
    case 551:
        if (mfx_optarg && strcmp(mfx_optarg,"skip") == 0)
            opt->overlay = opt->SKIP_OVERLAY;
        else if (mfx_optarg && strcmp(mfx_optarg,"copy") == 0)
            opt->overlay = opt->COPY_OVERLAY;
        else if (mfx_optarg && strcmp(mfx_optarg,"strip") == 0)
            opt->overlay = opt->STRIP_OVERLAY;
        else
            e_optarg(arg);
        break;
    case 552:
        opt->overlay = opt->SKIP_OVERLAY;
        break;
    case 553:
        opt->overlay = opt->COPY_OVERLAY;
        break;
    case 554:
        opt->overlay = opt->STRIP_OVERLAY;
        break;
    // CPU
    case 560:
        if (mfx_optarg && strcmp(mfx_optarg,"8086") == 0)
            opt->cpu = opt->CPU_8086;
        else if (mfx_optarg && strcmp(mfx_optarg,"386") == 0)
            opt->cpu = opt->CPU_386;
        else if (mfx_optarg && strcmp(mfx_optarg,"486") == 0)
            opt->cpu = opt->CPU_486;
        else
            e_optarg(arg);
        break;
    case 561:
        opt->cpu = opt->CPU_8086;
        break;
    case 563:
        opt->cpu = opt->CPU_386;
        break;
    case 564:
        opt->cpu = opt->CPU_486;
        break;
    //
    case 600:
        opt->dos_exe.force_stub = true;
        break;
    case 601:
        opt->dos_exe.no_reloc = true;
        break;
    case 610:
        opt->djgpp2_coff.coff = true;
        break;
    case 620:
        opt->watcom_le.le = true;
        break;
    case 630:
        opt->win32_pe.compress_exports = 1;
        if (mfx_optarg && mfx_optarg[0])
            getoptvar(&opt->win32_pe.compress_exports, 0, 1, arg);
        //printf("compress_exports: %d\n", opt->win32_pe.compress_exports);
        break;
    case 631:
        opt->win32_pe.compress_icons = 1;
        if (mfx_optarg && mfx_optarg[0])
            getoptvar(&opt->win32_pe.compress_icons, 0, 3, arg);
        //printf("compress_icons: %d\n", opt->win32_pe.compress_icons);
        break;
    case 632:
        opt->win32_pe.compress_resources = 1;
        if (mfx_optarg && mfx_optarg[0])
            getoptvar(&opt->win32_pe.compress_resources, 0, 1, arg);
        //printf("compress_resources: %d\n", opt->win32_pe.compress_resources);
        break;
    case 633:
        // opt->win32_pe.strip_loadconf - OBSOLETE - IGNORED
        break;
    case 634:
        opt->win32_pe.strip_relocs = 1;
        if (mfx_optarg && mfx_optarg[0])
            getoptvar(&opt->win32_pe.strip_relocs, 0, 1, arg);
        //printf("strip_relocs: %d\n", opt->win32_pe.strip_relocs);
        break;
    case 635:
        if (!mfx_optarg || !mfx_optarg[0])
            e_optarg(arg);
        opt->win32_pe.keep_resource = mfx_optarg;
        break;
    case 650:
        opt->atari_tos.split_segments = true;
        break;
    case 660:
        getoptvar(&opt->o_unix.blocksize, 8192u, ~0u, arg);
        break;
    case 661:
        opt->o_unix.force_execve = true;
        break;
    case 662:
        opt->o_unix.script_name = "/usr/local/lib/upx/upxX";
        if (mfx_optarg && mfx_optarg[0])
            set_script_name(mfx_optarg, 1);
        break;
    case 663:
        opt->o_unix.is_ptinterp = true;
        break;
    case 664:
        opt->o_unix.use_ptinterp = true;
        break;
    case 665:
        opt->o_unix.make_ptinterp = true;
        break;
    case 666:  // Linux
        opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_LINUX;
        break;
    case 667:  // FreeBSD
        opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_FREEBSD;
        break;
    case 668:  // NetBSD
        opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_NETBSD;
        break;
    case 669:  // OpenBSD
        opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_OPENBSD;
        break;
    case 670:
        opt->ps1_exe.boot_only = true;
        break;
    case 671:
        opt->ps1_exe.no_align = true;
        opt->ps1_exe.boot_only = false;
        break;
    case 672:
        opt->ps1_exe.do_8bit = true;
        break;
    case 673:
        opt->ps1_exe.do_8mib = false;
        break;
    case 674:
        opt->o_unix.unmap_all_pages = true;  // val ?
        break;

    case '\0':
        return -1;
    case ':':
        return -2;
    default:
        fprintf(stderr,"%s: internal error in getopt (%d)\n", argv0, optc);
        return -3;
    }

    UNUSED(i);
    return 0;
}
Esempio n. 5
0
File: edit.c Progetto: jff/mathspad
static void handle_filename(void *data, Char *name)
{
    EDITINFO *einf = (EDITINFO *) data;

    if (name) {
	FILE *f;
	int i;
	int check_found = check_name(einf, name);

	if (!(f = fopen((char*)UstrtoFilename(name),"rb"))) {
	    message2(MP_CLICKREMARK, translate("Unable to open file "), name);
	    free(name);
	    failure=MP_True;
	    return;
	}
	i = test_file(f);
	set_wait_cursor(einf->win_id);
	switch (i) {
	case BINDOC:
	    message(MP_MESSAGE, translate("Loading ascii file."));
	    read_file(f,BINARYFILE);
	    unset_file();
	    load_editwindow(einf->info);
	    break;
	case OLDDOC:
	    i = edit_fnr;
	    edit_fnr = 0;
	    load_notation_filenames(f);
	    old_load_editwindow(einf->info,f);
	    edit_fnr = i;
	    if (!state_open) clear_file_ref();
	    break;
	case NEWDOC:
	    i = edit_fnr;
	    edit_fnr = 0;
	    read_file(f,DOCUMENTFILE);
	    unset_file();
	    load_editwindow(einf->info);
	    edit_fnr = i;
	    break;
	default: break;
	}
	fclose(f);
	cleanup_nodestack();
	cleanup_filestack();
	cleanup_stencilstack();
	einf->saved = MP_True;
	einf->auto_saved = MP_True;
	einf->view_mode = check_found;
	set_name(einf, name);
	set_output_name(einf);
	name = NULL;
	remove_wait_cursor();
	if (check_found)
	    message(MP_CLICKREMARK, translate("The document is already loaded.\n"
		    "This copy has been loaded in view mode\n"
		    "in order to ensure that only one\n"
		    "backup is made."));
	return;
    }
    free(name);
}