

			     [43m  Change Default Tool  [0m

				 by Geoff Farrell



   Ed: Here's a first attempt at ARexx and it's a very useful one too, and
  with a lot of good info on using ARexx in this doc. Only use this program
  on a copy of Megadisc, by the way, it changes the disk.


[32m   ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[


   I have an Amiga 2000HD with 3Mb of RAM and have found it wastes a lot of
  time when the system uses ':c/fullview' every time I read an article on
  MegaDisc.  First it loads 'fullview' from the MD, then it loads the article
  from MD.  This happens for every article.  My solution is to diskcopy df0:
  to rad: and operate from there, where 'fullview' loads more rapidly from
  rad:.  But that does not help those without the extra RAM to get around the
  problem.  The answer would be to have the MD files use 'fullview' from ram:
  but that would require all the MD doc files to have 'ram:fullview' as the
  default tool in their icon file.  To change them manually would be a pain,
  so I developed ChangeDefaultTool.rexx to do the job.

   Why AREXX?  Well, I have read a lot of articles on AREXX, but have rarely
  seen any examples that actually do anything.  Most articles have talked
  about the principles but have left the application for the reader.  So when
  I experienced the problem with using 'fullview' on MD, I decided to develop
  an application using AREXX, from the point of view that you will learn very
  little about any programming language unless you actually program something
  with it.  This program could have been written in any language - there's
  nothing special about it that demands AREXX be used, and that's probably
  one limitation of this example: it does not employ inter-process
  communication, which is what AREXX is really intended for.  All it does is
  process AmigaDOS files from the CLI, something any program written in Basic
  or C could do.  However, you have to start somewhere, and as a first
  attempt at programming in AREXX, it taught me a lot - especially
  interpreting Commodore's AREXX manual (V2.04). This program does illustrate
  some powerful features of AREXX.  I am impressed with the ease of the
  AmigaDOS access it provides and also with its handling of strings.
  However, I must make one caveat: the program writes to the disk in df0:, so
  DO NOT USE IT WITH YOUR ORIGINAL MD - use a copy instead, just in case.

   The accompanying ChangeDefaultTool.rexx is fairly well commented, so I
  will give a general description of its operation, concentrating more on the
  AREXX instructions than on the program's structure.  The first line uses
  the 'Show' function to check if the 'rexxsupport.library' is available.  If
  not, it is added to the system using the addlib function.  The library is
  needed for the AmigaDOS functions.  Next, the TRACE command is commented
  out, but it would be very instructive to uncomment it, run the program and
  watch the variables change as the program progresses.  The trace function
  is quite informative and I found many errors during development by using
  it.  This is where I learnt about the instructions by trial and error when
  misinterpreting the manual.

   The next section initialises variables for keeping track of the
  directories found on the disk and on which level they are found.  For
  example, if a disk in df0: contained the following directories, sub-
  directories and files, the variables would relate as shown:

       Level 1 Level 2         Level 3         Level 4
       -----------------------------------------------------------
       df0:    Articles        MegaBites
			       Hints & Tips
			       etc
       -----------------------------------------------------------
	       c	       fullview
       -----------------------------------------------------------
	       Hardware        FixHardDisk
			       FixMonitor
			       etc
       -----------------------------------------------------------
	       Programs        SysInfo         SysInfo
					       SysInfo_doc
       -----------------------------------------------------------
			       EasyAccess      EasyAccess
					       EasyAccess_doc
       -----------------------------------------------------------
			       etc             etc
       -----------------------------------------------------------
	       Editorial
	       ..files
	       etc
       -----------------------------------------------------------

   In Level 1, 'df0:' is the only directory, so the program starts out with
  Dir.Level = 'df0:' and the remaining directories, RemDirs.Level = ""
  (NULL).  This is used later to detect when all the files on the disk have
  been done and to exit the program.  The use of compound variables
  illustrates the ease with which AREXX handles multi-dimensional arrays.
  On entering the main loop, the 'showdir' function is used to get both
  directories and files by using the 'd' or 'f' arguments.  The last ';'
  argument causes the names to be separated by a semi-colon in either
  'Directories' or 'Filenames'.  In our example disk above, the 'showdir'
  function would produce:

Directories = "Articles;c;Hardware;Programs" and
Filenames = Articles.info;Editorial;Editorial.info;Hardware.info;
		Programs.info;Disk.info;..etc".

   The program then checks if any filenames were found, and if so, enters the
  function 'StripFiles' to remove any drawer icon files (eg Articles.info),
  Disk icon files (Disk.info) and any non-icon files (eg Editorial).  This
  leaves only .info files that could have ':c/fullview' specified as the
  default tool.  If any filenames survive that screening, they are passed to
  the function 'ChangeInfo' where the default tool is change from
  ':c/fullview' or ':c/FullView' to 'ram:fullview'.  (Alternatively, you
  could change the first few lines of the ChangeInfo function to scan for
  'c:fullview' or 'c:Fullview' and change it to ':c/fullview' to correct for
  little errors which sometimes creep into otherwise faultless editions of
  MegaDisc.)

   If any names remain in 'Directories' then the program advances to the next
  Level and repeats the process with 'df0:Articles', looking for further
  sub-directories and files.  The process continues until all directories and
  files are done.  To get the next level's pathname, the 'parse' instruction
  is used to extract the first name from the 'Directories' string and place
  it in the 'SubDir' string.  Again, the ';' character is specified to denote
  the end of each sub-string in 'Directories'.  The remaining names in
  'Directories' at that stage are stored in 'RemDirs.Level', which keeps
  track of the remaining directories yet to do at that level.  The 'SubDir'
  string is added to the previous level's 'Dir.Level' to build up the
  pathname for the next directory.  The program exits when the 'Directories'
  and 'RemDirs.Level' variables are empty, ie all the directories and files
  are done.

   The 'StripFiles' and 'ChangeInfo' functions use the string manipulating
  features of AREXX and file-handling functions, so are worth mentioning.
  'StripFiles' uses the 'parse' instruction to get a directory name, and adds
  a '.info' suffix to build a directory icon name, 'SDir'.  The LENGTH
  function finds the length of the 'SDir' name, while the INDEX function is
  used to search for a match of 'SDir' in 'Files'.  If found, the DELSTR
  function is used to remove 'SDir' from 'Files', using its Position as found
  by INDEX(), and its length as found by LEN().  The same functions are used
  to remove the 'Disk.info' and '.info' filenames from 'Files'.  INDEX() is
  used to find instances of '.info' in the names and LASTPOS() finds the
  start of the filename by searching back to the ';' separating character.
  Finally, SUBSTR() extracts the 'filename.info' from 'Files' and puts it in
  'NewFiles'.  The '||' operator concatenates the filenames as they are
  found.

   'ChangeInfo' uses a few other functions worthy of mention.  Those are the
  routines to access AmigaDos files, OPEN(), CLOSE(), READCH() and WRITECH(),
  and the string manipulation functions INDEX(), DELSTR() and INSERT().
  INDEX() searches for the default tool name to change, DELSTR() deletes it
  and INSERT() replaces it with the new one.  ChangeInfo starts by building
  the search strings FromStr1 and FromStr2 in the format used by AmigaDOS,
  where each filename is preceded by a byte holding its length (in this case,
  NumFrom) and terminated by a zero byte, Term.  It also builds the
  destination string, ToStr, in a similar manner.  The function D2C() is used
  here to convert a numerical quantity to a single byte, represented as an
  ASCII character.  The concatenation operator is then used to build the
  search strings as used by AmigaDOS.  A two-pass loop is then used to search
  for instances of both strings, and where found, replaced by the new string.

   That's about all that needs explaining.  Keep in mind that the method of
  changing the default tool filename in the .info file may very well be the
  'sledgehammer' method not quite sanctioned by Commodore, but it works.
  Thus it is reiterated - make changes to backup disks.  I make no claim for
  the programming methods used and would welcome suggestions on better ways
  of programming in AREXX.  Hopefully though, it will serve as useful a
  learning tool for MegaDisc readers as it did for me.



[32m   ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[ ]] 32 [[


