From 8be3dad54301c3f3bd9155621e35d301db1c399f Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 20 Aug 2018 20:57:45 -0400 Subject: [PATCH] uncrustify. --- src/host_common.c | 1361 ++++++++++++++++--------------- src/host_common.h | 56 +- src/host_fst.c | 4 +- src/host_mli.c | 1990 ++++++++++++++++++++++----------------------- 4 files changed, 1705 insertions(+), 1706 deletions(-) diff --git a/src/host_common.c b/src/host_common.c index 666d4bb..ddb12d4 100644 --- a/src/host_common.c +++ b/src/host_common.c @@ -16,7 +16,7 @@ #include "host_common.h" -#if defined(__APPLE__) +#if defined(__APPLE__) #include #include #include @@ -28,7 +28,7 @@ #endif -#if defined(_WIN32) || defined(WIN_SDL) +#if defined(_WIN32) || defined(WIN_SDL) #include #include #endif @@ -66,39 +66,39 @@ int g_cfg_host_merlin = 0; unsigned host_startup(void) { - struct stat st; + struct stat st; - if (!g_cfg_host_path) return invalidFSTop; - if (!*g_cfg_host_path) return invalidFSTop; - if (host_root) free(host_root); - host_root = strdup(g_cfg_host_path); + if (!g_cfg_host_path) return invalidFSTop; + if (!*g_cfg_host_path) return invalidFSTop; + if (host_root) free(host_root); + host_root = strdup(g_cfg_host_path); - host_read_only = g_cfg_host_read_only; + host_read_only = g_cfg_host_read_only; - if (stat(host_root, &st) < 0) { - fprintf(stderr, "%s does not exist\n", host_root); - return invalidFSTop; - } - if (!S_ISDIR(st.st_mode)) { - fprintf(stderr, "%s is not a directory\n", host_root); - return invalidFSTop; - } + if (stat(host_root, &st) < 0) { + fprintf(stderr, "%s does not exist\n", host_root); + return invalidFSTop; + } + if (!S_ISDIR(st.st_mode)) { + fprintf(stderr, "%s is not a directory\n", host_root); + return invalidFSTop; + } - root_ino = st.st_ino; - root_dev = st.st_dev; + root_ino = st.st_ino; + root_dev = st.st_dev; - return 0; + return 0; } void host_shutdown(void) { - if (host_root) free(host_root); - host_root = NULL; - root_ino = 0; - root_dev = 0; + if (host_root) free(host_root); + host_root = NULL; + root_ino = 0; + root_dev = 0; } int host_is_root(struct stat *st) { - return st->st_ino == root_ino && st->st_dev == root_dev; + return st->st_ino == root_ino && st->st_dev == root_dev; } @@ -110,111 +110,111 @@ static void *gc[16]; static void **gc_ptr = &gc[0]; void *host_gc_malloc(size_t size) { - if (gc_ptr == &gc[16]) { - errno = ENOMEM; - return NULL; - } + if (gc_ptr == &gc[16]) { + errno = ENOMEM; + return NULL; + } - void *ptr = malloc(size); - if (ptr) { - *gc_ptr++ = ptr; - } - return ptr; + void *ptr = malloc(size); + if (ptr) { + *gc_ptr++ = ptr; + } + return ptr; } void host_gc_free(void) { - while (gc_ptr > gc) free(*--gc_ptr); + while (gc_ptr > gc) free(*--gc_ptr); } char *host_gc_strdup(const char *src) { - if (!src) return ""; - if (!*src) return ""; - int len = strlen(src) + 1; - char *cp = host_gc_malloc(len); - memcpy(cp, src, len); - return cp; + if (!src) return ""; + if (!*src) return ""; + int len = strlen(src) + 1; + char *cp = host_gc_malloc(len); + memcpy(cp, src, len); + return cp; } char *host_gc_append_path(const char *a, const char *b) { - /* strip all leading /s from b) */ - while (*b == '/') ++b; + /* strip all leading /s from b) */ + while (*b == '/') ++b; - int aa = strlen(a); - int bb = strlen(b); + int aa = strlen(a); + int bb = strlen(b); - char *cp = host_gc_malloc(aa + bb + 2); - if (!cp) return NULL; - memcpy(cp, a, aa); - int len = aa; + char *cp = host_gc_malloc(aa + bb + 2); + if (!cp) return NULL; + memcpy(cp, a, aa); + int len = aa; - /* strip all trailing /s from b */ - while (len > 2 && cp[len-1] == '/') --len; - cp[len++] = '/'; - memcpy(cp + len, b, bb); - len += bb; - cp[len] = 0; - return cp; + /* strip all trailing /s from b */ + while (len > 2 && cp[len-1] == '/') --len; + cp[len++] = '/'; + memcpy(cp + len, b, bb); + len += bb; + cp[len] = 0; + return cp; } char *host_gc_append_string(const char *a, const char *b) { - int aa = strlen(a); - int bb = strlen(b); + int aa = strlen(a); + int bb = strlen(b); - char *cp = host_gc_malloc(aa + bb + 2); - if (!cp) return NULL; - memcpy(cp, a, aa); - int len = aa; - memcpy(cp + len, b, bb); - len += bb; - cp[len] = 0; - return cp; + char *cp = host_gc_malloc(aa + bb + 2); + if (!cp) return NULL; + memcpy(cp, a, aa); + int len = aa; + memcpy(cp + len, b, bb); + len += bb; + cp[len] = 0; + return cp; } -/* +/* * text conversion. */ void host_cr_to_lf(byte *buffer, size_t size) { - size_t i; - for (i = 0; i < size; ++i) { - if (buffer[i] == '\r') buffer[i] = '\n'; - } + size_t i; + for (i = 0; i < size; ++i) { + if (buffer[i] == '\r') buffer[i] = '\n'; + } } void host_lf_to_cr(byte *buffer, size_t size) { - size_t i; - for (i = 0; i < size; ++i) { - if (buffer[i] == '\n') buffer[i] = '\r'; - } + size_t i; + for (i = 0; i < size; ++i) { + if (buffer[i] == '\n') buffer[i] = '\r'; + } } void host_merlin_to_text(byte *buffer, size_t size) { - size_t i; - for (i = 0; i < size; ++i) { - byte b = buffer[i]; - if (b == 0xa0) b = '\t'; - b &= 0x7f; - if (b == '\r') b = '\n'; - buffer[i] = b; - } + size_t i; + for (i = 0; i < size; ++i) { + byte b = buffer[i]; + if (b == 0xa0) b = '\t'; + b &= 0x7f; + if (b == '\r') b = '\n'; + buffer[i] = b; + } } void host_text_to_merlin(byte *buffer, size_t size) { - size_t i; - for (i = 0; i < size; ++i) { - byte b = buffer[i]; - if (b == '\t') b = 0xa0; - if (b == '\n') b = '\r'; - if (b != ' ') b |= 0x80; - buffer[i] = b; - } + size_t i; + for (i = 0; i < size; ++i) { + byte b = buffer[i]; + if (b == '\t') b = 0xa0; + if (b == '\n') b = '\r'; + if (b != ' ') b |= 0x80; + buffer[i] = b; + } } @@ -224,200 +224,200 @@ void host_text_to_merlin(byte *buffer, size_t size) { */ static word32 enoent(const char *path) { - /* - some op on path return ENOENT. check if it's - fileNotFound or pathNotFound - */ - char *p = (char *)path; - for(;;) { - struct stat st; - p = dirname(p); - if (p == NULL) break; - if (p[0] == '.' && p[1] == 0) break; - if (p[0] == '/' && p[1] == 0) break; - if (stat(p, &st) < 0) return pathNotFound; - } - return fileNotFound; + /* + some op on path return ENOENT. check if it's + fileNotFound or pathNotFound + */ + char *p = (char *)path; + for(;;) { + struct stat st; + p = dirname(p); + if (p == NULL) break; + if (p[0] == '.' && p[1] == 0) break; + if (p[0] == '/' && p[1] == 0) break; + if (stat(p, &st) < 0) return pathNotFound; + } + return fileNotFound; } word32 host_map_errno(int xerrno) { - switch(xerrno) { - case 0: return 0; - case EBADF: - return invalidAccess; - case EDQUOT: - case EFBIG: - return volumeFull; - case ENOENT: - return fileNotFound; - case ENOTDIR: - return pathNotFound; - case ENOMEM: - return outOfMem; - case EEXIST: - return dupPathname; - default: - return drvrIOError; - } + switch(xerrno) { + case 0: return 0; + case EBADF: + return invalidAccess; + case EDQUOT: + case EFBIG: + return volumeFull; + case ENOENT: + return fileNotFound; + case ENOTDIR: + return pathNotFound; + case ENOMEM: + return outOfMem; + case EEXIST: + return dupPathname; + default: + return drvrIOError; + } } word32 host_map_errno_path(int xerrno, const char *path) { - if (xerrno == ENOENT) return enoent(path); - return host_map_errno(xerrno); + if (xerrno == ENOENT) return enoent(path); + return host_map_errno(xerrno); } const char *host_error_name(word16 error) { - static char *errors[] = { - "", - "badSystemCall", - "", - "", - "invalidPcount", - "", - "", - "gsosActive", - "", - "", - "", - "", - "", - "", - "", - "", - // 0x10 - "devNotFound", - "invalidDevNum", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - // 0x20 - "drvrBadReq", - "drvrBadCode", - "drvrBadParm", - "drvrNotOpen", - "drvrPriorOpen", - "irqTableFull", - "drvrNoResrc", - "drvrIOError", - "drvrNoDevice", - "drvrBusy", - "", - "drvrWrtProt", - "drvrBadCount", - "drvrBadBlock", - "drvrDiskSwitch", - "drvrOffLine", - // 0x30 - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - // 0x40 - "badPathSyntax", - "", - "tooManyFilesOpen", - "invalidRefNum", - "pathNotFound", - "volNotFound", - "fileNotFound", - "dupPathname", - "volumeFull", - "volDirFull", - "badFileFormat", - "badStoreType", - "eofEncountered", - "outOfRange", - "invalidAccess", - "buffTooSmall", - // 0x50 - "fileBusy", - "dirError", - "unknownVol", - "paramRangeErr", - "outOfMem", - "", - "badBufferAddress", /* P8 MLI only */ - "dupVolume", - "notBlockDev", - "invalidLevel", - "damagedBitMap", - "badPathNames", - "notSystemFile", - "osUnsupported", - "", - "stackOverflow", - // 0x60 - "dataUnavail", - "endOfDir", - "invalidClass", - "resForkNotFound", - "invalidFSTID", - "invalidFSTop", - "fstCaution", - "devNameErr", - "defListFull", - "supListFull", - "fstError", - "", - "", - "", - "", - "", - //0x70 - "resExistsErr", - "resAddErr", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - //0x80 - "", - "", - "", - "", - "", - "", - "", - "", - "networkError" - }; + static char *errors[] = { + "", + "badSystemCall", + "", + "", + "invalidPcount", + "", + "", + "gsosActive", + "", + "", + "", + "", + "", + "", + "", + "", + // 0x10 + "devNotFound", + "invalidDevNum", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + // 0x20 + "drvrBadReq", + "drvrBadCode", + "drvrBadParm", + "drvrNotOpen", + "drvrPriorOpen", + "irqTableFull", + "drvrNoResrc", + "drvrIOError", + "drvrNoDevice", + "drvrBusy", + "", + "drvrWrtProt", + "drvrBadCount", + "drvrBadBlock", + "drvrDiskSwitch", + "drvrOffLine", + // 0x30 + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + // 0x40 + "badPathSyntax", + "", + "tooManyFilesOpen", + "invalidRefNum", + "pathNotFound", + "volNotFound", + "fileNotFound", + "dupPathname", + "volumeFull", + "volDirFull", + "badFileFormat", + "badStoreType", + "eofEncountered", + "outOfRange", + "invalidAccess", + "buffTooSmall", + // 0x50 + "fileBusy", + "dirError", + "unknownVol", + "paramRangeErr", + "outOfMem", + "", + "badBufferAddress", /* P8 MLI only */ + "dupVolume", + "notBlockDev", + "invalidLevel", + "damagedBitMap", + "badPathNames", + "notSystemFile", + "osUnsupported", + "", + "stackOverflow", + // 0x60 + "dataUnavail", + "endOfDir", + "invalidClass", + "resForkNotFound", + "invalidFSTID", + "invalidFSTop", + "fstCaution", + "devNameErr", + "defListFull", + "supListFull", + "fstError", + "", + "", + "", + "", + "", + //0x70 + "resExistsErr", + "resAddErr", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + //0x80 + "", + "", + "", + "", + "", + "", + "", + "", + "networkError" + }; - if (error < sizeof(errors) / sizeof(errors[0])) - return errors[error]; - return ""; + if (error < sizeof(errors) / sizeof(errors[0])) + return errors[error]; + return ""; } @@ -427,186 +427,185 @@ const char *host_error_name(word16 error) { */ -static int hex(byte c) -{ - if (c >= '0' && c <= '9') return c - '0'; - if (c >= 'a' && c <= 'f') return c + 10 - 'a'; - if (c >= 'A' && c <= 'F') return c + 10 - 'A'; - return 0; +static int hex(byte c) { + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'a' && c <= 'f') return c + 10 - 'a'; + if (c >= 'A' && c <= 'F') return c + 10 - 'A'; + return 0; } static int finder_info_to_filetype(const byte *buffer, word16 *file_type, word32 *aux_type) { - if (!memcmp("pdos", buffer + 4, 4)) - { - if (buffer[0] == 'p') { - *file_type = buffer[1]; - *aux_type = (buffer[2] << 8) | buffer[3]; - return 0; - } - if (!memcmp("PSYS", buffer, 4)) { - *file_type = 0xff; - *aux_type = 0x0000; - return 0; - } - if (!memcmp("PS16", buffer, 4)) { - *file_type = 0xb3; - *aux_type = 0x0000; - return 0; - } + if (!memcmp("pdos", buffer + 4, 4)) + { + if (buffer[0] == 'p') { + *file_type = buffer[1]; + *aux_type = (buffer[2] << 8) | buffer[3]; + return 0; + } + if (!memcmp("PSYS", buffer, 4)) { + *file_type = 0xff; + *aux_type = 0x0000; + return 0; + } + if (!memcmp("PS16", buffer, 4)) { + *file_type = 0xb3; + *aux_type = 0x0000; + return 0; + } - // old mpw method for encoding. - if (!isxdigit(buffer[0]) && isxdigit(buffer[1]) && buffer[2] == ' ' && buffer[3] == ' ') - { - *file_type = (hex(buffer[0]) << 8) | hex(buffer[1]); - *aux_type = 0; - return 0; - } - } - if (!memcmp("TEXT", buffer, 4)) { - *file_type = 0x04; - *aux_type = 0x0000; - return 0; - } - if (!memcmp("BINA", buffer, 4)) { - *file_type = 0x00; - *aux_type = 0x0000; - return 0; - } - if (!memcmp("dImgdCpy", buffer, 8)) { - *file_type = 0xe0; - *aux_type = 0x0005; - return 0; - } + // old mpw method for encoding. + if (!isxdigit(buffer[0]) && isxdigit(buffer[1]) && buffer[2] == ' ' && buffer[3] == ' ') + { + *file_type = (hex(buffer[0]) << 8) | hex(buffer[1]); + *aux_type = 0; + return 0; + } + } + if (!memcmp("TEXT", buffer, 4)) { + *file_type = 0x04; + *aux_type = 0x0000; + return 0; + } + if (!memcmp("BINA", buffer, 4)) { + *file_type = 0x00; + *aux_type = 0x0000; + return 0; + } + if (!memcmp("dImgdCpy", buffer, 8)) { + *file_type = 0xe0; + *aux_type = 0x0005; + return 0; + } - if (!memcmp("MIDI", buffer, 4)) { - *file_type = 0xd7; - *aux_type = 0x0000; - return 0; - } + if (!memcmp("MIDI", buffer, 4)) { + *file_type = 0xd7; + *aux_type = 0x0000; + return 0; + } - if (!memcmp("AIFF", buffer, 4)) { - *file_type = 0xd8; - *aux_type = 0x0000; - return 0; - } + if (!memcmp("AIFF", buffer, 4)) { + *file_type = 0xd8; + *aux_type = 0x0000; + return 0; + } - if (!memcmp("AIFC", buffer, 4)) { - *file_type = 0xd8; - *aux_type = 0x0001; - return 0; - } + if (!memcmp("AIFC", buffer, 4)) { + *file_type = 0xd8; + *aux_type = 0x0001; + return 0; + } - return -1; + return -1; } int host_file_type_to_finder_info(byte *buffer, word16 file_type, word32 aux_type) { - if (file_type > 0xff || aux_type > 0xffff) return -1; + if (file_type > 0xff || aux_type > 0xffff) return -1; - if (!file_type && aux_type == 0x0000) { - memcpy(buffer, "BINApdos", 8); - return 0; - } + if (!file_type && aux_type == 0x0000) { + memcpy(buffer, "BINApdos", 8); + return 0; + } - if (file_type == 0x04 && aux_type == 0x0000) { - memcpy(buffer, "TEXTpdos", 8); - return 0; - } + if (file_type == 0x04 && aux_type == 0x0000) { + memcpy(buffer, "TEXTpdos", 8); + return 0; + } - if (file_type == 0xff && aux_type == 0x0000) { - memcpy(buffer, "PSYSpdos", 8); - return 0; - } + if (file_type == 0xff && aux_type == 0x0000) { + memcpy(buffer, "PSYSpdos", 8); + return 0; + } - if (file_type == 0xb3 && aux_type == 0x0000) { - memcpy(buffer, "PS16pdos", 8); - return 0; - } + if (file_type == 0xb3 && aux_type == 0x0000) { + memcpy(buffer, "PS16pdos", 8); + return 0; + } - if (file_type == 0xd7 && aux_type == 0x0000) { - memcpy(buffer, "MIDIpdos", 8); - return 0; - } - if (file_type == 0xd8 && aux_type == 0x0000) { - memcpy(buffer, "AIFFpdos", 8); - return 0; - } - if (file_type == 0xd8 && aux_type == 0x0001) { - memcpy(buffer, "AIFCpdos", 8); - return 0; - } - if (file_type == 0xe0 && aux_type == 0x0005) { - memcpy(buffer, "dImgdCpy", 8); - return 0; - } + if (file_type == 0xd7 && aux_type == 0x0000) { + memcpy(buffer, "MIDIpdos", 8); + return 0; + } + if (file_type == 0xd8 && aux_type == 0x0000) { + memcpy(buffer, "AIFFpdos", 8); + return 0; + } + if (file_type == 0xd8 && aux_type == 0x0001) { + memcpy(buffer, "AIFCpdos", 8); + return 0; + } + if (file_type == 0xe0 && aux_type == 0x0005) { + memcpy(buffer, "dImgdCpy", 8); + return 0; + } - memcpy(buffer, "p pdos", 8); - buffer[1] = (file_type) & 0xff; - buffer[2] = (aux_type >> 8) & 0xff; - buffer[3] = (aux_type) & 0xff; - return 0; + memcpy(buffer, "p pdos", 8); + buffer[1] = (file_type) & 0xff; + buffer[2] = (aux_type >> 8) & 0xff; + buffer[3] = (aux_type) & 0xff; + return 0; } #if defined(__APPLE__) void host_get_file_xinfo(const char *path, struct file_info *fi) { - ssize_t tmp; - tmp = getxattr(path, XATTR_RESOURCEFORK_NAME, NULL, 0, 0, 0); - if (tmp < 0) tmp = 0; - fi->resource_eof = tmp; - fi->resource_blocks = (tmp + 511) / 512; + ssize_t tmp; + tmp = getxattr(path, XATTR_RESOURCEFORK_NAME, NULL, 0, 0, 0); + if (tmp < 0) tmp = 0; + fi->resource_eof = tmp; + fi->resource_blocks = (tmp + 511) / 512; - tmp = getxattr(path, XATTR_FINDERINFO_NAME, fi->finder_info, 32, 0, 0); - if (tmp == 16 || tmp == 32){ - fi->has_fi = 1; + tmp = getxattr(path, XATTR_FINDERINFO_NAME, fi->finder_info, 32, 0, 0); + if (tmp == 16 || tmp == 32) { + fi->has_fi = 1; - finder_info_to_filetype(fi->finder_info, &fi->file_type, &fi->aux_type); - } + finder_info_to_filetype(fi->finder_info, &fi->file_type, &fi->aux_type); + } } #elif defined(__sun) void host_get_file_xinfo(const char *path, struct file_info *fi) { - struct stat st; + struct stat st; - // can't stat an xattr directly? - int fd; - fd = attropen(path, XATTR_RESOURCEFORK_NAME, O_RDONLY); - if (fd >= 0) { - if (fstat(fd, &st) == 0) { - fi->resource_eof = st.st_size; - fi->resource_blocks = st.st_blocks; - } - close(fd); - } + // can't stat an xattr directly? + int fd; + fd = attropen(path, XATTR_RESOURCEFORK_NAME, O_RDONLY); + if (fd >= 0) { + if (fstat(fd, &st) == 0) { + fi->resource_eof = st.st_size; + fi->resource_blocks = st.st_blocks; + } + close(fd); + } - fd = attropen(path, XATTR_FINDERINFO_NAME, O_RDONLY); - if (fd >= 0) { - int tmp = read(fd, fi->finder_info, 32); - if (tmp == 16 || tmp == 32) { - fi->has_fi = 1; - finder_info_to_filetype(fi->finder_info, &fi->file_type, &fi->aux_type); - } - close(fd); - } + fd = attropen(path, XATTR_FINDERINFO_NAME, O_RDONLY); + if (fd >= 0) { + int tmp = read(fd, fi->finder_info, 32); + if (tmp == 16 || tmp == 32) { + fi->has_fi = 1; + finder_info_to_filetype(fi->finder_info, &fi->file_type, &fi->aux_type); + } + close(fd); + } } #elif defined(__linux__) void host_get_file_xinfo(const char *path, struct file_info *fi) { - ssize_t tmp; - tmp = getxattr(path, "user.com.apple.ResourceFork", NULL, 0); - if (tmp < 0) tmp = 0; - fi->resource_eof = tmp; - fi->resource_blocks = (tmp + 511) / 512; + ssize_t tmp; + tmp = getxattr(path, "user.com.apple.ResourceFork", NULL, 0); + if (tmp < 0) tmp = 0; + fi->resource_eof = tmp; + fi->resource_blocks = (tmp + 511) / 512; - tmp = getxattr(path, "user.com.apple.FinderInfo", fi->finder_info, 32); - if (tmp == 16 || tmp == 32){ - fi->has_fi = 1; + tmp = getxattr(path, "user.com.apple.FinderInfo", fi->finder_info, 32); + if (tmp == 16 || tmp == 32) { + fi->has_fi = 1; - finder_info_to_filetype(fi->finder_info, &fi->file_type, &fi->aux_type); - } + finder_info_to_filetype(fi->finder_info, &fi->file_type, &fi->aux_type); + } } #else void host_get_file_xinfo(const char *path, struct file_info *fi) { @@ -616,113 +615,113 @@ void host_get_file_xinfo(const char *path, struct file_info *fi) { #undef _ #define _(a, b, c) { a, sizeof(a) - 1, b, c } struct ftype_entry { - char *ext; - unsigned length; - unsigned file_type; - unsigned aux_type; + char *ext; + unsigned length; + unsigned file_type; + unsigned aux_type; }; static struct ftype_entry suffixes[] = { - _("c", 0xb0, 0x0008), - _("cc", 0xb0, 0x0008), - _("h", 0xb0, 0x0008), - _("rez", 0xb0, 0x0015), - _("asm", 0xb0, 0x0003), - _("mac", 0xb0, 0x0003), - _("pas", 0xb0, 0x0005), - _("txt", 0x04, 0x0000), - _("text", 0x04, 0x0000), - _("s", 0x04, 0x0000), - { 0, 0, 0, 0} + _("c", 0xb0, 0x0008), + _("cc", 0xb0, 0x0008), + _("h", 0xb0, 0x0008), + _("rez", 0xb0, 0x0015), + _("asm", 0xb0, 0x0003), + _("mac", 0xb0, 0x0003), + _("pas", 0xb0, 0x0005), + _("txt", 0x04, 0x0000), + _("text", 0x04, 0x0000), + _("s", 0x04, 0x0000), + { 0, 0, 0, 0} }; static struct ftype_entry prefixes[] = { - _("m16.", 0xb0, 0x0003), - _("e16.", 0xb0, 0x0003), - { 0, 0, 0, 0} + _("m16.", 0xb0, 0x0003), + _("e16.", 0xb0, 0x0003), + { 0, 0, 0, 0} }; #undef _ word32 host_get_file_info(const char *path, struct file_info *fi) { - struct stat st; - memset(fi, 0, sizeof(*fi)); + struct stat st; + memset(fi, 0, sizeof(*fi)); - int ok = stat(path, &st); - if (ok < 0) return host_map_errno(errno); + int ok = stat(path, &st); + if (ok < 0) return host_map_errno(errno); - fi->eof = st.st_size; - fi->blocks = st.st_blocks; + fi->eof = st.st_size; + fi->blocks = st.st_blocks; - fi->create_date = st.st_ctime; - fi->modified_date = st.st_mtime; + fi->create_date = st.st_ctime; + fi->modified_date = st.st_mtime; -#if defined(__APPLE__) - fi->create_date = st.st_birthtime; +#if defined(__APPLE__) + fi->create_date = st.st_birthtime; #endif - fi->st_mode = st.st_mode; + fi->st_mode = st.st_mode; - if (S_ISDIR(st.st_mode)) { - fi->storage_type = directoryFile; - fi->file_type = 0x0f; - if (host_is_root(&st)) - fi->storage_type = 0x0f; - } else if (S_ISREG(st.st_mode)) { - fi->file_type = 0x06; - if (st.st_size < 0x200) fi->storage_type = seedling; - else if (st.st_size < 0x20000) fi->storage_type = sapling; - else fi->storage_type = tree; - } else { - fi->storage_type = st.st_mode & S_IFMT; - fi->file_type = 0; - } - // 0x01 = read enable - // 0x02 = write enable - // 0x04 = invisible - // 0x08 = reserved - // 0x10 = reserved - // 0x20 = backup needed - // 0x40 = rename enable - // 0x80 = destroy enable + if (S_ISDIR(st.st_mode)) { + fi->storage_type = directoryFile; + fi->file_type = 0x0f; + if (host_is_root(&st)) + fi->storage_type = 0x0f; + } else if (S_ISREG(st.st_mode)) { + fi->file_type = 0x06; + if (st.st_size < 0x200) fi->storage_type = seedling; + else if (st.st_size < 0x20000) fi->storage_type = sapling; + else fi->storage_type = tree; + } else { + fi->storage_type = st.st_mode & S_IFMT; + fi->file_type = 0; + } + // 0x01 = read enable + // 0x02 = write enable + // 0x04 = invisible + // 0x08 = reserved + // 0x10 = reserved + // 0x20 = backup needed + // 0x40 = rename enable + // 0x80 = destroy enable - fi->access = 0xc3; // placeholder... + fi->access = 0xc3; // placeholder... - if (S_ISREG(st.st_mode)) { - host_get_file_xinfo(path, fi); + if (S_ISREG(st.st_mode)) { + host_get_file_xinfo(path, fi); - if (!fi->has_fi) { - /* guess the file type / auxtype based on extension */ - int n; - const char *dot = NULL; - const char *slash = NULL; + if (!fi->has_fi) { + /* guess the file type / auxtype based on extension */ + int n; + const char *dot = NULL; + const char *slash = NULL; - for(n = 0; ; ++n) { - char c = path[n]; - if (c == 0) break; - else if (c == '/') { slash = path + n + 1; dot = NULL; } - else if (c == '.') dot = path + n + 1; - } + for(n = 0;; ++n) { + char c = path[n]; + if (c == 0) break; + else if (c == '/') { slash = path + n + 1; dot = NULL; } + else if (c == '.') dot = path + n + 1; + } - if (dot && *dot) { - for (n = 0; n < sizeof(suffixes) / sizeof(suffixes[0]); ++n) { - if (!suffixes[n].ext) break; - if (!strcasecmp(dot, suffixes[n].ext)) { - fi->file_type = suffixes[n].file_type; - fi->aux_type = suffixes[n].aux_type; - break; - } - } - } - } - } + if (dot && *dot) { + for (n = 0; n < sizeof(suffixes) / sizeof(suffixes[0]); ++n) { + if (!suffixes[n].ext) break; + if (!strcasecmp(dot, suffixes[n].ext)) { + fi->file_type = suffixes[n].file_type; + fi->aux_type = suffixes[n].aux_type; + break; + } + } + } + } + } - // get file type/aux type + // get file type/aux type - if (fi->resource_eof) fi->storage_type = extendedFile; + if (fi->resource_eof) fi->storage_type = extendedFile; - return 0; + return 0; } @@ -731,99 +730,99 @@ word32 host_get_file_info(const char *path, struct file_info *fi) { #if defined(__APPLE__) word32 host_set_file_info(const char *path, struct file_info *fi) { - int ok; - struct attrlist list; - unsigned i = 0; - struct timespec dates[2]; + int ok; + struct attrlist list; + unsigned i = 0; + struct timespec dates[2]; - if (fi->has_fi && fi->storage_type != 0x0d) { - ok = setxattr(path, XATTR_FINDERINFO_NAME, fi->finder_info, 32, 0, 0); - if (ok < 0) return host_map_errno(errno); - } + if (fi->has_fi && fi->storage_type != 0x0d) { + ok = setxattr(path, XATTR_FINDERINFO_NAME, fi->finder_info, 32, 0, 0); + if (ok < 0) return host_map_errno(errno); + } - memset(&list, 0, sizeof(list)); - memset(dates, 0, sizeof(dates)); + memset(&list, 0, sizeof(list)); + memset(dates, 0, sizeof(dates)); - list.bitmapcount = ATTR_BIT_MAP_COUNT; - list.commonattr = 0; + list.bitmapcount = ATTR_BIT_MAP_COUNT; + list.commonattr = 0; - if (fi->create_date) - { - dates[i++].tv_sec = fi->create_date; - list.commonattr |= ATTR_CMN_CRTIME; - } + if (fi->create_date) + { + dates[i++].tv_sec = fi->create_date; + list.commonattr |= ATTR_CMN_CRTIME; + } - if (fi->modified_date) - { - dates[i++].tv_sec = fi->modified_date; - list.commonattr |= ATTR_CMN_MODTIME; - } + if (fi->modified_date) + { + dates[i++].tv_sec = fi->modified_date; + list.commonattr |= ATTR_CMN_MODTIME; + } - ok = 0; - if (i) ok = setattrlist(path, &list, dates, i * sizeof(struct timespec), 0); - return 0; + ok = 0; + if (i) ok = setattrlist(path, &list, dates, i * sizeof(struct timespec), 0); + return 0; } -#elif defined(__sun) +#elif defined(__sun) word32 host_set_file_info(const char *path, struct file_info *fi) { - if (fi->has_fi && fi->storage_type != 0x0d) { - int fd = attropen(path, XATTR_FINDERINFO_NAME, O_WRONLY | O_CREAT, 0666); - if (fd < 0) return host_map_errno(errno); - write(fd, fi->finder_info, 32); - close(fd); - } + if (fi->has_fi && fi->storage_type != 0x0d) { + int fd = attropen(path, XATTR_FINDERINFO_NAME, O_WRONLY | O_CREAT, 0666); + if (fd < 0) return host_map_errno(errno); + write(fd, fi->finder_info, 32); + close(fd); + } - if (fi->modified_date) { - struct timeval times[2]; + if (fi->modified_date) { + struct timeval times[2]; - memset(times, 0, sizeof(times)); + memset(times, 0, sizeof(times)); - //times[0] = 0; // access - times[1].tv_sec = fi.modified_date; // modified - int ok = utimes(path, times); - if (ok < 0) return host_map_errno(errno); - } - return 0; + //times[0] = 0; // access + times[1].tv_sec = fi.modified_date; // modified + int ok = utimes(path, times); + if (ok < 0) return host_map_errno(errno); + } + return 0; } #elif defined(__linux__) word32 host_set_file_info(const char *path, struct file_info *fi) { - if (fi->has_fi && fi->storage_type != 0x0d) { - int ok = setxattr(path, "user.apple.FinderInfo", fi->finder_info, 32, 0); - if (ok < 0) return host_map_errno(errno); - } + if (fi->has_fi && fi->storage_type != 0x0d) { + int ok = setxattr(path, "user.apple.FinderInfo", fi->finder_info, 32, 0); + if (ok < 0) return host_map_errno(errno); + } - if (fi->modified_date) { - struct timeval times[2]; + if (fi->modified_date) { + struct timeval times[2]; - memset(times, 0, sizeof(times)); + memset(times, 0, sizeof(times)); - //times[0] = 0; // access - times[1].tv_sec = fi->modified_date; // modified - int ok = utimes(path, times); - if (ok < 0) return host_map_errno(errno); - } - return 0; + //times[0] = 0; // access + times[1].tv_sec = fi->modified_date; // modified + int ok = utimes(path, times); + if (ok < 0) return host_map_errno(errno); + } + return 0; } #else word32 host_set_file_info(const char *path, struct file_info *fi) { - if (fi->modified_date) { + if (fi->modified_date) { - struct timeval times[2]; + struct timeval times[2]; - memset(times, 0, sizeof(times)); + memset(times, 0, sizeof(times)); - times[0] = 0; // access - times[1].tv_sec = fi->modified_date; // modified + times[0] = 0; // access + times[1].tv_sec = fi->modified_date; // modified - int ok = utimes(path, times); - if (ok < 0) return host_map_errno(errno); - } - return 0; + int ok = utimes(path, times); + if (ok < 0) return host_map_errno(errno); + } + return 0; } #endif @@ -839,22 +838,22 @@ word32 host_set_file_info(const char *path, struct file_info *fi) { void host_set_date_time_rec(word32 ptr, time_t time) { - if (time == 0) { - for (int i = 0; i < 8; ++i) set_memory_c(ptr++, 0, 0); - return; - } + if (time == 0) { + for (int i = 0; i < 8; ++i) set_memory_c(ptr++, 0, 0); + return; + } - struct tm *tm = localtime(&time); - if (tm->tm_sec == 60) tm->tm_sec = 59; /* leap second */ + struct tm *tm = localtime(&time); + if (tm->tm_sec == 60) tm->tm_sec = 59; /* leap second */ - set_memory_c(ptr++, tm->tm_sec, 0); - set_memory_c(ptr++, tm->tm_min, 0); - set_memory_c(ptr++, tm->tm_hour, 0); - set_memory_c(ptr++, tm->tm_year, 0); - set_memory_c(ptr++, tm->tm_mday - 1, 0); - set_memory_c(ptr++, tm->tm_mon, 0); - set_memory_c(ptr++, 0, 0); - set_memory_c(ptr++, tm->tm_wday + 1, 0); + set_memory_c(ptr++, tm->tm_sec, 0); + set_memory_c(ptr++, tm->tm_min, 0); + set_memory_c(ptr++, tm->tm_hour, 0); + set_memory_c(ptr++, tm->tm_year, 0); + set_memory_c(ptr++, tm->tm_mday - 1, 0); + set_memory_c(ptr++, tm->tm_mon, 0); + set_memory_c(ptr++, 0, 0); + set_memory_c(ptr++, tm->tm_wday + 1, 0); } /* @@ -862,167 +861,167 @@ void host_set_date_time_rec(word32 ptr, time_t time) { */ void host_set_date_time(word32 ptr, time_t time) { - if (time == 0) { - for (int i = 0; i < 4; ++i) set_memory_c(ptr++, 0, 0); - return; - } + if (time == 0) { + for (int i = 0; i < 4; ++i) set_memory_c(ptr++, 0, 0); + return; + } - struct tm *tm = localtime(&time); + struct tm *tm = localtime(&time); - word16 tmp = 0; - tmp |= (tm->tm_year % 100) << 9; - tmp |= tm->tm_mon << 5; - tmp |= tm->tm_mday; + word16 tmp = 0; + tmp |= (tm->tm_year % 100) << 9; + tmp |= tm->tm_mon << 5; + tmp |= tm->tm_mday; - set_memory16_c(ptr, tmp, 0); - ptr += 2; + set_memory16_c(ptr, tmp, 0); + ptr += 2; - tmp = 0; - tmp |= tm->tm_hour << 8; - tmp |= tm->tm_min; - set_memory16_c(ptr, tmp, 0); + tmp = 0; + tmp |= tm->tm_hour << 8; + tmp |= tm->tm_min; + set_memory16_c(ptr, tmp, 0); } word32 host_convert_date_time(time_t time) { - if (time == 0) return 0; + if (time == 0) return 0; - struct tm *tm = localtime(&time); + struct tm *tm = localtime(&time); - word16 dd = 0; - dd |= (tm->tm_year % 100) << 9; - dd |= tm->tm_mon << 5; - dd |= tm->tm_mday; + word16 dd = 0; + dd |= (tm->tm_year % 100) << 9; + dd |= tm->tm_mon << 5; + dd |= tm->tm_mday; - word16 tt = 0; - tt |= tm->tm_hour << 8; - tt |= tm->tm_min; + word16 tt = 0; + tt |= tm->tm_hour << 8; + tt |= tm->tm_min; - return (tt << 16) | dd; + return (tt << 16) | dd; } time_t host_get_date_time(word32 ptr) { - word16 a = get_memory16_c(ptr + 0, 0); - word16 b = get_memory16_c(ptr + 2, 0); - if (!a && !b) return 0; + word16 a = get_memory16_c(ptr + 0, 0); + word16 b = get_memory16_c(ptr + 2, 0); + if (!a && !b) return 0; - struct tm tm; - memset(&tm, 0, sizeof(tm)); + struct tm tm; + memset(&tm, 0, sizeof(tm)); - tm.tm_year = (a >> 9) & 0x7f; - tm.tm_mon = ((a >> 5) & 0x0f) - 1; - tm.tm_mday = (a >> 0) & 0x1f; + tm.tm_year = (a >> 9) & 0x7f; + tm.tm_mon = ((a >> 5) & 0x0f) - 1; + tm.tm_mday = (a >> 0) & 0x1f; - tm.tm_hour = (b >> 8) & 0x1f; - tm.tm_min = (b >> 0) & 0x3f; - tm.tm_sec = 0; + tm.tm_hour = (b >> 8) & 0x1f; + tm.tm_min = (b >> 0) & 0x3f; + tm.tm_sec = 0; - tm.tm_isdst = -1; + tm.tm_isdst = -1; - // 00 - 39 => 2000-2039 - // 40 - 99 => 1940-1999 - if (tm.tm_year < 40) tm.tm_year += 100; + // 00 - 39 => 2000-2039 + // 40 - 99 => 1940-1999 + if (tm.tm_year < 40) tm.tm_year += 100; - return mktime(&tm); + return mktime(&tm); } time_t host_get_date_time_rec(word32 ptr) { - byte buffer[8]; - for (int i = 0; i < 8; ++i) buffer[i] = get_memory_c(ptr++, 0); + byte buffer[8]; + for (int i = 0; i < 8; ++i) buffer[i] = get_memory_c(ptr++, 0); - if (!memcmp(buffer, "\x00\x00\x00\x00\x00\x00\x00\x00", 8)) return 0; + if (!memcmp(buffer, "\x00\x00\x00\x00\x00\x00\x00\x00", 8)) return 0; - struct tm tm; - memset(&tm, 0, sizeof(tm)); + struct tm tm; + memset(&tm, 0, sizeof(tm)); - tm.tm_sec = buffer[0]; - tm.tm_min = buffer[1]; - tm.tm_hour = buffer[2]; - tm.tm_year = buffer[3]; - tm.tm_mday = buffer[4] + 1; - tm.tm_mon = buffer[5]; - tm.tm_isdst = -1; + tm.tm_sec = buffer[0]; + tm.tm_min = buffer[1]; + tm.tm_hour = buffer[2]; + tm.tm_year = buffer[3]; + tm.tm_mday = buffer[4] + 1; + tm.tm_mon = buffer[5]; + tm.tm_isdst = -1; - return mktime(&tm); + return mktime(&tm); } void host_hexdump(word32 address, int size) { - const char *HexMap = "0123456789abcdef"; + const char *HexMap = "0123456789abcdef"; - char buffer1[16 * 3 + 1 + 1]; - char buffer2[16 + 1]; - unsigned i, j; + char buffer1[16 * 3 + 1 + 1]; + char buffer2[16 + 1]; + unsigned i, j; - printf("\n"); - while (size > 0) { - memset(buffer1, ' ', sizeof(buffer1)); - memset(buffer2, ' ', sizeof(buffer2)); + printf("\n"); + while (size > 0) { + memset(buffer1, ' ', sizeof(buffer1)); + memset(buffer2, ' ', sizeof(buffer2)); - int linelen = size; - if (linelen > 16) linelen = 16; + int linelen = size; + if (linelen > 16) linelen = 16; - for (i = 0, j = 0; i < linelen; i++) { - unsigned x = get_memory_c(address + i, 0); - buffer1[j++] = HexMap[x >> 4]; - buffer1[j++] = HexMap[x & 0x0f]; - j++; - if (i == 7) j++; - x &= 0x7f; - // isascii not part of std:: and may be a macro. - buffer2[i] = isascii(x) && isprint(x) ? x : '.'; - } + for (i = 0, j = 0; i < linelen; i++) { + unsigned x = get_memory_c(address + i, 0); + buffer1[j++] = HexMap[x >> 4]; + buffer1[j++] = HexMap[x & 0x0f]; + j++; + if (i == 7) j++; + x &= 0x7f; + // isascii not part of std:: and may be a macro. + buffer2[i] = isascii(x) && isprint(x) ? x : '.'; + } - buffer1[sizeof(buffer1) - 1] = 0; - buffer2[sizeof(buffer2) - 1] = 0; + buffer1[sizeof(buffer1) - 1] = 0; + buffer2[sizeof(buffer2) - 1] = 0; - printf("%06x:\t%s\t%s\n", - address, buffer1, buffer2); - address += 16; - size -= 16; - } - printf("\n"); + printf("%06x:\t%s\t%s\n", + address, buffer1, buffer2); + address += 16; + size -= 16; + } + printf("\n"); } void host_hexdump_native(void *data, unsigned address, int size) { - const char *HexMap = "0123456789abcdef"; + const char *HexMap = "0123456789abcdef"; - char buffer1[16 * 3 + 1 + 1]; - char buffer2[16 + 1]; - unsigned i, j; + char buffer1[16 * 3 + 1 + 1]; + char buffer2[16 + 1]; + unsigned i, j; - printf("\n"); - while (size > 0) { - memset(buffer1, ' ', sizeof(buffer1)); - memset(buffer2, ' ', sizeof(buffer2)); + printf("\n"); + while (size > 0) { + memset(buffer1, ' ', sizeof(buffer1)); + memset(buffer2, ' ', sizeof(buffer2)); - int linelen = size; - if (linelen > 16) linelen = 16; + int linelen = size; + if (linelen > 16) linelen = 16; - for (i = 0, j = 0; i < linelen; i++) { - unsigned x = ((byte *)data)[address + i]; - buffer1[j++] = HexMap[x >> 4]; - buffer1[j++] = HexMap[x & 0x0f]; - j++; - if (i == 7) j++; - x &= 0x7f; - // isascii not part of std:: and may be a macro. - buffer2[i] = isascii(x) && isprint(x) ? x : '.'; - } + for (i = 0, j = 0; i < linelen; i++) { + unsigned x = ((byte *)data)[address + i]; + buffer1[j++] = HexMap[x >> 4]; + buffer1[j++] = HexMap[x & 0x0f]; + j++; + if (i == 7) j++; + x &= 0x7f; + // isascii not part of std:: and may be a macro. + buffer2[i] = isascii(x) && isprint(x) ? x : '.'; + } - buffer1[sizeof(buffer1) - 1] = 0; - buffer2[sizeof(buffer2) - 1] = 0; + buffer1[sizeof(buffer1) - 1] = 0; + buffer2[sizeof(buffer2) - 1] = 0; - printf("%06x:\t%s\t%s\n", - address, buffer1, buffer2); - address += 16; - size -= 16; - } - printf("\n"); + printf("%06x:\t%s\t%s\n", + address, buffer1, buffer2); + address += 16; + size -= 16; + } + printf("\n"); } diff --git a/src/host_common.h b/src/host_common.h index d595f49..ee4cb71 100644 --- a/src/host_common.h +++ b/src/host_common.h @@ -1,33 +1,33 @@ enum { - file_non, - file_regular, - file_resource, - file_directory, + file_non, + file_regular, + file_resource, + file_directory, }; enum { - translate_none, - translate_crlf, - translate_merlin, + translate_none, + translate_crlf, + translate_merlin, }; struct file_info { - time_t create_date; - time_t modified_date; - word16 access; - word16 storage_type; - word16 file_type; - word32 aux_type; - word32 eof; - word32 blocks; - word32 resource_eof; - word32 resource_blocks; - mode_t st_mode; - int has_fi; - byte finder_info[32]; + time_t create_date; + time_t modified_date; + word16 access; + word16 storage_type; + word16 file_type; + word32 aux_type; + word32 eof; + word32 blocks; + word32 resource_eof; + word32 resource_blocks; + mode_t st_mode; + int has_fi; + byte finder_info[32]; }; @@ -43,14 +43,14 @@ extern Engine_reg engine; #define CLI() engine.psr &= ~0x04 enum { - C = 0x01, - Z = 0x02, - I = 0x04, - D = 0x08, - X = 0x10, - M = 0x20, - V = 0x40, - N = 0x80 + C = 0x01, + Z = 0x02, + I = 0x04, + D = 0x08, + X = 0x10, + M = 0x20, + V = 0x40, + N = 0x80 }; extern int g_cfg_host_read_only; diff --git a/src/host_fst.c b/src/host_fst.c index 082956e..adf87f6 100644 --- a/src/host_fst.c +++ b/src/host_fst.c @@ -930,7 +930,7 @@ static word32 fst_open(int class, const char *path) { if (pcount >= 5) set_memory16_c(pb + OpenRecGS_access, access, 0); if (pcount >= 6) set_memory16_c(pb + OpenRecGS_fileType, fi.file_type, 0); if (pcount >= 7) set_memory32_c(pb + OpenRecGS_auxType, fi.aux_type, 0); - if (pcount >= 8) set_memory16_c(pb + OpenRecGS_storageType, fi. storage_type, 0); + if (pcount >= 8) set_memory16_c(pb + OpenRecGS_storageType, fi.storage_type, 0); if (pcount >= 9) host_set_date_time_rec(pb + OpenRecGS_createDateTime, fi.create_date); if (pcount >= 10) host_set_date_time_rec(pb + OpenRecGS_modDateTime, fi.modified_date); @@ -968,7 +968,7 @@ static word32 fst_open(int class, const char *path) { return tooManyFilesOpen; } - if (type == file_regular){ + if (type == file_regular) { if (g_cfg_host_crlf) { if (fi.file_type == 0x04 || fi.file_type == 0xb0) diff --git a/src/host_mli.c b/src/host_mli.c index f00f626..4802467 100644 --- a/src/host_mli.c +++ b/src/host_mli.c @@ -22,11 +22,11 @@ #include "host_common.h" -#define LEVEL 0xBFD8 // current file level -#define DEVNUM 0xBF30 // last slot / drive -#define DEVCNT 0xBF31 // count - 1 -#define DEVLST 0xBF32 // active device list -#define PFIXPTR 0xbf9a // active prefix? +#define LEVEL 0xBFD8 // current file level +#define DEVNUM 0xBF30 // last slot / drive +#define DEVCNT 0xBF31 // count - 1 +#define DEVLST 0xBF32 // active device list +#define PFIXPTR 0xbf9a // active prefix? /* bf97 is appletalk prefix? */ @@ -46,85 +46,85 @@ static char *saved_prefix; enum { - CREATE = 0xc0, - DESTROY = 0xc1, - RENAME = 0xc2, - SET_FILE_INFO = 0xc3, - GET_FILE_INFO = 0xc4, - ONLINE = 0xc5, - SET_PREFIX = 0xc6, - GET_PREFIX = 0xc7, - OPEN = 0xc8, - NEWLINE = 0xc9, - READ = 0xca, - WRITE = 0xcb, - CLOSE = 0xcc, - FLUSH = 0xcd, - SET_MARK = 0xce, - GET_MARK = 0xcf, - SET_EOF = 0xd0, - GET_EOF = 0xd1, - SET_BUF = 0xd2, - GET_BUF = 0xd3, - ALLOC_INTERRUPT = 0x40, - DEALLOC_INTERRUPT = 0x41, - ATINIT = 0x99, - READ_BLOCK = 0x80, - WRITE_BLOCK = 0x81, - GET_TIME = 0x82, - QUIT = 0x65 + CREATE = 0xc0, + DESTROY = 0xc1, + RENAME = 0xc2, + SET_FILE_INFO = 0xc3, + GET_FILE_INFO = 0xc4, + ONLINE = 0xc5, + SET_PREFIX = 0xc6, + GET_PREFIX = 0xc7, + OPEN = 0xc8, + NEWLINE = 0xc9, + READ = 0xca, + WRITE = 0xcb, + CLOSE = 0xcc, + FLUSH = 0xcd, + SET_MARK = 0xce, + GET_MARK = 0xcf, + SET_EOF = 0xd0, + GET_EOF = 0xd1, + SET_BUF = 0xd2, + GET_BUF = 0xd3, + ALLOC_INTERRUPT = 0x40, + DEALLOC_INTERRUPT = 0x41, + ATINIT = 0x99, + READ_BLOCK = 0x80, + WRITE_BLOCK = 0x81, + GET_TIME = 0x82, + QUIT = 0x65 }; #if 0 enum { - noError = 0x0000, - invalidCallNum = 0x01, - invalidPcount = 0x04, - intTableFull = 0x25, - ioError = 0x27, - noDevConnect = 0x28, - writeProtectErr = 0x2B, - diskSwitchErr = 0x2E, - badPathname = 0x40, - fcbFullErr = 0x42, - badFileRefNum = 0x43, - pathNotFound = 0x44, - volumeNotFound = 0x45, - fileNotFound = 0x46, - dupFileName = 0x47, - volumeFullErr = 0x48, - dirFullErr = 0x49, - versionErr = 0x4A, - badStoreType = 0x4B, - eofEncountered = 0x4C, - positionRangeErr = 0x4D, - accessErr = 0x4E, - fileOpenErr = 0x50, - dirDamaged = 0x51, - badVolType = 0x52, - paramRangeErr = 0x53, - vcbFullErr = 0x55, - badBufferAddress = 0x56, - dupVolumeErr = 0x57, - blkNumRangeErr = 0x5A + noError = 0x0000, + invalidCallNum = 0x01, + invalidPcount = 0x04, + intTableFull = 0x25, + ioError = 0x27, + noDevConnect = 0x28, + writeProtectErr = 0x2B, + diskSwitchErr = 0x2E, + badPathname = 0x40, + fcbFullErr = 0x42, + badFileRefNum = 0x43, + pathNotFound = 0x44, + volumeNotFound = 0x45, + fileNotFound = 0x46, + dupFileName = 0x47, + volumeFullErr = 0x48, + dirFullErr = 0x49, + versionErr = 0x4A, + badStoreType = 0x4B, + eofEncountered = 0x4C, + positionRangeErr = 0x4D, + accessErr = 0x4E, + fileOpenErr = 0x50, + dirDamaged = 0x51, + badVolType = 0x52, + paramRangeErr = 0x53, + vcbFullErr = 0x55, + badBufferAddress = 0x56, + dupVolumeErr = 0x57, + blkNumRangeErr = 0x5A }; #endif #define badBufferAddress 0x56 struct file_entry { - unsigned type; - unsigned translate; - int fd; - unsigned buffer; - unsigned level; - unsigned newline_mask; - unsigned newline_char; + unsigned type; + unsigned translate; + int fd; + unsigned buffer; + unsigned level; + unsigned newline_mask; + unsigned newline_char; - /* directory stuff */ - unsigned mark; - unsigned eof; - unsigned char *directory_buffer; + /* directory stuff */ + unsigned mark; + unsigned eof; + unsigned char *directory_buffer; }; #define MAX_FILES 8 @@ -134,103 +134,103 @@ struct file_entry files[MAX_FILES]; static char *get_pstr(word32 ptr) { - if (!ptr) return NULL; - int length = get_memory_c(ptr, 0); - ptr += 1; - char *str = host_gc_malloc(length + 1); - for (int i = 0; i < length; ++i) { - char c = get_memory_c(ptr+i, 0) & 0x7f; - str[i] = c; - } - str[length] = 0; - return str; + if (!ptr) return NULL; + int length = get_memory_c(ptr, 0); + ptr += 1; + char *str = host_gc_malloc(length + 1); + for (int i = 0; i < length; ++i) { + char c = get_memory_c(ptr+i, 0) & 0x7f; + str[i] = c; + } + str[length] = 0; + return str; } static word32 set_pstr(word32 ptr, const char *str) { - if (!ptr) return paramRangeErr; + if (!ptr) return paramRangeErr; - int l = str ? strlen(str) : 0; + int l = str ? strlen(str) : 0; - if (l > 255) return buffTooSmall; - // / is the pascal separator. - set_memory_c(ptr++, l, 0); - for (int i = 0; i < l; ++i) { - set_memory_c(ptr++, *str++, 0); - } - return 0; + if (l > 255) return buffTooSmall; + // / is the pascal separator. + set_memory_c(ptr++, l, 0); + for (int i = 0; i < l; ++i) { + set_memory_c(ptr++, *str++, 0); + } + return 0; } static char *is_host_path(unsigned pathname) { - /* add + 5 below to skip past the /HOST/ part */ - /* (prefix may be missing trailing / ) */ - char *p = get_pstr(pathname); - if (!p) return NULL; - if (*p == '/') { - if (!strncasecmp(p, "/HOST", 5)) { - if (p[5] == 0) return "/"; - if (p[5] == '/') return p + 5; - } - return NULL; - } + /* add + 5 below to skip past the /HOST/ part */ + /* (prefix may be missing trailing / ) */ + char *p = get_pstr(pathname); + if (!p) return NULL; + if (*p == '/') { + if (!strncasecmp(p, "/HOST", 5)) { + if (p[5] == 0) return "/"; + if (p[5] == '/') return p + 5; + } + return NULL; + } - if (saved_prefix) { - return host_gc_append_path(saved_prefix + 5, p); - } - return NULL; + if (saved_prefix) { + return host_gc_append_path(saved_prefix + 5, p); + } + return NULL; } static int scandir_sort(const struct dirent **a, const struct dirent **b) { - return strcasecmp((**a).d_name, (**b).d_name); + return strcasecmp((**a).d_name, (**b).d_name); } static int scandir_filter(const struct dirent *d) { - int i; - const char *name = d->d_name; + int i; + const char *name = d->d_name; - if (name[0] == '.') return 0; - for (i = 0; ; ++i) { - unsigned char c = name[i]; - if (c & 0x80) return 0; - if (c == 0) break; - } - if (i > 15) return 0; - return 1; + if (name[0] == '.') return 0; + for (i = 0;; ++i) { + unsigned char c = name[i]; + if (c & 0x80) return 0; + if (c == 0) break; + } + if (i > 15) return 0; + return 1; } static int count_directory_entries(const char *path) { - DIR *dir; - int rv; + DIR *dir; + int rv; - dir = opendir(path); - if (!dir) return 0; + dir = opendir(path); + if (!dir) return 0; - for(rv = 0;;) { - struct dirent *dp = readdir(dir); - if (!dp) break; - if (!scandir_filter(dp)) continue; - ++rv; - } + for(rv = 0;;) { + struct dirent *dp = readdir(dir); + if (!dp) break; + if (!scandir_filter(dp)) continue; + ++rv; + } - closedir(dir); - return rv; + closedir(dir); + return rv; } static unsigned lowercase_bits(const char *name) { - unsigned rv = 0x8000; - unsigned bit = 0x4000; - for(unsigned i = 0; i < 15; ++i, bit >>= 1) { - char c = name[i]; - if (c == 0) break; - if (islower(c)) rv |= bit; - } - return rv; + unsigned rv = 0x8000; + unsigned bit = 0x4000; + for(unsigned i = 0; i < 15; ++i, bit >>= 1) { + char c = name[i]; + if (c == 0) break; + if (islower(c)) rv |= bit; + } + return rv; } /* name is relative to the host directory. */ @@ -238,654 +238,654 @@ static unsigned lowercase_bits(const char *name) { void *create_directory_file(const char *name, const char *path, unsigned *error_ptr, unsigned *block_ptr) { - byte *data; - int capacity = 0; - int count = 0; - unsigned offset = 0; - int i; - struct file_info fi; - unsigned blocks = 1; - unsigned terr; + byte *data; + int capacity = 0; + int count = 0; + unsigned offset = 0; + int i; + struct file_info fi; + unsigned blocks = 1; + unsigned terr; - word32 w32; + word32 w32; - struct dirent **entries = NULL; - int entry_count = 0; - entry_count = scandir(path, &entries, scandir_filter, scandir_sort); - if (entry_count < 0) { - *error_ptr = host_map_errno_path(errno, path); - goto exit; - } + struct dirent **entries = NULL; + int entry_count = 0; + entry_count = scandir(path, &entries, scandir_filter, scandir_sort); + if (entry_count < 0) { + *error_ptr = host_map_errno_path(errno, path); + goto exit; + } - /* also need space for volume/directory header */ - capacity = 1 + (1 + entry_count) / ENTRIES_PER_BLOCK; - capacity *= 512; + /* also need space for volume/directory header */ + capacity = 1 + (1 + entry_count) / ENTRIES_PER_BLOCK; + capacity *= 512; - data = malloc(capacity); - if (!data) { - *error_ptr = outOfMem; - goto exit; - } - memset(data, 0, capacity); + data = malloc(capacity); + if (!data) { + *error_ptr = outOfMem; + goto exit; + } + memset(data, 0, capacity); - terr = host_get_file_info(path, &fi); - if (terr) { - *error_ptr = terr; - goto exit; - } + terr = host_get_file_info(path, &fi); + if (terr) { + *error_ptr = terr; + goto exit; + } - /* TODO -- this is wrong. */ - /* trailing /s should be stripped */ - const char *base_name = strchr(name, '/'); - base_name = base_name ? base_name + 1 : name; - if (!base_name || !*base_name) base_name = "HOST"; + /* TODO -- this is wrong. */ + /* trailing /s should be stripped */ + const char *base_name = strchr(name, '/'); + base_name = base_name ? base_name + 1 : name; + if (!base_name || !*base_name) base_name = "HOST"; - int len = strlen(base_name); - if (len > 15) len = 15; - /* previous / next pointers */ - data[0] = 0; - data[1] = 0; - data[2] = 0; - data[3] = 0; - offset = 4; + int len = strlen(base_name); + if (len > 15) len = 15; + /* previous / next pointers */ + data[0] = 0; + data[1] = 0; + data[2] = 0; + data[3] = 0; + offset = 4; - int root = fi.storage_type == 0x0f; - if (root) { - data[offset++] = 0xf0 | len; - } else { - data[offset++] = 0xe0 | len; - } - for (i = 0; i < len; ++i) { - data[offset++] = toupper(base_name[i]); - } - for(; i < 15; ++i) { data[offset++] = 0; } - if (root) { - data[offset++] = 0; /* reserved */ - data[offset++] = 0; + int root = fi.storage_type == 0x0f; + if (root) { + data[offset++] = 0xf0 | len; + } else { + data[offset++] = 0xe0 | len; + } + for (i = 0; i < len; ++i) { + data[offset++] = toupper(base_name[i]); + } + for(; i < 15; ++i) { data[offset++] = 0; } + if (root) { + data[offset++] = 0; /* reserved */ + data[offset++] = 0; - w32 = host_convert_date_time(fi.modified_date); + w32 = host_convert_date_time(fi.modified_date); - data[offset++] = (w32 >> 0) & 0xff; /* last modified... */ - data[offset++] = (w32 >> 8) & 0xff; - data[offset++] = (w32 >> 16) & 0xff; - data[offset++] = (w32 >> 24) & 0xff; + data[offset++] = (w32 >> 0) & 0xff; /* last modified... */ + data[offset++] = (w32 >> 8) & 0xff; + data[offset++] = (w32 >> 16) & 0xff; + data[offset++] = (w32 >> 24) & 0xff; - w32 = lowercase_bits(base_name); - data[offset++] = (w32 >> 0) & 0xff; /* file name case bits */ - data[offset++] = (w32 >> 8) & 0xff; + w32 = lowercase_bits(base_name); + data[offset++] = (w32 >> 0) & 0xff; /* file name case bits */ + data[offset++] = (w32 >> 8) & 0xff; - } else { - data[offset++] = 0x75; /* password enabled */ - for (i = 0; i < 7; ++i) data[offset++] = 0; /* password */ - } + } else { + data[offset++] = 0x75; /* password enabled */ + for (i = 0; i < 7; ++i) data[offset++] = 0; /* password */ + } - w32 = host_convert_date_time(fi.create_date); + w32 = host_convert_date_time(fi.create_date); - data[offset++] = (w32 >> 0) & 0xff; /* creation... */ - data[offset++] = (w32 >> 8) & 0xff; - data[offset++] = (w32 >> 16) & 0xff; - data[offset++] = (w32 >> 24) & 0xff; + data[offset++] = (w32 >> 0) & 0xff; /* creation... */ + data[offset++] = (w32 >> 8) & 0xff; + data[offset++] = (w32 >> 16) & 0xff; + data[offset++] = (w32 >> 24) & 0xff; - data[offset++] = 0; /* version */ - data[offset++] = 0; /* min version */ - data[offset++] = fi.access; /* access */ - data[offset++] = ENTRY_LENGTH; /* entry length */ - data[offset++] = ENTRIES_PER_BLOCK; /* entries per block */ + data[offset++] = 0; /* version */ + data[offset++] = 0; /* min version */ + data[offset++] = fi.access; /* access */ + data[offset++] = ENTRY_LENGTH; /* entry length */ + data[offset++] = ENTRIES_PER_BLOCK; /* entries per block */ - data[offset++] = 0; /* file count (placeholder) */ - data[offset++] = 0; + data[offset++] = 0; /* file count (placeholder) */ + data[offset++] = 0; - data[offset++] = 0; /* bitmap ptr, parent ptr, etc */ - data[offset++] = 0; - data[offset++] = 0; - data[offset++] = 0; + data[offset++] = 0; /* bitmap ptr, parent ptr, etc */ + data[offset++] = 0; + data[offset++] = 0; + data[offset++] = 0; - int path_len = strlen(path); + int path_len = strlen(path); - count = 0; - blocks = 1; - for (int j = 0; j < entry_count; ++j) { + count = 0; + blocks = 1; + for (int j = 0; j < entry_count; ++j) { - char *name = entries[j]->d_name; - int len = strlen(name); - char *tmp = malloc(path_len + 2 + len); - if (!tmp) continue; + char *name = entries[j]->d_name; + int len = strlen(name); + char *tmp = malloc(path_len + 2 + len); + if (!tmp) continue; - memcpy(tmp, path, path_len); - tmp[path_len] = '/'; - strcpy(tmp + path_len + 1, name); + memcpy(tmp, path, path_len); + tmp[path_len] = '/'; + strcpy(tmp + path_len + 1, name); - unsigned terr = host_get_file_info(tmp, &fi); - free(tmp); - if (terr) continue; + unsigned terr = host_get_file_info(tmp, &fi); + free(tmp); + if (terr) continue; - /* wrap to next block ? */ - if ((offset + ENTRY_LENGTH) >> 9 == blocks) { - blocks++; - offset = (offset + 511) & ~511; - data[offset++] = 0; /* next/previous block pointers */ - data[offset++] = 0; - data[offset++] = 0; - data[offset++] = 0; - } + /* wrap to next block ? */ + if ((offset + ENTRY_LENGTH) >> 9 == blocks) { + blocks++; + offset = (offset + 511) & ~511; + data[offset++] = 0; /* next/previous block pointers */ + data[offset++] = 0; + data[offset++] = 0; + data[offset++] = 0; + } - assert(offset + ENTRY_LENGTH < capacity); + assert(offset + ENTRY_LENGTH < capacity); - /* create a prodos entry... */ + /* create a prodos entry... */ - if (fi.storage_type == extendedFile) - fi.storage_type = 1; - int st = fi.storage_type << 4; + if (fi.storage_type == extendedFile) + fi.storage_type = 1; + int st = fi.storage_type << 4; - data[offset++] = st | len; - for(i = 0; i < len; ++i) { - data[offset++] = toupper(name[i]); - } - for(; i < 15; ++i) data[offset++] = 0; - data[offset++] = fi.file_type; - data[offset++] = 0; /* key ptr */ - data[offset++] = 0; /* key ptr */ - data[offset++] = fi.blocks & 0xff; - data[offset++] = (fi.blocks >> 8) & 0xff; - data[offset++] = fi.eof & 0xff; - data[offset++] = (fi.eof >> 8) & 0xff; - data[offset++] = (fi.eof >> 16) & 0xff; + data[offset++] = st | len; + for(i = 0; i < len; ++i) { + data[offset++] = toupper(name[i]); + } + for(; i < 15; ++i) data[offset++] = 0; + data[offset++] = fi.file_type; + data[offset++] = 0; /* key ptr */ + data[offset++] = 0; /* key ptr */ + data[offset++] = fi.blocks & 0xff; + data[offset++] = (fi.blocks >> 8) & 0xff; + data[offset++] = fi.eof & 0xff; + data[offset++] = (fi.eof >> 8) & 0xff; + data[offset++] = (fi.eof >> 16) & 0xff; - w32 = host_convert_date_time(fi.create_date); + w32 = host_convert_date_time(fi.create_date); - data[offset++] = (w32 >> 0) & 0xff; /* creation... */ - data[offset++] = (w32 >> 8) & 0xff; - data[offset++] = (w32 >> 16) & 0xff; - data[offset++] = (w32 >> 24) & 0xff; + data[offset++] = (w32 >> 0) & 0xff; /* creation... */ + data[offset++] = (w32 >> 8) & 0xff; + data[offset++] = (w32 >> 16) & 0xff; + data[offset++] = (w32 >> 24) & 0xff; - w32 = lowercase_bits(name); - data[offset++] = (w32 >> 0) & 0xff; /* file name case bits */ - data[offset++] = (w32 >> 8) & 0xff; + w32 = lowercase_bits(name); + data[offset++] = (w32 >> 0) & 0xff; /* file name case bits */ + data[offset++] = (w32 >> 8) & 0xff; - data[offset++] = fi.access; - data[offset++] = fi.aux_type & 0xff; - data[offset++] = (fi.aux_type >> 8) & 0xff; + data[offset++] = fi.access; + data[offset++] = fi.aux_type & 0xff; + data[offset++] = (fi.aux_type >> 8) & 0xff; - w32 = host_convert_date_time(fi.modified_date); - data[offset++] = (w32 >> 0) & 0xff; /* last mod... */ - data[offset++] = (w32 >> 8) & 0xff; - data[offset++] = (w32 >> 16) & 0xff; - data[offset++] = (w32 >> 24) & 0xff; + w32 = host_convert_date_time(fi.modified_date); + data[offset++] = (w32 >> 0) & 0xff; /* last mod... */ + data[offset++] = (w32 >> 8) & 0xff; + data[offset++] = (w32 >> 16) & 0xff; + data[offset++] = (w32 >> 24) & 0xff; - data[offset++] = 0; /* header ptr */ - data[offset++] = 0; - count++; - } + data[offset++] = 0; /* header ptr */ + data[offset++] = 0; + count++; + } - data[4 + 0x21] = count & 0xff; - data[4 + 0x22] = (count >> 8)& 0xff; - *block_ptr = blocks; + data[4 + 0x21] = count & 0xff; + data[4 + 0x22] = (count >> 8)& 0xff; + *block_ptr = blocks; exit: - if (entries) { - for (i = 0; i < entry_count; ++i) { - free(entries[i]); - } - free(entries); - } - return data; + if (entries) { + for (i = 0; i < entry_count; ++i) { + free(entries[i]); + } + free(entries); + } + return data; } static int mli_atinit(unsigned dcb) { - unsigned pcount = get_memory_c(dcb, 0); + unsigned pcount = get_memory_c(dcb, 0); - if (pcount < 3|| pcount > 4) return invalidPcount; + if (pcount < 3|| pcount > 4) return invalidPcount; - unsigned version = get_memory_c(dcb + 1, 0); - saved_mli_address = get_memory16_c(dcb + 2, 0); - saved_patch_address = get_memory16_c(dcb + 4, 0); - if (!saved_patch_address) return paramRangeErr; - if (!saved_mli_address) return paramRangeErr; + unsigned version = get_memory_c(dcb + 1, 0); + saved_mli_address = get_memory16_c(dcb + 2, 0); + saved_patch_address = get_memory16_c(dcb + 4, 0); + if (!saved_patch_address) return paramRangeErr; + if (!saved_mli_address) return paramRangeErr; - saved_unit = 0x80; - if (pcount >= 4) saved_unit = get_memory16_c(dcb + 6, 0); + saved_unit = 0x80; + if (pcount >= 4) saved_unit = get_memory16_c(dcb + 6, 0); - if (!saved_unit) return paramRangeErr; + if (!saved_unit) return paramRangeErr; - saved_prefix = 0; + saved_prefix = 0; - memset(files, 0, sizeof(files)); /* ??? */ + memset(files, 0, sizeof(files)); /* ??? */ - return host_startup(); + return host_startup(); } enum { - FILE_INFO_pcount = 0, - FILE_INFO_pathname = 1, - FILE_INFO_access = 3, - FILE_INFO_file_type = 4, - FILE_INFO_aux_type = 5, - FILE_INFO_storage_type = 7, - FILE_INFO_blocks = 8, - FILE_INFO_mod_date = 10, - FILE_INFO_mod_time = 12, - FILE_INFO_create_date = 14, - FILE_INFO_create_time = 16 + FILE_INFO_pcount = 0, + FILE_INFO_pathname = 1, + FILE_INFO_access = 3, + FILE_INFO_file_type = 4, + FILE_INFO_aux_type = 5, + FILE_INFO_storage_type = 7, + FILE_INFO_blocks = 8, + FILE_INFO_mod_date = 10, + FILE_INFO_mod_time = 12, + FILE_INFO_create_date = 14, + FILE_INFO_create_time = 16 }; static int mli_set_file_info(unsigned dcb, const char *path) { - struct file_info fi; - memset(&fi, 0, sizeof(fi)); + struct file_info fi; + memset(&fi, 0, sizeof(fi)); - fi.access = get_memory_c(dcb + FILE_INFO_access, 0); - fi.file_type = get_memory_c(dcb + FILE_INFO_file_type, 0); - fi.aux_type = get_memory16_c(dcb + FILE_INFO_aux_type, 0); - fi.modified_date = host_get_date_time(dcb + FILE_INFO_mod_date); + fi.access = get_memory_c(dcb + FILE_INFO_access, 0); + fi.file_type = get_memory_c(dcb + FILE_INFO_file_type, 0); + fi.aux_type = get_memory16_c(dcb + FILE_INFO_aux_type, 0); + fi.modified_date = host_get_date_time(dcb + FILE_INFO_mod_date); - return host_set_file_info(path, &fi); + return host_set_file_info(path, &fi); } static int mli_get_file_info(unsigned dcb, const char *path) { - struct file_info fi; - int rv = host_get_file_info(path, &fi); - if (rv) return rv; + struct file_info fi; + int rv = host_get_file_info(path, &fi); + if (rv) return rv; - /* ignore resource fork */ - if (fi.storage_type == extendedFile) - fi.storage_type = seedling; + /* ignore resource fork */ + if (fi.storage_type == extendedFile) + fi.storage_type = seedling; - set_memory_c(dcb + FILE_INFO_access, fi.access, 0); - set_memory_c(dcb + FILE_INFO_file_type, fi.file_type, 0); - set_memory16_c(dcb + FILE_INFO_aux_type, fi.aux_type, 0); - set_memory_c(dcb + FILE_INFO_storage_type, fi.storage_type, 0); - set_memory16_c(dcb + FILE_INFO_blocks, fi.blocks, 0); - host_set_date_time(dcb + FILE_INFO_mod_date, fi.modified_date); - host_set_date_time(dcb + FILE_INFO_create_date, fi.create_date); + set_memory_c(dcb + FILE_INFO_access, fi.access, 0); + set_memory_c(dcb + FILE_INFO_file_type, fi.file_type, 0); + set_memory16_c(dcb + FILE_INFO_aux_type, fi.aux_type, 0); + set_memory_c(dcb + FILE_INFO_storage_type, fi.storage_type, 0); + set_memory16_c(dcb + FILE_INFO_blocks, fi.blocks, 0); + host_set_date_time(dcb + FILE_INFO_mod_date, fi.modified_date); + host_set_date_time(dcb + FILE_INFO_create_date, fi.create_date); - return 0; + return 0; } enum { - CREATE_pcount = 0, - CREATE_pathname = 1, - CREATE_access = 3, - CREATE_file_type = 4, - CREATE_aux_type = 5, - CREATE_storage_type = 7, - CREATE_create_date = 8, - CREATE_create_time = 10 + CREATE_pcount = 0, + CREATE_pathname = 1, + CREATE_access = 3, + CREATE_file_type = 4, + CREATE_aux_type = 5, + CREATE_storage_type = 7, + CREATE_create_date = 8, + CREATE_create_time = 10 }; static int mli_create(unsigned dcb, const char *path) { - struct file_info fi; - memset(&fi, 0, sizeof(fi)); + struct file_info fi; + memset(&fi, 0, sizeof(fi)); - fi.access = get_memory_c(dcb + CREATE_access, 0); - fi.file_type = get_memory_c(dcb + CREATE_file_type, 0); - fi.aux_type = get_memory16_c(dcb + CREATE_aux_type, 0); - fi.storage_type = get_memory_c(dcb + CREATE_storage_type, 0); - fi.create_date = host_get_date_time(dcb + CREATE_create_date); + fi.access = get_memory_c(dcb + CREATE_access, 0); + fi.file_type = get_memory_c(dcb + CREATE_file_type, 0); + fi.aux_type = get_memory16_c(dcb + CREATE_aux_type, 0); + fi.storage_type = get_memory_c(dcb + CREATE_storage_type, 0); + fi.create_date = host_get_date_time(dcb + CREATE_create_date); - if (g_cfg_host_read_only) return drvrWrtProt; + if (g_cfg_host_read_only) return drvrWrtProt; - /* - * actual prodos needs the correct storage type and file type - * for a usable directory. this just does the right thing. - * TODO - does ProDOS update the storage type in the dcb? - */ - switch(fi.storage_type) { - case 0x0d: - fi.file_type = 0x0f; - break; - case 0x01: - case 0x02: - case 0x03: - fi.storage_type = 0x01; - break; - case 0x00: - if (fi.file_type == 0x0f) fi.storage_type = 0x0d; - else fi.storage_type = 0x01; - break; - default: - return badStoreType; - } - // todo -- remap access. + /* + * actual prodos needs the correct storage type and file type + * for a usable directory. this just does the right thing. + * TODO - does ProDOS update the storage type in the dcb? + */ + switch(fi.storage_type) { + case 0x0d: + fi.file_type = 0x0f; + break; + case 0x01: + case 0x02: + case 0x03: + fi.storage_type = 0x01; + break; + case 0x00: + if (fi.file_type == 0x0f) fi.storage_type = 0x0d; + else fi.storage_type = 0x01; + break; + default: + return badStoreType; + } + // todo -- remap access. - if (fi.storage_type == 0x0d) { - int ok = mkdir(path, 0777); - if (ok < 0) - return host_map_errno_path(errno, path); - } else { - int fd = open(path, O_CREAT | O_EXCL | O_RDONLY, 0666); - if (fd < 0) - return host_map_errno_path(errno, path); + if (fi.storage_type == 0x0d) { + int ok = mkdir(path, 0777); + if (ok < 0) + return host_map_errno_path(errno, path); + } else { + int fd = open(path, O_CREAT | O_EXCL | O_RDONLY, 0666); + if (fd < 0) + return host_map_errno_path(errno, path); - host_file_type_to_finder_info(fi.finder_info, fi.file_type, fi.aux_type); - fi.has_fi = 1; - host_set_file_info(path, &fi); - close(fd); - } + host_file_type_to_finder_info(fi.finder_info, fi.file_type, fi.aux_type); + fi.has_fi = 1; + host_set_file_info(path, &fi); + close(fd); + } - return 0; + return 0; } static int mli_destroy(unsigned dcb, const char *path) { - /* can't delete the root directory */ - struct stat st; - if (stat(path, &st) < 0) { - return host_map_errno_path(errno, path); - } + /* can't delete the root directory */ + struct stat st; + if (stat(path, &st) < 0) { + return host_map_errno_path(errno, path); + } - if (host_is_root(&st)) - return badPathSyntax; + if (host_is_root(&st)) + return badPathSyntax; - int ok = S_ISDIR(st.st_mode) ? rmdir(path) : unlink(path); + int ok = S_ISDIR(st.st_mode) ? rmdir(path) : unlink(path); - if (ok < 0) return host_map_errno(errno); - return 0; + if (ok < 0) return host_map_errno(errno); + return 0; } static int mli_rename(unsigned dcb, const char *path1, const char *path2) { - /* can't rename the root directory */ - struct stat st; + /* can't rename the root directory */ + struct stat st; - if (!path1 || !path2) return badPathSyntax; + if (!path1 || !path2) return badPathSyntax; - if (stat(path1, &st) < 0) { - return host_map_errno_path(errno, path1); - } + if (stat(path1, &st) < 0) { + return host_map_errno_path(errno, path1); + } - if (host_is_root(&st)) - return badPathSyntax; + if (host_is_root(&st)) + return badPathSyntax; - if (stat(path2, &st) == 0) { - return dupPathname; - } - if (host_is_root(&st)) - return badPathSyntax; + if (stat(path2, &st) == 0) { + return dupPathname; + } + if (host_is_root(&st)) + return badPathSyntax; - int ok = rename(path1, path2); - if (ok < 0) return host_map_errno(errno); - return 0; + int ok = rename(path1, path2); + if (ok < 0) return host_map_errno(errno); + return 0; } static int mli_write(unsigned dcb, struct file_entry *file) { - /* todo -- translate */ + /* todo -- translate */ - set_memory16_c(dcb + 6, 0, 0); + set_memory16_c(dcb + 6, 0, 0); - if (!file->type) return invalidRefNum; - if (file->type != file_regular) return invalidAccess; + if (!file->type) return invalidRefNum; + if (file->type != file_regular) return invalidAccess; - unsigned data_buffer = get_memory16_c(dcb + 2, 0); - unsigned request_count = get_memory16_c(dcb + 4, 0); + unsigned data_buffer = get_memory16_c(dcb + 2, 0); + unsigned request_count = get_memory16_c(dcb + 4, 0); - if (!data_buffer) return badBufferAddress; + if (!data_buffer) return badBufferAddress; - byte *data = host_gc_malloc(request_count); - if (!data) return drvrIOError; + byte *data = host_gc_malloc(request_count); + if (!data) return drvrIOError; - for (unsigned i = 0; i < request_count; ++i) { - data[i] = get_memory_c(data_buffer + i, 0); - } + for (unsigned i = 0; i < request_count; ++i) { + data[i] = get_memory_c(data_buffer + i, 0); + } - switch (file->translate) { - case translate_crlf: - host_cr_to_lf(data, request_count); - break; - case translate_merlin: - host_merlin_to_text(data, request_count); - break; - } + switch (file->translate) { + case translate_crlf: + host_cr_to_lf(data, request_count); + break; + case translate_merlin: + host_merlin_to_text(data, request_count); + break; + } - int rv = pwrite(file->fd, data, request_count, file->mark); - if (rv < 0) return host_map_errno(errno); + int rv = pwrite(file->fd, data, request_count, file->mark); + if (rv < 0) return host_map_errno(errno); - set_memory16_c(dcb + 6, rv, 0); - file->mark += rv; + set_memory16_c(dcb + 6, rv, 0); + file->mark += rv; - return 0; + return 0; } static int mli_read(unsigned dcb, struct file_entry *file) { - /* todo -- translate */ + /* todo -- translate */ - set_memory16_c(dcb + 6, 0, 0); + set_memory16_c(dcb + 6, 0, 0); - if (!file->type) return invalidRefNum; + if (!file->type) return invalidRefNum; - unsigned data_buffer = get_memory16_c(dcb + 2, 0); - unsigned request_count = get_memory16_c(dcb + 4, 0); + unsigned data_buffer = get_memory16_c(dcb + 2, 0); + unsigned request_count = get_memory16_c(dcb + 4, 0); - if (!data_buffer) return badBufferAddress; + if (!data_buffer) return badBufferAddress; - unsigned count = 0; - unsigned mask = file->newline_mask; - unsigned nl = file->newline_char; + unsigned count = 0; + unsigned mask = file->newline_mask; + unsigned nl = file->newline_char; - if (file->type == file_directory) { - unsigned mark = file->mark; - if (mark >= file->eof) return eofEncountered; - /* support newline mode ... */ + if (file->type == file_directory) { + unsigned mark = file->mark; + if (mark >= file->eof) return eofEncountered; + /* support newline mode ... */ - if (mark + request_count > file->eof) - request_count = file->eof - mark; + if (mark + request_count > file->eof) + request_count = file->eof - mark; - for (count = 0; count < request_count; ++count) { - byte b = file->directory_buffer[mark++]; - set_memory_c(data_buffer + count, b, 0); - if (mask && (b & mask) == nl) break; - } - file->mark = mark; - set_memory16_c(dcb + 6, count, 0); - return 0; - } + for (count = 0; count < request_count; ++count) { + byte b = file->directory_buffer[mark++]; + set_memory_c(data_buffer + count, b, 0); + if (mask && (b & mask) == nl) break; + } + file->mark = mark; + set_memory16_c(dcb + 6, count, 0); + return 0; + } - if (file->type != file_regular) return invalidAccess; + if (file->type != file_regular) return invalidAccess; - byte *data = host_gc_malloc(request_count); - if (!data) return drvrIOError; + byte *data = host_gc_malloc(request_count); + if (!data) return drvrIOError; - int rv = pread(file->fd, data, request_count, file->mark); - if (rv < 0) return host_map_errno(errno); - if (rv == 0) return eofEncountered; - count = rv; + int rv = pread(file->fd, data, request_count, file->mark); + if (rv < 0) return host_map_errno(errno); + if (rv == 0) return eofEncountered; + count = rv; - switch (file->translate) { - case translate_crlf: - host_lf_to_cr(data, count); - break; - case translate_merlin: - host_text_to_merlin(data, count); - break; - } + switch (file->translate) { + case translate_crlf: + host_lf_to_cr(data, count); + break; + case translate_merlin: + host_text_to_merlin(data, count); + break; + } - if (mask) { - for (int count = 0; count < rv; ) { - byte b = data[count++]; - if ((b & mask) == nl) break; - } - } - for (unsigned i = 0; i < count; ++i) - set_memory_c(data_buffer + i, data[i], 0); + if (mask) { + for (int count = 0; count < rv; ) { + byte b = data[count++]; + if ((b & mask) == nl) break; + } + } + for (unsigned i = 0; i < count; ++i) + set_memory_c(data_buffer + i, data[i], 0); - file->mark += count; - set_memory16_c(dcb + 6, count, 0); - return 0; + file->mark += count; + set_memory16_c(dcb + 6, count, 0); + return 0; } static int mli_get_buf(unsigned dcb, struct file_entry *file) { - if (!file->type) return invalidRefNum; - set_memory16_c(dcb + 2, file->buffer, 0); - return 0; + if (!file->type) return invalidRefNum; + set_memory16_c(dcb + 2, file->buffer, 0); + return 0; } static int mli_set_buf(unsigned dcb, struct file_entry *file) { - unsigned buffer = get_memory16_c(dcb + 2, 0); - if (!file->type) return invalidRefNum; - //if (!buffer) return badBufferAddress; - if (buffer & 0xff) return badBufferAddress; + unsigned buffer = get_memory16_c(dcb + 2, 0); + if (!file->type) return invalidRefNum; + //if (!buffer) return badBufferAddress; + if (buffer & 0xff) return badBufferAddress; - file->buffer = buffer; - return 0; + file->buffer = buffer; + return 0; } static int mli_get_eof(unsigned dcb, struct file_entry *file) { - off_t eof = 0; + off_t eof = 0; - switch (file->type) { - default: - return invalidRefNum; + switch (file->type) { + default: + return invalidRefNum; - case file_directory: - eof = file->eof; - break; + case file_directory: + eof = file->eof; + break; - case file_regular: - eof = lseek(file->fd, SEEK_END, 0); - if (eof < 0) return host_map_errno(errno); - break; - } - if (eof > 0xffffff) return outOfRange; - set_memory24_c(dcb + 2, eof, 0); - return 0; + case file_regular: + eof = lseek(file->fd, SEEK_END, 0); + if (eof < 0) return host_map_errno(errno); + break; + } + if (eof > 0xffffff) return outOfRange; + set_memory24_c(dcb + 2, eof, 0); + return 0; } static int mli_set_eof(unsigned dcb, struct file_entry *file) { - off_t eof = get_memory24_c(dcb + 2, 0); + off_t eof = get_memory24_c(dcb + 2, 0); - switch (file->type) { - default: - return invalidRefNum; + switch (file->type) { + default: + return invalidRefNum; - case file_directory: - return invalidAccess; - break; + case file_directory: + return invalidAccess; + break; - case file_regular: - if (ftruncate(file->fd, eof) < 0) - return host_map_errno(errno); - break; - } - return 0; + case file_regular: + if (ftruncate(file->fd, eof) < 0) + return host_map_errno(errno); + break; + } + return 0; } static int mli_get_mark(unsigned dcb, struct file_entry *file) { - off_t position = 0; + off_t position = 0; - switch (file->type) { - default: - return invalidRefNum; + switch (file->type) { + default: + return invalidRefNum; - case file_directory: - case file_regular: - position = file->mark; - break; - } - if (position > 0xffffff) return outOfRange; - set_memory24_c(dcb + 2, position, 0); - return 0; + case file_directory: + case file_regular: + position = file->mark; + break; + } + if (position > 0xffffff) return outOfRange; + set_memory24_c(dcb + 2, position, 0); + return 0; } static int mli_set_mark(unsigned dcb, struct file_entry *file) { - off_t eof = 0; - word32 position = get_memory24_c(dcb + 2, 0); + off_t eof = 0; + word32 position = get_memory24_c(dcb + 2, 0); - switch (file->type) { - default: - return invalidRefNum; - case file_directory: - eof = file->eof; - break; - case file_regular: - eof = lseek(file->fd, SEEK_END, 0); - if (eof < 0) return host_map_errno(errno); - break; - } + switch (file->type) { + default: + return invalidRefNum; + case file_directory: + eof = file->eof; + break; + case file_regular: + eof = lseek(file->fd, SEEK_END, 0); + if (eof < 0) return host_map_errno(errno); + break; + } - if (position > eof) return outOfRange; - file->mark = position; + if (position > eof) return outOfRange; + file->mark = position; - return 0; + return 0; } static int mli_newline(unsigned dcb, struct file_entry *file) { - if (!file->type) return invalidRefNum; + if (!file->type) return invalidRefNum; - file->newline_mask = get_memory_c(dcb + 2, 0); - file->newline_char = get_memory_c(dcb + 3, 0); - return 0; + file->newline_mask = get_memory_c(dcb + 2, 0); + file->newline_char = get_memory_c(dcb + 3, 0); + return 0; } static int mli_close(unsigned dcb, struct file_entry *file) { - if (!file) { - unsigned level = get_memory_c(LEVEL, 0); - unsigned i; - for (i = 0; i < MAX_FILES; ++i) { - file = &files[i]; - if (!file->type) continue; - if (file->level < level) continue; - mli_close(dcb, file); - } - return -1; /* pass to prodos mli */ - } + if (!file) { + unsigned level = get_memory_c(LEVEL, 0); + unsigned i; + for (i = 0; i < MAX_FILES; ++i) { + file = &files[i]; + if (!file->type) continue; + if (file->level < level) continue; + mli_close(dcb, file); + } + return -1; /* pass to prodos mli */ + } - if (!file->type) return invalidRefNum; - if (file->fd >= 0) close(file->fd); - if (file->directory_buffer) free(file->directory_buffer); - memset(file, 0, sizeof(*file)); - file->fd = -1; + if (!file->type) return invalidRefNum; + if (file->fd >= 0) close(file->fd); + if (file->directory_buffer) free(file->directory_buffer); + memset(file, 0, sizeof(*file)); + file->fd = -1; - return 0; + return 0; } static int mli_flush(unsigned dcb, struct file_entry *file) { - if (!file) { - unsigned level = get_memory_c(LEVEL, 0); - unsigned i; - for (i = 0; i < MAX_FILES; ++i) { - file = &files[i]; - if (!file->type) continue; - if (file->level < level) continue; + if (!file) { + unsigned level = get_memory_c(LEVEL, 0); + unsigned i; + for (i = 0; i < MAX_FILES; ++i) { + file = &files[i]; + if (!file->type) continue; + if (file->level < level) continue; - if (file->fd >= 0) - fsync(file->fd); - } - return -1; /* pass to prodos mli */ - } + if (file->fd >= 0) + fsync(file->fd); + } + return -1; /* pass to prodos mli */ + } - if (!file->type) return invalidRefNum; - if (file->fd >= 0) fsync(file->fd); + if (!file->type) return invalidRefNum; + if (file->fd >= 0) fsync(file->fd); - return 0; + return 0; } @@ -894,114 +894,114 @@ static int mli_flush(unsigned dcb, struct file_entry *file) { * close all open files. */ static int mli_quit(unsigned dcb) { - unsigned i; - for (i = 0; i < MAX_FILES; ++i) { - struct file_entry *file = &files[i]; - if (!file->type) continue; - if (file->fd >= 0) close(file->fd); - if (file->directory_buffer) free(file->directory_buffer); - memset(file, 0, sizeof(*file)); - file->fd = -1; - } - /* need a better way to know... */ - /* host_shutdown(); */ - return -1; + unsigned i; + for (i = 0; i < MAX_FILES; ++i) { + struct file_entry *file = &files[i]; + if (!file->type) continue; + if (file->fd >= 0) close(file->fd); + if (file->directory_buffer) free(file->directory_buffer); + memset(file, 0, sizeof(*file)); + file->fd = -1; + } + /* need a better way to know... */ + /* host_shutdown(); */ + return -1; } static int mli_open(unsigned dcb, const char *name, const char *path) { - int fd; - int refnum = 0; - unsigned type; + int fd; + int refnum = 0; + unsigned type; - struct file_entry *file = NULL; - for (unsigned i = 0; i < MAX_FILES; ++i) { - file = &files[i]; - if (!file->type) { - refnum = MIN_FILE + i; - break; - } - } - if (!refnum) return tooManyFilesOpen; + struct file_entry *file = NULL; + for (unsigned i = 0; i < MAX_FILES; ++i) { + file = &files[i]; + if (!file->type) { + refnum = MIN_FILE + i; + break; + } + } + if (!refnum) return tooManyFilesOpen; - unsigned buffer = get_memory_c(dcb + 3, 0); - //if (buffer == 0) return badBufferAddress; - if (buffer & 0xff) return badBufferAddress; + unsigned buffer = get_memory_c(dcb + 3, 0); + //if (buffer == 0) return badBufferAddress; + if (buffer & 0xff) return badBufferAddress; - if (g_cfg_host_read_only) { - fd = open(path, O_RDONLY | O_NONBLOCK); - } else { - fd = open(path, O_RDWR | O_NONBLOCK); - if (fd < 0) { - if (errno == EACCES || errno == EISDIR) - fd = open(path, O_RDONLY | O_NONBLOCK); - } - } + if (g_cfg_host_read_only) { + fd = open(path, O_RDONLY | O_NONBLOCK); + } else { + fd = open(path, O_RDWR | O_NONBLOCK); + if (fd < 0) { + if (errno == EACCES || errno == EISDIR) + fd = open(path, O_RDONLY | O_NONBLOCK); + } + } - if (fd < 0) { - return host_map_errno_path(errno, path); - } + if (fd < 0) { + return host_map_errno_path(errno, path); + } - struct file_info fi; - unsigned terr = host_get_file_info(path, &fi); - if (terr) { - close(fd); - return terr; - } + struct file_info fi; + unsigned terr = host_get_file_info(path, &fi); + if (terr) { + close(fd); + return terr; + } - type = 0; - if (S_ISDIR(fi.st_mode)) { - unsigned blocks; - unsigned error; - void *tmp; - type = file_directory; - tmp = create_directory_file(name, path, &error, &blocks); - close(fd); - fd = -1; - if (!tmp) return error; - file->directory_buffer = tmp; - file->eof = blocks * 512; - } else if (S_ISREG(fi.st_mode)) { + type = 0; + if (S_ISDIR(fi.st_mode)) { + unsigned blocks; + unsigned error; + void *tmp; + type = file_directory; + tmp = create_directory_file(name, path, &error, &blocks); + close(fd); + fd = -1; + if (!tmp) return error; + file->directory_buffer = tmp; + file->eof = blocks * 512; + } else if (S_ISREG(fi.st_mode)) { - type = file_regular; + type = file_regular; - if (g_cfg_host_crlf) { - if (fi.file_type == 0x04 || fi.file_type == 0xb0) - file->translate = translate_crlf; - } + if (g_cfg_host_crlf) { + if (fi.file_type == 0x04 || fi.file_type == 0xb0) + file->translate = translate_crlf; + } - if (g_cfg_host_merlin && fi.file_type == 0x04) { - int n = strlen(path); - if (n >= 3 && path[n-1] == 'S' && path[n-2] == '.') - file->translate = translate_merlin; - } + if (g_cfg_host_merlin && fi.file_type == 0x04) { + int n = strlen(path); + if (n >= 3 && path[n-1] == 'S' && path[n-2] == '.') + file->translate = translate_merlin; + } - } else { - close(fd); - return badStoreType; - } + } else { + close(fd); + return badStoreType; + } - file->type = type; - file->level = get_memory_c(LEVEL, 0); - file->buffer = buffer; - file->fd = fd; - file->type = type; - file->mark = 0; - set_memory_c(dcb + 5, refnum, 0); - return 0; + file->type = type; + file->level = get_memory_c(LEVEL, 0); + file->buffer = buffer; + file->fd = fd; + file->type = type; + file->mark = 0; + set_memory_c(dcb + 5, refnum, 0); + return 0; } static int mli_get_prefix(unsigned dcb) { - if (!saved_prefix) return -1; - unsigned buffer = get_memory16_c(dcb + 1, 0); - if (!buffer) return badBufferAddress; + if (!saved_prefix) return -1; + unsigned buffer = get_memory16_c(dcb + 1, 0); + if (!buffer) return badBufferAddress; - set_pstr(buffer, saved_prefix); - return 0; + set_pstr(buffer, saved_prefix); + return 0; } /* @@ -1009,152 +1009,152 @@ static int mli_get_prefix(unsigned dcb) { * path is the path on the native fs. */ static int mli_set_prefix(unsigned dcb, char *name, char *path) { - /* - * IF path is null, tail patch if we own the prefix. - * otherwise, handle it or forward to mli. - */ - if (!path) { - return saved_prefix ? -2 : -1; - } + /* + * IF path is null, tail patch if we own the prefix. + * otherwise, handle it or forward to mli. + */ + if (!path) { + return saved_prefix ? -2 : -1; + } - int l; - struct stat st; + int l; + struct stat st; - if (stat(path, &st) < 0) - return host_map_errno_path(errno, path); + if (stat(path, &st) < 0) + return host_map_errno_path(errno, path); - if (!S_ISDIR(st.st_mode)) { - return badStoreType; - } + if (!S_ISDIR(st.st_mode)) { + return badStoreType; + } - /* /HOST/ was previously stripped... add it back. */ - name = host_gc_append_path("/HOST", name); + /* /HOST/ was previously stripped... add it back. */ + name = host_gc_append_path("/HOST", name); - l = strlen(name); - /* trim trailing / */ - while (l > 1 && name[l-1] == '/') --l; - name[l] = 0; + l = strlen(name); + /* trim trailing / */ + while (l > 1 && name[l-1] == '/') --l; + name[l] = 0; - if (l > 63) return badPathSyntax; + if (l > 63) return badPathSyntax; - if (saved_prefix) - free(saved_prefix); - saved_prefix = strdup(name); - set_memory_c(PFIXPTR, 1, 0); - return 0; + if (saved_prefix) + free(saved_prefix); + saved_prefix = strdup(name); + set_memory_c(PFIXPTR, 1, 0); + return 0; } static int mli_online(unsigned dcb) { - /* not yet ... */ - unsigned unit = get_memory_c(dcb + 1, 0); - unsigned buffer = get_memory16_c(dcb + 2, 0); - if (unit == saved_unit) { - if (!buffer) return badBufferAddress; - /* slot 2, drive 1 ... why not*/ - set_memory_c(buffer++, saved_unit | 0x04, 0); - set_memory_c(buffer++, 'H', 0); - set_memory_c(buffer++, 'O', 0); - set_memory_c(buffer++, 'S', 0); - set_memory_c(buffer++, 'T', 0); - return 0; - } - if (unit == 0) return -2; - return -1; + /* not yet ... */ + unsigned unit = get_memory_c(dcb + 1, 0); + unsigned buffer = get_memory16_c(dcb + 2, 0); + if (unit == saved_unit) { + if (!buffer) return badBufferAddress; + /* slot 2, drive 1 ... why not*/ + set_memory_c(buffer++, saved_unit | 0x04, 0); + set_memory_c(buffer++, 'H', 0); + set_memory_c(buffer++, 'O', 0); + set_memory_c(buffer++, 'S', 0); + set_memory_c(buffer++, 'T', 0); + return 0; + } + if (unit == 0) return -2; + return -1; } static int mli_online_tail(unsigned dcb) { - unsigned buffer = get_memory16_c(dcb + 2, 0); + unsigned buffer = get_memory16_c(dcb + 2, 0); - host_hexdump(buffer, 256); + host_hexdump(buffer, 256); - /* if there was an error with the device - there will be an error code instead of a name (length = 0) - */ - - for (unsigned i = 0; i < 16; ++i, buffer += 16) { - unsigned x = get_memory_c(buffer, 0); - if (x == 0 || ((x & 0xf0) == saved_unit)) { - set_memory_c(buffer++, saved_unit | 0x04, 0); - set_memory_c(buffer++, 'H', 0); - set_memory_c(buffer++, 'O', 0); - set_memory_c(buffer++, 'S', 0); - set_memory_c(buffer++, 'T', 0); - break; - } - } + /* if there was an error with the device + there will be an error code instead of a name (length = 0) + */ - return 0; + for (unsigned i = 0; i < 16; ++i, buffer += 16) { + unsigned x = get_memory_c(buffer, 0); + if (x == 0 || ((x & 0xf0) == saved_unit)) { + set_memory_c(buffer++, saved_unit | 0x04, 0); + set_memory_c(buffer++, 'H', 0); + set_memory_c(buffer++, 'O', 0); + set_memory_c(buffer++, 'S', 0); + set_memory_c(buffer++, 'T', 0); + break; + } + } + + return 0; } static int mli_rw_block(unsigned dcb) { - unsigned unit = get_memory_c(dcb + 1, 0); - unsigned buffer = get_memory16_c(dcb + 2, 0); + unsigned unit = get_memory_c(dcb + 1, 0); + unsigned buffer = get_memory16_c(dcb + 2, 0); - if (unit == saved_unit) { - if (!buffer) return badBufferAddress; - return notBlockDev; /* network error? */ - } - return -1; + if (unit == saved_unit) { + if (!buffer) return badBufferAddress; + return notBlockDev; /* network error? */ + } + return -1; } static unsigned call_pcount(unsigned call) { - switch (call) { - case CREATE: return 7; - case DESTROY: return 1; - case RENAME: return 2; - case SET_FILE_INFO: return 7; - case GET_FILE_INFO: return 10; - case ONLINE: return 2; - case SET_PREFIX: return 1; - case GET_PREFIX: return 1; - case OPEN: return 3; - case NEWLINE: return 3; - case READ: return 4; - case WRITE: return 4; - case CLOSE: return 1; - case FLUSH: return 1; - case SET_MARK: return 2; - case GET_MARK: return 2; - case SET_EOF: return 2; - case GET_EOF: return 2; - case SET_BUF: return 2; - case GET_BUF: return 2; + switch (call) { + case CREATE: return 7; + case DESTROY: return 1; + case RENAME: return 2; + case SET_FILE_INFO: return 7; + case GET_FILE_INFO: return 10; + case ONLINE: return 2; + case SET_PREFIX: return 1; + case GET_PREFIX: return 1; + case OPEN: return 3; + case NEWLINE: return 3; + case READ: return 4; + case WRITE: return 4; + case CLOSE: return 1; + case FLUSH: return 1; + case SET_MARK: return 2; + case GET_MARK: return 2; + case SET_EOF: return 2; + case GET_EOF: return 2; + case SET_BUF: return 2; + case GET_BUF: return 2; - default: return 0; - } + default: return 0; + } } static const char *call_name(unsigned call) { - switch (call) { - case CREATE: return "CREATE"; - case DESTROY: return "DESTROY"; - case RENAME: return "RENAME"; - case SET_FILE_INFO: return "SET_FILE_INFO"; - case GET_FILE_INFO: return "GET_FILE_INFO"; - case ONLINE: return "ONLINE"; - case SET_PREFIX: return "SET_PREFIX"; - case GET_PREFIX: return "GET_PREFIX"; - case OPEN: return "OPEN"; - case NEWLINE: return "NEWLINE"; - case READ: return "READ"; - case WRITE: return "WRITE"; - case CLOSE: return "CLOSE"; - case FLUSH: return "FLUSH"; - case SET_MARK: return "SET_MARK"; - case GET_MARK: return "GET_MARK"; - case SET_EOF: return "SET_EOF"; - case GET_EOF: return "GET_EOF"; - case SET_BUF: return "SET_BUF"; - case GET_BUF: return "GET_BUF"; - case ATINIT: return "ATINIT"; + switch (call) { + case CREATE: return "CREATE"; + case DESTROY: return "DESTROY"; + case RENAME: return "RENAME"; + case SET_FILE_INFO: return "SET_FILE_INFO"; + case GET_FILE_INFO: return "GET_FILE_INFO"; + case ONLINE: return "ONLINE"; + case SET_PREFIX: return "SET_PREFIX"; + case GET_PREFIX: return "GET_PREFIX"; + case OPEN: return "OPEN"; + case NEWLINE: return "NEWLINE"; + case READ: return "READ"; + case WRITE: return "WRITE"; + case CLOSE: return "CLOSE"; + case FLUSH: return "FLUSH"; + case SET_MARK: return "SET_MARK"; + case GET_MARK: return "GET_MARK"; + case SET_EOF: return "SET_EOF"; + case GET_EOF: return "GET_EOF"; + case SET_BUF: return "SET_BUF"; + case GET_BUF: return "GET_BUF"; + case ATINIT: return "ATINIT"; - default: return ""; - } + default: return ""; + } } /* @@ -1166,263 +1166,263 @@ static const char *call_name(unsigned call) { */ void host_mli_head() { - word32 rts = get_memory16_c(engine.stack+1, 0); - saved_call = get_memory_c(rts + 1, 0); - saved_dcb = get_memory16_c(rts + 2, 0); - saved_p = engine.psr; + word32 rts = get_memory16_c(engine.stack+1, 0); + saved_call = get_memory_c(rts + 1, 0); + saved_dcb = get_memory16_c(rts + 2, 0); + saved_p = engine.psr; - /* do pcount / path stuff here */ - char *path1 = NULL; - char *path2 = NULL; - char *path3 = NULL; - char *path4 = NULL; + /* do pcount / path stuff here */ + char *path1 = NULL; + char *path2 = NULL; + char *path3 = NULL; + char *path4 = NULL; - struct file_entry *file = NULL; + struct file_entry *file = NULL; - unsigned pcount = get_memory_c(saved_dcb, 0); - unsigned xpcount = call_pcount(saved_call); - int acc = 0; - int refnum = 0; + unsigned pcount = get_memory_c(saved_dcb, 0); + unsigned xpcount = call_pcount(saved_call); + int acc = 0; + int refnum = 0; - if (xpcount && xpcount != pcount) { - acc = invalidPcount; - goto cleanup; - } + if (xpcount && xpcount != pcount) { + acc = invalidPcount; + goto cleanup; + } - switch(saved_call) { - case CREATE: - case DESTROY: - case SET_FILE_INFO: - case GET_FILE_INFO: - case OPEN: - path1 = is_host_path(get_memory16_c(saved_dcb + 1, 0)); - if (!path1) goto prodos_mli; - path3 = host_gc_append_path(host_root, path1); - break; - case RENAME: - path1 = is_host_path(get_memory16_c(saved_dcb + 1,0)); - path2 = is_host_path(get_memory16_c(saved_dcb + 3,0)); - if (!path1 && !path2) goto prodos_mli; - if (path1) path3 = host_gc_append_path(host_root, path1); - if (path2) path4 = host_gc_append_path(host_root, path2); - break; + switch(saved_call) { + case CREATE: + case DESTROY: + case SET_FILE_INFO: + case GET_FILE_INFO: + case OPEN: + path1 = is_host_path(get_memory16_c(saved_dcb + 1, 0)); + if (!path1) goto prodos_mli; + path3 = host_gc_append_path(host_root, path1); + break; + case RENAME: + path1 = is_host_path(get_memory16_c(saved_dcb + 1,0)); + path2 = is_host_path(get_memory16_c(saved_dcb + 3,0)); + if (!path1 && !path2) goto prodos_mli; + if (path1) path3 = host_gc_append_path(host_root, path1); + if (path2) path4 = host_gc_append_path(host_root, path2); + break; - case SET_PREFIX: - path1 = is_host_path(get_memory16_c(saved_dcb + 1,0)); - if (!path1 && !saved_prefix) goto prodos_mli; - if (path1) path3 = host_gc_append_path(host_root, path1); - break; + case SET_PREFIX: + path1 = is_host_path(get_memory16_c(saved_dcb + 1,0)); + if (!path1 && !saved_prefix) goto prodos_mli; + if (path1) path3 = host_gc_append_path(host_root, path1); + break; - case GET_PREFIX: - if (!saved_prefix) goto prodos_mli; - break; + case GET_PREFIX: + if (!saved_prefix) goto prodos_mli; + break; - /* refnum based */ - case NEWLINE: - case READ: - case WRITE: - case SET_MARK: - case GET_MARK: - case SET_EOF: - case GET_EOF: - case SET_BUF: - case GET_BUF: - refnum = get_memory_c(saved_dcb + 1, 0); + /* refnum based */ + case NEWLINE: + case READ: + case WRITE: + case SET_MARK: + case GET_MARK: + case SET_EOF: + case GET_EOF: + case SET_BUF: + case GET_BUF: + refnum = get_memory_c(saved_dcb + 1, 0); - if (refnum >= MIN_FILE && refnum < MAX_FILE) { - file = &files[refnum - MIN_FILE]; - } else { - goto prodos_mli; - } - break; + if (refnum >= MIN_FILE && refnum < MAX_FILE) { + file = &files[refnum - MIN_FILE]; + } else { + goto prodos_mli; + } + break; - case CLOSE: - case FLUSH: - /* special case for refnum == 0 */ - refnum = get_memory_c(saved_dcb + 1, 0); + case CLOSE: + case FLUSH: + /* special case for refnum == 0 */ + refnum = get_memory_c(saved_dcb + 1, 0); - if (refnum >= MIN_FILE && refnum < MAX_FILE) { - file = &files[refnum - MIN_FILE]; - } else if (refnum) { - goto prodos_mli; - } + if (refnum >= MIN_FILE && refnum < MAX_FILE) { + file = &files[refnum - MIN_FILE]; + } else if (refnum) { + goto prodos_mli; + } - break; + break; - } + } - fprintf(stderr, "MLI: %02x %s", saved_call, call_name(saved_call)); - if (path1) fprintf(stderr, " - %s", path1); - if (path2) fprintf(stderr, " - %s", path2); + fprintf(stderr, "MLI: %02x %s", saved_call, call_name(saved_call)); + if (path1) fprintf(stderr, " - %s", path1); + if (path2) fprintf(stderr, " - %s", path2); - switch (saved_call) { - default: - engine.kpc = saved_mli_address; - return; + switch (saved_call) { + default: + engine.kpc = saved_mli_address; + return; - case ATINIT: - acc = mli_atinit(saved_dcb); - break; + case ATINIT: + acc = mli_atinit(saved_dcb); + break; - case CREATE: - acc = mli_create(saved_dcb, path3); - break; + case CREATE: + acc = mli_create(saved_dcb, path3); + break; - case DESTROY: - acc = mli_destroy(saved_dcb, path3); - break; + case DESTROY: + acc = mli_destroy(saved_dcb, path3); + break; - case SET_FILE_INFO: - acc = mli_set_file_info(saved_dcb, path3); - break; + case SET_FILE_INFO: + acc = mli_set_file_info(saved_dcb, path3); + break; - case GET_FILE_INFO: - acc = mli_get_file_info(saved_dcb, path3); - break; + case GET_FILE_INFO: + acc = mli_get_file_info(saved_dcb, path3); + break; - case OPEN: - acc = mli_open(saved_dcb, path1, path3); - break; + case OPEN: + acc = mli_open(saved_dcb, path1, path3); + break; - case RENAME: - acc = mli_rename(saved_dcb, path3, path4); - break; + case RENAME: + acc = mli_rename(saved_dcb, path3, path4); + break; - case SET_PREFIX: - acc = mli_set_prefix(saved_dcb, path1, path3); - break; + case SET_PREFIX: + acc = mli_set_prefix(saved_dcb, path1, path3); + break; - case GET_PREFIX: - acc = mli_get_prefix(saved_dcb); - break; + case GET_PREFIX: + acc = mli_get_prefix(saved_dcb); + break; - case ONLINE: - acc = mli_online(saved_dcb); - break; + case ONLINE: + acc = mli_online(saved_dcb); + break; - case NEWLINE: - acc = mli_newline(saved_dcb, file); - break; + case NEWLINE: + acc = mli_newline(saved_dcb, file); + break; - case READ: - acc = mli_read(saved_dcb, file); - break; + case READ: + acc = mli_read(saved_dcb, file); + break; - case WRITE: - acc = mli_write(saved_dcb, file); - break; + case WRITE: + acc = mli_write(saved_dcb, file); + break; - case SET_MARK: - acc = mli_set_mark(saved_dcb, file); - break; + case SET_MARK: + acc = mli_set_mark(saved_dcb, file); + break; - case GET_MARK: - acc = mli_get_mark(saved_dcb, file); - break; + case GET_MARK: + acc = mli_get_mark(saved_dcb, file); + break; - case SET_EOF: - acc = mli_set_eof(saved_dcb, file); - break; + case SET_EOF: + acc = mli_set_eof(saved_dcb, file); + break; - case GET_EOF: - acc = mli_get_eof(saved_dcb, file); - break; + case GET_EOF: + acc = mli_get_eof(saved_dcb, file); + break; - case SET_BUF: - acc = mli_set_buf(saved_dcb, file); - break; + case SET_BUF: + acc = mli_set_buf(saved_dcb, file); + break; - case GET_BUF: - acc = mli_get_buf(saved_dcb, file); - break; + case GET_BUF: + acc = mli_get_buf(saved_dcb, file); + break; - case CLOSE: - acc = mli_close(saved_dcb, file); - break; + case CLOSE: + acc = mli_close(saved_dcb, file); + break; - case FLUSH: - acc = mli_flush(saved_dcb, file); - break; + case FLUSH: + acc = mli_flush(saved_dcb, file); + break; - case WRITE_BLOCK: - case READ_BLOCK: - acc = mli_rw_block(saved_dcb); - break; + case WRITE_BLOCK: + case READ_BLOCK: + acc = mli_rw_block(saved_dcb); + break; - case QUIT: - acc = mli_quit(saved_dcb); - break; + case QUIT: + acc = mli_quit(saved_dcb); + break; - } - fputs("\n", stderr); - host_gc_free(); + } + fputs("\n", stderr); + host_gc_free(); - if (acc == -2) { - /* tail call needed */ - /* - jsr xxxx - dc.b xx - dc.w xxxx - wdm .. - rts - */ - SEI(); - set_memory_c(saved_patch_address + 0, saved_call, 0); - set_memory16_c(saved_patch_address + 1, saved_dcb, 0); - set_memory16_c(engine.stack+1, rts + 3, 0); - return; - } - if (acc < 0) { + if (acc == -2) { + /* tail call needed */ + /* + jsr xxxx + dc.b xx + dc.w xxxx + wdm .. + rts + */ + SEI(); + set_memory_c(saved_patch_address + 0, saved_call, 0); + set_memory16_c(saved_patch_address + 1, saved_dcb, 0); + set_memory16_c(engine.stack+1, rts + 3, 0); + return; + } + if (acc < 0) { prodos_mli: - host_gc_free(); - /* pass to normal dispatcher */ - engine.kpc = saved_mli_address; - return; - } + host_gc_free(); + /* pass to normal dispatcher */ + engine.kpc = saved_mli_address; + return; + } cleanup: - /* fixup */ - acc &= 0xff; + /* fixup */ + acc &= 0xff; - if (acc) fprintf(stderr, " %02x %s\n", acc, host_error_name(acc)); - if (acc == 0 && saved_call != ATINIT) { - set_memory_c(DEVNUM, saved_unit, 0); - } - engine.acc &= 0xff00; - engine.acc |= acc; - if (acc) { - SEC(); - CLZ(); - } else { - CLC(); - SEZ(); - } - engine.kpc = rts + 4; - engine.stack += 2; - return; + if (acc) fprintf(stderr, " %02x %s\n", acc, host_error_name(acc)); + if (acc == 0 && saved_call != ATINIT) { + set_memory_c(DEVNUM, saved_unit, 0); + } + engine.acc &= 0xff00; + engine.acc |= acc; + if (acc) { + SEC(); + CLZ(); + } else { + CLC(); + SEZ(); + } + engine.kpc = rts + 4; + engine.stack += 2; + return; } void host_mli_tail() { - if (!(engine.psr & C)) { + if (!(engine.psr & C)) { - switch(saved_call) { - case SET_PREFIX: - free(saved_prefix); - saved_prefix = NULL; - break; - case ONLINE: - mli_online_tail(saved_dcb); - break; - } - } + switch(saved_call) { + case SET_PREFIX: + free(saved_prefix); + saved_prefix = NULL; + break; + case ONLINE: + mli_online_tail(saved_dcb); + break; + } + } - // clean up I bit (set in head) - engine.psr &= ~I; - engine.psr |= (saved_p & I); - host_gc_free(); + // clean up I bit (set in head) + engine.psr &= ~I; + engine.psr |= (saved_p & I); + host_gc_free(); } \ No newline at end of file