home *** CD-ROM | disk | FTP | other *** search
- /*
- * WildDemo.c -- Demonstration of how to use the arp.library wildcard
- * routines. This program simulates a sort of dir command.
- *
- * -+=SDB=+-
- *
- * Copyright (c) 1987, Scott Ballantyne
- * Use and abuse as you please.
- */
-
- #include <exec/types.h>
- #include <libraries/arpbase.h>
- #include <libraries/dos.h> /* For ERROR_NO_MORE_ENTRIES, ^C, etc. */
- #include <arpfunctions.h>
-
- /* A slightly extended AnchorPath structure */
- /* We extend the anchor structure in this way because we will be
- * using the pattern matching functions to build complete path names.
- * If you don't want to use this ability, then you don't need to extend
- * the structure at all
- */
-
- struct UserAnchor {
- struct AnchorPath ua_AP;
- BYTE moremem[255]; /* cheap way to extend ap_Buf[] */
- };
-
- /* Our templates and help strings */
-
- char *CLI_Template = "Pattern";
- char *CLI_Help = "List Files or directories by wildcard";
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- struct UserAnchor *Anchor;
- char *pat;
- LONG Result;
-
- if (argc < 2)
- pat = "*"; /* All files/dirs in current directory */
- else
- pat = argv[1];
-
- /* Because a struct AnchorPath contains the BCPL structure
- * FileInfoBlock, we must always insure that the AnchorPath is
- * longword aligned. A simple way to do this and also track it
- * is to call ArpAlloc()
- */
-
- if ( Anchor = (struct UserAnchor *)ArpAlloc( (ULONG)sizeof( *Anchor )) )
- {
- Anchor->ua_AP.ap_Length = 255; /* Want full path built */
-
- /* We will be breaking on control 'C's */
- /* and on control 'D's, just to show how */
- Anchor->ua_AP.ap_BreakBits |= SIGBREAKF_CTRL_C;
- Anchor->ua_AP.ap_BreakBits |= SIGBREAKF_CTRL_D;
- }
- else
- {
- Puts("No memory!");
- exit(20);
- }
-
- Result = FindFirst( pat, Anchor);
-
- while ( Result == 0 )
- {
- Printf("%s", Anchor->ua_AP.ap_Buf); /* Display name */
-
- if (Anchor->ua_AP.ap_Info.fib_DirEntryType >= 0)
- Puts( "\t(dir)" ); /* Display type */
- else
- Puts(""); /* Just a newline */
- Result = FindNext( Anchor );
- }
-
- /* Free the Anchor chain built by the above functions */
- FreeAnchorChain( Anchor );
-
- /* Finally, check the result - if it is ERROR_NO_MORE_ENTRIES then
- * we are exiting normally, otherwise, it is either a ^C break
- * or an actual error of some kind.
- */
- if (Result == ERROR_BREAK) /* Control 'C' */
- {
- if ( Anchor->ua_AP.ap_FoundBreak & SIGBREAKF_CTRL_C)
- Puts("***Break on '^C'");
- else
- Puts("***Break on '^D'");
- }
- else if (Result == ERROR_OBJECT_NOT_FOUND)
- {
- Printf("Can't find %s\n", pat);
- exit(20);
- }
- else if (Result == ERROR_BUFFER_OVERFLOW)
- {
- Puts("I should have allocated a larger buffer. Sorry!");
- exit(20);
- }
- else if (Result != ERROR_NO_MORE_ENTRIES)
- {
- Puts("An IO error occured!");
- Printf("%ld\n", Result);
- exit(20);
- }
- /* else */
- exit(0);
- }
-
-