/*   -*- coding: utf-8 -*-  */
/***********************************************************************
   Projet : DilibSxml
   Module : SxmlInter
   Fichier: SxmlSelectTools.c
   $Id: SxmlSelectTools.c,v 1.4 2003/07/29 16:21:52 parmentf Exp $
 ***********************************************************************/
/**
   @file

   @brief Tool functions for SxmlSelect
   
   @author &copy; INIST-CNRS
   @author Jacques DUCLOY <DilibMaster@inist.fr>
 */

#include "SxmlSelect.h"
#include "SxmlC.h"

/**
   Creates, initializes, and returns a new SxmlMemory (initialized for
   Dom, SxPath, an C).

   @return the SxmlMemory created.  
   @warning the returned SxmlMemory needs to be freed.
 */
SxmlMemory *SxmlSelectMemoryCreate()
{
  SxmlMemory *mem1;
  mem1=SxmlMemoryCreate();
  SxmlDomMemoryInit(mem1);
  SxPathMemoryInit(mem1);
  SxmlCMemoryInit(mem1);
  return mem1;

}


/**
   Adds the script @a str1 to @a mem1, with the name @a n1.

   @param mem1 SxmlMemory to which the script is added
   @param n1   name of the script to add
   @param str1 string of the script to add
   @return the function created.
 */
SxmlNode *SxmlSelectMemoryAddScript(SxmlMemory *mem1,
				  char      *n1,
				  char      *str1)
{
  SxmlNode *sc1;
  SxmlNode *f1;
  sc1= SxmlFromString(str1);
  f1=SxmlMemoryAppendToFunction(mem1,n1,sc1);
  return f1;
}


/**
   Adds a print @c c:printf function to @a mem1, in order to print the
   @a str1 specification.

   @param mem1 
   @param str1 the name of the variable to print in "@va" format
   @return the SxmlProcessorFunction to print @a str1
 */
SxmlNode *SxmlSelectMemoryAddPrint(SxmlMemory *mem1,
				 char *str1)
{
  SxmlNode *nPrint;
  SxmlNode *f1;
  nPrint=SxmlCPrintfFromStringVar(str1);
  f1=SxmlMemoryAppendToFunction(mem1,"xmlSelect:steps",nPrint);
  return f1;
}

SxmlProcessor *SxmlSelectProcCreate()
{
  /*  SxmlMemory    *memorySxmlSelect; */
  SxmlProcessor *processorSxmlSelect;

  SxmlSelectMemory    = SxmlSelectMemoryCreate();
  processorSxmlSelect = SxmlProcessorCreate(SxmlSelectMemory);

  return processorSxmlSelect;
}
