/[drupal]/contributions/modules/api/parser.inc
ViewVC logotype

Diff of /contributions/modules/api/parser.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.25 by drumm, Mon May 19 07:09:38 2008 UTC revision 1.26 by drumm, Mon May 19 07:20:48 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: parser.inc,v 1.24.2.15 2008/01/23 02:49:56 drumm Exp $  // $Id: parser.inc,v 1.25 2008/05/19 07:09:38 drumm Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 35  function api_parse_php_manual($location) Line 35  function api_parse_php_manual($location)
35   */   */
36  function api_parse_file($file_path, $branch_name, $file_name) {  function api_parse_file($file_path, $branch_name, $file_name) {
37    if (preg_match('!\.(php|module|inc|install|engine|theme)$!', $file_name)) {    if (preg_match('!\.(php|module|inc|install|engine|theme)$!', $file_name)) {
38      watchdog('api', t('Parsing %path...', array('%path' => $file_path)));      watchdog('api', 'Parsing %path.', array('%path' => $file_path));
39      api_parse_php_file($file_path, $branch_name, $file_name);      api_parse_php_file($file_path, $branch_name, $file_name);
40      return TRUE;      return TRUE;
41    }    }
42    if (preg_match('!\.(txt)$!', $file_name)) {    if (preg_match('!\.(txt)$!', $file_name)) {
43      watchdog('api', t('Parsing %path...', array('%path' => $file_path)));      watchdog('api', 'Parsing %path.', array('%path' => $file_path));
44      api_parse_text_file($file_path, $branch_name, $file_name);      api_parse_text_file($file_path, $branch_name, $file_name);
45      return TRUE;      return TRUE;
46    }    }
47    if (preg_match('!\.(htm|html)$!', $file_name)) {    if (preg_match('!\.(htm|html)$!', $file_name)) {
48      watchdog('api', t('Parsing %path...', array('%path' => $file_path)));      watchdog('api', 'Parsing %path.', array('%path' => $file_path));
49      api_parse_html_file($file_path, $branch_name, $file_name);      api_parse_html_file($file_path, $branch_name, $file_name);
50      return TRUE;      return TRUE;
51    }    }
# Line 198  function api_parse_php_file($file_path, Line 198  function api_parse_php_file($file_path,
198        'title' => '',        'title' => '',
199        'summary' => '',        'summary' => '',
200        'documentation' => '',        'documentation' => '',
201        'code' => '');        'code' => '',
202        );
203      $docblock['content'] = str_replace(array("\n *", "\n "), array("\n", "\n"), $docblock_match[1][0]);      $docblock['content'] = str_replace(array("\n *", "\n "), array("\n", "\n"), $docblock_match[1][0]);
204      $docblock['start'] = $docblock_match[0][1];      $docblock['start'] = $docblock_match[0][1];
205      $docblock['length'] = strlen($docblock_match[0][0]);      $docblock['length'] = strlen($docblock_match[0][0]);
206        $code_start = $docblock['start'] + $docblock['length'] + 1;
207        $docblock['start_line'] = substr_count(substr($source, 0, $code_start), "\n");
208    
209      // Determine what kind of documentation block this is.      // Determine what kind of documentation block this is.
     $code_start = $docblock['start'] + $docblock['length'] + 1;  
