New upstream version 2.20
[debian/cpmtools] / fsed.cpm.c
index 0c3f03f8ea5a3e418ff195e40d047be0c8a13cfb..f120b77c4a364749a3cdc119469acd710576a24b 100644 (file)
@@ -3,13 +3,23 @@
 
 #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>
@@ -25,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);
@@ -87,7 +97,8 @@ static void map(struct cpmSuperBlock *sb) /*{{{*/
 {
   const char *msg;
   char bmap[18*80];
-  int secmap,pos,sys,directory;
+  int secmap,sys,directory;
+  int pos;
 
   clear();
   msg="Data map";
@@ -114,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));
@@ -129,7 +140,7 @@ static void map(struct cpmSuperBlock *sb) /*{{{*/
     }
   }
 
-  for (pos=0; pos<sizeof(bmap); ++pos)
+  for (pos=0; pos<(int)sizeof(bmap); ++pos)
   {
     move(2+pos%18,pos/18);
     addch(bmap[pos]);
@@ -143,7 +154,7 @@ static void map(struct cpmSuperBlock *sb) /*{{{*/
 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)
   {
@@ -168,7 +179,7 @@ int main(int argc, char *argv[]) /*{{{*/
   struct cpmInode root;
   const char *format;
   int c,usage=0;
-  unsigned long pos;
+  off_t pos;
   chtype ch;
   int reload;
   char *buf;
@@ -196,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)
@@ -270,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;
@@ -621,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;
@@ -657,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;