しらいです。

 file & directory 管理ツール FDclone 2.08f の patch その 2
です。

Submitted-by: shirai@chandra2
Archive-name: FD-2.08f.patch/part02

---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is `FD-2.08f.shar.02' (part 2 of FD-2.08f.patch).
# Do not concatenate these parts, unpack them in order with `/bin/sh'.
# File `FD-2.08f.patch' is being continued...
#
echo=echo
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  $echo 'WARNING: not restoring timestamps.  Consider getting and'
  $echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
if test ! -r _sh01590/seq; then
  $echo 'Please unpack part 1 first!'
  exit 1
fi
shar_sequence=`cat _sh01590/seq`
if test "$shar_sequence" != 2; then
  $echo 'Please unpack part' "$shar_sequence" 'next!'
  exit 1
fi
if test ! -f _sh01590/new; then
  $echo 'x -' 'STILL SKIPPING' 'FD-2.08f.patch'
else
  $echo 'x -' 'continuing file' 'FD-2.08f.patch'
  sed 's/^X//' << 'SHAR_EOF' >> FD-2.08f.patch &&
X shell.obj: fd.h
-shell.obj: machine.h config.h
-shell.obj: types.h
-shell.obj: printf.h kctype.h
-shell.obj: pathname.h term.h
-shell.obj: func.h
+shell.obj: machine.h config.h types.h
+shell.obj: printf.h
+shell.obj: kctype.h
+shell.obj: pathname.h term.h func.h
X shell.obj: dosdisk.h kanji.h system.h termio.h
X shell.obj: wait.h
X shell.obj: termemu.h
diff -urNP ../FD-2.08e/makefile.lpc ./makefile.lpc
--- ../FD-2.08e/makefile.lpc    Fri Jul 28 00:00:00 2006
+++ ./makefile.lpc      Tue Aug  8 00:00:00 2006
@@ -4,7 +4,7 @@
X 
X TITLE = FD-
X VERMAJ        = 2
-VERSION        = 2.08e
+VERSION        = 2.08f
X PREFIX        = 
X CONFDIR       = 
X BUILD =
@@ -671,11 +671,10 @@
X builtin.obj: wait.h
X builtin.obj: termemu.h
X shell.obj: fd.h
-shell.obj: machine.h config.h
-shell.obj: types.h
-shell.obj: printf.h kctype.h
-shell.obj: pathname.h term.h
-shell.obj: func.h
+shell.obj: machine.h config.h types.h
+shell.obj: printf.h
+shell.obj: kctype.h
+shell.obj: pathname.h term.h func.h
X shell.obj: dosdisk.h kanji.h system.h termio.h
X shell.obj: wait.h
X shell.obj: termemu.h
diff -urNP ../FD-2.08e/mkunitbl.c ./mkunitbl.c
--- ../FD-2.08e/mkunitbl.c      Fri Jul 28 00:00:00 2006
+++ ./mkunitbl.c        Tue Aug  8 00:00:00 2006
@@ -18,6 +18,7 @@
X 
X #define       USERDEFINE
X #define       MAXNFLEN        4
+#define        arraysize(a)    ((int)((u_int)sizeof(a) / (u_int)sizeof(*(a))))
X 
X typedef struct _convtable {
X       u_short unicode;
@@ -9250,7 +9251,7 @@
X       {0xffe4, 0xfa55},
X       {0xffe5, 0x818f},
X };
-#define        UNILISTSIZ      ((int)sizeof(unilist) / sizeof(convtable))
+#define        UNILISTSIZ      arraysize(unilist)
X 
X static nftable macunilist[] = {
X       {0x00c0, {0x0041, 0x0300, 0}},
@@ -10203,7 +10204,7 @@
X       {0xffe1, {0x00a3, 0}},
X       {0xffe2, {0x00ac, 0}},
X };
-#define        MACUNILISTSIZ   ((int)sizeof(macunilist) / sizeof(nftable))
+#define        MACUNILISTSIZ   arraysize(macunilist)
X 
X static int cmpuni(vp1, vp2)
X CONST VOID_P vp1;
@@ -10214,7 +10215,10 @@
X       tp1 = (convtable *)vp1;
X       tp2 = (convtable *)vp2;
X 
-       return(tp1 -> unicode - tp2 -> unicode);
+       if (tp1 -> unicode > tp2 -> unicode) return(1);
+       if (tp1 -> unicode < tp2 -> unicode) return(-1);
+
+       return(0);
X }
X 
X static int cmpnf(vp1, vp2)
@@ -10222,13 +10226,15 @@
X CONST VOID_P vp2;
X {
X       nftable *tp1, *tp2;
-       int i, n;
+       int i;
X 
X       tp1 = (nftable *)vp1;
X       tp2 = (nftable *)vp2;
X       for (i = 0; i < MAXNFLEN; i++) {
-               n = tp1 -> normalization[i] - tp2 -> normalization[i];
-               if (n) return(n);
+               if (tp1 -> normalization[i] > tp2 -> normalization[i])
+                       return(1);
+               if (tp1 -> normalization[i] < tp2 -> normalization[i])
+                       return(-1);
X       }
X 
X       return(0);
diff -urNP ../FD-2.08e/pathname.c ./pathname.c
--- ../FD-2.08e/pathname.c      Fri Jul 28 00:00:00 2006
+++ ./pathname.c        Tue Aug  8 00:00:00 2006
@@ -718,12 +718,13 @@
X char *s1, *s2;
X {
X       for (;;) {
-               if (toupper2(*s1) != toupper2(*s2)) return(*s1 - *s2);
+               if (toupper2(*s1) != toupper2(*s2))
+                       return((u_char)*s1 - (u_char)*s2);
X #ifndef       CODEEUC
X               if (issjis1(*s1)) {
X                       s1++;
X                       s2++;
-                       if (*s1 != *s2) return(*s1 - *s2);
+                       if (*s1 != *s2) return((u_char)*s1 - (u_char)*s2);
X               }
X #endif
X               if (!*s1) break;
@@ -739,13 +740,14 @@
X int n;
X {
X       while (n-- > 0) {
-               if (toupper2(*s1) != toupper2(*s2)) return(*s1 - *s2);
+               if (toupper2(*s1) != toupper2(*s2))
+                       return((u_char)*s1 - (u_char)*s2);
X #ifndef       CODEEUC
X               if (issjis1(*s1)) {
X                       if (n-- <= 0) break;
X                       s1++;
X                       s2++;
-                       if (*s1 != *s2) return(*s1 - *s2);
+                       if (*s1 != *s2) return((u_char)*s1 - (u_char)*s2);
X               }
X #endif
X               if (!*s1) break;
diff -urNP ../FD-2.08e/printf.h ./printf.h
--- ../FD-2.08e/printf.h        Fri Jul 28 00:00:00 2006
+++ ./printf.h  Tue Aug  8 00:00:00 2006
@@ -34,7 +34,7 @@
X #define       VF_UNSIGNED     001000
X 
X #define       strsize(s)      ((int)sizeof(s) - 1)
-#define        arraysize(a)    ((int)sizeof(a) / (int)sizeof(*(a)))
+#define        arraysize(a)    ((int)((u_int)sizeof(a) / (u_int)sizeof(*(a))))
X 
X #define       MAXLONGWIDTH    20              /* log10(2^64) = 19.266 */
X #define       MAXCOLSCOMMA(d) (MAXLONGWIDTH + (MAXLONGWIDTH / (d)))
diff -urNP ../FD-2.08e/shell.c ./shell.c
--- ../FD-2.08e/shell.c Fri Jul 28 00:00:00 2006
+++ ./shell.c   Tue Aug  8 00:00:00 2006
@@ -4,6 +4,7 @@
X  *    shell command module
X  */
X 
+#include <fcntl.h>
X #include "fd.h"
X #include "func.h"
X #include "kanji.h"
@@ -20,6 +21,10 @@
X #include "termemu.h"
X #endif
X 
+#ifndef        O_TEXT
+#define        O_TEXT          0
+#endif
+
X extern int mark;
X extern off_t marksize;
X extern char fullpath[];
@@ -1624,19 +1629,16 @@
X int loadhistory(n)
X int n;
X {
-#ifndef        NOFLOCK
-       int nfs;
-#endif
-       FILE *fp;
+       lockbuf_t *lck;
X       char *line;
X       int i, j, size;
X 
X       if (!histfile || !histfile[0]) return(0);
-       if (!(fp = Xfopen(histfile, "r"))) return(-1);
-#ifndef        NOFLOCK
-       if ((nfs = isnfs(histfile)) <= 0)
-               VOID_C lockfile(Xfileno(fp), LCK_READ);
-#endif
+       lck = lockfopen(histfile, "r", O_TEXT | O_RDONLY);
+       if (!lck || !(lck -> fp)) {
+               lockclose(lck);
+               return(-1);
+       }
X 
X       size = (int)histsize[n];
X       history[n] = (char **)malloc2((size + 1) * sizeof(char *));
@@ -1644,17 +1646,14 @@
X       histno[n] = (short)0;
X 
X       i = -1;
-       while ((line = fgets2(fp, 1))) {
+       while ((line = fgets2(lck -> fp, 1))) {
X               if (histno[n]++ >= MAXHISTNO) histno[n] = (short)0;
X               if (i < size) i++;
X               else free(history[n][i]);
X               for (j = i; j > 0; j--) history[n][j] = history[n][j - 1];
X               history[n][0] = line;
X       }
-#ifndef        NOFLOCK
-       if (nfs <= 0) VOID_C lockfile(Xfileno(fp), LCK_UNLOCK);
-#endif
-       Xfclose(fp);
+       lockclose(lck);
X 
X       for (i++; i <= size; i++) history[n][i] = NULL;
X 
@@ -1681,26 +1680,20 @@
X int savehistory(n)
X int n;
X {
-#ifndef        NOFLOCK
-       int nfs;
-#endif
-       FILE *fp;
+       lockbuf_t *lck;
X       int i, size;
X 
X       if (!histfile || !histfile[0] || savehist <= 0) return(0);
X       if (!history[n] || !history[n][0]) return(-1);
-       if (!(fp = Xfopen(histfile, "w"))) return(-1);
-#ifndef        NOFLOCK
-       if ((nfs = isnfs(histfile)) <= 0)
-               VOID_C lockfile(Xfileno(fp), LCK_WRITE);
-#endif
+       lck = lockfopen(histfile, "w", O_TEXT | O_WRONLY | O_CREAT | O_TRUNC);
+       if (!lck || !(lck -> fp)) {
+               lockclose(lck);
+               return(-1);
+       }
X 
X       size = (savehist > (int)histsize[n]) ? (int)histsize[n] : savehist;
-       for (i = size - 1; i >= 0; i--) convhistory(history[n][i], fp);
-#ifndef        NOFLOCK
-       if (nfs <= 0) VOID_C lockfile(Xfileno(fp), LCK_UNLOCK);
-#endif
-       Xfclose(fp);
+       for (i = size - 1; i >= 0; i--) convhistory(history[n][i], lck -> fp);
+       lockclose(lck);
X 
X       return(0);
X }
diff -urNP ../FD-2.08e/system.c ./system.c
--- ../FD-2.08e/system.c        Fri Jul 28 00:00:00 2006
+++ ./system.c  Tue Aug  8 00:00:00 2006
@@ -26,6 +26,10 @@
X #include "kctype.h"
X #include "pathname.h"
X 
+typedef struct _lockbuf_t {
+       int fd;
+} lockbuf_t;
+
X #ifdef        PATHNOCASE
X #define       TMPPREFIX       "TM"
X #else
@@ -405,6 +409,8 @@
X #endif        /* !MINIMUMSHELL */
X 
X #ifdef        FD
+extern lockbuf_t *lockopen __P_((char *, int, int));
+extern VOID lockclose __P_((lockbuf_t *));
X extern int mktmpfile __P_((char *));
X extern int rmtmpfile __P_((char *));
X # if  MSDOS
@@ -426,6 +432,8 @@
X # if  !MSDOS || !defined (MINIMUMSHELL)
X time_t time2 __P_((VOID_A));
X # endif
+static lockbuf_t *NEAR lockopen __P_((char *, int, int));
+static VOID NEAR lockclose __P_((lockbuf_t *));
X static int NEAR genrand __P_((int));
X static char *NEAR genrandname __P_((char *, int));
X static int NEAR mktmpfile __P_((char *));
@@ -1577,6 +1585,30 @@
X 
X 
X #ifndef       FD
+static lockbuf_t *NEAR lockopen(path, flags, mode)
+char *path;
+int flags, mode;
+{
+       lockbuf_t *lck;
+       int fd;
+
+       if ((fd = newdup(Xopen(path, flags, mode))) >= 0) /*EMPTY*/;
+       else if (errno != ENOENT) return(NULL);
+       lck = (lockbuf_t *)malloc2(sizeof(lockbuf_t));
+       lck -> fd = fd;
+
+       return(lck);
+}
+
+static VOID NEAR lockclose(lck)
+lockbuf_t *lck;
+{
+       if (lck) {
+               if (lck -> fd >= 0) VOID_C Xclose(lck -> fd);
+               free(lck);
+       }
+}
+
X # if  MSDOS && defined (MINIMUMSHELL)
X static int NEAR genrand(max)
X int max;
@@ -1867,7 +1899,7 @@
X 
X       if ((fd = Xdup(STDERR_FILENO)) < 0) fp = stderr;
X       else if (!(fp = Xfdopen(fd, "a"))) {
-               Xclose(fd);
+               VOID_C Xclose(fd);
X               fp = stderr;
X       }
X # if  !MSDOS
@@ -6289,13 +6321,14 @@
X                       ret = RET_FAIL;
X               }
X       }
-       else if ((fd = newdup(Kopen(path, O_BINARY | O_RDONLY, 0666))) < 0) {
+       else if ((fd = newdup(Kopen(path, O_TEXT | O_RDONLY, 0666))) < 0) {
X               doperror(NULL, argv[0]);
X               ret = RET_NOTEXEC;
X       }
X       else {
X               argvar = argv;
X               sourcefile(fd, argv[0], 0);
+               safeclose(fd);
X               ret = ret_status;
X       }
X #ifdef        DEBUG
@@ -8376,7 +8409,7 @@
X #endif
X               return(RET_FAIL);
X       }
-       if ((fd = newdup(Kopen(fname, O_BINARY | O_RDONLY, 0666))) < 0) {
+       if ((fd = newdup(Kopen(fname, O_TEXT | O_RDONLY, 0666))) < 0) {
X               doperror((trp -> comm) -> argv[0], fname);
X               return(RET_FAIL);
X       }
@@ -8394,6 +8427,7 @@
X               argvar[n] = NULL;
X               var = argvar;
X               sourcefile(fd, fname, 0);
+               safeclose(fd);
X               if (var != argvar) freevar(dupargvar);
X               else {
X                       freevar(argvar);
@@ -8402,7 +8436,10 @@
X       }
X       else
X #endif        /* BASHSTYLE */
-       sourcefile(fd, fname, 0);
+       {
+               sourcefile(fd, fname, 0);
+               safeclose(fd);
+       }
X 
X       return(ret_status);
X }
@@ -10536,7 +10573,6 @@
X               setshlineno(shlineno + 1L);
X #endif
X       }
-       safeclose(fd);
X 
X       if (!ret && errno) {
X               doperror(NULL, fname);
@@ -10561,8 +10597,9 @@
X #ifdef        MINIMUMSHELL
X       char *cp, path[MAXPATHLEN];
X #endif
+       lockbuf_t *lck;
X       char **dupargvar;
-       int fd, ret, duprestricted;
+       int ret, duprestricted;
X 
X       setsignal();
X #ifdef        MINIMUMSHELL
@@ -10576,10 +10613,13 @@
X       fname = adjustpname(fname);
X #endif
X       fname = evalpath(fname, 0);
-       if (noruncom || !isrootdir(fname)
-       || (fd = newdup(Xopen(fname, O_BINARY | O_RDONLY, 0666))) < 0)
-               ret = RET_SUCCESS;
-       else {
+       ret = RET_SUCCESS;
+       if (noruncom || !isrootdir(fname)) lck = NULL;
+       else if (!(lck = lockopen(fname, O_TEXT | O_RDONLY, 0666))) {
+               doperror(NULL, fname);
+               ret = RET_FAIL;
+       }
+       else if (lck -> fd >= 0) {
X #ifdef        FD
X               inruncom = 1;
X #endif
@@ -10589,7 +10629,7 @@
X               argvar = (char **)malloc2(2 * sizeof(char *));
X               argvar[0] = strdup2(fname);
X               argvar[1] = NULL;
-               ret = sourcefile(fd, fname, verbose);
+               ret = sourcefile(lck -> fd, fname, verbose);
X               freevar(argvar);
X               argvar = dupargvar;
X               restricted = duprestricted;
@@ -10597,6 +10637,7 @@
X               inruncom = 0;
X #endif
X       }
+       lockclose(lck);
X       resetsignal(0);
X       free(fname);
X 
diff -urNP ../FD-2.08e/term.c ./term.c
--- ../FD-2.08e/term.c  Fri Jul 28 00:00:00 2006
+++ ./term.c    Tue Aug  8 00:00:00 2006
@@ -1362,42 +1362,42 @@
X       tflush();
X # endif
X 
-       i = 0;
-       buf[i] = '\0';
+       buf[0] = '\0';
X       do {
-               if (!kbhit2(WAITKEYPAD * 1000L * 2)) break;
+               if (!kbhit2(1000000L * 5)) break;
X # if  MSDOS
-               buf[i] = bdos(0x07, 0x00, 0);
+               buf[0] = bdos(0x07, 0x00, 0);
X # else
X               if ((tmp = getch2()) == EOF) break;
-               buf[i] = tmp;
+               buf[0] = tmp;
X # endif
-       } while (buf[i] != format[0]);
+       } while (buf[0] != format[0]);
X 
-       if (buf[i] == format[0]) while (i < strsize(buf) - 1) {
+       i = 0;
+       if (buf[0] == format[0]) for (i++; i < strsize(buf); i++) {
X               if (!kbhit2(WAITKEYPAD * 1000L)) break;
X # if  MSDOS
-               buf[++i] = bdos(0x07, 0x00, 0);
+               buf[i] = bdos(0x07, 0x00, 0);
X # else
X               if ((tmp = getch2()) == EOF) break;
-               buf[++i] = tmp;
+               buf[i] = tmp;
X # endif
X               if (buf[i] == format[strsize(SIZEFMT) - 1]) break;
X       }
X       keyflush();
X       while (kbhit2(WAITKEYPAD * 1000L)) VOID_C getch2();
-       if (!i || buf[i] != format[strsize(SIZEFMT) - 1]) return(-1);
-       buf[++i] = '\0';
+       if (!i || buf[i++] != format[strsize(SIZEFMT) - 1]) return(-1);
+       buf[i] = '\0';
X 
X       count = 0;
X       val[0] = yp;
X       val[1] = xp;
X 
X       for (i = j = 0; format[i] && buf[j]; i++) {
-               if (format[i] == '%' && format[++i] == 'd' && count < 2) {
-                       tmp = getnum(buf, &j);
-                       if (tmp < 0 || buf[j] != format[i + 1]) break;
-                       *val[count++] = tmp;
+               if (format[i] == '%' && format[i + 1] == 'd') {
+                       if ((tmp = getnum(buf, &j)) < 0) break;
+                       i++;
+                       if (count++ < 2) *(val[count - 1]) = tmp;
X               }
X               else if (format[i] != buf[j++]) break;
X       }
diff -urNP ../FD-2.08e/termio.c ./termio.c
--- ../FD-2.08e/termio.c        Fri Jul 28 00:00:00 2006
+++ ./termio.c  Tue Aug  8 00:00:00 2006
@@ -363,7 +363,7 @@
X #endif
X 
X       if (*fdp >= 0) fd = *fdp;
-       else if ((fd = newdup(open(_PATH_TTY, flags, 0600))) < 0) return(-1);
+       else if ((fd = newdup(open(_PATH_TTY, flags, 0666))) < 0) return(-1);
X       if (*fpp) fp = *fpp;
X       else if (!(fp = fdopen(fd, "w+b")) && !(fp = fopen(_PATH_TTY, "w+b")))
X               return(-1);
diff -urNP ../FD-2.08e/types.h ./types.h
--- ../FD-2.08e/types.h Fri Jul 28 00:00:00 2006
+++ ./types.h   Tue Aug  8 00:00:00 2006
@@ -146,6 +146,17 @@
X       char *str;
X } strtable;
X 
+typedef struct _lockbuf_t {
+       int fd;
+       FILE *fp;
+       char *name;
+       u_char flags;
+} lockbuf_t;
+
+#define        LCK_FLOCK               0001
+#define        LCK_INVALID             0002
+#define        LCK_STREAM              0004
+
X typedef struct _bindtable {
X       short key;
X       u_char f_func;
diff -urNP ../FD-2.08e/unixemu.c ./unixemu.c
--- ../FD-2.08e/unixemu.c       Fri Jul 28 00:00:00 2006
+++ ./unixemu.c Tue Aug  8 00:00:00 2006
@@ -250,6 +250,7 @@
X                       else dd = lastdrv;
X               }
X               lastdrv = dd;
+               n = 0;
X       }
X #endif        /* !_NODOSDRIVE */
X       LOG1(_LOG_INFO_, n, "chdir(\"%k\");", path);
@@ -587,6 +588,18 @@
X       else ofs = lseek(fd, offset, whence);
X 
X       return(ofs);
+}
+
+int Xftruncate(fd, len)
+int fd;
+off_t len;
+{
+       int n;
+
+       if (fd >= DOSFDOFFSET) n = dosftruncate(fd, len);
+       else n = ftruncate(fd, len);
+
+       return(n);
X }
X 
X int Xdup(oldd)
diff -urNP ../FD-2.08e/version.h ./version.h
--- ../FD-2.08e/version.h       Fri Jul 28 00:00:00 2006
+++ ./version.h Tue Aug  8 00:00:00 2006
@@ -5,4 +5,4 @@
X  */
X 
X char *distributor = NULL;
-static char version[] = "@(#)fd.c  2.08e 07/28/06";
+static char version[] = "@(#)fd.c  2.08f 08/08/06";
SHAR_EOF
  $echo 'File' 'FD-2.08f.patch' 'is complete' &&
  $shar_touch -am 08072346106 'FD-2.08f.patch' &&
  chmod 0644 'FD-2.08f.patch' ||
  $echo 'restore of' 'FD-2.08f.patch' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'FD-2.08f.patch:' 'MD5 check failed'
6f1a7cbde3c8da5195446cd1484870c0  FD-2.08f.patch
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'FD-2.08f.patch'`"
    test 61441 -eq "$shar_count" ||
    $echo 'FD-2.08f.patch:' 'original size' '61441,' 'current size' "$shar_count!"
  fi
fi
$echo 'You have unpacked the last part'
rm -fr _sh01590
exit 0
-- 
                                               しらい たかし