home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume3 / pcmail / part05 / srctoman.sh < prev    next >
Text File  |  1989-02-03  |  4KB  |  202 lines

  1. : srctoman - see comment below
  2.  
  3. : process arguments
  4.  
  5. while :
  6. do
  7.     case $1 in
  8.  [0-9]) SECT=$1;;
  9.      -) LANG=$1; B='[#:]';;
  10.   -awk) LANG=$1; B='#';;
  11.     -c) LANG=$1; B='\/\*';;
  12.     -f) LANG=$1; B='[Cc]';;
  13.    -mk) LANG=$1; B='#';;
  14.  -n|-t) LANG=$1; B='\\"';;
  15.     -p) LANG=$1; B='{';;
  16.     -r) LANG=$1; B='#';;
  17.     -C) LANG=$1; B=$2; shift;;
  18.     -*) ERROR="unknown option: $1"; break;;
  19.     "") ERROR="missing file argument"; break;;
  20.      *) break;;
  21.     esac
  22.     shift
  23. done
  24.  
  25. : check error status
  26.  
  27. case $ERROR in
  28. "") ;;
  29.  *) echo "$0: $ERROR" 1>&2
  30.     echo "usage: $0 [-|-awk|-c|-f|-mk|-n|-p|-t|-r] [section] file(s)" 1>&2; exit 1;;
  31. esac
  32.  
  33. : set up for file suffix processing
  34.  
  35. case $LANG in
  36. "") sh='[:#]';    r='#';    rh=$r;    awk='#'; mk='#';
  37.     c='\/\*';    h=$c;    y=$c;    l=$c;
  38.     f='[Cc]';    fh=$f;    p='{';    ph=$p;
  39.     ms='\\"';    nr=$ms;    mn=$ms;    man=$ms;
  40. esac
  41.  
  42. : extract comments
  43.  
  44. for i in $*
  45. do
  46.     case $LANG in
  47.     "") eval B\="\$`expr $i : '^.*\.\([^.]*\)$'`"
  48.     test "$B" || { echo "$0: unknown suffix: $i; assuming c" 1>&2; B=$c; }
  49.     esac
  50.     sed '
  51.     /^'"$B"'++/,/^'"$B"'--/!d
  52.     /^'"$B"'++/d
  53.     /^'"$B"'--/d
  54.     s/[     ]*$//
  55.     /^'"$B"' \([A-Z]\)/{
  56.     s//\1/
  57.     /^NAME/{
  58.         N
  59.         s/^.*\n'"$B"'[     ]*//
  60.         h
  61.         y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
  62.         s/^.*$/.TH & '"$SECT"'\
  63. .ad\
  64. .fi\
  65. .SH NAME/
  66.         p
  67.         g
  68.         s/ [0-9]$//
  69.         a\
  70. \\-
  71.         p
  72.         d
  73.     }
  74.     /^SUMMARY/d
  75.     /^DESCRIPTION/s//.SH &\
  76. .ad\
  77. .fi/
  78.     /^BUGS/s//.SH &\
  79. .ad\
  80. .fi/
  81.     /^DIAGNOSTICS/s//.SH &\
  82. .ad\
  83. .fi/
  84.     /^[A-Z][A-Z][A-Z][^a-z]*$/s//.SH &\
  85. .na\
  86. .nf/
  87.     p
  88.     d
  89.     }
  90.     s/^'"$B"'[     ]*//
  91.     s/^[     ]*$//
  92. ' $i
  93. done 
  94.  
  95. exit
  96.  
  97. :++
  98. : NAME
  99. :    srctoman 1
  100. : SUMMARY
  101. :    extract manual page from source file comment
  102. : PACKAGE
  103. :    source file maintentance tools
  104. : SYNOPSIS
  105. :    srctoman [-|-awk|-c|-f|-mk|-m|-n|-p|-t|-r] [section] file(s)
  106. : DESCRIPTION
  107. :    Srctoman converts comments in various programming languages to
  108. :    UNIX-style manual pages.
  109. :    The command processes comments in the style of newsource(1);
  110. :    its standard output is suitable for formatting with nroff(1) or 
  111. :    troff(1) using the "-man" macro package.  
  112. :    Typically, srctoman is integrated with make(1) scripts.
  113. :
  114. :    Source files are processed in the indicated order; if no
  115. :    files argument the command produces no output.
  116. :
  117. :    The source file language can be specified through a command-line
  118. :    option, or can be implied by the filename suffix.
  119. :    The expected start-of-comment symbol is shown in the last column.
  120. :
  121. : .nf
  122.     option    language    comment
  123.  
  124.     -    shell        [:#]
  125.     -awk    awk        #
  126.     -c    c        /*
  127.     -f    fortran        [Cc]
  128.     -mk    make        #
  129.     -n    nroff        \\"
  130.     -p    pascal        {
  131.     -t    troff        \\"
  132.     -r    ratfor        #
  133.     -C    any language    next argument
  134. : .fi
  135. :
  136. : .nf
  137.     suffix    language    comment
  138.  
  139.     .awk    awk        #
  140.     .c    c        /*
  141.     .f    fortran        [Cc]
  142.     .fh    fortran        [Cc]
  143.     .h    c        /*
  144.     .l    lex        /*
  145.     .man    nroff,troff    \\"
  146.     .mk    make        #
  147.     .me    nroff,troff    \\"
  148.     .ms    nroff,troff    \\"
  149.     .nr    nroff,troff    \\"
  150.     .p    pascal        {
  151.     .ph    pascal        {
  152.     .r    ratfor        #
  153.     .rh    ratfor        #
  154.     .sh    shell        [:#]
  155.     .y    yacc        /*
  156. : .fi
  157. :
  158. :    The required format of comments is discussed below, where SOC
  159. :    stands for the start-of-comment symbol of the language being used.
  160. :
  161. :    1) Start of manual: SOC, followed by `++'.
  162. :
  163. :    2) Section heading: SOC, blank, section name in upper case.
  164. :
  165. :    3) New paragraph: empty line or line with SOC only.
  166. :
  167. :    4) All other text: SOC and subsequent blanks or tabs are removed.
  168. :    Lines that do not start with SOC are left unchanged (useful for 
  169. :    inclusion of program text).
  170. :
  171. :    5) End of manual: SOC, followed by `--'.
  172. :    An end-of-comment may follow if the source file language requires this.
  173. :
  174. :    The following manual sections receive a special treatment:
  175. :    NAME and SUMMARY should appear at the beginning and in
  176. :    this order; DESCRIPTION, DIAGNOSTICS and BUGS will be
  177. :    right-margin adjusted.
  178. :    Other sections may be added freely without confusing srctoman.
  179. : COMMANDS
  180. :    sh(1), sed(1), expr(1)
  181. : SEE ALSO
  182. :    newsource(1), modsource(1), xman(1)
  183. :    The earlier commands new(1), mod(1), mkman(1) and dssman(1)
  184. :    by Ruud Zwart and Ben Noordzij (Erasmus University, Rotterdam) 
  185. : DIAGNOSTICS
  186. :    The program complains if an unknown language is specified
  187. :    or if the language cannot be deduced from the file suffix.
  188. : AUTHOR(S)
  189. :    W.Z. Venema
  190. :    Eindhoven University of Technology
  191. :    Department of Mathematics and Computer Science
  192. :    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  193. : CREATION DATE
  194. :    Fri Jan 17 22:59:27 MET 1986
  195. : LAST MODIFICATION
  196. :    Thu Mar 10 20:08:15 MET 1988
  197. : VERSION/RELEASE
  198. :    1.20
  199. :--
  200.  
  201.  
  202.