210      if (substr($source, $code_start, 8) == 'function') {      if (substr($source, $code_start, 8) == 'function') {
211        $function_matches = array();        $function_matches = array();
212    
# Line 219  function api_parse_php_file($file_path, Line 221  function api_parse_php_file($file_path,
221        $docblock['code'] = substr($source, $code_start, $code_end - $code_start);        $docblock['code'] = substr($source, $code_start, $code_end - $code_start);
222        $docblock['code'] = api_format_php("<?php\n". $docblock['code'] ."\n?>");        $docblock['code'] = api_format_php("<?php\n". $docblock['code'] ."\n?>");
223    
       $docblock['start_line'] = substr_count(substr($source, 0, $code_start), "\n");  
   
224        // Find parameter definitions.        // Find parameter definitions.
225        $param_match = array();        $param_match = array();
226        $offset = 0;        $offset = 0;
# Line 274  function api_parse_php_file($file_path, Line 274  function api_parse_php_file($file_path,
274        $docblock['code'] = substr($source, $code_start, $code_end - $code_start);        $docblock['code'] = substr($source, $code_start, $code_end - $code_start);
275        $docblock['code'] = api_format_php("<?php\n". $docblock['code'] ."\n?>");        $docblock['code'] = api_format_php("<?php\n". $docblock['code'] ."\n?>");
276    
       $docblock['start_line'] = substr_count(substr($source, 0, $code_start), "\n");  
   
277        // Determine group membership.        // Determine group membership.
278        $group_matches = array();        $group_matches = array();
279        preg_match_all('!@(ingroup|addtogroup) ([a-zA-Z0-9_]+)!', $docblock['content'], $group_matches);        preg_match_all('!@(ingroup|addtogroup) ([a-zA-Z0-9_]+)!', $docblock['content'], $group_matches);
# Line 329  function api_parse_php_file($file_path, Line 327  function api_parse_php_file($file_path,
327      }      }
328      else if (strpos($docblock['content'], '@defgroup') !== FALSE) {      else if (strpos($docblock['content'], '@defgroup') !== FALSE) {
329        $group_matches = array();        $group_matches = array();
330        preg_match('!@defgroup ([a-zA-Z0-9_]+) +(.*?)\n!', $docblock['content'], $group_matches);        if (preg_match('!@defgroup ([a-zA-Z0-9_.-]+) +(.*?)\n!', $docblock['content'], $group_matches)) {
331        $docblock['object_name'] = $group_matches[1];          $docblock['object_name'] = $group_matches[1];
332        $docblock['title'] = $group_matches[2];          $docblock['title'] = $group_matches[2];
333        $docblock['content'] = preg_replace('!@defgroup.*?\n!', '', $docblock['content']);          $docblock['content'] = preg_replace('!@defgroup.*?\n!', '', $docblock['content']);
334        $docblock['object_type'] = 'group';          $docblock['object_type'] = 'group';
335          }
336          else {
337            watchdog('api', 'Malformed @defgroup in %file at line %line.', array('%file' => $file_path, '%line' => $docblock['start_line']), WATCHDOG_NOTICE);
338          }
339      }      }
340    
341      // Handle nested function groups.      // Handle nested function groups.
# Line 470  function api_parse_php_file($file_path, Line 472  function api_parse_php_file($file_path,
472   *   The documentation ID of the inserted/updated construct.   *   The documentation ID of the inserted/updated construct.
473   */   */
474  function api_save_documentation(&$docblock) {  function api_save_documentation(&$docblock) {
475    $result = db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = '%s'", $docblock['object_name'], $docblock['branch_name'], $docblock['object_type']);    $did = db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = '%s'", $docblock['object_name'], $docblock['branch_name'], $docblock['object_type'], $docblock['file_name']));
476    if (db_num_rows($result) > 0) {    if ($did > 0) {
     $did = db_result($result);  
477      db_query("UPDATE {api_documentation} SET title = '%s', file_name = '%s', summary = '%s', documentation = '%s', code = '%s' WHERE did = %d", $docblock['title'], $docblock['file_name'], $docblock['summary'], $docblock['documentation'], $docblock['code'], $did);      db_query("UPDATE {api_documentation} SET title = '%s', file_name = '%s', summary = '%s', documentation = '%s', code = '%s' WHERE did = %d", $docblock['title'], $docblock['file_name'], $docblock['summary'], $docblock['documentation'], $docblock['code'], $did);
478    }    }
479    else {    else {
480      $did = db_next_id('{api_documentation}_did');      db_query("INSERT INTO {api_documentation} (object_name, branch_name, object_type, title, file_name, summary, documentation, code) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $docblock['object_name'], $docblock['branch_name'], $docblock['object_type'], $docblock['title'], $docblock['file_name'], $docblock['summary'], $docblock['documentation'], $docblock['code']);
481      db_query("INSERT INTO {api_documentation} (did, object_name, branch_name, object_type, title, file_name, summary, documentation, code) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $did, $docblock['object_name'], $docblock['branch_name'], $docblock['object_type'], $docblock['title'], $docblock['file_name'], $docblock['summary'], $docblock['documentation'], $docblock['code']);      $did = db_last_insert_id('api_documentation', 'did');
482    }    }
483    
484    switch ($docblock['object_type']) {    switch ($docblock['object_type']) {
# Line 485  function api_save_documentation(&$docblo Line 486  function api_save_documentation(&$docblo
486        db_query('DELETE FROM {api_function} WHERE did = %d', $did);        db_query('DELETE FROM {api_function} WHERE did = %d', $did);
487        db_query("INSERT INTO {api_function} (did, signature, start_line, parameters, `return`) VALUES (%d, '%s', %d, '%s', '%s')", $did, $docblock['signature'], $docblock['start_line'], $docblock['parameters'], $docblock['return']);        db_query("INSERT INTO {api_function} (did, signature, start_line, parameters, `return`) VALUES (%d, '%s', %d, '%s', '%s')", $did, $docblock['signature'], $docblock['start_line'], $docblock['parameters'], $docblock['return']);
488    
489        if (is_array($docblock['function calls'])) {        if (isset($docblock['function calls'])) {
490          db_query("DELETE FROM {api_reference_storage} WHERE branch_name = '%s' AND object_type = 'function' AND from_did = %d", $docblock['branch_name'], $did);          db_query("DELETE FROM {api_reference_storage} WHERE branch_name = '%s' AND object_type = 'function' AND from_did = %d", $docblock['branch_name'], $did);
491          foreach ($docblock['function calls'] as $function_name) {          foreach ($docblock['function calls'] as $function_name) {
492            api_reference($docblock['branch_name'], 'function', $function_name, $did);            api_reference($docblock['branch_name'], 'function', $function_name, $did);
# Line 499  function api_save_documentation(&$docblo Line 500  function api_save_documentation(&$docblo
500        break;        break;
501    }    }
502    
503    if (is_array($docblock['groups'])) {    if (isset($docblock['groups'])) {
504      db_query("DELETE FROM {api_reference_storage} WHERE branch_name = '%s' AND object_type = 'group' AND from_did = %d", $docblock['branch_name'], $did);      db_query("DELETE FROM {api_reference_storage} WHERE branch_name = '%s' AND object_type = 'group' AND from_did = %d", $docblock['branch_name'], $did);
505      foreach ($docblock['groups'] as $group_name) {      foreach ($docblock['groups'] as $group_name) {
506        api_reference($docblock['branch_name'], 'group', $group_name, $did);        api_reference($docblock['branch_name'], 'group', $group_name, $did);
# Line 734  function api_reference($branch_name, $to Line 735  function api_reference($branch_name, $to
735    static $is_php_function = array();    static $is_php_function = array();
736    
737    if ($to_type == 'function' && !isset($is_php_function[$to_name])) {    if ($to_type == 'function' && !isset($is_php_function[$to_name])) {
738      $is_php_function[$to_name] = (db_num_rows(db_query("SELECT object_name FROM {api_documentation} WHERE object_name = '%s' AND branch_name = 'php'", $to_name)) == 1);      $is_php_function[$to_name] = (db_result(db_query("SELECT COUNT(*) FROM {api_documentation} WHERE object_name = '%s' AND branch_name = 'php'", $to_name)) == 1);
739    }    }
740    
741    if ($to_type != 'function' || !$is_php_function[$to_name]) {    if ($to_type != 'function' || !$is_php_function[$to_name]) {

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.26

  ViewVC Help
Powered by ViewVC 1.1.3