home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / util / batch / dosreqtools / dosextensions / requestersrc / rtfilerequest.c < prev    next >
C/C++ Source or Header  |  1994-11-26  |  10KB  |  366 lines

  1.  
  2. #include <dos/dos.h>
  3. #include <dos/rdargs.h>
  4. #include <clib/dos_protos.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <exec/lists.h>
  8.  
  9. #include <libraries/reqtools.h>
  10.  
  11. #include <functions.h>
  12.  
  13. static char version_string[] = "$VER: rtFileRequest 2.3 (16.11.94)";
  14.  
  15. char MyExtHelp[] =
  16. "\n"
  17. "Usage rtFileRequest\n"
  18. "\n"
  19. "  TITLE/A,DRAWER,FILE,PATTERN=PAT/K,NOBUFFER/S,MULTISELECT/S,SELECTDIRS/S,\n"
  20. "  SAVE/S,NOFILES/S,PATGAD/S,HEIGHT/N/K,OKTEXT/K,VOLUMEREQUEST/S,NOASSIGNS/S,\n"
  21. "  NODISKS/S,ALLDISKS/S,ALLOWEMPTY/S,BASENAME/S,POSITION = POS/K,TOPOFFSET=TOP/N/K,\n"
  22. "  LEFTOFFSET=LEFT/N/K,TO/K,PUBSCREEN/K\n"
  23. "\n"
  24. "Arguments:\n"
  25. "\n"
  26. "  TITLE   <text>- Requester window title.\n"
  27. "  DRAWER  <text>- Preload requester with this drawer.\n"
  28. "  FILE    <text>- Preload with DRAWER and this file.\n"
  29. "  PATTERN <text>- Use with PATGAD\n"
  30. "  NOBUFFER      - Do _not_ use a buffer to remember directory contents\n"
  31. "                   for the next time the file requester is used.\n"
  32. "  MULTISELECT   - Allow multiple files to be selected.\n"
  33. "  SELECTDIRS    - Allow selecting of dirs as well as files.\n"
  34. "  SAVE          - Set this if you are using the requester to save or\n"
  35. "                   delete something.  Double-clicking will be disabled\n"
  36. "                   so it is harder to make a mistake or select a wrong file.\n"
  37. "  NOFILES       - Select a directory rather than a file.\n"
  38. "  PATGAD        - Add pattern gadget to the requester.\n"
  39. "  HEIGHT  <num> - Suggested height of file requester window.\n"
  40. "  OKTEXT  <text>- Replacement text for \"Ok\" gadget, max 6 chars.\n"
  41. "  VOLUMEREQUEST - Turn the file requester into a volume/assign disk requester.\n"
  42. "                   This requester can be used to get a device name (\"DF0:\",\n"
  43. "                   \"DH1:\",..) or an assign (\"C:\", \"FONTS:\",...) from the user.\n"
  44. "  NOASSIGNS     - Do not include assigns in the list, only the real devices.\n"
  45. "  NODISKS       - Do not include devices, just show the assigns.\n"
  46. "  ALLDISKS      - Show _all_ devices.  Default behavior is to show only those\n"
  47. "                   devices which have valid disks inserted into them. So if\n"
  48. "                   you have no disk in drive DF0: it will not show up. Set\n"
  49. "                   this flag if you do want these devices included.\n"
  50. "  ALLOWEMPTY    - An empty file string will also be accepted and returned.\n"
  51. "  BASENAME      - Return root filename only.\n"
  52. "  POSITION    <pos> - Open requester window at <pos>.  Permissible values are:\n"
  53. " >or POS                CENTERSCR, TOPLEFTSCR, CENTERWIN, TOPLEFTWIN, POINTER.\n"
  54. "  TOPOFFSET   <num> - Offset position relative to above.\n"
  55. " >or TOP\n"
  56. "  LEFFTOFFSET <num> - Offset position relative to above.\n"
  57. " >or LEFT\n"
  58. "  TO         <file> - Send result to <file>.\n"
  59. "  PUBSCREEN <screen>- Public screen name.\n";
  60.  
  61. #define TEMPLATE "TITLE/A,DRAWER,FILE,PATTERN=PAT/K,NOBUFFER/S,MULTISELECT/S,SELECTDIRS/S,SAVE/S,NOFILES/S,PATGAD/S,HEIGHT/N/K,OKTEXT/K,VOLUMEREQUEST/S,NOASSIGNS/S,NODISKS/S,ALLDISKS/S,ALLOWEMPTY/S,BASENAME/S,POSITION=POS/K,TOPOFFSET=TOP/N/K,LEFTOFFSET=LEFT/N/K,TO/K,PUBSCREEN/K"
  62.  
  63. #define OPT_TITLE 0
  64. #define OPT_DRAWER 1
  65. #define OPT_FILE 2
  66. #define OPT_PATTERN 3
  67. #define OPT_NOBUFFER 4
  68. #define OPT_MULTISELECT 5
  69. #define OPT_SELECTDIRS 6
  70. #define OPT_SAVE 7
  71. #define OPT_NOFILES 8
  72. #define OPT_PATGAD 9
  73. #define OPT_HEIGHT 10
  74. #define OPT_OKTEXT 11
  75. #define OPT_VOLUMEREQUEST 12
  76. #define OPT_NOASSIGNS 13
  77. #define OPT_NODISKS 14
  78. #define OPT_ALLDISKS 15
  79. #define OPT_ALLOWEMPTY 16
  80. #define OPT_BASENAME 17
  81. #define OPT_POSITION 18
  82. #define OPT_TOPOFFSET 19
  83. #define OPT_LEFTOFFSET 20
  84. #define OPT_TO 21
  85. #define OPT_PUBSCREEN 22
  86. #define OPT_COUNT 23
  87.  
  88. struct Library *ReqToolsBase;
  89.  
  90. int
  91. main (int argc, char **argv)
  92. {
  93.   int retval = 0;
  94.  
  95.   if (argc)
  96.     {
  97.       if ((argc == 2) && (stricmp (argv[1], "HELP") == 0))
  98.     {
  99.       fprintf (stdout, "%s", MyExtHelp);
  100.     }
  101.       else
  102.     {
  103.       /* My custom RDArgs */
  104.       struct RDArgs *myrda;
  105.  
  106.       /* Need to ask DOS for a RDArgs structure */
  107.       if (myrda = (struct RDArgs *) AllocDosObject (DOS_RDARGS, NULL))
  108.         {
  109.           /*
  110.            * The array of LONGs where ReadArgs() will store the data from
  111.            * the command line arguments.  C guarantees that all the array
  112.            * entries will be set to zero.
  113.            */
  114.           LONG *result[OPT_COUNT] =
  115.           {NULL};
  116.  
  117.           /* parse my command line */
  118.           if (ReadArgs (TEMPLATE, result, myrda))
  119.         {
  120.           if (ReqToolsBase = (struct Library *) OpenLibrary ("reqtools.library", LIBRARY_MINIMUM))
  121.             {
  122.               struct rtFileRequester *requester;
  123.  
  124.               if (requester = (struct rtFileRequester *) rtAllocRequest (RT_FILEREQ, NULL))
  125.             {
  126.  
  127.               char filename[256];
  128.  
  129.               if (result[OPT_DRAWER])
  130.                 rtChangeReqAttr (requester, RTFI_Dir, result[OPT_DRAWER], TAG_END);
  131.  
  132.               strcpy (filename, ((result[OPT_FILE]) ? (char *) result[OPT_FILE] : ""));
  133.  
  134.               if (result[OPT_PATTERN])
  135.                 rtChangeReqAttr (requester, RTFI_MatchPat, result[OPT_PATTERN], TAG_END);
  136.  
  137.               /*
  138.                * Take care of requester positioning -
  139.                * These flags common to most rt requesters
  140.                */
  141.               if (stricmp (result[OPT_POSITION], "CENTERSCR") == 0)
  142.                 requester->ReqPos = REQPOS_CENTERSCR;
  143.               else if (stricmp (result[OPT_POSITION], "TOPLEFTSCR") == 0)
  144.                 requester->ReqPos = REQPOS_TOPLEFTSCR;
  145.               else if (stricmp (result[OPT_POSITION], "CENTERWIN") == 0)
  146.                 requester->ReqPos = REQPOS_CENTERWIN;
  147.               else if (stricmp (result[OPT_POSITION], "TOPLEFTWIN") == 0)
  148.                 requester->ReqPos = REQPOS_TOPLEFTWIN;
  149.               else
  150.                 requester->ReqPos = REQPOS_POINTER;
  151.  
  152.               /*
  153.                * take care of some rtFileRequest () specific flags
  154.                */
  155.               requester->Flags =
  156.                 ((result[OPT_NOBUFFER]) ? FREQF_NOBUFFER : NULL) |
  157.                 ((result[OPT_MULTISELECT]) ? FREQF_MULTISELECT : NULL) |
  158.                 ((result[OPT_SELECTDIRS]) ? FREQF_SELECTDIRS : NULL) |
  159.                 ((result[OPT_SAVE]) ? FREQF_SAVE : NULL) |
  160.                 ((result[OPT_NOFILES]) ? FREQF_NOFILES : NULL) |
  161.                 ((result[OPT_PATGAD]) ? FREQF_PATGAD : NULL);
  162.  
  163.               {
  164.                 struct Process *process = (struct Process *) FindTask (NULL);
  165.                 APTR windowptr = process->pr_WindowPtr;
  166.  
  167.                 APTR func_return;
  168.  
  169.                 /*
  170.                  * Tags will be used to take care ofattributes not directly
  171.                  * settable in the rtReqInfo structure
  172.                  */
  173.  
  174.                 retval = (func_return = (APTR) rtFileRequest (requester, filename, result[OPT_TITLE],
  175.  
  176.                 /*
  177.                  * Set some rtFileRequest() requrster specific tags
  178.                  */
  179.             (result[OPT_VOLUMEREQUEST]) ? RTFI_VolumeRequest : TAG_IGNORE,
  180.              ((result[OPT_NOASSIGNS]) ? VREQF_NOASSIGNS : NULL) |
  181.              ((result[OPT_NODISKS]) ? VREQF_NODISKS : NULL) |
  182.              ((result[OPT_ALLDISKS]) ? VREQF_ALLDISKS : NULL),
  183.  
  184.  
  185.  
  186.             (result[OPT_HEIGHT]) ? RTFI_Height : TAG_IGNORE,
  187.                          *result[OPT_HEIGHT],
  188.             (result[OPT_OKTEXT]) ? RTFI_OkText : TAG_IGNORE,
  189.                          result[OPT_OKTEXT],
  190.  
  191.             (result[OPT_ALLOWEMPTY]) ? RTFI_AllowEmpty : TAG_IGNORE,
  192.                          TRUE,
  193.                 /*
  194.                  * Finally,
  195.                  * set some more general tags shared by most requesters
  196.                  */
  197.  
  198.             RT_Underscore, '_',
  199.  
  200.             (result[OPT_TOPOFFSET]) ? RT_TopOffset : TAG_IGNORE,
  201.                          *result[OPT_TOPOFFSET],
  202.             (result[OPT_LEFTOFFSET]) ? RT_LeftOffset : TAG_IGNORE,
  203.                              *result[OPT_LEFTOFFSET],
  204.             (windowptr) ? RT_Window : TAG_IGNORE,
  205.                         windowptr,              
  206.             (result[OPT_PUBSCREEN]) ? RT_PubScrName : TAG_IGNORE,
  207.                         result[OPT_PUBSCREEN],
  208.             TAG_END)) ? 0 : 10;
  209.  
  210.                 if ((func_return) && (result[OPT_MULTISELECT]))
  211.                   {
  212.                 char buf[512];
  213.  
  214.                 {
  215.                   int i;
  216.  
  217.                   struct rtFileList *file_list;
  218.  
  219.                   strcpy (buf, "");    /* initialize buffer */
  220.  
  221.                   for (file_list = (struct rtFileList *) func_return, i = 0;
  222.                        file_list;
  223.                        file_list = file_list->Next, i++)
  224.                     {
  225.                       if (strchr (file_list->Name, ' '))
  226.                     strcat (buf, "\"");
  227.  
  228.                       strcat (buf, file_list->Name);
  229.  
  230.                       if (strchr (file_list->Name, ' '))
  231.                     strcat (buf, "\"");
  232.  
  233.                       strcat (buf, " ");
  234.                     }
  235.                 }
  236.  
  237.                 if (result[OPT_TO])
  238.                   {
  239.                     FILE *file;
  240.  
  241.                     if (file = fopen (result[OPT_TO], "w"))
  242.                       {
  243.                     fprintf (file, "%s\000", buf);
  244.                     fclose (file);
  245.                       }
  246.                     else
  247.                       {
  248.