home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / clarion / invalpha.zip / INVALPHA.INC < prev   
Text File  |  1989-08-29  |  6KB  |  159 lines

  1.            TITLE('Inverted Alpha Routines')
  2.            SOURCE
  3.  
  4. ! Include module for inverted alpha routines
  5. ! Written by Peter A. Hyman
  6. !         148 Tennyson Drive
  7. !         Plainsboro, NJ  08536
  8. !         (609) 799-2638
  9. !
  10. ! August 1989
  11. !
  12. ! Description
  13. !
  14. !   These functions allow for the use of inverted alpha fields. an inverted
  15. !   alpha field is one in which the last word in a string is stored first in
  16. !   the file.  Typically, this is used for correctly alphabetizing names of
  17. !   individuals, companies, etc.
  18. !
  19. !   In cases where the sort word should not be the last word, inverted alpha
  20. !   fields allow for the use of the \ character to be placed before the word
  21. !   which should be sorted first in the field.
  22. !
  23. !   Examples:
  24. !
  25. !   As entered               Inverted alpha equivalent
  26. !  ----------------------     ----------------------------
  27. !   Peter A. Hyman           Hyman Peter A.
  28. !   The \ABC Corporation       ABC\Corporation The
  29. !   John \Smith Jr.           Smith Jr.\John
  30. !
  31. !   In circumstances where it is desirable to use only one data entry field
  32. !   for storing a name, inverted alpha fields are very handy.
  33. !
  34. !   There are three functions used
  35. !
  36. !   Disp_Inv_Al         Displays an inverted alpha name w/o the \ character
  37. !   Invert         Inverts an alpha field for sorting
  38. !   Uninvert         Un-inverts a stored inverted alpha name for editing
  39. !             with the \ character
  40. !
  41. !   In usage, A field must be inverted before being added or put to a file.
  42. !          A field must be reinverted before field editing.
  43. !          A field should be displayed (using disp_inv_al) to remove the
  44. !        \ character (if any) for reporting or table scrolling.
  45. !
  46. !   All three functions require the singular argument 'Name' which is the
  47. !   string field to be inverted, uninverted or displayed.  All three functions
  48. !   return a string containing the modified field.  It does not modify the
  49. !   parameter passed.
  50. !
  51. !   Example:
  52. !
  53. !   Name     STRING(35)           !Name field
  54. !
  55. !   OF ?Mem:Name           !Using a memory variable or temp variable
  56. !     Fil:Name = Invert(Mem:Name)        ! is useful
  57. !     ....
  58. !   PUT(Name_File)
  59. !
  60. !
  61. !   SHOW(1,20,Disp_Inv_Al(Fil:Name),@S35)     !Display the name properly
  62. !
  63. !   Mem:Name = Uninvert(Fil:Name)        !Univert stored name for editing
  64. !   DISPLAY(?Mem:Name)                !Display it
  65.  
  66.  
  67.  EJECT('Invert Function')
  68.  !******************************************************* Function Invert *****
  69. Invert         FUNCTION(Name)
  70.          !* Create an inverted alpha string
  71.  
  72. Name         EXTERNAL      !* String to be inverted
  73. Slash         STRING(1)      !* Invert separator - a space or \
  74. Slash_Pos    BYTE      !* Separator position
  75.  
  76.          CODE
  77.   Len# = LEN(CLIP(Name))             !* Remove trailing spaces
  78.   Slash = '\'                     !* Assume a \ is in string
  79.   IF NOT INSTRING(Slash,Name,1)             !* If no \
  80.     IF NOT INSTRING(' ',CLIP(Name),1)
  81.       RETURN(Name)                 !* Return if only one word
  82.     END
  83.     Slash = ' '                     !* Set separator to a space
  84.     Temp# = 0
  85.     Slash_Pos = 0
  86.     LOOP                     !* Find last name
  87.       Slash_Pos += Temp#
  88.       Temp# = INSTRING(Slash,SUB(Name,Slash_Pos+1,Len#-Slash_Pos),1)
  89.       IF NOT Temp# THEN BREAK; END         !* No more spaces, then break
  90.     END
  91.   ELSE                         !* Otherwise a \ is in name
  92.     Slash_Pos = INSTRING(Slash,Name,1)         !* Locate \ in string
  93.     Len# += 1                     !* Add 1 for storage
  94.   END
  95.     !* Return last part of string.
  96.     !* Include separator - space or \ and first part of name.
  97.   RETURN(SUB(Name,Slash_Pos+1,Len#-Slash_Pos)     |
  98.    & SLASH & SUB(Name,1,Slash_Pos-1))
  99.  
  100.  
  101.  EJECT('Disp_Inv_Al Function')
  102.  !************************************************** Function Disp_Inv_Al *****
  103. Disp_Inv_Al  FUNCTION(Name)
  104.          !* Display inverted alpha field
  105.  
  106. Name         EXTERNAL      !* Inverted alpha field
  107. Slash         STRING(1)      !* Invert separator - a space or \
  108. Slash_Pos    BYTE      !* Separator location
  109.  
  110.          CODE
  111.   Slash = '\'                     !* Assume a \ is in string
  112.   Len# = LEN(CLIP(Name))             !* Remove trailing spaces
  113.   IF NOT INSTRING(Slash,Name,1)             !* If no \
  114.     Slash = ' '                     !* Set separator to a space
  115.   END
  116.   Slash_Pos = INSTRING(Slash,CLIP(Name),1)     !* First name begins after
  117.                          !*  first separator
  118.   IF NOT Slash_Pos                 !* Return if only one word
  119.     RETURN(Name)
  120.   ELSIF Slash_Pos = Len#             !* If slash is before first
  121.     RETURN(SUB( NAME, 1, SLASH_POS - 1 ) )     !*  word
  122.   ELSE
  123.     RETURN(SUB(Name,Slash_Pos+1,       |     !* Return uninverted name
  124.      Len# - Slash_Pos )               |     !* Last part first
  125.      & ' '                   |     !* Remove \
  126.      & SUB(Name,1,               |     !* and first part last
  127.      Slash_Pos-1))                 !* to separator position
  128.   END
  129.  
  130.  
  131.  EJECT('Uninvert Function')
  132.  !***************************************************** Function Uninvert *****
  133. UNINVERT     FUNCTION(NAME)
  134.          !* Uninvert name
  135.  
  136. Name         EXTERNAL      !* Inverted alpha string
  137. Slash         STRING(1)      !* Invert separator - a space or \
  138. Slash_Pos    BYTE      !* Separator location
  139.  
  140.          CODE
  141.   Slash = '\'                     !* Assume a \ is in string
  142.   Len# = LEN(CLIP(Name))             !* Remove trailing spaces
  143.   IF NOT INSTRING(Slash,Name,1)             !* If no \
  144.     Slash = ' '                     !* Set separator to a space
  145.   END
  146.  
  147.   Slash_Pos = INSTRING(Slash,CLIP(Name),1)     !* First name begins after
  148.                          !*  separator.
  149.   IF NOT Slash_Pos                 !* Return if only one word
  150.     RETURN(Name)
  151.   ELSIF Slash_Pos = Len#             !* If slash is before first
  152.     RETURN(Slash & SUB(Name,1,Slash_Pos-1))     !*  word.
  153.   ELSE
  154.     IF Slash = '\' THEN Len# += 1; END            !* Add space before slash
  155.     RETURN(SUB(Name,Slash_Pos+1,Len#-Slash_Pos) |   !* First part of name first
  156.      & Slash                    |   !* Append a space or \
  157.      & SUB(Name,1,Slash_Pos-1))                !* and last part of name
  158.   END
  159.