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 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
|
/* webfmt.c -- Project Gutenberg Webster converter
* Created: Sun Mar 16 09:29:39 1997 by faith@cs.unc.edu
* Revised: Sun Feb 22 09:27:45 1998 by faith@acm.org
* Copyright 1997, 1998 Rickard E. Faith (faith@acm.org)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 1, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: webfmt.c,v 1.5 1998/02/22 15:14:58 faith Exp $
*
*/
#include "webfmt.h"
#include "parse.h"
#include <sys/utsname.h>
extern int yy_flex_debug;
int database = 0;
static const char *id_string( const char *id )
{
static char buffer[256];
arg_List a = arg_argify( id, 0 );
if (arg_count(a) >= 2)
sprintf( buffer, "%s", arg_get( a, 2 ) );
else
buffer[0] = '\0';
arg_destroy( a );
return buffer;
}
static const char *pgw_get_banner( void )
{
static char *buffer= NULL;
const char *id = "$Id: webfmt.c,v 1.5 1998/02/22 15:14:58 faith Exp $";
struct utsname uts;
if (buffer) return buffer;
uname( &uts );
buffer = xmalloc(256);
sprintf( buffer,
"%s %s (%s %s)", err_program_name(), id_string( id ),
uts.sysname,
uts.release );
return buffer;
}
static void banner( void )
{
fprintf( stderr, "%s\n", pgw_get_banner() );
fprintf( stderr,
"Copyright 1997 Rickard E. Faith (faith@cs.unc.edu)\n" );
}
static void license( void )
{
static const char *license_msg[] = {
"",
"This program is free software; you can redistribute it and/or modify it",
"under the terms of the GNU General Public License as published by the",
"Free Software Foundation; either version 1, or (at your option) any",
"later version.",
"",
"This program is distributed in the hope that it will be useful, but",
"WITHOUT ANY WARRANTY; without even the implied warranty of",
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU",
"General Public License for more details.",
"",
"You should have received a copy of the GNU General Public License along",
"with this program; if not, write to the Free Software Foundation, Inc.,",
"675 Mass Ave, Cambridge, MA 02139, USA.",
};
const char **p = license_msg;
banner();
while (*p) fprintf( stderr, " %s\n", *p++ );
}
static void help( void )
{
static const char *help_msg[] = {
"-h --help give this help",
"-L --license display software license",
"-v --verbose verbose mode",
"-V --version display version number",
"-d --debug <option> select debug option",
"-c GCIDE",
0 };
const char **p = help_msg;
banner();
while (*p) fprintf( stderr, "%s\n", *p++ );
}
int main( int argc, char **argv )
{
int c;
struct option longopts[] = {
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ "debug", 1, 0, 'd' },
{ "help", 0, 0, 'h' },
{ "license", 0, 0, 'L' },
{ "gcide", 0, 0, 'c' },
{ 0, 0, 0, 0 }
};
maa_init(argv[0]);
dbg_register(DBG_VERBOSE, "verbose");
dbg_register(DBG_PARSE, "parse");
dbg_register(DBG_SCAN, "scan");
dbg_register(DBG_NEWLINE, "newline");
while ((c = getopt_long( argc, argv,
"vVd:hLc", longopts, NULL )) != EOF)
switch (c) {
case 'v': dbg_set( "verbose" ); break;
case 'V': banner(); exit(1); break;
case 'd': dbg_set( optarg ); break;
case 'L': license(); exit(1); break;
case 'c': database = 1; break;
case 'h':
default: help(); exit(1); break;
}
if (dbg_test(DBG_PARSE)) prs_set_debug(1);
if (dbg_test(DBG_SCAN)) yy_flex_debug = 1;
else yy_flex_debug = 0;
if (database == 1) fmt_open(dbg_test(DBG_VERBOSE) ? NULL : "gcide");
else fmt_open(dbg_test(DBG_VERBOSE) ? NULL : "web1913");
prs_stream( stdin, "[stdin]" );
fmt_close();
return 0;
}
|