Example #1
0
/* choice is the index of the chosen language in languages */
static int setupLanguage(int choice, int forced) {
    char * buf;
    int i;

    logMessage(DEBUGLVL, "going to set language to %s", languages[choice].lc_all);
    /* load the language only if it is displayable.  if they're using
     * a serial console or iSeries vioconsole, we hope it's smart enough */
    if ((strcmp(languages[choice].font, "latarcyrheb-sun16") && !FL_SERIAL(flags) && 
         !FL_VIRTPCONSOLE(flags) && !isVioConsole())) {
        if (forced == 1) return 0;

	newtWinMessage("Language Unavailable", "OK", 
		       "%s display is unavailable in text mode.  The "
		       "installation will continue in English until the "
		       "display of %s is possible.", languages[choice].lang,
		       languages[choice].lang);
        setLangEnv(english);
	return 0;
    }
    
    setLangEnv (choice);

    /* clear out top line */
    buf = alloca(80);
    for (i=0; i < 80; i++)
	buf[i] = ' ';
    newtDrawRootText(0, 0, buf);

    char *fmt = FL_RESCUE(flags) ? _(topLineWelcomeRescue) : _(topLineWelcome);
    if (asprintf(&buf, fmt, getProductName(), getProductArch()) == -1) {
        logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
        abort();
    }

    newtDrawRootText(0, 0, buf);
    free(buf);
    newtPopHelpLine();
    newtPushHelpLine(_(bottomHelpLine));

    return 0;

}
int chooseKeyboard(struct loaderData_s * loaderData, char ** kbdtypep) {
    int num = -1;
    int rc;
    gzFile f;
    struct kmapHeader hdr;
    struct kmapInfo * infoTable;
    struct langInfo * languages;
    int numLanguages;
    char ** kbds;
    char buf[16384]; 			/* I hope this is big enough */
    int i;
    char * defkbd = loaderData->kbd ? loaderData->kbd : NULL;
    char *lang;

#if defined(__s390__) || defined(__s390x__)
    return LOADER_NOOP;
#endif

    if (FL_SERIAL (flags) || FL_VIRTPCONSOLE(flags)) return LOADER_NOOP;

    numLanguages = getLangInfo(&languages);

    lang = getenv("LANG");
    if (!lang)
       lang = loaderData->lang;

    if (!defkbd && lang) {
	for (i = 0; i < numLanguages; i++) {
	    if (!strncmp(languages[i].lc_all, lang, 2)) {
		defkbd = languages[i].keyboard;
		break;
	    }
	}
    }

    if (!defkbd)
	defkbd = "us";

    f = gzopen("/etc/keymaps.gz", "r");
    if (!f) {
	errorWindow("cannot open /etc/keymaps.gz: %s");
	return LOADER_ERROR;
    }

    if (gzread(f, &hdr, sizeof(hdr)) != sizeof(hdr)) {
	errorWindow("failed to read keymaps header: %s");
	gzclose(f);
	return LOADER_ERROR;
    }

    logMessage(INFO, "%d keymaps are available", hdr.numEntries);

    i = hdr.numEntries * sizeof(*infoTable);
    infoTable = alloca(i);
    if (gzread(f, infoTable, i) != i) {
	errorWindow("failed to read keymap information: %s");
	gzclose(f);
	return LOADER_ERROR;
    }

    if (num == -1 ) {
	kbds = alloca(sizeof(*kbds) * (hdr.numEntries + 1));
	for (i = 0; i < hdr.numEntries; i++)  {
	    kbds[i] = infoTable[i].name;
	}

	kbds[i] = NULL;
	qsort(kbds, i, sizeof(*kbds), simpleStringCmp);

	for (i = 0; i < hdr.numEntries; i++) 
	    if (!strcmp(kbds[i], defkbd)) 
		num = i;

	rc = newtWinMenu(_("Keyboard Type"), 
			_("What type of keyboard do you have?"),
		        40, 5, 5, 8, kbds, &num, _("OK"), _("Back"), NULL);
	if (rc == 2) return LOADER_BACK;

	/* num needs to index the right keyboard infoTable */
	for (i = 0; i < hdr.numEntries; i++)
	    if (!strcmp(kbds[num], infoTable[i].name)) break;
	num = i;
    }

    rc = 0;

    for (i = 0; i < num; i++) {
	if (gzread(f, buf, infoTable[i].size) != infoTable[i].size) {
	    logMessage(ERROR, "error reading %d bytes from file: %m",
		       infoTable[i].size);
	    gzclose(f);
	    rc = LOADER_ERROR;
	}
    }

    if (!rc) rc = loadKeymap(f);

    /* normalize the error condition */
    /* MSWFIXME - do we want to warn the user that setting the
       keyboard didn't work?
    */
    if (rc != 0)
	rc = LOADER_ERROR;
    else
        gzclose(f);

    loaderData->kbd = strdup(infoTable[num].name);

    return rc;
}