home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / opcom-2.1 / part01 / srctoman < prev    next >
Encoding:
Text File  |  1993-04-10  |  4.6 KB  |  210 lines

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