
/****************************************************************************
*
*      Projet  : DilibPro
*      Module  : Sxml
*      Fichier : SxmlComment.c
*      Auteur  : J. Ducloy
*
*      Derniere mise a jour Decembre 2000
*
************************************************************************
* 
*     Copyrigth (C) 2001 CNRS INIST
*
****************************************************************************/

#include "Buffer.h"
#include "SxmlNode.h"
#include "Except.h"
SxmlNode *SxmlCommentCreate(str)
     char *str;
{
  SxmlNode	*curComment;
  char *strD;
  if(!(strD=strdup(str)))
    {
      ExceptSetError("SxmlNode","MA", "memory allocation failed","","",2);
    }
  curComment = SxmlNodeCreate(XML_NODE_COMMENT);
  SxmlSetNodeName(curComment,"#comment");
  SxmlSetNodeValue(curComment,strD);
  SxmlSetNodeValueToFree(curComment);

  return (curComment);
}

void SxmlCommentFilePrint(n1,f1)
     SxmlNode *n1;
     FILE *f1;
{
  fprintf(f1,"<!--%s-->",SxmlNodeValue(n1));
}

char *SxmlCommentToString(b1,c1)
     Buffer *b1;
     SxmlNode *c1;
{
  BufferStrcat(b1,"<!--");
  BufferStrcat(b1,SxmlNodeValue(c1));
  BufferStrcat(b1,"-->");
  return BufferString(b1);
}

void SxmlCommentIndent(SxmlNode *n1, Buffer *bufInd, int inc)
{
  printf("%s<!--%s-->\n", BufferString(bufInd),  SxmlNodeValue(n1));
}

char *SxmlCommentBufferCat(n1,b1)
     SxmlNode *n1;
     Buffer *b1;
{
  BufferStrcat(b1,"<!--");
  BufferStrcat(b1,SxmlNodeValue(n1));
  BufferStrcat(b1,"-->");
  return BufferString(b1);
}

SxmlNode *SxmlProcessingInstructionCreate(t1,d1)
     char *t1;
     char *d1;
{
  SxmlNode *x1;
  x1=SxmlNodeCreate(XML_NODE_PROCESSING_INSTRUCTION);
  SxmlProcessingInstructionSetTarget(x1,strdup(t1));
  if (d1)
    {
      SxmlProcessingInstructionSetData(x1,strdup(d1));
    }
  else
    {
      SxmlProcessingInstructionSetData(x1,strdup(""));
    }

  SxmlSetNodeValueToFree(x1);

  SxmlSetNodeNameToFree(x1);
  return x1;
}

void SxmlProcessingInstructionFilePrint(x1,f1)
     SxmlNode *x1;
     FILE *f1;
{
  fprintf(f1,"<?%s %s?>",
	  SxmlProcessingInstructionTarget(x1),
	  SxmlProcessingInstructionData(x1));
}

void SxmlProcessingInstructionIndent(SxmlNode *n1, Buffer *bufInd, int inc)
{
    printf("%s<?%s %s?>\n", BufferString(bufInd), 
	  SxmlProcessingInstructionTarget(n1),
	  SxmlProcessingInstructionData(n1));
}
