home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / clarion / library / memoed / me_util.cla < prev    next >
Text File  |  1992-02-15  |  6KB  |  174 lines

  1.  
  2. !═════════════════════════════════════════════════════════════════════════
  3. !
  4. !  %%keyword%% '%n'
  5. !  'ME_UTIL.CLA' - Utility Library functions for MEMOEDIT
  6. !
  7. !  %%keyword%% '%v'
  8. !  Revision Number: '1'
  9. !  %%keyword%% '%d'
  10. !  Revision Date  : '15-Feb-92'
  11. !
  12. !  Copyright : Bobcat Systems (c) 1992
  13. !  Author    : Robert J. Pupazzoni
  14. !           CIS:[70441,204]
  15. !
  16. !  Compiler  : Clarion Professional Developer v. 2.1, Batch 2105
  17. !
  18. !
  19. !  DESCRIPTION
  20. !
  21. !    This module contains various generic funcitons used in MEMOEDIT.
  22. !
  23. !═════════════════════════════════════════════════════════════════════════
  24.  
  25. ME_Util         MEMBER()
  26.  
  27. ! ═════════════════════════════════════════════════════════════════════════
  28. !                 Find Next Word Left
  29. ! ═════════════════════════════════════════════════════════════════════════
  30. Word_Left    FUNCTION( sLine, ibCol )
  31.  
  32.          ! Parameters:
  33. sLine         STRING(255)             ! Line of text
  34. ibCol         BYTE                 ! Column to start in
  35.  
  36.          ! Locals:
  37. aLine         BYTE,DIM(255),OVER(sLine)         ! String array alias
  38.  
  39.   CODE
  40.   LOOP WHILE (ibCol > 0)             ! Loop
  41.     IF aLine[ibCol] <> 32 THEN BREAK.         !   Break on non-space
  42.     ibCol -= 1                     !   Decrement column index
  43.   .                         ! End loop
  44.   LOOP WHILE (ibCol > 0)             ! Loop
  45.     IF aLine[ibCol] = 32 THEN BREAK.         !   Break on space
  46.     ibCol -= 1                     !   Decrement column index
  47.   .                         ! End loop
  48.   RETURN( ibCol+1 )                 !
  49.  
  50.  
  51. ! ═════════════════════════════════════════════════════════════════════════
  52. !               Find Next Word Right
  53. ! ═════════════════════════════════════════════════════════════════════════
  54. Word_Right   FUNCTION( sLine, ibCol )
  55.  
  56.          ! Parameters:
  57. sLine         STRING(255)             ! Line of text
  58. ibCol         BYTE                 ! Column to start in
  59.  
  60.          ! Locals:
  61. aLine         BYTE,DIM(255),OVER(sLine)         ! String array alias
  62. ibMaxLen     BYTE                 ! Max. length of string
  63.  
  64.   CODE
  65.   ibMaxLen = LEN(CLIP(sLine))             ! Get max length
  66.   LOOP WHILE (ibCol <= ibMaxLen)         ! Loop
  67.     IF aLine[ibCol] = 32 THEN BREAK.         !   Break on space
  68.     ibCol += 1                     !   Increment column index
  69.   .                         ! End loop
  70.   LOOP WHILE (ibCol <= ibMaxLen)         ! Loop
  71.     IF aLine[ibCol] <> 32 THEN BREAK.         !   Break on non-space
  72.     ibCol += 1                     !   Increment column index
  73.   .                         ! End loop
  74.   RETURN( ibCol )                 !
  75.  
  76.  
  77. ! ═════════════════════════════════════════════════════════════════════════
  78. !             Insert Characters in String
  79. ! ═════════════════════════════════════════════════════════════════════════
  80. Str_Insert   FUNCTION( sSource, sTarget, ibIndex )
  81.  
  82.          ! Parameters:
  83. sSource         EXTERNAL                 ! String to insert
  84. sTarget         EXTERNAL                 ! String to insert into
  85. ibIndex         BYTE                 ! Position to insert into
  86.  
  87.          ! Return:
  88. sRetVal         STRING(255)             ! Returned string
  89.  
  90.   CODE
  91.   IF CLIP(sSource)                 ! If not all spaces
  92.     sRetVal = SUB(sTarget, 1, ibIndex-1) & |     !   Insert string
  93.           CLIP(sSource)         & |     !
  94.           SUB(sTarget, ibIndex, 255)     !
  95.   ELSE                         ! Else
  96.     sRetVal = SUB(sTarget, 1, ibIndex-1) & |     !   Insert a space
  97.           ' '             & |     !
  98.           SUB(sTarget, ibIndex, 255)     !
  99.   .                         ! Endif
  100.   RETURN( sRetVal )                 ! Return result
  101.  
  102.  
  103. ! ═════════════════════════════════════════════════════════════════════════
  104. !             Delete Characters in String
  105. ! ═════════════════════════════════════════════════════════════════════════
  106. Str_Delete   FUNCTION( sString, ibIndex, ibCount )
  107.  
  108.          ! Parameters:
  109. sString         EXTERNAL                 ! String to operate on
  110. ibIndex         BYTE                 ! Start index
  111. ibCount         BYTE                 ! # of chars to delete
  112.  
  113.          ! Return:
  114. sRetVal         STRING(255)             ! Returned string
  115.  
  116.   CODE
  117.   sRetVal = SUB(sString, 1, ibIndex-1) & |     ! Delete string portion
  118.         SUB(sString, ibIndex+ibCount, 255)     !
  119.   RETURN( sRetVal )                 ! Return result
  120.  
  121.  
  122. ! ═════════════════════════════════════════════════════════════════════════
  123. !            Remap Strings Within Another String
  124. ! ═════════════════════════════════════════════════════════════════════════
  125. Str_ReMap    FUNCTION( sString, sFrom, sTo )
  126.  
  127.          ! Parameters:
  128. sString         EXTERNAL                 ! String to operate on
  129. sFrom         EXTERNAL                 ! 'From' string
  130. sTo         EXTERNAL                 ! 'To' string
  131.  
  132.          ! Return:
  133. sRetVal         STRING(255)             ! Returned string
  134.  
  135.          ! Locals:
  136. ibIndex         LONG                 ! Loop index
  137.  
  138.   CODE
  139.   sRetVal = sString                 ! Copy to string
  140.   ibIndex = INSTRING(sFrom, sRetVal, 1)         ! Get first ocurrence
  141.   LOOP WHILE ibIndex                 ! Loop while found
  142.     sRetVal = Str_Delete(sRetVal, ibIndex, LEN(CLIP(sFrom)))
  143.     sRetVal = Str_Insert(sTo, sRetVal, ibIndex)     !   Replace ocurrence
  144.     ibIndex = INSTRING(sFrom, sRetVal, 1, ibIndex+LEN(CLIP(sTo)))
  145.   .                         ! End loop
  146.   RETURN( sRetVal )                 ! Return result
  147.  
  148.  
  149. ! ═════════════════════════════════════════════════════════════════════════
  150. !              Return Greater of Two Integers
  151. ! ═════════════════════════════════════════════════════════════════════════
  152. Greater_Of   FUNCTION( ilArg1, ilArg2 )
  153.  
  154.          ! Parameters:
  155. ilArg1         LONG                 ! Argument #1
  156. ilArg2         LONG                 ! Argument #2
  157.  
  158.   CODE
  159.   IF ilArg1 > ilArg2 THEN RETURN(ilArg1) ELSE RETURN(ilArg2).
  160.  
  161.  
  162. ! ═════════════════════════════════════════════════════════════════════════
  163. !              Return Lesser of Two Integers
  164. ! ═════════════════════════════════════════════════════════════════════════
  165. Lesser_Of    FUNCTION( ilArg1, ilArg2 )
  166.  
  167.          ! Parameters:
  168. ilArg1         LONG                 ! Argument #1
  169. ilArg2         LONG                 ! Argument #2
  170.  
  171.   CODE
  172.   IF ilArg1 < ilArg2 THEN RETURN(ilArg1) ELSE RETURN(ilArg2).
  173.  
  174.