33cfa6f413627049dff644014af1a1d9f85425a7
18 public function __construct($path) {
19 $this->fd
= fopen($path, "rb");
23 * Read the title of the refentry
26 public function readTitle() {
27 if ($this->rewind(1)) {
28 return fgets($this->fd
);
33 * Read the description (first line) of the refentry
36 public function readDescription() {
38 && (false !== fgets($this->fd
))
39 && (false !== fgets($this->fd
))) {
40 return fgets($this->fd
);
45 * Read the full description (first section) of the refentry
48 public function readFullDescription() {
49 $desc = $this->readDescription();
50 while (false !== ($line = fgets($this->fd
))) {
51 if ($line{0} === "#") {
61 * Read the first subsection of a global refentry
64 public function readIntro() {
66 if ($this->rewind()) {
69 while (!feof($this->fd
)) {
70 if (false === ($line = fgets($this->fd
))) {
73 /* search first header and read until next header*/
74 if ($this->isHeading($line)) {
90 public function readSection($title) {
92 if ($this->rewind()) {
93 while (!feof($this->fd
)) {
94 if (false === ($line = fgets($this->fd
))) {
97 /* search for heading with $title and read until next heading */
98 if ($this->isHeading($line, $title)) {
100 if (false === $line = fgets($this->fd
)) {
103 if ($this->isHeading($line)) {
114 private function rewind($offset = 0) {
115 return 0 === fseek($this->fd
, $offset, SEEK_SET
);
118 private function isHeading(string $line, string $title = null) {
119 if ("## " !== substr($line, 0, 3)) {
123 return !strncmp(substr($line, 3), $title, strlen($title));