This file is indexed.

/usr/share/php/Text/Figlet.php is in php-text-figlet 1.0.2-2.

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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
<?php
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
/**
* ASCII art text creation
*
* Project home page (Russian): http://bolknote.ru/files/figlet/
*
* PHP Version 4
*
* @category Text
* @package  Text_Figlet
* @author   Evgeny Stepanischev <imbolk@gmail.com>
* @author   Christian Weiske <cweiske@php.net>
* @license  http://www.php.net/license PHP License
* @version  CVS: $Id$
* @link     http://pear.php.net/package/Text_Figlet
*/
require_once 'PEAR.php';

/**
* ASCII art text creation
*
* Project home page (Russian): http://bolknote.ru/files/figlet/
*
* PHP Version 4
*
* @category Text
* @package  Text_Figlet
* @author   Evgeny Stepanischev <imbolk@gmail.com>
* @author   Christian Weiske <cweiske@php.net>
* @license  http://www.php.net/license PHP License
* @link     http://pear.php.net/package/Text_Figlet
*/
class Text_Figlet
{
    /**
     * Height of a letter
     *
     * @var integer
     *
     * @access protected
     */
    var $height;

    /**
     * Letter baseline
     *
     * @var integer
     *
     * @access protected
     */
    var $oldlayout;

    /**
     * Flag - RTL (right to left) or LTR (left to right) text direction
     *
     * @var integer
     *
     * @access protected
     */
    var $rtol;

    /**
     * Information about special 'hardblank' character
     *
     * @var integer
     *
     * @access protected
     */
    var $hardblank;

    /**
     * Is used for keeping font
     *
     * @var array
     *
     * @access protected
     */
    var $font;

    /**
     * Flag is true if smushing occured in letters printing cycle
     *
     * @var integer
     *
     * @access protected
     */
    var $smush_flag;

    /**
     * Comment lines buffer
     *
     * @var string
     *
     * @access public
     */

    var $font_comment;


