From 88ead2b6e4144749ef0e1f761dfdde3c4b16fa7f Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 4 Jan 2009 18:13:31 -0800 Subject: abcprintd: fix fileop state machine; add debugging printfs Fix the fileop state machine. Disable daemonizing and add some debugging printfs for the moment. --- tools/abcprintd.c | 4 +++- tools/fileop.c | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/tools/abcprintd.c b/tools/abcprintd.c index 5925e55..15ff502 100644 --- a/tools/abcprintd.c +++ b/tools/abcprintd.c @@ -232,7 +232,9 @@ int main(int argc, char *argv[]) memcpy(lpr_argv, argv+optind+1, sizeof(char *)*(lpr_argc+1)); } - daemon(0,0); + fprintf(stderr, "filedir = %s\n", file_op_dir); + + // daemon(0,0); print_setup(&tf, &ps); diff --git a/tools/fileop.c b/tools/fileop.c index cce13df..ccb3b13 100644 --- a/tools/fileop.c +++ b/tools/fileop.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -110,7 +111,7 @@ static const char my_tolower[256] = static void do_open(int fd, uint16_t ix, char *name) { - char *path, *p; + char *path, *p, *p0; int opl; int i; bool nodot; @@ -131,12 +132,14 @@ static void do_open(int fd, uint16_t ix, char *name) path = alloca(opl+14); memcpy(path, file_op_dir, opl); p = path+opl; - *p++ = '/'; + if (p[-1] != '/') + *p++ = '/'; nodot = true; + p0 = p; for (i = 0; i < 11; i++) { if (name[i] != ' ') { - if (i >= 8 && !nodot) { + if (i >= 8 && nodot) { *p++ = '.'; nodot = false; } @@ -144,11 +147,14 @@ static void do_open(int fd, uint16_t ix, char *name) } } - if (p == path+opl+1) { + if (p == p0) { /* Empty filename */ send_reply(fd, 128+21); /* File not found */ return; } + *p = '\0'; + + fprintf(stderr, "open %s mode %s\n", path, modes[cmd[0] & 3]); fm = calloc(1, sizeof(struct file_info *)); if (!fm) { @@ -337,6 +343,8 @@ bool file_op(unsigned char c, int fd) static unsigned char lenbuf[2]; uint16_t ix, len; + fprintf(stderr, "<%02X %c>\n", c, isprint(c) ? c : '.'); + *bytep++ = c; if (--byte_count) return true; /* More to do... */ @@ -416,7 +424,6 @@ bool file_op(unsigned char c, int fd) /* unless otherwise specified, back to command mode */ bytep = cmd; byte_count = 4; + state = st_op; return false; } - - -- cgit