2004-06-21 02:20:14 +04:00
|
|
|
/* $NetBSD: msgdb.c,v 1.20 2004/06/20 22:20:16 jmc Exp $ */
|
1997-09-27 01:16:38 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997 Piermont Information Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Philip A. Nelson for Piermont Information Systems Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software develooped for the NetBSD Project by
|
|
|
|
* Piermont Information Systems Inc.
|
|
|
|
* 4. The name of Piermont Information Systems Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* mdb.c - message database manipulation */
|
|
|
|
|
2004-06-21 02:20:14 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-06-23 17:05:47 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
2003-07-17 12:33:03 +04:00
|
|
|
#if defined(__RCSID) && !defined(lint)
|
2004-06-21 02:20:14 +04:00
|
|
|
__RCSID("$NetBSD: msgdb.c,v 1.20 2004/06/20 22:20:16 jmc Exp $");
|
2003-06-23 17:05:47 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1997-09-27 01:16:38 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1997-10-03 20:37:25 +04:00
|
|
|
#include <string.h>
|
|
|
|
|
1997-09-27 01:16:38 +04:00
|
|
|
#include "defs.h"
|
2001-10-16 02:11:12 +04:00
|
|
|
#include "pathnames.h"
|
1997-09-27 01:16:38 +04:00
|
|
|
|
|
|
|
static struct id_rec *head = NULL, *tail = NULL;
|
2003-06-10 21:24:17 +04:00
|
|
|
static int msg_no = 1;
|
1997-09-27 01:16:38 +04:00
|
|
|
|
|
|
|
void define_msg (char *name, char *value)
|
|
|
|
{
|
|
|
|
struct id_rec *tmp = (struct id_rec *)malloc(sizeof(struct id_rec));
|
|
|
|
|
|
|
|
if (find_id (root, name))
|
|
|
|
yyerror ("%s is defined twice", name);
|
|
|
|
|
|
|
|
tmp->id = name;
|
|
|
|
tmp->msg = value;
|
|
|
|
tmp->msg_no = msg_no++;
|
|
|
|
tmp->next = NULL;
|
|
|
|
if (tail == NULL)
|
|
|
|
head = tail = tmp;
|
|
|
|
else {
|
|
|
|
tail->next = tmp;
|
|
|
|
tail = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
insert_id (&root, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_str (FILE *f, char *str)
|
|
|
|
{
|
|
|
|
(void)fprintf (f, "\"");
|
|
|
|
while (*str) {
|
|
|
|
if (*str == '\n')
|
|
|
|
(void) fprintf (f, "\\n\"\n\""), str++;
|
|
|
|
else if (*str == '"')
|
|
|
|
(void) fprintf (f, "\\\""), str++;
|
|
|
|
else
|
|
|
|
(void) fprintf (f, "%c", *str++);
|
|
|
|
}
|
|
|
|
(void)fprintf (f, "\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write out the msg files. */
|
|
|
|
void
|
|
|
|
write_msg_file ()
|
|
|
|
{
|
|
|
|
FILE *out_file;
|
|
|
|
FILE *sys_file;
|
|
|
|
char hname[1024];
|
|
|
|
char cname[1024];
|
|
|
|
char sname[1024];
|
|
|
|
char *sys_prefix;
|
|
|
|
|
|
|
|
int nlen;
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
struct id_rec *t;
|
|
|
|
|
|
|
|
/* Generate file names */
|
|
|
|
snprintf (hname, 1024, "%s.h", out_name);
|
|
|
|
nlen = strlen(hname);
|
|
|
|
if (hname[nlen-2] != '.' || hname[nlen-1] != 'h') {
|
|
|
|
(void) fprintf (stderr, "%s: name `%s` too long.\n",
|
|
|
|
prog_name, out_name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
snprintf (cname, 1024, "%s.c", out_name);
|
|
|
|
|
|
|
|
/* Open the msg_sys file first. */
|
|
|
|
sys_prefix = getenv ("MSGDEF");
|
|
|
|
if (sys_prefix == NULL)
|
2001-10-16 02:11:12 +04:00
|
|
|
sys_prefix = _PATH_DEFSYSPREFIX;
|
1997-09-27 01:16:38 +04:00
|
|
|
snprintf (sname, 1024, "%s/%s", sys_prefix, sys_name);
|
|
|
|
sys_file = fopen (sname, "r");
|
|
|
|
if (sys_file == NULL) {
|
|
|
|
(void) fprintf (stderr, "%s: could not open %s.\n",
|
|
|
|
prog_name, sname);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Output the .h file first. */
|
|
|
|
out_file = fopen (hname, "w");
|
|
|
|
if (out_file == NULL) {
|
|
|
|
(void) fprintf (stderr, "%s: could not open %s.\n",
|
|
|
|
prog_name, hname);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write it */
|
|
|
|
(void) fprintf (out_file, "%s",
|
|
|
|
"/* msg system definitions. */\n"
|
|
|
|
"\n"
|
|
|
|
"#ifndef MSG_DEFS_H\n"
|
|
|
|
"#define MSG_DEFS_H\n"
|
|
|
|
"#include <stdio.h>\n"
|
1999-06-19 23:25:10 +04:00
|
|
|
"#include <stdlib.h>\n"
|
2003-06-28 02:11:59 +04:00
|
|
|
"#include <unistd.h>\n"
|
|
|
|
"#include <fcntl.h>\n"
|
1997-09-27 01:16:38 +04:00
|
|
|
"#include <string.h>\n"
|
|
|
|
"#include <ctype.h>\n"
|
|
|
|
"#include <stdarg.h>\n"
|
2003-01-10 23:00:50 +03:00
|
|
|
"#include <stdint.h>\n"
|
1997-09-27 01:16:38 +04:00
|
|
|
"#include <curses.h>\n"
|
2003-06-28 02:11:59 +04:00
|
|
|
"#include <sys/mman.h>\n"
|
1997-09-27 01:16:38 +04:00
|
|
|
"\n"
|
1999-07-05 01:30:14 +04:00
|
|
|
"typedef const char *msg;\n"
|
|
|
|
"\n"
|
1997-09-27 01:16:38 +04:00
|
|
|
"/* Prototypes */\n"
|
2003-06-10 21:24:17 +04:00
|
|
|
"WINDOW *msg_window(WINDOW *window);\n"
|
2003-06-28 02:11:59 +04:00
|
|
|
"const char *msg_string(msg msg_no);\n"
|
|
|
|
"int msg_file(const char *);\n"
|
1997-09-27 01:16:38 +04:00
|
|
|
"void msg_clear(void);\n"
|
|
|
|
"void msg_standout(void);\n"
|
|
|
|
"void msg_standend(void);\n"
|
1999-07-05 01:30:14 +04:00
|
|
|
"void msg_display(msg msg_no,...);\n"
|
|
|
|
"void msg_display_add(msg msg_no,...);\n"
|
|
|
|
"void msg_prompt (msg msg_no, const char *def,"
|
2003-01-10 23:00:50 +03:00
|
|
|
" char *val, size_t max_chars, ...);\n"
|
1999-07-05 01:30:14 +04:00
|
|
|
"void msg_prompt_add (msg msg_no, const char *def,"
|
2003-01-10 23:00:50 +03:00
|
|
|
" char *val, size_t max_chars, ...);\n"
|
1999-07-05 01:30:14 +04:00
|
|
|
"void msg_prompt_noecho (msg msg_no, const char *def,"
|
2003-01-10 23:00:50 +03:00
|
|
|
" char *val, size_t max_chars, ...);\n"
|
2003-06-10 21:24:17 +04:00
|
|
|
"void msg_prompt_win (msg, int, int, int, int,"
|
2003-06-04 23:00:26 +04:00
|
|
|
" const char *, char *, size_t, ...);\n"
|
1999-07-05 01:30:14 +04:00
|
|
|
"void msg_table_add(msg msg_no,...);\n"
|
2003-09-25 22:32:10 +04:00
|
|
|
"int msg_row(void);\n"
|
1997-09-27 01:16:38 +04:00
|
|
|
"\n"
|
|
|
|
"/* Message names */\n"
|
|
|
|
);
|
1999-07-05 01:30:14 +04:00
|
|
|
(void) fprintf (out_file, "#define MSG_NONE\tNULL\n");
|
1997-09-27 01:16:38 +04:00
|
|
|
for (t=head; t != NULL; t = t->next) {
|
1999-07-05 01:30:14 +04:00
|
|
|
(void) fprintf (out_file, "#define MSG_%s\t((msg)(long)%d)\n",
|
1997-09-27 01:16:38 +04:00
|
|
|
t->id, t->msg_no);
|
|
|
|
}
|
1999-06-22 19:00:37 +04:00
|
|
|
(void) fprintf (out_file, "\n#endif\n");
|
1997-09-27 01:16:38 +04:00
|
|
|
|
|
|
|
fclose (out_file);
|
|
|
|
|
|
|
|
/* Now the C file */
|
|
|
|
out_file = fopen (cname, "w");
|
|
|
|
if (out_file == NULL) {
|
|
|
|
(void) fprintf (stderr, "%s: could not open %s.\n",
|
|
|
|
prog_name, cname);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hfile include ... */
|
|
|
|
(void)fprintf (out_file, "#include \"%s\"\n", hname);
|
|
|
|
|
|
|
|
/* msg_list */
|
2003-06-10 21:24:17 +04:00
|
|
|
(void)fprintf (out_file, "const char *msg_list[] = {\nNULL,\n");
|
1997-09-27 01:16:38 +04:00
|
|
|
for (t=head ; t != NULL; t = t->next)
|
|
|
|
write_str (out_file, t->msg);
|
|
|
|
(void)fprintf (out_file, "NULL};\n");
|
|
|
|
|
|
|
|
/* sys file out! */
|
|
|
|
while ((ch = fgetc(sys_file)) != EOF)
|
|
|
|
fputc(ch, out_file);
|
|
|
|
|
|
|
|
fclose (out_file);
|
|
|
|
fclose (sys_file);
|
|
|
|
}
|