/usr/share/perl5/AMC/Filter/register.pm is in auto-multiple-choice-common 1.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | #
# Copyright (C) 2012 Alexis Bienvenue <paamc@passoire.fr>
#
# This file is part of Auto-Multiple-Choice
#
# Auto-Multiple-Choice is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# Auto-Multiple-Choice is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Auto-Multiple-Choice. If not, see
# <http://www.gnu.org/licenses/>.
package AMC::Filter::register;
use Module::Load;
use Module::Load::Conditional qw/check_install/;
use AMC::Basic qw(!file_mimetype);
use_gettext;
#####################################################################
# These methods should be overwritten for derivated classes (that
# describe file formats that AMC can handle)
#####################################################################
sub new {
my $class = shift;
my $self={'project_options'=>''};
bless ($self, $class);
return $self;
}
# short name of the file format
sub name {
return("empty");
}
# default filename when creating a new one inside project directory
sub default_filename {
return("source");
}
# create new empty file
sub default_content {
my ($self,$file)=@_;
}
# weight in the list of all available formats. 0 is at the top, 1 is
# at the bottom line
sub weight {
return(1);
}
# function to set some project parameters for this format to work properly.
# use <set_project_option> method
sub configure {
my ($self,$options_project);
}
# this function returns a list of project options that are set
# automatically by the filter. These options will be greyed out in the
# Edit/Preferences window so that the user can not modify them.
sub forced_options {
return();
}
# description of the format, that will be display in the window
# showing details about file formats
sub description {
return(__"No description available.");
}
# list of file patterns (like "*.txt") that corresponds to source
# files for this format
sub file_patterns {
return();
}
# filetype to choose right editor. Currently, only "tex" and "txt" are
# available.
sub filetype {
return("");
}
# returns an URL where to find documentation about the syntax to be
# used
sub doc_url {
return("");
}
# list of required LaTeX packages
sub needs_latex_package {
return();
}
# list of required commands
sub needs_command {
return();
}
# list of required fonts
sub needs_font {
return([{'type'=>'fontconfig',
'family'=>[]}, # <-- needs one of the fonts in the list
]);
}
# returns a number that tells how likely the file is written for this
# format. 1.0 means "yes, I'm sure this file is written for this
# format", -1.0 means "I'm sure it is NOT written for this format",
# and 0.0 means "I don't know".
sub claim {
my ($self,$file)=@_;
return(0);
}
#####################################################################
# The following methods should NOT be overwritten
#####################################################################
sub set_oo {
my ($self,$o)=@_;
$self->{'project_options'}=$o;
}
sub set_project_option {
my ($self,$name,$value)=@_;
my $old=$self->{'project_options'}->{$name};
$self->{'project_options'}->{$name}=$value;
$self->{'project_options'}->{'_modifie'}.=','.$name if($value ne $old);
}
sub missing_latex_packages {
my ($self)=@_;
return() if(!commande_accessible("kpsewhich"));
my @mp=();
for my $p ($self->needs_latex_package()) {
my $ok=0;
open KW,"-|","kpsewhich","-all","$p.sty";
while(<KW>) { chomp();$ok=1 if(/./); }
close(KW);
push @mp,$p if(!$ok);
}
return(@mp);
}
sub missing_commands {
my ($self)=@_;
my @mc=();
for my $c ($self->needs_command()) {
push @mc,$c if(!commande_accessible($c));
}
return(@mc);
}
sub missing_fonts {
my ($self)=@_;
my @mf=();
my $fonts=$self->needs_font;
for my $spec (@$fonts) {
push @mf,$spec if(!check_fonts($spec));
}
return(@mf);
}
sub check_dependencies {
my ($self)=@_;
my %miss=('latex_packages'=>[$self->missing_latex_packages()],
'commands'=>[$self->missing_commands()],
'fonts'=>[$self->missing_fonts()],
);
my $ok=1;
for my $k (keys %miss) {
$ok=0 if(@{$miss{$k}});
}
$miss{'ok'}=$ok;
return(\%miss);
}
sub file_head {
my ($self,$file,$size)=@_;
return('') if(!$file);
my $h;
my $n;
my $fh;
return if(!-f $file);
if(open($fh,"<",$file)) {
$n=read $fh,$h,$size;
close($fh);
}
if(!defined($n)) {
debug_and_stderr("Error reading from $file: $!");
}
return($h);
}
sub file_mimetype {
my ($self,$file)=@_;
return(AMC::Basic::file_mimetype($file));
}
1;
|