home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / ii-43 / split.c < prev   
C/C++ Source or Header  |  1996-01-30  |  4KB  |  118 lines

  1. ;/* Split.c - AmigaMail SplitName() example.  Compiled with SAS/C 6.56.
  2. sc NMINC STRMERGE NOSTKCHK NODEBUG DATA=FAR IGNORE=73 Split.c
  3. slink from Split.o to Split lib lib:amiga.lib ; if you don't have pragmas
  4. quit
  5. * Tuesday, 16-Jul-91 12:15:49, Ewout
  6. *
  7. *
  8. */
  9. /*
  10. Copyright (c) 1991 Commodore-Amiga, Inc.
  11.  
  12. This example is provided in electronic form by Commodore-Amiga,
  13. Inc. for use with the Amiga Mail Volume II technical publication.
  14. Amiga Mail Volume II contains additional information on the correct
  15. usage of the techniques and operating system functions presented in
  16. these examples.  The source and executable code of these examples may
  17. only be distributed in free electronic form, via bulletin board or
  18. as part of a fully non-commercial and freely redistributable
  19. diskette.  Both the source and executable code (including comments)
  20. must be included, without modification, in any copy.  This example
  21. may not be published in printed form or distributed with any
  22. commercial product. However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga
  25. computers.
  26.  
  27. All other rights reserved.
  28.  
  29. This example is provided "as-is" and is subject to change; no
  30. warranties are made.  All use is at your own risk. No liability or
  31. responsibility is assumed.
  32. */
  33.  
  34. #include <exec/memory.h>
  35. #include <dos/dosextens.h>
  36. #include <dos/rdargs.h>
  37.  
  38. #include <clib/exec_protos.h>
  39. #include <clib/dos_protos.h>
  40.  
  41. /* def PRAGMAS if you have them */
  42. /* #define PRAGMAS */
  43. #ifdef PRAGMAS
  44. #include <pragmas/exec_pragmas.h>
  45. #include <pragmas/dos_pragmas.h>
  46. #else
  47. struct ExecBase *SysBase;
  48. struct DosLibrary *DOSBase;
  49.  
  50. #endif
  51.  
  52. #define BUFFERSIZE      128
  53.  
  54. VOID            main(VOID);
  55.  
  56. VOID
  57. main(VOID)
  58. {
  59. #ifdef PRAGMAS
  60.     struct DosLibrary *DOSBase;
  61.  
  62. #endif
  63.     struct RDArgs  *readargs;
  64.     LONG            rargs[2];
  65.     UBYTE          *filename, *buffer;
  66.     ULONG           buffersize;
  67.     WORD            position = 0;
  68.     LONG            vargs[4];
  69.  
  70. #ifndef PRAGMAS
  71.     /* set up SysBase */
  72.     SysBase = (*((struct Library **) 4));
  73. #endif
  74.  
  75.     /* Fail silently if < 37 */
  76.     if (DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37))
  77.     {
  78.  
  79.         /* See the DOS Autodocs for more information about ReadArgs() */
  80.         if (readargs = ReadArgs("FILE/A,BUFFERSIZE/A/N", rargs, NULL))
  81.         {
  82.             filename = (UBYTE *) rargs[0];
  83.             buffersize = *((LONG *) rargs[1]);
  84.             if (buffersize < 1 || buffersize > 4096)
  85.                 buffersize = BUFFERSIZE;
  86.  
  87.             if (buffer = AllocMem(buffersize, MEMF_CLEAR))
  88.             {
  89.                 position = SplitName(filename, ':', buffer, position, buffersize);
  90.  
  91.                 vargs[0] = position;
  92.                 vargs[1] = (LONG) buffer;
  93.                 VFPrintf(Output(), "Devicename: position: %ld Buffer: %s\n", vargs);
  94.  
  95.                 if (position == -1)
  96.                     position = 0;
  97.  
  98.                 do
  99.                 {
  100.                     position =
  101.                         SplitName(filename, '/', buffer, position, buffersize);
  102.                     vargs[0] = position;
  103.                     vargs[1] = (LONG) buffer;
  104.                     VFPrintf(Output(),
  105.                              "Path component: position: %ld Buffer: %s\n",
  106.                              vargs);
  107.                 } while (position != -1);
  108.                 FreeMem(buffer, buffersize);
  109.             }
  110.             FreeArgs(readargs);
  111.  
  112.         }
  113.         else
  114.             PrintFault(IoErr(), NULL);
  115.         CloseLibrary((struct Library *) DOSBase);
  116.     }
  117. }
  118.