home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Examples / AutoDoc / lib / perl5 / Autodoc / ParseComments.pm < prev    next >
Encoding:
Perl POD Document  |  1995-11-02  |  5.5 KB  |  196 lines

  1. package Autodoc::ParseComments;
  2.  
  3. ###############################################################################
  4. ###############################################################################
  5. ##
  6. ##    Written by Adam Swift (c) 1995 by Friday Software and Consulting
  7. ##                           All rights reserved.
  8. ##
  9. ##      This notice may not be removed from this source code.
  10. ##
  11. ##    This program is included in the MiscKit by permission from the author
  12. ##    and its use is governed by the MiscKit license, found in the file
  13. ##    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  14. ##    for a list of all applicable permissions and restrictions.
  15. ##
  16. ##    Because AutoDoc is licensed free of charge, there is no warranty 
  17. ##    for the program.  Copyright holder, Friday Software and Consulting, 
  18. ##    is providing this program "as is" and this program is distributed in 
  19. ##    the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
  20. ##    even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
  21. ##    PARTICULAR PURPOSE.
  22. ##
  23. ###############################################################################
  24. ###############################################################################
  25.  
  26. require 5.000;
  27.  
  28. ##########################
  29. # load required packages #
  30. ##########################
  31. use Exporter;
  32. use Autodoc::ScanFile;
  33.  
  34. @ISA      = qw(Exporter);
  35. @EXPORT   = qw(parse_extractADComment
  36.            parse_extract_preADComment
  37.            parse_extract_postADComment
  38.            parse_containsADComment);
  39.  
  40. $module_version = '$Revision: 1.2 $';
  41. $module_version =~ s!(\$\w+: | \$)!!g;
  42. $module_id    = '$Id: ParseComments.pm,v 1.2 1995/10/20 22:16:28 aswift Exp $';
  43. $module_id      =~ s!(\$\w+: | \$)!!g;
  44. $module_name    = $module_id;
  45. $module_name    =~ s!^([^\,]+).*$!$1!;
  46.  
  47. ############################################################################
  48. # Purpose: Module that encapsulates parsing autodoc style comments out of 
  49. #          source code
  50. #
  51. # HISTORY: START
  52. # $Log: ParseComments.pm,v $
  53. # Revision 1.2  1995/10/20  22:16:28  aswift
  54. # Added DevMan style changes Log support
  55. #
  56. #
  57. # HISTORY: END
  58. ############################################################################
  59.  
  60. #############################################################################
  61. #
  62. # NAME:       module_version
  63. #
  64. # ACTION:     returns the version number of this module
  65. #
  66. # RETURN:     the module version
  67. #
  68. #############################################################################
  69. sub module_version
  70. {
  71.     return $module_version;
  72. }
  73.  
  74. sub module_versionstamp
  75. {
  76.     return "$module_name (rev-$module_version)";
  77. }
  78.  
  79. #############################################################################
  80. #
  81. # NAME:       parse_extractADComment
  82. #
  83. # ACTION:     Extracts the portion of the string argument which contains 
  84. #             an autodoc comment and processes it to remove extra whitespace
  85. #
  86. # ARGUMENTS:  The string (possibly) containing an autodoc comment
  87. #
  88. # RETURN:     The processed portion of the string which contains an autodoc 
  89. #             comment, or an empty string if no comment was found.
  90. #
  91. #############################################################################
  92. sub parse_extractADComment
  93. {
  94.     local ($ADcomment, $in);
  95.  
  96.     use Autodoc::ScanFile;
  97.  
  98.     $ADcomment = "";
  99.     $in = $_[0];
  100.  
  101.     return "" if (!($in =~ m!/\*+\"(.*)\"\*+/!));
  102.  
  103.     
  104.     $ADcomment = scan_postprocess($1);
  105.     
  106.     # remove marked newlines from the beginning of the line
  107.     $ADcomment =~ s/^\s*\\n\s*// 
  108.     while ($ADcomment =~ m/^\\n/);
  109.     
  110.     # remove marked newlines from the end of the line also
  111.     $ADcomment =~ s/\s*\\n\s*$// 
  112.     while ($ADcomment =~ m/\\n$/);    
  113.     
  114. #    $ADcomment =~ s/\s*\\n\s*\\n\s*/ \\n/g
  115. #    while ($ADcomment =~ m/\\n\s*\\n/);    
  116. #                # Remove all repeater newlines
  117.     return $ADcomment;
  118. }
  119.  
  120.  
  121. #############################################################################
  122. #
  123. # NAME:       parse_containsADComment
  124. #
  125. # ACTION:     Returns 1 if the string passed as the argument conforms to 
  126. #             the format of an autodoc comment.
  127. #
  128. # ARGUMENTS:  The string which is being tested
  129. #
  130. # RETURN:     1 if the string passed contains an autodoc comment, 0 otherwise.
  131. #
  132. #############################################################################
  133. sub parse_containsADComment
  134. {
  135.     local ($in);
  136.  
  137.     $in = $_[0];
  138.  
  139.     return 1 if ($in =~ m!/\*+\".*\"\*+/!);
  140.     return 0;
  141. }
  142.  
  143.  
  144. #############################################################################
  145. #
  146. # NAME:       parse_extract_preADComment
  147. #
  148. # ACTION:     Returns the portion of the string that preceeds the autodoc 
  149. #             comment (if any).
  150. #
  151. # ARGUMENTS:  The string which is being extracted
  152. #
  153. # RETURN:     The portion of the string that preceeds the autodoc comment, or
  154. #             an empty string.
  155. #
  156. #############################################################################
  157. sub parse_extract_preADComment
  158. {
  159.     local ($in);
  160.  
  161.     $in = $_[0];
  162.  
  163.     return $` if ($in =~ m!/\*+\".*\"\*+/!);
  164.  
  165.     return "";
  166. }
  167.  
  168.  
  169. #############################################################################
  170. #
  171. # NAME:       parse_extract_postADComment
  172. #
  173. # ACTION:     Returns the portion of the string that follows the autodoc 
  174. #             comment (if any).
  175. #
  176. # ARGUMENTS:  The string which is being extracted
  177. #
  178. # RETURN:     The portion of the string that follows the autodoc comment, or
  179. #             an empty string.
  180. #
  181. #############################################################################
  182. sub parse_extract_postADComment
  183. {
  184.     local ($in);
  185.  
  186.     $in = $_[0];
  187.  
  188.     return $' if ($in =~ m!/\*+\".*\"\*+/!);
  189.  
  190.     return "";
  191. }
  192.  
  193.  
  194. 1;
  195.