File: Mkdoc.nawk

package info (click to toggle)
plan 1.8.4-9
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,964 kB
  • ctags: 1,986
  • sloc: ansic: 24,493; perl: 1,361; makefile: 531; sh: 516; yacc: 119; sed: 17
file content (119 lines) | stat: -rw-r--r-- 2,809 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#
# Convert plan.help to troff -ms format.
#
# author : christian.wagner@univ-pau.fr
#          wagner@crisv2.univ-pau.fr
#
# Inspired from a perl script written
# by gregg hanna <gregor@kafka.saic.com>
#

BEGIN { 
  nofill = 0; indent = 0; MxSp = 6; outs = "" ;
  print ".lg"
  print ".TL\nPLAN - documentation"
  print "\n.br"
  print "\\fI Thomas Driemeyer\\fR\n.br"
  print "thomas@bitrot.de"
# to be updated for double-side printing
  print ".OH 'Plan - documentation'''"
  print ".OF '\\*(DY''%'"
  print ".EH 'Plan - documentation'''"
  print ".EF '\\*(DY''%'"
}

{
#- `#' as first charcter
  if ( index($1,"#") == 1 ) {
    if ( indent ) indent = 0
  }
#- `%' as first character
  else if ( index($1,"%") == 1 ) {
   if ( indent ) indent = 0
   outs = ".SH\n"
   getline
   old_fs = FS
   FS = "\t"
   outs = outs$2"\\fR\n.br"
   FS = old_fs
  }
#- `TAB' as first character
  else if ( index($0,"\t") == 1 ) {
    if ( index($0, " -- ") != 0 ) {
      if ( indent ) indent = 0
      old_fs = FS
      FS = " -- "
      if ( $1 == "\tDon't show today's past" )
        $1 = "\tDon\\'t show today\\'s past"
      outs = ".IP \"\\fI"$1"\\fR\"\n "$2
      FS = "\t "
      while ( $0 != "" ) {getline; outs = outs$2}
      FS = old_fs
    }
    else if ( index($0,"\t\*") == 1 ) {
      if ( indent ) indent = 0
      old_fs = FS
      FS = "\t\*"
      outs = "\n"$2
      FS = "\t    "
      getline
      while ( $0 != "" ) { outs = outs" "$2 ; getline }
      FS = old_fs
    }
    else if ( match($0,/^\t[0-9]/) == 1 ) {
      if ( indent ) indent = 0
      old_fs = FS
      FS = "\t"
      outs = $2
      getline
      while ( $0 != "" ) {
        str = substr($2,index($2," "))
        while ( index(str," ") == 1 ) str = substr(str, 2)
        outs = outs" "str
	getline
      }
      outs = outs"\n"
    }
    else if ( $0 == "\t" ) {
        outs = ".LP"
	if ( indent ) indent = 0
    }
    else if ( index($0,"\t ") == 1 ) {
        str = substr($0,index($0," "))
        pos = 0
        while ( (n = index(str," ")) == 1 ) {
	  pos++
	  str = substr(str,2)
        }
	if ( index(str,"\.") == 1 )
	  str = " "str
        if ( pos > MxSp ) {
          if ( nofill ) print str
          else { nofill = 1; print ".nf\n"str }
        }
        else if ( indent ) {
          outs = ".br\n"str
        }
        else { indent = 1; outs = ".IP \"\" "pos"\n"str }
    }
    #- other cases where `TAB' is the first character
    else {
      if ( indent ) indent = 0
      old_fs = FS
      FS = "\t"
      outs = $2
      FS = old_fs
    }
  }
#- end first character = `TAB'
  else if ( $0 == "" ) {
    outs = ".LP"
    if ( indent ) indent = 0
  }
  else {
    outs = $0
    if ( indent ) indent = 0
  }
  if ( nofill ) { nofill = 0; print ".fi" }
  if ( outs != "" ) { print outs; outs = "" }
}