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