aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-08-08 18:05:37 -0700
committerH. Peter Anvin <hpa@zytor.com>2012-08-08 18:05:37 -0700
commitd227c2aefd6f0bc9dbbe4bfbd0a56f9082d232fb (patch)
treed7d190dd46bbedf85d45239bbc61483cc4b87d99
parent53a5e563dd11d19c811b4d6ab71d45248cb39211 (diff)
downloadabc80-d227c2aefd6f0bc9dbbe4bfbd0a56f9082d232fb.tar.gz
abc80-d227c2aefd6f0bc9dbbe4bfbd0a56f9082d232fb.tar.xz
abc80-d227c2aefd6f0bc9dbbe4bfbd0a56f9082d232fb.zip
fileop: for the LIB function, use 8.3 notation so INPUT can handle
Use 8.3 (LIB.BAS) instead of NNNNNNNNEEE (LIB BAS).
-rw-r--r--tools/fileop.c53
1 files changed, 40 insertions, 13 deletions
diff --git a/tools/fileop.c b/tools/fileop.c
index c0e4ff6..e25f50a 100644
--- a/tools/fileop.c
+++ b/tools/fileop.c
@@ -258,9 +258,9 @@ static void do_read_block(int fd, uint16_t ix, uint16_t len)
}
/*
- * Returns 0 for OK, -1 for failure
+ * Returns length for OK, 0 for failure
*/
-static int mangle_name(char *dst, const char *src)
+static int mangle_for_readdir(char *dst, const char *src)
{
static const wchar_t srcset[] =
L"0123456789_."
@@ -270,22 +270,23 @@ static int mangle_name(char *dst, const char *src)
"0123456789_."
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^[\\"
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^[\\";
- char *d = dst;
+ char *d;
const char *s;
wchar_t sc;
const wchar_t *scp;
char dc;
int n;
- char unmangle_buf[64];
+ char mangle_buf[12], unmangle_buf[64];
s = src;
- memset(dst, ' ', 11);
- dst[11] = '\0';
+ memset(mangle_buf, ' ', 11);
+ mangle_buf[11] = '\0';
mbtowc(NULL, NULL, 0); /* Reset the shift state */
- while (d < dst+11 && (n = mbtowc(&sc, s, (size_t)~0)) > 0) {
+ d = mangle_buf;
+ while (d < mangle_buf+11 && (n = mbtowc(&sc, s, (size_t)~0)) > 0) {
s += n;
if ( (scp = wcschr(srcset, sc)) ) {
@@ -295,13 +296,38 @@ static int mangle_name(char *dst, const char *src)
}
if ( dc == '.' )
- d = dst+8;
+ d = mangle_buf+8;
else
*d++ = dc;
}
- unmangle_filename(unmangle_buf, dst);
- return strcmp(unmangle_buf, src) ? 0 : -1;
+ unmangle_filename(unmangle_buf, mangle_buf);
+
+ if (strcmp(unmangle_buf, src))
+ return 0; /* Not round-trippable */
+
+ /* Compact to 8.3 notation */
+ d = dst;
+ s = mangle_buf;
+ for (n = 0; n < 8; n++) {
+ if (*s != ' ')
+ *d++ = *s;
+ s++;
+ }
+ if (memcmp(s, " ", 3)) {
+ *d++ = '.';
+ for (n = 0; n < 3; n++) {
+ if (*s != ' ')
+ *d++ = *s;
+ s++;
+ }
+ }
+ *d = '\0';
+
+ fprintf(stderr, "mangle: %s -> %11.11s -> %s -> %s\n",
+ src, mangle_buf, unmangle_buf, dst);
+
+ return d - dst;
}
@@ -360,13 +386,14 @@ static void do_input(int fd, uint16_t ix)
}
} else if (fm->d) {
while ( (de = readdir(fm->d)) ) {
- if (de->d_name[0] != '.' && !mangle_name(data1+2, de->d_name) &&
+ if (de->d_name[0] != '.' &&
+ (dlen = mangle_for_readdir(data1+2, de->d_name)) &&
!stat(de->d_name, &st) && S_ISREG(st.st_mode))
break;
}
if (de) {
- dlen = 11 + sprintf(data1+2+11, ",%lu\r\n",
- ((unsigned long)st.st_size + 252)/253);
+ dlen += sprintf(data1+2+dlen, ",%lu\r\n",
+ ((unsigned long)st.st_size + 252)/253);
err = 0;
} else {
err = 128+34;