home *** CD-ROM | disk | FTP | other *** search
/ Mega CD-ROM 1 / megacd_rom_1.zip / megacd_rom_1 / GNUISH / FUTIL14.ZIP / PATCHES < prev    next >
Text File  |  1990-09-24  |  118KB  |  4,473 lines

  1. *** e:\tmp/RCSt1006574    Wed Sep 19 13:27:44 1990
  2. --- argmatch.c    Wed Sep 19 12:36:14 1990
  3. ***************
  4. *** 17,26 ****
  5. --- 17,43 ----
  6.   
  7.   /* Written by David MacKenzie <djm@ai.mit.edu> */
  8.   
  9. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  10. +    This port is also distributed under the terms of the
  11. +    GNU General Public License as published by the
  12. +    Free Software Foundation.
  13. +    Please note that this file is not identical to the
  14. +    original GNU release, you should have received this
  15. +    code as patch to the official release.
  16. +    $Header: e:/gnu/fileutil/RCS/argmatch.c 1.4.0.2 90/09/19 12:27:25 tho Exp $
  17. +  */
  18.   #include <stdio.h>
  19.   #ifdef STDC_HEADERS
  20.   #include <string.h>
  21.   #endif
  22. + #ifdef MSDOS
  23. + int argmatch (char *arg, char **optlist);
  24. + void invalid_arg (char *kind, char *value, int problem);
  25. + #endif /* MSDOS */
  26.   
  27.   extern char *program_name;
  28.   
  29. *** e:\tmp/RCSt1006574    Wed Sep 19 13:27:46 1990
  30. --- backupfi.c    Wed Sep 19 12:36:34 1990
  31. ***************
  32. *** 17,23 ****
  33. --- 17,36 ----
  34.   
  35.   /* David MacKenzie <djm@ai.mit.edu>.
  36.      Some algorithms adapted from GNU Emacs. */
  37. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  38. +    This port is also distributed under the terms of the
  39. +    GNU General Public License as published by the
  40. +    Free Software Foundation.
  41.   
  42. +    Please note that this file is not identical to the
  43. +    original GNU release, you should have received this
  44. +    code as patch to the official release.  */
  45. + #ifdef MSDOS
  46. + static char RCS_Id[] =
  47. +   "$Header: e:/gnu/fileutil/RCS/backupfi.c 1.4.0.2 90/09/19 12:27:27 tho Exp $";
  48. + #endif /* MSDOS */
  49.   #include <stdio.h>
  50.   #include <ctype.h>
  51.   #include <sys/types.h>
  52. ***************
  53. *** 59,64 ****
  54. --- 72,89 ----
  55.   char *malloc ();
  56.   #endif
  57.   
  58. + #ifdef MSDOS
  59. + extern char *find_backup_file_name (char *file);
  60. + static int max_backup_version (char *file, char *dir);
  61. + static char *make_version_name (char *file, int version);
  62. + static int version_number (char *base, char *backup, int base_length);
  63. + static char *dirname (char *path);
  64. + static char *basename (char *name);
  65. + static char *concat (char *str1, char *str2);
  66. + static char *copystring (char *str);
  67. + static char *chop_filename (char *path, int n);
  68. + #endif /* MSDOS */
  69.   /* Which type of backup file names are generated. */
  70.   enum backup_type backup_type = none;
  71.   
  72. ***************
  73. *** 131,137 ****
  74. --- 156,166 ----
  75.   
  76.     while ((dp = readdir (dirp)) != 0)
  77.       {
  78. + #ifdef MSDOS
  79. +       if (NLENGTH (dp) <= file_name_length)
  80. + #else /* not MSDOS */
  81.         if (dp->d_ino == 0 || NLENGTH (dp) <= file_name_length)
  82. + #endif /* not MSDOS */
  83.       continue;
  84.         
  85.         this_version = version_number (file, dp->d_name, file_name_length);
  86. ***************
  87. *** 142,147 ****
  88. --- 171,180 ----
  89.     return highest_version;
  90.   }
  91.   
  92. + #ifdef MSDOS
  93. + static char suffix[5];
  94. + #endif /* not MSDOS */
  95.   /* Return a string, allocated with malloc, containing
  96.      "FILE.~VERSION~".  Return 0 if out of memory. */
  97.   
  98. ***************
  99. *** 150,155 ****
  100. --- 183,192 ----
  101.        char *file;
  102.        int version;
  103.   {
  104. + #ifdef MSDOS
  105. +   sprintf (suffix, ".~%.1d~", version);
  106. +   return concat (file, suffix);
  107. + #else /* not MSDOS */
  108.     char *backup_name;
  109.   
  110.     backup_name = malloc (strlen (file) + 16);
  111. ***************
  112. *** 157,162 ****
  113. --- 194,200 ----
  114.       return 0;
  115.     sprintf (backup_name, "%s.~%d~", file, version);
  116.     return backup_name;
  117. + #endif /* not MSDOS */
  118.   }
  119.   
  120.   /* If BACKUP is a numbered backup of BASE, return its version number;
  121. ***************
  122. *** 171,183 ****
  123.   {
  124.     int version;
  125.     char *p;
  126. !   
  127.     version = 0;
  128.     if (!strncmp (base, backup, base_length) && ISDIGIT (backup[base_length]))
  129.       {
  130.         for (p = &backup[base_length]; ISDIGIT (*p); ++p)
  131.       version = version * 10 + *p - '0';
  132.         if (p[0] != '~' || p[1])
  133.       version = 0;
  134.       }
  135.     return version;
  136. --- 209,225 ----
  137.   {
  138.     int version;
  139.     char *p;
  140.     version = 0;
  141.     if (!strncmp (base, backup, base_length) && ISDIGIT (backup[base_length]))
  142.       {
  143.         for (p = &backup[base_length]; ISDIGIT (*p); ++p)
  144.       version = version * 10 + *p - '0';
  145. + #ifdef MSDOS
  146. +       if (*p && *p != '~')
  147. + #else /* not MSDOS */
  148.         if (p[0] != '~' || p[1])
  149. + #endif /* not MSDOS */
  150.       version = 0;
  151.       }
  152.     return version;
  153. ***************
  154. *** 231,241 ****
  155. --- 273,300 ----
  156.     char *newstr;
  157.     char str1_length = strlen (str1);
  158.   
  159. + #ifdef MSDOS
  160. +   /* The MS-DOS version tries to squeeze the given string into a valid
  161. +      MS-DOS patch name.  STR1 is chopped and a leading period is removed
  162. +      from STR2.  Kludge: a leading period is counted in the length of STR2,
  163. +      this is because we will know, that in this case a digit will be appended
  164. +      afterwards.  */
  165. +   /* chop_filename () might add a '.', so allocate one more byte.  */
  166. +   newstr = malloc (str1_length + strlen (str2) + 2);
  167. +   if (newstr == 0)
  168. +     return 0;
  169. +   strcpy (newstr, str1);
  170. +   chop_filename (newstr, min (2, strlen(str2)));
  171. +   if (*str2 == '.')
  172. +     str2++;
  173. +   strcat (newstr, str2);
  174. + #else /* not MSDOS */
  175.     newstr = malloc (str1_length + strlen (str2) + 1);
  176.     if (newstr == 0)
  177.       return 0;
  178.     strcpy (newstr, str1);
  179.     strcpy (newstr + str1_length, str2);
  180. + #endif /* not MSDOS */
  181.     return newstr;
  182.   }
  183.   
  184. ***************
  185. *** 253,255 ****
  186. --- 312,343 ----
  187.     strcpy (newstr, str);
  188.     return newstr;
  189.   }
  190. + #ifdef MSDOS
  191. + /* Shorten a MS-DOS path to accomodate a backup suffix.  */
  192. + char *
  193. + chop_filename (char *path, int n)
  194. + {
  195. +   char *base;
  196. +   char *suffix;
  197. +   base = strrchr (path, '/');
  198. +   if (base == (char *)0)
  199. +     base = path;
  200. +   else
  201. +     base++;
  202. +   suffix = strchr (base, '.');
  203. +   if (suffix == (char *)0)
  204. +     strcat (base, ".");        /* is ok, since we have allocated enough! */
  205. +   else if (strlen (suffix) >= 4 - n)
  206. +     suffix[4-n] = '\0';
  207. +   return path;
  208. + }
  209. + #endif /* MSDOS */
  210. *** e:\tmp/RCSt1006574    Wed Sep 19 13:27:50 1990
  211. --- cat.c    Wed Sep 19 12:31:34 1990
  212. ***************
  213. *** 14,19 ****
  214. --- 14,44 ----
  215.      You should have received a copy of the GNU General Public License
  216.      along with this program; if not, write to the Free Software
  217.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  218. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  219. +    This port is also distributed under the terms of the
  220. +    GNU General Public License as published by the
  221. +    Free Software Foundation.
  222. +    Please note that this file is not identical to the
  223. +    original GNU release, you should have received this
  224. +    code as patch to the official release.  */
  225. + #ifdef MSDOS
  226. + static char RCS_Id[] =
  227. +   "$Header: e:/gnu/fileutil/RCS/cat.c 1.4.0.2 90/09/19 11:17:40 tho Exp $";
  228. + static char Program_Id[] = "cat";
  229. + static char RCS_Revision[] = "$Revision: 1.4.0.2 $";
  230. + #define VERSION \
  231. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  232. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  233. + #define COPYING \
  234. +   "This is free software, distributed under the terms of the\n" \
  235. +   "GNU General Public License.  For details, see the file COPYING.\n"
  236. + #endif /* MSDOS */
  237.   
  238.   /* Differences from the Unix cat:
  239.      * Always unbuffered, -u is ignored.
  240. ***************
  241. *** 27,34 ****
  242. --- 52,61 ----
  243.   #include <errno.h>
  244.   #include <sys/types.h>
  245.   #ifndef _POSIX_SOURCE
  246. + #ifndef MSDOS
  247.   #include <sys/ioctl.h>
  248.   #endif
  249. + #endif
  250.   #include "system.h"
  251.   
  252.   #ifdef STDC_HEADERS
  253. ***************
  254. *** 40,49 ****
  255.   extern int errno;
  256.   #endif
  257.   
  258. ! #define max(h,i) ((h) > (i) ? (h) : (i))
  259.   
  260. ! typedef unsigned char uchar;
  261.   
  262.   char *copystring ();
  263.   void cat ();
  264.   void error ();
  265. --- 67,92 ----
  266.   extern int errno;
  267.   #endif
  268.   
  269. ! #ifdef MSDOS
  270.   
  271. ! #include <string.h>
  272. ! #include <fcntl.h>
  273. ! #include <malloc.h>
  274. ! #include <io.h>
  275. ! extern void main (int, char **);
  276. ! extern void error (int status, int errnum, char *message, ...);
  277. ! extern void usage (char *);
  278. ! extern void simple_cat (unsigned char *, int);
  279. ! extern void cat (unsigned char *, int, unsigned char *,\
  280. !          int, int, int, int, int, int, int);
  281. ! extern void next_line_num (void);
  282. ! extern char *copystring (char *, char *);
  283. ! #else /* not MSDOS */
  284.   
  285. + #define max(h,i) ((h) > (i) ? (h) : (i))
  286.   char *copystring ();
  287.   void cat ();
  288.   void error ();
  289. ***************
  290. *** 50,55 ****
  291. --- 93,102 ----
  292.   void next_line_num ();
  293.   void simple_cat ();
  294.   
  295. + #endif /* not MSDOS */
  296. + typedef unsigned char uchar;
  297.   /* Name under which this program was invoked.  */
  298.   char *program_name;
  299.   
  300. ***************
  301. *** 89,98 ****
  302. --- 136,152 ----
  303.     if (reason != NULL)
  304.       fprintf (stderr, "%s: %s\n", program_name, reason);
  305.   
  306. + #ifdef MSDOS
  307. +   fprintf (stderr, "\
  308. + Usage: %s [-benstuvABET] [+number] [+number-nonblank] [+squeeze-blank]\n\
  309. +        [+show-nonprinting] [+show-ends] [+show-tabs] [+show-all] [+binary]\n\
  310. +        [+copying] [+version] [file...]\n", program_name);
  311. + #else /* not MSDOS */
  312.     fprintf (stderr, "\
  313.   Usage: %s [-benstuvAET] [+number] [+number-nonblank] [+squeeze-blank]\n\
  314.          [+show-nonprinting] [+show-ends] [+show-tabs] [+show-all] [file...]\n",
  315.          program_name);
  316. + #endif /* not MSDOS */
  317.   
  318.     exit (2);
  319.   }
  320. ***************
  321. *** 140,148 ****
  322. --- 194,210 ----
  323.     int output_tabs = 1;
  324.     int options = 0;
  325.     int longind;
  326. + #ifdef MSDOS
  327. +   int binary = 0;
  328. + #endif
  329.   
  330.     static struct option long_options[] =
  331.     {
  332. + #ifdef MSDOS
  333. +     {"binary", 0, NULL, 'B'},
  334. +     {"copying", 0, NULL, 30},
  335. +     {"version", 0, NULL, 31},
  336. + #endif
  337.       {"number-nonblank", 0, NULL, 'b'},
  338.       {"number", 0, NULL, 'n'},
  339.       {"squeeze-blank", 0, NULL, 's'},
  340. ***************
  341. *** 157,163 ****
  342. --- 219,229 ----
  343.   
  344.     /* Parse command line options.  */
  345.   
  346. + #ifdef MSDOS
  347. +   while ((c = getopt_long (argc, argv, "benstuvABET", long_options, &longind))
  348. + #else
  349.     while ((c = getopt_long (argc, argv, "benstuvAET", long_options, &longind))
  350. + #endif
  351.        != EOF)
  352.       {
  353.         options++;
  354. ***************
  355. *** 201,206 ****
  356. --- 267,289 ----
  357.         output_tabs = 0;
  358.         break;
  359.   
  360. + #ifdef MSDOS
  361. +     case 'B':
  362. +       binary++;
  363. +       options--;    /* stdout will be binary iff no other option!  */
  364. +       break;
  365. +     case 30:
  366. +       fprintf (stderr, COPYING);
  367. +       exit (0);
  368. +       break;
  369. +     case 31:
  370. +       fprintf (stderr, VERSION);
  371. +       exit (0);
  372. +       break;
  373. + #endif
  374.       case 'E':
  375.         mark_line_ends = 1;
  376.         break;
  377. ***************
  378. *** 263,268 ****
  379. --- 346,363 ----
  380.           }
  381.       }
  382.   
  383. + #ifdef MSDOS
  384. +       if (binary)
  385. +     {
  386. +       setmode (input_desc, O_BINARY);
  387. +       /* We will not set the output to binary mode if we have
  388. +          another (verbose) option active.  */
  389. +       if (options == 0)
  390. +         setmode (output_desc, O_BINARY);
  391. +     }
  392. + #endif
  393.         if (fstat (input_desc, &stat_buf) < 0)
  394.       {
  395.         error (0, errno, "%s", infile);
  396. ***************
  397. *** 299,304 ****
  398. --- 394,402 ----
  399.       }
  400.         else
  401.       {
  402. + #ifdef MSDOS            /* the user wants it slow, he can get it! */
  403. +       insize = outsize = 0x1000;
  404. + #endif
  405.         inbuf = (uchar *) malloc (insize + 1);
  406.         if (inbuf == NULL)
  407.           error (1, 0, "virtual memory exhausted");
  408. *** e:\tmp/RCSt1006574    Wed Sep 19 13:27:52 1990
  409. --- chmod.c    Wed Sep 19 12:32:40 1990
  410. ***************
  411. *** 15,20 ****
  412. --- 15,45 ----
  413.      along with this program; if not, write to the Free Software
  414.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  415.   
  416. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  417. +    This port is also distributed under the terms of the
  418. +    GNU General Public License as published by the
  419. +    Free Software Foundation.
  420. +    Please note that this file is not identical to the
  421. +    original GNU release, you should have received this
  422. +    code as patch to the official release.  */
  423. + #ifdef MSDOS
  424. + static char RCS_Id[] =
  425. +   "$Header: e:/gnu/fileutil/RCS/chmod.c 1.4.0.2 90/09/19 11:17:44 tho Exp $";
  426. + static char Program_Id[] = "chmod";
  427. + static char RCS_Revision[] = "$Revision: 1.4.0.2 $";
  428. + #define VERSION \
  429. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  430. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  431. + #define COPYING \
  432. +   "This is free software, distributed under the terms of the\n" \
  433. +   "GNU General Public License.  For details, see the file COPYING.\n"
  434. + #endif /* MSDOS */
  435.   /* Usage: chmod [-Rcdfv] mode file...
  436.             mode is [ugoa...][[+-=][rwxXstugo...]...][,...] or octal number.
  437.   
  438. ***************
  439. *** 44,49 ****
  440. --- 69,99 ----
  441.   extern int errno;
  442.   #endif
  443.   
  444. + #ifdef MSDOS
  445. + #include <malloc.h>
  446. + #include <io.h>
  447. + #define lstat stat
  448. + extern void main (int argc, char **argv);
  449. + extern void filemodestring (struct stat *,char *);
  450. + extern void error (int status, int errnum, char *message, ...);
  451. + extern void mode_string (unsigned short mode, char *str);
  452. + static int change_file_mode (char *file, struct mode_change *changes);
  453. + static int change_dir_mode (char *dir, struct mode_change *changes,\
  454. +                 struct stat *statp);
  455. + extern char *savedir (char *dir, unsigned name_size);
  456. + static char *stpcpy (char *dest, char *source);
  457. + static void describe_change (char *file, unsigned short mode, int changed);
  458. + static char *xmalloc (unsigned int n);
  459. + static char *xrealloc (char *p, unsigned n);
  460. + static char *stp_cpy (char *dest, char *source);
  461. + static void usage (void);
  462. + #else /* not MSDOS */
  463.   int lstat ();
  464.   int stat ();
  465.   
  466. ***************
  467. *** 57,62 ****
  468. --- 107,114 ----
  469.   void mode_string ();
  470.   void usage ();
  471.   
  472. + #endif /* not MSDOS */
  473.   typedef enum
  474.   {
  475.     false = 0, true = 1
  476. ***************
  477. *** 78,84 ****
  478. --- 130,140 ----
  479.   boolean changes_only;
  480.   
  481.   /* A pointer to either lstat or stat. */
  482. + #ifdef MSDOS
  483. + int (*xstat) (char *, struct stat *);
  484. + #else
  485.   int (*xstat) ();
  486. + #endif
  487.   
  488.   /* Parse the ASCII mode given on the command line into a linked list
  489.      of `struce mode_change' and apply that to each file argument. */
  490. ***************
  491. *** 103,109 ****
  492. --- 159,169 ----
  493.       {
  494.         thisind = optind ? optind : 1;
  495.   
  496. + #ifdef MSDOS
  497. +       c = getopt (argc, argv, "RcdfvrwxXstugoa,+-=CV");
  498. + #else
  499.         c = getopt (argc, argv, "RcdfvrwxXstugoa,+-=");
  500. + #endif
  501.         if (c == EOF)
  502.       break;
  503.   
  504. ***************
  505. *** 143,148 ****
  506. --- 203,218 ----
  507.       case 'v':
  508.         verbose = true;
  509.         break;
  510. + #ifdef MSDOS
  511. +     case 'C':
  512. +       fprintf (stderr, COPYING);
  513. +       exit (0);
  514. +       break;
  515. +     case 'V':
  516. +       fprintf (stderr, VERSION);
  517. +       exit (0);
  518. +       break;
  519. + #endif
  520.       default:
  521.         usage ();
  522.       }
  523. ***************
  524. *** 314,322 ****
  525. --- 384,399 ----
  526.   void
  527.   usage ()
  528.   {
  529. + #ifdef MSDOS
  530. +   fprintf (stderr, "\
  531. + Usage: %s [-RcdfvCV] mode file...\n\
  532. +        mode is [ugoa...][[+-=][rwxXstugo...]...][,...] or octal number\n",
  533. +        program_name);
  534. + #else /* not MSDOS */
  535.     fprintf (stderr, "\
  536.   Usage: %s [-Rcdfv] mode file...\n\
  537.          mode is [ugoa...][[+-=][rwxXstugo...]...][,...] or octal number\n",
  538.          program_name);
  539. + #endif /* not MSDOS */
  540.     exit (1);
  541.   }
  542. *** e:\tmp/RCSt1006574    Wed Sep 19 13:27:54 1990
  543. --- cmp.c    Wed Sep 19 12:34:26 1990
  544. ***************
  545. *** 14,19 ****
  546. --- 14,44 ----
  547.      You should have received a copy of the GNU General Public License
  548.      along with this program; if not, write to the Free Software
  549.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  550. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  551. +    This port is also distributed under the terms of the
  552. +    GNU General Public License as published by the
  553. +    Free Software Foundation.
  554. +    Please note that this file is not identical to the
  555. +    original GNU release, you should have received this
  556. +    code as patch to the official release.  */
  557. + #ifdef MSDOS
  558. + static char RCS_Id[] =
  559. +   "$Header: e:/gnu/fileutil/RCS/cmp.c 1.4.0.2 90/09/19 11:17:46 tho Exp $";
  560. + static char Program_Id[] = "cmp";
  561. + static char RCS_Revision[] = "$Revision: 1.4.0.2 $";
  562. + #define VERSION \
  563. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  564. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  565. + #define COPYING \
  566. +   "This is free software, distributed under the terms of the\n" \
  567. +   "GNU General Public License.  For details, see the file COPYING.\n"
  568. + #endif /* MSDOS */
  569.   
  570.   /* Differences from the Unix cmp:
  571.      * 6 - 40 - oo times faster.
  572. ***************
  573. *** 38,43 ****
  574. --- 63,82 ----
  575.   extern int errno;
  576.   #endif
  577.   
  578. + #ifdef MSDOS
  579. + #include <io.h>
  580. + #include <gnulib.h>
  581. + extern void main (int, char **);
  582. + extern void usage (char *);
  583. + extern void cmp (void);
  584. + extern int bcmp2 (char *, char *);
  585. + extern int bcmp_cnt (int *count, char *p1, char *p2, unsigned char c);
  586. + extern int bread (int, char *, int);
  587. + extern void printc (FILE *fs, int width, unsigned int c);
  588. + #else /* not MSDOS */
  589.   #define max(h, i)    ((h) > (i) ? (h) : (i))
  590.   #define min(l, o)    ((l) < (o) ? (l) : (o))
  591.   
  592. ***************
  593. *** 48,53 ****
  594. --- 87,94 ----
  595.   void printc ();
  596.   void error ();
  597.   
  598. + #endif /* not MSDOS */
  599.   /* Name under which this program was invoked.  */
  600.   
  601.   char *program_name;
  602. ***************
  603. *** 83,88 ****
  604. --- 124,133 ----
  605.   
  606.   struct option long_options[] =
  607.   {
  608. + #ifdef MSDOS
  609. +   {"copying", 0, NULL, 30},
  610. +   {"version", 0, NULL, 31},
  611. + #endif
  612.     {"show-chars", 0, &flag_print_chars, 1},
  613.     {"silent", 0, &flag, 's'},
  614.     {"quiet", 0, &flag, 's'},
  615. ***************
  616. *** 97,105 ****
  617. --- 142,157 ----
  618.     if (reason != NULL)
  619.       fprintf (stderr, "%s: %s\n", program_name, reason);
  620.   
  621. + #ifdef MSDOS
  622. +   fprintf (stderr, "\
  623. + Usage: %s [-cls] [+show-chars] [+verbose] [+silent] [+quiet]\n\
  624. +            [+copying] [+version] file1 [file2]\n",
  625. +        program_name);
  626. + #else /* not MSDOS */
  627.     fprintf (stderr, "\
  628.   Usage: %s [-cls] [+show-chars] [+verbose] [+silent] [+quiet] file1 [file2]\n",
  629.          program_name);
  630. + #endif /* not MSDOS */
  631.   
  632.     exit (2);
  633.   }
  634. ***************
  635. *** 139,144 ****
  636. --- 191,208 ----
  637.       flag = c;
  638.       break;
  639.   
  640. + #ifdef MSDOS
  641. +       case 30:
  642. +     fprintf (stderr, COPYING);
  643. +     exit (0);
  644. +     break;
  645. +       case 31:
  646. +     fprintf (stderr, VERSION);
  647. +     exit (0);
  648. +     break;
  649. + #endif
  650.         default:
  651.       usage ((char *) 0);
  652.         }
  653. ***************
  654. *** 233,238 ****
  655. --- 297,307 ----
  656.     if (buf1 == NULL || buf2 == NULL)
  657.       error (2, 0, "virtual memory exhausted");
  658.   
  659. + #ifdef MSDOS
  660. +   setmode (file1_desc, O_BINARY);
  661. +   setmode (file2_desc, O_BINARY);
  662. + #endif
  663.     cmp ();
  664.   }
  665.   
  666. ***************
  667. *** 426,431 ****
  668. --- 495,501 ----
  669.     return p1c - p1;
  670.   }
  671.   
  672.   /* Compare two blocks of memory P1 and P2 until they differ.
  673.      Assumes that P1 and P2 are aligned at long addresses!
  674.      If the blocks are not guaranteed to be different, put sentinels at the ends
  675. ***************
  676. *** 508,514 ****
  677. --- 578,589 ----
  678.         --width;
  679.       }
  680.   
  681. + #ifdef MSDOS
  682. +   putc ((int) c, fs);
  683. + #else
  684.     putc (c, fs);
  685. + #endif
  686.     while (--width > 0)
  687.       putc (' ', fs);
  688.   }
  689. *** e:\tmp/RCSt1006574    Wed Sep 19 13:27:58 1990
  690. --- cp-aux.c    Wed Sep 19 12:37:08 1990
  691. ***************
  692. *** 18,23 ****
  693. --- 18,35 ----
  694.       Written by Torbjorn Granlund, Sweden (tege@sics.se).
  695.   */
  696.   
  697. + /*  MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  698. +     This port is also distributed under the terms of the
  699. +     GNU General Public License as published by the
  700. +     Free Software Foundation.
  701. +     Please note that this file is not identical to the
  702. +     original GNU release, you should have received this
  703. +     code as patch to the official release.
  704. +     $Header: e:/gnu/fileutil/RCS/cp-aux.c 1.4.0.2 90/09/19 11:18:11 tho Exp $
  705. +  */
  706.   #include <stdio.h>
  707.   
  708.   #include "cp.h"
  709. ***************
  710. *** 31,36 ****
  711. --- 43,63 ----
  712.     if (reason != NULL)
  713.       fprintf (stderr, "%s: %s\n", program_name, reason);
  714.   
  715. + #ifdef MSDOS
  716. +   fprintf (stderr, "\
  717. + Usage: %s [-bdfipruvxR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  718. +        [+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
  719. +        [+preserve] [+recursive] [+update] [+verbose] [+suffix backup-suffix]\n\
  720. +        [+version-control {numbered,existing,simple}] [+copying] [+version]\n\
  721. +        source dest\n\
  722. + \n\
  723. +        %s [-bdfipruvxR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  724. +        [+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
  725. +        [+preserve] [+recursive] [+update] [+verbose] [+suffix backup-suffix]\n\
  726. +        [+version-control {numbered,existing,simple}] [+copying] [+version]\n\
  727. +        source... directory\n",
  728. +        program_name, program_name);
  729. + #else /* not MSDOS */
  730.     fprintf (stderr, "\
  731.   Usage: %s [-bdfipruvxR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  732.          [+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
  733. ***************
  734. *** 42,51 ****
  735. --- 69,82 ----
  736.          [+preserve] [+recursive] [+update] [+verbose] [+suffix backup-suffix]\n\
  737.          [+version-control {numbered,existing,simple}] source... directory\n",
  738.          program_name, program_name);
  739. + #endif /* not MSDOS */
  740.   
  741.     exit (2);
  742.   }
  743.   
  744. + /* Use the one from gnulib */
  745. + #ifndef MSDOS
  746.   char *
  747.   xmalloc (size)
  748.        unsigned size;
  749. ***************
  750. *** 67,72 ****
  751. --- 98,105 ----
  752.     return x;
  753.   }
  754.   
  755. + #endif /* not MSDOS */
  756.   char *
  757.   stpcpy (s1, s2)
  758.        char *s1;
  759. ***************
  760. *** 89,94 ****
  761. --- 122,130 ----
  762.     return c == 'y' || c == 'Y';
  763.   }
  764.   
  765. + #ifndef MSDOS            /* no links ... */
  766.   int
  767.   is_ancestor (sb, ancestors)
  768.        struct stat *sb;
  769. ***************
  770. *** 103,108 ****
  771. --- 139,145 ----
  772.     return 0;
  773.   }
  774.   
  775.   /* Remove trailing slashes from PATH; they cause some system calls to fail. */
  776.   
  777.   void
  778. ***************
  779. *** 115,117 ****
  780. --- 152,166 ----
  781.     while (last > 0 && path[last] == '/')
  782.       path[last--] = '\0';
  783.   }
  784. + #else /* MSDOS */
  785. + void
  786. + strip_trailing_slashes (char **path)
  787. + {
  788. +   char *new_path = _fullpath (NULL, *path, 0);
  789. +   free (*path);
  790. +   *path = msdos_format_filename (new_path);
  791. + }
  792. + #endif /* MSDOS */
  793. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:00 1990
  794. --- cp.c    Wed Sep 19 12:35:14 1990
  795. ***************
  796. *** 17,22 ****
  797. --- 17,45 ----
  798.   
  799.       Written by Torbjorn Granlund and David MacKenzie. */
  800.   
  801. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  802. +    This port is also distributed under the terms of the
  803. +    GNU General Public License as published by the
  804. +    Free Software Foundation.
  805. +    Please note that this file is not identical to the
  806. +    original GNU release, you should have received this
  807. +    code as patch to the official release.  */
  808. + static char RCS_Id[] =
  809. +   "$Header: e:/gnu/fileutil/RCS/cp.c 1.4.0.2 90/09/19 11:18:06 tho Exp $";
  810. + static char Program_Id[] = "cp";
  811. + static char RCS_Revision[] = "$Revision: 1.4.0.2 $";
  812. + #define VERSION \
  813. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  814. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  815. + #define COPYING \
  816. +   "This is free software, distributed under the terms of the\n" \
  817. +   "GNU General Public License.  For details, see the file COPYING.\n"
  818.   /* Yet to be done:
  819.   
  820.    * Symlink translation. */
  821. ***************
  822. *** 26,31 ****
  823. --- 49,70 ----
  824.   #include "cp.h"
  825.   #include "backupfile.h"
  826.   
  827. + #ifdef MSDOS
  828. + #include <assert.h>
  829. + extern enum backup_type get_version (char *version);
  830. + extern char *savedir (char *dir, unsigned name_size);
  831. + #define strip_trailing_slashes(path)    strip_trailing_slashes (&path)
  832. + #define is_ancestor(statb, ancestors)    0
  833. + #define hash_init(module, size)
  834. + #define remember_copied(path, ino, dev)    NULL
  835. + #define remember_created(path)        0
  836. + #define forget_all()
  837. + char new_file;
  838. + #endif
  839.   #ifdef MKFIFO_MISSING
  840.   /* This definition assumes that MODE has the S_IFIFO bit set. */
  841.   #define mkfifo(path, mode) (mknod ((path), (mode), 0))
  842. ***************
  843. *** 42,48 ****
  844. --- 81,91 ----
  845.   
  846.   /* A pointer to either lstat or stat, depending on
  847.      whether dereferencing of symlinks is done.  */
  848. + #ifdef MSDOS
  849. + int (*xstat) (char *, struct stat *);
  850. + #else
  851.   int (*xstat) ();
  852. + #endif
  853.   
  854.   /* The invocation name of this program.  */
  855.   char *program_name;
  856. ***************
  857. *** 87,92 ****
  858. --- 130,139 ----
  859.   
  860.   struct option long_opts[] =
  861.   {
  862. + #ifdef MSDOS
  863. +   {"copying", 0, NULL, 30},
  864. +   {"version", 0, NULL, 31},
  865. + #endif
  866.     {"backup", 0, NULL, 'b'},
  867.     {"force", 0, NULL, 'f'},
  868.     {"interactive", 0, NULL, 'i'},
  869. ***************
  870. *** 123,129 ****
  871. --- 170,180 ----
  872.        that created directories can be written, even if it would not
  873.        have been allowed with the mask this process was started with.  */
  874.   
  875. + #ifdef MSDOS            /* not 100%ly correct ... */
  876. +   umask_kill = 07777 ^ umask (0);
  877. + #else
  878.     umask_kill = 0777777 ^ umask (0);
  879. + #endif
  880.   
  881.     while ((c = getopt_long (argc, argv, "bdfipruvxRS:V:", long_opts, &ind))
  882.        != EOF)
  883. ***************
  884. *** 185,190 ****
  885. --- 236,253 ----
  886.         version = optarg;
  887.         break;
  888.   
  889. + #ifdef MSDOS
  890. +     case 30:
  891. +       fprintf (stderr, COPYING);
  892. +       exit (0);
  893. +       break;
  894. +     case 31:
  895. +       fprintf (stderr, VERSION);
  896. +       exit (0);
  897. +       break;
  898. + #endif
  899.       default:
  900.         usage ((char *) 0);
  901.       }
  902. ***************
  903. *** 194,200 ****
  904. --- 257,267 ----
  905.       backup_type = get_version (version);
  906.   
  907.     if (flag_preserve == 1)
  908. + #ifdef MSDOS            /* not 100%ly correct ... */
  909. +     umask_kill = 07777;
  910. + #else
  911.       umask_kill = 0777777;
  912. + #endif
  913.   
  914.     /* The key difference between -d (+no-dereference) and not is the version
  915.        of `stat' to call.  */
  916. ***************
  917. *** 280,285 ****
  918. --- 347,359 ----
  919.         else
  920.           ap++;
  921.         dst_path = xmalloc (strlen (target) + strlen (ap) + 2);
  922. + #ifdef MSDOS
  923. +       /* Here a trailing slash might still be present (needed for
  924. +          stat()'ing root directories), take care of that. */
  925. +       if (target[strlen(target) - 1] == '/')
  926. +         stpcpy (stpcpy (dst_path, target), ap);
  927. +       else
  928. + #endif /* MSDOS */
  929.         stpcpy (stpcpy (stpcpy (dst_path, target), "/"), ap);
  930.   
  931.         ret |= copy (arg, dst_path, new_dst, 0, (struct dir_list *) 0);
  932. ***************
  933. *** 317,323 ****
  934. --- 391,401 ----
  935.     struct stat src_sb;
  936.     struct stat dst_sb;
  937.     int src_mode;
  938. + #ifdef MSDOS
  939. +   unsigned int src_type;
  940. + #else /* not MSDOS */
  941.     int src_type;
  942. + #endif /* not MSDOS */
  943.     char *earlier_file;
  944.     char *dst_backup = NULL;
  945.     int dir_mode_changed = 0;
  946. ***************
  947. *** 373,379 ****
  948.         else
  949.       {
  950.         /* The file exists already.  */
  951.         if (src_sb.st_ino == dst_sb.st_ino && src_sb.st_dev == dst_sb.st_dev)
  952.           {
  953.             error (0, 0, "`%s' and `%s' are the same file",
  954. --- 451,463 ----
  955.         else
  956.       {
  957.         /* The file exists already.  */
  958. ! #ifdef MSDOS
  959. !       if (strcmp (dst_path, src_path) == 0)
  960. !         {
  961. !           error (0, 0, "`%s': can't copy file to itself", src_path);
  962. !           return 1;
  963. !         }
  964. ! #else /* not MSDOS */
  965.         if (src_sb.st_ino == dst_sb.st_ino && src_sb.st_dev == dst_sb.st_dev)
  966.           {
  967.             error (0, 0, "`%s' and `%s' are the same file",
  968. ***************
  969. *** 380,385 ****
  970. --- 464,470 ----
  971.                src_path, dst_path);
  972.             return 1;
  973.           }
  974. + #endif /* not MSDOS */
  975.   
  976.         if (src_type != S_IFDIR)
  977.           {
  978. ***************
  979. *** 496,501 ****
  980. --- 581,587 ----
  981.         break;
  982.   #endif
  983.   
  984. + #ifndef MSDOS
  985.       case S_IFBLK:
  986.       case S_IFCHR:
  987.   #ifdef S_IFSOCK
  988. ***************
  989. *** 507,512 ****
  990. --- 593,599 ----
  991.         goto un_backup;
  992.       }
  993.         break;
  994. + #endif /* not MSDOS */
  995.   
  996.       case S_IFDIR:
  997.         {
  998. ***************
  999. *** 526,531 ****
  1000. --- 613,623 ----
  1001.       /* Insert the current directory in the list of parents.  */
  1002.   
  1003.       dir = (struct dir_list *) alloca (sizeof (struct dir_list));
  1004. + #ifdef MSDOS            /* always short of stack space ... */
  1005. +     if (!dir)
  1006. +       error (1, 0, "%s: stack overflow", src_path);
  1007. + #endif
  1008.       dir->parent = ancestors;
  1009.       dir->ino = src_sb.st_ino;
  1010.       dir->dev = src_sb.st_dev;
  1011. ***************
  1012. *** 668,674 ****
  1013. --- 760,771 ----
  1014.     int ret = 0;
  1015.   
  1016.     errno = 0;
  1017. + #ifdef MSDOS
  1018. +   assert (src_sb->st_size < 0xffffL);
  1019. +   name_space = savedir (src_path_in, (size_t) src_sb->st_size);
  1020. + #else
  1021.     name_space = savedir (src_path_in, src_sb->st_size);
  1022. + #endif
  1023.     if (name_space == 0)
  1024.       {
  1025.         if (errno)
  1026. ***************
  1027. *** 728,734 ****
  1028. --- 825,835 ----
  1029.     int *ip;
  1030.     int last_write_made_hole = 0;
  1031.   
  1032. + #ifdef MSDOS
  1033. +   source_desc = open (src_path, O_BINARY | O_RDONLY);
  1034. + #else
  1035.     source_desc = open (src_path, O_RDONLY);
  1036. + #endif
  1037.     if (source_desc < 0)
  1038.       {
  1039.         error (0, errno, "%s", src_path);
  1040. ***************
  1041. *** 738,744 ****
  1042. --- 839,849 ----
  1043.     /* Create the new regular file with small permissions initially,
  1044.        to not create a security hole.  */
  1045.   
  1046. + #ifdef MSDOS
  1047. +   target_desc = open (dst_path, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0600);
  1048. + #else
  1049.     target_desc = open (dst_path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
  1050. + #endif
  1051.     if (target_desc < 0)
  1052.       {
  1053.         error (0, errno, "cannot create regular file `%s'", dst_path);
  1054. ***************
  1055. *** 760,765 ****
  1056. --- 865,874 ----
  1057.     /* Make a buffer with space for a sentinel at the end.  */
  1058.   
  1059.     buf = (char *) alloca (buf_size + sizeof (int));
  1060. + #ifdef MSDOS
  1061. +   if (!buf)
  1062. +     error (2, 0, "%s: stack overflow", src_path);
  1063. + #endif
  1064.   
  1065.     for (;;)
  1066.       {
  1067. ***************
  1068. *** 773,779 ****
  1069. --- 882,892 ----
  1070.         if (n_read == 0)
  1071.       break;
  1072.   
  1073. + #ifdef MSDOS
  1074. +       n_read_total += (long) n_read;
  1075. + #else
  1076.         n_read_total += n_read;
  1077. + #endif
  1078.   
  1079.         buf[n_read] = 1;        /* Sentinel to stop loop.  */
  1080.   
  1081. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:02 1990
  1082. --- cp.h    Wed Sep 19 12:35:24 1990
  1083. ***************
  1084. *** 17,22 ****
  1085. --- 17,34 ----
  1086.   
  1087.       Written by Torbjorn Granlund, Sweden (tege@sics.se). */
  1088.   
  1089. + /*  MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  1090. +     This port is also distributed under the terms of the
  1091. +     GNU General Public License as published by the
  1092. +     Free Software Foundation.
  1093. +     Please note that this file is not identical to the
  1094. +     original GNU release, you should have received this
  1095. +     code as patch to the official release.
  1096. +     $Header: e:/gnu/fileutil/RCS/cp.h 1.4.0.2 90/09/19 12:27:43 tho Exp $
  1097. +  */
  1098.   #include <sys/types.h>
  1099.   
  1100.   #include "system.h"
  1101. ***************
  1102. *** 48,53 ****
  1103. --- 60,77 ----
  1104.   extern int exit_status;
  1105.   extern struct htab *htab;
  1106.   
  1107. + #ifdef MSDOS
  1108. + #include <gnulib.h>
  1109. + extern void forget_all (void);
  1110. + extern int copy_reg (char *, char *);
  1111. + extern void hash_init (unsigned int, unsigned int);
  1112. + extern int remember_created (char *);
  1113. + extern char *remember_copied (char *, unsigned short, short);
  1114. + #else /* not MSDOS */
  1115.   extern char *xmalloc ();
  1116.   extern char *xrealloc ();
  1117.   extern void forget_copied ();
  1118. ***************
  1119. *** 57,66 ****
  1120. --- 81,106 ----
  1121.   extern char *remember_copied ();
  1122.   extern int remember_created ();
  1123.   
  1124. + #endif /* not MSDOS */
  1125.   /* For created inodes, a pointer in the search structure to this
  1126.      character identifies that the inode as new.  */
  1127.   extern char new_file;
  1128.   
  1129. + #ifdef MSDOS
  1130. + extern  void main (int, char **);
  1131. + extern  void usage (char *);
  1132. + extern  void error (int status, int errnum, char *message, ...);
  1133. + extern  int yesno (void);
  1134. + extern  char *stpcpy (char *, char *);
  1135. + extern  int user_confirm_overwriting (char *);
  1136. + extern  int member (int);
  1137. + extern  int do_copy (int, char **);
  1138. + extern  int copy (char *, char *, int, short, struct dir_list *);
  1139. + extern  int copy_dir(char *,char *,int,struct stat *,struct dir_list *);
  1140. + extern  void strip_trailing_slashes (char **path);
  1141. + #endif /* MSDOS */
  1142.   extern void error ();
  1143.   extern void usage ();
  1144.   extern char *savedir ();
  1145. ***************
  1146. *** 73,78 ****
  1147. --- 113,136 ----
  1148.   extern int is_ancestor ();
  1149.   
  1150.   /* System calls.  */
  1151. + #ifdef MSDOS
  1152. + #include <direct.h>
  1153. + #include <io.h>
  1154. + #include <malloc.h>
  1155. + #include <pwd.h>
  1156. + /* Very "interesting" system calls ... */
  1157. + #define    link(a, b)            (-1)
  1158. + #define chown(path, uid, gid)        0
  1159. + #define mkdir(path, mode)        mkdir (path)
  1160. + #define ftruncate            chsize
  1161. + extern  int eaccess_stat (struct stat *statp, int mode);
  1162. + #else /* not MSDOS */
  1163.   extern int mknod ();
  1164.   
  1165.   #ifdef _POSIX_SOURCE
  1166. ***************
  1167. *** 100,105 ****
  1168. --- 158,165 ----
  1169.   extern int isatty ();
  1170.   extern off_t lseek ();
  1171.   #endif
  1172. + #endif /* not MSDOS */
  1173.   
  1174.   /* Library calls.  */
  1175.   #include <errno.h>
  1176. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:04 1990
  1177. --- cut.c    Wed Sep 19 12:38:18 1990
  1178. ***************
  1179. *** 62,67 ****
  1180. --- 62,92 ----
  1181.   
  1182.      A FILE of `-' means standard input. */
  1183.   
  1184. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  1185. +    This port is also distributed under the terms of the
  1186. +    GNU General Public License as published by the
  1187. +    Free Software Foundation.
  1188. +    Please note that this file is not identical to the
  1189. +    original GNU release, you should have received this
  1190. +    code as patch to the official release.  */
  1191. + #ifdef MSDOS
  1192. + static char RCS_Id[] =
  1193. +   "$Header: e:/gnu/fileutil/RCS/cut.c 1.4.0.3 90/09/19 11:17:49 tho Exp $";
  1194. + static char Program_Id[] = "cut";
  1195. + static char RCS_Revision[] = "$Revision: 1.4.0.3 $";
  1196. + #define VERSION \
  1197. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  1198. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  1199. + #define COPYING \
  1200. +   "This is free software, distributed under the terms of the\n" \
  1201. +   "GNU General Public License.  For details, see the file COPYING.\n"
  1202. + #endif /* MSDOS */
  1203.   #include <stdio.h>
  1204.   #include <errno.h>
  1205.   #include <getopt.h>
  1206. ***************
  1207. *** 78,83 ****
  1208. --- 103,123 ----
  1209.   extern int errno;
  1210.   #endif
  1211.   
  1212. + #ifdef MSDOS
  1213. + #include <gnulib.h>
  1214. + void main (int argc, char **argv);
  1215. + int set_fields (char *fieldstr);
  1216. + void cut_file (FILE * stream);
  1217. + void cut_file_bytes (FILE * fno);
  1218. + void cut_file_fields (FILE * fno);
  1219. + void enlarge_line (int new_size);
  1220. + void invalid_list (void);
  1221. + void usage (void);
  1222. + #else /* not MSDOS */
  1223.   char *xmalloc ();
  1224.   char *xrealloc ();
  1225.   int set_fields ();
  1226. ***************
  1227. *** 89,94 ****
  1228. --- 129,136 ----
  1229.   void invalid_list ();
  1230.   void usage ();
  1231.   
  1232. + #endif /* not MSDOS */
  1233.   /* The number of elements allocated for the input line
  1234.      and the byte or field number.
  1235.      Enlarged as necessary. */
  1236. ***************
  1237. *** 138,143 ****
  1238. --- 180,189 ----
  1239.   
  1240.   struct option longopts[] =
  1241.   {
  1242. + #ifdef MSDOS
  1243. +   {"copying", 0, NULL, 30},
  1244. +   {"version", 0, NULL, 31},
  1245. + #endif
  1246.     {"bytes", 1, 0, 'b'},
  1247.     {"characters", 1, 0, 'c'},
  1248.     {"fields", 1, 0, 'f'},
  1249. ***************
  1250. *** 211,216 ****
  1251. --- 257,274 ----
  1252.         delimited_lines_only++;
  1253.         break;
  1254.   
  1255. + #ifdef MSDOS
  1256. +     case 30:
  1257. +       fprintf (stderr, COPYING);
  1258. +       exit (0);
  1259. +       break;
  1260. +     case 31:
  1261. +       fprintf (stderr, VERSION);
  1262. +       exit (0);
  1263. +       break;
  1264. + #endif
  1265.       default:
  1266.         usage ();
  1267.       }
  1268. ***************
  1269. *** 528,533 ****
  1270. --- 586,594 ----
  1271.     line_size = new_size;
  1272.   }
  1273.   
  1274. + #ifndef MSDOS            /* We have it in gnulib  */
  1275.   /* Allocate N bytes of memory dynamically, with error checking.  */
  1276.   
  1277.   char *
  1278. ***************
  1279. *** 553,558 ****
  1280. --- 614,621 ----
  1281.     return p;
  1282.   }
  1283.   
  1284. + #endif /* not MSDOS */
  1285.   void
  1286.   invalid_list ()
  1287.   {
  1288. ***************
  1289. *** 562,567 ****
  1290. --- 625,641 ----
  1291.   void
  1292.   usage ()
  1293.   {
  1294. + #ifdef MSDOS
  1295. +   fprintf (stderr, "\
  1296. + Usage: %s {-b byte-list,+bytes byte-list} [-n] [+copying]\n\
  1297. +        [+version] [file...]\n\
  1298. +        %s {-c character-list,+characters character-list} [+copying]\n\
  1299. +        [+version] [file...]\n\
  1300. +        %s {-f field-list,+fields field-list} [-d delim] [-s]\n\
  1301. +        [+delimiter delim] [+only-delimited] [+copying] [+version] [file...]\n",
  1302. +        program_name, program_name, program_name);
  1303. + #else /* not MSDOS */
  1304.     fprintf (stderr, "\
  1305.   Usage: %s {-b byte-list,+bytes byte-list} [-n] [file...]\n\
  1306.          %s {-c character-list,+characters character-list} [file...]\n\
  1307. ***************
  1308. *** 568,572 ****
  1309. --- 642,647 ----
  1310.          %s {-f field-list,+fields field-list} [-d delim] [-s]\n\
  1311.          [+delimiter delim] [+only-delimited] [file...]\n",
  1312.          program_name, program_name, program_name);
  1313. + #endif /* not MSDOS */
  1314.     exit (2);
  1315.   }
  1316. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:08 1990
  1317. --- dd.c    Wed Sep 19 12:41:20 1990
  1318. ***************
  1319. *** 17,22 ****
  1320. --- 17,47 ----
  1321.   
  1322.   /* Written by Paul Rubin and David MacKenzie. */
  1323.   
  1324. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  1325. +    This port is also distributed under the terms of the
  1326. +    GNU General Public License as published by the
  1327. +    Free Software Foundation.
  1328. +    Please note that this file is not identical to the
  1329. +    original GNU release, you should have received this
  1330. +    code as patch to the official release.  */
  1331. + #ifdef MSDOS
  1332. + static char RCS_Id[] =
  1333. +   "$Header: e:/gnu/fileutil/RCS/dd.c 1.4.0.2 90/09/19 11:17:53 tho Exp $";
  1334. + static char Program_Id[] = "dd";
  1335. + static char RCS_Revision[] = "$Revision: 1.4.0.2 $";
  1336. + #define VERSION \
  1337. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  1338. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  1339. + #define COPYING \
  1340. +   "This is free software, distributed under the terms of the\n" \
  1341. +   "GNU General Public License.  For details, see the file COPYING.\n"
  1342. + #endif /* MSDOS */
  1343.   /* Options:
  1344.   
  1345.      Numbers can be followed by a multiplier:
  1346. ***************
  1347. *** 53,58 ****
  1348. --- 78,90 ----
  1349.      sync                Pad every input block to size of ibs with
  1350.                   trailing NULs. */
  1351.   
  1352. + #ifdef MSDOS
  1353. + /*
  1354. +    im={text,binary}        Input file translation mode (default: text)
  1355. +    om={text,binary}        Output file translation mode (default: text)
  1356. +  */
  1357. + #endif
  1358.   #include <stdio.h>
  1359.   #include <ctype.h>
  1360.   #ifdef STDC_HEADERS
  1361. ***************
  1362. *** 65,70 ****
  1363. --- 97,103 ----
  1364.   #include <sys/types.h>
  1365.   #include <signal.h>
  1366.   #include "system.h"
  1367.   #ifdef STDC_HEADERS
  1368.   #include <errno.h>
  1369.   #include <stdlib.h>
  1370. ***************
  1371. *** 79,85 ****
  1372. --- 112,120 ----
  1373.   #endif
  1374.   
  1375.   #define equal(p, q) (strcmp ((p),(q)) == 0)
  1376. + #ifndef MSDOS
  1377.   #define max(a, b) ((a) > (b) ? (a) : (b))
  1378. + #endif
  1379.   
  1380.   /* Default input and output blocksize. */
  1381.   #define DEFAULT_BLOCKSIZE 512
  1382. ***************
  1383. *** 98,103 ****
  1384. --- 133,160 ----
  1385.   /* Use separate input and output buffers, and combine partial input blocks. */
  1386.   #define C_TWOBUFS 04000
  1387.   
  1388. + #ifdef MSDOS
  1389. + #include <io.h>
  1390. + extern void error (int status, int errnum, char *message, ...);
  1391. + extern void main (int argc, char **argv);
  1392. + static void copy (void);
  1393. + static void scanargs (int argc, char **argv);
  1394. + static int parse_integer (char *str);
  1395. + static void parse_conversion (char *str);
  1396. + static void apply_translations (void);
  1397. + static void translate_charset (unsigned char *new_trans);
  1398. + static int bit_count (unsigned int i);
  1399. + static void print_stats (void);
  1400. + static void quit (int code);
  1401. + static SIGTYPE interrupt_handler (void);
  1402. + static char *xmalloc (unsigned short n);
  1403. + static void usage (char *string, char *arg0, char *arg1);
  1404. + #else /* not MSDOS */
  1405.   char *xmalloc ();
  1406.   SIGTYPE interrupt_handler ();
  1407.   int bit_count ();
  1408. ***************
  1409. *** 112,117 ****
  1410. --- 169,176 ----
  1411.   void scanargs ();
  1412.   void usage ();
  1413.   
  1414. + #endif /* not MSDOS */
  1415.   /* The name this program was run with. */
  1416.   char *program_name;
  1417.   
  1418. ***************
  1419. *** 128,146 ****
  1420. --- 187,221 ----
  1421.   int output_fd = 1;
  1422.   
  1423.   /* The number of bytes in which atomic reads are done. */
  1424. + #ifdef MSDOS
  1425. + int input_blocksize = -1;
  1426. + #else
  1427.   long input_blocksize = -1;
  1428. + #endif
  1429.   
  1430.   /* The number of bytes in which atomic writes are done. */
  1431. + #ifdef MSDOS
  1432. + int output_blocksize = -1;
  1433. + #else
  1434.   long output_blocksize = -1;
  1435. + #endif
  1436.   
  1437.   /* Conversion buffer size, in bytes.  0 prevents conversions. */
  1438. + #ifdef MSDOS
  1439. + int conversion_blocksize = 0;
  1440. + #else
  1441.   long conversion_blocksize = 0;
  1442. + #endif
  1443.   
  1444.   /* Skip this many records of `input_blocksize' bytes before input. */
  1445.   int skip_records = 0;
  1446.   
  1447.   /* Skip this many records of `output_blocksize' bytes before output. */
  1448. + #ifdef MSDOS
  1449. + int seek_record = 0;
  1450. + #else
  1451.   long seek_record = 0;
  1452. + #endif
  1453.   
  1454.   /* Copy only this many records.  <0 means no limit. */
  1455.   int max_record = -1;
  1456. ***************
  1457. *** 163,168 ****
  1458. --- 238,249 ----
  1459.   /* Records truncated by conv=block. */
  1460.   unsigned r_truncate = 0;
  1461.   
  1462. + #ifdef MSDOS
  1463. + /* Translation modes */
  1464. + int input_file_mode = O_TEXT;
  1465. + int output_file_mode = O_TEXT;
  1466. + #endif
  1467.   /* Output representation of newline and space characters. */
  1468.   unsigned char newline_character = '\n';
  1469.   unsigned char space_character = ' ';
  1470. ***************
  1471. *** 312,317 ****
  1472. --- 393,399 ----
  1473.     for (i = 0; i < 256; i++)
  1474.       trans_table[i] = i;
  1475.   
  1476.     /* Decode arguments. */
  1477.     scanargs (argc, argv);
  1478.     apply_translations ();
  1479. ***************
  1480. *** 333,339 ****
  1481.       }
  1482.     else
  1483.       output_file = "standard output";
  1484. !   
  1485.     signal (SIGINT, interrupt_handler);
  1486.     copy ();
  1487.   }
  1488. --- 415,426 ----
  1489.       }
  1490.     else
  1491.       output_file = "standard output";
  1492. ! #ifdef MSDOS
  1493. !   setmode (input_fd, input_file_mode);
  1494. !   setmode (output_fd, output_file_mode);
  1495. ! #endif
  1496.     signal (SIGINT, interrupt_handler);
  1497.     copy ();
  1498.   }
  1499. ***************
  1500. *** 369,375 ****
  1501. --- 456,466 ----
  1502.       }
  1503.     if ((in_stats.st_mode & S_IFMT) == S_IFREG)
  1504.       {
  1505. + #ifdef MSDOS
  1506. +       if (lseek (input_fd, skip_records * (long) input_blocksize, L_SET) < 0)
  1507. + #else
  1508.         if (lseek (input_fd, skip_records * input_blocksize, L_SET) < 0)
  1509. + #endif
  1510.       {
  1511.         error (0, errno, "%s", input_file);
  1512.         quit (1);
  1513. ***************
  1514. *** 393,399 ****
  1515. --- 484,494 ----
  1516.       }
  1517.     if ((out_stats.st_mode & S_IFMT) == S_IFREG)
  1518.       {
  1519. + #ifdef MSDOS
  1520. +       if (lseek (output_fd, seek_record * (long) output_blocksize, L_SET) < 0)
  1521. + #else
  1522.         if (lseek (output_fd, seek_record * output_blocksize, L_SET) < 0)
  1523. + #endif
  1524.       {
  1525.         error (0, errno, "%s", output_file);
  1526.         quit (1);
  1527. ***************
  1528. *** 643,648 ****
  1529. --- 738,755 ----
  1530.         char *name, *val;
  1531.   
  1532.         name = argv[i];
  1533. + #ifdef MSDOS
  1534. +       if (equal (name, "copying"))
  1535. +     {
  1536. +       fprintf (stderr, COPYING);
  1537. +       exit (0);
  1538. +     }
  1539. +       else if (equal (name, "version"))
  1540. +     {
  1541. +       fprintf (stderr, VERSION);
  1542. +       exit (0);
  1543. +     }
  1544. + #endif
  1545.         val = index (name, '=');
  1546.         if (val == NULL)
  1547.       usage ("unrecognized option `%s'", name);
  1548. ***************
  1549. *** 654,659 ****
  1550. --- 761,786 ----
  1551.       output_file = val;
  1552.         else if (equal (name, "conv"))
  1553.       parse_conversion (val);
  1554. + #ifdef MSDOS
  1555. +       else if (equal (name, "im"))
  1556. +     {
  1557. +       if (equal (val, "text"))
  1558. +         input_file_mode = O_TEXT;
  1559. +       else if (equal (val, "binary"))
  1560. +         input_file_mode = O_BINARY;
  1561. +       else
  1562. +         error (1, 0, "Input file mode must be text or binary");
  1563. +     }
  1564. +       else if (equal (name, "om"))
  1565. +     {
  1566. +       if (equal (val, "text"))
  1567. +         output_file_mode = O_TEXT;
  1568. +       else if (equal (val, "binary"))
  1569. +         output_file_mode = O_BINARY;
  1570. +       else
  1571. +         error (1, 0, "Output file mode must be text or binary");
  1572. +     }
  1573. + #endif /* MSDOS */
  1574.         else
  1575.       {
  1576.         n = parse_integer (val);
  1577. ***************
  1578. *** 886,891 ****
  1579. --- 1013,1028 ----
  1580.     fprintf (stderr, "%s: ", program_name);
  1581.     fprintf (stderr, string, arg0, arg1);
  1582.     fprintf (stderr, "\n");
  1583. + #ifdef MSDOS
  1584. +   fprintf (stderr, "\
  1585. + Usage: %s [if=file] [of=file] [ibs=bytes] [obs=bytes] [bs=bytes] [cbs=bytes]\n\
  1586. +        [skip=blocks] [seek=blocks] [count=blocks]\n\
  1587. +        [im={text,binary}] [om={text,binary}] [copying] [version]\n\
  1588. +        [conv={ascii,ebcdic,ibm,block,unblock,lcase,ucase,swab,noerror,sync}]\n\
  1589. + Numbers can be followed by a multiplier:\n\
  1590. + b=512, k=1024, w=2, xm=number m\n",
  1591. +        program_name);
  1592. + #else /* not MSDOS */
  1593.     fprintf (stderr, "\
  1594.   Usage: %s [if=file] [of=file] [ibs=bytes] [obs=bytes] [bs=bytes] [cbs=bytes]\n\
  1595.          [skip=blocks] [seek=blocks] [count=blocks]\n\
  1596. ***************
  1597. *** 893,897 ****
  1598. --- 1030,1035 ----
  1599.   Numbers can be followed by a multiplier:\n\
  1600.   b=512, k=1024, w=2, xm=number m\n",
  1601.          program_name);
  1602. + #endif /* not MSDOS */
  1603.     exit (1);
  1604.   }
  1605. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:10 1990
  1606. --- eaccess.c    Wed Sep 19 12:37:30 1990
  1607. ***************
  1608. *** 17,33 ****
  1609. --- 17,55 ----
  1610.   
  1611.   /* David MacKenzie and Torbjorn Granlund */
  1612.   
  1613. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  1614. +    This port is also distributed under the terms of the
  1615. +    GNU General Public License as published by the
  1616. +    Free Software Foundation.
  1617. +    Please note that this file is not identical to the
  1618. +    original GNU release, you should have received this
  1619. +    code as patch to the official release.
  1620. +    $Header: e:/gnu/fileutil/RCS/eaccess.c 1.4.0.2 90/09/19 12:27:30 tho Exp $
  1621. +  */
  1622.   #include <sys/types.h>
  1623.   #include <sys/stat.h>
  1624.   #ifdef _POSIX_SOURCE
  1625.   #include <unistd.h>
  1626.   #else
  1627. + #ifdef MSDOS
  1628. + #include <pwd.h>
  1629. + #else /* not MSDOS */
  1630.   #include <sys/param.h>
  1631. + #endif /* not MSDOS */
  1632.   #endif
  1633.   #include <errno.h>
  1634.   #if defined(EACCES) && !defined(EACCESS)
  1635.   #define EACCESS EACCES
  1636.   #endif
  1637. + #ifdef MSDOS
  1638. + #include <stdlib.h>
  1639. + extern  int eaccess (char *path, int mode);
  1640. + extern  int eaccess_stat (struct stat *statp, int mode);
  1641. + #endif /* MSDOS */
  1642.   
  1643.   #ifndef _POSIX_SOURCE
  1644.   #define F_OK 0
  1645. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:14 1990
  1646. --- filemode.c    Wed Sep 19 12:33:12 1990
  1647. ***************
  1648. *** 14,19 ****
  1649. --- 14,31 ----
  1650.      You should have received a copy of the GNU General Public License
  1651.      along with this program; if not, write to the Free Software
  1652.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1653. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  1654. +    This port is also distributed under the terms of the
  1655. +    GNU General Public License as published by the
  1656. +    Free Software Foundation.
  1657. +    Please note that this file is not identical to the
  1658. +    original GNU release, you should have received this
  1659. +    code as patch to the official release.
  1660. +    $Header: e:/gnu/fileutil/RCS/filemode.c 1.4.0.1 90/09/17 08:18:12 tho Exp $
  1661. +  */
  1662.   
  1663.   #include <sys/types.h>
  1664.   #include <sys/stat.h>
  1665. ***************
  1666. *** 23,32 ****
  1667. --- 35,52 ----
  1668.   #define S_IEXEC S_IXUSR
  1669.   #endif
  1670.   
  1671. + #ifdef MSDOS
  1672. + extern void filemodestring (struct stat *, char *);
  1673. + extern void mode_string (unsigned short mode, char *str);
  1674. + static char ftypelet (unsigned short bits);
  1675. + static void rwx (unsigned short, char *);
  1676. + static void setst (unsigned short, char *);
  1677. + #else /* not MSDOS */
  1678.   void mode_string ();
  1679.   static char ftypelet ();
  1680.   static void rwx ();
  1681.   static void setst ();
  1682. + #endif /* not MSDOS */
  1683.   
  1684.   /* filemodestring - fill in string STR with an ls-style ASCII
  1685.      representation of the st_mode field of file stats block STATP.
  1686. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:16 1990
  1687. --- getdate.y    Wed Sep 19 12:52:14 1990
  1688. ***************
  1689. *** 5,10 ****
  1690. --- 5,24 ----
  1691.       /*    University of North Carolina at Chapel Hill    */
  1692.       /*    @(#)getdate.y    2.17    11/30/87            */
  1693.   
  1694. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  1695. +    This port is also distributed under the terms of the
  1696. +    GNU General Public License as published by the
  1697. +    Free Software Foundation.
  1698. +    Please note that this file is not identical to the
  1699. +    original GNU release, you should have received this
  1700. +    code as patch to the official release.  */
  1701. + #ifdef MSDOS
  1702. + static char RCS_Id[] =
  1703. +   "$Header: e:/gnu/fileutil/RCS/getdate.y 1.4.0.2 90/09/19 12:27:47 tho Exp $";
  1704. + #endif /* MSDOS */
  1705.   /* #include "defs.h" JF not used any more */
  1706.   #include <sys/types.h>
  1707.   #ifdef USG
  1708. ***************
  1709. *** 39,44 ****
  1710. --- 53,74 ----
  1711.   #endif
  1712.   #endif
  1713.   
  1714. + #ifdef MSDOS
  1715. + #include <malloc.h>
  1716. + int getdate_yyparse (void);
  1717. + long getdate (char *p, struct timeb *now);
  1718. + void ftime (struct timeb *timeb);
  1719. + static long dateconv (int mm, int dd, int yy, int h, int m, int s, int mer,
  1720. +               int zone, int dayflag);
  1721. + static long dayconv (int ord, int day, long now);
  1722. + static long timeconv (int hh, int mm, int ss, int mer);
  1723. + static long monthadd (long sdate, long relmonth);
  1724. + static long daylcorr (long future, long now);
  1725. + static int lookup (char *id);
  1726. + static int yyerror (char *s);
  1727. + static int yylex (void);
  1728. + #endif /* MSDOS */
  1729.   #ifndef NULL
  1730.   #define    NULL    0
  1731.   #endif
  1732. ***************
  1733. *** 604,609 ****
  1734. --- 634,640 ----
  1735.   {
  1736.     return 0;
  1737.   }
  1738.   
  1739.   #ifdef USG
  1740.   static void
  1741. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:18 1990
  1742. --- getversi.c    Wed Sep 19 12:37:46 1990
  1743. ***************
  1744. *** 17,26 ****
  1745. --- 17,44 ----
  1746.   
  1747.   /* Written by David MacKenzie <djm@ai.mit.edu> */
  1748.   
  1749. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  1750. +    This port is also distributed under the terms of the
  1751. +    GNU General Public License as published by the
  1752. +    Free Software Foundation.
  1753. +    Please note that this file is not identical to the
  1754. +    original GNU release, you should have received this
  1755. +    code as patch to the official release.
  1756. +    $Header: e:/gnu/fileutil/RCS/getversi.c 1.4.0.2 90/09/19 12:27:31 tho Exp $
  1757. +  */
  1758.   #include "backupfile.h"
  1759.   
  1760. + #ifdef MSDOS
  1761. + extern enum backup_type get_version (char *version);
  1762. + extern int argmatch (char *arg, char **optlist);
  1763. + extern void invalid_arg (char *kind, char *value, int problem);
  1764. + #else /* not MSDOS */
  1765.   int argmatch ();
  1766.   void invalid_arg ();
  1767. + #endif /* not MSDOS */
  1768.   
  1769.   extern char *program_name;
  1770.   
  1771. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:20 1990
  1772. --- head.c    Wed Sep 19 12:42:30 1990
  1773. ***************
  1774. *** 15,20 ****
  1775. --- 15,45 ----
  1776.      along with this program; if not, write to the Free Software
  1777.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1778.   
  1779. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  1780. +    This port is also distributed under the terms of the
  1781. +    GNU General Public License as published by the
  1782. +    Free Software Foundation.
  1783. +    Please note that this file is not identical to the
  1784. +    original GNU release, you should have received this
  1785. +    code as patch to the official release.  */
  1786. + #ifdef MSDOS
  1787. + static char RCS_Id[] =
  1788. +   "$Header: e:/gnu/fileutil/RCS/head.c 1.4.0.3 90/09/19 11:17:59 tho Exp $";
  1789. + static char Program_Id[] = "head";
  1790. + static char RCS_Revision[] = "$Revision: 1.4.0.3 $";
  1791. + #define VERSION \
  1792. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  1793. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  1794. + #define COPYING \
  1795. +   "This is free software, distributed under the terms of the\n" \
  1796. +   "GNU General Public License.  For details, see the file COPYING.\n"
  1797. + #endif /* MSDOS */
  1798.   /* Usage: head [-b #] [-c #] [-n #] [-qv] [+blocks #] [+bytes #] [+lines #]
  1799.             [+quiet] [+silent] [+verbose] [file...]
  1800.   
  1801. ***************
  1802. *** 64,69 ****
  1803. --- 89,97 ----
  1804.   #define BYTES 1            /* Head in bytes. */
  1805.   #define BLOCKS 2        /* Head in blocks. */
  1806.   #define HEADERS 4        /* Write filename headers. */
  1807. + #ifdef MSDOS
  1808. + #define BINARY 32        /* Suppress crlf translation. */
  1809. + #endif
  1810.   
  1811.   /* When to print the filename banners. */
  1812.   enum header_mode
  1813. ***************
  1814. *** 71,76 ****
  1815. --- 99,125 ----
  1816.     multiple_files, always, never
  1817.   };
  1818.   
  1819. + #ifdef MSDOS
  1820. + #include <string.h>
  1821. + #include <stdarg.h>
  1822. + #include <io.h>
  1823. + #include <gnulib.h>
  1824. + extern  void main (int, char **);
  1825. + extern  int head_file (char *, int, long);
  1826. + extern  void write_header (char *);
  1827. + extern  int head (char *, int, int, long);
  1828. + extern  int head_bytes (char *, int, long);
  1829. + extern  int head_lines (char *, int, long);
  1830. + extern  void xwrite (int, char *, int);
  1831. + extern  long atou (char *);
  1832. + extern  char *basename (char *);
  1833. + extern  void usage (void);
  1834. + #else /* not MSDOS */
  1835.   int head ();
  1836.   int head_bytes ();
  1837.   int head_file ();
  1838. ***************
  1839. *** 81,91 ****
  1840. --- 130,147 ----
  1841.   void write_header ();
  1842.   void xwrite ();
  1843.   
  1844. + #endif /* MSDOS */
  1845.   /* The name this program was run with. */
  1846.   char *program_name;
  1847.   
  1848.   struct option long_options[] =
  1849.   {
  1850. + #ifdef MSDOS
  1851. +   {"binary", 1, NULL, 'B'},
  1852. +   {"copying", 0, NULL, 30},
  1853. +   {"version", 0, NULL, 31},
  1854. + #endif
  1855.     {"blocks", 1, NULL, 'b'},
  1856.     {"bytes", 1, NULL, 'c'},
  1857.     {"lines", 1, NULL, 'n'},
  1858. ***************
  1859. *** 154,164 ****
  1860. --- 210,240 ----
  1861.         argc--;
  1862.       }
  1863.   
  1864. + #ifdef MSDOS
  1865. +   while ((c = getopt_long (argc, argv, "Bb:c:n:qv", long_options, &longind))
  1866. + #else
  1867.     while ((c = getopt_long (argc, argv, "b:c:n:qv", long_options, &longind))
  1868. + #endif
  1869.        != EOF)
  1870.       {
  1871.         switch (c)
  1872.       {
  1873. + #ifdef MSDOS
  1874. +     case 30:
  1875. +       fprintf (stderr, COPYING);
  1876. +       exit (0);
  1877. +       break;
  1878. +     case 31:
  1879. +       fprintf (stderr, VERSION);
  1880. +       exit (0);
  1881. +       break;
  1882. +     case 'B':
  1883. +       mode |= BINARY;
  1884. +       break;
  1885. + #endif
  1886.       case 'b':
  1887.         mode |= BLOCKS;
  1888.         mode &= ~BYTES;
  1889. ***************
  1890. *** 274,283 ****
  1891. --- 350,382 ----
  1892.        int mode;
  1893.        long number;
  1894.   {
  1895. + #ifdef MSDOS
  1896. +   int errors;
  1897. +   if (mode & BINARY)
  1898. +     {
  1899. +       setmode (fileno (stdout), O_BINARY);
  1900. +       setmode (fd, O_BINARY);
  1901. +     }
  1902. +   if (mode & (BYTES | BLOCKS))
  1903. +     errors = head_bytes (filename, fd, number);
  1904. +   else
  1905. +     errors = head_lines (filename, fd, number);
  1906. +   if (mode & BINARY)
  1907. +     setmode (fileno (stdout), O_TEXT);
  1908. +   return errors;
  1909. + #else /* not MSDOS */
  1910.     if (mode & (BYTES | BLOCKS))
  1911.       return head_bytes (filename, fd, number);
  1912.     else
  1913.       return head_lines (filename, fd, number);
  1914. + #endif /* not MSDOS */
  1915.   }
  1916.   
  1917.   int
  1918. ***************
  1919. *** 299,308 ****
  1920. --- 398,414 ----
  1921.       }
  1922.         if (bytes_read == 0)
  1923.       break;
  1924. + #ifdef MSDOS
  1925. +       if ((long) bytes_read > bytes_to_write)
  1926. +     bytes_read = (int) bytes_to_write;
  1927. +       xwrite (1, buffer, bytes_read);
  1928. +       bytes_to_write -= (long) bytes_read;
  1929. + #else /* not MSDOS */
  1930.         if (bytes_read > bytes_to_write)
  1931.       bytes_read = bytes_to_write;
  1932.         xwrite (1, buffer, bytes_read);
  1933.         bytes_to_write -= bytes_read;
  1934. + #endif /* not MSDOS */
  1935.       }
  1936.     return 0;
  1937.   }
  1938. ***************
  1939. *** 356,371 ****
  1940.   atou (str)
  1941.        char *str;
  1942.   {
  1943. !   int value;
  1944.   
  1945.     for (value = 0; ISDIGIT (*str); ++str)
  1946.       value = value * 10 + *str - '0';
  1947. !   return *str ? -1 : value;
  1948.   }
  1949.   
  1950.   void
  1951.   usage ()
  1952.   {
  1953.     fprintf (stderr, "\
  1954.   Usage: %s [-b #] [-c #] [-n #] [-qv] [+blocks #] [+bytes #] [+lines #]\n\
  1955.          [+quiet] [+silent] [+verbose] [file...]\n\
  1956. --- 462,486 ----
  1957.   atou (str)
  1958.        char *str;
  1959.   {
  1960. !   long value;
  1961.   
  1962.     for (value = 0; ISDIGIT (*str); ++str)
  1963.       value = value * 10 + *str - '0';
  1964. !   return *str ? -1L : value;
  1965.   }
  1966.   
  1967.   void
  1968.   usage ()
  1969.   {
  1970. + #ifdef MSDOS
  1971. +   fprintf (stderr, "\
  1972. + Usage: %s [-b #] [-c #] [-n #] [-qvB] [+blocks #] [+bytes #]\n\
  1973. +        [+lines #] [+quiet] [+silent] [+verbose] [+binary] [+version]\n\
  1974. +        [+copying] [file...]\n\
  1975. + \n\
  1976. +        %s [-#bclqv] [file...]\n", program_name, program_name);
  1977. +   exit (1);
  1978. + #else
  1979.     fprintf (stderr, "\
  1980.   Usage: %s [-b #] [-c #] [-n #] [-qv] [+blocks #] [+bytes #] [+lines #]\n\
  1981.          [+quiet] [+silent] [+verbose] [file...]\n\
  1982. ***************
  1983. *** 372,375 ****
  1984. --- 487,491 ----
  1985.   \n\
  1986.          %s [-#bclqv] [file...]\n", program_name, program_name);
  1987.     exit (1);
  1988. + #endif
  1989.   }
  1990. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:24 1990
  1991. --- ls.c    Wed Sep 19 12:39:12 1990
  1992. ***************
  1993. *** 14,19 ****
  1994. --- 14,43 ----
  1995.      You should have received a copy of the GNU General Public License
  1996.      along with this program; if not, write to the Free Software
  1997.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1998. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  1999. +    This port is also distributed under the terms of the
  2000. +    GNU General Public License as published by the
  2001. +    Free Software Foundation.
  2002. +    Please note that this file is not identical to the
  2003. +    original GNU release, you should have received this
  2004. +    code as patch to the official release.  */
  2005. + #ifdef MSDOS
  2006. + static char RCS_Id[] =
  2007. +   "$Header: e:/gnu/fileutil/RCS/ls.c 1.4.0.2 90/09/19 11:18:27 tho Exp $";
  2008. + static char RCS_Revision[] = "$Revision: 1.4.0.2 $";
  2009. + #define VERSION \
  2010. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", PROGNAME, \
  2011. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  2012. + #define COPYING \
  2013. +   "This is free software, distributed under the terms of the\n" \
  2014. +   "GNU General Public License.  For details, see the file COPYING.\n"
  2015. + #endif /* MSDOS */
  2016.   
  2017.   /* If the macro MULTI_COL is defined,
  2018.      the multi-column format is the default regardless
  2019. ***************
  2020. *** 36,45 ****
  2021. --- 60,73 ----
  2022.   #ifdef _POSIX_SOURCE
  2023.   #define S_IEXEC S_IXUSR
  2024.   #else
  2025. + #ifndef MSDOS
  2026.   #include <sys/ioctl.h>
  2027. + #endif /* not MSDOS */
  2028.   #endif
  2029.   #include <stdio.h>
  2030. + #ifndef MSDOS
  2031.   #include <grp.h>
  2032. + #endif
  2033.   #include <pwd.h>
  2034.   #include <getopt.h>
  2035.   #include "system.h"
  2036. ***************
  2037. *** 65,70 ****
  2038. --- 93,150 ----
  2039.   extern int errno;
  2040.   #endif
  2041.   
  2042. + #ifdef MSDOS
  2043. + #include <string.h>
  2044. + #include <io.h>
  2045. + #include <gnulib.h>
  2046. + extern  int glob_match (char *, char *, int);
  2047. + extern  void mode_string (unsigned short mode, char *str);
  2048. + extern  void main (int, char **);
  2049. + extern  int argmatch (char *, char **);
  2050. + extern  int decode_switches (int, char **);
  2051. + extern  void invalid_arg (char *, char *, int);
  2052. + extern  void queue_directory (char *, char *);
  2053. + extern  void print_dir (char *, char *);
  2054. + extern  void add_ignore_pattern (char *);
  2055. + extern  int file_interesting (struct direct *);
  2056. + extern  void clear_files (void);
  2057. + extern  int gobble_file (char *, int, char *);
  2058. + extern  void extract_dirs_from_files (char *, int);
  2059. + extern  int is_not_dot_or_dotdot (char *);
  2060. + extern  void sort_files (void);
  2061. + extern  int compare_ctime (struct file *, struct file *);
  2062. + extern  int rev_cmp_ctime (struct file *, struct file *);
  2063. + extern  int compare_mtime (struct file *, struct file *);
  2064. + extern  int rev_cmp_mtime (struct file *, struct file *);
  2065. + extern  int compare_atime (struct file *, struct file *);
  2066. + extern  int rev_cmp_atime (struct file *, struct file *);
  2067. + extern  int compare_size (struct file *, struct file *);
  2068. + extern  int rev_cmp_size (struct file *, struct file *);
  2069. + extern  int compare_name (struct file *, struct file *);
  2070. + extern  int rev_cmp_name (struct file *, struct file *);
  2071. + extern  int compare_extension (struct file *file1, struct file *file2);
  2072. + extern  int rev_cmp_extension (struct file *file1, struct file *file2);
  2073. + extern  void print_current_files (void);
  2074. + extern  void print_long_format (struct file *);
  2075. + extern  void print_name_with_quoting (char *);
  2076. + extern  void print_file_name_and_frills (struct file *);
  2077. + extern  void print_type_indicator (unsigned int);
  2078. + extern  int length_of_file_name_and_frills (struct file *);
  2079. + extern  void print_many_per_line (void);
  2080. + extern  void print_horizontal (void);
  2081. + extern  void print_with_commas (void);
  2082. + extern  char *getuser (unsigned short);
  2083. + extern  char *getgroup (unsigned short);
  2084. + extern  void indent (int, int);
  2085. + extern  char *copystring (char *);
  2086. + extern  void attach (char *, char *, char *);
  2087. + extern  char *basename (char *);
  2088. + extern  void usage (void);
  2089. + #else /* not MSDOS */
  2090.   struct group *getgrgid ();
  2091.   struct passwd *getpwuid ();
  2092.   int glob_match ();
  2093. ***************
  2094. *** 114,119 ****
  2095. --- 194,201 ----
  2096.   void queue_directory ();
  2097.   void sort_files ();
  2098.   void usage ();
  2099. + #endif /* not MSDOS */
  2100.   
  2101.   enum filetype
  2102.   {
  2103. ***************
  2104. *** 376,383 ****
  2105. --- 458,484 ----
  2106.   
  2107.     if (i < argc)
  2108.       dir_defaulted = 0;
  2109. + #ifdef MSDOS
  2110. +   for (; i < argc; i++)
  2111. +     {
  2112. +       if (strlen (argv[i]) == 2 && argv[i][1] == ':')
  2113. +     {
  2114. +       /* The user wants the cwd on another drive.  Help
  2115. +          DOS by appending a `.'!  (This allows to stat()
  2116. +          the directory.)  */
  2117. +       char *temp = (char *) xmalloc (4);
  2118. +       strcpy (temp, argv[i]);
  2119. +       strcat (temp, ".");
  2120. +       argv[i] = temp;
  2121. +     }
  2122. +       gobble_file (argv[i], 1, "");
  2123. +     }
  2124. + #else /* not MSDOS */
  2125.     for (; i < argc; i++)
  2126.       gobble_file (argv[i], 1, "");
  2127. + #endif /* not MSDOS */
  2128.   
  2129.     if (dir_defaulted)
  2130.       {
  2131. ***************
  2132. *** 420,425 ****
  2133. --- 521,530 ----
  2134.   
  2135.   struct option long_options[] =
  2136.   {
  2137. + #ifdef MSDOS
  2138. +   {"copying", 0, NULL, 30},
  2139. +   {"version", 0, NULL, 31},
  2140. + #endif
  2141.     {"all", 0, 0, 'a'},
  2142.     {"escape", 0, 0, 'b'},
  2143.     {"directory", 0, 0, 'd'},
  2144. ***************
  2145. *** 726,732 ****
  2146.           }
  2147.         format = formats[longind];
  2148.         break;
  2149. !       
  2150.       default:
  2151.         usage ();
  2152.       }
  2153. --- 831,849 ----
  2154.           }
  2155.         format = formats[longind];
  2156.         break;
  2157. ! #ifdef MSDOS
  2158. !     case 30:
  2159. !       fprintf (stderr, COPYING);
  2160. !       exit (0);
  2161. !       break;
  2162. !     case 31:
  2163. !       fprintf (stderr, VERSION);
  2164. !       exit (0);
  2165. !       break;
  2166. ! #endif
  2167.       default:
  2168.         usage ();
  2169.       }
  2170. ***************
  2171. *** 989,998 ****
  2172. --- 1106,1117 ----
  2173.                      kilobyte_blocks);
  2174.         if (blocks >= 10000 && block_size_size < 5)
  2175.       block_size_size = 5;
  2176. + #ifndef MSDOS
  2177.         if (blocks >= 100000 && block_size_size < 6)
  2178.       block_size_size = 6;
  2179.         if (blocks >= 1000000 && block_size_size < 7)
  2180.       block_size_size = 7;
  2181. + #endif /* not MSDOS */
  2182.       }
  2183.     else
  2184.       blocks = 0;
  2185. ***************
  2186. *** 1380,1387 ****
  2187. --- 1499,1510 ----
  2188.     else
  2189.       printf ("%-8.8s ", getgroup (f->stat.st_gid));
  2190.   
  2191. + #ifdef S_IFBLK
  2192.     if ((f->stat.st_mode & S_IFMT) == S_IFCHR
  2193.         || (f->stat.st_mode & S_IFMT) == S_IFBLK)
  2194. + #else /* not S_IFBLK */
  2195. +   if ((f->stat.st_mode & S_IFMT) == S_IFCHR)
  2196. + #endif /* not S_IFBLK */
  2197.       printf ("%3u, %3u ", major (f->stat.st_rdev), minor (f->stat.st_rdev));
  2198.     else
  2199.       printf ("%8lu ", f->stat.st_size);
  2200. ***************
  2201. *** 1769,1774 ****
  2202. --- 1892,1898 ----
  2203.         return tail->name;
  2204.   
  2205.     pwent = getpwuid (uid);
  2206.     tail = (struct userid *) xmalloc (sizeof (struct userid));
  2207.     tail->uid = uid;
  2208.     tail->next = user_alist;
  2209. ***************
  2210. *** 1839,1844 ****
  2211. --- 1963,1970 ----
  2212.   /* Low level subroutines of general use,
  2213.      not specifically related to the task of listing a directory.  */
  2214.   
  2215. + #ifndef MSDOS
  2216.   char *
  2217.   xrealloc (obj, size)
  2218.        char *obj;
  2219. ***************
  2220. *** 1864,1869 ****
  2221. --- 1990,1997 ----
  2222.     return val;
  2223.   }
  2224.   
  2225. + #endif /* MSDOS */
  2226.   /* Return a newly allocated copy of `string'. */
  2227.   
  2228.   char *
  2229. ***************
  2230. *** 1904,1913 ****
  2231. --- 2032,2050 ----
  2232.          [+numeric-uid-gid] [+hide-control-chars] [+reverse] [+size]\n\
  2233.          [+width cols] [+tabsize cols] [+almost-all] [+ignore-backups]\n",
  2234.          program_name);
  2235. + #ifdef MSDOS
  2236. +   fprintf (stderr, "\
  2237. +        [+classify] [+file-type] [+ignore pattern] [+dereference] [+literal]\n\
  2238. +        [+quote-name] [+recursive] [+sort {none,time,size,extension}]\n\
  2239. +        [+format {long,verbose,commas,across,vertical,single-column}]\n\
  2240. +        [+time {atime,access,use,ctime,status}] [+copying] [+version]\n\
  2241. +        [path...]\n");
  2242. + #else /* not MSDOS */
  2243.     fprintf (stderr, "\
  2244.          [+classify] [+file-type] [+ignore pattern] [+dereference] [+literal]\n\
  2245.          [+quote-name] [+recursive] [+sort {none,time,size,extension}]\n\
  2246.          [+format {long,verbose,commas,across,vertical,single-column}]\n\
  2247.          [+time {atime,access,use,ctime,status}] [path...]\n");
  2248. + #endif /* not MSDOS */
  2249.     exit (1);
  2250.   }
  2251. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:28 1990
  2252. --- mkdir.c    Wed Sep 19 12:45:00 1990
  2253. ***************
  2254. *** 14,20 ****
  2255. --- 14,44 ----
  2256.      You should have received a copy of the GNU General Public License
  2257.      along with this program; if not, write to the Free Software
  2258.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  2259. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  2260. +    This port is also distributed under the terms of the
  2261. +    GNU General Public License as published by the
  2262. +    Free Software Foundation.
  2263.   
  2264. +    Please note that this file is not identical to the
  2265. +    original GNU release, you should have received this
  2266. +    code as patch to the official release.  */
  2267. + #ifdef MSDOS
  2268. + static char RCS_Id[] =
  2269. +   "$Header: e:/gnu/fileutil/RCS/mkdir.c 1.4.0.2 90/09/19 12:10:16 tho Exp $";
  2270. + static char Program_Id[] = "mkdir";
  2271. + static char RCS_Revision[] = "$Revision: 1.4.0.2 $";
  2272. + #define VERSION \
  2273. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  2274. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  2275. + #define COPYING \
  2276. +   "This is free software, distributed under the terms of the\n" \
  2277. +   "GNU General Public License.  For details, see the file COPYING.\n"
  2278. + #endif /* MSDOS */
  2279.   /* Usage: mkdir [-p] [-m mode] [+path] [+mode mode] dir...
  2280.   
  2281.      Options:
  2282. ***************
  2283. *** 42,52 ****
  2284. --- 66,94 ----
  2285.   extern int errno;
  2286.   #endif
  2287.   
  2288. + #ifdef MSDOS
  2289. + #include <direct.h>
  2290. + #include <io.h>
  2291. + #include <gnulib.h>
  2292. + extern void main (int argc, char **argv);
  2293. + static int make_path (char *path, unsigned short mode,\
  2294. +               unsigned short parent_mode);
  2295. + static void strip_trailing_slashes (char *path);
  2296. + static void usage (void);
  2297. + #define mkdir(path, mode)    mkdir (path)
  2298. + #else /* not MSDOS */
  2299.   int make_path ();
  2300.   void error ();
  2301.   void strip_trailing_slashes ();
  2302.   void usage ();
  2303.   
  2304. + #endif /* not MSDOS */
  2305.   /* If nonzero, ensure that a path exists.  */
  2306.   int path_mode;
  2307.   
  2308. ***************
  2309. *** 55,60 ****
  2310. --- 97,106 ----
  2311.   
  2312.   struct option longopts[] =
  2313.   {
  2314. + #ifdef MSDOS
  2315. +   {"copying", 0, NULL, 30},
  2316. +   {"version", 0, NULL, 31},
  2317. + #endif
  2318.     {"mode", 1, NULL, 'm'},
  2319.     {"path", 0, &path_mode, 1},
  2320.     {NULL, 0, NULL, 0}
  2321. ***************
  2322. *** 89,94 ****
  2323. --- 135,150 ----
  2324.       case 'm':
  2325.         symbolic_mode = optarg;
  2326.         break;
  2327. + #ifdef MSDOS
  2328. +     case 30:
  2329. +       fprintf (stderr, COPYING);
  2330. +       exit (0);
  2331. +       break;
  2332. +     case 31:
  2333. +       fprintf (stderr, VERSION);
  2334. +       exit (0);
  2335. +       break;
  2336. + #endif
  2337.       default:
  2338.         usage ();
  2339.       }
  2340. ***************
  2341. *** 198,206 ****
  2342.   void
  2343.   usage ()
  2344.   {
  2345.     fprintf (stderr, "\
  2346.   Usage: %s [-p] [-m mode] [+path] [+mode mode] dir...\n",
  2347.          program_name);
  2348.     exit (1);
  2349.   }
  2350. --- 254,267 ----
  2351.   void
  2352.   usage ()
  2353.   {
  2354. + #ifdef MSDOS
  2355. +   fprintf (stderr, "\
  2356. + Usage: %s [-p] [-m mode] [+path] [+mode mode] [+copying] \n\
  2357. +        [+version] dir...\n", program_name);
  2358. + #else
  2359.     fprintf (stderr, "\
  2360.   Usage: %s [-p] [-m mode] [+path] [+mode mode] dir...\n",
  2361.          program_name);
  2362. + #endif
  2363.     exit (1);
  2364.   }
  2365. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:30 1990
  2366. --- modechan.c    Wed Sep 19 12:33:30 1990
  2367. ***************
  2368. *** 15,20 ****
  2369. --- 15,32 ----
  2370.      along with this program; if not, write to the Free Software
  2371.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  2372.   
  2373. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  2374. +    This port is also distributed under the terms of the
  2375. +    GNU General Public License as published by the
  2376. +    Free Software Foundation.
  2377. +    Please note that this file is not identical to the
  2378. +    original GNU release, you should have received this
  2379. +    code as patch to the official release.
  2380. +    $Header: e:/gnu/fileutil/RCS/modechan.c 1.4.0.1 90/09/17 09:27:41 tho Exp $
  2381. +  */
  2382.   /* Written by David MacKenzie <djm@ai.mit.edu> */
  2383.   
  2384.   /* The ASCII mode string is compiled into a linked list of `struct
  2385. ***************
  2386. *** 27,32 ****
  2387. --- 39,50 ----
  2388.   #include <sys/types.h>
  2389.   #include <sys/stat.h>
  2390.   #include "modechange.h"
  2391. + #ifdef MSDOS
  2392. + #include <stdio.h>
  2393. + #include <io.h>
  2394. + static int oatoi (char *s);
  2395. + #endif
  2396.   
  2397.   #ifdef STDC_HEADERS
  2398.   #include <stdlib.h>
  2399. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:40 1990
  2400. --- mv.c    Wed Sep 19 12:45:40 1990
  2401. ***************
  2402. *** 14,20 ****
  2403. --- 14,44 ----
  2404.      You should have received a copy of the GNU General Public License
  2405.      along with this program; if not, write to the Free Software
  2406.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  2407. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  2408. +    This port is also distributed under the terms of the
  2409. +    GNU General Public License as published by the
  2410. +    Free Software Foundation.
  2411.   
  2412. +    Please note that this file is not identical to the
  2413. +    original GNU release, you should have received this
  2414. +    code as patch to the official release.  */
  2415. + #ifdef MSDOS
  2416. + static char RCS_Id[] =
  2417. +   "$Header: e:/gnu/fileutil/RCS/mv.c 1.4.0.2 90/09/19 12:11:15 tho Exp $";
  2418. + static char Program_Id[] = "mv";
  2419. + static char RCS_Revision[] = "$Revision: 1.4.0.2 $";
  2420. + #define VERSION \
  2421. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  2422. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  2423. + #define COPYING \
  2424. +   "This is free software, distributed under the terms of the\n" \
  2425. +   "GNU General Public License.  For details, see the file COPYING.\n"
  2426. + #endif /* MSDOS */
  2427.   /* Options:
  2428.      -f, +force        Assume a 'y' answer to all questions it would
  2429.               normally ask, and not ask the questions.
  2430. ***************
  2431. *** 52,57 ****
  2432. --- 76,105 ----
  2433.   extern int errno;
  2434.   #endif
  2435.   
  2436. + #ifdef MSDOS
  2437. + #include <io.h>
  2438. + #include <gnulib.h>
  2439. + extern  void main (int argc, char **argv);
  2440. + extern  void error (int status, int errnum, char *message, ...);
  2441. + extern  int eaccess_stat (struct stat *statp, int mode);
  2442. + extern  enum backup_type get_version (char *version);
  2443. + static  int isdir (char *fn);
  2444. + static  int movefile (char *from, char *to);
  2445. + static  int do_move (char *from, char *to);
  2446. + static  int copy (char *from, char *to);
  2447. + static  int yesno (void );
  2448. + static  void strip_trailing_slashes (char **path);
  2449. + static  int force_unlink (char *filename);
  2450. + static  void usage (void );
  2451. + #define unlink(name)        force_unlink (name)
  2452. + #define rename(from, to)    (unlink (to) || rename (from, to))
  2453. + #define strip_trailing_slashes(path)    strip_trailing_slashes (&path)
  2454. + #else /* not MSDOS */
  2455.   enum backup_type get_version ();
  2456.   int copy ();
  2457.   int do_move ();
  2458. ***************
  2459. *** 62,67 ****
  2460. --- 110,117 ----
  2461.   void strip_trailing_slashes ();
  2462.   void usage ();
  2463.   
  2464. + #endif /* not MSDOS */
  2465.   /* The name this program was run with. */
  2466.   char *program_name;
  2467.   
  2468. ***************
  2469. *** 77,82 ****
  2470. --- 127,136 ----
  2471.   
  2472.   struct option long_options[] =
  2473.   {
  2474. + #ifdef MSDOS
  2475. +   {"copying", 0, NULL, 30},
  2476. +   {"version", 0, NULL, 31},
  2477. + #endif
  2478.     {"backup", 0, NULL, 'b'},
  2479.     {"force", 0, NULL, 'f'},
  2480.     {"interactive", 0, NULL, 'i'},
  2481. ***************
  2482. *** 134,139 ****
  2483. --- 188,203 ----
  2484.       case 'V':
  2485.         version = optarg;
  2486.         break;
  2487. + #ifdef MSDOS
  2488. +     case 30:
  2489. +       fprintf (stderr, COPYING);
  2490. +       exit (0);
  2491. +       break;
  2492. +     case 31:
  2493. +       fprintf (stderr, VERSION);
  2494. +       exit (0);
  2495. +       break;
  2496. + #endif
  2497.       default:
  2498.         usage ();
  2499.       }
  2500. ***************
  2501. *** 178,183 ****
  2502. --- 242,254 ----
  2503.       cp = from;
  2504.   
  2505.         newto = (char *) alloca (strlen (to) + 1 + strlen (cp) + 1);
  2506. + #ifdef MSDOS
  2507. +       /* Here a trailing slash might still be present (needed for
  2508. +      stat()'ing root directories), take care of that. */
  2509. +       if (to[strlen(to) - 1] == '/')
  2510. +     sprintf (newto, "%s%s", to, cp);
  2511. +       else
  2512. + #endif /* MSDOS */
  2513.         sprintf (newto, "%s/%s", to, cp);
  2514.         return do_move (from, newto);
  2515.       }
  2516. ***************
  2517. *** 206,211 ****
  2518. --- 277,289 ----
  2519.   
  2520.     if (lstat (to, &to_stats) == 0)
  2521.       {
  2522. + #ifdef MSDOS
  2523. +       if (strcmp (to, from) == 0)
  2524. +     {
  2525. +       error (0, 0, "`%s': can't move file to itself", from);
  2526. +       return 1;
  2527. +     }
  2528. + #else /* not MSDOS */
  2529.         if (from_stats.st_dev == to_stats.st_dev
  2530.         && from_stats.st_ino == to_stats.st_ino)
  2531.       {
  2532. ***************
  2533. *** 212,217 ****
  2534. --- 290,296 ----
  2535.         error (0, 0, "`%s' and `%s' are the same file", from, to);
  2536.         return 1;
  2537.       }
  2538. + #endif /* not MSDOS */
  2539.   
  2540.         if ((to_stats.st_mode & S_IFMT) == S_IFDIR)
  2541.       {
  2542. ***************
  2543. *** 324,336 ****
  2544. --- 403,424 ----
  2545.         return 1;
  2546.       }
  2547.   
  2548. + #ifdef MSDOS
  2549. +   ifd = open (from, O_RDONLY | O_BINARY, 0);
  2550. + #else /* not MSDOS */
  2551.     ifd = open (from, O_RDONLY, 0);
  2552. + #endif /* not MSDOS */
  2553.     if (ifd < 0)
  2554.       {
  2555.         error (0, errno, "%s", from);
  2556.         return 1;
  2557.       }
  2558. + #ifdef MSDOS
  2559. +   ofd = open (to, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0777);
  2560. + #else /* not MSDOS */
  2561.     ofd = open (to, O_WRONLY | O_CREAT | O_TRUNC, 0777);
  2562. + #endif /* not MSDOS */
  2563.     if (ofd < 0)
  2564.       {
  2565.         error (0, errno, "%s", to);
  2566. ***************
  2567. *** 431,436 ****
  2568. --- 519,538 ----
  2569.   
  2570.   /* Remove trailing slashes from PATH. */
  2571.   
  2572. + #ifdef MSDOS
  2573. + #undef strip_trailing_slashes
  2574. + void
  2575. + strip_trailing_slashes (char **path)
  2576. + {
  2577. +   char *new_path = _fullpath (NULL, *path, 0);
  2578. +   free (*path);
  2579. +   *path = msdos_format_filename (new_path);
  2580. + }
  2581. + #else /* not MSDOS */
  2582.   void
  2583.   strip_trailing_slashes (path)
  2584.        char *path;
  2585. ***************
  2586. *** 442,450 ****
  2587. --- 544,567 ----
  2588.       path[last--] = '\0';
  2589.   }
  2590.   
  2591. + #endif /* not MSDOS */
  2592.   void
  2593.   usage ()
  2594.   {
  2595. + #ifdef MSDOS
  2596. +   fprintf (stderr, "\
  2597. + Usage: %s [-bfiuv] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  2598. +        [+backup] [+force] [+interactive] [+update] [+verbose]\n\
  2599. +        [+suffix backup-suffix] [+version-control {numbered,existing,simple}]\n\
  2600. +        [+copying] [+version] source dest\n\
  2601. + \n\
  2602. +        %s [-bfiuv] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  2603. +        [+backup] [+force] [+interactive] [+update] [+verbose]\n\
  2604. +        [+suffix backup-suffix] [+version-control {numbered,existing,simple}]\n\
  2605. +        [+copying] [+version] source... directory\n",
  2606. +        program_name, program_name);
  2607. + #else /* not MSDOS */
  2608.     fprintf (stderr, "\
  2609.   Usage: %s [-bfiuv] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  2610.          [+backup] [+force] [+interactive] [+update] [+verbose]\n\
  2611. ***************
  2612. *** 456,460 ****
  2613. --- 573,600 ----
  2614.          [+suffix backup-suffix] [+version-control {numbered,existing,simple}]\n\
  2615.          source... directory\n",
  2616.          program_name, program_name);
  2617. + #endif /* not MSDOS */
  2618.     exit (1);
  2619.   }
  2620. + #ifdef MSDOS
  2621. + #undef unlink                    /* nasty tricks ... */
  2622. + int
  2623. + force_unlink (char *filename)
  2624. + {
  2625. +   if (access (filename, 0))    /* file doesn't exist, pretend success */
  2626. +     return 0;
  2627. +   else
  2628. +     {
  2629. +       if (access (filename, 2)              /* no write permission */
  2630. +       && chmod (filename, S_IREAD|S_IWRITE))  /* can't force it ...  */
  2631. +     {
  2632. +       error (0, errno, "can't force write permission for %s", filename);
  2633. +       return -1;
  2634. +     }
  2635. +       else
  2636. +     return unlink (filename);
  2637. +     }
  2638. + }
  2639. + #endif /* MSDOS */
  2640. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:42 1990
  2641. --- paste.c    Wed Sep 19 12:46:38 1990
  2642. ***************
  2643. *** 40,46 ****
  2644. --- 40,70 ----
  2645.                   start again at its beginning.
  2646.      A FILE of `-' means standard input.
  2647.      If no FILEs are given, standard input is used. */
  2648. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  2649. +    This port is also distributed under the terms of the
  2650. +    GNU General Public License as published by the
  2651. +    Free Software Foundation.
  2652.   
  2653. +    Please note that this file is not identical to the
  2654. +    original GNU release, you should have received this
  2655. +    code as patch to the official release.  */
  2656. + #ifdef MSDOS
  2657. + static char RCS_Id[] =
  2658. +   "$Header: e:/gnu/fileutil/RCS/paste.c 1.4.0.3 90/09/19 12:11:19 tho Exp $";
  2659. + static char Program_Id[] = "paste";
  2660. + static char RCS_Revision[] = "$Revision: 1.4.0.3 $";
  2661. + #define VERSION \
  2662. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  2663. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  2664. + #define COPYING \
  2665. +   "This is free software, distributed under the terms of the\n" \
  2666. +   "GNU General Public License.  For details, see the file COPYING.\n"
  2667. + #endif /* MSDOS */
  2668.   #include <stdio.h>
  2669.   #include <errno.h>
  2670.   #include <getopt.h>
  2671. ***************
  2672. *** 57,62 ****
  2673. --- 81,98 ----
  2674.   extern int errno;
  2675.   #endif
  2676.   
  2677. + #ifdef MSDOS
  2678. + #include <gnulib.h>
  2679. + void main (int argc, char **argv);
  2680. + char *collapse_escapes (char *strptr);
  2681. + int paste_parallel (int nfiles, char **fnamptr);
  2682. + int paste_serial (int nfiles, char **fnamptr);
  2683. + void usage (void);
  2684. + #else /* not MSDOS */
  2685.   char *collapse_escapes ();
  2686.   char *xmalloc ();
  2687.   char *xrealloc ();
  2688. ***************
  2689. *** 65,70 ****
  2690. --- 101,109 ----
  2691.   void error ();
  2692.   void usage ();
  2693.   
  2694. + #endif /* not MSDOS */
  2695.   /* Indicates that no delimiter should be added in the current position. */
  2696.   #define EMPTY_DELIM '\0'
  2697.   
  2698. ***************
  2699. *** 89,94 ****
  2700. --- 128,137 ----
  2701.   
  2702.   struct option longopts[] =
  2703.   {
  2704. + #ifdef MSDOS
  2705. +   {"copying", 0, NULL, 30},
  2706. +   {"version", 0, NULL, 31},
  2707. + #endif
  2708.     {"serial", 0, 0, 's'},
  2709.     {"delimiters", 1, 0, 'd'},
  2710.     {0, 0, 0, 0}
  2711. ***************
  2712. *** 124,129 ****
  2713. --- 167,184 ----
  2714.         serial_merge++;
  2715.         break;
  2716.   
  2717. + #ifdef MSDOS
  2718. +     case 30:
  2719. +       fprintf (stderr, COPYING);
  2720. +       exit (0);
  2721. +       break;
  2722. +     case 31:
  2723. +       fprintf (stderr, VERSION);
  2724. +       exit (0);
  2725. +       break;
  2726. + #endif
  2727.       default:
  2728.         usage ();
  2729.       }
  2730. ***************
  2731. *** 438,443 ****
  2732. --- 493,500 ----
  2733.     return errors;
  2734.   }
  2735.   
  2736. + #ifndef MSDOS            /* We have it in gnulib  */
  2737.   /* Allocate N bytes of memory dynamically, with error checking.  */
  2738.   
  2739.   char *
  2740. ***************
  2741. *** 463,474 ****
  2742. --- 520,540 ----
  2743.     return p;
  2744.   }
  2745.   
  2746. + #endif /* not MSDOS */
  2747.   void
  2748.   usage ()
  2749.   {
  2750. + #ifdef MSDOS
  2751. +   fprintf (stderr, "\
  2752. + Usage: %s [-s] [-d delim-list] [+serial] [+delimiters delim-list]\n\
  2753. +        [+copying] [+version] [file...]\n",
  2754. + #else /* not MSDOS */
  2755.     fprintf (stderr, "\
  2756.   Usage: %s [-s] [-d delim-list] [+serial] [+delimiters delim-list]\n\
  2757.          [file...]\n",
  2758. + #endif /* not MSDOS */
  2759.          program_name);
  2760.     exit (1);
  2761.   }
  2762. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:44 1990
  2763. --- posixtim.y    Wed Sep 19 12:54:42 1990
  2764. ***************
  2765. *** 17,25 ****
  2766. --- 17,39 ----
  2767.   
  2768.   /* Written by Jim Kingdon and David MacKenzie. */
  2769.   
  2770. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  2771. +    This port is also distributed under the terms of the
  2772. +    GNU General Public License as published by the
  2773. +    Free Software Foundation.
  2774. +    Please note that this file is not identical to the
  2775. +    original GNU release, you should have received this
  2776. +    code as patch to the official release.  */
  2777.   %token digit
  2778.   
  2779.   %{
  2780. + #ifdef MSDOS
  2781. + static char RCS_Id[] =
  2782. +   "$Header: e:/gnu/fileutil/RCS/posixtim.y 1.4.0.2 90/09/19 12:54:32 tho Exp $";
  2783. + #endif /* MSDOS */
  2784.   #include <stdio.h>
  2785.   #include <sys/types.h>
  2786.   #include <time.h>
  2787. ***************
  2788. *** 41,49 ****
  2789.   
  2790.   time_t mktime ();
  2791.   
  2792.   static int yylex ();
  2793. - #define yyparse posixtime_yyparse
  2794.   static int yyerror ();
  2795.   %}
  2796.   
  2797.   %%
  2798. --- 55,70 ----
  2799.   
  2800.   time_t mktime ();
  2801.   
  2802. + #ifdef MSDOS
  2803. + #include <malloc.h>
  2804. + static int yyerror (void);
  2805. + static int yylex (void);
  2806. + #else /* not MSDOS */
  2807.   static int yylex ();
  2808.   static int yyerror ();
  2809. + #endif /* not MSDOS */
  2810. + #define yyparse posixtime_yyparse
  2811.   %}
  2812.   
  2813.   %%
  2814. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:46 1990
  2815. --- rm.c    Wed Sep 19 12:47:36 1990
  2816. ***************
  2817. *** 17,22 ****
  2818. --- 17,47 ----
  2819.   
  2820.   /* Written by Paul Rubin, David MacKenzie, and Richard Stallman. */
  2821.   
  2822. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  2823. +    This port is also distributed under the terms of the
  2824. +    GNU General Public License as published by the
  2825. +    Free Software Foundation.
  2826. +    Please note that this file is not identical to the
  2827. +    original GNU release, you should have received this
  2828. +    code as patch to the official release.  */
  2829. + #ifdef MSDOS
  2830. + static char RCS_Id[] =
  2831. +   "$Header: e:/gnu/fileutil/RCS/rm.c 1.4.0.3 90/09/20 08:46:14 tho Exp $";
  2832. + static char Program_Id[] = "rm";
  2833. + static char RCS_Revision[] = "$Revision: 1.4.0.3 $";
  2834. + #define VERSION \
  2835. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  2836. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  2837. + #define COPYING \
  2838. +   "This is free software, distributed under the terms of the\n" \
  2839. +   "GNU General Public License.  For details, see the file COPYING.\n"
  2840. + #endif /* MSDOS */
  2841.   #include <stdio.h>
  2842.   #include <getopt.h>
  2843.   #include <sys/types.h>
  2844. ***************
  2845. *** 32,37 ****
  2846. --- 57,91 ----
  2847.   extern int errno;
  2848.   #endif
  2849.   
  2850. + #ifdef MSDOS
  2851. + #include <string.h>
  2852. + #include <malloc.h>
  2853. + #include <io.h>
  2854. + #include <direct.h>
  2855. + #include <gnulib.h>
  2856. + extern  void main (int argc, char **argv);
  2857. + static  int rm (void);
  2858. + static  int remove_file (struct stat *statp);
  2859. + static  int remove_dir (struct stat *statp);
  2860. + static  int clear_directory (struct stat *statp);
  2861. + static  int yesno (void);
  2862. + static  char *basename (char *name);
  2863. + static  char *stpcpy (char *dest, char *source);
  2864. + static  void usage (void);
  2865. + extern  int eaccess (char *path, int mode);
  2866. + extern  int eaccess_stat (struct stat *statp, int mode);
  2867. + static  void strip_trailing_slashes (char **path);
  2868. + #define strip_trailing_slashes(path)    strip_trailing_slashes (&path)
  2869. + #define check_stack(stck, ino)        0
  2870. + #define unlink(name)            force_unlink (name)
  2871. + static int force_unlink (char *filename);
  2872. + #else /* not MSDOS */
  2873.   char *basename ();
  2874.   char *stpcpy ();
  2875.   char *xmalloc ();
  2876. ***************
  2877. *** 47,52 ****
  2878. --- 101,109 ----
  2879.   void strip_trailing_slashes ();
  2880.   void usage ();
  2881.   
  2882. + #endif /* not MSDOS */
  2883.   /* Path of file now being processed; extended as necessary. */
  2884.   char *pathname;
  2885.   
  2886. ***************
  2887. *** 80,85 ****
  2888. --- 137,146 ----
  2889.   
  2890.   struct option long_opts[] =
  2891.   {
  2892. + #ifdef MSDOS
  2893. +   {"copying", 0, NULL, 30},
  2894. +   {"version", 0, NULL, 31},
  2895. + #endif
  2896.     {"directory", 0, &unlink_dirs, 1},
  2897.     {"force", 0, NULL, 'f'},
  2898.     {"interactive", 0, NULL, 'i'},
  2899. ***************
  2900. *** 101,108 ****
  2901.     verbose = ignore_missing_files = recursive = interactive
  2902.       = unlink_dirs = 0;
  2903.     pnsize = 256;
  2904. -   pathname = xmalloc (pnsize);
  2905.     program_name = argv[0];
  2906.   
  2907.     while ((c = getopt_long (argc, argv, "dfirvR", long_opts, &ind)) != EOF)
  2908.       {
  2909. --- 162,169 ----
  2910.     verbose = ignore_missing_files = recursive = interactive
  2911.       = unlink_dirs = 0;
  2912.     pnsize = 256;
  2913.     program_name = argv[0];
  2914. +   pathname = xmalloc (pnsize);
  2915.   
  2916.     while ((c = getopt_long (argc, argv, "dfirvR", long_opts, &ind)) != EOF)
  2917.       {
  2918. ***************
  2919. *** 128,133 ****
  2920. --- 189,204 ----
  2921.       case 'v':
  2922.         verbose = 1;
  2923.         break;
  2924. + #ifdef MSDOS
  2925. +     case 30:
  2926. +       fprintf (stderr, COPYING);
  2927. +       exit (0);
  2928. +       break;
  2929. +     case 31:
  2930. +       fprintf (stderr, VERSION);
  2931. +       exit (0);
  2932. +       break;
  2933. + #endif
  2934.       default:
  2935.         usage ();
  2936.       }
  2937. ***************
  2938. *** 136,141 ****
  2939. --- 207,213 ----
  2940.     if (optind == argc)
  2941.       usage ();
  2942.   
  2943. + #ifndef MSDOS            /* this fails at the root ... */
  2944.     if (lstat (".", &stats))
  2945.       error (1, errno, ".");
  2946.     dot_dev = stats.st_dev;
  2947. ***************
  2948. *** 144,149 ****
  2949. --- 216,222 ----
  2950.       error (1, errno, "..");
  2951.     dotdot_dev = stats.st_dev;
  2952.     dotdot_ino = stats.st_ino;
  2953. + #endif /* not MSDOS */
  2954.   
  2955.     for (; optind < argc; optind++)
  2956.       {
  2957. ***************
  2958. *** 180,185 ****
  2959. --- 253,259 ----
  2960.         return 1;
  2961.       }
  2962.   
  2963. + #ifndef MSDOS
  2964.     if ((path_stats.st_dev == dot_dev && path_stats.st_ino == dot_ino)
  2965.         || (path_stats.st_dev == dotdot_dev && path_stats.st_ino == dotdot_ino))
  2966.       {
  2967. ***************
  2968. *** 186,191 ****
  2969. --- 260,266 ----
  2970.         error (0, 0, "%s: cannot remove current directory or parent", pathname);
  2971.         return 1;
  2972.       }
  2973. + #endif /* not MSDOS */
  2974.   
  2975.     if ((path_stats.st_mode & S_IFMT) == S_IFDIR && !unlink_dirs)
  2976.       return remove_dir (&path_stats);
  2977. ***************
  2978. *** 329,341 ****
  2979. --- 404,425 ----
  2980.         return 1;
  2981.       }
  2982.   
  2983. + #ifdef MSDOS                /* stat () it ourselves ... */
  2984. +   statp->st_size = 0L;
  2985. +   for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp))
  2986. +     statp->st_size += strlen(dp->d_name) + 1;
  2987. +   seekdir(dirp, 0L);
  2988. + #endif /* MSDOS */
  2989.     name_size = statp->st_size;
  2990.     name_space = (char *) xmalloc (name_size);
  2991.     namep = name_space;
  2992.   
  2993. + #ifndef MSDOS
  2994.     inode_size = statp->st_size;
  2995.     inode_space = (ino_t *) xmalloc (inode_size);
  2996.     inodep = inode_space;
  2997. + #endif /* not MSDOS */
  2998.   
  2999.     while ((dp = readdir (dirp)) != NULL)
  3000.       {
  3001. ***************
  3002. *** 359,364 ****
  3003. --- 443,449 ----
  3004.           }
  3005.         namep = stpcpy (namep, dp->d_name) + 1;
  3006.   
  3007. + #ifndef MSDOS
  3008.         if (inodep == inode_space + inode_size)
  3009.           {
  3010.             ino_t *new_inode_space;
  3011. ***************
  3012. *** 369,374 ****
  3013. --- 454,460 ----
  3014.             inode_space = new_inode_space;
  3015.           }
  3016.         *inodep++ = dp->d_ino;
  3017. + #endif /* not MSDOS */
  3018.       }
  3019.       }
  3020.     *namep = '\0';
  3021. ***************
  3022. *** 415,424 ****
  3023. --- 501,513 ----
  3024.         pathstack = pathstack->next;    /* Pop the stack. */
  3025.       }
  3026.     free (name_space);
  3027. + #ifndef MSDOS
  3028.     free (inode_space);
  3029. + #endif /* not MSDOS */
  3030.     return err;
  3031.   }
  3032.   
  3033. + #ifndef MSDOS
  3034.   /* If STACK does not already have an entry with the same i-number as INUM,
  3035.      return 0. Otherwise, ask the user whether to continue;
  3036.      if yes, return 1, and if no, exit.
  3037. ***************
  3038. *** 455,460 ****
  3039. --- 544,550 ----
  3040.       }
  3041.     return 0;
  3042.   }
  3043. + #endif /* !MSDOS */
  3044.   
  3045.   /* Query the user for a line from the keyboard;
  3046.      return 1 if yes, 0 otherwise. */
  3047. ***************
  3048. *** 476,482 ****
  3049. --- 566,585 ----
  3050.   
  3051.   /* Remove trailing slashes from PATH; they cause some system calls to fail. */
  3052.   
  3053. + #ifdef MSDOS
  3054. + #undef strip_trailing_slashes
  3055.   void
  3056. + strip_trailing_slashes (char **path)
  3057. + {
  3058. +   char *new_path = _fullpath (NULL, *path, 0);
  3059. +   free (*path);
  3060. +   *path = msdos_format_filename (new_path);
  3061. + }
  3062. + #else /* not MSDOS */
  3063. + void
  3064.   strip_trailing_slashes (path)
  3065.        char *path;
  3066.   {
  3067. ***************
  3068. *** 510,515 ****
  3069. --- 613,620 ----
  3070.     return p;
  3071.   }
  3072.   
  3073. + #endif /* not MSDOS */
  3074.   /* Return NAME with any leading path stripped off.  */
  3075.   
  3076.   char *
  3077. ***************
  3078. *** 539,547 ****
  3079. --- 644,671 ----
  3080.   void
  3081.   usage ()
  3082.   {
  3083. + #ifdef MSDOS
  3084. +   fprintf (stderr, "\
  3085. + Usage: %s [-dfirvR] [+directory] [+force] [+interactive] [+recursive]\n\
  3086. +        [+verbose] [+copying] [+version] path...\n",
  3087. + #else /* not MSDOS */
  3088.     fprintf (stderr, "\
  3089.   Usage: %s [-dfirvR] [+directory] [+force] [+interactive] [+recursive]\n\
  3090.          [+verbose] path...\n",
  3091. + #endif /* not MSDOS */
  3092.          program_name);
  3093.     exit (1);
  3094.   }
  3095. + #ifdef MSDOS
  3096. + int
  3097. + force_unlink(char *filename)
  3098. + {
  3099. +   if (access( filename, 2))            /* read only */
  3100. +     if (chmod( filename, S_IREAD|S_IWRITE))
  3101. +       error (0, errno, "can't force write permission for %s", filename);
  3102. + #undef unlink                    /* nasty tricks ... */
  3103. +   return unlink (filename);
  3104. + }
  3105. + #endif /* MSDOS */
  3106. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:50 1990
  3107. --- rmdir.c    Wed Sep 19 12:48:32 1990
  3108. ***************
  3109. *** 15,20 ****
  3110. --- 15,45 ----
  3111.      along with this program; if not, write to the Free Software
  3112.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  3113.   
  3114. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  3115. +    This port is also distributed under the terms of the
  3116. +    GNU General Public License as published by the
  3117. +    Free Software Foundation.
  3118. +    Please note that this file is not identical to the
  3119. +    original GNU release, you should have received this
  3120. +    code as patch to the official release.  */
  3121. + #ifdef MSDOS
  3122. + static char RCS_Id[] =
  3123. +   "$Header: e:/gnu/fileutil/RCS/rmdir.c 1.4.0.2 90/09/19 12:09:14 tho Exp $";
  3124. + static char Program_Id[] = "rmdir";
  3125. + static char RCS_Revision[] = "$Revision: 1.4.0.2 $";
  3126. + #define VERSION \
  3127. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  3128. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  3129. + #define COPYING \
  3130. +   "This is free software, distributed under the terms of the\n" \
  3131. +   "GNU General Public License.  For details, see the file COPYING.\n"
  3132. + #endif /* MSDOS */
  3133.   /* Usage: rmdir [-p] [+path] dir...
  3134.   
  3135.      Options:
  3136. ***************
  3137. *** 36,46 ****
  3138. --- 61,85 ----
  3139.   extern int errno;
  3140.   #endif
  3141.   
  3142. + #ifdef MSDOS
  3143. + #include <direct.h>
  3144. + #include <gnulib.h>
  3145. + extern void main (int argc, char * *argv);
  3146. + static void remove_parents (char *path);
  3147. + static void strip_trailing_slashes (char *path);
  3148. + static void usage (void);
  3149. + #else /* not MSDOS */
  3150.   void remove_parents ();
  3151.   void error ();
  3152.   void strip_trailing_slashes ();
  3153.   void usage ();
  3154.   
  3155. + #endif /* not MSDOS */
  3156.   /* If nonzero, remove empty parent directories. */
  3157.   int empty_paths;
  3158.   
  3159. ***************
  3160. *** 49,54 ****
  3161. --- 88,97 ----
  3162.   
  3163.   struct option longopts[] =
  3164.   {
  3165. + #ifdef MSDOS
  3166. +   {"copying", 0, NULL, 30},
  3167. +   {"version", 0, NULL, 31},
  3168. + #endif
  3169.     {"path", 0, &empty_paths, 1},
  3170.     {NULL, 0, NULL, 0}
  3171.   };
  3172. ***************
  3173. *** 74,79 ****
  3174. --- 117,132 ----
  3175.       case 'p':
  3176.         empty_paths = 1;
  3177.         break;
  3178. + #ifdef MSDOS
  3179. +     case 30:
  3180. +       fprintf (stderr, COPYING);
  3181. +       exit (0);
  3182. +       break;
  3183. +     case 31:
  3184. +       fprintf (stderr, VERSION);
  3185. +       exit (0);
  3186. +       break;
  3187. + #endif
  3188.       default:
  3189.         usage ();
  3190.       }
  3191. ***************
  3192. *** 136,142 ****
  3193. --- 189,199 ----
  3194.   void
  3195.   usage ()
  3196.   {
  3197. + #ifdef MSDOS
  3198. +   fprintf (stderr, "Usage: %s [-p] [+path] [+copying] [+version] dir...\n",
  3199. + #else /* not MSDOS */
  3200.     fprintf (stderr, "Usage: %s [-p] [+path] dir...\n",
  3201. + #endif /* not MSDOS */
  3202.          program_name);
  3203.     exit (1);
  3204.   }
  3205. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:50 1990
  3206. --- savedir.c    Wed Sep 19 12:33:58 1990
  3207. ***************
  3208. *** 17,23 ****
  3209. --- 17,36 ----
  3210.   
  3211.   /* Written by David MacKenzie <djm@ai.mit.edu>. */
  3212.   
  3213. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  3214. +    This port is also distributed under the terms of the
  3215. +    GNU General Public License as published by the
  3216. +    Free Software Foundation.
  3217. +    Please note that this file is not identical to the
  3218. +    original GNU release, you should have received this
  3219. +    code as patch to the official release.
  3220. +    $Header: e:/gnu/fileutil/RCS/savedir.c 1.4.0.2 90/09/17 09:28:48 tho Exp $
  3221. +  */
  3222.   #include <sys/types.h>
  3223.   #ifdef DIRENT
  3224.   #include <dirent.h>
  3225.   #ifdef direct
  3226. ***************
  3227. *** 50,55 ****
  3228. --- 63,74 ----
  3229.   #endif
  3230.   #endif
  3231.   
  3232. + #ifdef MSDOS
  3233. + #include <stdio.h>
  3234. + extern char *savedir (char *dir, unsigned name_size);
  3235. + static char *stpcpy (char *dest, char *source);
  3236. + #endif /* MSDOS */
  3237.   static char *stpcpy ();
  3238.   
  3239.   /* Return a freshly allocated string containing the filenames
  3240. ***************
  3241. *** 72,77 ****
  3242. --- 91,103 ----
  3243.     dirp = opendir (dir);
  3244.     if (dirp == NULL)
  3245.       return NULL;
  3246. + #ifdef MSDOS                 /* stat () it ourselves ... */
  3247. +   name_size = 0;
  3248. +   for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp))
  3249. +     name_size += strlen(dp->d_name) + 1;
  3250. +   seekdir(dirp, 0L);
  3251. + #endif /* MSDOS */
  3252.   
  3253.     name_space = (char *) malloc (name_size);
  3254.     if (name_space == NULL)
  3255. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:52 1990
  3256. --- system.h    Wed Sep 19 12:31:38 1990
  3257. ***************
  3258. *** 17,22 ****
  3259. --- 17,34 ----
  3260.   
  3261.   /* Include sys/types.h before this file.  */
  3262.   
  3263. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  3264. +    This port is also distributed under the terms of the
  3265. +    GNU General Public License as published by the
  3266. +    Free Software Foundation.
  3267. +    Please note that this file is not identical to the
  3268. +    original GNU release, you should have received this
  3269. +    code as patch to the official release.
  3270. +    $Header: e:/gnu/fileutil/RCS/system.h 1.4.0.2 90/09/19 12:27:45 tho Exp $
  3271. +  */
  3272.   #include <sys/stat.h>
  3273.   
  3274.   #ifdef _POSIX_SOURCE
  3275. ***************
  3276. *** 25,36 ****
  3277. --- 37,54 ----
  3278.   #else
  3279.   
  3280.   #ifdef USG
  3281. + #ifdef MSDOS
  3282. + #include <time.h>
  3283. + #else /* not MSDOS */
  3284.   #include <sys/times.h>
  3285. + #endif /* not MSDOS */
  3286.   #else
  3287.   #include <sys/time.h>
  3288.   #endif
  3289.   
  3290. + #ifndef MSDOS
  3291.   #include <sys/param.h>
  3292. + #endif /* not MSDOS */
  3293.   #define _POSIX_PATH_MAX 255
  3294.   #define _POSIX_NAME_MAX 14
  3295.   
  3296. ***************
  3297. *** 67,73 ****
  3298. --- 85,96 ----
  3299.   #define makedev(maj, min)  (((maj) << 8) | (min))
  3300.   #else
  3301.   #ifdef USG
  3302. + #ifdef MSDOS
  3303. + #define major(dev)  (((dev) >> 8) & 0xff)
  3304. + #define minor(dev)  ((dev) & 0xff)
  3305. + #else /* not MSDOS */
  3306.   #include <sys/sysmacros.h>
  3307. + #endif /* not MSDOS */
  3308.   #endif
  3309.   #endif
  3310.   
  3311. ***************
  3312. *** 79,84 ****
  3313. --- 102,110 ----
  3314.     long actime;
  3315.     long modtime;
  3316.   };
  3317. + #ifdef MSDOS
  3318. + int utime(char *, struct utimbuf *);
  3319. + #endif /* MSDOS */
  3320.   #endif
  3321.   
  3322.   #if defined(USG) || defined(STDC_HEADERS)
  3323. ***************
  3324. *** 134,139 ****
  3325. --- 160,173 ----
  3326.   #endif
  3327.   #endif
  3328.   
  3329. + #ifdef MSDOS
  3330. + #define ST_BLKSIZE(statbuf) BLKSIZE
  3331. + #define ST_NBLOCKS(statbuf) (((statbuf).st_size + DEV_BSIZE - 1) / DEV_BSIZE)
  3332. + #else /* not MSDOS */
  3333.   /* Extract data from a `struct stat'.
  3334.      ST_BLKSIZE: Optimal I/O blocksize for the file.
  3335.      ST_NBLOCKS: Number of blocks in the file (including indirect blocks). */
  3336. ***************
  3337. *** 152,157 ****
  3338. --- 186,193 ----
  3339.   #endif
  3340.   #endif
  3341.   
  3342. + #endif /* not MSDOS */
  3343.   /* Convert B blocks of DEV_BSIZE bytes
  3344.      to kilobytes if K is nonzero, otherwise to blocks of 512 bytes. */
  3345.   
  3346. ***************
  3347. *** 181,186 ****
  3348. --- 217,226 ----
  3349.   #ifdef sparc
  3350.   #include <alloca.h>
  3351.   #else
  3352. + #ifdef MSDOS
  3353. + #include <malloc.h>
  3354. + #else
  3355.   char *alloca ();
  3356. + #endif
  3357.   #endif
  3358.   #endif
  3359. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:54 1990
  3360. --- tac.c    Wed Sep 19 12:49:08 1990
  3361. ***************
  3362. *** 18,23 ****
  3363. --- 18,48 ----
  3364.   /* Written by Jay Lepreau (lepreau@cs.utah.edu).
  3365.      GNU enhancements by David MacKenzie (djm@ai.mit.edu). */
  3366.   
  3367. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  3368. +    This port is also distributed under the terms of the
  3369. +    GNU General Public License as published by the
  3370. +    Free Software Foundation.
  3371. +    Please note that this file is not identical to the
  3372. +    original GNU release, you should have received this
  3373. +    code as patch to the official release.  */
  3374. + #ifdef MSDOS
  3375. + static char RCS_Id[] =
  3376. +   "$Header: e:/gnu/fileutil/RCS/tac.c 1.4.0.3 90/09/19 12:09:16 tho Exp $";
  3377. + static char Program_Id[] = "tac";
  3378. + static char RCS_Revision[] = "$Revision: 1.4.0.3 $";
  3379. + #define VERSION \
  3380. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  3381. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  3382. + #define COPYING \
  3383. +   "This is free software, distributed under the terms of the\n" \
  3384. +   "GNU General Public License.  For details, see the file COPYING.\n"
  3385. + #endif /* MSDOS */
  3386.   /* Usage: tac [-br] [-s separator] [+before] [+regex] [+separator separator]
  3387.             [file...]
  3388.   
  3389. ***************
  3390. *** 67,72 ****
  3391. --- 92,121 ----
  3392.   off_t lseek ();
  3393.   #endif
  3394.   
  3395. + #ifdef MSDOS
  3396. + #include <gnulib.h>
  3397. + #include <io.h>
  3398. + /* We need a static malloc (with cleanup) here, so mask off
  3399. +    the one from gnulib   */
  3400. + #define xmalloc _xmalloc
  3401. + #define xrealloc _xrealloc
  3402. + static char *_xmalloc (unsigned int n);
  3403. + static char *_xrealloc (char *p, unsigned int n);
  3404. + extern void main (int argc, char **argv);
  3405. + static int tac (int fd, char *file);
  3406. + static int tac_file (char *file);
  3407. + static int tac_stdin (void );
  3408. + static void output (char *start, char *past_end);
  3409. + static void save_stdin (void );
  3410. + static void xwrite (int desc, char *buffer, int size);
  3411. + static SIGTYPE cleanup (void );
  3412. + #else /* not MSDOS */
  3413.   SIGTYPE cleanup ();
  3414.   int tac ();
  3415.   int tac_file ();
  3416. ***************
  3417. *** 77,82 ****
  3418. --- 126,132 ----
  3419.   void error ();
  3420.   void save_stdin ();
  3421.   void xwrite ();
  3422. + #endif /* not MSDOS */
  3423.   
  3424.   /* The name this program was run with. */
  3425.   char *program_name;
  3426. ***************
  3427. *** 114,119 ****
  3428. --- 164,173 ----
  3429.   
  3430.   struct option longopts[] =
  3431.   {
  3432. + #ifdef MSDOS
  3433. +   {"copying", 0, NULL, 30},
  3434. +   {"version", 0, NULL, 31},
  3435. + #endif
  3436.     {"before", 0, &separator_ends_record, 0},
  3437.     {"regex", 0, &sentinel_length, 0},
  3438.     {"separator", 1, NULL, 's'},
  3439. ***************
  3440. *** 120,126 ****
  3441.     {NULL, 0, NULL, 0}
  3442.   };
  3443.   
  3444. ! int
  3445.   main (argc, argv)
  3446.        int argc;
  3447.        char **argv;
  3448. --- 174,180 ----
  3449.     {NULL, 0, NULL, 0}
  3450.   };
  3451.   
  3452. ! void
  3453.   main (argc, argv)
  3454.        int argc;
  3455.        char **argv;
  3456. ***************
  3457. *** 129,134 ****
  3458. --- 183,193 ----
  3459.     int optc, longind, errors;
  3460.   
  3461.     program_name = argv[0];
  3462. + #ifdef MSDOS
  3463. +   setmode (0, O_BINARY);
  3464. +   setmode (1, O_BINARY);
  3465. + #endif /* MSDOS */
  3466.     errors = 0;
  3467.     separator = "\n";
  3468.     sentinel_length = 1;
  3469. ***************
  3470. *** 152,161 ****
  3471. --- 211,236 ----
  3472.         if (*separator == 0)
  3473.           error (1, 0, "separator cannot be empty");
  3474.         break;
  3475. + #ifdef MSDOS
  3476. +     case 30:
  3477. +       fprintf (stderr, COPYING);
  3478. +       exit (0);
  3479. +       break;
  3480. +     case 31:
  3481. +       fprintf (stderr, VERSION);
  3482. +       exit (0);
  3483. +       break;
  3484. + #endif
  3485.       default:
  3486. + #ifdef MSDOS
  3487. +       fprintf (stderr, "\
  3488. + Usage: %s [-br] [-s separator] [+before] [+regex] [+separator separator]\n\
  3489. +        [+copying] [+version] [file...]\n",
  3490. + #else /* not MSDOS */
  3491.         fprintf (stderr, "\
  3492.   Usage: %s [-br] [-s separator] [+before] [+regex] [+separator separator]\n\
  3493.          [file...]\n",
  3494. + #endif /* not MSDOS */
  3495.              program_name);
  3496.         exit (1);
  3497.       }
  3498. ***************
  3499. *** 164,170 ****
  3500. --- 239,250 ----
  3501.     if (sentinel_length == 0)
  3502.       {
  3503.         compiled_separator.allocated = 100;
  3504. + #ifdef MSDOS
  3505. +       compiled_separator.buffer
  3506. +     = xmalloc ((size_t) compiled_separator.allocated);
  3507. + #else /* not MSDOS */
  3508.         compiled_separator.buffer = xmalloc (compiled_separator.allocated);
  3509. + #endif /* not MSDOS */
  3510.         compiled_separator.fastmap = xmalloc (256);
  3511.         compiled_separator.translate = 0;
  3512.         error_message = re_compile_pattern (separator, strlen (separator),
  3513. ***************
  3514. *** 235,243 ****
  3515. --- 315,325 ----
  3516.     sigint = signal (SIGINT, SIG_IGN);
  3517.     if (sigint != SIG_IGN)
  3518.       signal (SIGINT, cleanup);
  3519. + #ifdef SIGHUP
  3520.     sighup = signal (SIGHUP, SIG_IGN);
  3521.     if (sighup != SIG_IGN)
  3522.       signal (SIGHUP, cleanup);
  3523. + #endif
  3524.     sigterm = signal (SIGTERM, SIG_IGN);
  3525.     if (sigterm != SIG_IGN)
  3526.       signal (SIGTERM, cleanup);
  3527. ***************
  3528. *** 247,259 ****
  3529. --- 329,348 ----
  3530.   
  3531.     unlink (tempfile);
  3532.     signal (SIGINT, sigint);
  3533. + #ifdef SIGHUP
  3534.     signal (SIGHUP, sighup);
  3535. + #endif
  3536.     signal (SIGTERM, sigterm);
  3537.     return errors;
  3538.   }
  3539.   
  3540. + #ifdef MSDOS
  3541. + char template[] = "/tacXXXXXX";
  3542. + char *workplate;
  3543. + #else /* not MSDOS */
  3544.   char template[] = "/tmp/tacXXXXXX";
  3545.   char workplate[sizeof template];
  3546. + #endif /* not MSDOS */
  3547.   
  3548.   /* Make a copy of the standard input in `tempfile'. */
  3549.   
  3550. ***************
  3551. *** 263,276 ****
  3552. --- 352,391 ----
  3553.     int fd;
  3554.     int bytes_read;
  3555.   
  3556. + #ifdef MSDOS
  3557. +   char *p;
  3558. +   if ((p = getenv ("TMP")) || (p = getenv ("TEMP")))
  3559. +     {
  3560. +       int len = strlen (p);
  3561. +       workplate = (char *) xmalloc (sizeof (template) + len + 1);
  3562. +       strcpy (workplate, p);
  3563. +       p = workplate + len - 1;
  3564. +       if (*p == '/' || *p == '\\')    /*  strip trailing slash */
  3565. +     *p = '\0';
  3566. +     }
  3567. +   else
  3568. +     {
  3569. +       workplate = (char *) xmalloc (sizeof (template) + 2);
  3570. +       strcpy (workplate, ".");
  3571. +     }
  3572. +   strcat (workplate, template);
  3573. + #else /* not MSDOS */
  3574.     strcpy (workplate, template);
  3575. + #endif /* not MSDOS */
  3576.     tempfile = mktemp (workplate);
  3577. + #ifdef MSDOS
  3578. +   fd = open (tempfile, O_CREAT|O_TRUNC|O_RDWR|O_BINARY, S_IWRITE|S_IREAD);
  3579. + #else /* not MSDOS */
  3580.     fd = creat (tempfile, 0600);
  3581. + #endif /* not MSDOS */
  3582.     if (fd == -1)
  3583.       {
  3584.         error (0, errno, "%s", tempfile);
  3585.         cleanup ();
  3586.       }
  3587.     while ((bytes_read = read (0, buffer, read_size)) > 0)
  3588.       if (write (fd, buffer, bytes_read) != bytes_read)
  3589.         {
  3590. ***************
  3591. *** 294,300 ****
  3592. --- 409,419 ----
  3593.   {
  3594.     int fd, errors;
  3595.   
  3596. + #ifdef MSDOS
  3597. +   fd = open (file, O_RDONLY|O_BINARY);
  3598. + #else /* not MSDOS */
  3599.     fd = open (file, 0);
  3600. + #endif /* not MSDOS */
  3601.     if (fd == -1)
  3602.       {
  3603.         error (0, errno, "%s", file);
  3604. ***************
  3605. *** 340,346 ****
  3606. --- 459,469 ----
  3607.        not always hold during the program run, but since it usually will, leave
  3608.        it here for i/o efficiency (page/sector boundaries and all that).
  3609.        Note: the efficiency gain has not been verified. */
  3610. + #ifdef MSDOS
  3611. +   saved_record_size = (unsigned int) (file_pos % read_size);
  3612. + #else /* not MSDOS */
  3613.     saved_record_size = file_pos % read_size;
  3614. + #endif /* not MSDOS */
  3615.     if (saved_record_size == 0)
  3616.       saved_record_size = read_size;
  3617.     file_pos -= saved_record_size;
  3618. ***************
  3619. *** 354,359 ****
  3620. --- 477,498 ----
  3621.         return 1;
  3622.       }
  3623.   
  3624. + #ifdef MSDOS
  3625. +   /* Some loosing editors add one or more ^Z to the end of a text file and
  3626. +      loosing MS-DOS devices interpret this as End Of File.  We turn them
  3627. +      into spaces and print a warning message.  */
  3628. +     {
  3629. +       char *ctrl_z = buffer + saved_record_size - 1;
  3630. +       if (*ctrl_z == '\032')
  3631. +     {
  3632. +       *ctrl_z = ' ';
  3633. +       error (0, 0, "%s: trailing ^Z translated to space.", file);
  3634. +       while (*--ctrl_z == '\032')
  3635. +         *ctrl_z = ' ';
  3636. +     }
  3637. +     }
  3638. + #endif /* MSDOS */
  3639.     match_start = past_end = buffer + saved_record_size;
  3640.     /* For non-regexp search, move past impossible positions for a match. */
  3641.     if (sentinel_length)
  3642. ***************
  3643. *** 430,436 ****
  3644.           file_pos -= read_size;
  3645.         else
  3646.           {
  3647. !           read_size = file_pos;
  3648.             file_pos = 0;
  3649.           }
  3650.         lseek (fd, file_pos, L_SET);
  3651. --- 569,575 ----
  3652.           file_pos -= read_size;
  3653.         else
  3654.           {
  3655. !           read_size = (unsigned) file_pos;
  3656.             file_pos = 0;
  3657.           }
  3658.         lseek (fd, file_pos, L_SET);
  3659. ***************
  3660. *** 528,533 ****
  3661. --- 667,673 ----
  3662.         cleanup ();
  3663.       }
  3664.   }
  3665.   
  3666.   /* Allocate N bytes of memory dynamically, with error checking.  */
  3667.   
  3668. *** e:\tmp/RCSt1006574    Wed Sep 19 13:28:58 1990
  3669. --- tail.c    Wed Sep 19 12:50:58 1990
  3670. ***************
  3671. *** 15,20 ****
  3672. --- 15,45 ----
  3673.      along with this program; if not, write to the Free Software
  3674.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  3675.   
  3676. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  3677. +    This port is also distributed under the terms of the
  3678. +    GNU General Public License as published by the
  3679. +    Free Software Foundation.
  3680. +    Please note that this file is not identical to the
  3681. +    original GNU release, you should have received this
  3682. +    code as patch to the official release.  */
  3683. + #ifdef MSDOS
  3684. + static char RCS_Id[] =
  3685. +   "$Header: e:/gnu/fileutil/RCS/tail.c 1.4.0.4 90/09/19 12:09:20 tho Exp $";
  3686. + static char Program_Id[] = "tail";
  3687. + static char RCS_Revision[] = "$Revision: 1.4.0.4 $";
  3688. + #define VERSION \
  3689. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  3690. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  3691. + #define COPYING \
  3692. +   "This is free software, distributed under the terms of the\n" \
  3693. +   "GNU General Public License.  For details, see the file COPYING.\n"
  3694. + #endif /* MSDOS */
  3695.   /* Can display any amount of data, unlike the Unix version, which uses
  3696.      a fixed size buffer and therefore can only deliver a limited number
  3697.      of lines.
  3698. ***************
  3699. *** 86,91 ****
  3700. --- 111,119 ----
  3701.   #define FOREVER 4        /* Read from end of file forever. */
  3702.   #define START 8            /* Count from start of file instead of end. */
  3703.   #define HEADERS 16        /* Print filename headers. */
  3704. + #ifdef MSDOS
  3705. + #define BINARY 32        /* Suppress crlf translation. */
  3706. + #endif
  3707.   
  3708.   /* When to print the filename banners. */
  3709.   enum header_mode
  3710. ***************
  3711. *** 93,98 ****
  3712. --- 121,152 ----
  3713.     multiple_files, always, never
  3714.   };
  3715.   
  3716. + #ifdef MSDOS
  3717. + #include <io.h>
  3718. + #include <string.h>
  3719. + extern  void main (int, char **);
  3720. + extern  void write_header (char *);
  3721. + extern  int tail (char *, int, int, long);
  3722. + extern  int tail_file (char *, int, long);
  3723. + extern  int tail_bytes (char *, int, int, long);
  3724. + extern  int tail_lines (char *, int, int, long);
  3725. + extern  int file_lines (char *, int, long, long);
  3726. + extern  int pipe_lines (char *, int, long);
  3727. + extern  int pipe_bytes (char *, int, long);
  3728. + extern  int start_bytes (char *, int, long);
  3729. + extern  int start_lines (char *, int, long);
  3730. + extern  void dump_remainder (char *, int, int);
  3731. + extern  void xwrite (int, char *, int);
  3732. + extern  char *xmalloc (int);
  3733. + extern  long atou (char *);
  3734. + extern  char *basename (char *);
  3735. + extern  void error (int status, int errnum, char *message, ...);
  3736. + extern  void usage (void);
  3737. + #else  /* not MSDOS */
  3738.   char *xmalloc ();
  3739.   int file_lines ();
  3740.   int pipe_bytes ();
  3741. ***************
  3742. *** 110,116 ****
  3743.   void write_header ();
  3744.   void xwrite ();
  3745.   
  3746. ! extern int errno;
  3747.   
  3748.   /* The name this program was run with. */
  3749.   char *program_name;
  3750. --- 164,170 ----
  3751.   void write_header ();
  3752.   void xwrite ();
  3753.   
  3754. ! #endif /* not MSDOS */
  3755.   
  3756.   /* The name this program was run with. */
  3757.   char *program_name;
  3758. ***************
  3759. *** 117,122 ****
  3760. --- 171,181 ----
  3761.   
  3762.   struct option long_options[] =
  3763.   {
  3764. + #ifdef MSDOS
  3765. +   {"binary", 1, NULL, 'B'},
  3766. +   {"copying", 0, NULL, 30},
  3767. +   {"version", 0, NULL, 31},
  3768. + #endif
  3769.     {"blocks", 1, NULL, 'b'},
  3770.     {"bytes", 1, NULL, 'c'},
  3771.     {"follow", 0, NULL, 'f'},
  3772. ***************
  3773. *** 200,210 ****
  3774. --- 259,289 ----
  3775.         argc--;
  3776.       }
  3777.   
  3778. + #ifdef MSDOS
  3779. +   while ((c = getopt_long (argc, argv, "b:c:n:fqvB", long_options, &longind))
  3780. + #else
  3781.     while ((c = getopt_long (argc, argv, "b:c:n:fqv", long_options, &longind))
  3782. + #endif
  3783.        != EOF)
  3784.       {
  3785.         switch (c)
  3786.       {
  3787. + #ifdef MSDOS
  3788. +     case 30:
  3789. +       fprintf (stderr, COPYING);
  3790. +       exit (0);
  3791. +       break;
  3792. +     case 31:
  3793. +       fprintf (stderr, VERSION);
  3794. +       exit (0);
  3795. +       break;
  3796. +     case 'B':
  3797. +       mode |= BINARY;
  3798. +       break;
  3799. + #endif
  3800.       case 'b':
  3801.         mode |= BLOCKS;
  3802.         mode &= ~BYTES;
  3803. ***************
  3804. *** 236,242 ****
  3805.         break;
  3806.   
  3807.       case 'f':
  3808. !       mode |= FOREVER;
  3809.         break;
  3810.   
  3811.       case 'n':
  3812. --- 315,323 ----
  3813.         break;
  3814.   
  3815.       case 'f':
  3816. ! #ifndef MSDOS
  3817. !         mode |= FOREVER;
  3818. ! #endif /* not MSDOS */
  3819.         break;
  3820.   
  3821.       case 'n':
  3822. ***************
  3823. *** 365,374 ****
  3824. --- 446,478 ----
  3825.        int mode;
  3826.        long number;
  3827.   {
  3828. + #ifdef MSDOS
  3829. +   int errors;
  3830. +   if (mode & BINARY)
  3831. +     {
  3832. +       setmode (fileno (stdout), O_BINARY);
  3833. +       setmode (fd, O_BINARY);
  3834. +     }
  3835. +   if (mode & (BYTES | BLOCKS))
  3836. +     errors = tail_bytes (filename, fd, mode, number);
  3837. +   else
  3838. +     errors = tail_lines (filename, fd, mode, number);
  3839. +   if (mode & BINARY)
  3840. +     setmode (fileno (stdout), O_TEXT);
  3841. +   return errors;
  3842. + #else /* not MSDOS */
  3843.     if (mode & (BYTES | BLOCKS))
  3844.       return tail_bytes (filename, fd, mode, number);
  3845.     else
  3846.       return tail_lines (filename, fd, mode, number);
  3847. + #endif /* not MSDOS */
  3848.   }
  3849.   
  3850.   /* Display the last part of file `filename', open for reading in`fd',
  3851. ***************
  3852. *** 485,491 ****
  3853. --- 589,599 ----
  3854.   
  3855.     /* Set `bytes_read' to the size of the last, probably partial, buffer;
  3856.        0 < `bytes_read' <= `BUFSIZE'. */
  3857. + #ifdef MSDOS                /* shut up the compiler */
  3858. +   bytes_read = (int) (pos % (long) BUFSIZE);
  3859. + #else
  3860.     bytes_read = pos % BUFSIZE;
  3861. + #endif
  3862.     if (bytes_read == 0)
  3863.       bytes_read = BUFSIZE;
  3864.     /* Make `pos' a multiple of `BUFSIZE' (0 if the file is short), so that all
  3865. ***************
  3866. *** 557,563 ****
  3867.     typedef struct linebuffer LBUFFER;
  3868.     LBUFFER *first, *last, *tmp;
  3869.     int i;            /* Index into buffers. */
  3870. !   int total_lines = 0;        /* Total number of newlines in all buffers. */
  3871.     int errors = 0;
  3872.   
  3873.     first = last = (LBUFFER *) xmalloc (sizeof (LBUFFER));
  3874. --- 665,671 ----
  3875.     typedef struct linebuffer LBUFFER;
  3876.     LBUFFER *first, *last, *tmp;
  3877.     int i;            /* Index into buffers. */
  3878. !   long total_lines = 0;        /* Total number of newlines in all buffers. */
  3879.     int errors = 0;
  3880.   
  3881.     first = last = (LBUFFER *) xmalloc (sizeof (LBUFFER));
  3882. ***************
  3883. *** 637,643 ****
  3884. --- 745,755 ----
  3885.         /* Skip `total_lines' - `number' newlines.  We made sure that
  3886.            `total_lines' - `number' <= `tmp->nlines'. */
  3887.         cp = tmp->buffer;
  3888. + #ifdef MSDOS                /* shut up the compiler */
  3889. +       for (i = (int) (total_lines - number); i; --i)
  3890. + #else
  3891.         for (i = total_lines - number; i; --i)
  3892. + #endif
  3893.       while (*cp++ != '\n')
  3894.         /* Do nothing. */ ;
  3895.         i = cp - tmp->buffer;
  3896. ***************
  3897. *** 678,684 ****
  3898. --- 790,800 ----
  3899.     typedef struct charbuffer CBUFFER;
  3900.     CBUFFER *first, *last, *tmp;
  3901.     int i;            /* Index into buffers. */
  3902. + #ifdef MSDOS
  3903. +   long total_bytes = 0;        /* Total characters in all buffers. */
  3904. + #else
  3905.     int total_bytes = 0;        /* Total characters in all buffers. */
  3906. + #endif
  3907.     int errors = 0;
  3908.   
  3909.     first = last = (CBUFFER *) xmalloc (sizeof (CBUFFER));
  3910. ***************
  3911. *** 737,743 ****
  3912. --- 853,863 ----
  3913.     /* Find the correct beginning, then print the rest of the file.
  3914.        We made sure that `total_bytes' - `number' <= `tmp->nbytes'. */
  3915.     if (total_bytes > number)
  3916. + #ifdef MSDOS                /* shut up the compiler */
  3917. +     i = (int) (total_bytes - number);
  3918. + #else
  3919.       i = total_bytes - number;
  3920. + #endif
  3921.     else
  3922.       i = 0;
  3923.     xwrite (1, &tmp->buffer[i], tmp->nbytes - i);
  3924. ***************
  3925. *** 776,782 ****
  3926. --- 896,906 ----
  3927.         return 1;
  3928.       }
  3929.     else if (number < 0)
  3930. + #ifdef MSDOS                /* |number| < 64k ??? */
  3931. +     xwrite (1, &buffer[bytes_read + number], (unsigned int) (-number));
  3932. + #else
  3933.       xwrite (1, &buffer[bytes_read + number], -number);
  3934. + #endif
  3935.     return 0;
  3936.   }
  3937.   
  3938. ***************
  3939. *** 829,839 ****
  3940. --- 953,965 ----
  3941.       xwrite (1, buffer, bytes_read);
  3942.     if (bytes_read == -1)
  3943.       error (1, errno, "%s", filename);
  3944. + #ifndef MSDOS
  3945.     if (mode & FOREVER)
  3946.       {
  3947.         sleep (1);
  3948.         goto output;
  3949.       }
  3950. + #endif
  3951.   }
  3952.   
  3953.   /* Write plus error check. */
  3954. ***************
  3955. *** 874,885 ****
  3956.   
  3957.     for (value = 0; ISDIGIT (*str); ++str)
  3958.       value = value * 10 + *str - '0';
  3959. !   return *str ? -1 : value;
  3960.   }
  3961.   
  3962.   void
  3963.   usage ()
  3964.   {
  3965.     fprintf (stderr, "\
  3966.   Usage: %s [-b [+]#] [-c [+]#] [-n [+]#] [-fqv] [+blocks [+]#]\n\
  3967.          [+bytes [+]#] [+lines [+]#] [+follow] [+quiet] [+silent]\n\
  3968. --- 1000,1020 ----
  3969.   
  3970.     for (value = 0; ISDIGIT (*str); ++str)
  3971.       value = value * 10 + *str - '0';
  3972. !   return *str ? -1L : value;
  3973.   }
  3974.   
  3975.   void
  3976.   usage ()
  3977.   {
  3978. + #ifdef MSDOS
  3979. +   fprintf (stderr, "\
  3980. + Usage: %s [-b [+]#] [-c [+]#] [-n [+]#] [-fqvB] [+blocks [+]#]\n\
  3981. +        [+bytes [+]#] [+lines [+]#] [+follow] [+quiet] [+silent]\n\
  3982. +        [+verbose] [+binary] [+copying] [+version] [file...]\n\
  3983. + \n\
  3984. +        %s [+/-#bcflqv] [file...]\n", program_name, program_name);
  3985. +   exit (1);
  3986. + #else
  3987.     fprintf (stderr, "\
  3988.   Usage: %s [-b [+]#] [-c [+]#] [-n [+]#] [-fqv] [+blocks [+]#]\n\
  3989.          [+bytes [+]#] [+lines [+]#] [+follow] [+quiet] [+silent]\n\
  3990. ***************
  3991. *** 887,890 ****
  3992. --- 1022,1026 ----
  3993.   \n\
  3994.          %s [+/-#bcflqv] [file...]\n", program_name, program_name);
  3995.     exit (1);
  3996. + #endif
  3997.   }
  3998. *** e:\tmp/RCSt1006574    Wed Sep 19 13:29:02 1990
  3999. --- touch.c    Wed Sep 19 12:51:54 1990
  4000. ***************
  4001. *** 15,20 ****
  4002. --- 15,45 ----
  4003.      along with this program; if not, write to the Free Software
  4004.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  4005.   
  4006. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  4007. +    This port is also distributed under the terms of the
  4008. +    GNU General Public License as published by the
  4009. +    Free Software Foundation.
  4010. +    Please note that this file is not identical to the
  4011. +    original GNU release, you should have received this
  4012. +    code as patch to the official release.  */
  4013. + #ifdef MSDOS
  4014. + static char RCS_Id[] =
  4015. +   "$Header: e:/gnu/fileutil/RCS/touch.c 1.4.0.2 90/09/19 12:09:27 tho Exp $";
  4016. + static char Program_Id[] = "touch";
  4017. + static char RCS_Revision[] = "$Revision: 1.4.0.2 $";
  4018. + #define VERSION \
  4019. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  4020. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  4021. + #define COPYING \
  4022. +   "This is free software, distributed under the terms of the\n" \
  4023. +   "GNU General Public License.  For details, see the file COPYING.\n"
  4024. + #endif /* MSDOS */
  4025.   /* Usage: touch [-acm] [-r reference-file] [-t MMDDhhmm[[CC]YY][.ss]]
  4026.             [-d time] [+time {atime,access,use,mtime,modify}] [+date time]
  4027.             [+file reference-file] [+no-create] file...
  4028. ***************
  4029. *** 58,63 ****
  4030. --- 83,104 ----
  4031.   long lseek ();
  4032.   #endif
  4033.   
  4034. + #ifdef MSDOS
  4035. + #include <io.h>
  4036. + #include <gnulib.h>
  4037. + extern int argmatch (char *arg, char **optlist);
  4038. + extern void invalid_arg (char *kind, char *value, int problem);
  4039. + extern time_t posixtime (char *s);
  4040. + extern time_t getdate (char *p, struct timeb *now);
  4041. + void main (int argc, char **argv);
  4042. + int touch (char *file);
  4043. + void usage (void);
  4044. + #else /* not MSDOS */
  4045.   int argmatch ();
  4046.   int touch ();
  4047.   time_t getdate ();
  4048. ***************
  4049. *** 66,71 ****
  4050. --- 107,114 ----
  4051.   void invalid_arg ();
  4052.   void usage ();
  4053.   
  4054. + #endif /* not MSDOS */
  4055.   /* Bitmasks for `change_times'. */
  4056.   #define CH_ATIME 1
  4057.   #define CH_MTIME 2
  4058. ***************
  4059. *** 104,109 ****
  4060. --- 147,156 ----
  4061.   
  4062.   struct option longopts[] =
  4063.   {
  4064. + #ifdef MSDOS
  4065. +   {"copying", 0, NULL, 30},
  4066. +   {"version", 0, NULL, 31},
  4067. + #endif
  4068.     {"time", 1, 0, 130},
  4069.     {"no-create", 0, 0, 'c'},
  4070.     {"date", 1, 0, 'd'},
  4071. ***************
  4072. *** 185,190 ****
  4073. --- 232,249 ----
  4074.         change_times |= time_masks[longind];
  4075.         break;
  4076.   
  4077. + #ifdef MSDOS
  4078. +     case 30:
  4079. +       fprintf (stderr, COPYING);
  4080. +       exit (0);
  4081. +       break;
  4082. +     case 31:
  4083. +       fprintf (stderr, VERSION);
  4084. +       exit (0);
  4085. +       break;
  4086. + #endif
  4087.       default:
  4088.         usage ();
  4089.       }
  4090. ***************
  4091. *** 335,340 ****
  4092. --- 394,401 ----
  4093.     return 0;
  4094.   }
  4095.   
  4096. + /*  Use the one from gnulib */
  4097. + #ifndef MSDOS
  4098.   
  4099.   /* Like malloc but get error if no storage available. */
  4100.   
  4101. ***************
  4102. *** 363,375 ****
  4103. --- 424,445 ----
  4104.     return val;
  4105.   }
  4106.   
  4107. + #endif /* not MSDOS */
  4108.   void
  4109.   usage ()
  4110.   {
  4111. + #ifdef MSDOS
  4112. +   fprintf (stderr, "\
  4113. + Usage: %s [-acm] [-r reference-file] [-t MMDDhhmm[[CC]YY][.ss]]\n\
  4114. +        [-d time] [+time {atime,access,use,mtime,modify}] [+date time]\n\
  4115. +        [+file reference-file] [+no-create] [+copying] [+version] file...\n",
  4116. + #else /* not MSDOS */
  4117.     fprintf (stderr, "\
  4118.   Usage: %s [-acm] [-r reference-file] [-t MMDDhhmm[[CC]YY][.ss]]\n\
  4119.          [-d time] [+time {atime,access,use,mtime,modify}] [+date time]\n\
  4120.          [+file reference-file] [+no-create] file...\n",
  4121. + #endif /* not MSDOS */
  4122.          program_name);
  4123.     exit (1);
  4124.   }
  4125.