{***********************************************************************}
{									}
{ __EnTabStr  Return a string with spaces converted to tab characters	}
{									}
{ function __EnTabStr(Source : string; Incr : byte) : string;		}
{									}
{	      Source	The string to be converted.			}
{	      Incr	Interval separating tab stops.			}
{									}
{ Description __EnTabStr returns a 'tabified' string in which blank	}
{	      spaces (' ') have been replaced with tab characters	}
{	      (chr(9)) so as to shorten (possibly) the length of the	}
{	      string.  Use of tab characters is minimal:  that is,	}
{	      whenever a single balnk space will serve instead of a	}
{	      tab, the blank is used.					}
{									}
{	      If Incr is greater than 0, tab stops are set every Incr	}
{	      characters starting from the first character in the	}
{	      returned string.	If Incr is 0, Source will be returned	}
{	      intact.							}
{									}
{	      Existing tab characters are left intact and are regarded	}
{	      as advancing to the next tab stop.			}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

function __EnTabStr(Source : string; Incr : byte) : string;

  const
    BLANK = #32;
    TAB   = #9;

  var
    Column, NumBlanks : word;
    SourceIdx	      : word;		{ Index into Source		}
    TargetIdx	      : word;		{ Index into Target		}
    ThisCh	      : char;

  begin {__EnTabStr}

    { If the Source is either NULL or Incr is not positive, exit	}
    { immediately.							}

    if ((Length(Source) = 0) or (Incr <= 0)) then
      begin
	__EnTabStr := Source;		{ Return Source unchanged	}
	Exit
      end;

    Column    := 0;
    NumBlanks := 0;
    SourceIdx := 0;
    TargetIdx := 0;

    repeat
      Inc(SourceIdx);
      ThisCh := Source[SourceIdx];
      case ThisCh of
	BLANK :
		begin

		  { When a blank is found, keep track of how many have	}
		  { many have been found.  If at a tab stop, place a	}
		  { tab in the target, and reset the blank count.	}

		  Inc(NumBlanks);
		  Inc(Column);
		  if ((Incr <= 0) or (Column mod Incr = 0)) then
		    begin
		      Inc(TargetIdx);
		      if (NumBlanks > 1) then
			__EnTabStr[TargetIdx] := TAB
		      else
			__EnTabStr[TargetIdx] := BLANK;
		      NumBlanks := 0
		    end;
		end;
	TAB :
		begin

		  { Existing tab characters are left intact, but view	}
		  { as advancing to the next tab stop.			}

		  Inc(TargetIdx);
		  Column		:= 0;
		  NumBlanks		:= 0;
		  __EnTabStr[TargetIdx] := TAB
		end;
	else
	  begin

	    { For any other character, first output the blanks found	}
	    { so far, and then place the character in the target	}
	    { string.  Remember blanks are replaced only by a tab if	}
	    { a blank is found at a tab stop.				}

	    Inc(Column);
	    Inc(TargetIdx);
	    while NumBlanks > 0 do
	      begin
		__EnTabStr[TargetIdx] := BLANK;
		Dec(NumBlanks);
		Inc(TargetIdx)
	      end;
	    __EnTabStr[TargetIdx] := ThisCh
	  end;

	end; {case ThisCh}

    until (SourceIdx = Length(Source));


    __EnTabStr[0] := Chr(TargetIdx)    { Set Length of returned string	}

  end; {__EnTabStr}
