/usr/share/doc/defoma-doc/defoma-script.html/ch2.html is in defoma-doc 0.11.12ubuntu1.
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 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>A Tutorial on Writing Defoma Configuration Script - Simple Defoma-configuration script.</title>
<link href="index.html" rel="start">
<link href="ch1.html" rel="prev">
<link href="ch3.html" rel="next">
<link href="index.html#contents" rel="contents">
<link href="index.html#copyright" rel="copyright">
<link href="ch1.html" rel="chapter" title="1 Introduction">
<link href="ch2.html" rel="chapter" title="2 Simple Defoma-configuration script.">
<link href="ch3.html" rel="chapter" title="3 Using hints.">
<link href="ch4.html" rel="chapter" title="4 Using Defoma::Id module.">
<link href="ch5.html" rel="chapter" title="5 Using Defoma::Id (2)">
<link href="ch6.html" rel="chapter" title="6 Using Defoma::Subst module.">
<link href="ch7.html" rel="chapter" title="7 Using x-postscript Category.">
</head>
<body>
<p><a name="ch2"></a></p>
<hr>
<p>
[ <a href="ch1.html">previous</a> ]
[ <a href="index.html#contents">Contents</a> ]
[ <a href="ch1.html">1</a> ]
[ 2 ]
[ <a href="ch3.html">3</a> ]
[ <a href="ch4.html">4</a> ]
[ <a href="ch5.html">5</a> ]
[ <a href="ch6.html">6</a> ]
[ <a href="ch7.html">7</a> ]
[ <a href="ch3.html">next</a> ]
</p>
<hr>
<h1>
A Tutorial on Writing Defoma Configuration Script
<br>Chapter 2 - Simple Defoma-configuration script.
</h1>
<hr>
<p>
This chapter describes writing a Defoma-configuration script for a package
named `example1' which accepts truetype and type1 category fonts. The
application reads a font-configuration file which just lists available truetype
and type1 fonts. The script generates <samp>font.conf</samp> file under
<samp>/var/lib/defoma/example1.d</samp>, which is supposed to be symlinked or
included from the font-configuration file the application actually reads.
</p>
<p>
First of all, let's write a header of the script. The script accepts truetype
and type1 categories, and the name of the package is `example1', so the header
goes like this:
</p>
<pre>
@ACCEPT_CATEGORIES = qw(type1 truetype);
package example1;
</pre>
<p>
Before registration and unregistration of fonts is performed, init command is
certainly passed. And before quitting, term command is certainly passed. Let
the script read the font-configuration file on init command and write it on
term command.
</p>
<pre>
package example1;
my @file = ();
my $readflag = 0;
my $writeflag = 0;
sub init {
return 0 if ($readflag);
$readflag = 1;
open(F, '/var/lib/defoma/example1.d/font.conf') || return 0;
while (<F>) {
chomp($_);
push(@file, $_);
}
close F;
return 0;
}
sub term {
return 0 if ($writeflag);
$writeflag = 1;
open(F, '>/var/lib/defoma/example1.d/font.conf') || return 0;
foreach my $i (@file) {
print F $i, "\n" if ($i ne '');
}
close F;
return 0;
}
</pre>
<p>
Let the script add the font to @file on register and erase the font from @file
on unregister command.
</p>
<pre>
sub register {
my $font = shift;
push(@file, $font);
return 0;
}
sub unregister {
my $font = shift;
my $i;
for ($i = 0; $i < @file; $i++) {
if ($file[$i] eq $font) {
$file[$i] = '';
return 0;
}
}
return 0;
}
</pre>
<p>
The functions above are not directly called. <samp>type1()</samp> and
<samp>truetype()</samp> must call them according to the command.
</p>
<pre>
sub type1 {
my $com = shift;
if ($com eq 'init') {
return init();
} elsif ($com eq 'term') {
return term();
} elsif ($com eq 'register') {
return register(@_);
} elsif ($com eq 'unregister') {
return unregister(@_);
}
return 0;
}
sub truetype {
my $com = shift;
if ($com eq 'init') {
return init();
} elsif ($com eq 'term') {
return term();
} elsif ($com eq 'register') {
return register(@_);
} elsif ($com eq 'unregister') {
return unregister(@_);
}
return 0;
}
1;
</pre>
<hr>
<p>
[ <a href="ch1.html">previous</a> ]
[ <a href="index.html#contents">Contents</a> ]
[ <a href="ch1.html">1</a> ]
[ 2 ]
[ <a href="ch3.html">3</a> ]
[ <a href="ch4.html">4</a> ]
[ <a href="ch5.html">5</a> ]
[ <a href="ch6.html">6</a> ]
[ <a href="ch7.html">7</a> ]
[ <a href="ch3.html">next</a> ]
</p>
<hr>
<p>
A Tutorial on Writing Defoma Configuration Script
</p>
<address>
Yasuhiro Take<br>
<br>
</address>
<hr>
</body>
</html>
|