Add run-time selection of installation language.

Make 'doingwhat' an argument to find_disks() instead of a global.
This commit is contained in:
dsl 2003-06-27 22:20:14 +00:00
parent e2724ab4be
commit 16a2d1e961
17 changed files with 304 additions and 39 deletions

View File

@ -1,10 +1,13 @@
# $NetBSD: Makefile.inc,v 1.22 2003/06/27 13:36:04 dsl Exp $
# $NetBSD: Makefile.inc,v 1.23 2003/06/27 22:20:14 dsl Exp $
#
# Makefile for sysinst
PROG= sysinst
NOMAN= # defined
SYSINSTLANG?= en
LANGUAGES?= en fr pl
MSG_MD?= msg.md.${SYSINSTLANG}
MENUS_MD?= menus.md.${SYSINSTLANG}
@ -15,6 +18,7 @@ LDADD= -lcurses -ltermcap -lutil
LDSTATIC?= -static
UNIF_AWK= ${.CURDIR}/../../unif.awk
MSG_XLAT_SH= ${.CURDIR}/../../msg_xlat.sh
VERDEP= ${NETBSDSRCDIR}/sys/conf/osrelease.sh
VER!= sh ${VERDEP}
@ -52,9 +56,8 @@ CPPFLAGS+= -DSYSINST_CDROM_DIR=\"${SYSINST_CDROM_DIR}\"
WARNS= 1
CLEANFILES= menu_defs.c menu_defs.h menus.def \
msg_defs.c msg_defs.h msg.def msgtouch
SYSINSTLANG?= en
msg_defs.c msg_defs.h msg.def msgtouch \
sysinstmsgs.*
.PATH: ${.CURDIR}/../..
@ -83,6 +86,17 @@ menus.def: menus.mi ${MENUS_MD} msgtouch
menu_defs.c: msg_defs.h
.for LANG in ${LANGUAGES}
# .if ${LANG} != ${SYSINSTLANG}
sysinstmsgs.${LANG}: msg.mi.${LANG} ${MSG_MD:S/.${SYSINSTLANG}$/.${LANG}/} msgtouch msg_defs.h
sed "s/@@VERSION@@/${VER}/" ${.ALLSRC:M*.${LANG}} | \
awk -f ${UNIF_AWK} -v defines="${MD_OPTIONS}" | \
sh ${MSG_XLAT_SH} > ${.TARGET}
${PROG}: sysinstmsgs.${LANG}
# .endif
.endfor
XOBJS:=${SRCS:M*.c:R:O:S/$/.o/g}
${XOBJS}: msg_defs.h menu_defs.h

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.4 2003/06/12 11:20:04 dsl Exp $
# $NetBSD: Makefile,v 1.5 2003/06/27 22:20:17 dsl Exp $
#
# Makefile for i386
#
@ -9,4 +9,6 @@ SRCS= menu_defs.c msg_defs.c main.c install.c upgrade.c \
txtwalk.c run.c factor.c net.c disks.c disks_lfs.c util.c geom.c \
label.c target.c md.c sizemultname.c
LANGUAGES= en fr
.include "../../Makefile.inc"

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.6 2003/06/12 11:20:04 dsl Exp $
# $NetBSD: Makefile,v 1.7 2003/06/27 22:20:17 dsl Exp $
#
# Makefile for atari
#
@ -11,5 +11,6 @@ SRCS= menu_defs.c msg_defs.c main.c install.c upgrade.c \
bsddisklabel.c
MD_OPTIONS= AOUT2ELF
LANGUAGES= en
.include "../../Makefile.inc"

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.5 2003/06/12 11:20:08 dsl Exp $
# $NetBSD: Makefile,v 1.6 2003/06/27 22:20:18 dsl Exp $
#
# Makefile for mac68k
#
@ -10,5 +10,6 @@ SRCS= menu_defs.c msg_defs.c main.c install.c upgrade.c \
label.c target.c md.c aout2elf.c sizemultname.c
MD_OPTIONS= AOUT2ELF
LANGUAGES= en pl
.include "../../Makefile.inc"

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.5 2003/06/12 11:20:11 dsl Exp $
# $NetBSD: Makefile,v 1.6 2003/06/27 22:20:18 dsl Exp $
#
# Makefile for prep
#
@ -12,5 +12,6 @@ SRCS= menu_defs.c msg_defs.c main.c install.c upgrade.c \
MENUS_MD= menus.md.${SYSINSTLANG} menus.mbr
MSG_MD= msg.md.${SYSINSTLANG} msg.mbr.${SYSINSTLANG}
LANGUAGES= en pl
.include "../../Makefile.inc"

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.7 2003/06/12 11:20:15 dsl Exp $
# $NetBSD: Makefile,v 1.8 2003/06/27 22:20:18 dsl Exp $
#
# Makefile for x68k
#
@ -10,7 +10,9 @@ SRCS= menu_defs.c msg_defs.c main.c install.c upgrade.c \
label.c target.c md.c savenewlabel.c sizemultname.c \
bsddisklabel.c
.include "../../Makefile.inc"
# Note: we have no french messages, because x68k console does not
# support ISO-8859-1 (right half) character set.
LANGUAGES= en pl
.include "../../Makefile.inc"

