parser.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. $version = "2.1.5";
  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 'merge':
  53. $options[$key] = true;
  54. break;
  55. case 'show':
  56. $options[$key] = true;
  57. break;
  58. case 'reference':
  59. $options[$key] = true;
  60. break;
  61. case 'iphone':
  62. $options[$key] = true;
  63. break;
  64. case 'cocoa':
  65. $options[$key] = true;
  66. break;
  67. case 'webkit':
  68. $options[$key] = true;
  69. break;
  70. case 'sdk':
  71. $options[$key] = trim($value, "\"");
  72. break;
  73. case 'ignore':
  74. $ignore_headers = explode(",", trim($value, "\""));
  75. break;
  76. case 'only':
  77. $only_files = explode(",", trim($value, "\""));
  78. break;
  79. case 'frameworks':
  80. $options[$key] = explode(",", trim($value, "\""));
  81. break;
  82. default:
  83. //print("unknown switch $key\n");
  84. break;
  85. }
  86. }
  87. }
  88. // Print the script usage if the command line is empty
  89. if (count($GLOBALS["argv"]) == 1) {
  90. print("Cocoa Framework Parser ($version) usage:\n");
  91. print("php parser.php [options]\n\n");
  92. print("Options:\n\n");
  93. print(" -all Print all headers (.h) from AppKit/Foundation frameworks.\n");
  94. print(" -header=\"foundation/NSObject.h\" Prints a single header from system frameworks (if specified) or direct path.\n");
  95. print(" -root Sets the root path of the output directory.\n");
  96. print(" -framework_path Sets the root path of the frameworks directory (defaults to /System/Library/Frameworks).\n");
  97. print(" -show Prints output to screen instead of file (mutually exclusive to -noprint).\n");
  98. print(" -comments Parses comments.\n");
  99. print(" -merge Headers are merged by difference (using diff/patch) instead of overwritten.\n");
  100. print(" -ignore=\"NSObject.h,NSArray.h\" Ignores the list of headers during parsing (-all only, no spaces).\n");
  101. print(" -only=\"NSObject.h,NSArray.h\" Only print these files (-all only, no spaces).\n");
  102. print(" -noprint Parses but does not print.\n");
  103. print(" -encodings Prints Pascal type encoding glue for GenerateTypeEncodings.p (-all only).\n");
  104. print(" -iphone One-time parse for iPhone headers.\n");
  105. print(" -cocoa One-time parse for Cocoa (AppKit/Foundation) headers.\n");
  106. print(" -frameworks=\"appkit,foundation\" List of supported frameworks to parse.\n");
  107. print("\n\n");
  108. }
  109. // get the command line options
  110. if (count($GLOBALS["argv"]) > 1) {
  111. HandleCommandLineOptions($GLOBALS["argv"]);
  112. //print_r($options);
  113. }
  114. // Make the output directory
  115. if ($options["out"]) {
  116. @mkdir($root_path, 0777);
  117. @mkdir($root_path."/foundation", 0777);
  118. @mkdir($root_path."/appkit", 0777);
  119. @mkdir($root_path."/uikit", 0777);
  120. }
  121. // setup -iphone options
  122. if ($options["iphone"]) {
  123. $options["all"] = true;
  124. if (!$options["sdk"]) $options["sdk"] = "4.2";
  125. //$options["framework_path"] = "/Developer/Platforms/iPhoneOS.Platform/Developer/SDKs/iPhoneOS$sdk_version.sdk/System/Library/Frameworks";
  126. $options["framework_path"] = "/Developer/Platforms/iPhoneSimulator.Platform/Developer/SDKs/iPhoneSimulator".$options["sdk"].".sdk/System/Library/Frameworks";
  127. $options["frameworks"] = array("foundation","quartzcore","opengles","uikit");
  128. }
  129. // setup -cocoa options
  130. if ($options["cocoa"]) {
  131. $options["all"] = true;
  132. $options["frameworks"] = array("appkit","foundation","quartzcore");
  133. $ignore_headers = array();
  134. }
  135. if ($options["webkit"]) {
  136. $options["all"] = true;
  137. $options["frameworks"] = array("foundation","webkit");
  138. }
  139. // create the parser instance
  140. $parser = new ObjectivePParser($root_path, "", $options["frameworks"], $options["framework_path"], $options["show"]);
  141. // Set additional options
  142. // ??? These should be accessors
  143. $parser->parse_comments = $options["comments"];
  144. $parser->merge_headers = $options["merge"];
  145. // Process single headers
  146. if ($options["header"] && !$options["all"]) {
  147. $path = $options["framework_path"]."/".$options["header"]["framework"].".framework/Headers/".$options["header"]["name"];
  148. print("* Processing $path...\n");
  149. $parser->ProcessFile($path, !$options["noprint"]);
  150. }
  151. // Process all headers
  152. if ($options["all"]) {
  153. $parser->ParseAllFrameworks($ignore_headers, null);
  154. if (!$options["noprint"]) $parser->PrintAllHeaders("", $duplicate_headers, $only_files, $options["reference"]);
  155. }
  156. ?>