Exemple #1
0
/* If `name' has a bzip-like extension, try to uncompress it into a temporary
   file using bzip.  If this succeeds, return the name of the temporary file;
   return NULL otherwise.  */
static char *try_uncompress_with_bzip(const char *name)
{
    char *tmp_name = NULL;
    size_t l = strlen(name);
    int exit_status;
    char *argv[4];

    /* Check whether the name sounds like a bzipped file by checking the
       extension.  MSDOS and UNIX variants of bzip v2 use the extension
       '.bz2'.  bzip v1 is obsolete.  */
    if (l < 5 || strcasecmp(name + l - 4, ".bz2") != 0) {
        return NULL;
    }

    /* `exec*()' does not want these to be constant...  */
    argv[0] = lib_stralloc("bzip2");
    argv[1] = lib_stralloc("-cd");
    argv[2] = archdep_filename_parameter(name);
    argv[3] = NULL;

    ZDEBUG(("try_uncompress_with_bzip: spawning bzip -cd %s", name));
    exit_status = archdep_spawn("bzip2", argv, &tmp_name, NULL);

    lib_free(argv[0]);
    lib_free(argv[1]);
    lib_free(argv[2]);

    if (exit_status == 0) {
        ZDEBUG(("try_uncompress_with_bzip: OK"));
        return tmp_name;
    } else {
        ZDEBUG(("try_uncompress_with_bzip: failed"));
        ioutil_remove(tmp_name);
        lib_free(tmp_name);
        return NULL;
    }
}
Exemple #2
0
int cmdline_register_options(const cmdline_option_t *c)
{
    cmdline_option_ram_t *p;

    p = options + num_options;
    for (; c->name != NULL; c++, p++) {
        if (num_allocated_options <= num_options) {
            num_allocated_options *= 2;
            options = lib_realloc(options, (sizeof(cmdline_option_ram_t) * num_allocated_options));
            p = options + num_options;
        }

        p->name = lib_stralloc(c->name);
        p->type = c->type;
        p->need_arg = c->need_arg;
        p->set_func = c->set_func;
        p->extra_param = c->extra_param;
        if (c->resource_name != NULL)
            p->resource_name = lib_stralloc(c->resource_name);
        else
            p->resource_name = NULL;
        p->resource_value = c->resource_value;

        p->use_param_name_id = c->use_param_name_id;
        p->use_description_id = c->use_description_id;

        p->param_name = c->param_name;
        p->description = c->description;

        p->param_name_trans = c->param_name_trans;
        p->description_trans = c->description_trans;

        num_options++;
    }

    return 0;
}
Exemple #3
0
static void ffmpeg_get_formats_and_codecs(void)
{
    int i, j, ai, vi = 0, f;
    gfxoutputdrv_codec_t *audio_codec_list;
    gfxoutputdrv_codec_t *video_codec_list;
    gfxoutputdrv_codec_t *ac, *vc;

    f = 0;
    ffmpegdrv_formatlist = lib_malloc(sizeof(gfxoutputdrv_format_t));

    for (i = 0; formats_to_test[i].name != NULL; i++) {
        if (VICE_P_AV_GUESS_FORMAT(formats_to_test[i].name, NULL, NULL)) {
            audio_codec_list = NULL;
            video_codec_list = NULL;
            if (formats_to_test[i].audio_codecs != NULL) {
                ai = 0;
                audio_codec_list = lib_malloc(sizeof(gfxoutputdrv_codec_t));
                ac = formats_to_test[i].audio_codecs;
                for (j = 0; ac[j].name != NULL; j++) {
                    if ((ac[j].id == AV_CODEC_ID_NONE) || VICE_P_AVCODEC_FIND_ENCODER(ac[j].id)) {
                        audio_codec_list[ai++] = ac[j];
                        audio_codec_list = lib_realloc(audio_codec_list, (ai + 1) * sizeof(gfxoutputdrv_codec_t));
                    }
                }
                audio_codec_list[ai].name = NULL;
            }
            if (formats_to_test[i].video_codecs != NULL) {
                vi = 0;
                video_codec_list = lib_malloc(sizeof(gfxoutputdrv_codec_t));
                vc = formats_to_test[i].video_codecs;
                for (j = 0; vc[j].name != NULL; j++) {
                    if (vc[j].id == AV_CODEC_ID_NONE || VICE_P_AVCODEC_FIND_ENCODER(vc[j].id)) {
                        video_codec_list[vi++] = formats_to_test[i].video_codecs[j];
                        video_codec_list = lib_realloc(video_codec_list, (vi + 1) * sizeof(gfxoutputdrv_codec_t));
                    }
                }
                video_codec_list[vi].name = NULL;
            }
            if (((audio_codec_list == NULL) || (ai > 0)) && ((video_codec_list == NULL) || (vi > 0))) {
                ffmpegdrv_formatlist[f].name = lib_stralloc(formats_to_test[i].name);
                ffmpegdrv_formatlist[f].audio_codecs = audio_codec_list;
                ffmpegdrv_formatlist[f++].video_codecs = video_codec_list;
                ffmpegdrv_formatlist = lib_realloc(ffmpegdrv_formatlist, (f + 1) * sizeof(gfxoutputdrv_format_t));
            }
        }
    }
    ffmpegdrv_formatlist[f].name = NULL;
    ffmpeg_drv.formatlist = ffmpegdrv_formatlist;
}
Exemple #4
0
/*
    amount is 2 or more
*/
static void io_source_log_collisions(WORD addr, int amount, io_source_list_t *start)
{
    io_source_list_t *current = start;
    char *old_msg = NULL;
    char *new_msg = NULL;
    int found = 0;

    current = current->next;

    DBG(("IO: check %d sources for addr %04x\n", amount, addr));
    while (current) {
        /* DBG(("IO: check '%s'\n", current->device->name)); */
        if (current->device->io_source_valid && 
            addr >= current->device->start_address && 
            addr <= current->device->end_address && 
            current->device->io_source_prio == IO_PRIO_NORMAL) {
            /* found a conflict */
            DBG(("IO: found #%d: '%s'\n", found, current->device->name));

            /* first part of the message "read collision at x from" */
            if (found == 0) {
                old_msg = lib_stralloc(translate_text(IDGS_IO_READ_COLL_AT_X_FROM));
                new_msg = util_concat(old_msg, current->device->name, NULL);
                lib_free(old_msg);
            }
            if ((found != amount - 1) && (found != 0)) {
                old_msg = new_msg;
                new_msg = util_concat(old_msg, ", ", current->device->name, NULL);
                lib_free(old_msg);
            }
            if (found == amount - 1) {
                old_msg = new_msg;
                new_msg = util_concat(old_msg, translate_text(IDGS_AND), current->device->name, NULL);
                lib_free(old_msg);
            }
            found++;
            if (found == amount) {
                break;
            }
        }
        current = current->next;
    }

    if (found) {
        log_message(LOG_DEFAULT, new_msg, addr);
        lib_free(new_msg);

    }
}
Exemple #5
0
static struct file_list *file_list_read_nolfn(const char *path, const char *pattern)
{
    char *cwd = ioutil_current_dir();
    struct file_list *fl = NULL;
    struct find_t f;