View File

@ -1,4 +1,4 @@
/* $NetBSD: defs.h,v 1.92 2003/06/25 15:45:21 dsl Exp $ */
/* $NetBSD: defs.h,v 1.93 2003/06/27 22:20:14 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -157,7 +157,6 @@ EXTERN pid_t ttysig_forward;
EXTERN int layoutkind;
EXTERN int sizemult INIT(1);
EXTERN const char *multname;
EXTERN const char *doingwhat;
EXTERN const char *shellpath;
/* loging variables */
@ -322,7 +321,7 @@ void md_set_no_x(void);
void toplevel(void);
/* from disks.c */
int find_disks(void);
int find_disks(const char *);
void fmt_fspart(char *, size_t, int);
void disp_cur_fspart(int, int);
int write_disklabel(void);

View File

@ -1,4 +1,4 @@
/* $NetBSD: disks.c,v 1.60 2003/06/16 20:10:02 dsl Exp $ */
/* $NetBSD: disks.c,v 1.61 2003/06/27 22:20:15 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -120,7 +120,7 @@ get_disks(void)
int
find_disks(void)
find_disks(const char *doingwhat)
{
char *tp;
const char *prompt;

View File

@ -1,4 +1,4 @@
/* $NetBSD: install.c,v 1.35 2003/06/25 15:45:22 dsl Exp $ */
/* $NetBSD: install.c,v 1.36 2003/06/27 22:20:15 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -49,7 +49,6 @@
void
do_install(void)
{
doingwhat = msg_string(MSG_install);
msg_display(MSG_installusure);
process_menu(MENU_noyes, NULL);
@ -58,7 +57,7 @@ do_install(void)
get_ramsize();
if (find_disks() < 0)
if (find_disks(msg_string(MSG_install)) < 0)
return;
if (check_swap(diskdev, 0) > 0) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.35 2003/06/25 15:45:22 dsl Exp $ */
/* $NetBSD: main.c,v 1.36 2003/06/27 22:20:15 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -46,6 +46,7 @@
#include <curses.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#define MAIN
#include "defs.h"
@ -55,6 +56,7 @@
#include "txtwalk.h"
int main(int, char **);
static void select_language(void);
static void usage(void);
static void miscsighandler(int);
static void ttysighandler(int);
@ -150,13 +152,110 @@ main(int argc, char **argv)
touchwin(stdscr);
refresh();
select_language();
/* Menu processing */
process_menu(MENU_netbsd, NULL);
exit_cleanly = 1;
return 0;
}
static int
set_language(menudesc *m, menu_ent *e, void *arg)
{
char **fnames = arg;
msg_file(fnames[e - m->opts]);
return 1;
}
static void
select_language(void)
{
DIR *dir;
struct dirent *dirent;
char **lang_msg, **fnames;
int max_lang = 16, num_lang = 0;
const char *cp;
menu_ent *opt = 0;
int lang_menu = -1;
int lang;
dir = opendir(".");
if (!dir)
return;
lang_msg = malloc(max_lang * sizeof *lang_msg);
fnames = malloc(max_lang * sizeof *fnames);
if (!lang_msg || !fnames)
goto done;
lang_msg[0] = strdup(msg_string(MSG_sysinst_message_language));
fnames[0] = 0;
num_lang = 1;
while ((dirent = readdir(dir)) != 0) {
if (memcmp(dirent->d_name, "sysinstmsgs.", 12))
continue;
if (msg_file(dirent->d_name))
continue;
cp = msg_string(MSG_sysinst_message_language);
if (!strcmp(cp, lang_msg[0]))
continue;
if (num_lang == max_lang) {
char **new;
max_lang *= 2;
new = realloc(lang_msg, max_lang * sizeof *lang_msg);
if (!new)
break;
lang_msg = new;
new = realloc(fnames, max_lang * sizeof *fnames);
if (!new)
break;
fnames = new;
}
fnames[num_lang] = strdup(dirent->d_name);
lang_msg[num_lang++] = strdup(cp);
}
msg_file(0);
closedir(dir);
dir = 0;
if (num_lang == 1)
goto done;
opt = calloc(num_lang, sizeof *opt);
if (!opt)
goto done;
for (lang = 0; lang < num_lang; lang++) {
opt[lang].opt_name = lang_msg[lang];
opt[lang].opt_menu = OPT_NOMENU;
opt[lang].opt_action = set_language;
}
lang_menu = new_menu(NULL, opt, num_lang, -1, 12, 0, 0, MC_NOEXITOPT,
NULL, NULL, NULL, NULL);
if (lang_menu != -1) {
msg_display(MSG_hello);
process_menu(lang_menu, fnames);
}
done:
if (dir)
closedir(dir);
if (lang_menu != -1)
free_menu(lang_menu);
free(opt);
while (num_lang) {
free(lang_msg[--num_lang]);
free(fnames[num_lang]);
}
free(lang_msg);
free(fnames);
}
/* toplevel menu handler ... */
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg.mbr.fr,v 1.5 2003/06/16 20:12:44 dsl Exp $ */
/* $NetBSD: msg.mbr.fr,v 1.6 2003/06/27 22:20:15 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -134,9 +134,11 @@ message ovrwrite
vraiment l'écraser par une partition NetBSD ?
}
.if 0
message parttable
{La table des partitions de votre disque est :
}
.endif
message editpart
{La partition %d ressemble à:

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg.mbr.pl,v 1.4 2003/06/14 12:58:45 dsl Exp $ */
/* $NetBSD: msg.mbr.pl,v 1.5 2003/06/27 22:20:15 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -130,9 +130,11 @@ message ovrwrite
nadpisac z NetBSD?
}
.if 0
message parttable
{Aktualnie tablica partycji na twoim dysku wyglada tak:
}
.endif
message editpart
{Edytujesz partycje %d. Podswietlona partycja to ta, ktora edytujesz.
@ -215,7 +217,7 @@ message dofdisk
}
message wmbrfail
{Nadpisanie MBR nie powiodlo sie. Nie moge kontynuowac.}
{Nadpisanie MBR nie powiodlo sie. Nie moge kontynuowac.}
.if BOOTSEL
message installbootsel

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg.mi.en,v 1.108 2003/06/27 13:36:06 dsl Exp $ */
/* $NetBSD: msg.mi.en,v 1.109 2003/06/27 22:20:15 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -42,6 +42,9 @@ message usage
{usage: sysinst [-r release] [-f definition-file]
}
message sysinst_message_language
{Installation messages in English}
message newline {\n}
message Yes {Yes}

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg.mi.fr,v 1.58 2003/06/27 13:36:06 dsl Exp $ */
/* $NetBSD: msg.mi.fr,v 1.59 2003/06/27 22:20:16 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -42,6 +42,9 @@ message usage
{utilisation : sysinst [-r version] [-f fichier de definition]
}
message sysinst_message_language
{Installation messages in French} /* XXX translate */
message newline {\n}
message Yes {Oui}
@ -620,9 +623,6 @@ message net_domain
message net_host
{Votre nom de machine}
message net_ip6autoconf
{Autoconfiguration IPv6}
message net_ip
{Votre adresse IPv4}
@ -728,10 +728,6 @@ Vous allez devoir proc
differente pour les composants et essayer à nouveau.
}
message openmsgbuf
{Impossible d'ouvrir /kern/msgbuf.
}
message createfstab
{Erreur fatale ! Impossible de créer /mnt/etc/fstab.
Nous devons quitter immédiatement !

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg.mi.pl,v 1.20 2003/06/27 13:36:06 dsl Exp $ */
/* $NetBSD: msg.mi.pl,v 1.21 2003/06/27 22:20:16 dsl Exp $ */
/* Based on english version: */
/* NetBSD: msg.mi.en,v 1.86 2002/04/04 14:26:44 ad Exp */
@ -44,6 +44,9 @@ message usage
{uzycie: sysinst [-r wersja] [-f plik-definicji]
}
message sysinst_message_language
{Installation messages in Polish} /* XXX translate */
message newline {\n}
message Yes {Tak}

143
distrib/utils/sysinst/msg_xlat.sh Executable file
View File

@ -0,0 +1,143 @@
#! /bin/sh
# $NetBSD: msg_xlat.sh,v 1.1 2003/06/27 22:20:16 dsl Exp $
#-
# Copyright (c) 2003 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by David Laight.
#
# 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 developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``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 THE FOUNDATION OR CONTRIBUTORS
# 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.
#
nl="
"
# Read header file and set up map of message names to numbers
exec 3<&0 <msg_defs.h
while read define MSG_name number rest
do
[ -z "$number" -o -n "$rest" ] && continue
[ "$define" = "#define" ] || continue
name="${MSG_name#MSG_}"
[ "$name" = "${MSG_name}" ] && continue
msg_number="${number#((msg)(long)}"
[ "$msg_number" = "$number" ] && continue
msg_number="${msg_number%)}"
eval $MSG_name=$msg_number
eval MSGNUM_$msg_number=\$MSG_name
# eval echo \$$MSG_name \$MSGNUM_$msg_number
done
last_msg_number="$msg_number"
# Read message definition file and set up map of munbers to strings
exec <&3 3<&-
name=
msg=
OIFS="$IFS"
while
IFS=
read -r line
do
[ -z "$name" ] && {
IFS=" "
set -- $line
[ "$1" = message ] || continue
name="$2"
eval number=\$MSG_$name
[ -z "$number" ] && {
echo "unknown text \"$name\"" >&2
number=unknown
}
l=${line#*\{}
[ "$l" = "$line" ] && continue
line="{$l"
}
[ -z "$msg" ] && {
l="${line#\{}"
[ "$l" = "$line" ] && continue
msg="$line"
} || msg="$msg$nl$line"
m="${msg%\}}"
[ "$m" = "$msg" ] && {
# Allow <tab>*/* comment */ (eg XXX translate)
m="${msg%%\}*/\**\*/}"
[ "$m" = "$msg" ] &&
continue
}
# We need the %b to expand the \n that exist in the message file
msg="$(printf "%bz" "${m#\{}")"
msg="${msg%z}"
eval MSGTEXT_$number=\"\${msg}\"
# echo $number $msg
name=
msg=
done
# Output the total number of messages and the offset of each in the file.
# Use ascii numbers because generating target-ordered binary numbers
# is just a smidgen tricky in the shell.
offset="$(( 8 + $last_msg_number * 8 + 8 ))"
printf 'INSTMSGS%-8d' $last_msg_number
msgnum=0
while
msgnum="$(( $msgnum + 1 ))"
[ "$msgnum" -le "$last_msg_number" ]
do
eval msg=\${MSGTEXT_$msgnum}
[ -z "$msg" ] && {
eval echo "No translation for message \$MSGNUM_$msgnum" >&2
printf '%-8d' 0
continue
}
printf '%-8d' $offset
offset="$(( $offset + ${#msg} + 1 ))"
done
# Finally output and null terminate the messages.
msgnum=0
while
msgnum="$(( $msgnum + 1 ))"
[ "$msgnum" -le "$last_msg_number" ]
do
eval msg=\${MSGTEXT_$msgnum}
[ -z "$msg" ] && continue
printf '%s\0' $msg
done

View File

@ -1,4 +1,4 @@
/* $NetBSD: upgrade.c,v 1.34 2003/06/16 19:42:14 dsl Exp $ */
/* $NetBSD: upgrade.c,v 1.35 2003/06/27 22:20:16 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -60,7 +60,6 @@ int merge_X (void);
void
do_upgrade(void)
{
doingwhat = msg_string(MSG_upgrade);
msg_display(MSG_upgradeusure);
process_menu(MENU_noyes, NULL);
@ -69,7 +68,7 @@ do_upgrade(void)
get_ramsize();
if (find_disks() < 0)
if (find_disks(msg_string(MSG_upgrade)) < 0)
return;
if (md_pre_update() < 0)
@ -246,7 +245,6 @@ merge_X(void)
void
do_reinstall_sets(void)
{
doingwhat = msg_string(MSG_reinstall);
unwind_mounts();
msg_display(MSG_reinstallusure);
@ -254,7 +252,7 @@ do_reinstall_sets(void)
if (!yesno)
return;
if (find_disks() < 0)
if (find_disks(msg_string(MSG_reinstall)) < 0)
return;
/* if we need the user to mount root, ask them to. */