home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / firstcap.zip / FCAP.ASM next >
Assembly Source File  |  1986-03-12  |  8KB  |  201 lines

  1.  
  2. ;-------------------------------:
  3. ; Program File.: FCAP.ASM       :
  4. ; Author.......: Dennis L. Dias :
  5. ; Source ID....: NAN449         :
  6. ; Date.........: 12/14/85       :
  7. ;-------------------------------:
  8. ;
  9. ;-------------------------------------------------------------------:
  10. ;This assembly language routine is called by Clipper to convert     :
  11. ; the first letter of each word of the input string to caps. The    :
  12. ; special words listed as "special" below will remain lower case    :
  13. ; unless they appear as the first or last word or if they are       :
  14. ; followed by a non-space character. The input string must be passed:
  15. ; as lower case.                                                    :
  16. ; The apostrophe (') is considered a character.                     :
  17. ;-------------------------------------------------------------------:
  18. ;
  19.         public  fcap            ;Public procedure
  20. ;
  21. _prog   segment byte            ;Clipper segment
  22.         assume  cs:_prog,ds:_prog,es:nothing,ss:nothing
  23. ;
  24. ;----------------:
  25. ;Local data area :
  26. ;----------------:
  27. ;
  28. ;Special words are grouped according to length. Each group is
  29. ;  preceeded by the length plus one space, and the number of words of
  30. ;  that length. This greatly reduces the number of comparisons
  31. ;  required to search the entire list.  These numbers MUST be changed
  32. ;  when adding or removing words from the list.
  33. ;
  34. special db      4,4,"and the for but "
  35.         db      3,9,"to or by an in of on if at "
  36.         db      2,1,"a ",0    ;Special words are terminated with null
  37. ;
  38. ;List of characters to be considered "in-word" characters
  39. ;
  40. char    db      "0123456789abcdefghijklmnopqrstuvwxyz'"
  41. ;
  42. ;------------------------------------------------------:
  43. ;Primary routine..far procedure as required by Clipper :
  44. ;------------------------------------------------------:
  45. ;
  46. fcap    proc    far
  47. ;
  48.         push    bp              ;Required by Clipper
  49.         mov     bp,sp           ;To address variable at SP + 6
  50.         push    ds              ;Must save seg regs
  51.         push    es
  52.         cld                     ;Forward direction flag
  53. ;
  54.         lds     si,dword ptr[bp+6] ;Point to input string with DS:SI
  55.         push    cs
  56.         pop     es             ;Address local data via ES register
  57. ;
  58.         lea     di,char         ;ES:DI points to in-word characters
  59.         mov     cx,37           ;Length of in-word characters
  60. ;
  61. ;Capitalize the first word no matter what it is
  62. ;
  63. fc1:    lodsb                   ;Fetch char
  64.         or      al,al           ;Check for null terminator
  65.         jz      fc_ret          ;Quit if null..no characters at all
  66. ;
  67.         call    fl_scan         ;Test for in-word character
  68.         jnz     fc1             ;Scan off word separators
  69.         mov     bx,si
  70.         dec     bx              ;DS:BX points to first character
  71.         call    fl_cap          ;Cap first letter
  72. ;
  73. ;Return here for each new word
  74. ;
  75. fc2:    mov     bx,si
  76.         dec     bx              ;DS:BX points to first character
  77. ;
  78. fc3:    lodsb                   ;Fetch character
  79.         or      al,al           ;Check for null terminator
  80.         jz      fc5             ;Cap last word
  81. ;
  82.         call    fl_scan           ;Test for in-word character
  83.         jz      fc3             ;Scan past in-word characters
  84. ;
  85. fc4:    mov     dx,si
  86.         sub     dx,bx           ;DX has size of word plus 1
  87.         cmp     dl,4            ;Special words are 3 chars
  88.         ja      fc5             ;   plus 1 space max
  89. ;
  90.         call    fl_com          ;Test for special word
  91.         jc      fc6             ;Found..don't cap
  92. ;
  93. fc5:    call    fl_cap          ;Cap first letter
  94. ;
  95. fc6:    dec     si              ;Point to end of prev word + 1
  96.         lea     di,char         ;Point to in-word characters
  97.         mov     cx,37           ;Length of in-word characters
  98. ;
  99. fc7:    lodsb                   ;Fetch char
  100.         or      al,al           ;Check for null terminator
  101.         jz      fc_ret          ;Quit if null
  102. ;
  103.         call    fl_scan
  104.         jnz     fc7             ;Scan off word separators
  105.         jmp     fc2             ;Go process next word
  106. ;
  107. ;Done
  108. ;
  109. fc_ret: pop     es              ;Restore registers for Clipper
  110.         pop     ds
  111.         pop     bp
  112.         ret                     ;Far return to Clipper
  113. ;
  114. fcap    endp
  115. ;
  116. ;------------------:
  117. ;Local subroutines :
  118. ;------------------:
  119. ;
  120. ;The following procedure tests the character in AL as being in-word
  121. ;    or not. The zero flag returns set if the character is in-word.
  122. ;
  123. fl_scan proc    near
  124. ;
  125.         push    di              ;Save pointer to in-word characters
  126.         push    cx              ;Save length of in-word characters
  127.         repne   scasb           ;Look for match
  128.         pop     cx              ;Restore saved values and return
  129.         pop     di              ;   result in Zero flag
  130.         ret                     ;Near return
  131. ;
  132. fl_scan endp
  133. ;
  134. ;Convert lower case to upper case..DS:BX points to the character
  135. ;
  136. fl_cap  proc    near
  137. ;
  138.         cmp     byte ptr[bx],"a"
  139.         jb      fl_cap_ret       ;Less than "a" not lower
  140.         cmp     byte ptr[bx],"z"
  141.         ja      fl_cap_ret     ;Above "z" not lower
  142.         sub     byte ptr[bx],20h ;Convert to upper case
  143. ;
  144. fl_cap_ret:     ret             ;Near return
  145. ;
  146. fl_cap  endp
  147. ;
  148. ;Look for special words..return carry flag set if found..on entry
  149. ;DS:BX points to first character of the word to test. Begin by
  150. ;exchanging the contents of ES with DS to facilitate the use of the
  151. ;string instructions. AX, CX, DX, and DI destroyed.
  152. ;
  153. fl_com  proc    near
  154. ;
  155.         push    si           ;Save current pointer
  156.         push    ds
  157.         pop     es           ;Clipper segment to ES
  158.         push    cs
  159.         pop     ds           ;Local segment to DS
  160.         mov     di,bx        ;ES:DI points to current word
  161.         lea     si,special   ;DS:SI points to local list of words
  162. ;
  163. fl_c1:  lodsb                ;Fetch word size
  164.         or      al,al        ;Check for null terminator
  165.         jz      fl_clc       ;Exit routine..special word not found
  166. ;
  167.         mov     cl,al       ;Size of next group of words to count reg
  168.         xor     ch,ch        ;Zero high byte
  169.         lodsb                ;Fetch word count
  170.         mov     dh,al        ;To DH for outer loop
  171.         mov     ax,cx        ;Save count in AX
  172. ;
  173. fl_c2:  push    di           ;Save pointer to test word
  174.         mov     cx,ax        ;Word size to counter
  175.         repe    cmpsb        ;Compare bytes
  176.         je      fl_stc       ;Jump if special word found
  177.         add     si,cx        ;Point to next word or next group
  178.         pop     di           ;Recover pointer to test word
  179.         dec     dh           ;Reduce outer loop counter
  180.         jnz     fl_c2        ;Anoter word..same length
  181.         jmp     fl_c1        ;Go for next group of words
  182. ;
  183. fl_clc: clc                  ;Clear carry..special word not found
  184. ;
  185. fl_com_ret: pop si           ;Restore registers and return
  186.         push    es
  187.         pop     ds           ;Clipper segment to DS
  188.         push    cs
  189.         pop     es           ;Local segment to ES
  190.         ret                  ;Near return
  191. ;
  192. ;Special word found..return result in carry flag
  193. ;
  194. fl_stc: pop     di              ;Clear stack
  195.         stc                     ;Set carry flag
  196.         jmp     fl_com_ret      ;Restore and return
  197. ;
  198. fl_com  endp
  199. _prog   ends
  200.         end
  201.