| 1 | #!/usr/bin/perl |
---|
| 2 | #Created by Jason Wies (Zone, zone@users.sourceforge.net) |
---|
| 3 | #Copyright 2001 Jason Wies |
---|
| 4 | #Released under GNU Public License |
---|
| 5 | |
---|
| 6 | #Converts HeaderDoc style inline comments to LyX style LaTeX |
---|
| 7 | #Usage: ./inline2lyx.pl file Title Author Date Abstract |
---|
| 8 | |
---|
| 9 | if (!@ARGV[0]) |
---|
| 10 | { |
---|
| 11 | print "Usage: ./inline2lyx.pl file Title Author Date Abstract\n"; |
---|
| 12 | exit; |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | $output .= '\lyxformat 2.16 |
---|
| 16 | \textclass linuxdoc |
---|
| 17 | \language default |
---|
| 18 | \inputencoding latin1 |
---|
| 19 | \fontscheme default |
---|
| 20 | \graphics default |
---|
| 21 | \paperfontsize default |
---|
| 22 | \spacing single |
---|
| 23 | \papersize Default |
---|
| 24 | \paperpackage a4 |
---|
| 25 | \use_geometry 0 |
---|
| 26 | \use_amsmath 0 |
---|
| 27 | \paperorientation portrait |
---|
| 28 | \secnumdepth 2 |
---|
| 29 | \tocdepth 2 |
---|
| 30 | \paragraph_separation indent |
---|
| 31 | \defskip medskip |
---|
| 32 | \quotes_language english |
---|
| 33 | \quotes_times 2 |
---|
| 34 | \papercolumns 1 |
---|
| 35 | \papersides 1 |
---|
| 36 | \paperpagestyle default |
---|
| 37 | |
---|
| 38 | \layout Title |
---|
| 39 | \added_space_top vfill \added_space_bottom vfill |
---|
| 40 | ' . @ARGV[1] . ' |
---|
| 41 | \layout Author |
---|
| 42 | |
---|
| 43 | ' . @ARGV[2] . ' |
---|
| 44 | |
---|
| 45 | \layout Date |
---|
| 46 | |
---|
| 47 | ' . @ARGV[3] . ' |
---|
| 48 | |
---|
| 49 | \layout Abstract |
---|
| 50 | |
---|
| 51 | ' . @ARGV[4] . ' |
---|
| 52 | |
---|
| 53 | \layout Section |
---|
| 54 | |
---|
| 55 | ' . @ARGV[1]; |
---|
| 56 | |
---|
| 57 | $file = `cat @ARGV[0]`; |
---|
| 58 | |
---|
| 59 | @lines = split ('\n', $file); |
---|
| 60 | |
---|
| 61 | foreach $line (@lines) |
---|
| 62 | { |
---|
| 63 | undef $start; |
---|
| 64 | undef $class; |
---|
| 65 | undef $function; |
---|
| 66 | undef $abstract; |
---|
| 67 | undef $param; |
---|
| 68 | undef $result; |
---|
| 69 | undef $discussion; |
---|
| 70 | undef $end; |
---|
| 71 | undef $layout; |
---|
| 72 | |
---|
| 73 | if ($line =~ /\/\*\!/) |
---|
| 74 | { |
---|
| 75 | $in = 1; |
---|
| 76 | $start = 1; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | if ($looking && $line =~ /function/) |
---|
| 80 | { |
---|
| 81 | $layout = "verbatim"; |
---|
| 82 | undef $looking; |
---|
| 83 | } |
---|
| 84 | elsif (!$in) |
---|
| 85 | { |
---|
| 86 | goto next; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | if ($line =~ /\@(class)/) |
---|
| 90 | { |
---|
| 91 | $layout = "subsection"; |
---|
| 92 | $name = $1; |
---|
| 93 | $class = 1; |
---|
| 94 | } |
---|
| 95 | if ($line =~ /\@(function)/) |
---|
| 96 | { |
---|
| 97 | $layout = "subsection"; |
---|
| 98 | $name = $1; |
---|
| 99 | $function = 1; |
---|
| 100 | } |
---|
| 101 | if ($line =~ /\@(abstract)/) |
---|
| 102 | { |
---|
| 103 | $layout = "standard"; |
---|
| 104 | $name = $1; |
---|
| 105 | $abstract = 1; |
---|
| 106 | } |
---|
| 107 | if ($line =~ /\@(description)/) |
---|
| 108 | { |
---|
| 109 | $layout = "standard"; |
---|
| 110 | $name = $1; |
---|
| 111 | $description = 1; |
---|
| 112 | } |
---|
| 113 | if ($line =~ /\@(param)/) |
---|
| 114 | { |
---|
| 115 | $layout = "standard"; |
---|
| 116 | $name = $1; |
---|
| 117 | $param = 1; |
---|
| 118 | } |
---|
| 119 | if ($line =~ /\@(result)/) |
---|
| 120 | { |
---|
| 121 | $layout = "standard"; |
---|
| 122 | $name = $1; |
---|
| 123 | $result = 1; |
---|
| 124 | } |
---|
| 125 | if ($line =~ /\@(discussion)/) |
---|
| 126 | { |
---|
| 127 | $layout = "standard"; |
---|
| 128 | $name = $1; |
---|
| 129 | $discussion = 1; |
---|
| 130 | } |
---|
| 131 | if ($line =~ /\*\// && $in) |
---|
| 132 | { |
---|
| 133 | undef $in; |
---|
| 134 | $looking = 1; |
---|
| 135 | $end = 1; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | if ($layout) |
---|
| 139 | { |
---|
| 140 | $output .= "\n\n" . '\layout ' . ucfirst ($layout); |
---|
| 141 | $line =~ s/\@function//; |
---|
| 142 | $line =~ s/\@//; |
---|
| 143 | $data = ucfirst ($line); |
---|
| 144 | if (!$function && !$class) |
---|
| 145 | { |
---|
| 146 | $data =~ s/$name/$name:/; |
---|
| 147 | } |
---|
| 148 | $output .= "\n$data"; |
---|
| 149 | if ($function || $class) |
---|
| 150 | { |
---|
| 151 | $output .= "\n" . '\begin_inset LatexCommand \label{sec:' . "$data" . '}' . "\n\n" . '\end_inset'; |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | elsif ($in && !$start) |
---|
| 155 | { |
---|
| 156 | $output .= '\layout Standard' . "\n$line"; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | next: |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | $output .= "\n" . '\the_end'; |
---|
| 163 | |
---|
| 164 | print $output; |
---|