home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0938.lha / Angie / ImportedModules.lha / SPrintf.mod < prev   
Text File  |  1993-09-07  |  6KB  |  165 lines

  1. (* ------------------------------------------------------------------------
  2.   :Program.       SPrintf.mod
  3.   :Contents.      var args sprintf for Amiga-Oberon
  4.   :Author.        Franz Schwarz
  5.   :Copyright.     Public Domain
  6.   :Language.      Oberon-2
  7.   :Translator.    Amiga Oberon 3.00
  8.   :History.       SPrintf.mod 1.0 (7.9.93) fSchwarz
  9.   :Address.       Mⁿhlenstra▀e 2, D-78591 Durchhausen, Germany / R.F.A.
  10.   :Address.       uucp: Franz.Schwarz@mil.ka.sub.org; Fido: 2:241/7506.18
  11.   :Remark.        As of Amiga Oberon Release 3.00: possible odd pointers to
  12.   :Remark.        array of char/byte: _don't_ compile with OddChk. The
  13.   :Remark.        compiler's options stack is broken as of Amiga-Oberon 3.00
  14. --------------------------------------------------------------------------- *)
  15.  
  16.  
  17. MODULE SPrintf;
  18.  
  19. IMPORT 
  20.   e := Exec, y := SYSTEM;
  21.  
  22. TYPE
  23.   FakeBasePtr = UNTRACED POINTER TO FakeBase;
  24.  
  25.   FakeBase = STRUCT
  26.     code1 : LONGINT;
  27.     jmp1  : e.PROC;
  28.   END;
  29.   
  30. CONST
  31.   fkBase = FakeBase (4E714EF9H, NIL);
  32.                  (* nop                *
  33.                   * jmp    0x00000000  *)
  34.  
  35. VAR
  36.   FkBase : FakeBasePtr;
  37.   FkBaseS: FakeBase;
  38.  
  39.  
  40. (****** SPrintf/SPrintf ****************************************************
  41. *
  42. *   NAME
  43. *       SPrintf -- varargs sprintf output formatting using Exec.RawDoFmt
  44. *       SPrintF -- varargs sprintf output formatting without result code
  45. *       VSPrintf -- vector sprintf output formatting using Exec.RawDoFmt
  46. *       VSPrintF -- vector sprintf output formatting without result code
  47. *
  48. *   SYNOPSIS
  49. *       SPrintf (buffer: ARRAY OF CHAR;
  50. *                format: ARRAY OF CHAR;
  51. *                args..: Exec.APTR     ): LONGINT;
  52. *
  53. *       SPrintF (buffer: ARRAY OF CHAR;
  54. *                format: ARRAY OF CHAR;
  55. *                args..: Exec.APTR     );
  56. *
  57. *       VSPrintf (buffer: ARRAY OF CHAR;
  58. *                 format: ARRAY OF CHAR;
  59. *                 args  : Exec.APTR     ): LONGINT;
  60. *
  61. *       VSPrintF (buffer: ARRAY OF CHAR;
  62. *                 format: ARRAY OF CHAR;
  63. *                 args  : Exec.APTR     );
  64. *
  65. *   FUNCTION
  66. *       These functions are full featured implementations of sprintf()/
  67. *       vsprintf(), supporting also the nifty varargs paramters provided
  68. *       by Amiga-Oberon for library calls. Due to the fact that these
  69. *       functions are implemented as library functions, you may pass NIL
  70. *       for the buffer ARRAY OF CHAR parameter which makes this function
  71. *       doing nothing but returning the length WITHOUT the trailing null
  72. *       byte of the generated output.
  73. *
  74. *   INPUTS
  75. *       buffer   - the buffer into which the output is written or NIL
  76. *       format   - the format string with the formatting directives.
  77. *                  For a detailed description of all possible directives
  78. *                  have a look at Exec/RawDoFmt(). *ALL* directives
  79. *                  except of %s/%b require a leading 'l' right before the
  80. *                  type character, e.g. '%ld', '%08lx' or '%lc' instead of
  81. *                  '%d', '%08x' or '%c'. This is true for Dos/Printf() and
  82. *                  similar functions as well.
  83. *       args     - the arguments to be included into the generated
  84. *                  string according to the directives specified in the
  85. *                  format string. Either as varargs for SPrintf()/SPrintF()
  86. *                  or as a pointer to the arguemnts for VSPrintf()/
  87. *                  VSPrintF()
  88. *
  89. *   RESULT
  90. *      LONGINT   - the length of the generated output WITHOUT the trailing
  91. *                  null byte, which is actually written into the buffer
  92. *                  as the last byte.
  93. *
  94. *   SEE ALSO
  95. *       Exec/RawDoFmt(), Dos/Printf()
  96. *
  97. *****************************************************************************)
  98.  
  99. PROCEDURE SPrintf * {FkBase, 0} (buffer{11}: ARRAY OF CHAR;
  100.                                  format{8} : ARRAY OF CHAR;
  101.                                  args{9}.. : e.APTR        ): LONGINT;
  102.  
  103. PROCEDURE SPrintF * {FkBase, 0} (buffer{11}: ARRAY OF CHAR;
  104.                                  format{8} : ARRAY OF CHAR;
  105.                                  args{9}.. : e.APTR        );
  106.  
  107. PROCEDURE VSPrintf * {FkBase, 0} (buffer{11}: ARRAY OF CHAR;
  108.                                   format{8} : ARRAY OF CHAR;
  109.                                   args{9}   : e.APTR        ): LONGINT;
  110.  
  111. PROCEDURE VSPrintF * {FkBase, 0} (buffer{11}: ARRAY OF CHAR;
  112.                                   format{8} : ARRAY OF CHAR;
  113.                                   args{9}   : e.APTR        );
  114.  
  115. PROCEDURE SPrintFInternal();
  116. (* $EntryExitCode- *)                             
  117. BEGIN
  118.  
  119.   y.INLINE (048E7U,00032U,04FEFU,0FFF8U,02F4BU,00004U,04297U,0264FU,
  120.             045FAU,0001AU,02C79U,00000U,00004U,04EAEU,0FDF6U,02017U,
  121.             04FEFU,00008U,04CDFU,04C00U,05380U,04E75U,02F0CU,05293U,
  122.             04AABU,00004U,0670AU,0286BU,00004U,01880U,052ABU,00004U,
  123.             0285FU,04E75U                                           );
  124.  
  125.  
  126.  
  127. (*
  128.  * 00.00000000  48e7 0032                 MOVEM.L A2-A3/A6,-(A7)
  129.  * 00.00000004  4fef fff8                 LEA.L   fff8(A7),A7
  130.  * 00.00000008  2f4b 0004                 MOVE.L  A3,0004(A7)
  131.  * 00.0000000c  4297                      CLR.L   (A7)
  132.  * 00.0000000e  264f                      MOVEA.L A7,A3
  133.  * 00.00000010  45fa 001a                 LEA.L   002c(pc),A2
  134.  * 00.00000014  2c79 0000 0004            MOVEA.L 00000004,A6
  135.  * 00.0000001a  4eae fdf6                 JSR     fdf6(A6)
  136.  * 00.0000001e  2017                      MOVE.L  (A7),D0
  137.  * 00.00000020  4fef 0008                 LEA.L   0008(A7),A7
  138.  * 00.00000024  4cdf 4c00                 MOVEM.L (A7)+,A2-A3/A6
  139.  * 00.00000028  5380                      SUBQ.L  #1,D0
  140.  * 00.0000002a  4e75                      RTS
  141.  * 00.0000002c  2f0c                      MOVE.L  A4,-(A7)
  142.  * 00.0000002e  5293                      ADDQ.L  #1,(A3)
  143.  * 00.00000030  4aab 0004                 TST.L   0004(A3)
  144.  * 00.00000034  670a                      BEQ.B   00000040
  145.  * 00.00000036  286b 0004                 MOVEA.L 0004(A3),A4
  146.  * 00.0000003a  1880                      MOVE.B  D0,(A4)
  147.  * 00.0000003c  52ab 0004                 ADDQ.L  #1,0004(A3)
  148.  * 00.00000040  285f                      MOVEA.L (A7)+,A4
  149.  * 00.00000042  4e75                      RTS
  150.  *)
  151.  
  152. END SPrintFInternal;
  153.  
  154.  
  155. BEGIN
  156.   FkBaseS := fkBase;
  157.   FkBase := y.ADR (FkBaseS);
  158.   FkBase.jmp1 := SPrintFInternal;
  159.   IF e.exec.libNode.version >= 37 THEN e.CacheClearU(); END;
  160. CLOSE
  161.   (* nop *)
  162. END SPrintf.
  163.  
  164.  
  165.