
/*
 *	Function	BuildIntuiText
 *	Programmer	N.d'Alterio
 *	Date		22/09/95
 *
 *  Synopsis:	This function builds a linked list of IntuiText structures
 *		containing the FullInfo structures information ready for 
 *		printing. The linked list is of fixed length so that the
 *		news list blanks the contents of the mail list when they 
 *		switch and vice versa.
 *		To free the linked list call FreeIntuiText.
 *
 *  Arguments:	struct IntuiText *base_it		IntuiText structure used for
 *							intialisation.
 *		struct FullInfo *fi			FullInfo structure containing 
 *							information to print.
 *		int max_lines				Length of linked list.
 *
 *  Returns:	struct IntuiText *			Filled in IntuiText structure.
 *		NULL					If error.
 *
 *  Variables:	 i					Loop variable.
 * 		 error					Error flag;
 *		*it					Start of linked list. Returned 
 *		*cur_it					Temp IntuiText pointer.
 *		*cur_fi					Temp FullInfo pointer.
 *
 *  Functions:  AllocIntuiText				Allocates IntuiText struct (SW)
 *		FreeIntuiText				Frees IntuiText struct/linked 
 *							list (SW)
 *		sprintf					Prints to a string (EXEC)
 *
 *  $Id: BuildIntuiText.c 1.1 1995/09/23 17:08:52 daltern Exp $
 *
 */

#include "SpoolWatch.h"

struct IntuiText *BuildIntuiText( struct IntuiText *base_it, struct FullInfo *fi, int max_lines )

{

  register int i;

  int error;

  struct IntuiText *it = NULL;
  struct IntuiText *cur_it;
  
  struct FullInfo  *cur_fi;

/*
 *   Prepare Header text.
 */

  error = FALSE;

  cur_it = AllocIntuiText( base_it );
  if ( cur_it ) {

	it = cur_it;
  	sprintf( cur_it->IText, " Num  Size            Destination                 Time Queued" );

	cur_it->NextText = AllocIntuiText( base_it );
	if ( cur_it->NextText ) {

  		cur_it = cur_it->NextText;
  		cur_it->TopEdge = (long)(cur_it->ITextFont->ta_YSize);


/*
 *   Create the linked list and fill with the full info text. Also
 *   set the text position.
 */

		cur_fi = fi;
		for ( i = 0; i < max_lines; i++ ) {

			cur_it->NextText = AllocIntuiText( base_it );
			if ( cur_it->NextText ) {

				cur_it = cur_it->NextText;	
				cur_it->TopEdge = (long)((i+2) * cur_it->ITextFont->ta_YSize);

				if ( cur_fi ) {
					sprintf( cur_it->IText, 
                                                 "%3d %6d %-35s %3d days %2d h %2d m", 
									i+1, 
									cur_fi->fi_size, 
									cur_fi->fi_dest, 
									cur_fi->fi_days, 
									cur_fi->fi_hours, 
									cur_fi->fi_mins );

					cur_fi = cur_fi->fi_next;
				}   /* end if cur_fi */
			
			} else {

				error = TRUE;

			}   /* end if cur_it->NextText */

		}   /* end for i */

  	} else {

		error = TRUE;

	}   /* end if cur_it->NextText */

  }   /* end if cur_it */

  if ( error ) FreeIntuiText( it );

  return it;

}   /* end function BuildIntuiText */

/*========================================================================*
                        END FUNCTION BuildIntuiText
 *========================================================================*/
