home *** CD-ROM | disk | FTP | other *** search
- /* Directory recursion code
- * Missing in RISC-OS, but not UNIX! Let's have a RISC-PC UNIX guys!
- * (c) NA Carson 1994 A.D.
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
-
- #include "discindex.h"
- #include "kernel.h"
- #include "os.h"
- #include "wimp.h"
-
- #define OS_GBPB 0x0C
-
- void recurse(char *source_dir, recurse_proc call)
- {
- _kernel_swi_regs r;
- os_error *error;
- os_gbpb_block record;
- int cnt;
-
- r.r[0] = 10;
- r.r[1] = (int) source_dir;
- r.r[2] = (int) &record;
- r.r[4] = 0;
- r.r[5] = sizeof(os_gbpb_block);
- r.r[6] = 0;
-
- while (1)
- {
- r.r[3] = 1;
- error = (os_error *) _kernel_swi(OS_GBPB, &r, &r);
- if (error != 0)
- {
- wimp_reporterror(error, wimp_EOK, "Disc Index");
- return;
- }
- if (r.r[3] == 0) return;
- if (r.r[4] == -1) return;
- for (cnt=0; cnt < 32; cnt ++)
- if (record.name[cnt] < 32) record.name[cnt] = 0;
- call(source_dir, &record);
- if (record.type == 2)
- {
- char *temp;
-
- temp = malloc(512);
- if (temp == 0) exit(0);
- strcpy(temp, source_dir);
- strcat(temp, ".");
- strcat(temp, record.name);
- recurse(temp, call);
- free(temp);
- }
- }
- }
-