From a1b5508bd90c19cd713c9513a2effc57dec40ef9 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 7 Jul 2018 00:36:04 +0100 Subject: [PATCH] cpmfs: update types etc --- Applications/cpmfs/src/bitmap.c | 20 +++++++++++--------- Applications/cpmfs/src/blockio.c | 8 ++++---- Applications/cpmfs/src/cfillbuf.c | 5 +++-- Applications/cpmfs/src/cflsbuf.c | 2 +- Applications/cpmfs/src/cmdhdl.c | 25 ++++++++++--------------- Applications/cpmfs/src/cpm.c | 13 ++++--------- Applications/cpmfs/src/cpm.h | 16 ++++++++-------- Applications/cpmfs/src/extent.c | 4 ++-- Applications/cpmfs/src/interact.c | 5 ++--- Applications/cpmfs/src/physio.c | 9 ++++----- Applications/cpmfs/src/rename.c | 2 +- 11 files changed, 50 insertions(+), 59 deletions(-) diff --git a/Applications/cpmfs/src/bitmap.c b/Applications/cpmfs/src/bitmap.c index 7788e24e..663940ec 100644 --- a/Applications/cpmfs/src/bitmap.c +++ b/Applications/cpmfs/src/bitmap.c @@ -7,7 +7,7 @@ #include "cpm.h" -int bm_size; +unsigned int bm_size; /* * Bit map handling routines; @@ -25,9 +25,10 @@ int bm_size; /* * Allocate a new disk block, return NULL if disk full */ -int alloc(void) +unsigned int alloc(void) { - int i, j, blk; + unsigned int i, blk; + int j; /* FIXME use ptr and ++ for bitmap */ for (i = 0; i < bm_size; i++) { @@ -55,7 +56,7 @@ void dbmap(const char *str) { #ifdef DEBUG - int i; + unsigned int i; printf("%s\n", str); for (i = 0; i < bm_size; i++) @@ -68,7 +69,7 @@ void dbmap(const char *str) * directory, including the directory blocks */ -int blks_used(void) +unsigned int blks_used(void) { int j, i, temp; @@ -95,9 +96,10 @@ int blks_used(void) void build_bmap(void) { - int i, j, offset, block; + unsigned int i, j; + unsigned int offset, block; - bm_size = 1 + ((seclth * sectrk * (tracks - restrk)) / blksiz) / INTSIZE; + bm_size = 1 + (((uint32_t)seclth * sectrk * (tracks - restrk)) / blksiz) / INTSIZE; if (!bitmap) { if ((bitmap = malloc(bm_size * 4)) == NULL) { @@ -119,7 +121,7 @@ void build_bmap(void) for (i = 0; i < maxdir; i++) { if ((dirbuf + i)->status != (char) 0xe5) { #ifdef DEBUG - printf("%d ->%8s\n", i, (dirbuf + i)->name); + printf("%u ->%8s\n", i, (dirbuf + i)->name); #endif if (use16bitptrs) for (j = 0; (j < 8) && (((dirbuf + i)->pointers[2 * j] != '\0') @@ -128,7 +130,7 @@ void build_bmap(void) + (0xff00 & ((int) (dirbuf + i)->pointers[2 * j + 1] << 8)); offset = block / INTSIZE; #ifdef DEBUG - printf("blk:%d, offs:%d, bit:%d\n", block, offset, block % INTSIZE); + printf("blk:%u, offs:%u, bit:%u\n", block, offset, block % INTSIZE); #endif if (offset < 0 || offset > bm_size * 4) { fprintf(stderr, "bad offset into bitmap, wrong format?\n"); diff --git a/Applications/cpmfs/src/blockio.c b/Applications/cpmfs/src/blockio.c index 394add65..0f7fb14d 100644 --- a/Applications/cpmfs/src/blockio.c +++ b/Applications/cpmfs/src/blockio.c @@ -10,10 +10,10 @@ * if nsect is negative then always read a full block. */ -int getblock(int blockno, char *buffer, int nsect) +int getblock(unsigned int blockno, char *buffer, int nsect) { - int sect, track, counter; + unsigned int sect, track, counter; #ifdef DEBUG printf("block: %d\n", blockno); @@ -42,10 +42,10 @@ int getblock(int blockno, char *buffer, int nsect) * If nsects is negative, write a full block. */ -int putblock(int blockno, char *buffer, int nsect) +int putblock(unsigned int blockno, char *buffer, int nsect) { - int sect, track, counter; + unsigned int sect, track, counter; if (nsect < 0) nsect = blksiz / seclth; diff --git a/Applications/cpmfs/src/cfillbuf.c b/Applications/cpmfs/src/cfillbuf.c index 6227cba3..0f8dd153 100644 --- a/Applications/cpmfs/src/cfillbuf.c +++ b/Applications/cpmfs/src/cfillbuf.c @@ -8,13 +8,14 @@ int c_fillbuf(C_FILE * fptr) int nsect; - if (++fptr->c_blk == (use16bitptrs ? 8 : 16)) + if (++fptr->c_blk == (use16bitptrs ? 8 : 16)) { if (fptr->c_dirp->blkcnt == (char) 0x80) { /* find next extent (if it exists) */ - if (getnext(fptr) == NULL) + if (getnext(fptr) == 0) return EOF; } else return EOF; + } /* This seems to reccur - uninline ? */ nsect = (fptr->c_seccnt > blksiz / seclth) ? blksiz / seclth : fptr->c_seccnt; if (nsect == 0) diff --git a/Applications/cpmfs/src/cflsbuf.c b/Applications/cpmfs/src/cflsbuf.c index c9962973..f82814b7 100644 --- a/Applications/cpmfs/src/cflsbuf.c +++ b/Applications/cpmfs/src/cflsbuf.c @@ -28,7 +28,7 @@ int c_flush(C_FILE * fptr) fptr->c_dirp->blkcnt = (char) 0x80; savedir(); /* create new extent */ - if ((it = creext(fptr->c_ext)) == NULL) { + if ((it = creext(fptr->c_ext)) == 0) { fprintf(stderr, "can't create new extent, current: %d\n", fptr->c_ext); return EOF; } diff --git a/Applications/cpmfs/src/cmdhdl.c b/Applications/cpmfs/src/cmdhdl.c index 7847328c..e7198e68 100644 --- a/Applications/cpmfs/src/cmdhdl.c +++ b/Applications/cpmfs/src/cmdhdl.c @@ -7,7 +7,7 @@ #include "cpm.h" #ifndef HELPFILE -#define HELPFILE "/usr/local/lib/cpm.hlp" +#define HELPFILE "/usr/lib/cpm.hlp" #endif /* @@ -16,21 +16,16 @@ * return the number of characters read. */ -int cmdinp(char *cmd) +void cmdinp(char *cmd, int len) { - - int cnt = 0, c; - - while (cnt == 0) { + char *p; + do { printf("cpm> "); - /* BUFFER OVERFLOW FIXME */ - while ((c = getchar()) != EOF && c != '\n') - cmd[cnt++] = c; - if (c == EOF) + if (fgets(cmd, len - 1, stdin) == NULL) exit(0); - cmd[cnt] = '\0'; - } - return cnt; + p = cmd + strlen(cmd); + p[-1] = 0; + } while(*cmd); } /* @@ -109,8 +104,8 @@ int namesep(const char *fname, char *name, char *ext) int i = 0; - strncpy(name, " ", 9); - strncpy(ext, " ", 4); + memcpy(name, " ", 9); + memcpy(ext, " ", 4); while (i < 8 && !(iscntrl(fname[i])) && fname[i] != '.') { name[i] = fname[i]; i++; diff --git a/Applications/cpmfs/src/cpm.c b/Applications/cpmfs/src/cpm.c index a7d3d74f..e651c448 100644 --- a/Applications/cpmfs/src/cpm.c +++ b/Applications/cpmfs/src/cpm.c @@ -56,7 +56,7 @@ #include #include "cpm.h" -#define BIG 2147483647UL +#define BIG 0xFFFFUL C_FILE c_iob[C_NFILE]; int fid; @@ -342,24 +342,19 @@ int number(int big) continue; case 'w': - n *= sizeof(int); + n *= 2; continue; case 'b': n *= 512; continue; - case '*': - case 'x': - string = cs; - n *= number(BIG); - case '\0': if (n >= big || n < 0) { - fprintf(stderr, "number: argument %D out of range\n", n); + fprintf(stderr, "number: argument %ld out of range\n", n); exit(1); } - return (n); + return n; } } diff --git a/Applications/cpmfs/src/cpm.h b/Applications/cpmfs/src/cpm.h index 726cdbcb..fb15bef6 100644 --- a/Applications/cpmfs/src/cpm.h +++ b/Applications/cpmfs/src/cpm.h @@ -36,7 +36,7 @@ extern int skew; extern int restrk; /* reserved tracks (for system) */ extern int *bitmap, *skewtab; -extern int bm_size; +extern unsigned int bm_size; extern int use16bitptrs; /* cpmfio.h 1.5 83/05/13 */ @@ -67,13 +67,13 @@ extern C_FILE c_iob[C_NFILE]; #define MODFLG 0x08 #define BINARY 0x10 -extern int alloc(void); +extern unsigned int alloc(void); extern void dbmap(const char *str); -extern int blks_used(void); +extern unsigned int blks_used(void); extern void build_bmap(void); -extern int getblock(int blockno, char *buffer, int nsect); -extern int putblock(int blockno, char *buffer, int nsect); +extern int getblock(unsigned int blockno, char *buffer, int nsect); +extern int putblock(unsigned int blockno, char *buffer, int nsect); extern int c_close(C_FILE * fptr); extern C_FILE *c_creat(const char *name, const char *ext, int flag); @@ -81,7 +81,7 @@ extern int c_fillbuf(C_FILE * fptr); extern int c_flush(C_FILE * fptr); extern int c_flsbuf(int c, C_FILE * fptr); extern int c_write(C_FILE * fptr, char *buf, int cnt); -extern int cmdinp(const char *cmd); +extern void cmdinp(char *cmd, int len); extern int chkcmd(const char *cmd); extern void help(void); extern int namesep(const char *fname, char *name, char *ext); @@ -108,8 +108,8 @@ extern void hexdump(C_FILE * fp); extern void printline(FILE * piped, int *cbuf, int nc); extern void interact(void); extern void intrpt(int sig); -extern int putpsect(int tr, int sect, const char *buf); -extern int getpsect(int tr, int sect, const char *buf); +extern int putpsect(unsigned int tr, unsigned int sect, const char *buf); +extern int getpsect(unsigned int tr, unsigned int sect, char *buf); extern int initcpm(const char *name); extern void pip(char *cmdline, int bin); extern void pipc(const char *unixfile, const char *cpmfile, int bin); diff --git a/Applications/cpmfs/src/extent.c b/Applications/cpmfs/src/extent.c index c5b13ae1..60551c68 100644 --- a/Applications/cpmfs/src/extent.c +++ b/Applications/cpmfs/src/extent.c @@ -15,7 +15,7 @@ int creext(int curext) { - int i, j; + unsigned int i, j; for (i = 0; i < maxdir; i++) if ((dirbuf + i)->status == (char) 0xe5) @@ -45,7 +45,7 @@ int creext(int curext) int getnext(C_FILE * cur) { - int ind; + unsigned int ind; cur->c_extno++; for (ind = 0; ind < maxdir; ind++) diff --git a/Applications/cpmfs/src/interact.c b/Applications/cpmfs/src/interact.c index 1c241c38..4dd1cc61 100644 --- a/Applications/cpmfs/src/interact.c +++ b/Applications/cpmfs/src/interact.c @@ -22,8 +22,7 @@ void interact(void) signal(SIGINT, intrpt); (void) setjmp(env); } - if (cmdinp(cmd) < 0) - return; + cmdinp(cmd, 80); rest = strchr(cmd, ' '); if (rest) *rest++ = '\0'; @@ -93,7 +92,7 @@ void interact(void) void intrpt(int sig) { - /* FIXME: restore signal handler! */ + signal(sig, intrpt); firsttime = 0; printf("\n"); longjmp(env, 0); diff --git a/Applications/cpmfs/src/physio.c b/Applications/cpmfs/src/physio.c index de33916b..c5f27af5 100644 --- a/Applications/cpmfs/src/physio.c +++ b/Applications/cpmfs/src/physio.c @@ -6,15 +6,14 @@ #include #include "cpm.h" -/* Again look at sizes - think we need uint16_t's */ /* * Write physical sector to floppy disk file */ -int putpsect(int tr, int sect, const char *buf) +int putpsect(unsigned int tr, unsigned int sect, const char *buf) { - long newpos; + off_t newpos; if (sect > sectrk || sect < 1) { fprintf(stderr, "putpsect: sector number out of range: %d\n", sect); @@ -36,10 +35,10 @@ int putpsect(int tr, int sect, const char *buf) * Read physical sector from floppy disk file */ -int getpsect(int tr, int sect, const char *buf) +int getpsect(unsigned int tr, unsigned int sect, char *buf) { - long newpos; + off_t newpos; if (sect > sectrk || sect < 1) { fprintf(stderr, "getpsect: sector number out of range: %d\n", sect); diff --git a/Applications/cpmfs/src/rename.c b/Applications/cpmfs/src/rename.c index f2507adf..6acd9753 100644 --- a/Applications/cpmfs/src/rename.c +++ b/Applications/cpmfs/src/rename.c @@ -32,7 +32,7 @@ int Rename(char *cmdline) do { strncpy(cio->c_dirp->name, newname, 8); strncpy(cio->c_dirp->ext, newext, 3); - } while (getnext(cio) != NULL); + } while (getnext(cio) != 0); } else { fnfound(oldname, oldext); return 1; -- 2.34.1