Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
1.8KB

  1. #!/usr/bin/php
  2. <?php
  3. /**
  4. * @file util/createdoxygen.php
  5. * @brief Adds a doxygen header to functions
  6. */
  7. if (count($_SERVER["argv"]) < 2)
  8. die("usage: createdoxygen.php file\n");
  9. $file = $_SERVER["argv"][1];
  10. $data = file_get_contents($file);
  11. $lines = explode("\n", $data);
  12. $previous = "";
  13. foreach ($lines AS $line) {
  14. $line = rtrim(trim($line, "\r"));
  15. if (strstr(strtolower($line), "function")) {
  16. $detect = strtolower(trim($line));
  17. $detect = implode(" ", explode(" ", $detect));
  18. $found = false;
  19. if (substr($detect, 0, 9) == "function ")
  20. $found = true;
  21. if (substr($detect, 0, 17) == "private function ")
  22. $found = true;
  23. if (substr($detect, 0, 23) == "public static function ")
  24. $found = true;
  25. if (substr($detect, 0, 10) == "function (")
  26. $found = false;
  27. if ($found and (trim($previous) == "*/"))
  28. $found = false;
  29. if ($found and !strstr($detect, "{"))
  30. $found = false;
  31. if ($found) {
  32. echo add_documentation($line);
  33. }
  34. }
  35. echo $line."\n";
  36. $previous = $line;
  37. }
  38. /**
  39. * @brief Adds a doxygen header
  40. *
  41. * @param string $line The current line of the document
  42. *
  43. * @return string added doxygen header
  44. */
  45. function add_documentation($line) {
  46. $trimmed = ltrim($line);
  47. $length = strlen($line) - strlen($trimmed);
  48. $space = substr($line, 0, $length);
  49. $block = $space."/**\n".
  50. $space." * @brief \n".
  51. $space." *\n"; /**/
  52. $left = strpos($line, "(");
  53. $line = substr($line, $left + 1);
  54. $right = strpos($line, ")");
  55. $line = trim(substr($line, 0, $right));
  56. if ($line != "") {
  57. $parameters = explode(",", $line);
  58. foreach ($parameters AS $parameter) {
  59. $parameter = trim($parameter);
  60. $splitted = explode("=", $parameter);
  61. $block .= $space." * @param ".trim($splitted[0], "& ")."\n";
  62. }
  63. if (count($parameters) > 0)
  64. $block .= $space." *\n";
  65. }
  66. $block .= $space." * @return \n".
  67. $space." */\n";
  68. return $block;
  69. }