{***********************************************************************}
{									}
{ __SpLisPrt  Return the next item in the PRINT spooler queue		}
{									}
{ function  __SpLisPrt(ItemNo : word;					}
{			    var Size,ErrorCode : word) : _Path; 	}
{									}
{	      ItemNo	The number of the item in the queue whose value }
{			is to be returned.  If ItemNo is less than 1,	}
{			or greater than the length of the queue, the	}
{			null string is returned as the function value,	}
{			and an error is returned.			}
{	      Size	The number of items in the PRINT spooler queue. }
{			This value is always returned even if the value }
{			for ItemNo is out of range.			}
{	      ErrorCode The returned error status code. The values are: }
{			0 - Item successfully returned. 		}
{			1 - Spooler not installed. You must execute	}
{			    the PRINT command.				}
{			6 - The queue is empty				}
{			7 - Item requested is out of range		}
{			9 - Spooler is busy; unable to get attention.	}
{			For nonzero return codes, the function value is }
{			always the null string. 			}
{									}
{ Description The PRINT spooler queue is a list of pathname entries,	}
{	      each 64 bytes in length.	The beginning of the list	}
{	      is found by making calling subfunction 4 of interrupt	}
{	      service $2F.  The end of the list is marked by an entry	}
{	      beginning with a NUL byte (ASCII 0).			}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc. 1987		}
{_______________________________________________________________________}

function __SpLisPrt(ItemNo : word; var Size,ErrorCode : word) : _Path;

  type
    QueueItem = array[1..64] of char;
    Queue     = array[1..32] of QueueItem;

  var
    QueuePtr  : ^Queue;
    NextItem  : QueueItem;
    PathName  : _Path;
    I	      : integer;
    EndQueue  : boolean;
    Reg       : registers;

  begin {SpLisPrt}

    ErrorCode := 0;
    Size      := 0;

    if (not __SpInsPrt) then
       begin
	 ErrorCode := _NOTINSTALLED_PRT;
	 Exit
       end;

    with Reg do
      begin
	AX := $0104;		       { Return a pointer to the start	}
	Intr(_PRINT,Reg);	       { of the queue.			}
	if ((Flags and FCarry) <> 0) then { Carry flag is set; an error }
	   begin		       { occurred and number is in AX	}
	     ErrorCode := AX;
	     AX        := $0105;       { Reactivate the queue		}
	     Intr(_PRINT,Reg);
	     PathName  := '';
	   end
	else
	   QueuePtr := Ptr(DS,SI)
      end;

    if (ErrorCode <> 0) then
       Exit;

    I	     := 1;
    EndQueue := FALSE;
    repeat
      if (QueuePtr^[I][1] = #0) then
	 begin
	   Size     := Pred(I);
	   EndQueue := TRUE
	 end;
      Inc(I)
    until (EndQueue);

    if ((ItemNo < 1) or (ItemNo > Size)) then
       begin
	 ErrorCode := _RANGE_PRT;      { Item out of range		}
	 PathName  := ''
       end
    else
       begin			       { Look for trailing NUL byte	}
	 I := 1;		       { in the queue item.		}
	 while ((QueuePtr^[ItemNo][I] <> #0) and (I < 64)) do
	   Inc(I);
	 Move(QueuePtr^[ItemNo][1],PathName[1],I);
	 PathName[0] := Chr(I)
       end;

    if (Size = 0) then
       ErrorCode := _QUEUEEMPTY_PRT;   { Queue is empty 		}

    with Reg do
      begin
	AX := $0105;		       { Thaw the queue; it may now	}
	Intr(_PRINT,Reg)	       { accept additional entries.	}
      end;

    __SpLisPrt := PathName

  end;	{__SpLisPrt}
