home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / obero / oberon-a / source / od / od.mod < prev    next >
Encoding:
Text File  |  1994-09-03  |  4.9 KB  |  203 lines

  1. (*************************************************************************
  2.  
  3.      $RCSfile: OD.mod $
  4.   Description: The Oberon-A module definition utility.
  5.  
  6.    Created by: fjc (Frank Copeland)
  7.     $Revision: 1.5 $
  8.       $Author: fjc $
  9.         $Date: 1994/09/03 16:29:42 $
  10.  
  11.   Copyright © 1994, Frank Copeland.
  12.   This file is part of Oberon-A.
  13.   See Oberon-A.doc for conditions of use and distribution.
  14.  
  15.   Log entries are at the end of the file.
  16.  
  17. *************************************************************************)
  18.  
  19. MODULE OD;
  20.  
  21. (*
  22. ** $C= CaseChk       $I= IndexChk  $L= LongAdr   $N= NilChk
  23. ** $P- PortableCode  $R= RangeChk  $S= StackChk  $T= TypeChk
  24. ** $V= OvflChk       $Z= ZeroVars
  25. *)
  26.  
  27. IMPORT
  28.   SYS := SYSTEM,
  29.   ODRev,
  30.   Errors,
  31.   e := Exec,
  32.   u := Utility,
  33.   d := Dos,
  34.   str := Strings,
  35.   ODT;
  36.  
  37. CONST
  38.  
  39.   CopyrightStr = "Copyright © 1994 Frank Copeland\n";
  40.   UsageStr     = "See OD.doc for conditions of use\n";
  41.  
  42. CONST
  43.  
  44.   template = "FROM/A/M,TO/K,VERBOSE/S";
  45.   optFrom = 0;
  46.   optTo = 1;
  47.   optVerbose = 2;
  48.   optCount = 3;
  49.  
  50. TYPE
  51.  
  52.   StringArray = CPOINTER TO ARRAY 32767 OF e.STRPTR;
  53.  
  54. VAR
  55.  
  56.   rdArgs    : d.RDArgsPtr;
  57.   fromArray : StringArray;
  58.   toDir     : e.STRPTR;
  59.  
  60.  
  61. (* -------------------------------------
  62. **
  63. ** Writes a string to the standard output stream.
  64. ** This is OS 1.3 compatible, because it will be used
  65. ** to tell people they can't use OD on that version of
  66. ** the OS :-)
  67. *)
  68.  
  69. PROCEDURE PutStr ( str : ARRAY OF CHAR );
  70. (* $D- Don't copy open arrays *)
  71. BEGIN (* PutStr *)
  72.   SYS.SETREG (0, d.base.Write (d.base.Output(), str, SYS.STRLEN (str)))
  73. END PutStr;
  74.  
  75. (*------------------------------------*)
  76. PROCEDURE* Cleanup ();
  77.  
  78. BEGIN (* Cleanup *)
  79.   IF rdArgs # NIL THEN d.base.FreeArgs (rdArgs) END
  80. END Cleanup;
  81.  
  82. (*------------------------------------*)
  83. PROCEDURE Init ();
  84.  
  85. BEGIN (* Init *)
  86.   IF d.base.version >= 37 THEN
  87.     rdArgs := NIL; fromArray := NIL; toDir := NIL;
  88.     SYS.SETCLEANUP (Cleanup)
  89.   ELSE
  90.     PutStr (" !! OD requires OS release 2.04 or greater\n");
  91.     HALT (d.returnWarn)
  92.   END
  93. END Init;
  94.  
  95. (*------------------------------------*)
  96. PROCEDURE GetArgs ();
  97.  
  98.   VAR
  99.     argArray  : ARRAY optCount OF SYS.LONGWORD;
  100.     i : INTEGER;
  101.  
  102. BEGIN (* GetArgs *)
  103.   FOR i := 0 TO optCount - 1 DO argArray [i] := NIL END;
  104.   rdArgs := d.base.ReadArgs (template, argArray, NIL);
  105.   IF rdArgs # NIL THEN
  106.     (*
  107.     ** fromArray is guaranteed to contain something, because of the /A
  108.     ** toDir can be NIL
  109.     *)
  110.     fromArray := SYS.VAL (StringArray, argArray [optFrom]);
  111.     toDir := SYS.VAL (e.STRPTR, argArray [optTo]);
  112.     ODT.verbose := (SYS.VAL (LONGINT, argArray [optVerbose]) # 0)
  113.   ELSE
  114.     IF d.base.PrintFault (d.base.IoErr(), " !! ") THEN END;
  115.     HALT (d.returnError)
  116.   END
  117. END GetArgs;
  118.  
  119. (*------------------------------------*)
  120. PROCEDURE Main ();
  121.  
  122.   VAR
  123.     i : INTEGER;
  124.     pat : e.STRPTR; modName : ARRAY 32 OF CHAR;
  125.     myAnchor : d.AnchorPathPtr; result : LONGINT;
  126.     fileName : ARRAY 256 OF CHAR;
  127.  
  128. BEGIN (* Main *)
  129.   (* myAnchor is allocated because it must be longword aligned *)
  130.   (* $Z+ make sure it is zeroed *)NEW (myAnchor);(* $Z= *)
  131.   myAnchor.strlen := SHORT (LEN (myAnchor.buf));
  132.   i := 0;
  133.   LOOP
  134.     (*
  135.     ** fromArray is an array of pointers to strings, each string
  136.     ** being a file name or an AmigaDOS pattern. The last entry
  137.     ** NIL.
  138.     *)
  139.     pat := fromArray [i];
  140.     IF pat = NIL THEN EXIT END;
  141.     (* Find the first file matching the pattern *)
  142.     result := d.base.MatchFirst (pat^, myAnchor^);
  143.     WHILE result = 0 DO
  144.       (* Process the symbol file *)
  145.       ODT.Init ();
  146.       IF ODT.Import (myAnchor.buf, modName) THEN
  147.         IF toDir # NIL THEN COPY (toDir^, fileName)
  148.         ELSE fileName := ""
  149.         END;
  150.         IF d.base.AddPart (fileName, modName, LEN (fileName)) THEN
  151.           str.Append (fileName, ".Def");
  152.           ODT.Export (fileName, modName)
  153.         ELSE
  154.           PutStr (" !! Could not construct file name\n");
  155.           HALT (d.returnError)
  156.         END;
  157.       ELSE
  158.         (* The cause of the error is already reported by Import() *)
  159.         HALT (d.returnError)
  160.       END;
  161.       ODT.Close ();
  162.       SYS.GC;
  163.       (* Get the next matching file *)
  164.       result := d.base.MatchNext (myAnchor^)
  165.     END;
  166.     d.base.MatchEnd (myAnchor^); (* Clean up anchor data *)
  167.     INC (i)
  168.   END;
  169. END Main;
  170.  
  171. BEGIN (* OD *)
  172.   PutStr (ODRev.vString);
  173.   PutStr (CopyrightStr);
  174.   PutStr (UsageStr);
  175.   PutStr ("\n");
  176.   Init ();
  177.   GetArgs ();
  178.   Main ();
  179.   PutStr ("\x9B\x4B !! All done\n")
  180. END OD.
  181.  
  182. (*************************************************************************
  183.  
  184.   $Log: OD.mod $
  185.   Revision 1.5  1994/09/03  16:29:42  fjc
  186.   - Uses version string from ODRev.
  187.  
  188.   Revision 1.4  1994/08/08  16:36:15  fjc
  189.   Release 1.4
  190.  
  191.   Revision 1.3  1994/07/22  13:56:21  fjc
  192.   - Bumped version number.
  193.  
  194.   Revision 1.2  1994/07/10  12:34:21  fjc
  195.   - Added check for dos.library V37+
  196.   - General tidy up
  197.  
  198.   Revision 1.1  1994/07/09  21:55:50  fjc
  199.   Initial revision
  200.  
  201. *************************************************************************)
  202.  
  203.