#!/usr/bin/perl eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0; # not running under some shell # PASSarola EXErcise Generator v1.0 use utf8::all; use strict; use warnings; 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 res showrand no db store solved h dl d d1 dump test exid=s 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} = 1; $S{res} = 0 } if($S{store} ){ $S{d} = 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 = (); if($S{catalog}) { push( @catlist, (split(/:/,$S{catalog})) ); } else { push( @catlist, "$ENV{HOME}/.mex_catalogue") if -f "$ENV{HOME}/.mex_catalogue"; } my $f1 = shift or die("usage: $0 [options] file\n"); my ($f,$nam1,$nam2)=($f1,".",""); ($f,$nam1,$nam2)=get_pass_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"; if($S{passdir}) { set_pass_basedir($S{passdir}); } else { set_pass_basedir($ENV{'HOME'}.'/.passarola/'); } pass2exsheets ({ ($S{nosol} ? (nosol =>$S{nosol}) :()), ($S{res} ? (res =>$S{res}) :()), ($S{solved} ? (solved=>$S{solved}):()), ($S{s} ? (s =>$S{s}) :()), ($S{title} ? (title =>$S{title}) :()), ($S{autthor}? (author=>$S{author}):()), },[$f,@ARGV],$S{o}); sub mariq_ebank_store{ my $exid=shift; if($S{test}){ print $exid; } else { print "New exercise is id: $exid \n"; } } sub pass2exsheets{ ## multi-exercise : generates a exe.tex file my %opt =(n => 1,res=>0, nosol => 0, s => 0,solved =>0); if(ref($_[0]) eq "HASH") {%opt = (%opt , %{shift(@_)}) } ; my ($f,$o)= @_; my @files = ref($f)? @$f : ($f); my @q = (); my @r = (); my @resol = (); my ($enu,$sol,$res,$t); open (F,">:utf8",$o) or die("cant create output file $o\n"); for my $f2 (@files){ ($f1,$nam1,$nam2)=get_pass_filename($f2,@catlist); die("File $1 does not exist!\n") unless $f1 && -e $f1; 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}; $enu = $t->{question}{v1} ; $sol = $t->{result}{v1} ; $res = $t->{resolution}{v1} ; print F "\\begin{question}\n$enu\n\\end{question}\n"; if($opt{solved}){ print F "\\begin{solution}[print]\n$res\n\\end{solution}\n" ; } else { print F "\\begin{solution}\n$sol\n\\end{solution}\n" if not $opt{res}; print F "\\begin{solution}\n$res\n\\end{solution}\n" if $opt{res}; } print F "\n\n" ; } close F; my %meta = ( title => $opt{title}, subtitle => $opt{author} || '\mbox{}' , data => $opt{data} || '\today' ); } #======== Exe::Gen::Catalogue sub get_pass_filename{ my ($f,@cata)=@_; if(-f $f){ ## if local file: if( $f =~ m!(.*)/(.*)!){ return( $f , $1, $2)} else { return("./$f",".", $f)} } my $cata=""; $cata = "-cata ". join(":",@cata) if @cata; my $a = `pass-logue -meta $cata "$f"`; warn("Error $!\n") if $!; my $b = eval $a; warn("Error $@\n") if $@; return ("","","") unless $b->[0]{file}; ## not found return ("$b->[0]{dir}/$b->[0]{file}",$b->[0]{dir},$b->[0]{file}); } #======= Exe::Gen::converter (mariquices diversa) sub showpdf{ my $p=shift(@_); my $shh = ' > /dev/null 2>&1'; # para manter os comandos calados ($S{d1} and system("acroread $p".$shh) == 0) or system("jpdf $p".$shh) == 0 or #system("xpdf $p".$shh) == 0 or system("evince $p".$shh) == 0 or system("gnome-open $p".$shh) == 0 or system("open $p".$shh) == 0 or die("pass-exer.showpdf: Unable to find pdf (".$p.")\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}