#include #include #include #include "permut.h" #include "pagin.h" class PAGIN_XML: public PAGIN_V{ bool sgml_aware; protected: FILE *fout; /*~PROTOBEG~ PAGIN_XML */ public: PAGIN_XML (void); void check (int); void close (void); void finsous (void); void form (void); void format_fct (const char *fct, int premiere); void format_paragraphe (char *buf); void format_ref (const char *ref); void format_spec (const char *filespec, const char *buf); void format_titre (int niveau, const char *secnum, char *buf); void fprintf (FILE *f, const char *ctl, ...); void fputs (const char *buf, FILE *fout); void nl (void); int openerr (const char *fname, int quit); void printf (const char *ctl, ...); int set_format (int _format); void soussection (void); ~PAGIN_XML (void); /*~PROTOEND~ PAGIN_XML */ }; PUBLIC PAGIN_XML::PAGIN_XML() { fout = NULL; sgml_aware = false; } PUBLIC PAGIN_XML::~PAGIN_XML() { close(); } /* Ouvre un fichier d'output avec pagination Retourne -1 si erreur */ PUBLIC int PAGIN_XML::openerr ( const char *fname, int quit) { if (fname == NULL){ fout = stdout; }else{ fout = fopen_err (fname,"w",quit); } format = PAG_FORMAT_PARA; return 0; } /* Termine output dans un fichier */ PUBLIC void PAGIN_XML::close () { if (fout != NULL){ if (fout != stdout) fclose (fout); fout = NULL; } } /* Controle le mode de formattage des paragraphe. Retourne la valeur courante. */ PUBLIC int PAGIN_XML::set_format (int _format) { int ret = format; if (_format != format){ char *cmd = ""; if (format == PAG_FORMAT_NONE){ //cmd = "\n"; }else if (format == PAG_FORMAT_QUOT){ //cmd = "\n"; } ::fprintf (fout,"%s",cmd); PAGIN_V::set_format (_format); cmd = ""; if (format == PAG_FORMAT_NONE){ // cmd = "\n"; }else if (format == PAG_FORMAT_QUOT){ //cmd = "\n"; } ::fprintf (fout,"%s",cmd); } return ret; } /* Génère un saut de page et ajuste */ PUBLIC void PAGIN_XML::form () { } static void paging_fputc (char car, FILE *fout, bool sgml_aware) { if (car == '&'){ ::fputs ("&",fout); //}else if (car == '$'){ // ::fputs ("$",fout); //}else if (car == '#'){ // ::fputs ("#",fout); //}else if (car == '%'){ // ::fputs ("%",fout); //}else if (car == '~'){ // ::fputs ("˜",fout); //}else if (car == '"'){ // ::fputs ("&dquot;",fout); }else if (!sgml_aware){ if (car == '<'){ ::fputs ("<",fout); }else if (car == '>'){ ::fputs (">",fout); }else{ fputc (car,fout); } }else{ fputc (car,fout); } } static void paging_url ( const char *file, const char *entry, FILE *fout) { ::fprintf (fout,"" ,file,entry,entry); } PUBLIC void PAGIN_XML::fputs (const char *buf, FILE *fout) { if (format != PAG_FORMAT_PARA){ while (*buf != '\0') paging_fputc (*buf++,fout,sgml_aware); }else{ crosstbl_filter (buf,fout,paging_fputc,paging_url,sgml_aware); } } PUBLIC void PAGIN_XML::printf ( const char *ctl, ...) { if (format == PAG_FORMAT_QUOT) fputs ("\t",fout); va_list list; va_start (list,ctl); char buf[5000]; vsnprintf (buf,sizeof(buf)-1,ctl,list); fputs (buf,fout); va_end (list); } /* fprintf avec traduction. */ PUBLIC void PAGIN_XML::fprintf ( FILE *f, const char *ctl, ...) { va_list list; va_start (list,ctl); char buf[5000]; vsprintf (buf,ctl,list); va_end (list); fputs (buf,f); } /* Saute une ligne */ PUBLIC void PAGIN_XML::nl () { //fputs ("

\n",fout); } /* Vérifie s'il y a au moins N lignes disponible jusqu'à la fin de la page Si pas assez, génère un saut de page. Le nombre de lignes est automatiquement ajouté. L'appelant devra affiché lui-même sans utiliser les fonctions de pagin. Le compte sera faussé sinon */ PUBLIC void PAGIN_XML::check (int) { } /* Génère un paragraphe d'un coup en formattant ou pas. En mode XML, on ne s'occupe pas de ca. C'est set_format qui fait tout. */ PUBLIC void PAGIN_XML::format_paragraphe (char *buf) { if (format) ::fputs ("

\n",fout); fputs (buf,fout); fputs ("\n",fout); } /* Génère le titre d'une section. */ PUBLIC void PAGIN_XML::format_titre ( int niveau, // Niveau de numérotation const char *secnum, // Numérotation de la section char *buf) // Titre de la section { int old_format = format; format = PAG_FORMAT_QUOT; if (niveau == 0){ ::fputs ("",fout); printf ("%s\n",buf); ::fputs ("

\n",fout); }else{ ::fprintf (fout,"",niveau); printf ("%s\n",buf); ::fputs ("

\n",fout); } format = old_format; } /* Génère l'entête d'une spécification. */ PUBLIC void PAGIN_XML::format_spec ( const char *filespec, // Nom du fichier qui contient cette spec const char *buf) // Titre de la spec (clé de classement) { nl(); ::fputs ("

\n",fout); printf ("%s (%s)\n\n",buf,filespec); } /* Génère l'entête d'une fonction. */ PUBLIC void PAGIN_XML::format_fct ( const char *fct, // Nom du fichier qui contient cette spec int premiere) // Premiere fois qu'on parle de cette fonction { ::fputs ("

\n",fout); if (premiere){ ::fprintf (fout,"

\n",fct,fct); }else{ ::fprintf (fout,"

\n",fct,fct); } nl(); } /* Génère un label */ PUBLIC void PAGIN_XML::format_ref ( const char *ref) // Référence à encoder { ::fprintf (fout,"

\n",section); } nacom_process (pout,argv+1,argc-1,".",recur,xml); pout.close (); if (xml){ printf ("
\n"); } ret = 0; } } return ret; }