    if (cwd == NULL) {
        return NULL;
    }

    if (ioutil_chdir(path) < 0) {
        goto end;
    }

    if (_dos_findfirst("*.*", (_A_NORMAL | _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_SUBDIR | _A_ARCH), &f)) {
        goto end;
    }

    fl = file_list_create();

    /* (We skip `.' here.) */

    while (!_dos_findnext(&f)) {
        strlwr(f.name);
        if (pattern == NULL || (f.attrib & _A_SUBDIR)) {
            file_list_add_item(fl, f.name, (f.attrib & _A_SUBDIR) ? FT_DIR : FT_NORMAL);
            continue;
        }
        {
            char *p = lib_stralloc(pattern);
            char *element;

            element = strtok(p, ";");
            do {
                if (fnmatch(element, f.name, FNM_NOCASE) == 0) {
                    file_list_add_item(fl, f.name, (f.attrib & _A_SUBDIR) ? FT_DIR : FT_NORMAL);
                }
                element = strtok(NULL, ";");
            } while (element != NULL);
            lib_free(p);
        }
    }

    file_list_sort(fl);

end:
    ioutil_chdir(cwd);
    return fl;
}
int aciacart_cmdline_options_init(void)
{
#if defined(HAVE_RS232DEV) || defined(HAVE_RS232NET)
    if (machine_class == VICE_MACHINE_C128) {
        acia_base_list = lib_stralloc(". (0xD700, 0xDE00, 0xDF00)");
    } else if (machine_class == VICE_MACHINE_VIC20) {
        acia_base_list = lib_stralloc(". (0x9800, 0x9C00)");
    } else {
        acia_base_list = lib_stralloc(". (0xDE00, 0xDF00)");
    }

    base_cmdline_options[0].description = acia_base_list;

    if (cmdline_register_options(base_cmdline_options) < 0) {
          return -1;
    }

    if (cmdline_register_options(cart_cmdline_options) < 0) {
          return -1;
    }
#endif

    return acia1_cmdline_options_init();
}
Exemple #7
0
void ui_display_tape_current_image(const char *image)
{
    char *name;
    int i;
    int num_app_shells = get_num_shells();

    lib_free(last_attached_tape);
    last_attached_tape = lib_stralloc(image);
    util_fname_split(image, NULL, &name);

    for (i = 0; i < num_app_shells; i++) {
        gtk_widget_set_tooltip_text(GTK_WIDGET(gtk_widget_get_parent(gtk_widget_get_parent(app_shells[i].tape_status.box))), name);
    }
    lib_free(name);
}
Exemple #8
0
int archdep_init(int *argc, char **argv)
{
#ifndef __ANDROID__
    _fmode = O_BINARY;

    //_setmode(_fileno(stdin), O_BINARY);
    //_setmode(_fileno(stdout), O_BINARY);
#endif //__ANDROID__

    argv0 = lib_stralloc(argv[0]);

    //orig_workdir = getcwd(NULL, MAX_PATH);

    return 0;
}
Exemple #9
0
char *uimonfb_get_in(char **ppchCommandLine, const char *prompt)
{
    char *p, *ret_sting;

    p = readline(prompt);
#if defined(HAVE_READLINE) && defined(HAVE_READLINE_READLINE_H)
    if (p && *p) {
        add_history(p);
    }
#endif
    ret_sting = lib_stralloc(p);
    free(p);

    return ret_sting;
}
Exemple #10
0
/* return malloced version of full pathname of filename */
int archdep_expand_path(char **return_path, const char *filename)
{
    if (filename[0] == '\\' || filename[1] == ':') {
        *return_path = lib_stralloc(filename);
    } else {
        char *p = (char *)malloc(512);
        while (getcwd(p, 512) == NULL) {
            return 0;
        }

        *return_path = util_concat(p, "\\", filename, NULL);
        lib_free(p);
    }
    return 0;
}
Exemple #11
0
BOOL enumfunc(AIN_Device *device, void *UserData)
{
    devices.ids[devices.count] = device->DeviceID;
    devices.names[devices.count] = lib_stralloc(device->DeviceName);

    if (default_id != -1) {
        if (default_id == device->DeviceID) {
            default_count = devices.count;
        }
    }

    devices.count++;

    return FALSE;
}
Exemple #12
0
unsigned int interrupt_cpu_status_int_new(interrupt_cpu_status_t *cs,
                                          const char *name)
{
    cs->num_ints += 1;

    cs->pending_int = (unsigned int *)lib_realloc(cs->pending_int, cs->num_ints
                                                  * sizeof(*(cs->pending_int)));
    cs->pending_int[cs->num_ints - 1] = 0;

    cs->int_name = (char **)lib_realloc(cs->int_name, cs->num_ints
                                        * sizeof(char *));
    cs->int_name[cs->num_ints - 1] = lib_stralloc(name);

    return cs->num_ints - 1;
}
Exemple #13
0
palette_t *palette_create(unsigned int num_entries, const char *entry_names[])
{
    palette_t *p;
    unsigned int i;

    p = lib_malloc(sizeof(palette_t));

    p->num_entries = num_entries;
    p->entries = lib_calloc(num_entries, sizeof(palette_entry_t));

    if (entry_names != NULL)
        for (i = 0; i < num_entries; i++)
            p->entries[i].name = lib_stralloc(entry_names[i]);

    return p;
}
Exemple #14
0
rawfile_info_t *rawfile_open(const char *file_name, const char *path,
                             unsigned int command)
{
    rawfile_info_t *info;
    char *complete;
    FILE *fd;
    const char *mode = NULL;

    if (path == NULL)
        complete = lib_stralloc(file_name);
    else
        complete = util_concat(path, FSDEV_DIR_SEP_STR, file_name, NULL);

    switch (command) {
      case FILEIO_COMMAND_READ:
        mode = MODE_READ;
        break;
      case FILEIO_COMMAND_WRITE:
        mode = MODE_WRITE;
        break;
      case FILEIO_COMMAND_APPEND:
        mode = MODE_APPEND;
        break;
      case FILEIO_COMMAND_APPEND_READ:
        mode = MODE_APPEND_READ_WRITE;
        break;
      default:
        return NULL;
    }

    fd = fopen(complete, mode);

    if (fd == NULL) {
        lib_free(complete);
        return NULL;
    }

    info = lib_malloc(sizeof(rawfile_info_t));

    info->fd = fd;
    util_fname_split(complete, &(info->path), &(info->name));
    info->read_only = 0;

    lib_free(complete);

    return info;
}
Exemple #15
0
static UI_CALLBACK(set_custom_maximum_speed)
{
    static char input_string[32];
    char *msg_string;
    ui_button_t button;
    int i;
    int current_speed;

    resources_get_int("Speed", &current_speed);
    if (!*input_string) {
        sprintf(input_string, "%d", current_speed);
    }

    if (CHECK_MENUS) {
	switch (current_speed) {
	case 200:
	case 100:
	case  50:
	case  20:
	case  10:
	case   0:
            ui_menu_set_tick(w, 0);
	    break;
	default:
            ui_menu_set_tick(w, 1);
	}
    } else {
        vsync_suspend_speed_eval();
        msg_string = lib_stralloc(_("Enter speed"));
        button = ui_input_string(_("Maximum speed"), msg_string, input_string, 32);
        lib_free(msg_string);
        if (button == UI_BUTTON_OK) {
            int current_refresh_rate;

            resources_get_int("RefreshRate", &current_refresh_rate);

            i = atoi(input_string);
            if (!(current_refresh_rate <= 0 && i <= 0) && i >= 0 && current_speed != i) {
                resources_set_int("Speed", i);
                ui_update_menus();
            } else {
                ui_error(_("Invalid speed value"));
            }
        }
    }
}
Exemple #16
0
const char *archdep_boot_path(void)
{
    if (boot_path == NULL) {
        /* FIXME: bad name of define */
#ifdef USE_PROC_SELF_EXE
        /* known from setup in archdep_init_extra() so just reuse it */
        boot_path = lib_stralloc(argv0);
#else
        boot_path = findpath(argv0, getenv("PATH"), IOUTIL_ACCESS_X_OK);
#endif

        /* Remove the program name.  */
        *strrchr(boot_path, '/') = '\0';
    }

    return boot_path;
}
Exemple #17
0
/* create the default directory where prefs, fliplist, autostart images etc are stored
   a pointer to the resulting path is returned, and it should be freed by the caller. */
