#include <assert.h>
#include <ctype.h>
+#if NEED_NCURSES
+#if HAVE_NCURSES_NCURSES_H
+#include <ncurses/ncurses.h>
+#else
+#include <ncurses.h>
+#endif
+#else
#include <curses.h>
+#endif
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <time.h>
#include "cpmfs.h"
+#include "getopt_.h"
+
+#ifdef USE_DMALLOC
+#include <dmalloc.h>
+#endif
/*}}}*/
extern char **environ;
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);
{
const char *msg;
char bmap[18*80];
- int secmap,pos,system,directory;
+ int secmap,sys,directory;
+ int pos;
clear();
msg="Data map";
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)
{
{
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));
}
}
- for (pos=0; pos<sizeof(bmap); ++pos)
+ for (pos=0; pos<(int)sizeof(bmap); ++pos)
{
move(2+pos%18,pos/18);
addch(bmap[pos]);
static void data(struct cpmSuperBlock *sb, const char *buf, unsigned long int pos) /*{{{*/
{
int offset=(pos%sb->secLength)&~0x7f;
- int i;
+ unsigned int i;
for (i=0; i<128; ++i)
{
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;
}
if (optind!=(argc-1)) usage=1;
- else image=argv[optind];
+ else image=argv[optind++];
if (usage)
{
/* 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)
{
/* 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);
{
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;
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: ");
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: ");
{
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;
{
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;
/*}}}*/
case 'P': /* previous track */ /*{{{*/
{
- if (pos>drive.sectrk*drive.secLength)
+ if (pos>=drive.sectrk*drive.secLength)
{
pos-=drive.sectrk*drive.secLength;
reload=1;