X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=fsed.cpm.c;h=f120b77c4a364749a3cdc119469acd710576a24b;hb=b1e873c5b2f6376bb39ff0fda1464cbbacbae5f7;hp=dfd94670ba79fe62a5776b91cb051b7b5106eec9;hpb=32087c67d53a8f8058b359388f23e2dbc9436d54;p=debian%2Fcpmtools diff --git a/fsed.cpm.c b/fsed.cpm.c index dfd9467..f120b77 100644 --- a/fsed.cpm.c +++ b/fsed.cpm.c @@ -3,13 +3,27 @@ #include #include +#if NEED_NCURSES +#if HAVE_NCURSES_NCURSES_H +#include +#else +#include +#endif +#else #include +#endif #include #include #include #include +#include #include "cpmfs.h" +#include "getopt_.h" + +#ifdef USE_DMALLOC +#include +#endif /*}}}*/ extern char **environ; @@ -21,7 +35,7 @@ static struct tm *cpmtime(char lday, char hday, char hour, char min) /*{{{*/ static struct tm tm; unsigned long days=(lday&0xff)|((hday&0xff)<<8); int d; - int md[12]={31,0,31,30,31,30,31,31,30,31,30,31}; + unsigned int md[12]={31,0,31,30,31,30,31,31,30,31,30,31}; tm.tm_sec=0; tm.tm_min=((min>>4)&0xf)*10+(min&0xf); @@ -83,7 +97,8 @@ static void map(struct cpmSuperBlock *sb) /*{{{*/ { const char *msg; char bmap[18*80]; - int secmap,pos,system,directory; + int secmap,sys,directory; + int pos; clear(); msg="Data map"; @@ -91,11 +106,11 @@ static void map(struct cpmSuperBlock *sb) /*{{{*/ secmap=(sb->tracks*sb->sectrk+80*18-1)/(80*18); memset(bmap,' ',sizeof(bmap)); - system=sb->boottrk*sb->sectrk; - memset(bmap,'S',system/secmap); + sys=sb->boottrk*sb->sectrk; + memset(bmap,'S',sys/secmap); directory=(sb->maxdir*32+sb->secLength-1)/sb->secLength; - memset(bmap+system/secmap,'D',directory/secmap); - memset(bmap+(system+directory)/secmap,'.',sb->sectrk*sb->tracks/secmap); + memset(bmap+sys/secmap,'D',directory/secmap); + memset(bmap+(sys+directory)/secmap,'.',sb->sectrk*sb->tracks/secmap); for (pos=0; pos<(sb->maxdir*32+sb->secLength-1)/sb->secLength; ++pos) { @@ -110,7 +125,7 @@ static void map(struct cpmSuperBlock *sb) /*{{{*/ { for (i=0; i<16; ++i) { - unsigned int sector; + int sector; sector=mapbuf[entry*32+16+i]&0xff; if (sb->size>=256) sector|=(((mapbuf[entry*32+16+ ++i]&0xff)<<8)); @@ -125,7 +140,7 @@ static void map(struct cpmSuperBlock *sb) /*{{{*/ } } - for (pos=0; possecLength)&~0x7f; - int i; + unsigned int i; for (i=0; i<128; ++i) { @@ -162,16 +177,17 @@ int main(int argc, char *argv[]) /*{{{*/ const char *err; struct cpmSuperBlock drive; struct cpmInode root; - const char *format=FORMAT; + const char *format; int c,usage=0; - unsigned long pos; + off_t pos; chtype ch; int reload; char *buf; /*}}}*/ /* parse options */ /*{{{*/ - while ((c=getopt(argc,argv,"f:h?"))!=EOF) switch(c) + if (!(format=getenv("CPMTOOLSFMT"))) format=FORMAT; + while ((c=getopt(argc,argv,"T:f:h?"))!=EOF) switch(c) { case 'f': format=optarg; break; case 'T': devopts=optarg; break; @@ -180,7 +196,7 @@ int main(int argc, char *argv[]) /*{{{*/ } if (optind!=(argc-1)) usage=1; - else image=argv[optind]; + else image=argv[optind++]; if (usage) { @@ -191,10 +207,14 @@ int main(int argc, char *argv[]) /*{{{*/ /* open image */ /*{{{*/ if ((err=Device_open(&drive.dev,image,O_RDONLY,devopts))) { - fprintf(stderr,"%s: can not open %s (%s)\n",cmd,image,err); + fprintf(stderr,"%s: cannot open %s (%s)\n",cmd,image,err); + exit(1); + } + if (cpmReadSuper(&drive,&root,format)==-1) + { + fprintf(stderr,"%s: cannot read superblock (%s)\n",cmd,boo); exit(1); } - cpmReadSuper(&drive,&root,format); /*}}}*/ /* alloc sector buffers */ /*{{{*/ if ((buf=malloc(drive.secLength))==(char*)0 || (mapbuf=malloc(drive.secLength))==(char*)0) @@ -220,25 +240,23 @@ int main(int argc, char *argv[]) /*{{{*/ { /* display position and load data */ /*{{{*/ clear(); - move(2,0); printw("Byte %8d (0x%08x) ",pos,pos); + move(2,0); printw("Byte %8lu (0x%08lx) ",pos,pos); if (pos<(drive.boottrk*drive.sectrk*drive.secLength)) { - printw("Physical sector %3d ",((pos/drive.secLength)%drive.sectrk)+1); + printw("Physical sector %3lu ",((pos/drive.secLength)%drive.sectrk)+1); } else { - printw("Sector %3d ",((pos/drive.secLength)%drive.sectrk)+1); + printw("Sector %3lu ",((pos/drive.secLength)%drive.sectrk)+1); printw("(physical %3d) ",drive.skewtab[(pos/drive.secLength)%drive.sectrk]+1); } - printw("Offset %5d ",pos%drive.secLength); - printw("Track %5d",pos/(drive.secLength*drive.sectrk)); + printw("Offset %5lu ",pos%drive.secLength); + printw("Track %5lu",pos/(drive.secLength*drive.sectrk)); move(LINES-3,0); printw("N)ext track P)revious track"); - move(LINES-2,0); printw("n)ext record n)revious record f)orward byte b)ackward byte"); + move(LINES-2,0); printw("n)ext record p)revious record f)orward byte b)ackward byte"); move(LINES-1,0); printw("i)nfo q)uit"); if (reload) { - const char *err; - if (pos<(drive.boottrk*drive.sectrk*drive.secLength)) { err=Device_readSector(&drive.dev,pos/(drive.secLength*drive.sectrk),(pos/drive.secLength)%drive.sectrk,buf); @@ -267,7 +285,7 @@ int main(int argc, char *argv[]) /*{{{*/ { case 'F': /* next 16 byte */ /*{{{*/ { - if (pos+16<(drive.sectrk*drive.tracks*(unsigned long)drive.secLength)) + if (pos+16<(drive.sectrk*drive.tracks*(off_t)drive.secLength)) { if (pos/drive.secLength!=(pos+16)/drive.secLength) reload=1; pos+=16; @@ -413,11 +431,11 @@ int main(int argc, char *argv[]) /*{{{*/ printw("Password: "); for (i=0; i<8; ++i) { - char c; + char printable; if (offset==16+(7-i)) attron(A_REVERSE); - c=(buf[entrystart+16+(7-i)]^buf[entrystart+13])&0x7f; - printw("%c",isprint(c) ? c : ' '); + printable=(buf[entrystart+16+(7-i)]^buf[entrystart+13])&0x7f; + printw("%c",isprint(printable) ? printable : ' '); attroff(A_REVERSE); } printw(" XOR value: "); @@ -592,11 +610,11 @@ int main(int argc, char *argv[]) /*{{{*/ printw("Password: "); for (i=0; i<8; ++i) { - char c; + char printable; if (offset==16+(7-i)) attron(A_REVERSE); - c=(buf[entrystart+16+(7-i)]^buf[entrystart+13])&0x7f; - printw("%c",isprint(c) ? c : ' '); + printable=(buf[entrystart+16+(7-i)]^buf[entrystart+13])&0x7f; + printw("%c",isprint(printable) ? printable : ' '); attroff(A_REVERSE); } printw(" XOR value: "); @@ -618,7 +636,7 @@ int main(int argc, char *argv[]) /*{{{*/ { case 'F': /* next entry */ /*{{{*/ { - if (pos+32<(drive.sectrk*drive.tracks*(unsigned long)drive.secLength)) + if (pos+32<(drive.sectrk*drive.tracks*(off_t)drive.secLength)) { if (pos/drive.secLength!=(pos+32)/drive.secLength) reload=1; pos+=32; @@ -654,7 +672,7 @@ int main(int argc, char *argv[]) /*{{{*/ { case 'n': /* next record */ /*{{{*/ { - if (pos+128<(drive.sectrk*drive.tracks*(unsigned long)drive.secLength)) + if (pos+128<(drive.sectrk*drive.tracks*(off_t)drive.secLength)) { if (pos/drive.secLength!=(pos+128)/drive.secLength) reload=1; pos+=128; @@ -684,7 +702,7 @@ int main(int argc, char *argv[]) /*{{{*/ /*}}}*/ case 'P': /* previous track */ /*{{{*/ { - if (pos>drive.sectrk*drive.secLength) + if (pos>=drive.sectrk*drive.secLength) { pos-=drive.sectrk*drive.secLength; reload=1;