home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / indent / diffs / amiga.diffs next >
Text File  |  1999-05-21  |  14KB  |  589 lines

  1. diff -cr ram:indent-1.7/args.c dh1:indent-1.7/args.c
  2. *** ram:indent-1.7/args.c    Mon Feb 08 23:41:08 1993
  3. --- dh1:indent-1.7/args.c    Sat Feb 13 18:13:37 1993
  4. ***************
  5. *** 772,777 ****
  6. --- 772,797 ----
  7.     static char prof[] = INDENT_PROFILE;
  8.     char *homedir;
  9.   
  10. + #ifdef AMIGA
  11. +   if ((f = fopen (prof, "r")) != NULL)
  12. +     {
  13. +       scan_profile (f);
  14. +       (void) fclose (f);
  15. +       fname = xmalloc (sizeof prof);
  16. +       strcpy (fname, prof);
  17. +       return fname;
  18. +     }
  19. +   fname = xmalloc (sizeof prof + 5);
  20. +   sprintf (fname, "S:%s", prof);
  21. +   if ((f = fopen (fname, "r")) != NULL)
  22. +     {
  23. +       scan_profile (f);
  24. +       (void) fclose (f);
  25. +       return fname;
  26. +     }
  27. + #else /* !AMIGA */
  28.     if ((f = fopen (INDENT_PROFILE, "r")) != NULL)
  29.       {
  30.         int len = strlen (INDENT_PROFILE) + 3;
  31. ***************
  32. *** 801,806 ****
  33. --- 821,827 ----
  34.   
  35.         free (fname);
  36.       }
  37. + #endif /* !AMIGA */
  38.   
  39.     return 0;
  40.   }
  41. diff -cr ram:indent-1.7/backup.c dh1:indent-1.7/backup.c
  42. *** ram:indent-1.7/backup.c    Mon Feb 08 15:07:28 1993
  43. --- dh1:indent-1.7/backup.c    Sat Feb 13 18:16:42 1993
  44. ***************
  45. *** 74,79 ****
  46. --- 74,82 ----
  47.   #endif /* !SYSNDIR */
  48.   #else /* !USG */
  49.   #include <sys/dir.h>
  50. + #ifdef AMIGA
  51. + #define dirent direct
  52. + #endif /* AMIGA */
  53.   #endif /* !USG */
  54.   #endif /* !DIRENT */
  55.   
  56. ***************
  57. *** 94,100 ****
  58. --- 97,107 ----
  59.   #endif /* NODIR */
  60.   
  61.   /* Default backup file suffix to use */
  62. + #ifdef AMIGA
  63. + char *simple_backup_suffix = "!";
  64. + #else /* !AMIGA */
  65.   char *simple_backup_suffix = "~";
  66. + #endif /* !AMIGA */
  67.   
  68.   /* What kinds of backup files to make -- see
  69.      table `version_control_values' below. */
  70. ***************
  71. *** 135,141 ****
  72. --- 142,152 ----
  73.       {
  74.         for (p = &direntry[base_length + 2]; ISDIGIT (*p); ++p)
  75.       version = version * 10 + *p - '0';
  76. + #ifdef AMIGA
  77. +       if (p[0] != '!' || p[1])
  78. + #else /* !AMIGA */
  79.         if (p[0] != '~' || p[1])
  80. + #endif /* !AMIGA */
  81.       version = 0;
  82.       }
  83.   
  84. ***************
  85. *** 191,196 ****
  86. --- 202,237 ----
  87.     int version;
  88.   
  89.     p = pathname + pathlen - 1;
  90. + #ifdef AMIGA
  91. +   while (p > pathname && *p != '/' && *p != ':')
  92. +     p--;
  93. +   if (*p == '/')
  94. +     {
  95. +       int dirlen = p - pathname;
  96. +       register char *dirname;
  97. +       filename = p + 1;
  98. +       dirname = xmalloc (dirlen + 1);
  99. +       strncpy (dirname, pathname, (dirlen));
  100. +       dirname[dirlen] = '\0';
  101. +       version = highest_version (filename, dirname);
  102. +       free (dirname);
  103. +       return version;
  104. +     }
  105. +   else if (*p == ':')
  106. +     {
  107. +       int dirlen = p - pathname + 1;
  108. +       register char *dirname;
  109. +       filename = p + 1;
  110. +       dirname = xmalloc (dirlen + 1);
  111. +       strncpy (dirname, pathname, (dirlen));
  112. +       dirname[dirlen] = '\0';
  113. +       version = highest_version (filename, dirname);
  114. +       free (dirname);
  115. +       return version;
  116. +     }
  117. + #else /* !AMIGA */
  118.     while (p > pathname && *p != '/')
  119.       p--;
  120.   
  121. ***************
  122. *** 207,215 ****
  123. --- 248,261 ----
  124.         free (dirname);
  125.         return version;
  126.       }
  127. + #endif /* !AMIGA */
  128.   
  129.     filename = pathname;
  130. + #ifdef AMIGA
  131. +   version = highest_version (filename, "");
  132. + #else /* !AMIGA */
  133.     version = highest_version (filename, ".");
  134. + #endif /* !AMIGA */
  135.     return version;
  136.   }
  137.   
  138. ***************
  139. *** 241,248 ****
  140. --- 287,299 ----
  141.     if (!backup_name)
  142.       return 0;
  143.   
  144. + #ifdef AMIGA
  145. +   sprintf (backup_name, "%s.!%d!", pathname,
  146. +            (int) last_numbered_version);
  147. + #else /* !AMIGA */
  148.     sprintf (backup_name, "%s.~%d~", pathname,
  149.          (int) last_numbered_version);
  150. + #endif /* !AMIGA */
  151.     return backup_name;
  152.   }
  153.   
  154. ***************
  155. *** 326,336 ****
  156. --- 377,406 ----
  157.     char *new_backup_name;
  158.   
  159.     backup_filename = generate_backup_filename (version_control, file->name);
  160. + #ifdef AMIGA
  161. +   /* The original code contains a bug here. generate_backup_filename sets
  162. +      the return value to NULL if version_control == none. Just do nothing
  163. +      in this case. */
  164. +   if (! backup_filename)
  165. +     {
  166. +       if (version_control != none)
  167. +         {
  168. +           fprintf (stderr, "indent: Can't make backup filename of %s\n", file->name);
  169. +           exit (1);
  170. +         }
  171. +       else
  172. +         {
  173. +           free (backup_filename);
  174. +           return;
  175. +         }
  176. +     }
  177. + #else /* !AMIGA */
  178.     if (!backup_filename)
  179.       {
  180.         fprintf (stderr, "indent: Can't make backup filename of %s", file->name);
  181.         exit (1);
  182.       }
  183. + #endif /* !AMIGA */
  184.   
  185.     fd = creat (backup_filename, 0666);
  186.     if (fd < 0)
  187. diff -cr ram:indent-1.7/indent.c dh1:indent-1.7/indent.c
  188. *** ram:indent-1.7/indent.c    Thu Feb 11 01:24:06 1993
  189. --- dh1:indent-1.7/indent.c    Sat Feb 13 18:17:07 1993
  190. ***************
  191. *** 21,26 ****
  192. --- 21,41 ----
  193.   #include "indent.h"
  194.   #include <ctype.h>
  195.   
  196. + #ifdef AMIGA
  197. + #include <exec/types.h>
  198. + #include <dos/dos.h>
  199. + #include <dos/dosextens.h>
  200. + #include <dos/dosasl.h>
  201. + #include <proto/dos.h>
  202. + #define MAXPATH 200
  203. + #define MAXARGS 256
  204. + extern struct DosLibrary *DOSBase;
  205. + int expand_args ();
  206. + #endif /* AMIGA */
  207.   void
  208.   usage ()
  209.   {
  210. ***************
  211. *** 1637,1648 ****
  212. --- 1652,1691 ----
  213.     struct file_buffer *current_input;
  214.     char *profile_pathname = 0;
  215.     int using_stdin = false;
  216. + #ifdef AMIGA
  217. +   int ex_err;
  218. + #endif /* AMIGA */
  219.   
  220.   #ifdef DEBUG
  221.     if (debug)
  222.       debug_init ();
  223.   #endif
  224.   
  225. + #ifdef AMIGA
  226. +   if (DOSBase->dl_lib.lib_Version < 37)
  227. +     {
  228. +       fprintf (stderr, "You must have Kickstart 2.0 (V37) or higher!\n");
  229. +       exit (20);
  230. +     }
  231. +   if (argc == 2 && stricmp (argv[1],"-h") == 0)
  232. +     {
  233. +       usage ();
  234. +       exit (0);
  235. +     }
  236. +   if ((ex_err = expand_args (&argc, &argv)) == 0)
  237. +     {
  238. +       fprintf (stderr, "Couldn't expand wildcards\n");
  239. +       exit (20);
  240. +     }
  241. +   if (ex_err == 2)
  242. +     {
  243. +       fprintf (stderr, "Wildcards didn't match a file\n");
  244. +       exit (5);
  245. +     }
  246. + #endif /* AMIGA */
  247.     init_parser ();
  248.     initialize_backups ();
  249.   
  250. ***************
  251. *** 1745,1752 ****
  252. --- 1788,1803 ----
  253.   
  254.         for (i = 0; input_files; i++, input_files--)
  255.       {
  256. + #ifdef AMIGA
  257. +           /* Reset line- and comment-count */
  258. +           out_lines = out_coms = 0;
  259. + #endif /* AMIGA */
  260.         current_input = read_file (in_file_names[i]);
  261.         in_name = out_name = in_file_names[i];
  262. + #ifdef AMIGA
  263. +           if (verbose)
  264. +             printf ("\n%s:\n", out_name);
  265. + #endif /* AMIGA */
  266.         output = fopen (out_name, "w");
  267.         if (output == 0)
  268.           {
  269. ***************
  270. *** 1778,1783 ****
  271. --- 1829,1838 ----
  272.         if (!out_name && !use_stdout)
  273.           {
  274.             out_name = in_file_names[0];
  275. + #ifdef AMIGA
  276. +               if (verbose)
  277. +                 printf ("\n%s:\n", out_name);
  278. + #endif /* AMIGA */
  279.             make_backup (current_input);
  280.           }
  281.       }
  282. ***************
  283. *** 1803,1805 ****
  284. --- 1858,1981 ----
  285.   
  286.     exit (0);
  287.   }
  288. + #ifdef AMIGA
  289. + char *expand_next_file (pattern)
  290. +      char *pattern;
  291. + {
  292. +   long err;
  293. +   char *pathname;
  294. +   static struct AnchorPath *an = NULL;
  295. +   pathname = NULL;
  296. +   if (pattern == NULL)
  297. +     err = -1;
  298. +   else
  299. +     do
  300. +       {
  301. +         if (an == NULL)
  302. +           {
  303. +             an = malloc (sizeof (struct AnchorPath) + MAXPATH);
  304. +             memset (an, 0, sizeof (struct AnchorPath) + MAXPATH);
  305. +             an->ap_BreakBits = SIGBREAKF_CTRL_C;
  306. +             an->ap_Strlen = MAXPATH;
  307. +             an->ap_Flags = APF_DOWILD;
  308. +             err = MatchFirst (pattern, an);
  309. +           }
  310. +         else
  311. +           err = MatchNext (an);
  312. +         /* Expand only files */
  313. +         if (an->ap_Info.fib_DirEntryType < 0)
  314. +           pathname = an->ap_Buf;
  315. +       } while (err == 0 && pathname == NULL);
  316. +   if (err)
  317. +     {
  318. +       MatchEnd (an);
  319. +       free (an);
  320. +       an = NULL;
  321. +       return NULL;
  322. +     }
  323. +   else
  324. +     return pathname;
  325. + }
  326. + int
  327. + in_prev_args (arg, argv, argc)
  328. +      char *arg, **argv;
  329. +      int argc;
  330. + {
  331. +   int i, is_in_args;
  332. +   is_in_args = 0;
  333. +   for (i = 1; i < argc - 1; i++)
  334. +     if (strcmp (arg, argv[i]) == 0)
  335. +       is_in_args = 1;
  336. +   return is_in_args;
  337. + }
  338. + int
  339. + expand_args (oargc, oargv)
  340. +      int *oargc;
  341. +      char ***oargv;
  342. + {
  343. +   int i;
  344. +   char *str, **argv, buf[MAXPATH];
  345. +   int argc, no_match_at_all, num_matches, contains_wildcards;
  346. +   no_match_at_all = 1;
  347. +   contains_wildcards = 0;
  348. +   argc = 0;
  349. +   argv = malloc (MAXARGS * sizeof (char *));
  350. +   if (argv == NULL)
  351. +     return 0;
  352. +   argv[argc++] = (*oargv)[0];
  353. +   for (i = 1; i < *oargc; i++)
  354. +     {
  355. +       if (ParsePattern ((*oargv)[i], buf, MAXPATH))
  356. +         {
  357. +           contains_wildcards = 1;
  358. +           num_matches = 0;
  359. +           while (str = expand_next_file ((*oargv)[i]))
  360. +             if (argc >= MAXARGS)
  361. +               {
  362. +                 expand_next_file (NULL);
  363. +                 return 0;
  364. +               }
  365. +             else
  366. +               {
  367. +                 /* Avoid duplicate entries */
  368. +                 if (!in_prev_args (str, argv, argc))
  369. +                   {
  370. +                     argv[argc++] = strdup (str);
  371. +                     num_matches++;
  372. +                   }
  373. +               }
  374. +           if (num_matches != 0)
  375. +             no_match_at_all = 0;
  376. +         }
  377. +       else
  378. +         if (argc >= MAXARGS)
  379. +           return 0;
  380. +         else
  381. +           {
  382. +             if ((*oargv)[i][0] != '-' && (*oargv)[i][0] != '+')
  383. +               /* Found a file with no wildcards */
  384. +               no_match_at_all = 0;
  385. +             if (!in_prev_args ((*oargv)[i], argv, argc))
  386. +               argv[argc++] = (*oargv)[i];
  387. +           }
  388. +     }
  389. +   *oargc = argc;
  390. +   *oargv = argv;
  391. +   if (no_match_at_all && contains_wildcards)
  392. +     return 2;
  393. +   else
  394. +     return 1;
  395. + }
  396. + #endif /* AMIGA */
  397. diff -cr ram:indent-1.7/io.c dh1:indent-1.7/io.c
  398. *** ram:indent-1.7/io.c    Wed Feb 10 22:03:16 1993
  399. --- dh1:indent-1.7/io.c    Sat Feb 13 18:17:11 1993
  400. ***************
  401. *** 26,33 ****
  402. --- 26,39 ----
  403.      <sys/fcntl.h> or <sys/file.h> instead.  */
  404.   #include <fcntl.h>
  405.   
  406. + #ifdef AMIGA
  407. + #include <exec/types.h>
  408. + #include <dos/dos.h>
  409. + #include <proto/dos.h>
  410. + #else /* !AMIGA */
  411.   #include <sys/types.h>
  412.   #include <sys/stat.h>
  413. + #endif /* !AMIGA */
  414.   
  415.   /* number of levels a label is placed to left of code */
  416.   #define LABEL_OFFSET 2
  417. ***************
  418. *** 477,485 ****
  419. --- 483,516 ----
  420.        char *filename;
  421.   {
  422.     int fd;
  423. + #ifndef AMIGA
  424.     struct stat file_stats;
  425. + #endif /* !AMIGA */
  426.     int namelen = strlen (filename);
  427. + #ifdef AMIGA
  428. +   BPTR in_fh;
  429. +   struct FileInfoBlock __aligned in_fib;
  430. + #endif
  431. + #ifdef AMIGA
  432. +   in_fh = Lock (filename, SHARED_LOCK);
  433. +   if (in_fh == 0)
  434. +     sys_error (filename);
  435. +   if (Examine (in_fh, &in_fib) == 0)
  436. +     sys_error (filename);
  437. +   if (fileptr.data != 0)
  438. +     free (fileptr.data);
  439. +   fileptr.size = in_fib.fib_Size;
  440. +   fileptr.data = (char *) xmalloc (fileptr.size + 3);
  441.   
  442. +   UnLock (in_fh);
  443. +   fd = open (filename, O_RDONLY, 0777);
  444. +   if (fd < 0)
  445. +     sys_error (filename);
  446. + #else /* !AMIGA */
  447.     fd = open (filename, O_RDONLY, 0777);
  448.     if (fd < 0)
  449.       sys_error (filename);
  450. ***************
  451. *** 491,496 ****
  452. --- 522,528 ----
  453.       free (fileptr.data);
  454.     fileptr.size = file_stats.st_size;
  455.     fileptr.data = (char *) xmalloc (file_stats.st_size + 1);
  456. + #endif /* !AMIGA */
  457.   
  458.     if (read (fd, fileptr.data, fileptr.size) < 0)
  459.       sys_error (filename);
  460. ***************
  461. *** 523,532 ****
  462. --- 555,599 ----
  463.     unsigned int size = 15 * BUFSIZ;
  464.     int ch;
  465.     register char *p;
  466. + #ifdef AMIGA
  467. +   char *in_prog;
  468. +   int in_prog_size;
  469. + #endif /* AMIGA */
  470.   
  471.     if (stdinptr.data != 0)
  472.       free (stdinptr.data);
  473.   
  474. + /* The following code had to be changed, because you can't assume, that
  475. +    xrealloc() always returns the original pointer. By the way: the original
  476. +    code violates the GNU coding standards!!! */
  477. + #ifdef AMIGA
  478. +   in_prog = (char *) xmalloc (size + 1);
  479. +   in_prog_size = 0;
  480. +   do
  481. +     {
  482. +       for (; in_prog_size < size; in_prog_size++)
  483. +     {
  484. +       ch = getc (stdin);
  485. +       if (ch == EOF)
  486. +         break;
  487. +       in_prog[in_prog_size] = ch;
  488. +     }
  489. +       if (ch != EOF)
  490. +     {
  491. +       size += (2 * BUFSIZ);
  492. +       in_prog = xrealloc (in_prog, size);
  493. +     }
  494. +     }
  495. +   while (ch != EOF);
  496. +   stdinptr.data = in_prog;
  497. +   stdinptr.size = in_prog_size;
  498. +   stdinptr.name = "Standard Input";
  499. +   stdinptr.data[stdinptr.size] = '\0';
  500. + #else /* !AMIGA */
  501.     stdinptr.data = (char *) xmalloc (size + 1);
  502.     stdinptr.size = 0;
  503.     p = stdinptr.data;
  504. ***************
  505. *** 554,559 ****
  506. --- 621,627 ----
  507.     stdinptr.name = "Standard Input";
  508.   
  509.     stdinptr.data[stdinptr.size] = '\0';
  510. + #endif /* !AMIGA */
  511.   
  512.     return &stdinptr;
  513.   }
  514. diff -cr ram:indent-1.7/sys.h dh1:indent-1.7/sys.h
  515. *** ram:indent-1.7/sys.h    Wed Feb 10 21:39:58 1993
  516. --- dh1:indent-1.7/sys.h    Sat Feb 13 18:20:49 1993
  517. ***************
  518. *** 8,13 ****
  519. --- 8,18 ----
  520.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  */
  521.   
  522.   #include <stdio.h>
  523. + #ifdef AMIGA
  524. + /* For malloc, etc... */
  525. + #include <stdlib.h>
  526. + #include <string.h>
  527. + #endif /* AMIGA */
  528.   
  529.   /* Values of special characters. */
  530.   #define TAB '\t'
  531. ***************
  532. *** 26,34 ****
  533. --- 31,41 ----
  534.   
  535.   /* configure defines USG if it can't find bcopy */
  536.   
  537. + #ifndef AMIGA
  538.   #ifndef USG
  539.   #define memcpy(dest,src,len) bcopy((src),(dest),len)
  540.   #endif
  541. + #endif /* !AMIGA */
  542.   
  543.   struct file_buffer
  544.   {
  545. ***************
  546. *** 40,47 ****
  547. --- 47,56 ----
  548.   extern struct file_buffer *read_file (), *read_stdin ();
  549.   
  550.   /* Standard memory allocation routines.  */
  551. + #ifndef AMIGA
  552.   char *malloc ();
  553.   char *realloc ();
  554. + #endif /* !AMIGA */
  555.   
  556.   /* Similar, but abort with an error if out of memory (see globs.c).  */
  557.   char *xmalloc ();
  558.