| 1 |
/* $Id$ */ |
| 2 |
/* |
| 3 |
* Copyright (c) 1993-1996 Sam Leffler |
| 4 |
* Copyright (c) 1993-1996 Silicon Graphics, Inc. |
| 5 |
* HylaFAX is a trademark of Silicon Graphics |
| 6 |
* |
| 7 |
* Permission to use, copy, modify, distribute, and sell this software and |
| 8 |
* its documentation for any purpose is hereby granted without fee, provided |
| 9 |
* that (i) the above copyright notices and this permission notice appear in |
| 10 |
* all copies of the software and related documentation, and (ii) the names of |
| 11 |
* Sam Leffler and Silicon Graphics may not be used in any advertising or |
| 12 |
* publicity relating to the software without the specific, prior written |
| 13 |
* permission of Sam Leffler and Silicon Graphics. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, |
| 16 |
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY |
| 17 |
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. |
| 18 |
* |
| 19 |
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR |
| 20 |
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, |
| 21 |
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
| 22 |
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF |
| 23 |
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 24 |
* OF THIS SOFTWARE. |
| 25 |
*/ |
| 26 |
|
| 27 |
/* |
| 28 |
* A sort of enscript clone... |
| 29 |
*/ |
| 30 |
#include "TextFormat.h" |
| 31 |
#include "Sys.h" |
| 32 |
#include "config.h" |
| 33 |
|
| 34 |
#if HAS_LOCALE |
| 35 |
extern "C" { |
| 36 |
#include <locale.h> |
| 37 |
} |
| 38 |
#endif |
| 39 |
|
| 40 |
static const char* prog; |
| 41 |
|
| 42 |
static void |
| 43 |
usage() |
| 44 |
{ |
| 45 |
fprintf(stderr, _("Usage: %s" |
| 46 |
" [-1]" |
| 47 |
" [-2]" |
| 48 |
" [-B]" |
| 49 |
" [-c]" |
| 50 |
" [-D]" |
| 51 |
" [-f fontname]" |
| 52 |
" [-F fontdir(s)]" |
| 53 |
" [-m N]" |
| 54 |
" [-o #]" |
| 55 |
" [-p #]" |
| 56 |
" [-r]" |
| 57 |
" [-U]" |
| 58 |
" [-Ml=#,r=#,t=#,b=#]" |
| 59 |
" [-V #]" |
| 60 |
" files... >out.ps\n"), prog); |
| 61 |
fprintf(stderr, _("Default options:" |
| 62 |
" -f Courier" |
| 63 |
" -1" |
| 64 |
" -p 11bp" |
| 65 |
" -o 0" |
| 66 |
"\n")); |
| 67 |
exit(1); |
| 68 |
} |
| 69 |
|
| 70 |
int |
| 71 |
main(int argc, char* argv[]) |
| 72 |
{ |
| 73 |
extern int optind; |
| 74 |
extern char* optarg; |
| 75 |
int c; |
| 76 |
|
| 77 |
#ifdef LC_CTYPE |
| 78 |
setlocale(LC_CTYPE, ""); // for <ctype.h> calls |
| 79 |
#endif |
| 80 |
#ifdef LC_TIME |
| 81 |
setlocale(LC_TIME, ""); // for strftime calls |
| 82 |
#endif |
| 83 |
|
| 84 |
TextFormat fmt; |
| 85 |
|
| 86 |
fmt.resetConfig(); |
| 87 |
fmt.readConfig(FAX_SYSCONF); |
| 88 |
fmt.readConfig(FAX_USERCONF); |
| 89 |
|
| 90 |
prog = argv[0]; |
| 91 |
while ((c = Sys::getopt(argc, argv, "f:F:m:M:o:p:s:V:12BcDGrRU")) != -1) |
| 92 |
switch(c) { |
| 93 |
case '1': // 1-column output |
| 94 |
case '2': // 2-column output |
| 95 |
fmt.setNumberOfColumns(c - '0'); |
| 96 |
break; |
| 97 |
case 'B': |
| 98 |
fmt.setPageHeaders(false); |
| 99 |
break; |
| 100 |
case 'c': // clip/cut instead of wrapping lines |
| 101 |
fmt.setLineWrapping(false); |
| 102 |
break; |
| 103 |
case 'D': // don't use ISO 8859-1 encoding |
| 104 |
fmt.setISO8859(false); |
| 105 |
break; |
| 106 |
case 'f': // body font |
| 107 |
if (!fmt.setTextFont(optarg)) { |
| 108 |
fprintf(stderr, |
| 109 |
_("%s: No font metric information found for \"%s\".\n"), |
| 110 |
prog, optarg); |
| 111 |
usage(); |
| 112 |
} |
| 113 |
break; |
| 114 |
case 'F': // set Font path |
| 115 |
fmt.setFontPath(optarg); |
| 116 |
break; |
| 117 |
case 'G': // gaudy mode |
| 118 |
fmt.setGaudyHeaders(true); |
| 119 |
break; |
| 120 |
case 'm': // multi-column output |
| 121 |
fmt.setNumberOfColumns(atoi(optarg)); |
| 122 |
break; |
| 123 |
case 'M': // margin(s) |
| 124 |
if (!fmt.setPageMargins(optarg)) { |
| 125 |
fprintf(stderr, _("Bad margin syntax.\n")); |
| 126 |
usage(); |
| 127 |
} |
| 128 |
break; |
| 129 |
case 'o': // outline columns |
| 130 |
fmt.setOutlineMargin(TextFormat::inch(optarg)); |
| 131 |
break; |
| 132 |
case 'p': // text point size |
| 133 |
fmt.setTextPointSize(TextFormat::inch(optarg)); |
| 134 |
break; |
| 135 |
case 'r': // rotate page (landscape) |
| 136 |
fmt.setPageOrientation(TextFormat::LANDSCAPE); |
| 137 |
break; |
| 138 |
case 'R': // don't rotate page (portrait) |
| 139 |
fmt.setPageOrientation(TextFormat::PORTRAIT); |
| 140 |
break; |
| 141 |
case 's': // page size |
| 142 |
if (!fmt.setPageSize(optarg)) { |
| 143 |
fprintf(stderr, _("Unknown page size %s.\n"), optarg); |
| 144 |
usage(); |
| 145 |
} |
| 146 |
break; |
| 147 |
case 'U': // reverse page collation |
| 148 |
fmt.setPageCollation(TextFormat::REVERSE); |
| 149 |
break; |
| 150 |
case 'V': // vertical line height+spacing |
| 151 |
fmt.setTextLineHeight(TextFormat::inch(optarg)); |
| 152 |
break; |
| 153 |
default: |
| 154 |
fprintf(stderr, _("Unrecognized option \"%c\".\n"), c); |
| 155 |
usage(); |
| 156 |
} |
| 157 |
#ifdef notdef |
| 158 |
fmt.setTitle(); |
| 159 |
#endif |
| 160 |
fmt.beginFormatting(stdout); |
| 161 |
if (optind < argc) { |
| 162 |
for (; optind < argc; optind++) { |
| 163 |
struct stat sb; |
| 164 |
if (Sys::stat(argv[optind], sb) >= 0) |
| 165 |
fmt.setModTimeAndDate((time_t) sb.st_mtime); |
| 166 |
fmt.formatFile(argv[optind]); |
| 167 |
} |
| 168 |
} else { |
| 169 |
fmt.setFilename("<stdin>"); |
| 170 |
fmt.setModTimeAndDate(Sys::now()); |
| 171 |
fmt.formatFile(stdin); |
| 172 |
} |
| 173 |
fmt.endFormatting(); |
| 174 |
return (0); |
| 175 |
} |