home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / utilities3 / discindex / DiscIndex / Source / C / Recurse < prev    next >
Text File  |  1994-08-03  |  1KB  |  59 lines

  1. /* Directory recursion code
  2.  * Missing in RISC-OS, but not UNIX! Let's have a RISC-PC UNIX guys!
  3.  * (c) NA Carson 1994 A.D.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9.  
  10. #include "discindex.h"
  11. #include "kernel.h"
  12. #include "os.h"
  13. #include "wimp.h"
  14.  
  15. #define OS_GBPB      0x0C
  16.  
  17. void recurse(char *source_dir, recurse_proc call)
  18. {
  19.     _kernel_swi_regs r;
  20.     os_error *error;
  21.     os_gbpb_block record;
  22.     int cnt;
  23.  
  24.     r.r[0] = 10;
  25.     r.r[1] = (int) source_dir;
  26.     r.r[2] = (int) &record;
  27.     r.r[4] = 0;
  28.     r.r[5] = sizeof(os_gbpb_block);
  29.     r.r[6] = 0;
  30.  
  31.     while (1)
  32.     {
  33.         r.r[3] = 1;
  34.         error = (os_error *) _kernel_swi(OS_GBPB, &r, &r);
  35.         if (error != 0)
  36.         {
  37.             wimp_reporterror(error, wimp_EOK, "Disc Index");
  38.             return;
  39.         }
  40.         if (r.r[3] == 0) return;
  41.         if (r.r[4] == -1) return;
  42.         for (cnt=0; cnt < 32; cnt ++)
  43.             if (record.name[cnt] < 32) record.name[cnt] = 0;
  44.         call(source_dir, &record);
  45.         if (record.type == 2)
  46.         {
  47.             char *temp;
  48.  
  49.             temp = malloc(512);
  50.             if (temp == 0) exit(0);
  51.             strcpy(temp, source_dir);
  52.             strcat(temp, ".");
  53.             strcat(temp, record.name);
  54.             recurse(temp, call);
  55.             free(temp);
  56.         }
  57.     }
  58. }
  59.