home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
clarion
/
invalpha.zip
/
INVALPHA.COM
/
INVALPHA.INC
Wrap
Text File
|
1989-08-29
|
6KB
|
159 lines
TITLE('Inverted Alpha Routines')
SOURCE
! Include module for inverted alpha routines
! Written by Peter A. Hyman
! 148 Tennyson Drive
! Plainsboro, NJ 08536
! (609) 799-2638
!
! August 1989
!
! Description
!
! These functions allow for the use of inverted alpha fields. an inverted
! alpha field is one in which the last word in a string is stored first in
! the file. Typically, this is used for correctly alphabetizing names of
! individuals, companies, etc.
!
! In cases where the sort word should not be the last word, inverted alpha
! fields allow for the use of the \ character to be placed before the word
! which should be sorted first in the field.
!
! Examples:
!
! As entered Inverted alpha equivalent
! ---------------------- ----------------------------
! Peter A. Hyman Hyman Peter A.
! The \ABC Corporation ABC\Corporation The
! John \Smith Jr. Smith Jr.\John
!
! In circumstances where it is desirable to use only one data entry field
! for storing a name, inverted alpha fields are very handy.
!
! There are three functions used
!
! Disp_Inv_Al Displays an inverted alpha name w/o the \ character
! Invert Inverts an alpha field for sorting
! Uninvert Un-inverts a stored inverted alpha name for editing
! with the \ character
!
! In usage, A field must be inverted before being added or put to a file.
! A field must be reinverted before field editing.
! A field should be displayed (using disp_inv_al) to remove the
! \ character (if any) for reporting or table scrolling.
!
! All three functions require the singular argument 'Name' which is the
! string field to be inverted, uninverted or displayed. All three functions
! return a string containing the modified field. It does not modify the
! parameter passed.
!
! Example:
!
! Name STRING(35) !Name field
!
! OF ?Mem:Name !Using a memory variable or temp variable
! Fil:Name = Invert(Mem:Name) ! is useful
! ....
! PUT(Name_File)
!
!
! SHOW(1,20,Disp_Inv_Al(Fil:Name),@S35) !Display the name properly
!
! Mem:Name = Uninvert(Fil:Name) !Univert stored name for editing
! DISPLAY(?Mem:Name) !Display it
EJECT('Invert Function')
!******************************************************* Function Invert *****
Invert FUNCTION(Name)
!* Create an inverted alpha string
Name EXTERNAL !* String to be inverted
Slash STRING(1) !* Invert separator - a space or \
Slash_Pos BYTE !* Separator position
CODE
Len# = LEN(CLIP(Name)) !* Remove trailing spaces
Slash = '\' !* Assume a \ is in string
IF NOT INSTRING(Slash,Name,1) !* If no \
IF NOT INSTRING(' ',CLIP(Name),1)
RETURN(Name) !* Return if only one word
END
Slash = ' ' !* Set separator to a space
Temp# = 0
Slash_Pos = 0
LOOP !* Find last name
Slash_Pos += Temp#
Temp# = INSTRING(Slash,SUB(Name,Slash_Pos+1,Len#-Slash_Pos),1)
IF NOT Temp# THEN BREAK; END !* No more spaces, then break
END
ELSE !* Otherwise a \ is in name
Slash_Pos = INSTRING(Slash,Name,1) !* Locate \ in string
Len# += 1 !* Add 1 for storage
END
!* Return last part of string.
!* Include separator - space or \ and first part of name.
RETURN(SUB(Name,Slash_Pos+1,Len#-Slash_Pos) |
& SLASH & SUB(Name,1,Slash_Pos-1))
EJECT('Disp_Inv_Al Function')
!************************************************** Function Disp_Inv_Al *****
Disp_Inv_Al FUNCTION(Name)
!* Display inverted alpha field
Name EXTERNAL !* Inverted alpha field
Slash STRING(1) !* Invert separator - a space or \
Slash_Pos BYTE !* Separator location
CODE
Slash = '\' !* Assume a \ is in string
Len# = LEN(CLIP(Name)) !* Remove trailing spaces
IF NOT INSTRING(Slash,Name,1) !* If no \
Slash = ' ' !* Set separator to a space
END
Slash_Pos = INSTRING(Slash,CLIP(Name),1) !* First name begins after
!* first separator
IF NOT Slash_Pos !* Return if only one word
RETURN(Name)
ELSIF Slash_Pos = Len# !* If slash is before first
RETURN(SUB( NAME, 1, SLASH_POS - 1 ) ) !* word
ELSE
RETURN(SUB(Name,Slash_Pos+1, | !* Return uninverted name
Len# - Slash_Pos ) | !* Last part first
& ' ' | !* Remove \
& SUB(Name,1, | !* and first part last
Slash_Pos-1)) !* to separator position
END
EJECT('Uninvert Function')
!***************************************************** Function Uninvert *****
UNINVERT FUNCTION(NAME)
!* Uninvert name
Name EXTERNAL !* Inverted alpha string
Slash STRING(1) !* Invert separator - a space or \
Slash_Pos BYTE !* Separator location
CODE
Slash = '\' !* Assume a \ is in string
Len# = LEN(CLIP(Name)) !* Remove trailing spaces
IF NOT INSTRING(Slash,Name,1) !* If no \
Slash = ' ' !* Set separator to a space
END
Slash_Pos = INSTRING(Slash,CLIP(Name),1) !* First name begins after
!* separator.
IF NOT Slash_Pos !* Return if only one word
RETURN(Name)
ELSIF Slash_Pos = Len# !* If slash is before first
RETURN(Slash & SUB(Name,1,Slash_Pos-1)) !* word.
ELSE
IF Slash = '\' THEN Len# += 1; END !* Add space before slash
RETURN(SUB(Name,Slash_Pos+1,Len#-Slash_Pos) | !* First part of name first
& Slash | !* Append a space or \
& SUB(Name,1,Slash_Pos-1)) !* and last part of name
END