parser.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. $version = "2.1.6";
  3. require("source/objp.php");
  4. /**
  5. * Cocoa framework parser for Objective-Pascal
  6. *
  7. * @author Ryan Joseph
  8. * @author Jonas Maebe
  9. **/
  10. // These files have duplicates in AppKit and Foundation so we ignore the foundation versions and everything is merged into AppKit
  11. # $duplicate_headers = array("foundation/NSAttributedString.inc", "foundation/NSAffineTransform.inc");
  12. $duplicate_headers = array();
  13. // Print only these files
  14. $only_files = null;
  15. $options = array();
  16. function HandleCommandLineOptions ($argv) {
  17. global $options;
  18. global $root_path;
  19. global $ignore_headers;
  20. global $only_files;
  21. // Define defaults
  22. $options["framework_path"] = "/System/Library/Frameworks";
  23. foreach ($argv as $option) {
  24. $pair = explode("=", $option);
  25. $key = trim($pair[0], "-");
  26. $value = $pair[1];
  27. switch ($key) {
  28. case 'root':
  29. $root_path = trim($value, "\"");
  30. break;
  31. case 'header':
  32. $where = explode("/", trim($value, "\""));
  33. $options[$key]["framework"] = ucfirst($where[0]);
  34. $options[$key]["name"] = $where[1];
  35. $options["all"] = false; // headers override -all
  36. break;
  37. case 'framework_path':
  38. $options["framework_path"] = trim($value, "\"");
  39. break;
  40. case 'all':
  41. $options[$key] = true;
  42. break;
  43. case 'encodings':
  44. $options[$key] = true;
  45. break;
  46. case 'noprint':
  47. $options[$key] = true;
  48. break;
  49. case 'comments':
  50. $options[$key] = true;
  51. break;
  52. case 'docsets':
  53. $options[$key] = true;
  54. break;
  55. case 'merge':
  56. $options[$key] = true;
  57. break;
  58. case 'show':
  59. $options[$key] = true;
  60. break;
  61. case 'reference':
  62. $options[$key] = true;
  63. break;
  64. case 'iphone':
  65. $options[$key] = true;
  66. break;
  67. case 'cocoa':
  68. $options[$key] = true;
  69. break;
  70. case 'webkit':
  71. $options[$key] = true;
  72. break;
  73. case 'sdk':
  74. $options[$key] = trim($value, "\"");
  75. break;
  76. case 'ignore':
  77. $ignore_headers = explode(",", trim($value, "\""));
  78. break;
  79. case 'only':
  80. $only_files = explode(",", trim($value, "\""));
  81. break;
  82. case 'frameworks':
  83. $options[$key] = explode(",", trim($value, "\""));
  84. break;
  85. default:
  86. //print("unknown switch $key\n");
  87. break;
  88. }
  89. }
  90. }
  91. // Print the script usage if the command line is empty
  92. if (count($GLOBALS["argv"]) == 1) {
  93. print("Cocoa Framework Parser ($version) usage:\n");
  94. print("php parser.php [options]\n\n");
  95. print("Options:\n\n");
  96. print(" -all Print all headers (.h) from AppKit/Foundation frameworks.\n");
  97. print(" -header=\"foundation/NSObject.h\" Prints a single header from system frameworks (if specified) or direct path.\n");
  98. print(" -root Sets the root path of the output directory.\n");
  99. print(" -framework_path Sets the root path of the frameworks directory (defaults to /System/Library/Frameworks).\n");
  100. print(" -show Prints output to screen instead of file (mutually exclusive to -noprint).\n");
  101. print(" -comments Parses comments.\n");
  102. print(" -merge Headers are merged by difference (using diff/patch) instead of overwritten.\n");
  103. print(" -ignore=\"NSObject.h,NSArray.h\" Ignores the list of headers during parsing (-all only, no spaces).\n");
  104. print(" -only=\"NSObject.h,NSArray.h\" Only print these files (-all only, no spaces).\n");
  105. print(" -noprint Parses but does not print.\n");
  106. print(" -encodings Prints Pascal type encoding glue for GenerateTypeEncodings.p (-all only).\n");
  107. print(" -iphone One-time parse for iPhone headers.\n");
  108. print(" -cocoa One-time parse for Cocoa (AppKit/Foundation) headers.\n");
  109. print(" -frameworks=\"appkit,foundation\" List of supported frameworks to parse.\n");
  110. print("\n\n");
  111. }
  112. // get the command line options
  113. if (count($GLOBALS["argv"]) > 1) {
  114. HandleCommandLineOptions($GLOBALS["argv"]);
  115. //print_r($options);
  116. }
  117. // Make the output directory
  118. if ($options["out"]) {
  119. @mkdir($root_path, 0777);
  120. @mkdir($root_path."/foundation", 0777);
  121. @mkdir($root_path."/appkit", 0777);
  122. @mkdir($root_path."/uikit", 0777);
  123. }
  124. // setup -iphone options
  125. if ($options["iphone"]) {
  126. $options["all"] = true;
  127. if (!$options["sdk"]) $options["sdk"] = "4.2";
  128. //$options["framework_path"] = "/Developer/Platforms/iPhoneOS.Platform/Developer/SDKs/iPhoneOS$sdk_version.sdk/System/Library/Frameworks";
  129. $options["framework_path"] = "/Developer/Platforms/iPhoneSimulator.Platform/Developer/SDKs/iPhoneSimulator".$options["sdk"].".sdk/System/Library/Frameworks";
  130. $options["frameworks"] = array("foundation","quartzcore","opengles","uikit");
  131. }
  132. // setup -cocoa options
  133. if ($options["cocoa"]) {
  134. $options["all"] = true;
  135. $options["frameworks"] = array("appkit","foundation","quartzcore");
  136. $ignore_headers = array();
  137. }
  138. if ($options["webkit"]) {
  139. $options["all"] = true;
  140. $options["frameworks"] = array("foundation","webkit");
  141. }
  142. // create the parser instance
  143. $parser = new ObjectivePParser($root_path, "", $options["frameworks"], $options["framework_path"], $options["show"]);
  144. // Set additional options
  145. // ??? These should be accessors
  146. $parser->parse_comments = $options["comments"];
  147. $parser->merge_headers = $options["merge"];
  148. $parser->parse_docsets = $options["docsets"];
  149. // Process single headers
  150. if ($options["header"] && !$options["all"]) {
  151. $path = $options["framework_path"]."/".$options["header"]["framework"].".framework/Headers/".$options["header"]["name"];
  152. print("* Processing $path...\n");
  153. $parser->ProcessFile($path, !$options["noprint"]);
  154. }
  155. // Process all headers
  156. if ($options["all"]) {
  157. $parser->ParseAllFrameworks($ignore_headers, null);
  158. if (!$options["noprint"]) $parser->PrintAllHeaders("", $duplicate_headers, $only_files, $options["reference"]);
  159. }
  160. ?>