static char *archdep_make_default_pref_path(int create)
{
    char *path;
    if (archdep_pref_path == NULL) {
        const char *home;
        home = archdep_home_path();
        path = util_concat(home, "/.vice", NULL);
    } else {
        path = lib_stralloc(archdep_pref_path);
    }
    if(create) {
        if (access(path, F_OK)) {
            mkdir(path, S_IRWXU);
        }
    }
    return path;
}
Exemple #18
0
FILE *archdep_mkstemp_fd(char **filename, const char *mode)
{
    char *tmp;
    FILE *fd;

    tmp = lib_stralloc(tmpnam(NULL));

    fd = fopen(tmp, mode);

    if (fd == NULL) {
        return NULL;
    }

    *filename = tmp;

    return fd;
}
Exemple #19
0
char *archdep_program_name(void)
{
    static char *program_name = NULL;

    if (program_name == NULL) {
        char *p, name[1024];

        GetProgramName(name, 1024);
        p = FilePart(name);

        if (p != NULL) {
            program_name = lib_stralloc(p);
        }
    }

    return program_name;
}
Exemple #20
0
const char *archdep_boot_path(void)
{
    if (boot_path == NULL) {
        char cwd[1024];
        BPTR lock;

        lock = GetProgramDir();
        if (NameFromLock(lock, cwd, 1024)) {
            if (cwd[strlen(cwd) - 1] != ':') {
                strcat(cwd, "/");
            }
            boot_path = lib_stralloc(cwd);
        }
    }

    return boot_path;
}
rtc_72421_t *rtc72421_init(char *device)
{
    rtc_72421_t *retval = lib_calloc(1, sizeof(rtc_72421_t));
    int loaded = rtc_load_context(device, 0, 0);

    if (loaded) {
        retval->offset = rtc_get_loaded_offset();
    } else {
        retval->offset = 0;
    }
    retval->old_offset = retval->offset;

    retval->hour24 = 0;
    retval->device = lib_stralloc(device);

    return retval;
}
Exemple #22
0
int archdep_expand_path(char **return_path, const char *orig_name)
{
    char tmp[FILENAME_MAX];
    int len;

    if (archdep_path_is_relative(orig_name)) {
        getcwd(tmp, FILENAME_MAX);
        len = strlen(tmp);
        if (tmp[len - 1] == FSDEV_DIR_SEP_CHR) {
            *return_path = util_concat(tmp, orig_name, NULL);
        } else {
            *return_path = util_concat(tmp, FSDEV_DIR_SEP_STR, orig_name, NULL);
        }
    } else {
        *return_path = lib_stralloc(orig_name);
    }
    return 0;
}
Exemple #23
0
char *uimon_get_in(char **ppchCommandLine, const char *prompt)
{
    int y, x_off;
    char *input;

    y = menu_draw->max_text_y - 1;
    x_pos = 0;

    x_off = sdl_ui_print(prompt, 0, y);
    input = sdl_ui_readline(NULL, x_off, y);
    sdl_ui_scroll_screen_up();

    if (input == NULL) {
        input = lib_stralloc("x");
    }

    return input;
}
Exemple #24
0
/* Autostart tape image `file_name'.  */
int autostart_tape(const char *file_name, const char *program_name,
                   unsigned int program_number, unsigned int runmode)
{
    char *name = NULL;

    if (network_connected() || !file_name || !autostart_enabled)
        return -1;

    /* Get program name first to avoid more than one file handle open on
       image.  */
    if (!program_name && program_number > 0)
        name = image_contents_filename_by_number(IMAGE_CONTENTS_TAPE,
                                                 file_name, 0, program_number);
    else
        name = lib_stralloc(program_name ? program_name : "");

    if (!(tape_image_attach(1, file_name) < 0)) {
        log_message(autostart_log,
                    "Attached file `%s' as a tape image.", file_name);
        if (tape_tap_attched()) {
            if (program_number > 0) {
                lib_free(name);
                name = NULL;
                /* program numbers in tape_seek_to_file() start at 0 */
                tape_seek_to_file(tape_image_dev1, program_number-1);
            } else {
                tape_seek_start(tape_image_dev1);
            }
        }
        resources_set_int("VirtualDevices", 1); /* Kludge: iAN CooG - for t64 images we need devtraps ON */
        reboot_for_autostart(name, AUTOSTART_HASTAPE, runmode);
        lib_free(name);

        return 0;
    }

    autostartmode = AUTOSTART_ERROR;
    deallocate_program_name();

    if (name)
        lib_free(name);

    return -1;
}
Exemple #25
0
unsigned int rawfile_remove(const char *src_name, const char *path)
{
    char *complete_src;
    int rc;

    if (path == NULL)
        complete_src = lib_stralloc(src_name);
    else
        complete_src = util_concat(path, FSDEV_DIR_SEP_STR, src_name, NULL);

    rc = ioutil_remove(complete_src);

    lib_free(complete_src);

    if (rc < 0)
        return FILEIO_FILE_NOT_FOUND;

    return FILEIO_FILE_SCRATCHED;
}
Exemple #26
0
rtc_ds1216e_t *ds1216e_init(char *device)
{
    rtc_ds1216e_t *retval = lib_calloc(1, sizeof(rtc_ds1216e_t));
    int loaded = rtc_load_context(device, 0, DS1216E_REG_SIZE);

    if (loaded) {
        retval->offset = rtc_get_loaded_offset();
        retval->clock_regs = rtc_get_loaded_clockregs();
    } else {
        retval->offset = 0;
        retval->clock_regs = lib_calloc(1, DS1216E_REG_SIZE);
    }
    retval->old_offset = retval->offset;
    memcpy(retval->old_clock_regs, retval->clock_regs, DS1216E_REG_SIZE);

    retval->device = lib_stralloc(device);

    return retval;
}
Exemple #27
0
static char *cbmfile_find_file(const char *fsname, const char *path)
{
    struct ioutil_dir_s *ioutil_dir;
    BYTE *name1, *name2;
    char *name, *retname = NULL;
    const char *open_path;

    open_path = path;
    if (path == NULL)
        open_path = "";

    ioutil_dir = ioutil_opendir(open_path);

    if (ioutil_dir == NULL)
        return NULL;

    name1 = cbmdos_dir_slot_create(fsname, (unsigned int)strlen(fsname));

    while (1) {
        unsigned int equal;

        name = ioutil_readdir(ioutil_dir);

        if (name == NULL)
            break;

        name2 = cbmdos_dir_slot_create(name, (unsigned int)strlen(name));
        equal = cbmdos_parse_wildcard_compare(name1, name2);

        lib_free(name2);

        if (equal > 0) {
            retname = lib_stralloc(name);
            break;
        }
    }

    lib_free(name1);
    ioutil_closedir(ioutil_dir);

    return retname;
}
Exemple #28
0
log_t log_open(const char *id)
{
    log_t new_log = 0;
    log_t i;

    for (i = 0; i < num_logs; i++) {
        if (logs[i] == NULL) {
            new_log = i;
            break;
        }
    }
    if (i == num_logs) {
        new_log = num_logs++;
        logs = lib_realloc(logs, sizeof(*logs) * num_logs);
    }

    logs[new_log] = lib_stralloc(id);

    return new_log;
}
Exemple #29
0
char *romset_file_list(const char **resource_list)
{
    char *list;
    const char *s;

    list = lib_stralloc("");
    s = *resource_list++;

    while (s != NULL) {
        char *line;
        line = resources_write_item_to_string(s, ARCHDEP_LINE_DELIMITER);
        if (line != NULL) {
            util_addline_free(&list, line);
        }

        s = *resource_list++;
    }

    return list;
}
Exemple #30
0
/* Clean memory and reboot for autostart.  */
static void reboot_for_autostart(const char *program_name, unsigned int mode,
                                 unsigned int runmode)
{
    if (!autostart_enabled)
        return;

    log_message(autostart_log, "Resetting the machine to autostart '%s'",
                program_name ? program_name : "*");
    mem_powerup();
    autostart_ignore_reset = 1;
    deallocate_program_name();
    if (program_name && program_name[0])
        autostart_program_name = (BYTE *)lib_stralloc(program_name);
    machine_trigger_reset(MACHINE_RESET_MODE_SOFT);
    /* The autostartmode must be set AFTER the shutdown to make the autostart
       threadsafe for OS/2 */
    autostartmode = mode;
    autostart_run_mode = runmode;
    autostart_wait_for_reset = 1;
}