Allow to generate PHP sigfiles in different language
authorTomas Mysik <tmysik@netbeans.org>
Mon, 05 Jun 2017 07:26:47 +0200
changeset 6388d493d11c1b46
parent 6387 046e7091c52c
child 6389 8b57d477a2db
Allow to generate PHP sigfiles in different language
php/sigfiles/generate.php
     1.1 --- a/php/sigfiles/generate.php	Wed May 24 15:00:12 2017 +0200
     1.2 +++ b/php/sigfiles/generate.php	Mon Jun 05 07:26:47 2017 +0200
     1.3 @@ -21,6 +21,7 @@
     1.4  $phpdocDir = null;
     1.5  
     1.6  $phpDir = "php";
     1.7 +$lang = "en";
     1.8  
     1.9  // Parse arguments:
    1.10  $argv = $_SERVER["argv"];
    1.11 @@ -31,10 +32,32 @@
    1.12  			$splitFiles = false;
    1.13  			break;
    1.14  
    1.15 +		case "-split":
    1.16 +			$splitFiles = true;
    1.17 +			break;
    1.18 +
    1.19  		case "-help":
    1.20  			show_help();
    1.21  			break;
    1.22  
    1.23 +		case "-lang":
    1.24 +			++$i;
    1.25 +			$lang = $argv[$i];
    1.26 +                        if ($lang[0] === '-') {
    1.27 +				show_message("Invalid arg for -lang: " . $argv[$i]);
    1.28 +				show_help();
    1.29 +                        }
    1.30 +			break;
    1.31 +
    1.32 +		case "-output":
    1.33 +			++$i;
    1.34 +			$phpDir = $argv[$i];
    1.35 +                        if ($phpDir[0] === '-') {
    1.36 +				show_message("Invalid arg for -output: " . $argv[$i]);
    1.37 +				show_help();
    1.38 +                        }
    1.39 +			break;
    1.40 +
    1.41  		default:
    1.42  			$phpdocDir = $argv[$i];
    1.43  	}
    1.44 @@ -69,11 +92,11 @@
    1.45  
    1.46  /***************** REMOVED FUNCTIONS (END) *************************/
    1.47  
    1.48 -$entities = parse_entities($phpdocDir);
    1.49 +$entities = parse_entities($phpdocDir, $lang);
    1.50  $extensions = get_loaded_extensions();
    1.51 -$functionsDoc = parse_phpdoc_functions ($phpdocDir, $extensions);
    1.52 -$fieldsDoc = parse_phpdoc_fields ($phpdocDir, $extensions);
    1.53 -$classesDoc = parse_phpdoc_classes ($phpdocDir, $extensions);
    1.54 +$functionsDoc = parse_phpdoc_functions ($phpdocDir, $extensions, $lang);
    1.55 +$fieldsDoc = parse_phpdoc_fields ($phpdocDir, $extensions, $lang);
    1.56 +$classesDoc = parse_phpdoc_classes ($phpdocDir, $extensions, $lang);
    1.57  $constantsDoc = parse_phpdoc_constants ($phpdocDir);
    1.58  $removedFunctions = array(
    1.59      'ob_iconv_handler',
    1.60 @@ -296,15 +319,15 @@
    1.61   * @param phpdocDir string PHP.net documentation directory
    1.62   * @return array Function information gathered from the PHP.net documentation by parsing XML files
    1.63   */
    1.64 -function parse_phpdoc_functions ($phpdocDir, $extensions) {
    1.65 +function parse_phpdoc_functions ($phpdocDir, $extensions, $lang) {
    1.66  	$xml_files = array_merge (
    1.67 -		glob ("{$phpdocDir}/en" . BRANCH_DIR . "/reference/*/functions/*.xml"),
    1.68 -		glob ("{$phpdocDir}/en" . BRANCH_DIR . "/language/predefined/*/*.xml"),
    1.69 -		glob ("{$phpdocDir}/en" . BRANCH_DIR . "/reference/*/functions/*/*.xml")
    1.70 +		glob ("{$phpdocDir}/{$lang}" . BRANCH_DIR . "/reference/*/functions/*.xml"),
    1.71 +		glob ("{$phpdocDir}/{$lang}" . BRANCH_DIR . "/language/predefined/*/*.xml"),
    1.72 +		glob ("{$phpdocDir}/{$lang}" . BRANCH_DIR . "/reference/*/functions/*/*.xml")
    1.73  	);
    1.74  	foreach ($extensions as $extName) {
    1.75  		$extName = strtolower($extName);
    1.76 -		$globPattern = "{$phpdocDir}/en" . BRANCH_DIR . "/reference/{$extName}/*/*.xml";
    1.77 +		$globPattern = "{$phpdocDir}/{$lang}" . BRANCH_DIR . "/reference/{$extName}/*/*.xml";
    1.78  		$xml_files = array_merge (
    1.79  			$xml_files,
    1.80  			glob ($globPattern)
    1.81 @@ -434,15 +457,15 @@
    1.82   * @param phpdocDir string PHP.net documentation directory
    1.83   * @return array Function information gathered from the PHP.net documentation by parsing XML files
    1.84   */
    1.85 -function parse_phpdoc_fields ($phpdocDir, $extensions) {
    1.86 +function parse_phpdoc_fields ($phpdocDir, $extensions, $lang) {
    1.87  	$xml_files = array();
    1.88  	foreach ($extensions as $extName) {
    1.89  		$extName = strtolower($extName);
    1.90  
    1.91  		$xml_files = array_merge (
    1.92  			$xml_files,
    1.93 -			glob ("{$phpdocDir}/en" . BRANCH_DIR . "/reference/{$extName}/*.xml"),
    1.94 -                        glob ("{$phpdocDir}/en" . BRANCH_DIR . "/reference/{$extName}/*/*.xml")
    1.95 +			glob ("{$phpdocDir}/{$lang}" . BRANCH_DIR . "/reference/{$extName}/*.xml"),
    1.96 +                        glob ("{$phpdocDir}/{$lang}" . BRANCH_DIR . "/reference/{$extName}/*/*.xml")
    1.97  		);
    1.98  	}
    1.99          foreach ($xml_files as $xml_file) {
   1.100 @@ -483,16 +506,16 @@
   1.101   * @param phpdocDir string PHP.net documentation directory
   1.102   * @return array Class information gathered from the PHP.net documentation by parsing XML files
   1.103   */
   1.104 -function parse_phpdoc_classes ($phpdocDir, $extensions) {
   1.105 +function parse_phpdoc_classes ($phpdocDir, $extensions, $lang) {
   1.106  	$xml_files = array_merge (
   1.107 -		glob ("{$phpdocDir}/en" . BRANCH_DIR . "/reference/*/reference.xml"),
   1.108 -		glob ("{$phpdocDir}/en" . BRANCH_DIR . "/reference/*/classes.xml"),
   1.109 -		glob ("{$phpdocDir}/en" . BRANCH_DIR . "/language/*/*.xml"),
   1.110 -		glob ("{$phpdocDir}/en" . BRANCH_DIR . "/language/*.xml")
   1.111 +		glob ("{$phpdocDir}/{$lang}" . BRANCH_DIR . "/reference/*/reference.xml"),
   1.112 +		glob ("{$phpdocDir}/{$lang}" . BRANCH_DIR . "/reference/*/classes.xml"),
   1.113 +		glob ("{$phpdocDir}/{$lang}" . BRANCH_DIR . "/language/*/*.xml"),
   1.114 +		glob ("{$phpdocDir}/{$lang}" . BRANCH_DIR . "/language/*.xml")
   1.115  	);
   1.116  	foreach ($extensions as $extName) {
   1.117  		$extName = strtolower($extName);
   1.118 -		$globPattern = "{$phpdocDir}/en" . BRANCH_DIR . "/reference/{$extName}/*.xml";
   1.119 +		$globPattern = "{$phpdocDir}/{$lang}" . BRANCH_DIR . "/reference/{$extName}/*.xml";
   1.120  		$xml_files = array_merge (
   1.121  			$xml_files,
   1.122  			glob ($globPattern)
   1.123 @@ -1017,7 +1040,8 @@
   1.124   * @return URL
   1.125   */
   1.126  function make_url ($id) {
   1.127 -	return "http://php.net/manual/en/{$id}.php";
   1.128 +	global $lang;
   1.129 +	return "http://php.net/manual/{$lang}/{$id}.php";
   1.130  }
   1.131  
   1.132  /**
   1.133 @@ -1358,10 +1382,10 @@
   1.134      return $str;
   1.135  }
   1.136  
   1.137 -function parse_entities($phpdocDir) {
   1.138 +function parse_entities($phpdocDir, $lang) {
   1.139      $entities = array();
   1.140 -    parse_entities_from_file($entities, $phpdocDir, '/en/language-defs.ent');
   1.141 -    parse_entities_from_file($entities, $phpdocDir, '/en/language-snippets.ent');
   1.142 +    parse_entities_from_file($entities, $phpdocDir, "/{$lang}/language-defs.ent");
   1.143 +    parse_entities_from_file($entities, $phpdocDir, "/{$lang}/language-snippets.ent");
   1.144      parse_entities_from_file($entities, $phpdocDir, '/doc-base/docbook/docbook-xml/ent/isonum.ent');
   1.145      parse_entities_from_file($entities, $phpdocDir, '/doc-base/entities/global.ent');
   1.146      return $entities;
   1.147 @@ -1612,11 +1636,18 @@
   1.148  
   1.149  Where options are:
   1.150  
   1.151 --help	Show this help.
   1.152 --split	Split output to different files (one file per PHP extension).
   1.153 +-help		Show this help.
   1.154 +-nosplit	Don't split output to different files.
   1.155 +-split		Split output to different files (one file per PHP extension).
   1.156 +-lang		Specify the language("en" by default). e.g. -lang en, -lang ja
   1.157 +-output 	Output directory name("php" by default).
   1.158  
   1.159  EOF
   1.160  	);
   1.161  }
   1.162  
   1.163 +function show_message($message) {
   1.164 +	echo $message . PHP_EOL;
   1.165 +}
   1.166 +
   1.167  ?>