/*==================================================================
  ==================================================================
  ==	XMusic -- An Interactive Interface to Csound		  ==
  ==       Copyright (C) 1988 by George D. Drapeau                ==
  ==                  All Rights Reserved                         ==
  ==================================================================
  ==================================================================
*/
/* $Header: /home/sioux/drapeau/x/xmusic/RCS/drawinfo.c,v 1.4 89/08/06 18:03:02 drapeau Exp $ */

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/List.h>
#include <string.h>
#include "defs.h"
#include "externs.h"

void DrawInfoWin(tool)
     Tool	*tool;
{
  char		tempStr[32], RateToChar(), *RateToStr();
  int		i;
  
  switch (tool->type)
    {
    case SineTool:
      sprintf(tempStr,"SineTool");
      break;
    case AmpTool:
      sprintf(tempStr,"AmpTool");
      break;
    case EQTool:
      sprintf(tempStr,"EQTool");
      break;
    case SumTool:
      sprintf(tempStr,"SumTool");
      break;
    case NoiseTool:
      sprintf(tempStr,"NoiseTool");
      break;
    case EnvTool:
      sprintf(tempStr,"EnvTool");
      break;
    case ParamTool:
      sprintf(tempStr,"ParamTool");
      break;
    }								    /* end switch */


  toolInfoList[0] = "Tool Type:";				    /* Setup the first line of text, left side */
  if (toolInfoList[1])						    /* Is this array element pointing to a string? */
    free(toolInfoList[1]);					    /* Yes, free the memory taken by that string */
  toolInfoList[1] = (String)malloc(strlen(tempStr)+1);		    /* Allocate space for the argument's name and value */
  strncpy(toolInfoList[1],tempStr,strlen(tempStr)+1);		    /* Setup the first line of text, right side */
  toolInfoList[2] = "Tool Name:";				    /* Setup the second line of text, left side */
  toolInfoList[3] = tool->name;					    /* Setup the second line of text, right side  */
  toolInfoList[4] = "Tool Rate:";				    /* Third line, left side */
  toolInfoList[5] = RateToStr(tool->rate);			    /* Third line, right side */
  toolInfoList[6] = "Csound Function:";				    /* Fourth line, left side */
  toolInfoList[7] = tool->fName;				    /* Fourth line, right side */

  for (i=8;i<=24;i++)						    /* Clear out all optional arguments for the... */
    {								    /* ...Info Window */
      if (toolInfoList[i])					    /* Has memory been allocated for this argument? */
	free(toolInfoList[i]);					    /* Yes, return it */
      toolInfoList[i] = NULL;					    /* Make this element point to a NULL string */
    }

  if (toolArg1)							    /* Does the tool being examined have this argument?  */
    {
      sprintf(tempStr,"%d. %s",1,toolArg1);			    /* Yes, allocate space for the argument's name and... */
      toolInfoList[8] = (String)malloc(strlen(tempStr)+1);	    /* ...value */
      strncpy(toolInfoList[8],tempStr,strlen(tempStr)+1);
      
      if (tool->input1)						    /* Does this tool have a first input? */
	{							    /* Yes, determine which name to use for the input name */
	  if ((tool->input1->type == EQTool) ||			    /* Use the equation or parameter name */
	      (tool->input1->type == ParamTool))
	    sprintf(tempStr,"%s",tool->input1->fName);
	  else							    /* Use the name of the tool */
	    sprintf(tempStr,"%c%s",RateToChar(tool->input1->rate),
		    tool->input1->name);
	}
      else							    /* No, this tool has not input, try to use default arg */
	{
	  if (tool->arg1)					    /* Does a default argument exist for this tool? */
	    sprintf(tempStr,"%s",tool->arg1);			    /* Yes, use it */
	  else							    /* No, print a blank string for the Info Window */
	    sprintf(tempStr," ");
	}
      toolInfoList[9] = (String)malloc(strlen(tempStr)+1);	    /* Allocate space for the argument's name and value */
      strncpy(toolInfoList[9],tempStr,strlen(tempStr)+1);
    }								    /* end if (toolArg1)... */
  else
    return;
  if (toolArg2)							    /* Does the tool being examined have this argument?  */
    {
      sprintf(tempStr,"%d. %s",2,toolArg2);			    /* Yes, allocate space for the argument's name and... */
      toolInfoList[10] = (String)malloc(strlen(tempStr)+1);	    /* ...value */
      strncpy(toolInfoList[10],tempStr,strlen(tempStr)+1);
      if (tool->input2)						    /* Does this tool have a second input? */
	{							    /* Yes, determine which name to use for the input name */
	  if ((tool->input2->type == EQTool) ||			    /* Use the equation or parameter name */
	      (tool->input2->type == ParamTool))
	    sprintf(tempStr,"%s",tool->input2->fName);
	  else							    /* Use the name of the tool */
	    sprintf(tempStr,"%c%s",RateToChar(tool->input2->rate),
		    tool->input2->name);
	}
      else							    /* No, this tool has not input, try to use default arg */
	{
	  if (tool->arg2)					    /* Does a default argument exist for this tool? */
	    sprintf(tempStr,"%s",tool->arg2);			    /* Yes, use it */
	  else							    /* No, print a blank string for the Info Window */
	    sprintf(tempStr," ");
	}
      toolInfoList[11] = (String)malloc(strlen(tempStr)+1);	    /* Allocate space for the argument's name and value */
      strncpy(toolInfoList[11],tempStr,strlen(tempStr)+1);
    }
  else
    return;
  if (toolArg3)							    /* Does the tool being examined have this argument?  */
    {
      sprintf(tempStr,"%d. %s",3,toolArg3);			    /* Yes, allocate space for the argument's name and... */
      toolInfoList[12] = (String)malloc(strlen(tempStr)+1);	    /* ...value */
      strncpy(toolInfoList[12],tempStr,strlen(tempStr)+1);
      if (tool->input3)						    /* Does this tool have another input? */
	{							    /* Yes, determine which name to use for the input name */
	  if ((tool->input3->type == EQTool) ||			    /* Use the equation or parameter name */
	      (tool->input3->type == ParamTool))
	    sprintf(tempStr,"%s",tool->input3->fName);
	  else							    /* Use the name of the tool */
	    sprintf(tempStr,"%c%s",RateToChar(tool->input3->rate),
		    tool->input3->name);
	}
      else							    /* No, this tool has not input, try to use default arg */
	{
	  if (tool->arg3)					    /* Does a default argument exist for this tool? */
	    sprintf(tempStr,"%s",tool->arg3);			    /* Yes, use it */
	  else							    /* No, print a blank string for the Info Window */
	    sprintf(tempStr," ");
	}
      toolInfoList[13] = (String)malloc(strlen(tempStr)+1);	    /* Allocate space for the argument's name and value */
      strncpy(toolInfoList[13],tempStr,strlen(tempStr)+1);
    }
  else
    return;
  if (toolArg4)							    /* Does the tool being examined have this argument?  */
    {
      sprintf(tempStr,"%d. %s",4,toolArg4);			    /* Yes, allocate space for the argument's name and... */
      toolInfoList[14] = (String)malloc(strlen(tempStr)+1);	    /* ...value */
      strncpy(toolInfoList[14],tempStr,strlen(tempStr)+1);
      if (tool->input4)						    /* Does this tool have another input? */
	{							    /* Yes, determine which name to use for the input name */
	  if ((tool->input4->type == EQTool) ||			    /* Use the equation or parameter name */
	      (tool->input4->type == ParamTool))
	    sprintf(tempStr,"%s",tool->input4->fName);
	  else							    /* Use the name of the tool */
	    sprintf(tempStr,"%c%s",RateToChar(tool->input4->rate),
		    tool->input4->name);
	}
      else							    /* No, this tool has not input, try to use default arg */
	{
	  if (tool->arg4)					    /* Does a default argument exist for this tool? */
	    sprintf(tempStr,"%s",tool->arg4);			    /* Yes, use it */
	  else							    /* No, print a blank string for the Info Window */
	    sprintf(tempStr," ");
	}
      toolInfoList[15] = (String)malloc(strlen(tempStr)+1);	    /* Allocate space for the argument's name and value */
      strncpy(toolInfoList[15],tempStr,strlen(tempStr)+1);
    }
  else
    return;
  if (toolArg5)							    /* Does the tool being examined have this argument?  */
    {
      sprintf(tempStr,"%d. %s",5,toolArg5);			    /* Yes, allocate space for the argument's name and... */
      toolInfoList[16] = (String)malloc(strlen(tempStr)+1);	    /* ...value */
      strncpy(toolInfoList[16],tempStr,strlen(tempStr)+1);
      if (tool->input5)						    /* Does this tool have another input? */
	{							    /* Yes, determine which name to use for the input name */
	  if ((tool->input5->type == EQTool) ||			    /* Use the equation or parameter name */
	      (tool->input5->type == ParamTool))
	    sprintf(tempStr,"%s",tool->input5->fName);
	  else							    /* Use the name of the tool */
	    sprintf(tempStr,"%c%s",RateToChar(tool->input5->rate),
		    tool->input5->name);
	}
      else							    /* No, this tool has not input, try to use default arg */
	{
	  if (tool->arg5)					    /* Does a default argument exist for this tool? */
	    sprintf(tempStr,"%s",tool->arg5);			    /* Yes, use it */
	  else							    /* No, print a blank string for the Info Window */
	    sprintf(tempStr," ");
	}
      toolInfoList[17] = (String)malloc(strlen(tempStr)+1);	    /* Allocate space for the argument's name and value */
      strncpy(toolInfoList[17],tempStr,strlen(tempStr)+1);
    }
  else
    return;
  if (toolArg6)							    /* Does the tool being examined have this argument?  */
    {
      sprintf(tempStr,"%d. %s",6,toolArg6);			    /* Yes, allocate space for the argument's name and... */
      toolInfoList[18] = (String)malloc(strlen(tempStr)+1);	    /* ...value */
      strncpy(toolInfoList[18],tempStr,strlen(tempStr)+1);
      if (tool->input6)						    /* Does this tool have another input? */
	{							    /* Yes, determine which name to use for the input name */
	  if ((tool->input6->type == EQTool) ||			    /* Use the equation or parameter name */
	      (tool->input6->type == ParamTool))
	    sprintf(tempStr,"%s",tool->input6->fName);
	  else							    /* Use the name of the tool */
	    sprintf(tempStr,"%c%s",RateToChar(tool->input6->rate),
		    tool->input6->name);
	}
      else							    /* No, this tool has not input, try to use default arg */
	{
	  if (tool->arg6)					    /* Does a default argument exist for this tool? */
	    sprintf(tempStr,"%s",tool->arg6);			    /* Yes, use it */
	  else							    /* No, print a blank string for the Info Window */
	    sprintf(tempStr," ");
	}
      toolInfoList[19] = (String)malloc(strlen(tempStr)+1);	    /* Allocate space for the argument's name and value */
      strncpy(toolInfoList[19],tempStr,strlen(tempStr)+1);
    }
  else
    return;
  if (toolArg7)							    /* Does the tool being examined have this argument?  */
    {
      sprintf(tempStr,"%d. %s",7,toolArg7);			    /* Yes, allocate space for the argument's name and... */
      toolInfoList[20] = (String)malloc(strlen(tempStr)+1);	    /* ...value */
      strncpy(toolInfoList[20],tempStr,strlen(tempStr)+1);
      if (tool->input7)						    /* Does this tool have another input? */
	{							    /* Yes, determine which name to use for the input name */
	  if ((tool->input7->type == EQTool) ||			    /* Use the equation or parameter name */
	      (tool->input7->type == ParamTool))
	    sprintf(tempStr,"%s",tool->input7->fName);
	  else							    /* Use the name of the tool */
	    sprintf(tempStr,"%c%s",RateToChar(tool->input7->rate),
		    tool->input7->name);
	}
      else							    /* No, this tool has not input, try to use default arg */
	{
	  if (tool->arg7)					    /* Does a default argument exist for this tool? */
	    sprintf(tempStr,"%s",tool->arg7);			    /* Yes, use it */
	  else							    /* No, print a blank string for the Info Window */
	    sprintf(tempStr," ");
	}
      toolInfoList[21] = (String)malloc(strlen(tempStr)+1);	    /* Allocate space for the argument's name and value */
      strncpy(toolInfoList[21],tempStr,strlen(tempStr)+1);
    }
  else
    return;
  if (toolArg8)							    /* Does the tool being examined have this argument?  */
    {
      sprintf(tempStr,"%d. %s",8,toolArg8);			    /* Yes, allocate space for the argument's name and... */
      toolInfoList[22] = (String)malloc(strlen(tempStr)+1);	    /* ...value */
      strncpy(toolInfoList[22],tempStr,strlen(tempStr)+1);
      if (tool->input8)						    /* Does this tool have another input? */
	{							    /* Yes, determine which name to use for the input name */
	  if ((tool->input8->type == EQTool) ||			    /* Use the equation or parameter name */
	      (tool->input8->type == ParamTool))
	    sprintf(tempStr,"%s",tool->input8->fName);
	  else							    /* Use the name of the tool */
	    sprintf(tempStr,"%c%s",RateToChar(tool->input8->rate),
		    tool->input8->name);
	}
      else							    /* No, this tool has not input, try to use default arg */
	{
	  if (tool->arg8)					    /* Does a default argument exist for this tool? */
	    sprintf(tempStr,"%s",tool->arg8);			    /* Yes, use it */
	  else							    /* No, print a blank string for the Info Window */
	    sprintf(tempStr," ");
	}
      toolInfoList[23] = (String)malloc(strlen(tempStr)+1);	    /* Allocate space for the argument's name and value */
      strncpy(toolInfoList[23],tempStr,strlen(tempStr)+1);
    }
  else
    return;
}								    /* end function DrawInfoWin */
