Subversion Repositories wimsdev

Rev

Blame | Last modification | View Log | RSS feed

  1. #!/usr/local/bin/perl
  2.  
  3. $lignes_de_reponse = 5;
  4.  
  5. open ('TEX', '>chemtest.tex');
  6. print TEX "\\documentclass{article}\n";
  7. print TEX "\\title{Chemeq, a parser for chemical equations}\n";
  8. print TEX "\\author{\\copyright{} GPL 2000, Georges Khaznadar
  9. \\emph{georgesk\@boltz.univ-littoral.fr}}\n";
  10. print TEX "\\begin{document}\n\\maketitle\n\n";
  11. print TEX "\\abstract{Chemtest is a parser which analyses its standard input
  12. and outputs useful strings accounting for informations related to chemical
  13. equations. It can be embedded in educational applications.
  14. Here are listed examples of possible inputs for
  15. chemeq. Some outputs are usefully interpreted by the LaTeX language
  16. in math mode. The other outputs are typeset with \\texttt{teletype fonts}.}\n";
  17.  
  18. print TEX "\~\\\\\[3ex]\n\\hrule\n\\tableofcontents\n\~\\\\\[3ex]\n\\hrule\n";
  19. while(chomp($essai = <STDIN>)){
  20.     if(length($essai) != 0 && substr($essai,0,1) ne "#"){
  21.         for ($i=0; $i < $lignes_de_reponse; $i++){
  22.             chomp($tmp=<STDIN>); @reponse[$i]=$tmp;
  23.         }
  24.         $essai_ = $essai;
  25.         $essai_ =~ s/\'/\\\'/g;
  26.         @args = ("echo \"$essai_\" | chemeq > tmp.1");
  27.         system @args;
  28.         open (TMP,'tmp.1');
  29.         $ok=1;
  30.         $essai =~ s/\^/\\\^{}/g;
  31.         $essai =~ s/\_/\\\_{}/g;
  32.         for ($i=0; $i < $lignes_de_reponse; $i++){
  33.             chomp($tmp=<TMP>); @result[$i]=$tmp;
  34.             if (@result[$i] ne @reponse[$i]){
  35.                 @idem[i]="KO";
  36.                 $ok=0;
  37.             }
  38.             else {
  39.                 @idem[i]="OK";
  40.             }
  41.         }
  42.         if ($ok){
  43.             print TEX "\\section{OK : \\texttt{$essai}}\n";
  44.         }
  45.         else {
  46.             print TEX "\\section{ERROR : \\texttt{$essai}}\n";
  47.         }
  48.         for ($i=0; $i < $lignes_de_reponse; $i++){
  49.             print TEX @idem[i],"  ";
  50.         }
  51.         print TEX "\\\\\n";
  52.         print TEX "Expected output :\n";
  53.         print TEX "\\begin{enumerate} \n";
  54.         for ($i=0; $i < $lignes_de_reponse; $i++){
  55.             print TEX "\\item ";
  56.             if (@reponse[$i] =~ /\\/){
  57.                 print TEX "\$\$",@reponse[$i],"\$\$\n";
  58.             }
  59.             else {
  60.                 $buffer = @reponse[$i];
  61.                 print TEX "\\verb|", $buffer,"|\n";
  62.             }
  63.         }
  64.         print TEX "\\end{enumerate}\n";
  65.         if (!$ok){
  66.             print TEX "found output :\n";
  67.             print TEX "\\begin{enumerate} \n";
  68.             for ($i=0; $i < $lignes_de_reponse; $i++){
  69.                 print TEX "\\item \\verb|", @reponse[$i], "|\n";
  70.             }
  71.             print TEX "\\end{enumerate}\n";
  72.         }
  73.     }
  74. }
  75.  
  76. print TEX "\\end{document}\n";
  77.  
  78. close TEX;
  79.  
  80. system ("echo q | latex chemtest.tex");
  81. system ("echo q | latex chemtest.tex");
  82. system ("xdvi chemtest.dvi");
  83.