| 1 | |
|---|
| 2 | eval 'exec perl -S $0 "$@"' |
|---|
| 3 | if $runnning_under_some_shell; |
|---|
| 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 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | $short_line_length = 40; |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | $preformat_whitespace_min = 5; |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | $preformat_trigger_lines = 2; |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | $endpreformat_trigger_lines = 2; |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | $hrule_min = 4; |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | $min_caps_length = 3; |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | $caps_tag = "STRONG"; |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | $mailmode = 0; |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | $unhyphenation = 1; |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | $append_file = 0; |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | $title = 0; |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | $underline_tolerance_long = 1; |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | $underline_tolerance_short = 1; |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | $tab_width = 8; |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | $indent_width = 2; |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | $extract = 0; |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | $NONE = 0; |
|---|
| 244 | $LIST = 1; |
|---|
| 245 | $HRULE = 2; |
|---|
| 246 | $PAR = 4; |
|---|
| 247 | $PRE = 8; |
|---|
| 248 | $END = 16; |
|---|
| 249 | $BREAK = 32; |
|---|
| 250 | $HEADER = 64; |
|---|
| 251 | $MAILHEADER = 128; |
|---|
| 252 | $MAILQUOTE = 256; |
|---|
| 253 | $CAPS = 512; |
|---|
| 254 | |
|---|
| 255 | $OL = 1; |
|---|
| 256 | $UL = 2; |
|---|
| 257 | |
|---|
| 258 | sub usage |
|---|
| 259 | { |
|---|
| 260 | $0 =~ s |
|---|
| 261 | local($s) = " " x length($0); |
|---|
| 262 | print STDERR <<EOF; |
|---|
| 263 | |
|---|
| 264 | Usage: $0 [options] |
|---|
| 265 | |
|---|
| 266 | where options are: |
|---|
| 267 | $s [-v ] | [--version ] |
|---|
| 268 | $s [-h ] | [--help ] |
|---|
| 269 | $s [-s <n> ] | [--shortline <n> ] |
|---|
| 270 | $s [-p <n> ] | [--prewhite <n> ] |
|---|
| 271 | $s [-pb <n> ] | [--prebegin <n> ] |
|---|
| 272 | $s [-pe <n> ] | [--preend <n> ] |
|---|
| 273 | $s [-e/+e ] | [--extract / --noextract ] |
|---|
| 274 | $s [-r <n> ] | [--hrule <n> ] |
|---|
| 275 | $s [-c <n> ] | [--caps <n> ] |
|---|
| 276 | $s [-ct <tag> ] | [--capstag <tag> ] |
|---|
| 277 | $s [-m/+m ] | [--mail / --nomail ] |
|---|
| 278 | $s [-u/+u ] | [--unhyphen / --nounhyphen ] |
|---|
| 279 | $s [-a <file> ] | [--append <file> ] |
|---|
| 280 | $s [+a ] | [--noappend ] |
|---|
| 281 | $s [-t <title>] | [--title <title> ] |
|---|
| 282 | $s [-tw <n> ] | [--tabwidth <n> ] |
|---|
| 283 | $s [-iw <n> ] | [--indent <n> ] |
|---|
| 284 | $s [-ul <n> ] | [--underlinelong <n> ] |
|---|
| 285 | $s [-us <n> ] | [--underlineshort <n> ] |
|---|
| 286 | |
|---|
| 287 | More complete explanations of these options can be found in |
|---|
| 288 | comments near the beginning of the script. |
|---|
| 289 | |
|---|
| 290 | EOF |
|---|
| 291 | } |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | sub deal_with_options |
|---|
| 295 | { |
|---|
| 296 | while ($ARGV[0] =~ /^[-+].+/) |
|---|
| 297 | { |
|---|
| 298 | if (($ARGV[0] eq "-r" || $ARGV[0] eq "--hrule") && |
|---|
| 299 | $ARGV[1] =~ /^%d+$/) |
|---|
| 300 | { |
|---|
| 301 | $hrule_min = $ARGV[1]; |
|---|
| 302 | shift @ARGV; |
|---|
| 303 | next; |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | if (($ARGV[0] eq "-s" || $ARGV[0] eq "--shortline") && |
|---|
| 307 | $ARGV[1] =~ /^\d+$/) |
|---|
| 308 | { |
|---|
| 309 | $short_line_length = $ARGV[1]; |
|---|
| 310 | shift @ARGV; |
|---|
| 311 | next; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | if (($ARGV[0] eq "-p" || $ARGV[0] eq "--prewhite") && |
|---|
| 315 | $ARGV[1] =~ /^\d+$/) |
|---|
| 316 | { |
|---|
| 317 | $preformat_whitespace_min = $ARGV[1]; |
|---|
| 318 | shift @ARGV; |
|---|
| 319 | next; |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | if (($ARGV[0] eq "-pb" || $ARGV[0] eq "--prebegin") && |
|---|
| 323 | $ARGV[1] =~ /^\d+$/) |
|---|
| 324 | { |
|---|
| 325 | $preformat_trigger_lines = $ARGV[1]; |
|---|
| 326 | shift @ARGV; |
|---|
| 327 | next; |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | if (($ARGV[0] eq "-pe" || $ARGV[0] eq "--preend") && |
|---|
| 331 | $ARGV[1] =~ /^\d+$/) |
|---|
| 332 | { |
|---|
| 333 | $endpreformat_trigger_lines = $ARGV[1]; |
|---|
| 334 | shift @ARGV; |
|---|
| 335 | next; |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | if (($ARGV[0] eq "-e" || $ARGV[0] eq "--extract")) |
|---|
| 339 | { |
|---|
| 340 | $extract = 1; |
|---|
| 341 | shift @ARGV; |
|---|
| 342 | next; |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | if (($ARGV[0] eq "+e" || $ARGV[0] eq "--noextract")) |
|---|
| 346 | { |
|---|
| 347 | $extract = 0; |
|---|
| 348 | shift @ARGV; |
|---|
| 349 | next; |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | if (($ARGV[0] eq "-c" || $ARGV[0] eq "--caps") && |
|---|
| 353 | $ARGV[1] =~ /^\d+$/) |
|---|
| 354 | { |
|---|
| 355 | $min_caps_length = $ARGV[1]; |
|---|
| 356 | shift @ARGV; |
|---|
| 357 | next; |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | if (($ARGV[0] eq "-ct" || $ARGV[0] eq "--capstag") && |
|---|
| 361 | $ARGV[1]) |
|---|
| 362 | { |
|---|
| 363 | $caps_tag = $ARGV[1]; |
|---|
| 364 | shift @ARGV; |
|---|
| 365 | next; |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | if ($ARGV[0] eq "-m" || $ARGV[0] eq "--mail") |
|---|
| 369 | { |
|---|
| 370 | $mailmode = 1; |
|---|
| 371 | next; |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | if ($ARGV[0] eq "+m" || $ARGV[0] eq "--nomail") |
|---|
| 375 | { |
|---|
| 376 | $mailmode = 0; |
|---|
| 377 | next; |
|---|
| 378 | } |
|---|
| 379 | |
|---|
| 380 | if ($ARGV[0] eq "-u" || $ARGV[0] eq "--unhyphen") |
|---|
| 381 | { |
|---|
| 382 | $unhyphenation = 1; |
|---|
| 383 | next; |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | if ($ARGV[0] eq "+u" || $ARGV[0] eq "--nounhyphen") |
|---|
| 387 | { |
|---|
| 388 | $unhyphenation = 0; |
|---|
| 389 | next; |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | if (($ARGV[0] eq "-a" || $ARGV[0] eq "--append") && |
|---|
| 393 | $ARGV[1]) |
|---|
| 394 | { |
|---|
| 395 | if (-r $ARGV[1]) { |
|---|
| 396 | $append_file = $ARGV[1]; |
|---|
| 397 | } else { |
|---|
| 398 | print STDERR "Can't find or read $ARGV[1].\n"; |
|---|
| 399 | } |
|---|
| 400 | shift @ARGV; |
|---|
| 401 | next; |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | if ($ARGV[0] eq "+a" || $ARGV[0] eq "--noappend") |
|---|
| 405 | { |
|---|
| 406 | $append_file = 0; |
|---|
| 407 | next; |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | if (($ARGV[0] eq "-t" || $ARGV[0] eq "--title") && |
|---|
| 411 | $ARGV[1]) |
|---|
| 412 | { |
|---|
| 413 | $title = $ARGV[1]; |
|---|
| 414 | shift @ARGV; |
|---|
| 415 | next; |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | if (($ARGV[0] eq "-ul" || $ARGV[0] eq "--underlinelong") && |
|---|
| 419 | $ARGV[1] =~ /^\d+$/) |
|---|
| 420 | { |
|---|
| 421 | $underline_tolerance_long = $ARGV[1]; |
|---|
| 422 | shift @ARGV; |
|---|
| 423 | next; |
|---|
| 424 | } |
|---|
| 425 | |
|---|
| 426 | if (($ARGV[0] eq "-us" || $ARGV[0] eq "--underlineshort") && |
|---|
| 427 | $ARGV[1] =~ /^\d+$/) |
|---|
| 428 | { |
|---|
| 429 | $underline_tolerance_short = $ARGV[1]; |
|---|
| 430 | shift @ARGV; |
|---|
| 431 | next; |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | if (($ARGV[0] eq "-tw" || $ARGV[0] eq "--tabwidth") && |
|---|
| 435 | $ARGV[1] =~ /^\d+$/) |
|---|
| 436 | { |
|---|
| 437 | $tab_width = $ARGV[1]; |
|---|
| 438 | shift @ARGV; |
|---|
| 439 | next; |
|---|
| 440 | } |
|---|
| 441 | |
|---|
| 442 | if (($ARGV[0] eq "-iw" || $ARGV[0] eq "--indentwidth") && |
|---|
| 443 | $ARGV[1] =~ /^\d+$/) |
|---|
| 444 | { |
|---|
| 445 | $indent_width = $ARGV[1]; |
|---|
| 446 | shift @ARGV; |
|---|
| 447 | next; |
|---|
| 448 | } |
|---|
| 449 | |
|---|
| 450 | if ($ARGV[0] eq "-v" || $ARGV[0] eq "--version") |
|---|
| 451 | { |
|---|
| 452 | print '$Header: /users/hilco/seth/projects/txt2html/txt2html.pl,v 1 |
|---|
| 453 | .10 1994/12/28 20:10:25 seth Exp seth $ '; |
|---|
| 454 | print "\n"; |
|---|
| 455 | exit; |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | if ($ARGV[0] eq "-h" || $ARGV[0] eq "--help") |
|---|
| 459 | { |
|---|
| 460 | &usage; |
|---|
| 461 | exit; |
|---|
| 462 | } |
|---|
| 463 | |
|---|
| 464 | print STDERR "Unrecognized option: $ARGV[0]\n"; |
|---|
| 465 | print STDERR " or bad paramater: $ARGV[1]\n" if($ARGV[1]); |
|---|
| 466 | |
|---|
| 467 | &usage; |
|---|
| 468 | exit(1); |
|---|
| 469 | |
|---|
| 470 | } continue { |
|---|
| 471 | |
|---|
| 472 | shift @ARGV; |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | $preformat_trigger_lines = 0 if ($preformat_trigger_lines < 0); |
|---|
| 476 | $preformat_trigger_lines = 2 if ($preformat_trigger_lines > 2); |
|---|
| 477 | |
|---|
| 478 | $endpreformat_trigger_lines = 1 if ($preformat_trigger_lines == 0); |
|---|
| 479 | $endpreformat_trigger_lines = 0 if ($endpreformat_trigger_lines < 0); |
|---|
| 480 | $endpreformat_trigger_lines = 2 if ($endpreformat_trigger_lines > 2); |
|---|
| 481 | |
|---|
| 482 | $underline_tolerance_long = 0 if $underline_tolerance_long < 0; |
|---|
| 483 | $underline_tolerance_short = 0 if $underline_tolerance_short < 0; |
|---|
| 484 | } |
|---|
| 485 | |
|---|
| 486 | sub is_blank |
|---|
| 487 | { |
|---|
| 488 | return $_[0] =~ /^\s*$/; |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | sub escape |
|---|
| 492 | { |
|---|
| 493 | $line =~ s/&/&/g; |
|---|
| 494 | $line =~ s/>/>/g; |
|---|
| 495 | $line =~ s/</</g; |
|---|
| 496 | $line =~ s/\014/\n<HR>\n/g; |
|---|
| 497 | } |
|---|
| 498 | |
|---|
| 499 | sub hrule |
|---|
| 500 | { |
|---|
| 501 | if ($line =~ /^\s*([-_~=\*]\s*){$hrule_min,}$/) |
|---|
| 502 | { |
|---|
| 503 | $line = "<HR>\n"; |
|---|
| 504 | $prev =~ s/<p>//; |
|---|
| 505 | $line_action |= $HRULE; |
|---|
| 506 | } |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | sub shortline |
|---|
| 510 | { |
|---|
| 511 | if (!($mode & $PRE) && |
|---|
| 512 | !&is_blank($line) && |
|---|
| 513 | ($line_length < $short_line_length) && |
|---|
| 514 | !&is_blank($nextline) && |
|---|
| 515 | !($line_action & ($HEADER | $HRULE | $BREAK | $LIST))) |
|---|
| 516 | { |
|---|
| 517 | $line =~ s/$/<BR>/; |
|---|
| 518 | $line_action |= $BREAK; |
|---|
| 519 | } |
|---|
| 520 | } |
|---|
| 521 | |
|---|
| 522 | sub mailstuff |
|---|
| 523 | { |
|---|
| 524 | if ((($line =~ /^\w*>/) || |
|---|
| 525 | ($line =~ /^\w*\|/))&& |
|---|
| 526 | !&is_blank($nextline)) |
|---|
| 527 | { |
|---|
| 528 | $line =~ s/$/<BR>/; |
|---|
| 529 | $line_action |= $BREAK | $MAILQUOTE; |
|---|
| 530 | } elsif (($line =~ /^[\w\-]*:/) |
|---|
| 531 | && (($previous_action & $MAILHEADER) || &is_blank($prev)) |
|---|
| 532 | && !&is_blank($nextline)) |
|---|
| 533 | { |
|---|
| 534 | &anchor_mail if !($previous_action & $MAILHEADER); |
|---|
| 535 | $line =~ s/$/<BR>/; |
|---|
| 536 | $line_action |= $BREAK | $MAILHEADER; |
|---|
| 537 | } elsif (($line =~ /^\s+\S/) && |
|---|
| 538 | ($previous_action & $MAILHEADER) && |
|---|
| 539 | !&is_blank($nextline)) |
|---|
| 540 | { |
|---|
| 541 | $line =~ s/$/<BR>/; |
|---|
| 542 | $line_action |= $BREAK | $MAILHEADER; |
|---|
| 543 | } |
|---|
| 544 | } |
|---|
| 545 | |
|---|
| 546 | sub paragraph |
|---|
| 547 | { |
|---|
| 548 | $prev .= "<p>\n"; |
|---|
| 549 | $line_action |= $PAR; |
|---|
| 550 | } |
|---|
| 551 | |
|---|
| 552 | sub listprefix |
|---|
| 553 | { |
|---|
| 554 | local($line) = @_; |
|---|
| 555 | local($prefix, $number, $rawprefix); |
|---|
| 556 | |
|---|
| 557 | return (0,0,0) if (!($line =~ /^\s*[-=\*o]\s+\S/ ) && |
|---|
| 558 | !($line =~ /^\s*(\d+|[a-zA-Z])[\.\)\]:]\s+\S/ )); |
|---|
| 559 | |
|---|
| 560 | ($number) = $line =~ /^\s*(\d+|[a-zA-Z])/; |
|---|
| 561 | |
|---|
| 562 | |
|---|
| 563 | |
|---|
| 564 | |
|---|
| 565 | if($line =~ /^\s*o\s/) |
|---|
| 566 | { |
|---|
| 567 | $number = 0; |
|---|
| 568 | } |
|---|
| 569 | |
|---|
| 570 | if ($number) |
|---|
| 571 | { |
|---|
| 572 | ($rawprefix) = $line =~ /^(\s*(\d+|[a-zA-Z]).)/; |
|---|
| 573 | $prefix = $rawprefix; |
|---|
| 574 | $prefix =~ s/(\d+|[a-zA-Z])//; # Take the number out |
|---|
| 575 | } else { |
|---|
| 576 | ($rawprefix) = $line =~ /^(\s*[-=o\*].)/; |
|---|
| 577 | $prefix = $rawprefix; |
|---|
| 578 | } |
|---|
| 579 | ($prefix, $number, $rawprefix); |
|---|
| 580 | } |
|---|
| 581 | |
|---|
| 582 | sub startlist |
|---|
| 583 | { |
|---|
| 584 | local($prefix, $number, $rawprefix) = @_; |
|---|
| 585 | |
|---|
| 586 | $listprefix[$listnum] = $prefix; |
|---|
| 587 | if($number) |
|---|
| 588 | { |
|---|
| 589 | |
|---|
| 590 | if (($number != 1) && ($number ne "a") && ($number ne "A")) |
|---|
| 591 | { |
|---|
| 592 | return; |
|---|
| 593 | } |
|---|
| 594 | $prev .= "$list_indent<OL>\n"; |
|---|
| 595 | $list[$listnum] = $OL; |
|---|
| 596 | } else { |
|---|
| 597 | $prev .= "$list_indent<font size=-2><UL>\n"; |
|---|
| 598 | $list[$listnum] = $UL; |
|---|
| 599 | } |
|---|
| 600 | $listnum++; |
|---|
| 601 | $list_indent = " " x $listnum x $indent_width; |
|---|
| 602 | $line_action |= $LIST; |
|---|
| 603 | $mode |= $LIST; |
|---|
| 604 | } |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | sub endlist |
|---|
| 608 | { |
|---|
| 609 | local($n) = @_; |
|---|
| 610 | for(; $n > 0; $n--, $listnum--) |
|---|
| 611 | { |
|---|
| 612 | $list_indent = " " x ($listnum-1) x $indent_width; |
|---|
| 613 | if($list[$listnum-1] == $UL) |
|---|
| 614 | { |
|---|
| 615 | $prev .= "$list_indent</UL></font>\n"; |
|---|
| 616 | } elsif($list[$listnum-1] == $OL) |
|---|
| 617 | { |
|---|
| 618 | $prev .= "$list_indent</OL>\n"; |
|---|
| 619 | } else |
|---|
| 620 | { |
|---|
| 621 | print STDERR "Encountered list of unknown type\n"; |
|---|
| 622 | } |
|---|
| 623 | } |
|---|
| 624 | $line_action |= $END; |
|---|
| 625 | $mode ^= ($LIST & $mode) if (!$listnum); |
|---|
| 626 | } |
|---|
| 627 | |
|---|
| 628 | sub continuelist |
|---|
| 629 | { |
|---|
| 630 | $line =~ s/^\s*[-=o\*]\s*/$list_indent<LI> / if $list[$listnum-1] == $UL; |
|---|
| 631 | $line =~ s/^\s*(\d+|[a-zA-Z]).\s*/$list_indent<LI> / if $list[$listnum-1 |
|---|
| 632 | ] == $OL; |
|---|
| 633 | $line_action |= $LIST; |
|---|
| 634 | } |
|---|
| 635 | |
|---|
| 636 | sub liststuff |
|---|
| 637 | { |
|---|
| 638 | local($i); |
|---|
| 639 | |
|---|
| 640 | local($prefix, $number, $rawprefix) = &listprefix($line); |
|---|
| 641 | |
|---|
| 642 | $i = $listnum; |
|---|
| 643 | if (!$prefix) |
|---|
| 644 | { |
|---|
| 645 | return if !&is_blank($prev); |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | return if !($mode & $LIST); |
|---|
| 649 | $i = 0; |
|---|
| 650 | } else |
|---|
| 651 | { |
|---|
| 652 | |
|---|
| 653 | $i-- while (($prefix ne $listprefix[$i-1]) && ($i >= 0)); |
|---|
| 654 | } |
|---|
| 655 | |
|---|
| 656 | if (($i >= 0) && ($i != $listnum)) |
|---|
| 657 | { |
|---|
| 658 | &endlist($listnum - $i); |
|---|
| 659 | } elsif (!$listnum || $i != $listnum) |
|---|
| 660 | { |
|---|
| 661 | &startlist($prefix, $number, $rawprefix); |
|---|
| 662 | } |
|---|
| 663 | |
|---|
| 664 | &continuelist($prefix, $number, $rawprefix) if ($mode & $LIST); |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| 667 | sub endpreformat |
|---|
| 668 | { |
|---|
| 669 | if(!($line =~ /\s{$preformat_whitespace_min,}\S+/) && |
|---|
| 670 | ($endpreformat_trigger_lines == 1 || |
|---|
| 671 | !($nextline =~ /\s{$preformat_whitespace_min,}\S+/))) |
|---|
| 672 | { |
|---|
| 673 | $prev =~ s |
|---|
| 674 | $mode ^= ($PRE & $mode); |
|---|
| 675 | $line_action |= $END; |
|---|
| 676 | } |
|---|
| 677 | } |
|---|
| 678 | |
|---|
| 679 | sub preformat |
|---|
| 680 | { |
|---|
| 681 | if($preformat_trigger_lines == 0 || |
|---|
| 682 | (($line =~ /\s{$preformat_whitespace_min,}\S+/) && |
|---|
| 683 | ($preformat_trigger_lines == 1 || |
|---|
| 684 | $nextline =~ /\s{$preformat_whitespace_min,}\S+/))) |
|---|
| 685 | { |
|---|
| 686 | $line =~ s/^/<font size=-1><PRE>\n/; |
|---|
| 687 | $prev =~ s/<p>//; |
|---|
| 688 | $mode |= $PRE; |
|---|
| 689 | $line_action |= $PRE; |
|---|
| 690 | } |
|---|
| 691 | } |
|---|
| 692 | |
|---|
| 693 | sub make_new_anchor |
|---|
| 694 | { |
|---|
| 695 | $anchor++; |
|---|
| 696 | $anchor; |
|---|
| 697 | } |
|---|
| 698 | |
|---|
| 699 | sub anchor_mail |
|---|
| 700 | { |
|---|
| 701 | local($text) = $line =~ /\S+: *(.*) *$/; |
|---|
| 702 | local($anchor) = &make_new_anchor($text); |
|---|
| 703 | $line =~ s/(.*)/<A NAME="$anchor">$1<\/A>/; |
|---|
| 704 | } |
|---|
| 705 | |
|---|
| 706 | sub anchor_heading |
|---|
| 707 | { |
|---|
| 708 | local($heading) = @_; |
|---|
| 709 | local($anchor) = &make_new_anchor($heading); |
|---|
| 710 | $line =~ s/(<H.>.*<\/H.>)/<A NAME="$anchor">$1<\/A>/; |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | sub heading |
|---|
| 714 | { |
|---|
| 715 | local($hindent, $heading) = $line =~ /^(\s*)(.+)$/; |
|---|
| 716 | $hindent = 0; |
|---|
| 717 | |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | |
|---|
| 723 | local($underline) = $nextline =~ /^\s*(\S+)\s*$/; |
|---|
| 724 | |
|---|
| 725 | if((length($heading) > (length($underline) + $underline_tolerance_short)) |
|---|
| 726 | || (length($heading) < (length($underline) -$underline_tolerance_long))) |
|---|
| 727 | { |
|---|
| 728 | return; |
|---|
| 729 | } |
|---|
| 730 | |
|---|
| 731 | |
|---|
| 732 | $underline = substr($underline,0,1); |
|---|
| 733 | |
|---|
| 734 | local($hlevel); |
|---|
| 735 | $hlevel = 1 if $underline eq "*"; |
|---|
| 736 | $hlevel = 2 if $underline eq "="; |
|---|
| 737 | $hlevel = 3 if $underline eq "+"; |
|---|
| 738 | $hlevel = 4 if $underline eq "-"; |
|---|
| 739 | $hlevel = 5 if $underline eq "~"; |
|---|
| 740 | $hlevel = 6 if $underline eq "."; |
|---|
| 741 | return if !$hlevel; |
|---|
| 742 | |
|---|
| 743 | $nextline = <STDIN>; |
|---|
| 744 | &tagline("H${hlevel}"); |
|---|
| 745 | &anchor_heading($heading); |
|---|
| 746 | $line_action |= $HEADER; |
|---|
| 747 | } |
|---|
| 748 | |
|---|
| 749 | sub unhyphenate |
|---|
| 750 | { |
|---|
| 751 | local($second); |
|---|
| 752 | |
|---|
| 753 | |
|---|
| 754 | |
|---|
| 755 | |
|---|
| 756 | |
|---|
| 757 | |
|---|
| 758 | ($second) = $nextline =~ /^\s*([a-zA-Z]+[\)\}\]\.,:;\'\"\>]*\s*)/; |
|---|
| 759 | $nextline =~ s/^(\s*)[a-zA-Z]+[\)\}\]\.,:;\'\"\>]*\s*/$1/; |
|---|
| 760 | |
|---|
| 761 | |
|---|
| 762 | $line =~ s/\-\s*$/$second/; |
|---|
| 763 | $line .= "\n"; |
|---|
| 764 | } |
|---|
| 765 | |
|---|
| 766 | sub untabify |
|---|
| 767 | { |
|---|
| 768 | local($oldws) = $line =~ /^([ \011]+)/; |
|---|
| 769 | local($oldlen) = (length($oldws)); |
|---|
| 770 | |
|---|
| 771 | local($i, $column); |
|---|
| 772 | for($i=0, $column = 0; $i < $oldlen; $i++) |
|---|
| 773 | { |
|---|
| 774 | if(substr($oldws, $i, 1) eq " ") |
|---|
| 775 | { |
|---|
| 776 | $column++; |
|---|
| 777 | } else { |
|---|
| 778 | $column += $tab_width - ($column % $tab_width); |
|---|
| 779 | } |
|---|
| 780 | } |
|---|
| 781 | $line = (" " x $column) . substr($line, $oldlen); |
|---|
| 782 | } |
|---|
| 783 | |
|---|
| 784 | sub tagline |
|---|
| 785 | { |
|---|
| 786 | local($tag) = @_; |
|---|
| 787 | $line =~ s/^\s*(.*)\s*$/<$tag>$1<\/$tag>\n/; |
|---|
| 788 | } |
|---|
| 789 | |
|---|
| 790 | sub caps |
|---|
| 791 | { |
|---|
| 792 | if($line =~ /^[^a-z<]*[A-Z]{$min_caps_length,}[^a-z<]*$/) |
|---|
| 793 | { |
|---|
| 794 | &tagline($caps_tag); |
|---|
| 795 | $line_action |= $CAPS; |
|---|
| 796 | } |
|---|
| 797 | } |
|---|
| 798 | |
|---|
| 799 | |
|---|
| 800 | |
|---|
| 801 | sub main |
|---|
| 802 | { |
|---|
| 803 | &deal_with_options; |
|---|
| 804 | |
|---|
| 805 | if(1) |
|---|
| 806 | { |
|---|
| 807 | print q( |
|---|
| 808 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
|---|
| 809 | "http://www.w3.org/TR/html4/loose.dtd"> |
|---|
| 810 | <html lang="en-US"> |
|---|
| 811 | <head> |
|---|
| 812 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
|---|
| 813 | <meta name="Description" content="ImageMagick - a robust collection of tools and libraries to read, write and manipulate an image in any of the popular image formats. ImageMagick allows dynamic creation of GIFs, making it suitable for Web applications."> |
|---|
| 814 | <meta name="Keywords" content="ImageMagick,Image Magick,Image Magic,PerlMagick,Perl Magick,Perl Magic,WebMagick,Web Magic,image processing,software development,simulation,image software,AniMagick,Animagic,Magick++"> |
|---|
| 815 | <meta name="Resource-type" content="document"> |
|---|
| 816 | <meta name="Robots" content="ALL"> |
|---|
| 817 | <link rel="stylesheet" type="text/css" href="../www/magick.css"> |
|---|
| 818 | </head> |
|---|
| 819 | |
|---|
| 820 | <body marginheight=1 marginwidth=1 topmargin=1 leftmargin=1> |
|---|
| 821 | <a name="top"></a> |
|---|
| 822 | <table border="0" cellpadding="0" cellspacing="0" summary="Masthead" width="100%"> |
|---|
| 823 | <tbody> |
|---|
| 824 | <tr> |
|---|
| 825 | <td bgcolor="#003399" width="25%" height="118" background="../images/background.gif"><a href="http://www.imagemagick.org/"><img src="../images/script.gif" width="278" height="118" border="0" alt="" /></a></td> |
|---|
| 826 | <td bgcolor="#003399" width="60%" height="118" background="../images/background.gif"><a href="http://www.networkeleven.com/direct.php?magick_all"><img src="../images/promote.png" border="0" width="186" height="52" vspace="29" alt="Powered by NetworkEleven" /></a></td> |
|---|
| 827 | <td bgcolor="#003399" width="114" height="118" align="right"><img src="../images/sprite.png" width="114" height="118" alt="" /></td> |
|---|
| 828 | <td bgcolor="#003399" width="114" height="118" align="right"><a href="http://www.imagemagick.net"><img src="../images/logo.png" width="114" height="118" border="0" alt="ImageMagick logo" /></a></td> |
|---|
| 829 | </tr></tbody></table> |
|---|
| 830 | </table><table align="left" border=0 cellpadding=2 cellspacing=2 summary="Navigation buttons" width="20%"> |
|---|
| 831 | <tr> |
|---|
| 832 | <td> |
|---|
| 833 | <form target="_self" action="../index.html"><input type="submit" title="ImageMagick Home" value=" Home " style="background-image:url('../images/background.gif'); color:#fbc713; font-weight:bold"></form> |
|---|
| 834 | </td><td> |
|---|
| 835 | <form target="_self" action="../www/apis.html"><input type="submit" title="ImageMagick API" value=" API " style="background-image:url('../images/background.gif'); color:#fbc713; font-weight:bold"></form> |
|---|
| 836 | </td><td> |
|---|
| 837 | <form target="_self" action="../www/archives.html"><input type="submit" title="ImageMagick Download" value="Download" style="background-image:url('../images/background.gif'); color:#fbc713; font-weight:bold"></form> |
|---|
| 838 | </td> |
|---|
| 839 | </tr> |
|---|
| 840 | </table> |
|---|
| 841 | <div align="right" style="margin-top:3px; padding-right:4px"> |
|---|
| 842 | <form action="http://studio.imagemagick.org/Sage/scripts/Sage.cgi"> |
|---|
| 843 | <input type="TEXT" name="query" size=32 maxlength=255> |
|---|
| 844 | <input type="SUBMIT" name="sa" value="Search" style="background-image:url('../images/background.gif'); bgcolor:#003399; color:#fbc713; font-weight:bold"> |
|---|
| 845 | </form><br> |
|---|
| 846 | </div> |
|---|
| 847 | <table align="left" border=0 cellpadding=10 cellspacing=0 style="margin-top:-17px" width="100%"><tr><td> |
|---|
| 848 | |
|---|
| 849 | <br> <br> |
|---|
| 850 | ) . "\n"; |
|---|
| 851 | print "<HTML>\n"; |
|---|
| 852 | print "<HEAD>\n"; |
|---|
| 853 | |
|---|
| 854 | |
|---|
| 855 | |
|---|
| 856 | print "<TITLE>$title</TITLE>\n" if($title); |
|---|
| 857 | |
|---|
| 858 | print "</HEAD>\n"; |
|---|
| 859 | |
|---|
| 860 | print q(<body text="#000000" bgcolor="#fbc713" link="#1F00FF" vlink="#9900DD" alink="#FF0000">) . "\n"; |
|---|
| 861 | |
|---|
| 862 | if ($title) { |
|---|
| 863 | print "<h3>$title</h3>\n"; |
|---|
| 864 | } |
|---|
| 865 | } |
|---|
| 866 | |
|---|
| 867 | $prev = ""; |
|---|
| 868 | $line = <STDIN>; |
|---|
| 869 | $nextline = <STDIN>; |
|---|
| 870 | do |
|---|
| 871 | { |
|---|
| 872 | $line =~ s/[ \011]*$//; # Chop trailing whitespace |
|---|
| 873 | |
|---|
| 874 | &untabify; |
|---|
| 875 | |
|---|
| 876 | $line_length = length($line); |
|---|
| 877 | |
|---|
| 878 | &escape; |
|---|
| 879 | |
|---|
| 880 | &endpreformat if (($mode & $PRE) && ($preformat_trigger_lines != 0)); |
|---|
| 881 | |
|---|
| 882 | &hrule if !($mode & $PRE); |
|---|
| 883 | |
|---|
| 884 | &heading if (!($mode & $PRE) && |
|---|
| 885 | $nextline =~ /^\s*[=\-\*\.~\+]+$/); |
|---|
| 886 | |
|---|
| 887 | &caps if !($mode & $PRE); |
|---|
| 888 | |
|---|
| 889 | &liststuff if (!($mode & $PRE) && |
|---|
| 890 | !&is_blank($line)); |
|---|
| 891 | |
|---|
| 892 | &mailstuff if ($mailmode && |
|---|
| 893 | !($mode & $PRE) && |
|---|
| 894 | !($line_action & $HEADER)); |
|---|
| 895 | |
|---|
| 896 | &preformat if (!($line_action & ($HEADER | $LIST | $MAILHEADER)) && |
|---|
| 897 | !($mode & ($LIST | $PRE)) && |
|---|
| 898 | ($endpreformat_trigger_lines != 0)); |
|---|
| 899 | |
|---|
| 900 | ¶graph if ((&is_blank($prev) || ($line_action & $END)) && |
|---|
| 901 | !&is_blank($line) && |
|---|
| 902 | !($mode & ($LIST | $PRE)) && |
|---|
| 903 | |
|---|
| 904 | (!$line_action || |
|---|
| 905 | ($line_action & ($CAPS | $END | $MAILQUOTE)))); |
|---|
| 906 | |
|---|
| 907 | &shortline; |
|---|
| 908 | |
|---|
| 909 | &unhyphenate if ($unhyphenation && |
|---|
| 910 | ($line =~ /[a-zA-Z]\-$/) && |
|---|
| 911 | |
|---|
| 912 | ($nextline =~ /^\s*[a-zA-Z]/) && |
|---|
| 913 | !($mode & ($PRE | $HEADER | $MAILHEADER | $BREAK))); |
|---|
| 914 | |
|---|
| 915 | |
|---|
| 916 | |
|---|
| 917 | |
|---|
| 918 | print $prev; |
|---|
| 919 | |
|---|
| 920 | if (!&is_blank($nextline)) |
|---|
| 921 | { |
|---|
| 922 | $previous_action = $line_action; |
|---|
| 923 | $line_action = $NONE; |
|---|
| 924 | } |
|---|
| 925 | |
|---|
| 926 | $prev = $line; |
|---|
| 927 | $line = $nextline; |
|---|
| 928 | $nextline = <STDIN>; |
|---|
| 929 | } until (!$nextline && !$line && !$prev); |
|---|
| 930 | |
|---|
| 931 | $prev = ""; |
|---|
| 932 | &endlist($listnum) if ($mode & $LIST); |
|---|
| 933 | print $prev; |
|---|
| 934 | |
|---|
| 935 | print "\n"; |
|---|
| 936 | |
|---|
| 937 | print "</PRE></font>\n" if ($mode & $PRE); |
|---|
| 938 | |
|---|
| 939 | if ($append_file) |
|---|
| 940 | { |
|---|
| 941 | if(-r $append_file) |
|---|
| 942 | { |
|---|
| 943 | open(APPEND, $append_file); |
|---|
| 944 | print while <APPEND>; |
|---|
| 945 | } else { |
|---|
| 946 | print STDERR "Can't find or read file $append_file to append.\n"; |
|---|
| 947 | } |
|---|
| 948 | } else { |
|---|
| 949 | print q(<hr>) . "\n"; |
|---|
| 950 | print q( |
|---|
| 951 | <a href="#top"><img src="../images/top.gif" border=0 width="35" height="46" align="right" alt="Top of page"></a> |
|---|
| 952 | <form action="http://studio.imagemagick.org/magick/" style="margin-top:5px"> |
|---|
| 953 | <input type="submit" title="Help!" value="Help!" style="background-image:url('../images/background.gif'); color:#fbc713; font-weight:bold"> |
|---|
| 954 | <small>"Image manipulation software that works like magick"</small> |
|---|
| 955 | </form></td> |
|---|
| 956 | </tr></table> |
|---|
| 957 | ) . "\n"; |
|---|
| 958 | } |
|---|
| 959 | |
|---|
| 960 | if(!$extract) |
|---|
| 961 | { |
|---|
| 962 | print "</BODY>\n"; |
|---|
| 963 | print "</HTML>\n"; |
|---|
| 964 | } |
|---|
| 965 | } |
|---|
| 966 | |
|---|
| 967 | &main(); |
|---|
| 968 | |
|---|