    /**
     * Load user font. Must be invoked first.
     * Automatically tries the Text_Figlet font data directory
     *  as long as no path separator is in the filename.
     *
     * @param string $filename   font file name
     * @param bool   $loadgerman (optional) load German character set or not
     *
     * @access public
     * @return mixed PEAR_Error or true for success
     */
    function loadFont($filename, $loadgerman = true)
    {
        $this->font = array();
        if (!file_exists($filename)) {
            //if it does not exist, try the Text_Figlet data directory
            include_once 'PEAR/Config.php';

            $config  = PEAR_Config::singleton();
            $fontdir = $config->get('data_dir') . '/Text_Figlet/fonts/';

            //only for filenames without path separators
            if (strpos($filename, '/') === false
                && file_exists($fontdir . $filename)
            ) {
                $filename = $fontdir . $filename;
            } else {
                return PEAR::raiseError('Figlet font file "' 
                                        . $filename 
                                        . '" cannot be found', 1);
            }
        }

        $this->font_comment = '';

        // If Gzip compressed font
        if (substr($filename, -3, 3) == '.gz') {
            $filename   = 'compress.zlib://' . $filename;
            $compressed = true;

            if (!function_exists('gzcompress')) {
                return PEAR::raiseError('Cannot load gzip compressed fonts since'
                                        . ' gzcompress() is not available.',
                                        3);
            }
        } else {
            $compressed = false;
        }

        if (!($fp = fopen($filename, 'rb'))) {
            return PEAR::raiseError('Cannot open figlet font file ' . $filename, 2);
        }

        if (!$compressed) {
            /* ZIPed font */
            if (fread($fp, 2) == 'PK') {
                if (!function_exists('zip_open')) {
                    return PEAR::raiseError('Cannot load ZIP compressed fonts since'
                                            . ' ZIP PHP extension is not available.',
                                            5);                        
                }

                fclose($fp);

                if (!($fp = zip_open($filename))) {
                    return PEAR::raiseError('Cannot open figlet font file ' . $filename, 2);
                }

                $name = zip_entry_name(zip_read($fp));
                zip_close($fp);

                if (!($fp = fopen('zip://' . realpath($filename) . '#' . $name, 'rb'))) {
                    return PEAR::raiseError('Cannot open figlet font file ' . $filename, 2);
                }

                $compressed = true;
            } else {
                flock($fp, LOCK_SH);
                rewind($fp);
            }
        }

        //            flf2a$ 6 5 20 15 3 0 143 229
        //              |  | | | |  |  | |  |   |
        //             /  /  | | |  |  | |  |   \
        //    Signature  /  /  | |  |  | |   \   Codetag_Count
        //      Hardblank  /  /  |  |  |  \   Full_Layout
        //           Height  /   |  |   \  Print_Direction
        //           Baseline   /    \   Comment_Lines
        //            Max_Length      Old_Layout


        $header = explode(' ', fgets($fp, 2048));

        if (substr($header[0], 0, 5) <> 'flf2a') {
            return PEAR::raiseError('Unknown FIGlet font format.', 4);
        }

        @list ($this->hardblank, $this->height,,,
        $this->oldlayout, $cmt_count, $this->rtol) = $header;

        $this->hardblank = substr($this->hardblank, -1, 1);

        for ($i = 0; $i < $cmt_count; $i++) {
            $this->font_comment .= fgets($fp, 2048);
        }

        // ASCII charcters
        for ($i = 32; $i < 127; $i++) {
            $this->font[$i] = $this->_char($fp);
        }

        foreach (array(196, 214, 220, 228, 246, 252, 223) as $i) {
            if ($loadgerman) {
                $letter = $this->_char($fp);

                // Invalid character but main font is loaded and I can use it
                if ($letter === false) {
                    fclose($fp);
                    return true;
                }

                // Load if it is not blank only
                if (trim(implode('', $letter)) <> '') {
                    $this->font[$i] = $letter;
                }
            } else {
                $this->_skip($fp);
            }
        }

        // Extented characters
        for ($n = 0; !feof($fp); $n++) {
            list ($i) = explode(' ', rtrim(fgets($fp, 1024)), 2);
            if ($i == '') {
                continue;
            }

            // If comment
            if (preg_match('/^\-0x/i', $i)) {
                $this->_skip($fp);
            } else {
                // If Unicode
                if (preg_match('/^0x/i', $i)) {
                    $i = hexdec(substr($i, 2));
                } else {
                    // If octal
                    if ($i{0} === '0' && $i !== '0' || substr($i, 0, 2) == '-0') {
                        $i = octdec($i);
                    }
                }

                $letter = $this->_char($fp);

                // Invalid character but main font is loaded and I can use it
                if ($letter === false) {
                    fclose($fp);
                    return true;
                }

                $this->font[$i] = $letter;
            }
        }

        fclose($fp);
        return true;
    }



    /**
    * Print string using font loaded by LoadFont method
    *
    * @param string $str    string for printing
    * @param bool   $inhtml (optional) output mode
    *                       - HTML (true) or plain text (false)
    *
    * @access public
    * @return string contains
    */
    function lineEcho($str, $inhtml = false)
    {
        $out = array();

        for ($i = 0; $i<strlen($str); $i++) {
            // Pseudo Unicode support
            if (substr($str, $i, 2) == '%u') {
                $lt = hexdec(substr($str, $i+2, 4));
                $i += 5;
            } else {
                $lt = ord($str{$i});
            }

            $hb = preg_quote($this->hardblank, '/');
            $sp = "$hb\\x00\\s";

            // If chosen character not found try to use default
            // If default character is not defined skip it

            if (!isset($this->font[$lt])) {
                if (isset($this->font[0])) {
                    $lt = 0;
                } else {
                    continue;
                }
            }

            for ($j = 0; $j < $this->height; $j++) {
                $line = $this->font[$lt][$j];

                // Replace hardblanks
                if (isset($out[$j])) {
                    if ($this->rtol) {
                        $out[$j] = $line . $out[$j];
                    } else {
                        $out[$j] .= $line;
                    }
                } else {
                    $out[$j] = $line;
                }
            }

            if ($this->oldlayout > -1 && $i) {
                // Calculate minimal distance between two last letters

                $mindiff = -1;

                for ($j = 0; $j < $this->height; $j++) {
                    if (preg_match("/\S(\s*\\x00\s*)\S/", $out[$j], $r)) {
                        if ($mindiff == -1) {
                            $mindiff = strlen($r[1]);
                        } else {
                            $mindiff = min($mindiff, strlen($r[1]));
                        }
                    }
                }

                // Remove spaces between two last letter
                // dec mindiff for exclude \x00 symbol

                if (--$mindiff > 0) {
                    for ($j = 0; $j < $this->height; $j++) {
                        if (preg_match("/\\x00(\s{0,{$mindiff}})/", $out[$j], $r)) {
                            $l       = strlen($r[1]);
                            $b       = $mindiff - $l;
                            $out[$j] = preg_replace("/\s{0,$b}\\x00\s{{$l}}/",
                                                    "\0",
                                                    $out[$j],
                                                    1);
                        }
                    }
                }
                // Smushing

                $this->smush_flag = 0;

                for ($j = 0; $j < $this->height; $j++) {
                    $out[$j] = preg_replace_callback("#([^$sp])\\x00([^$sp])#",
                                                     array(&$this, '_rep'),
                                                     $out[$j]);
                }

                // Remove one space if smushing
                // and remove all \x00 except tail whenever

                if ($this->smush_flag) {
                    $pat = array("/\s\\x00(?!$)|\\x00\s/", "/\\x00(?!$)/");
                    $rep = array('', '');
                } else {
                    $pat = "/\\x00(?!$)/";
                    $rep = '';
                }

                for ($j = 0; $j<$this->height; $j++) {
                    $out[$j] = preg_replace($pat, $rep, $out[$j]);
                }
            }
        }

        $trans = array("\0" => '', $this->hardblank => ' ');
        $str   = strtr(implode("\n", $out), $trans);

        if ($inhtml) {
            return '<nobr>'.
                   nl2br(str_replace(' ', '&nbsp;', htmlspecialchars($str))).
                   '</nobr>';
        }

        return $str;
    }



