Пример #1
0
_WCRTLINK int execv( const CHAR_TYPE * path,
                     const CHAR_TYPE * const argv[] )
{
    const CHAR_TYPE * const *envp = (const CHAR_TYPE **)_RWD_environ;
    CHAR_TYPE               *envmem;
    CHAR_TYPE               *envstrings;
    unsigned                envseg;
    int                     len;
    CHAR_TYPE SPVE_NEAR     *np;
    CHAR_TYPE SPVE_NEAR     *p;
    CHAR_TYPE SPVE_NEAR     *end_of_p;
    int                     retval;
    int                     num_of_paras;       /* for environment */
    size_t                  cmdline_len;
    CHAR_TYPE SPVE_NEAR     *cmdline_mem;
    CHAR_TYPE SPVE_NEAR     *cmdline;
    CHAR_TYPE               *drive;
    CHAR_TYPE               *dir;
    CHAR_TYPE               *fname;
    CHAR_TYPE               *ext;
    
    retval = __F_NAME(__cenvarg,__wcenvarg)( argv, envp, &envmem,
        &envstrings, &envseg,
        &cmdline_len, FALSE );
    if( retval == -1 ) {
        return( -1 );
    }
    num_of_paras = retval;
    len = __F_NAME(strlen,wcslen)( path ) + 7 + _MAX_PATH2;
    np = LIB_ALLOC( len * sizeof( CHAR_TYPE ) );
    if( np == NULL ) {
        p = (CHAR_TYPE SPVE_NEAR *)alloca( len*sizeof(CHAR_TYPE) );
        if( p == NULL ) {
            lib_free( envmem );
            return( -1 );
        }
    } else {
        p = np;
    }
    __F_NAME(_splitpath2,_wsplitpath2)( path, p + (len-_MAX_PATH2),
                                        &drive, &dir, &fname, &ext );

    /* allocate the cmdline buffer */
    cmdline_mem = LIB_ALLOC( cmdline_len * sizeof( CHAR_TYPE ) );
    if( cmdline_mem == NULL ) {
        cmdline = (CHAR_TYPE SPVE_NEAR *)alloca( cmdline_len*sizeof(CHAR_TYPE) );
        if( cmdline == NULL ) {
            retval = -1;
            _RWD_errno = E2BIG;
            goto cleanup;
        }
    } else {
        cmdline = cmdline_mem;
    }
    
    __F_NAME(_makepath,_wmakepath)( p, drive, dir, fname, ext );
    _RWD_errno = ENOENT;
    if( ext[0] != '\0' ) {
        if( __F_NAME(stricmp,wcscmp)( ext, __F_NAME(".bat",L".bat") ) == 0 )
        {
            retval = -1; /* assume file doesn't exist */
            if( file_exists( p ) ) goto spawn_command_com;
        } else {
            _RWD_errno = 0;
            /* user specified an extension, so try it */
            retval = _doexec( p, cmdline, argv );
        }
    }
    else {
        end_of_p = p + __F_NAME(strlen,wcslen)( p );
        __F_NAME(strcpy,wcscpy)( end_of_p, __F_NAME(".com",L".com") );
        _RWD_errno = 0;
        retval = _doexec( p, cmdline, argv );
        if( _RWD_errno == ENOENT || _RWD_errno == EINVAL ) {
            _RWD_errno = 0;
            __F_NAME(strcpy,wcscpy)( end_of_p, __F_NAME(".exe",L".exe") );
            retval = _doexec( p, cmdline, argv );
            if( _RWD_errno == ENOENT || _RWD_errno == EINVAL ) {
                /* try for a .BAT file */
                _RWD_errno = 0;
                __F_NAME(strcpy,wcscpy)( end_of_p, __F_NAME(".bat",L".bat") );
                if( file_exists( p ) ) {
spawn_command_com:
                /* the environment will have to be reconstructed */
                lib_free( envmem );
                envmem = NULL;
                __F_NAME(__ccmdline,__wccmdline)( p, argv, cmdline, 1 );
                retval = execl( getenv("COMSPEC"),
                    "COMMAND",
                    "/c ",
                    p, cmdline );
                }
            }
        }
    }
cleanup:
    LIB_FREE( cmdline_mem );
    LIB_FREE( np );
    lib_free( envmem );
    return( retval );
}
Пример #2
0
/* Initialize the hardware-level drive emulation (should be called at least
   once before anything else).  Return 0 on success, -1 on error.  */
int drive_init(void)
{
    unsigned int dnr;
    drive_t *drive;

    if (rom_loaded)
        return 0;

    drive_init_was_called = 1;

    driverom_init();
    drive_image_init();

    drive_log = log_open("Drive");

    for (dnr = 0; dnr < DRIVE_NUM; dnr++) {
        char *logname;

        drive = drive_context[dnr]->drive;
        logname = lib_msprintf("Drive %i", dnr + 8);
        drive->log = log_open(logname);
        lib_free(logname);

        drive_clk[dnr] = 0L;
        drive->clk = &drive_clk[dnr];
        drive->mynumber = dnr;
    }

    if (driverom_load_images() < 0) {
        resources_set_int("Drive8Type", DRIVE_TYPE_NONE);
        resources_set_int("Drive9Type", DRIVE_TYPE_NONE);
        resources_set_int("Drive10Type", DRIVE_TYPE_NONE);
        resources_set_int("Drive11Type", DRIVE_TYPE_NONE);
        return -1;
    }

    log_message(drive_log, "Finished loading ROM images.");
    rom_loaded = 1;

    drive_overflow_init();

    for (dnr = 0; dnr < DRIVE_NUM; dnr++) {
        drive = drive_context[dnr]->drive;
        drive->drive_ram_expand2 = NULL;
        drive->drive_ram_expand4 = NULL;
        drive->drive_ram_expand6 = NULL;
        drive->drive_ram_expand8 = NULL;
        drive->drive_ram_expanda = NULL;

        machine_drive_port_default(drive_context[dnr]);

        if (drive_check_type(drive->type, dnr) < 1)
            resources_set_int_sprintf("Drive%iType", DRIVE_TYPE_NONE, dnr + 8);

        machine_drive_rom_setup_image(dnr);

        drive->rtc_offset = (time_t)0; /* TODO: offset */
        drive->ds1216 = ds1216e_init(&drive->rtc_offset);
        drive->ds1216->hours12 = 1;
    }

    for (dnr = 0; dnr < DRIVE_NUM; dnr++) {
        drive = drive_context[dnr]->drive;
        drive->gcr = gcr_create_image();
        drive->p64 = lib_calloc(1, sizeof(TP64Image));
        P64ImageCreate(drive->p64);
        drive->byte_ready_level = 1;
        drive->byte_ready_edge = 1;
        drive->GCR_dirty_track = 0;
        drive->GCR_write_value = 0x55;
        drive->GCR_track_start_ptr = drive->gcr->data;
        drive->GCR_current_track_size = 0;
        drive->attach_clk = (CLOCK)0;
        drive->detach_clk = (CLOCK)0;
        drive->attach_detach_clk = (CLOCK)0;
        drive->old_led_status = 0;
        drive->old_half_track = 0;
        drive->side = 0;
        drive->GCR_image_loaded = 0;
        drive->P64_image_loaded = 0;
        drive->P64_dirty = 0;
        drive->read_only = 0;
        drive->clock_frequency = 1;
        drive->led_last_change_clk = *(drive->clk);
        drive->led_last_uiupdate_clk = *(drive->clk);
        drive->led_active_ticks = 0;

        rotation_reset(drive);
        drive_image_init_track_size_d64(drive);

        /* Position the R/W head on the directory track.  */
        drive_set_half_track(36, drive);
        drive_led_color[dnr] = DRIVE_ACTIVE_RED;
    }

    for (dnr = 0; dnr < DRIVE_NUM; dnr++) {
        drive = drive_context[dnr]->drive;
        driverom_initialize_traps(drive, 1);

        drivesync_clock_frequency(drive->type, drive);

        rotation_init((drive->clock_frequency == 2) ? 1 : 0, dnr);

        if (drive->type == DRIVE_TYPE_2000 || drive->type == DRIVE_TYPE_4000) {
            drivecpu65c02_init(drive_context[dnr], drive->type);
        } else {
            drivecpu_init(drive_context[dnr], drive->type);
        }

        /* Make sure the sync factor is acknowledged correctly.  */
        drivesync_factor(drive_context[dnr]);

        /* Make sure the traps are moved as needed.  */
        if (drive->enable)
            drive_enable(drive_context[dnr]);
    }

    return 0;
}
Пример #3
0
void kbdbuf_shutdown(void)
{
    lib_free(kbd_buf_string);
}
Пример #4
0
/*
    FIXME: partition support
 */
