#!/usr/bin/perl BEGIN{ print "This script is deprecated, use pass-exeg.\n"; exit 0;} use strict; use utf8::all; use Getopt::Long qw(:config no_auto_abbrev ); use Pod::Usage; use Cwd; use MLDBM qw(DB_File); use DB_File; use Fcntl; use Data::Dumper; use Exercise::Gen::Let; use Exercise::Gen::Verify; use Parse::DSLUtils; skimport(); my %S=(n=>1); GetOptions( \%S, qw{help|? man l s=i o=s srand=i passdir=s pdf pdf2 nosol nores showrand nohead no db store h dl d d1 dump test catalog=s title|tit=s author|aut=s outdir=s } ) or die "Specify the --help (or -?) option for usage information.\n"; if($S{help} ){ pod2usage(2) } if($S{man} ){ pod2usage(-exitstatus => 0, -verbose => 2) } if($S{no} ){ $S{nosol} = $S{nores} = $S{nohead} = 1 } #if($S{d} ){ $S{pdf} = 1 } if($S{d1} ){ $S{showrand} = $S{pdf} = 1 } if($S{srand} ){ srand($S{srand}) } if($S{h} ){ print EXE(); exit 0 } ### Mex skeleton ## Output directory my $cwd=cwd(); $S{outdir} //="OUT"; $S{outdir} = "$cwd/$S{outdir}" unless $S{outdir} =~ m!^[./~]!; $S{outdir} =~ s!^\.!$cwd/! if $S{outdir} =~ m!^[.][^.]!; mkdir $S{outdir}; ## Catálogue my @catlist = (); push( @catlist, (split(/:/,$S{catalog})) ) if $S{catalog}; push( @catlist, "$ENV{HOME}/.mex_catalogue") if -f "$ENV{HOME}/.mex_catalogue"; my $state = {}; my $f1 = shift or die("usage: $0 [options] file\n"); my ($f,$nam1,$nam2)=($f1,".",""); ($f,$nam1,$nam2)=get_mex_filename($f1,@catlist); die("File $1 does not exist!\n") unless $f && -e $f; my $base = $nam2; $base =~ s!\.(.{1,5}$)!!; $S{o} ||= "$S{outdir}/$base.tex"; set_pass_basedir($S{passdir}) if $S{passdir}; if($S{dl}){ Exercise::Gen::Let::lexdebug($f); exit 0} if($S{dump} ){ Exercise::Gen::Let::parseFile($f); print Dumper(\%Exercise::Gen::Let::sem ); exit 0} if($S{d}){ debugmex ($f,$S{o})} else { mex2tex ({ ($S{nosol} ? (nosol =>$S{nosol}) :()), ($S{nores} ? (nores =>$S{nores}) :()), ($S{nohead} ? (nohead=>$S{nohead}):()), ($S{s} ? (s =>$S{s}) :()), ($S{title} ? (title =>$S{title}) :()), ($S{autthor}? (author=>$S{author}):()), },[$f],$S{o})} if($S{pdf} or $S{pdf2}){ tex2pdf("$S{outdir}/$base.tex"); showpdf("$S{outdir}/$base.pdf") if $S{pdf}; } sub debug_tab{ my $tab=""; my $t= $Exercise::Gen::Let::sem{texblocks}; my $v= $Exercise::Gen::Let::sem{ts}; for (keys %$v ){ $tab.= sprintf("%5s | %20s | %s\n", $_, $v->{$_}{fv}, $v->{$_}{v1})}; RAND({tab => $tab}); } sub debugmex{ ## debug multi-exercise : generates a exe+solu+... tex file my ($f,$o)= @_; Exercise::Gen::Let::parseFile($f); Exercise::Gen::Let::calcsem(); my $t= $Exercise::Gen::Let::sem{texblocks}; my $v= $Exercise::Gen::Let::sem{ts}; my $tab=""; if($S{showrand}){$tab=debug_tab(); } open (F,">",$o) or die("cant create output file $o\n");; print F LATDEBUG({ showrand => $tab, map {("_$_"=>$t->{$_}{v1} )} qw(sugestion result author title usepackage resolution obs question) }); close F; if($S{db}){ my $verify = $Exercise::Gen::Let::sem{verify}; my $verify_fun = $Exercise::Gen::Let::sem{verify_fun}; mex2db($verify, $base, $S{outdir}, $verify_fun); } if($S{store}){ my $verify = $Exercise::Gen::Let::sem{verify}; my $verify_fun = $Exercise::Gen::Let::sem{verify_fun}; ebank_store($verify, $t->{question}{v1}, $verify_fun, $o); } } sub ebank_store{ my ($verify, $q, $verify_fun, $o) = @_; my $exid = pass_newid(); my $tmp = {}; $tmp->{enun} = $q; set_exercise_enun($exid,$tmp->{enun}); set_exercise_html($exid,tex2rhtml($o)); set_exercise_verify_func($exid, $verify_fun); my $tmp2 = {}; my $n = 0; for(@{$verify}){ $n++; $tmp2->{"Q_$n"} = {v => $_->{v1}, type => $_->{type}, func => $_->{func}}; } set_exercise_answer($exid,$tmp2,$n); if($S{test}){ print $exid; } else{ print "New exercise is id: $exid \n"; } } #deprecated sub mex2db{ my ($verify, $base, $outdir, $verify_fun) = @_; my %EXER; my $x= tie %EXER, 'MLDBM' , "MEX/mex.db", O_CREAT|O_RDWR, 0644 or die $! ; my $topid = $EXER{topid}; $EXER{topid} = $topid+1; my $tmp = $EXER{$topid}; $tmp->{enun} = scalar(`ppdflatex -p -Q $outdir/$base.tex | tth -a -e1 -u -r 2>/dev/null`); my $tmp2 = $tmp->{answer}; for(@{$verify}){ my $h = {answer => $_->{v1}, type => $_->{type}, func => $_->{func}}; push(@{$tmp2},$h); } $tmp->{answer} = $tmp2; $tmp->{perl} = $verify_fun; $EXER{$topid} = $tmp; print "New exercise is id: $topid \n"; } sub mex2tex{ ## multi-exercise : generates a exe.tex file my %opt =(n => 1,nores=>0, nosol => 0, s => 0,nohead=>0); if(ref($_[0]) eq "HASH") {%opt = (%opt , %{shift(@_)}) } ; my ($f,$o)= @_; my @files = ref($f)? @$f : ($f); my @q = (); my @r = (); my $rule = "\n\n....................\n\n"; my @resol = (); my ($enu,$sol,$res,$t); for my $f1 (@files){ Exercise::Gen::Let::parseFile($f1); Exercise::Gen::Let::calcsem(); $t= $Exercise::Gen::Let::sem{texblocks}; $opt{title} //= $t->{title}{v1}; $opt{subtitle} //= $t->{author}{v1}; $opt{data} //= $t->{data}{v1}; push(@q ,{q=> $t->{question}{v1} }); push(@r ,{q=> $t->{question}{v1} . $rule . $t->{result}{v1} }); push(@resol ,{q=> $t->{question}{v1} . $rule . $t->{resolution}{v1} }); } my %meta = ( title => $opt{title}, subtitle => $opt{author} || '\mbox{}' , data => $opt{data} || '\today' ); if ($opt{s}==0){ $enu= join("\n\n\\hrule\n\n",map {$_->{q}} @q); $sol= join("\n\n\\hrule\n\n",map {$_->{q}} @r); $res= join("\n\n\\hrule\n\n",map {$_->{q}} @resol); } elsif($opt{s}==1){ $enu= question( @q); $sol= question( @r); $res= question( @resol); } elsif($opt{s}==2){ $enu = ENUN({ questions => question( @q), %meta }); $sol = ENUN({ questions => question( @r), %meta }); $res = ENUN({ questions => question( @resol), %meta }); } my $body= join('\newpage ', ( $enu, ($opt{nosol} ? () : ($sol)), ($opt{nores} ? () : ($res)), )); if($opt{nohead}){ open (F,">:utf8",$o) or die("cant create output file $o\n"); print F $enu; close F; open (F,">:utf8","$o-sol") or die("cant create output file $o\n"); print F $res; close F; } else { open (F,">:utf8",$o) or die("cant create output file $o\n"); print F TEX( { _usepackage => $t->{usepackage}{v1}, tex_body => $body, }); close F; } } #======== Exe::Gen::Catalogue sub get_mex_filename{ my ($f,$cata)=@_; my $a = `mex_catalogue -meta -cata "$cata" "$f"`; warn("Error $!\n") if $!; my $b = eval $a; warn("Error $@\n") if $@; return ("","","") unless $b->[0]{file}; return ("$b->[0]{dir}/$b->[0]{file}",$b->[0]{dir},$b->[0]{file}); } #======= Exe::Gen::converter (mariquices diversa) sub showpdf{ my $p= shift || "$S{outdir}/$base.tex"; ($S{d1} and system("acroread $p") == 0) or system("jpdf $p") == 0 or # system("xpdf $p") == 0 or system("evince $p") == 0 or system("open $p") == 0 or die("Error no PDF found\n"); } sub tex2pdf{ my $file=shift; my $pp = undef; if( -x "/usr/local/bin/ppdflatex" ){ $pp ||='/usr/local/bin/ppdflatex';} if( -x "/usr/bin/ppdflatex" ){ $pp ||='/usr/bin/ppdflatex';} if( -x "/bin/ppdflatex" ){ $pp ||='/bin/ppdflatex';} if( -x "/opt/bin/ppdflatex" ){ $pp ||='/opt/bin/ppdflatex';} if( -x "/opt/local/bin/ppdflatex" ){ $pp ||='/opt/local/bin/ppdflatex';} if($pp){ system("$pp -Q $file")== 0 or die("Error in ppdflatex\n");} else { my $op = ""; if( $file =~ m!(.+)/(.*)!) {$op="--output-directory $1"} system("pdflatex -interaction nonstopmode $op $file")== 0 or die("Error in ppdflatex\n");} } sub tex2rhtml{ my $file=shift; my $pp = undef; if( -x "/usr/local/bin/ppdflatex" ){ $pp ||='/usr/local/bin/ppdflatex';} if( -x "/usr/bin/ppdflatex" ){ $pp ||='/usr/bin/ppdflatex';} if( -x "/bin/ppdflatex" ){ $pp ||='/bin/ppdflatex';} if( -x "/opt/bin/ppdflatex" ){ $pp ||='/opt/bin/ppdflatex';} if( -x "/opt/local/bin/ppdflatex" ){ $pp ||='/opt/local/bin/ppdflatex';} return scalar(`$pp -p -Q $file | tth -a -e1 -u -r 2>/dev/null`); } __DATA__ __jjaulas__ \RequirePackage[a4paper,top=2cm,left=2cm,right=2cm,bottom=1.5cm,nohead,nofoot]{geometry} \parindent 0pt \parskip 3pt \fvset{fontsize=\small, numbers=left, frame=leftline, numberblanklines=false} \newcounter{quest} %\def\theenumi{\alpha{enumi}} \newenvironment{questao}[2][]{ \def\theenumi{\alph{enumi})} \addtocounter{quest}{1}{\bf Quest\~ao \thequest\ (#2)} \marginpar{#1} }{ \addvspace{2mm}\mbox{}\hrule\mbox{} } \newenvironment{exame}[3]{\noindent\fbox{\begin{minipage}{\textwidth}\begin{center} {\Huge #1 \\ \huge #2 \\ \large #3\\} \end{center}\end{minipage}} \mbox{}\\}{} \newcommand{\exametitle}[3]{\noindent\fbox{\begin{minipage}{\textwidth}\begin{center} {\Huge #1 \\ \huge #2 \\ \large #3\\} \end{center}\end{minipage}} \mbox{}\\} \newif\iftth __LATDEBUG__ [%default:{ _usepackage=>'%no #usepackage provided', _sugestion =>'... no sugestion provided', _resolution=>'... no resolution provided', _author=>'', data=>'\today', _obs=>'', sugestion => 'sugestion', resolution => 'resolution', result => 'result', showrand => '', }%] \documentclass[portuges,a4paper]{article} \usepackage{babel} \usepackage[mathletters]{ucs} \usepackage[utf8x]{inputenc} \usepackage[T1]{fontenc} \usepackage{fancyvrb} %\usepackage{t1enc} %\usepackage{jjaulas} \usepackage{graphicx} [% _usepackage %] [%!jjaulas %] \begin{document} \exametitle{[% _title %]}{[% _author %]\mbox{}}{[%data%]} \iftth \begin{html}