    /**
    * It is preg_replace callback function that makes horizontal letter smushing
    *
    * @param array $r preg_replace matches array
    *
    * @return string
    * @access private
    */
    function _rep($r)
    {
        if ($this->oldlayout & 1 && $r[1] == $r[2]) {
            $this->smush_flag = 1;
            return $r[1];
        }

        if ($this->oldlayout & 2) {
            $symb = '|/\\[]{}()<>';

            if ($r[1] == '_' && strpos($symb, $r[2]) !== false ||
                $r[2] == '_' && strpos($symb, $r[1]) !== false) {
                $this->smush_flag = 1;
                return $r[1];
            }
        }

        if ($this->oldlayout & 4) {
            $classes = '|/\\[]{}()<>';

            if (($left = strpos($classes, $r[1])) !== false) {
                if (($right = strpos($classes, $r[2])) !== false) {
                    $this->smush_flag = 1;
                    return $right > $left ? $r[2] : $r[1];
                }
            }
        }

        if ($this->oldlayout & 8) {
            $t = array('[' => ']', ']' => '[', '{' => '}', '}' => '{',
            '(' => ')', ')' => '(');

            if (isset($t[$r[2]]) && $r[1] == $t[$r[2]]) {
                $this->smush_flag = 1;
                return '|';
            }
        }

        if ($this->oldlayout & 16) {
            $t = array("/\\" => '|', "\\/" => 'Y', '><' => 'X');

            if (isset($t[$r[1].$r[2]])) {
                $this->smush_flag = 1;
                return $t[$r[1].$r[2]];
            }
        }

        if ($this->oldlayout & 32) {
            if ($r[1] == $r[2] && $r[1] == $this->hardblank) {
                $this->smush_flag = 1;
                return $this->hardblank;
            }
        }

        return $r[1]."\00".$r[2];
    }



    /**
    * Function loads one character in the internal array from file
    *
    * @param resource &$fp handle of font file
    *
    * @return mixed lines of the character or false if foef occured
    * @access private
    */
    function _char(&$fp)
    {
        $out = array();

        for ($i = 0; $i < $this->height; $i++) {
            if (feof($fp)) {
                return false;
            }

            $line = rtrim(fgets($fp, 2048), "\r\n");
            if (preg_match('/(.){1,2}$/', $line, $r)) {
                $line = str_replace($r[1], '', $line);
            }

            $line .= "\x00";

            $out[] = $line;
        }

        return $out;
    }



    /**
    * Function for skipping one character in a font file
    *
    * @param resource &$fp handle of font file
    *
    * @return boolean always return true
    * @access private
    */
    function _skip(&$fp)
    {
        for ($i = 0; $i<$this->height && !feof($fp); $i++) {
            fgets($fp, 2048);
        }

        return true;
    }
}
?>