Bull. Soc. sci. Nancy (1898) Millot/Outils

De Wicri Nancy
Révision datée du 2 mars 2020 à 00:19 par imported>Jacques Ducloy (Jacques Ducloy a déplacé la page Bull. Soc. sci. Nancy (1898) Millot/Lex vers Bull. Soc. sci. Nancy (1898) Millot/Outils)

Cette page montre une utilisation de l'analyseur lexical lex pour faciliter la conversion des tableaux.

Le programme lex

cat <<... > convertTab.lex
 int zone;
%START TEMP
%START AN
%%
^[1-9][0-9]*       {printf("|-\n|%s\n|&nbsp;", yytext); BEGIN TEMP; zone=2;}
<TEMP>"—"             printf("-");
<TEMP>[1-9]"°"[0-9]*  {printf("0%s\n", yytext); zone++;  BEGIN AN;}
<TEMP>[1-9][0-9]"°"[0-9]*  {printf("%s\n", yytext); zone++;  BEGIN AN;}
<AN>18[0-9][0-9]      {printf("|%s\n|", yytext); zone++; BEGIN TEMP; }
<AN>18[0-9][0-9][ ]*"et"[ ]*18[0-9][0-9]      {printf("|%s\n|", yytext); zone++; BEGIN TEMP; }
. ;
\n BEGIN 0;
%%
int main()
{
    printf("{| class=\"wikitable sortable\"\n");
    printf("|-\n!jour\n!minimum\n!année\n!maximum\n!année\n!différence\n");
    yylex();
    printf("|-\n|}\n");
}
...

lex convertTab.lex

gcc lex.yy.c -ll -o convertTab

./convertTab < fevrier.text

Récupération des tableaux

WicriGetPage -l wicri-nancy.fr -p "Bull. Soc. sci. Nancy (1898) Millot/Tableaux mensuels"
cat <<... > consolide.c
#include "SxmlNode.h"
main()
{
  SxmlNode *docu;
  char *c1, *c2, *c3, *c4, *c5, *mois, *an ;
  mois=malloc(10);
  an=malloc(10);
  while((docu=SxmlInputGetDocumentElement()))
    {
       c1=SxmlLeafText(SxmlFirstChild(SxmlGetFirstChildByTagName(docu,"c1")));
       c2=SxmlLeafText(SxmlFirstChild(SxmlGetFirstChildByTagName(docu,"c2")));
       if (strcmp(c1, "mois")==0) {strcpy(mois, c2); continue;}
       c3=SxmlLeafText(SxmlFirstChild(SxmlGetFirstChildByTagName(docu,"c3")));
       printf("|-\n|");
       if(strlen(c3) > 4) {strncpy(an,c3,4); printf ("%s/", an); }
       else printf ("%s/", c3);
       printf("%s/%s\n", mois, c1);
       printf("|%s\n", c2);
       c4=SxmlLeafText(SxmlFirstChild(SxmlGetFirstChildByTagName(docu,"c4")));
       c5=SxmlLeafText(SxmlFirstChild(SxmlGetFirstChildByTagName(docu,"c5")));
       if(strlen(c5) > 4) {strncpy(an,c5,4); printf ("|%s/", an); }
       else printf ("|%s/", c5);
       printf("%s/%s\n", mois, c1);
       printf("|%s\n", c4);
    }
}
...

gcc consolide.c $DILIB_CC -o consolide