Debian Codegraph @

maned.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # maned.sh
3 # A rudimentary man page editor
4
5 # Version: 0.1 (Alpha, probably buggy)
6 # Author: Mendel Cooper <[email protected]>
7 # Reldate: 16 June 2008
8 # License: GPL3
9
10
11 savefile= # Global, used in multiple functions.
12 E_NOINPUT=90 # User input missing (error). May or may not be critical.
13
14 # =========== Markup Tags ============ #
15 TopHeader=".TH"
16 NameHeader=".SH NAME"
17 SyntaxHeader=".SH SYNTAX"
18 SynopsisHeader=".SH SYNOPSIS"
19 InstallationHeader=".SH INSTALLATION"
20 DescHeader=".SH DESCRIPTION"
21 OptHeader=".SH OPTIONS"
22 FilesHeader=".SH FILES"
23 EnvHeader=".SH ENVIRONMENT"
24 AuthHeader=".SH AUTHOR"
25 BugsHeader=".SH BUGS"
26 SeeAlsoHeader=".SH SEE ALSO"
27 BOLD=".B"
28 # Add more tags, as needed.
29 # See groff docs for markup meanings.
30 # ==================================== #
31
32 startscip-shell shell abs-guide 10-4 start(). ()
33 {
34 clearscip-shell system . . clear. # Clear screen.
35 echoscip-shell system . . echo. "ManEd"
36 echoscip-shell system . . echo. "-----"
37 echoscip-shell system . . echo.
38 echoscip-shell system . . echo. "Simple man page creator"
39 echoscip-shell system . . echo. "Author: Mendel Cooper"
40 echoscip-shell system . . echo. "License: GPL3"
41 echoscip-shell system . . echo.; echoscip-shell system . . echo.; echoscip-shell system . . echo.
42 }
43
44 prognamescip-shell shell abs-guide 10-4 progname(). ()
45 {
46 echoscip-shell system . . echo. -n "Program name? "
47 read name
48
49 echoscip-shell system . . echo. -n "Manpage section? [Hit RETURN for default (\"1\") ] "
50 read section
51 if [scip-shell system . . `[`. -z "$section" ]
52 then
53 section=1 # Most man pages are in section 1.
54 fi
55
56 if [scip-shell system . . `[`. -n "$name" ]
57 then
58 savefile=""$name"."$section"" # Filename suffix = section.
59 echoscip-shell system . . echo. -n "$1 " >>$savefile
60 name1=$(echoscip-shell system . . echo. "$name" | trscip-shell system . . tr. a-z A-Z) # Change to uppercase,
61 #+ per man page convention.
62 echoscip-shell system . . echo. -n "$name1" >>$savefile
63 else
64 echoscip-shell system . . echo. "Error! No input." # Mandatory input.
65 exit $E_NOINPUT # Critical!
66 # Exercise: The script-abort if no filename input is a bit clumsy.
67 # Rewrite this section so a default filename is used
68 #+ if no input.
69 fi
70
71 echoscip-shell system . . echo. -n " \"$section\"">>$savefile # Append, always append.
72
73 echoscip-shell system . . echo. -n "Version? "
74 read ver
75 echoscip-shell system . . echo. -n " \"Version $ver \"">>$savefile
76 echoscip-shell system . . echo. >>$savefile
77
78 echoscip-shell system . . echo. -n "Short description [0 - 5 words]? "
79 read sdesc
80 echoscip-shell system . . echo. "$NameHeader">>$savefile
81 echoscip-shell system . . echo. ""$BOLD" "$name"">>$savefile
82 echoscip-shell system . . echo. "\- "$sdesc"">>$savefile
83
84 }
85
86 fill_inscip-shell shell abs-guide 10-4 fill_in(). ()
87 { # This function more or less copied from "pad.sh" script.
88 echoscip-shell system . . echo. -n "$2? " # Get user input.
89 read var # May paste (a single line only!) to fill in field.
90
91 if [scip-shell system . . `[`. -n "$var" ]
92 then
93 echoscip-shell system . . echo. "$1 " >>$savefile
94 echoscip-shell system . . echo. -n "$var" >>$savefile
95 else # Don't append empty field to file.
96 return $E_NOINPUT # Not critical here.
97 fi
98
99 echoscip-shell system . . echo. >>$savefile
100
101 }
102
103
104 endscip-shell shell abs-guide 10-4 end(). ()
105 {
106 clearscip-shell system . . clear.
107 echoscip-shell system . . echo. -n "Would you like to view the saved man page (y/n)? "
108 read ans
109 if [scip-shell system . . `[`. "$ans" = "n" -o "$ans" = "N" ]; then exit; fi
110 exec less "$savefile" # Exit script and hand off control to "less" ...
111 #+ ... which formats for viewing man page source.
112 }
113
114
115 # ---------------------------------------- #
116 startscip-shell shell abs-guide 10-4 start().
117 prognamescip-shell shell abs-guide 10-4 progname(). "$TopHeader"
118 fill_inscip-shell shell abs-guide 10-4 fill_in(). "$SynopsisHeader" "Synopsis"
119 fill_inscip-shell shell abs-guide 10-4 fill_in(). "$DescHeader" "Long description"
120 # May paste in *single line* of text.
121 fill_inscip-shell shell abs-guide 10-4 fill_in(). "$OptHeader" "Options"
122 fill_inscip-shell shell abs-guide 10-4 fill_in(). "$FilesHeader" "Files"
123 fill_inscip-shell shell abs-guide 10-4 fill_in(). "$AuthHeader" "Author"
124 fill_inscip-shell shell abs-guide 10-4 fill_in(). "$BugsHeader" "Bugs"
125 fill_inscip-shell shell abs-guide 10-4 fill_in(). "$SeeAlsoHeader" "See also"
126 # fill_in "$OtherHeader" ... as necessary.
127 endscip-shell shell abs-guide 10-4 end(). # ... exit not needed.
128 # ---------------------------------------- #
129
130 # Note that the generated man page will usually
131 #+ require manual fine-tuning with a text editor.
132 # However, it's a distinct improvement upon
133 #+ writing man source from scratch
134 #+ or even editing a blank man page template.
135
136 # The main deficiency of the script is that it permits
137 #+ pasting only a single text line into the input fields.
138 # This may be a long, cobbled-together line, which groff
139 # will automatically wrap and hyphenate.
140 # However, if you want multiple (newline-separated) paragraphs,
141 #+ these must be inserted by manual text editing on the
142 #+ script-generated man page.
143 # Exercise (difficult): Fix this!
144
145 # This script is not nearly as elaborate as the
146 #+ full-featured "manedit" package
147 #+ http://freshmeat.net/projects/manedit/
148 #+ but it's much easier to use.