int vdrive_command_format(vdrive_t *vdrive, const char *disk_name)
{
    BYTE tmp[256];
    int status;
    char *name, *comma;
    BYTE id[2];

    if (!disk_name)
        return CBMDOS_IPE_SYNTAX;

    if (vdrive->image->read_only || VDRIVE_IMAGE_FORMAT_4000_TEST)
        return CBMDOS_IPE_WRITE_PROTECT_ON;

    if (vdrive->image->device == DISK_IMAGE_DEVICE_FS) {
        if (disk_image_fsimage_fd_get(vdrive->image) == NULL)
            return CBMDOS_IPE_NOT_READY;
    }

    comma = strchr(disk_name, ',');
    if (comma != NULL) {
        if (comma != disk_name) {
            name = lib_malloc(comma - disk_name + 1);
            memcpy(name, disk_name, comma - disk_name);
            name[comma - disk_name] = '\0';
        } else {
            name = lib_stralloc(" ");
        }
        if (comma[1] != '\0') {
            id[0] = comma[1];
            if (comma[2] != '\0') {
                id[1] = comma[2];
            } else {
                id[1] = ' ';
            }
        } else {
            id[1] = id[0] = ' ';
        }
    } else {
        name = lib_stralloc(disk_name);
        id[1] = id[0] = ' ';
    }

    /* Make the first dir-entry.  */
    memset(tmp, 0, 256);
    tmp[1] = 255;

    if (vdrive_write_sector(vdrive, tmp, vdrive->Dir_Track,
        vdrive->Dir_Sector) < 0) {
        lib_free(name);
        return CBMDOS_IPE_WRITE_ERROR_VER;
    }
    vdrive_bam_create_empty_bam(vdrive, name, id);
    vdrive_bam_write_bam(vdrive);

    /* Validate is called to clear the BAM.  */
    status = vdrive_command_validate(vdrive);

    lib_free(name);

    return status;
}
Пример #5
0
int console_close(console_t *log)
{
    lib_free(log);

    return 0;
}
Пример #6
0
static void uiperipheral_dialog(HWND hwnd)
{
    PROPSHEETPAGE psp[8];
    PROPSHEETHEADER psh;
    int i, no_of_drives, no_of_printers;

    for (i = 0; i < 3; i++ ) {
        printertextdevice[i] = lib_malloc(MAX_PATH);
        strcpy(printertextdevice[i], "");
    }

    no_of_drives = 4;
    no_of_printers = 3;

    if (have_printer_userport < 0) {
        have_printer_userport = (resources_touch("PrinterUserport")) < 0 ? 0 : 1;
    }
    if (have_printer_userport) {
        no_of_printers++;
    }

    for (i = 0; i < no_of_printers; i++) {
        psp[i].dwSize = sizeof(PROPSHEETPAGE);
        psp[i].dwFlags = PSP_USETITLE /*| PSP_HASHELP*/ ;
        psp[i].hInstance = winmain_instance;
#ifdef _ANONYMOUS_UNION
        psp[i].pszTemplate = MAKEINTRESOURCE(IDD_PRINTER_SETTINGS_DIALOG);
        psp[i].pszIcon = NULL;
#else
        psp[i].DUMMYUNIONNAME.pszTemplate
            = MAKEINTRESOURCE(IDD_PRINTER_SETTINGS_DIALOG);
        psp[i].u2.pszIcon = NULL;
#endif
        psp[i].lParam = 0;
        psp[i].pfnCallback = NULL;
    }

    for (i = 0; i < no_of_drives; i++) {
        psp[no_of_printers + i].dwSize = sizeof(PROPSHEETPAGE);
        psp[no_of_printers + i].dwFlags = PSP_USETITLE /*| PSP_HASHELP*/ ;
        psp[no_of_printers + i].hInstance = winmain_instance;
#ifdef _ANONYMOUS_UNION
#ifdef HAVE_OPENCBM
        if (opencbmlib_is_available()) {
            psp[no_of_printers + i].pszTemplate = MAKEINTRESOURCE(IDD_DISKDEVICE_OPENCBM_DIALOG);
        } else
#endif
        {
            psp[no_of_printers + i].pszTemplate = MAKEINTRESOURCE(IDD_DISKDEVICE_DIALOG);
        }
        psp[no_of_printers + i].pszIcon = NULL;
#else
#ifdef HAVE_OPENCBM
        if (opencbmlib_is_available()) {
            psp[no_of_printers + i].DUMMYUNIONNAME.pszTemplate = MAKEINTRESOURCE(IDD_DISKDEVICE_OPENCBM_DIALOG);
        } else 
#endif
        {
            psp[no_of_printers + i].DUMMYUNIONNAME.pszTemplate = MAKEINTRESOURCE(IDD_DISKDEVICE_DIALOG);
        }
        psp[no_of_printers + i].u2.pszIcon = NULL;
#endif
        psp[no_of_printers + i].lParam = 0;
        psp[no_of_printers + i].pfnCallback = NULL;
    }

    if (have_printer_userport) {
        psp[0].pfnDlgProc = callback_0;
        psp[0].pszTitle = translate_text(IDS_PRINTER_USERPORT);
        i = 1;
    } else
        i = 0;

    psp[i + 0].pfnDlgProc = callback_4;
    psp[i + 0].pszTitle = translate_text(IDS_PRINTER_4);
    psp[i + 1].pfnDlgProc = callback_5;
    psp[i + 1].pszTitle = translate_text(IDS_PRINTER_5);
    psp[i + 2].pfnDlgProc = callback_6;
    psp[i + 2].pszTitle = translate_text(IDS_PRINTER_6);
    psp[i + 3].pfnDlgProc = callback_8;
    psp[i + 3].pszTitle = translate_text(IDS_DRIVE_8);
    psp[i + 4].pfnDlgProc = callback_9;
    psp[i + 4].pszTitle = translate_text(IDS_DRIVE_9);
    psp[i + 5].pfnDlgProc = callback_10;
    psp[i + 5].pszTitle = translate_text(IDS_DRIVE_10);
    psp[i + 6].pfnDlgProc = callback_11;
    psp[i + 6].pszTitle = translate_text(IDS_DRIVE_11);

    psh.dwSize = sizeof(PROPSHEETHEADER);
    psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
    psh.hwndParent = hwnd;
    psh.hInstance = winmain_instance;
    psh.pszCaption = translate_text(IDS_PERIPHERAL_SETTINGS);
    psh.nPages = no_of_drives + no_of_printers;
#ifdef _ANONYMOUS_UNION
    psh.pszIcon = NULL;
    psh.nStartPage = i + 2;
    psh.ppsp = psp;
#else
    psh.DUMMYUNIONNAME.pszIcon = NULL;
    psh.u2.nStartPage = i + 2;
    psh.u3.ppsp = psp;
#endif
    psh.pfnCallback = NULL;

    PropertySheet(&psh);

    for (i = 0; i < 3; i++) {
        lib_free(printertextdevice[i]);
    }
}
Пример #7
0
/*
    CBM style sub partition support (using CBM filetype)

    on 1581 dos command "/dirname" enters a partition, "i" will go back to root

    FIXME: this works only for .d81
*/
static int vdrive_command_chpart(vdrive_t *vdrive, BYTE *name, int length)
{
    int status, rc;
    int ts,ss,te,len;
    BYTE *slot, buffer[256];
    cbmdos_cmd_parse_t cmd_parse;

    cmd_parse.cmd = name;
    cmd_parse.cmdlength = length;
    cmd_parse.readmode = 0;

    rc = cbmdos_command_parse(&cmd_parse);

    if (rc != SERIAL_OK) {
        status = CBMDOS_IPE_NO_NAME;
    } else {
/*#ifdef DEBUG_DRIVE*/
        log_debug("chpart name='%s', len=%d (%d), type= %d.",
                  cmd_parse.parsecmd, cmd_parse.parselength,
                  length, cmd_parse.filetype);
/*#endif*/

        vdrive_dir_find_first_slot(vdrive, cmd_parse.parsecmd,
                                   cmd_parse.parselength, CBMDOS_FT_CBM);

        slot = vdrive_dir_find_next_slot(vdrive);

        status = CBMDOS_IPE_BAD_PARTN; /* FIXME: is this correct ? */
        if (slot) {
            slot = &vdrive->Dir_buffer[vdrive->SlotNumber * 32];
            /*
            In order to use a partition as a sub-directory, it  must  adhere  to  
            the following four rules:

            1. It must start on sector 0
            2. It's size must be in multiples of 40 sectors (which means the 
               last sector is 39)
            3. It must be a minimum of 120 sectors long (3 tracks)
            4. It must not start on or cross  track 40
            */
            ts = slot[SLOT_FIRST_TRACK];
            ss = slot[SLOT_FIRST_SECTOR];
            len = slot[SLOT_NR_BLOCKS] + (slot[SLOT_NR_BLOCKS + 1] * 256);

            if ((ss == 0) && ((len % 40) == 0) && (len >= 120) && (ts != 40)) {
                te = ts + (len / 40);
                if (((ts < 40) && (te >= 40)) || (te >= (int)vdrive->num_tracks)) {
                    return CBMDOS_IPE_BAD_PARTN; /* FIXME: is this correct ? */
                }

                /* read the first BAM sector to get the DIR start 
                   The BAM track for the sub-directory exists on  the  first  
                   track  of  the partition, and has the same layout as the disk 
                   BAM on track 40.
                 */
                rc = vdrive_read_sector(vdrive, buffer, ts, 0);

                if (rc > 0) {
                    return rc;
                }
                if (rc < 0) {
                    return CBMDOS_IPE_NOT_READY;
                }

                /* more sanity checks */
                if ((buffer[0] < ts) || (buffer[1] > 39)) {
                    return CBMDOS_IPE_BAD_PARTN; /* FIXME: is this correct ? */
                }

/*#ifdef DEBUG_DRIVE*/
                log_debug("Partition Trk %d Sec %d - Trk %d len: %d", ts, ss, te, len);
/*#endif*/
                /* setup BAM location */
                vdrive->Header_Track = ts;
                vdrive->Header_Sector = 0;
                vdrive->Bam_Track = ts;
                vdrive->Bam_Sector = 0;
                /* set area for active partition */
                vdrive->Part_Start = ts;
                vdrive->Part_End = te;
                /* start of directory */
                vdrive->Dir_Track = buffer[0];
                vdrive->Dir_Sector = buffer[1];

                status = CBMDOS_IPE_OK;
            }
        }
    }

    vdrive_command_set_error(vdrive, status, 0, 0);
    lib_free(cmd_parse.parsecmd);

    return status;
}
Пример #8
0
int _dospawn( int mode, CHAR_TYPE *pgmname, CHAR_TYPE *cmdline,
                                  CHAR_TYPE *envpar, 
                                  const CHAR_TYPE * const argv[] )
{
    int tid;
    int handle;
    int wait;
    int rc = -1;
    int fh;
    int len;
    char *p;
    char *drive;
    char *dir;
    char *fname;
    char *ext;
    char *envdata;
    char *envp;
    char *ep;
    char *options;
    int ok;

    options = __CreateInheritString();

    __F_NAME(__ccmdline,__wccmdline)( pgmname, argv, cmdline, 0 );

    ok = 0;

    len = strlen( pgmname ) + 7 + _MAX_PATH2;
    p = lib_malloc( len );

    _splitpath2( pgmname, p + (len-_MAX_PATH2),
                 &drive, &dir, &fname, &ext );

    _makepath( p, drive, dir, fname, ext );
    fh = RdosOpenFile( p, 0 );
    if( fh == 0 ) {
        if( strlen( drive ) == 0 && strlen( dir ) == 0 ) {
            envdata = getenv( "PATH" );
            if( envdata ) {
                envp = envdata;
                while( envp && !ok) {
                    ep = strchr( envp, ';' );
                    if( ep ) {
                        *ep = 0;
                        ep++;
                    }
                    _makepath( p, "", envp, fname, ext );
                    fh = RdosOpenFile( pgmname, 0 );
                    if( fh ) {
                        ok = 1;
                        RdosCloseFile( fh );
                    }
                    envp = ep;
                }                
            }
        }
    } else {
        RdosCloseFile( fh );    
        ok = 1;
    }

    if( ok ) {
        handle = RdosSpawn( pgmname, cmdline, 0, envpar, options, &tid );

        if( !handle )
            ok = 0;
    }

    if( ok ) {
        if( mode == P_WAIT ) {
            wait = RdosCreateWait();
            RdosAddWaitForProcessEnd( wait, handle, 0 );
            RdosWaitForever( wait );
            rc = RdosGetProcessExitCode( handle );
            RdosCloseWait( wait );
        } 
        else
            rc = tid;
            
        RdosFreeProcessHandle( handle );                        
    }

    lib_free( options );
    lib_free( p );

    return( rc );
}
Пример #9
0
static UI_CALLBACK(browse_manual)
{
    const char *bcommand = NULL;

    /* first try to open the manual using desktop mechanisms */
#ifdef USE_GNOMEUI
    const char *path;
    int res;

#ifdef MACOSX_BUNDLE
    /* On Macs the manual path is relative to the bundle. */
    path = util_concat(archdep_boot_path(), "/../doc/", NULL);
#else
    path = util_concat(DOCDIR, "/", NULL);
#endif
    res = ui_open_manual(path);
    lib_free(path);
    if (res == 0) {
        return;
    }
#endif

    /* FIXME: desktop neutral ways to find the default application may be used
              here first (xdg-open) */

    /* as a last resort, use HTMLBrowserCommand */

    resources_get_string("HTMLBrowserCommand", &bcommand);

    if (bcommand == NULL || *bcommand == '\0') {
        ui_error(_("No HTML browser is defined."));
    } else {
        /* FIXME: Argh.  Ugly!  */
#define BROWSE_CMD_BUF_MAX 16384
        char buf[BROWSE_CMD_BUF_MAX];

#ifdef MACOSX_BUNDLE
        /* On Macs the manual path is relative to the bundle. */
        const char *boot_path;
        boot_path = archdep_boot_path();
        char *manual_path;
        manual_path = util_concat(boot_path, "/../doc/vice_toc.html", NULL);
#else
        static const char manual_path[] = DOCDIR "/vice_toc.html";
#endif
        
        char *res_ptr;
        int manual_path_len, cmd_len;

#ifdef HAVE_FULLSCREEN
        fullscreen_suspend(0);
#endif
        cmd_len = strlen(bcommand);
        manual_path_len = strlen(manual_path);

        res_ptr = strstr(bcommand, "%s");
        if (res_ptr == NULL) {
            /* No substitution. */
            if (cmd_len + 2 > BROWSE_CMD_BUF_MAX - 1) {
                ui_error(_("Browser command too long."));
                return;
            }
            sprintf(buf, "%s &", bcommand);
        } else {
            char *tmp_ptr, *cmd_ptr;
            int offs;

            /* Replace each occurrence of "%s" with the path of the HTML
               manual. */

            cmd_len += manual_path_len - 2;
            cmd_len += 2;       /* Trailing " &". */
            if (cmd_len > BROWSE_CMD_BUF_MAX - 1) {
                ui_error(_("Browser command too long."));
                return;
            }

            offs = res_ptr - bcommand;
            memcpy(buf, bcommand, offs);
            strcpy(buf + offs, manual_path);
            cmd_ptr = buf + offs + manual_path_len;
            res_ptr += 2;

            while ((tmp_ptr = strstr(res_ptr, "%s")) != NULL) {
                cmd_len += manual_path_len - 2;
                if (cmd_len > BROWSE_CMD_BUF_MAX - 1) {
                    ui_error(_("Browser command too long."));
                    return;
                }
                offs = tmp_ptr - res_ptr;
                memcpy(cmd_ptr, res_ptr, offs);
                strcpy(cmd_ptr + offs, manual_path);
                cmd_ptr += manual_path_len + offs;
                res_ptr = tmp_ptr + 2;
            }

            sprintf(cmd_ptr, "%s &", res_ptr);
        }

        log_debug("Executing `%s'...", buf);
        if (system(buf) != 0) {
            ui_error(_("Cannot run HTML browser."));
        }
            
#ifdef MACOSX_BUNDLE
        lib_free(manual_path);
#endif
    }
}
Пример #10
0
int fclose(FAR FILE *stream)
{
  int err = EINVAL;
  int ret = ERROR;
  int status;

  /* Verify that a stream was provided. */

  if (stream)
    {
      /* Check that the underlying file descriptor corresponds to an an open
       * file.
       */

      ret = OK;
      if (stream->fs_fd >= 0)
        {
          /* If the stream was opened for writing, then flush the stream */

          if ((stream->fs_oflags & O_WROK) != 0)
            {
              ret = lib_fflush(stream, true);
              err = errno;
            }

          /* Close the underlying file descriptor and save the return status */

          status = close(stream->fs_fd);

          /* If close() returns an error but flush() did not then make sure
           * that we return the close() error condition.
           */

          if (ret == OK)
            {
              ret = status;
              err = errno;
            }
        }

#if CONFIG_STDIO_BUFFER_SIZE > 0
      /* Destroy the semaphore */

      sem_destroy(&stream->fs_sem);

      /* Release the buffer */

      if (stream->fs_bufstart)
        {
          lib_free(stream->fs_bufstart);
        }

      /* Clear the whole structure */

      memset(stream, 0, sizeof(FILE));
#else
#if CONFIG_NUNGET_CHARS > 0
      /* Reset the number of ungetc characters */

      stream->fs_nungotten = 0;
#endif
      /* Reset the flags */

      stream->fs_oflags = 0;
#endif
      /* Setting the file descriptor to -1 makes the stream available for reuse */

      stream->fs_fd = -1;
    }

  /* On an error, reset the errno to the first error encountered and return
   * EOF.
   */

  if (ret != OK)
    {
      set_errno(err);
      return EOF;
    }

  /* Return success */

  return OK;
}
Пример #11
0
HACCEL uikeyboard_create_accelerator_table(void)
{
    FILE *fshortcuts;
    char *complete_path;
    char buffer[1000];
    char *p, *menustr, *metastr, *keystr, *displaystr;
    int i;

    ACCEL accellist[MAXACCEL];
    int accelnum = 0;

    menuitemmodifier_len = 0;
    for (i = 0; idmlist[i].str != NULL; i++)
        if (idmlist[i].cmd >= menuitemmodifier_len)
            menuitemmodifier_len = idmlist[i].cmd + 1;

    menuitemmodifier = (char**) lib_calloc(menuitemmodifier_len, sizeof(char*));
    memset(menuitemmodifier, 0, menuitemmodifier_len * sizeof(char*));

    fshortcuts = sysfile_open("win_shortcuts.vsc", &complete_path, MODE_READ_TEXT);
    lib_free(complete_path);
    if (fshortcuts == NULL) {
        log_error(LOG_DEFAULT, "Warning. Cannot open keyboard shortcut file win_shortcuts.vsc.");
        return NULL;
    }

    /* read the shortcut table */
    do {
        buffer[0] = 0;
        if (fgets(buffer, 999, fshortcuts)) {

            if (strlen(buffer) == 0)
                break;

            buffer[strlen(buffer) - 1] = 0; /* remove newline */
	        /* remove comments */
	        if((p = strchr(buffer, '#')))
	            *p=0;

            metastr = strtok(buffer, " \t:");
            keystr = strtok(NULL, " \t:");
            menustr = strtok(NULL, " \t:");
            displaystr = strtok(NULL, " \t:");
	        if (displaystr && (p = strchr(displaystr, '#')))
	            *p=0;

            if (metastr && keystr && menustr) {
                for (i = 0; idmlist[i].str; i++) {
                    if (strcmp(idmlist[i].str, menustr) == 0)
                        break;
                }

                if (idmlist[i].str) {
                    ACCEL accel;

                    accel.fVirt = FVIRTKEY | FNOINVERT;
                    if (strstr(strlwr(metastr), "ctrl") != NULL)
                        accel.fVirt |= FCONTROL;
                    if (strstr(strlwr(metastr), "alt") != NULL)
                        accel.fVirt |= FALT;

                    if (keystr[0] == '\'' && keystr[2] == '\'') {
                        accel.key = keystr[1];
                        if (displaystr == NULL || displaystr[0] == 0) {
                            displaystr = keystr + 1;
                            keystr[2] = 0;
                        }
                    } else {
                        accel.key = (unsigned short)strtol(keystr, NULL, 0);
                    }

                    accel.cmd = idmlist[i].cmd;

                    if (accel.key > 0 && accel.cmd > 0 && accelnum < MAXACCEL)
                        accellist[accelnum++] = accel;

                    if (displaystr != NULL) {
                        p = util_concat("\t",
                                    ((accel.fVirt & FCONTROL) ? "Ctrl+" : ""),
                                    ((accel.fVirt & FALT) ? "Alt+" : ""),
                                    displaystr, NULL);

                        menuitemmodifier[accel.cmd] = p;
                    }
                }
            }
        }
    } while (!feof(fshortcuts));
    fclose(fshortcuts);

    return CreateAcceleratorTable(accellist, accelnum);
}
Пример #12
0
DIAGNOSTIC *
sasl_login (BP_CONNECTION             *bp,
            char                      *serverName) {
    char                *cp,
                        *mechanism;
    DIAGNOSTIC          *d;
    PRO_LOCALDATA       *il;
    PROFILE              ps,
                        *p = &ps;
    struct configobj    *appconfig = bp_get_config (bp);

    if (((cp = config_get (appconfig, SASL_REMOTE_CODE)) != NULL)
            && (*cp == '2'))
        return bp_diagnostic_new (bp, 520, NULL,
                                  "already tuned for authentication");

    if (!(mechanism = config_get (appconfig,
                                  SASL_LOCAL_MECHANISM)))
        return bp_diagnostic_new (bp, 501, NULL, "mechanism undefined");

    if (!(il = (PRO_LOCALDATA *) lib_malloc (sizeof *il)))
        return bp_diagnostic_new (bp, 421, NULL, "out of memory");

    memset (il, 0, sizeof *il);
    il -> pl_flags = PRO_INITIATOR | PRO_STARTING | PRO_CLOSED;
    il -> pl_sent = 1;

    memset (p, 0, sizeof *p);

    if (!strcasecmp (mechanism, "anonymous")) {
        il -> pl_task = PRO_CLIENT_ANON;
        if (!(p -> uri = config_get (appconfig, SASL_ANONYMOUS_URI)))
            p -> uri = PRO_ANONYMOUS_URI;
        p -> piggyback =
              sasl_anonymous_client_guts (config_get (appconfig,
                                                      SASL_LOCAL_TRACEINFO),
                                          &il -> pl_sdb);
    } else if (!strcasecmp (mechanism, "otp")) {
        char    *authenID,
                *authorID;

        il -> pl_task = PRO_CLIENT_OTP;
        if (!(p -> uri = config_get (appconfig, SASL_OTP_URI)))
            p -> uri = PRO_OTP_URI;
        if (!(authenID = config_get (appconfig, SASL_LOCAL_USERNAME))) {
            lib_free (il);
            return bp_diagnostic_new (bp, 501, NULL,
                                      "authentication ID undefined");
        }
        authorID = config_get (appconfig, SASL_LOCAL_TARGET);

        p -> piggyback = sasl_otp_client_guts_1 (authenID, authorID,
                                                 &il -> pl_sdb);
    } else {
        lib_free (il);
        return bp_diagnostic_new (bp, 501, NULL, "mechanism unknown: %s",
                                  mechanism);
    }
    p -> piggyback_length = strlen (p -> piggyback);

    config_delete (appconfig, SASL_LOCAL_CODE);
    config_delete (appconfig, SASL_LOCAL_REASON);
    config_set (appconfig, SASL_LOCAL_MECHANISM, mechanism);

    if ((d = bp_start_request (bp, BLU_CHAN0_CHANO_DEFAULT,
                               BLU_CHAN0_MSGNO_DEFAULT, p, serverName, NULL,
                               (void *) il)) != NULL)
        goto out;

    while ((il -> pl_status == NULL)
               && ((il -> pl_flags & (PRO_STARTING|PRO_CLOSED)) != PRO_CLOSED)
               && (bp -> status != INST_STATUS_EXIT))
        YIELD ();

    if (!il -> pl_status) {
        d =  bp_diagnostic_new (bp, 450, NULL,
                                bp -> status != INST_STATUS_EXIT
                                    ? "lost channel during tuning"
                                    : "lost session during tuning");
        goto out;
    }

    if (il -> pl_status -> code >= 400)
        d = il -> pl_status;
    else
        bp_diagnostic_destroy (NULL, il -> pl_status);

out: ;
    if (!(il -> pl_flags & PRO_CLOSED))
        il -> pl_channel -> profile -> user_ptr1 = NULL;

    lib_free (il);

    return d;
}
Пример #13
0
void tfe_resources_shutdown(void)
{
    lib_free(tfe_interface);
}
Пример #14
0
void functionrom_resources_shutdown(void)
{
    lib_free(internal_function_rom_name);
    lib_free(external_function_rom_name);
}
Пример #15
0
void fliplist_shutdown(void)
{
    lib_free(current_image);
    current_image = NULL;
}
Пример #16
0
void uicommands_shutdown(void)
{
    lib_free(load_snapshot_last_dir);
}
Пример #17
0
void fliplist_set_current(unsigned int unit, const char *filename)
{
    lib_free(current_image);
    current_image = lib_stralloc(filename);
    current_drive = unit;
}
Пример #18
0
void closedir(DIR *dir)
{
    FindClose(dir->handle);
    lib_free(dir->filter);
    lib_free(dir);
}
Пример #19
0
static int vdrive_command_rename(vdrive_t *vdrive, BYTE *dest, int length)
{
    BYTE *src;
    BYTE *slot;
    int status = CBMDOS_IPE_OK, rc;
    cbmdos_cmd_parse_t cmd_parse_dst, cmd_parse_src;

    if (!dest || !(src = memchr((char *)++dest, '=', length)) ) {
        return CBMDOS_IPE_SYNTAX;
    }
    *src++ = 0;

#ifdef DEBUG_DRIVE
    log_debug("RENAME: dest= '%s', orig= '%s'.", dest, src);
#endif

    cmd_parse_dst.cmd = dest;
    cmd_parse_dst.cmdlength = (unsigned int)strlen((char *)dest);
    cmd_parse_dst.readmode = CBMDOS_FAM_READ;

    rc = cbmdos_command_parse(&cmd_parse_dst);

    if (rc == FLOPPY_ERROR) {
        status = CBMDOS_IPE_SYNTAX;
        goto out1;
    }

    cmd_parse_src.cmd = src;
    cmd_parse_src.cmdlength = (unsigned int)strlen((char *)src);
    cmd_parse_src.readmode = CBMDOS_FAM_READ;

    rc = cbmdos_command_parse(&cmd_parse_src);

    if (rc == FLOPPY_ERROR) {
        status = CBMDOS_IPE_SYNTAX;
        goto out2;
    }

    if (vdrive->image->read_only || VDRIVE_IMAGE_FORMAT_4000_TEST) {
        status = CBMDOS_IPE_WRITE_PROTECT_ON;
        goto out2;
    }

    /* Check if the destination name is already in use.  */

    vdrive_dir_find_first_slot(vdrive, cmd_parse_dst.parsecmd,
                               cmd_parse_dst.parselength,
                               cmd_parse_dst.filetype);

    slot = vdrive_dir_find_next_slot(vdrive);

    if (slot) {
        status = CBMDOS_IPE_FILE_EXISTS;
        goto out2;
    }

    /* Find the file to rename. */

    vdrive_dir_find_first_slot(vdrive, cmd_parse_src.parsecmd,
                               cmd_parse_src.parselength,
                               cmd_parse_src.filetype);

    slot = vdrive_dir_find_next_slot(vdrive);

    if (!slot) {
        status = CBMDOS_IPE_NOT_FOUND;
        goto out2;
    }

    /* Now we can replace the old file name...  */
    /* We write directly to the Dir_buffer.  */

    slot = &vdrive->Dir_buffer[vdrive->SlotNumber * 32];
    memset(slot + SLOT_NAME_OFFSET, 0xa0, 16);
    memcpy(slot + SLOT_NAME_OFFSET, cmd_parse_dst.parsecmd,
           cmd_parse_dst.parselength);

    /* FIXME: is this right? */
    if (cmd_parse_dst.filetype)
        slot[SLOT_TYPE_OFFSET] = cmd_parse_dst.filetype;

    /* Update the directory.  */
    if (vdrive_write_sector(vdrive, vdrive->Dir_buffer,
        vdrive->Curr_track, vdrive->Curr_sector) < 0)
        status = CBMDOS_IPE_WRITE_ERROR_VER;

out2:
    lib_free(cmd_parse_src.parsecmd);
out1:
    lib_free(cmd_parse_dst.parsecmd);

    return status;
}
Пример #20
0
void c64exp_resources_shutdown(void)
{
    lib_free(profdos_1571_name);
    lib_free(supercard_name);
}
Пример #21
0
int vdrive_command_execute(vdrive_t *vdrive, const BYTE *buf,
                           unsigned int length)
{
    int status = CBMDOS_IPE_INVAL;
    BYTE *p, *minus;
    char *name;

    if (!length)
        return CBMDOS_IPE_OK;
    if (length > IP_MAX_COMMAND_LEN) {
        vdrive_command_set_error(vdrive, CBMDOS_IPE_LONG_LINE, 0, 0);
        return CBMDOS_IPE_LONG_LINE;
    }

    if (buf[length - 1] == 0x0d) {
        --length; /* chop CR character */
    }

    p = lib_malloc(length + 1);
    memcpy(p, buf, length);
    p[length] = 0;

    minus = (BYTE *)memchr(p, '-', length);
    name = (char *)memchr(p, ':', length);

#ifdef DEBUG_DRIVE
    log_debug("Command '%c' (%s).", *p, p);
#endif

    switch (*p) {
      case 'M':
      case 'P':
        break;          /* In binary commands, colons are data */
      default:
        if (name) {     /* Fix name length */
            length -= (BYTE *)name - p;
        }
    }

    switch (*p) {
      case 'C':         /* Copy */
        if (p[1] == 'D' && vdrive->image_format == VDRIVE_IMAGE_FORMAT_4000) {
            if (!name) { /* CD_ doesn't allow a : */
                name = (char *)(p + 1);
            }
            status = vdrive_command_chdir(vdrive, (BYTE *)name, length);
        } else {
            status = vdrive_command_copy(vdrive, (char *)name, length);
        }
        break;

      case '/':         /* change partition */
        if ((vdrive->image_format == VDRIVE_IMAGE_FORMAT_1581) ||
            (vdrive->image_format == VDRIVE_IMAGE_FORMAT_4000)) {
            if (!name) { /* handle "/dir" */
                name = (char *)(p + 1);
                --length;
            }
            status = vdrive_command_chpart(vdrive, (BYTE *)name, length);
        }
        break;

#if 0
      case 'D':         /* Duplicate is unused */
        break;
#endif

      case 'R':         /* Rename */
        status = vdrive_command_rename(vdrive, (BYTE *)name, length);
        break;

      case 'S':         /* Scratch */
        status = vdrive_command_scratch(vdrive, (BYTE *)name, length);
        break;

      case 'I':
        status = vdrive_command_initialize(vdrive);
        break;

      case 'N':
        /* Skip ":" at the start of the name.  */
        status = vdrive_command_format(vdrive,
                                       (name == NULL) ? NULL : name + 1);
        break;

      case 'V':
        status = vdrive_command_validate(vdrive);
        break;

      case 'B': /* Block, Buffer */
        if (!name)      /* B-x does not require a : */
            name = (char *)(p + 2);
        if (minus) {
            status = vdrive_command_block(vdrive, minus[1], name + 1);
        }
        break;

      case 'M': /* Memory */
        if (minus) {
            status = vdrive_command_memory(vdrive, minus + 1, length);
        }
        break;

      case 'P': /* Position */
        status = vdrive_command_position(vdrive, p, length);
        break;

      case 'U': /* User */
        if (!name) {    /* Colons are optional */
            name = (char *)(p + 1);
        }
        switch (p[1] & 0x0f) {
          case 1: /* UA */
            if (name)
                status = vdrive_command_block(vdrive, (unsigned char)0xd2, name + 1);
            break;

          case 2: /* UB */
            if (name)
                status = vdrive_command_block(vdrive, (unsigned char)0xd7, name + 1);
            break;

          case 3: /* Jumps */
          case 4:
          case 5:
          case 6:
          case 7:
          case 8:
            status = CBMDOS_IPE_NOT_READY;
            break;

          case 9: /* UI */
            if (p[2] == '-' || p[2] == '+') {
                status = CBMDOS_IPE_OK; /* Set IEC bus speed */
                break;
            }
            /* Fall through. */
          case 10: /* U:, UJ */
            vdrive_close_all_channels(vdrive); /* Warm/Cold reset */
            status = CBMDOS_IPE_DOS_VERSION;
            break;

          default: /* U0, UK..UO */
            if (p[1] == '0') {
                status = CBMDOS_IPE_OK;
                break;
            }
            status = CBMDOS_IPE_NOT_READY;
            break;
        } /* Un */
        break;

      default:
        break;
    } /* commands */

    if (status == CBMDOS_IPE_INVAL) {
        log_error(vdrive_command_log, "Wrong command `%s'.", p);
    }

    vdrive_command_set_error(vdrive, status, 0, 0);

    lib_free((char *)p);
    return status;
}
Пример #22
0
void archdep_shutdown_extra(void)
{
    lib_free(argv0);
}
Пример #23
0
void expert_resources_shutdown(void)
{
    lib_free(expert_filename);
    expert_filename = NULL;
}
Пример #24
0
static void update_inputs(ULONG ID)
{
    char name[256];
    unsigned int i;
    int num, offset;

    for (i = 0; i < inputs.count; i++) {
        lib_free(inputs.names[i]);
    }
    memset(&inputs, 0, sizeof(inputs));

    inputs.offsets[0] = 0;
    inputs.names[0] = lib_stralloc("-");
    inputs.types[0] = TYPE_NONE;
    inputs.count++;

    if (ID == -1) {
        return;
    }

    /* BUTTON */
    AIN_Query(CTX, ID, AINQ_NUMBUTTONS, 0, &num, sizeof(num));
    AIN_Query(CTX, ID, AINQ_BUTTON_OFFSET, 0, &offset, sizeof(offset));
    for (i = 0; i < num; i++) {
        name[0] = '\0';
        AIN_Query(CTX, ID, AINQ_BUTTONNAME, i, name, sizeof(name));
        if (name[0] != '\0') {
            inputs.offsets[inputs.count] = offset + i;
            inputs.names[inputs.count] = lib_stralloc(name);
            inputs.types[inputs.count] = TYPE_BUTTON;
            inputs.count++;
        }
    }

    /* AXES */
    AIN_Query(CTX, ID, AINQ_NUMAXES, 0, &num, sizeof(num));
    AIN_Query(CTX, ID, AINQ_AXIS_OFFSET, 0, &offset, sizeof(offset));
    for (i = 0; i < num; i++) {
        name[0] = '\0';
        AIN_Query(CTX, ID, AINQ_AXISNAME, i, name, sizeof(name));
        if (name[0] != '\0') {
            inputs.offsets[inputs.count] = offset + i;
            inputs.names[inputs.count] = lib_stralloc(name);
            inputs.types[inputs.count] = TYPE_AXES;
            inputs.count++;
        }
    }

    /* HATS */
    AIN_Query(CTX, ID, AINQ_NUMHATS, 0, &num, sizeof(num));
    AIN_Query(CTX, ID, AINQ_HAT_OFFSET, 0, &offset, sizeof(offset));
    for (i = 0; i < num; i++) {
        name[0] = '\0';
        AIN_Query(CTX, ID, AINQ_HATNAME, i, name, sizeof(name));
        if (name[0] != '\0') {
            inputs.offsets[inputs.count] = offset + i;
            inputs.names[inputs.count] = lib_stralloc(name);
            inputs.types[inputs.count] = TYPE_HAT;
            inputs.count++;
        }
    }
}
Пример #25
0
void digimax_resources_shutdown(void)
{
    if (digimax_address_list) {
        lib_free(digimax_address_list);
    }
}
Пример #26
0
void rtc58321a_destroy(rtc_58321a_t *context)
{
    lib_free(context);
}
Пример #27
0
int __F_NAME(__cenvarg,__wcenvarg)(
/*
 *  Build environment and command line for new process.  Length of environment
 *  (in bytes) is returned on success.  -1 is returned on failure.
 */
    const CHAR_TYPE     *const argv[],  /* i: arguments for new process */
    const CHAR_TYPE     *const envp[],  /* i: env strings for new process */
    CHAR_TYPE           **_envptr,      /* o: environment ptr (unaligned) */
    CHAR_TYPE           **envptr,       /* o: environment ptr (DOS 16-bit aligned to para) */
    unsigned            *envseg,        /* o: environment segment (DOS 16-bit normalized, zero for others) */
    size_t              *cmdline_len,   /* o: size required to hold cmd line */
    int                 exec )          /* i: TRUE if for exec */
{
    unsigned            length;         /* environment length in bytes */
    unsigned            old_amblksiz;
    CHAR_TYPE           *p;
    CHAR_TYPE _WCNEAR   *np;
    unsigned            len;            /* command line length in characters */
    int                 i;

#if !defined( __DOS_086__ )
    exec = exec;
#endif
    if( envp == NULL ) {
#ifdef __WIDECHAR__
        if( _RWD_wenviron == NULL )
            __create_wide_environment();
#endif
        envp = (const CHAR_TYPE * const *)__F_NAME(_RWD_environ,_RWD_wenviron);
    }
    length = 0;
    if( envp != NULL ) {
        for( i = 0; envp[i] != NULL; i++ ) {
            length += ( __F_NAME(strlen,wcslen)( envp[i] ) + 1 ) * sizeof( CHAR_TYPE );
        }
    }
    length += sizeof( CHAR_TYPE ); /* trailing \0 for env */
#if defined( __DOS_086__ )
    if( exec ) {
        /* store argv[0] at 2 bytes past end of env */
        length += 2;
        length += strlen( argv[0] ) + 1;
    }
#endif
    /* round environment length to para */
    length = __ROUND_UP_SIZE_PARA( length );
#if defined( __DOS_086__ )
    /* add space for pointer alignment */
    /* so we can start on a paragraph boundary even if memory pointer is not aligned to para */
    length += 15;
#endif
    /* allocate space for new environment */
    old_amblksiz = _RWD_amblksiz;
    _RWD_amblksiz = 16; /* force allocation in 16 byte increments */
    p = np = lib_nmalloc( length );
    if( np == NULL ) {
        p = lib_malloc( length );
        if( p == NULL ) {
            _RWD_errno = ENOMEM;
            _RWD_doserrno = E_nomem;
            _RWD_amblksiz = old_amblksiz;
            return( -1 );
        }
    }
    _RWD_amblksiz = old_amblksiz;
    *_envptr = p;
#if defined( __DOS_086__ )
    /* align DOS 16-bit environment pointer to para boundary */
  #if defined(__SMALL_DATA__)
    p = (char *)__ROUND_UP_SIZE_PARA( FP_OFF( p ) );
  #else     /* __LARGE_DATA__ */
    p = MK_FP( FP_SEG( p ), __ROUND_UP_SIZE_PARA( FP_OFF( p ) ) );
  #endif
    /* normalize DOS 16-bit aligned environment pointer to segment */
    *envseg = FP_SEG( p ) + __ROUND_DOWN_SIZE_TO_PARA( FP_OFF( p ) );
    /* correct environment length (subtract aditional pointer alignment space) */
    length -= 15;
#else
    *envseg = 0;
#endif
    *envptr = p;            /* save ptr to env strings. */
    if( envp != NULL ) {
        for( i = 0; envp[i] != NULL; ++i ) {
            p = stpcpy( p, envp[i] ) + 1;
        }
    }
    *p++ = NULLCHAR;
#if defined( __DOS_086__ )
    if( exec ) {
        *p++ = 1;
        *p++ = 0;
        strcpy( p, argv[0] );
    }
#endif
    len = 0;
    if( argv[0] != NULL ) {
        for( i = 1; argv[i] != NULL; ++i ) {
            if( len != 0 )
                ++len;       /* plus 1 for blank separator */
            len += __F_NAME(strlen,wcslen)( argv[i] );
        }
    }
#if defined( __NT__ )
    // we are going to add quotes around program name (argv[0])
    len += _MAX_PATH2 + 3;
#elif defined( __OS2__ )
    len += _MAX_PATH2 + 1;
#elif defined( __RDOS__ ) || defined( __RDOSDEV__ )
    len += _MAX_PATH2 + 1;
#else       /* __DOS__ */
    if( len > 126 ) {
        _RWD_errno = E2BIG;
        _RWD_doserrno = E_badenv;
        lib_free( *_envptr );
        return( -1 );
    }
    len = _MAX_PATH;    /* always use _MAX_PATH chars for DOS */
#endif
    *cmdline_len = len;

    /* convert environment length in bytes to length in para */
    return( __ROUND_DOWN_SIZE_TO_PARA( length ) );
}
Пример #28
0
static void command_directory_get(vdrive_t *vdrive, bufinfo_t *bufinfo,
                                  BYTE *data, unsigned int secondary)
{
    int i, l, f, statrc;
    unsigned int blocks;
    char *direntry;
    unsigned int filelen, isdir;
    fileio_info_t *finfo = NULL;
    unsigned int format = 0;
    char *buf;

    buf = lib_malloc(ioutil_maxpathlen());

    bufinfo->bufp = bufinfo->name;

    if (fsdevice_convert_p00_enabled[(vdrive->unit) - 8]) {
        format |= FILEIO_FORMAT_P00;
    }
    if (!fsdevice_hide_cbm_files_enabled[vdrive->unit - 8]) {
        format |= FILEIO_FORMAT_RAW;
    }

    /*
     * Find the next directory entry and return it as a CBM
     * directory line.
     */

    /* first test if dirmask is needed - maybe this should be
       replaced by some regex functions... */
    f = 1;
    do {
        BYTE *p;
        finfo = NULL;

        direntry = ioutil_readdir(bufinfo->ioutil_dir);

        if (direntry == NULL) {
            break;
        }

        finfo = fileio_open(direntry, bufinfo->dir, format,
                            FILEIO_COMMAND_STAT | FILEIO_COMMAND_FSNAME,
                            FILEIO_TYPE_PRG);

        if (finfo == NULL) {
            continue;
        }

        bufinfo->type = finfo->type;

        if (bufinfo->dirmask[0] == '\0') {
            break;
        }

        l = (int)strlen(bufinfo->dirmask);

        for (p = finfo->name, i = 0;
            *p && bufinfo->dirmask[i] && i < l; i++) {
            if (bufinfo->dirmask[i] == '?') {
                p++;
            } else if (bufinfo->dirmask[i] == '*') {
                if (!(bufinfo->dirmask[i + 1])) {
                    f = 0;
                    break;
                } /* end mask */
                while (*p && (*p != bufinfo->dirmask[i + 1])) {
                    p++;
                }
            } else {
                if (*p != bufinfo->dirmask[i]) {
                    break;
                }
                p++;
            }
            if ((!*p) && (!(bufinfo->dirmask[i + 1]))) {
                f = 0;
                break;
            }
        }
        if (f > 0) {
            fileio_close(finfo);
        }
    } while (f);

    if (direntry != NULL) {
        BYTE *p = bufinfo->name;

        strcpy(buf, bufinfo->dir);
        strcat(buf, FSDEV_DIR_SEP_STR);
        strcat(buf, direntry);

        /* Line link, Length and spaces */

        *p++ = 1;
        *p++ = 1;

        statrc = ioutil_stat(buf, &filelen, &isdir);
        if (statrc == 0) {
            blocks = (filelen + 253) / 254;
        } else {
            blocks = 0;   /* this file can't be opened */
        }

        if (blocks > 0xffff) {
            blocks = 0xffff; /* Limit file size to 16 bits.  */
        }

        SET_LO_HI(p, blocks);

        if (blocks < 10) {
            *p++ = ' ';
        }
        if (blocks < 100) {
            *p++ = ' ';
        }
        if (blocks < 1000) {
            *p++ = ' ';
        }

        /*
         * Filename
         */

        *p++ = '"';

        for (i = 0; finfo->name[i] && (*p = finfo->name[i]); ++i, ++p) {
            ;
        }

        *p++ = '"';
        for (; i < 16; i++) {
            *p++ = ' ';
        }

        if (isdir != 0) {
            *p++ = ' '; /* normal file */
            *p++ = 'D';
            *p++ = 'I';
            *p++ = 'R';
        } else {
            if (blocks) {
                *p++ = ' '; /* normal file */
            } else {
                *p++ = '*'; /* splat file */
            }
            switch(bufinfo->type) {
              case CBMDOS_FT_DEL:
                *p++ = 'D';
                *p++ = 'E';
                *p++ = 'L';
                break;
              case CBMDOS_FT_SEQ:
                *p++ = 'S';
                *p++ = 'E';
                *p++ = 'Q';
                break;
              case CBMDOS_FT_PRG:
                *p++ = 'P';
                *p++ = 'R';
                *p++ = 'G';
                break;
              case CBMDOS_FT_USR:
                *p++ = 'U';
                *p++ = 'S';
                *p++ = 'R';
                break;
              case CBMDOS_FT_REL:
                *p++ = 'R';
                *p++ = 'E';
                *p++ = 'L';
                break;
            }
        }

        if (ioutil_access(buf, IOUTIL_ACCESS_W_OK)) {
            *p++ = '<'; /* read-only file */
        }

        *p = '\0';        /* to allow strlen */

        /* some (really very) old programs rely on the directory
           entry to be 32 Bytes in total (incl. nullbyte) */
        l = (int)strlen((char *)(bufinfo->name + 4)) + 4;
        while (l < 31) {
            *p++ = ' ';
            l++;
        }

        *p++ = '\0';

        bufinfo->buflen = (int)(p - bufinfo->name);

    } else {
        BYTE *p = bufinfo->name;

        /* EOF => End file */

        *p++ = 1;
        *p++ = 1;
        *p++ = 0;
        *p++ = 0;
        memcpy(p, "BLOCKS FREE.", 12);
        p += 12;
        memset(p, ' ', 13);
        p += 13;

        memset(p, 0, 3);
        bufinfo->buflen = 32;
        bufinfo->eof++;
    }

    if (finfo != NULL) {
        fileio_close(finfo);
    }

    lib_free(buf);
}
Пример #29
0
static GtkWidget *build_netplay_dialog(void)
{
    GtkWidget *d, *f, *b, *hb, *rb, *l, *entry, *h;
    char *unknown = util_concat("<", _("Unknown"), ">", NULL);
    char *connect_to = util_concat(_("Connect to"), " ", NULL);
    char *current_mode_text = util_concat(_("Current mode"), ": ", NULL);
    char *tcp_port = util_concat(_("TCP port"), ": ", NULL);

    d = gtk_dialog_new_with_buttons(_("Netplay Settings"), NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);

    f = gtk_frame_new(_("Netplay Settings"));

    h = gtk_hbox_new(FALSE, 5);
    ctrls = b = gtk_vbox_new(FALSE, 5);

    hb = gtk_hbox_new(FALSE, 0);
    l = gtk_label_new(current_mode_text);
    gtk_container_add(GTK_CONTAINER(hb), l);
    gtk_widget_show(l);
    current_mode = gtk_label_new(unknown);
    lib_free(unknown);
    lib_free(current_mode_text);

    gtk_container_add(GTK_CONTAINER(hb), current_mode);
    gtk_widget_show(current_mode);
    gtk_box_pack_start(GTK_BOX(b), hb, FALSE, FALSE, 5);
    gtk_widget_show(hb);

    /* button "start server" */
    hb = gtk_hbox_new(FALSE, 0);
    rb = gtk_button_new_with_label(_("Start server"));
    gtk_box_pack_start(GTK_BOX(hb), rb, FALSE, FALSE, 5);
    g_signal_connect(G_OBJECT(rb), "clicked", G_CALLBACK(netplay_start_server), rb);
    gtk_widget_set_can_focus(rb, 0);
    gtk_widget_show(rb);

    l = gtk_label_new(tcp_port);
    gtk_container_add(GTK_CONTAINER(hb), l);
    gtk_widget_show(l);
    lib_free(tcp_port);

    /* entry IP server bind address */
    np_server_bind = entry = gtk_entry_new();
    gtk_box_pack_start(GTK_BOX(hb), entry, FALSE, FALSE, 0);
    gtk_widget_set_size_request(entry, 100, -1);
    gtk_widget_show(entry);

    /* entry port */
    np_port = entry = gtk_entry_new();
    gtk_box_pack_start(GTK_BOX(hb), entry, FALSE, FALSE, 0);
    gtk_widget_set_size_request(entry, 50, -1);
    gtk_widget_show(entry);

    gtk_box_pack_start(GTK_BOX(b), hb, FALSE, FALSE, 5);
    gtk_widget_show(hb);

    /* button "connect to server" */
    hb = gtk_hbox_new(FALSE, 0);
    rb = gtk_button_new_with_label(connect_to);
    gtk_box_pack_start(GTK_BOX(hb), rb, FALSE, FALSE, 5);
    g_signal_connect(G_OBJECT(rb), "clicked", G_CALLBACK(netplay_connect), rb);
    gtk_widget_set_can_focus(rb, 0);
    gtk_widget_show(rb);
    lib_free(connect_to);

    /* entry "remote IP" */
    np_server = entry = gtk_entry_new();
    gtk_box_pack_start(GTK_BOX(hb), entry, FALSE, FALSE, 0);
    gtk_widget_set_size_request(entry, 100, -1);
    gtk_widget_show(entry);

    gtk_box_pack_start(GTK_BOX(b), hb, FALSE, FALSE, 5);
    gtk_widget_show(hb);

    gtk_box_pack_start(GTK_BOX(h), b, FALSE, FALSE, 5);
    gtk_widget_show(b);

    /* Control widgets */
    {
        GtkWidget *cf, *tmp, *table;
        int i;

        cf = gtk_frame_new(_("Control"));
        gtk_box_pack_start(GTK_BOX(h), cf, FALSE, FALSE, 5);
        gtk_widget_show(cf);

        table = gtk_table_new(NR_NPCONROLS + 1, 3, FALSE);
        tmp = gtk_label_new(_("Server"));
        gtk_table_attach(GTK_TABLE(table), tmp, 1, 2, 0, 1, 0, 0, 5, 0);
        gtk_widget_show(tmp);
        tmp = gtk_label_new(_("Client"));
        gtk_table_attach(GTK_TABLE(table), tmp, 2, 3, 0, 1, 0, 0, 5, 0);
        gtk_widget_show(tmp);

        for (i = 0; i < NR_NPCONROLS; i++) {
            tmp = gtk_label_new(_(np_controls[i].name));
            gtk_table_attach_defaults(GTK_TABLE(table), tmp, 0, 1, i + 1, i + 2);
            gtk_widget_show(tmp);
            np_controls[i].s_cb = gtk_check_button_new();
            gtk_table_attach_defaults(GTK_TABLE(table), np_controls[i].s_cb, 1, 2, i + 1, i + 2);
            g_signal_connect(G_OBJECT(np_controls[i].s_cb), "toggled", G_CALLBACK(netplay_update_control_res), (gpointer)&np_controls[i].s_mask);
            gtk_widget_show(np_controls[i].s_cb);
            np_controls[i].c_cb = gtk_check_button_new();
            gtk_table_attach_defaults(GTK_TABLE(table), np_controls[i].c_cb, 2, 3, i + 1, i + 2);
            g_signal_connect(G_OBJECT(np_controls[i].c_cb), "toggled", G_CALLBACK(netplay_update_control_res), (gpointer)&np_controls[i].c_mask);
            gtk_widget_show(np_controls[i].c_cb);
        }
        gtk_container_add(GTK_CONTAINER(cf), table);
        gtk_widget_show(table);
    }

    gtk_container_add(GTK_CONTAINER(f), h);
    gtk_widget_show(h);
    gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(d))), f, TRUE, TRUE, 0);
    gtk_widget_show(f);

    dcb = rb = gtk_button_new_with_label(_("Disconnect"));
    gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(d))), rb, FALSE, FALSE, 5);
    g_signal_connect(G_OBJECT(rb), "clicked", G_CALLBACK(netplay_disconnect), rb);
    gtk_widget_set_can_focus(rb, 0);
    gtk_widget_show(rb);

    netplay_update_status();

    /* gtk_dialog_close_hides(GTK_DIALOG(d), TRUE); */
    return d;
}
Пример #30
0
int tapeport_snapshot_read_module(snapshot_t *s)
{
    BYTE major_version, minor_version;
    snapshot_module_t *m;
    int amount = 0;
    char **detach_resource_list = NULL;
    tapeport_device_list_t *current = tapeport_head.next;
    int *devices = NULL;
    tapeport_snapshot_list_t *c = NULL;
    int i = 0;

    /* detach all tapeport devices */
    while (current) {
        ++amount;
        current = current->next;
    }

    if (amount) {
        detach_resource_list = lib_malloc(sizeof(char *) * (amount + 1));
        memset(detach_resource_list, 0, sizeof(char *) * (amount + 1));
        current = tapeport_head.next;
        while (current) {
            detach_resource_list[i++] = current->device->resource;
            current = current->next;
        }
        for (i = 0; i < amount; ++i) {
            resources_set_int(detach_resource_list[i], 0);
        }
        lib_free(detach_resource_list);
    }

    m = snapshot_module_open(s, snap_module_name, &major_version, &minor_version);

    if (m == NULL) {
        return -1;
    }

    /* Do not accept versions higher than current */
    if (major_version > SNAP_MAJOR || minor_version > SNAP_MINOR) {
        snapshot_set_error(SNAPSHOT_MODULE_HIGHER_VERSION);
        goto fail;
    }

    if (0
        || SMR_B_INT(m, &tapeport_active) < 0
        || SMR_B_INT(m, &amount) < 0) {
        goto fail;
    }

    if (amount) {
        devices = lib_malloc(sizeof(int) * (amount + 1));
        for (i = 0; i < amount; ++i) {
            if (SMR_B_INT(m, &devices[i]) < 0) {
                lib_free(devices);
                goto fail;
            }
        }
        snapshot_module_close(m);
        for (i = 0; i < amount; ++i) {
            c = tapeport_snapshot_head.next;
            while (c) {
                if (c->snapshot->id == devices[i]) {
                    if (c->snapshot->read_snapshot) {
                        if (c->snapshot->read_snapshot(s) < 0) {
                            lib_free(devices);
                            return -1;
                        }
                    }
                }
                c = c->next;
            }
        }
        return 0;
    }

    return snapshot_module_close(m);

fail:
    snapshot_module_close(m);
    return -1;
}