File: translate.php

package info (click to toggle)
manpages-tr 1.0.2+cvs20040401-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 1,268 kB
  • ctags: 24
  • sloc: xml: 13,540; php: 74; makefile: 46; sh: 13
file content (71 lines) | stat: -rwxr-xr-x 2,065 bytes parent folder | download
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
#!/usr/bin/php -q
<?php
/*
 Copyright ©  2002  Nilgün Belma Bugüner <nilgun@superonline.com>
 This program 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.

 This program 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 this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
*/

if ($argc == "1"):
  echo "Usage:   translate.php infile > outfile\n\n";
  exit();
endif;
$infilename = implode("", explode("\'",$argv[1]));
if ($infilename != "-"):
  $farray = file($infilename);
else:
  $farray = file("php://stdin");
endif;

$temp=file("man-chars");

$cnt = count($temp);
for ($i = 0; $i < $cnt; $i++):
  $linearray = explode(" ",implode("",explode("\n", $temp[$i])));
  $chararray[$linearray[1]] = $linearray[0];
endfor;

$cnt = count($farray);
for ($i = 0; $i < $cnt; $i++):
  $temp = $farray[$i];
  $templen = strlen($temp);
  $inlinestr = "";
  $k = 0;
  
  while ($k < $templen):
    $chr = substr($temp, $k, 1);
    $twochr = substr($temp, $k, 2);
    $t3chr = substr($temp, $k, 3);
    $hexchr = substr($temp, $k, 7);
    if(!empty($chararray[$chr])):
      $inlinestr .= "\\" . $chararray[$chr];
    elseif(!empty($chararray[$twochr])):
      $inlinestr .= "\\" . $chararray[$twochr];
      $k++;
    elseif(!empty($chararray[$t3chr])):
      $inlinestr .= "\\" . $chararray[$t3chr];
      $k +=2;
    elseif(!empty($chararray[$hexchr])):
      $inlinestr .= "\\" . $chararray[$hexchr];
      $k +=6;
    elseif ($chr == "�"):
      $inlinestr .= "";
    else:
      $inlinestr .= $chr;
    endif;
    $k++;
  endwhile;
  echo $inlinestr;
endfor;
?>