|
| 1 | +<?php |
| 2 | +/* |
| 3 | ++----------------------------------------------------------------------+ |
| 4 | +| Copyright (c) 1997-2023 The PHP Group | |
| 5 | ++----------------------------------------------------------------------+ |
| 6 | +| This source file is subject to version 3.01 of the PHP license, | |
| 7 | +| that is bundled with this package in the file LICENSE, and is | |
| 8 | +| available through the world-wide-web at the following url: | |
| 9 | +| https://www.php.net/license/3_01.txt. | |
| 10 | +| If you did not receive a copy of the PHP license and are unable to | |
| 11 | +| obtain it through the world-wide-web, please send a note to | |
| 12 | +| [email protected], so we can mail you a copy immediately. | |
| 13 | ++----------------------------------------------------------------------+ |
| 14 | +| Authors: André L F S Bacci <ae php.net> | |
| 15 | ++----------------------------------------------------------------------+ |
| 16 | +| Description: Split an .ent file into individual files. | |
| 17 | ++----------------------------------------------------------------------+ |
| 18 | +
|
| 19 | +# With or withour tracking |
| 20 | +
|
| 21 | +For spliting files from doc-base and doc-en, no revtag or hash tracking |
| 22 | +is necessary. But for translations, further processing is necessary to |
| 23 | +fill revtags with... some data. |
| 24 | +
|
| 25 | +This is a translation leve decision. To have hash and maintainer blank |
| 26 | +filled, to be manually filled with text revision, or to using the |
| 27 | +deduce algorithm to fill hash and maintainers. |
| 28 | +
|
| 29 | +*/ |
| 30 | + |
| 31 | +if ( count( $argv ) < 4 ) |
| 32 | + die(" Syntax: php $argv[0] infile outdir ext [maintainer]\n" ); |
| 33 | + |
| 34 | +$infile = $argv[1]; |
| 35 | +$outdir = $argv[2]; |
| 36 | +$ext = $argv[3]; |
| 37 | +$maintainer = $argv[4] ?? ""; |
| 38 | + |
| 39 | +$content = file_get_contents( $infile ); |
| 40 | +$entities = []; |
| 41 | + |
| 42 | +// Parse |
| 43 | + |
| 44 | +$pos1 = 0; |
| 45 | +while ( true ) |
| 46 | +{ |
| 47 | + $pos1 = strpos( $content , "<!ENTITY", $pos1 ); |
| 48 | + if ( $pos1 === false ) break; |
| 49 | + |
| 50 | + $posS = strpos( $content , "'" , $pos1 ); |
| 51 | + $posD = strpos( $content , '"' , $pos1 ); |
| 52 | + |
| 53 | + if ( $posS < $posD ) |
| 54 | + $q = "'"; |
| 55 | + else |
| 56 | + $q = '"'; |
| 57 | + |
| 58 | + $pos1 += 8; |
| 59 | + $pos2 = min( $posS , $posD ) + 1; |
| 60 | + $pos3 = strpos( $content , $q , $pos2 ); |
| 61 | + |
| 62 | + $name = substr( $content , $pos1 , $pos2 - $pos1 - 1 ); |
| 63 | + $text = substr( $content , $pos2 , $pos3 - $pos2 ); |
| 64 | + |
| 65 | + $name = trim( $name ); |
| 66 | + |
| 67 | + $entities[$name] = $text; |
| 68 | +} |
| 69 | + |
| 70 | +// Check |
| 71 | + |
| 72 | +foreach( $entities as $name => $text ) |
| 73 | +{ |
| 74 | + $file = "$outdir/$name.$ext"; |
| 75 | + if ( file_exists( $file ) ) |
| 76 | + exit( "Name colision: $file\n" ); |
| 77 | +} |
| 78 | + |
| 79 | +// Write |
| 80 | + |
| 81 | +foreach( $entities as $name => $text ) |
| 82 | +{ |
| 83 | + $file = "$outdir/$name.$ext"; |
| 84 | + file_put_contents( $file , $text ); |
| 85 | + print "Generated $file\n"; |
| 86 | +} |
0 commit comments