{***********************************************************************}
{									}
{ __JustStr   Justify a string within a field.				}
{									}
{ function  __JustStr(Source : string;					}
{		      FillCh : char;					}
{		   FieldSize : word;					}
{		    JustCode : word) : string;				}
{									}
{	      Source	The string to be justified within the specified }
{			field.						}
{	      FillCh	The character to be used for padding within the }
{			field.						}
{	      FieldSize The size of the field; that is, the number of	}
{			characters in the returned string.		}
{	      JustCode	The justification code.  The possible values	}
{			0 (_LEFT_JUST_STR)  Left justify		}
{			1 (_RIGHT_JUST_STR) Right justify		}
{			2 (_CENTER_STR)     Center			}
{									}
{ Description __JustStr justifies a string within a field of specified	}
{	      length, padding the string with the character FillCh.	}
{	      The source string is not altered, and the functional	}
{	      value is the justified string.  If FieldSize is less than }
{	      the length of the source string, either the left, right,	}
{	      or center portion of the string is returned depending on	}
{	      the value of JustCode.  If JustCode is out of range, 0	}
{	      is assumed (that is, left justification and pad on the	}
{	      right will the fill character, FillCh).			}
{									}
{ Version     4.00  (C)Copyright Blaise Computing Inc. 1987		}
{_______________________________________________________________________}

function  __JustStr(Source : string;
		    FillCh : char;
		 FieldSize : word;
		  JustCode : word) : string;

  var
    JustString : string;
    Len        : word;

  begin {__JustStr}

    if (FieldSize > MAXSTR_) then      { Make sure FieldSize is good,	}
       FieldSize  := MAXSTR_	       { and initialize the field.	}
    else if (FieldSize < 1) then
       FieldSize  := 0;
    FillChar(JustString[1],FieldSize,FillCh);
    Length(JustString) := FieldSize;
    Len 	       := Length(Source);

    case JustCode of

      _RIGHT_JUST_STR:		       { Right justification		}
	 if (Len <= FieldSize) then
	    Move(Source[1],JustString[FieldSize - Len + 1],Len)
	 else
	    Move(Source[Len - FieldSize + 1],JustString[1],FieldSize);
      _CENTER_STR:		       { Center 			}
	 if (Len <= FieldSize) then
	    Move(Source[1],JustString[((FieldSize - Len) div 2) + 1],Len)
	 else
	    Move(Source[((Len - FieldSize) div 2) + 1],
						 JustString[1],FieldSize);
      else			       { Left justification		}
	 begin
	   if (Len <= FieldSize) then
	      Move(Source[1],JustString[1],Len)
	   else
	      Move(Source[1],JustString[1],FieldSize)
	 end;

    end; {case JustCode}

    __JustStr := JustString

  end;	{__JustStr}
