home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / amiga / programm / 17572 < prev    next >
Encoding:
Text File  |  1992-12-21  |  3.1 KB  |  96 lines

  1. Path: sparky!uunet!cs.utexas.edu!usc!hela.iti.org!cs.widener.edu!dsinc!bagate!cbmvax!jesup
  2. From: jesup@cbmvax.commodore.com (Randell Jesup)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: AmigaDos Assign command
  5. Message-ID: <37922@cbmvax.commodore.com>
  6. Date: 15 Dec 92 21:30:23 GMT
  7. References: <ianm.03r4@laghey.UUCP>
  8. Reply-To: jesup@cbmvax.commodore.com (Randell Jesup)
  9. Organization: Commodore, West Chester, PA
  10. Lines: 84
  11.  
  12. ianm@laghey.UUCP (Ian Moran) writes:
  13. >I have noticed strange behaviour with the 'assign' command under 2.04 and
  14. >above. If I take advantage of the multiple assign facility thus :
  15. >
  16. > assign rexx: s: dh0:turbotext/rexx
  17. >
  18. >Then Arexx macros will not be located under Turbotext which is contrary to
  19. >what I would expect, only s: is searched.
  20.  
  21.     Instead of trying to Lock() or Open() "rexx:<file>", it's Lock()ing
  22. rexx:, CurrentDir()ing to it, then trying to Open() <file>.  Lock() will
  23. give you a lock on the first directory.  If searching for a specific item,
  24. use AddPart() to build a full path first.
  25.  
  26. >Also, why do few (if any) file requesters follow multiple assigned
  27. >paths similar to the above. If I enter rexx: in the C= requester then I will
  28. >get only the contents of s:
  29.  
  30.     How I would handle doing something to each entry in an assign (multi-
  31. assign or not): 
  32.  
  33. BOOL do_something_to_all (char *path, BOOL (*function)(BPTR lock))
  34. {
  35.     struct DeviceProc *dp = NULL;
  36.     struct MsgPort *old_fsport;
  37.     BPTR lock, old_curdir;
  38.     char *remainder;
  39.     LONG err;
  40.  
  41.     // NOTE: not strrchr - PathMan has files with ':'s in them
  42.     remainder = strchr(path,':');
  43.     if (remainder == NULL)
  44.         remainder = path;
  45.     else
  46.         remainder++;    /* point past ':' */
  47.  
  48.     while (1) {
  49.         dp = GetDeviceProc(path,dp);
  50.         if (!dp)
  51.         {    /* getdevproc freed dp for us */
  52.             // NOTE: 2.04 and 3.0 have a bug, and never return
  53.             // ERROR_NO_MORE_ENTRIES.  Accept 0 as no error as well
  54.             // This will be fixed next release.
  55.             err = IoErr();
  56.             if (err == 0 || err == ERROR_NO_MORE_ENTRIES)
  57.                 return TRUE;    // all done
  58.             else
  59.                 return FALSE;    // never found anything
  60.         }
  61.         /* save filesystem port pointer, set default FS to target */
  62.         old_fsport = SetFileSysTask(dp->dvp_Port);
  63.         old_curdir = CurrentDir(dp->dvp_Lock);       // may be NULL
  64.  
  65.         /* we have an entry, get a lock on the remainder of path */
  66.         lock = Lock(remainder,SHARED_LOCK);
  67.  
  68.         /* reset filesystem port and current dir */
  69.         (void) SetFileSysTask(old_fsport);
  70.         (void) CurrentDir(old_curdir);
  71.  
  72.         /* we got a lock on it, call user function.  Function can */
  73.         /* return FALSE to stop the scan. */
  74.         if (!lock || !(*function)(lock))
  75.         {
  76.             UnLock(lock);        // NULL is safe
  77.             FreeDeviceProc(dp);
  78.             return FALSE;
  79.         }
  80.         UnLock(lock);
  81.     }
  82. }
  83.  
  84.     Warning: that was written off the top of my head, but I do have the
  85. source code for reference.  Also, at least one developer has used this and
  86. it works.
  87.  
  88.     The person keeping the FAQ might want to add this...
  89.  
  90. -- 
  91. To be or not to be = 0xff
  92. -
  93. Randell Jesup, Jack-of-quite-a-few-trades, Commodore Engineering.
  94. {uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.cbm.commodore.com  BIX: rjesup  
  95. Disclaimer: Nothing I say is anything other than my personal opinion.
  96.