Exemplo n.º 1
0
/*
 * @unimplemented
 */
char *setlocale(int category, const char *locale)
{
	char lang[100];
	char country[100];
	char code_page[100];
	if (NULL != locale) {
		parse_locale((char *)locale,lang,country,code_page);
	}

	//printf("%s %s %s %s\n",locale,lang,country,code_page);


	switch ( category )
  	{
  		case LC_COLLATE:
  		break;
		case LC_CTYPE:
		break;
		case LC_MONETARY:
		break;
		case LC_NUMERIC:
		break;
		case LC_TIME:
		break;
		case LC_ALL:
		break;
		default:
		break;
	}

	return "C";

}
Exemplo n.º 2
0
void load_config(void) {
	if ((lang = malloc(strlen(DEFAULT_LANGUAGE)+1))==NULL)
		print_error("Out of memory");
	strcpy(lang, DEFAULT_LANGUAGE);
	if ((locale = malloc(strlen(DEFAULT_LOCALE)+1))==NULL)
		print_error("Out of memory");
	strcpy(locale, DEFAULT_LOCALE);
	units = DEFAULT_UNITS;
	ifaces = NULL;
	FILE *stream;

	if ((stream = fopen(CONFIG_PATH, "r")) == NULL)
		print_error("Can't open config file");;
	while (!feof(stream)) {
		char *line = read_line(stream);
		char *directive, *value;
		parse_line(line, &directive, &value);

		if (directive!=NULL) {
			lowerstr(directive);
			if (strcmp(directive, "language")== 0) {
				parse_language(value);
			}
			else if (strcmp(directive, "locale")== 0) {
				parse_locale(value);
			}
			else if (strcmp(directive, "units")==0) {
				parse_units(value);
			}
			else if (strcmp(directive, "interface")==0) {
				parse_interface(value);
			}
			free(directive);
			free(value);
		}
		free(line);
	}

	if (ifaces == NULL) {
		print_error("No interface specified in config file.");
	}
}
Exemplo n.º 3
0
/* perform locale matching by implementing the algorithm specified in
 * xdg desktop entry specification, section "localized values for keys".
 */
static Bool compare_matchlevel(int *current_level, const char *found_locale)
{
	/* current key locale */
	char *key_lang, *key_ctry, *key_enc, *key_mod;

	parse_locale(found_locale, &key_lang, &key_ctry, &key_enc, &key_mod);

	if (env_lang && key_lang &&		/* Shortcut: if key and env languages don't match, */
	    strcmp(env_lang, key_lang) != 0)	/* don't even bother. This takes care of the great */
		return False;			/* majority of the cases without having to go through */
						/* the more theoretical parts of the spec'd algo. */

	if (!env_mod && key_mod)	/* If LC_MESSAGES does not have a MODIFIER field, */
		return False;		/* then no key with a modifier will be matched. */

	if (!env_ctry && key_ctry)	/* Similarly, if LC_MESSAGES does not have a COUNTRY field, */
		return False;		/* then no key with a country specified will be matched. */

	/* LC_MESSAGES value: lang_COUNTRY@MODIFIER */
	if (env_lang && env_ctry && env_mod) {		/* lang_COUNTRY@MODIFIER */
		if (key_lang && key_ctry && key_mod &&
		    strcmp(env_lang, key_lang) == 0 &&
		    strcmp(env_ctry, key_ctry) == 0 &&
		    strcmp(env_mod,  key_mod) == 0) {
			*current_level = MATCH_LANG_COUNTRY_MODIFIER;
			return True;
		} else if (key_lang && key_ctry &&	/* lang_COUNTRY */
		    strcmp(env_lang, key_lang) == 0 &&
		    strcmp(env_ctry, key_ctry) == 0 &&
		    *current_level < MATCH_LANG_COUNTRY) {
			*current_level = MATCH_LANG_COUNTRY;
			return True;
		} else if (key_lang && key_mod &&	/* lang@MODIFIER */
		    strcmp(env_lang, key_lang) == 0 &&
		    strcmp(env_mod,  key_mod) == 0 &&
		    *current_level < MATCH_LANG_MODIFIER) {
			*current_level = MATCH_LANG_MODIFIER;
			return True;
		} else if (key_lang &&			/* lang */
		    strcmp(env_lang, key_lang) == 0 &&
		    *current_level < MATCH_LANG) {
			*current_level = MATCH_LANG;
			return True;
		} else {
			return False;
		}
	}

	/* LC_MESSAGES value: lang_COUNTRY */
	if (env_lang && env_ctry) {			/* lang_COUNTRY */
		if (key_lang && key_ctry &&
		    strcmp(env_lang, key_lang) == 0 &&
		    strcmp(env_ctry, key_ctry) == 0 &&
		    *current_level < MATCH_LANG_COUNTRY) {
			*current_level = MATCH_LANG_COUNTRY;
			return True;
		} else if (key_lang &&			/* lang */
		    strcmp(env_lang, key_lang) == 0 &&
		    *current_level < MATCH_LANG) {
			*current_level = MATCH_LANG;
			return True;
		} else {
			return False;
		}
	}

	/* LC_MESSAGES value: lang@MODIFIER */
	if (env_lang && env_mod) {			/* lang@MODIFIER */
		if (key_lang && key_mod &&
		    strcmp(env_lang, key_lang) == 0 &&
		    strcmp(env_mod,  key_mod) == 0 &&
		    *current_level < MATCH_LANG_MODIFIER) {
			*current_level = MATCH_LANG_MODIFIER;
			return True;
		} else if (key_lang &&			/* lang */
		    strcmp(env_lang, key_lang) == 0 &&
		    *current_level < MATCH_LANG) {
			*current_level = MATCH_LANG;
			return True;
		} else {
			return False;
		}
	}

	/* LC_MESSAGES value: lang */
	if (env_lang) {					/* lang */
		if (key_lang &&
		    strcmp(env_lang, key_lang) == 0 &&
		    *current_level < MATCH_LANG) {
			*current_level = MATCH_LANG;
			return True;
		} else {
			return False;
		}
	}

	/* MATCH_DEFAULT is handled in getLocalizedStringValue */

	return False;
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
	struct stat st;
	int i;
	int *previousDepth;

	prog_name = argv[0];
	plMenuNodes = WMCreateArray(8); /* grows on demand */
	menu = (WMTreeNode *)NULL;
	parse = NULL;
	validateFilename = NULL;

	/* assemblePLMenuFunc passes this around */
	previousDepth = (int *)wmalloc(sizeof(int));
	*previousDepth = -1;

	/* currently this is used only by the xdg parser, but it might be useful
	 * in the future localizing other menus, so it won't hurt to have it here.
	 */
	parse_locale(NULL, &env_lang, &env_ctry, &env_enc, &env_mod);
	terminal = find_terminal_emulator();

	for (i = 1; i < argc; i++)
	{
		if (strncmp(argv[i], "-parser", 7) == 0 &&
		    (argv[i][7] == '=' ||
		     argv[i][7] == ':' || /* for legacy compatibility */
		     argv[i][7] == '\0')) {
			const char *name;

			if (argv[i][7] == '\0') {
				if (++i > argc) {
					fprintf(stderr, "%s: Missing parser name after \"-parser\"\n", prog_name);
					return 2;
				}
				name = argv[i];
			} else {
				name = argv[i] + 8;
			}

			if (strcmp(name, "xdg") == 0) {
				parse = &parse_xdg;
			} else if (strcmp(name, "wmconfig") == 0) {
				parse = &parse_wmconfig;
				validateFilename = &wmconfig_validate_file;
			} else {
				fprintf(stderr, "%s: Unknown parser \"%s\"\n", prog_name, name);
				return 2;
			}
			continue;
		}

		if (strcmp(argv[i], "--version") == 0) {
			printf("%s (Window Maker %s)\n", prog_name, VERSION);
			return 0;
		}

		if (strcmp(argv[i], "-h") == 0 ||
		    strcmp(argv[i], "-help") == 0 ||
		    strcmp(argv[i], "--help") == 0) {
			print_help();
			return 0;
		}

		if (parse == NULL) {
			fprintf(stderr, "%s: argument \"%s\" with no valid parser\n", prog_name, argv[i]);
			return 2;
		}

#if DEBUG
		fprintf(stderr, "%s: Using parser \"%s\" to process \"%s\"\n",
		        prog_name, get_parser_name(), argv[i]);
#endif

		if (stat(argv[i], &st) == -1) {
			fprintf(stderr, "%s: unable to stat \"%s\", %s\n",
			        prog_name, argv[i], strerror(errno));
			return 1;
		} else if (S_ISREG(st.st_mode)) {
			parse(argv[i], addWMMenuEntryCallback);
		} else if (S_ISDIR(st.st_mode)) {
			nftw(argv[i], dirParseFunc, 16, FTW_PHYS);
		} else {
			fprintf(stderr, "%s: \"%s\" is not a file or directory\n", prog_name, argv[i]);
			return 1;
		}
	}

	if (!menu) {
		fprintf(stderr, "%s: parsers failed to create a valid menu\n", prog_name);
		return 1;
	}

	WMSortTree(menu, menuSortFunc);
	WMTreeWalk(menu, assemblePLMenuFunc, previousDepth, True);

	i = WMGetArrayItemCount(plMenuNodes);
	if (i > 2) { /* more than one submenu unprocessed is almost certainly an error */
		fprintf(stderr, "%s: unprocessed levels on the stack. fishy.\n", prog_name);
		return 3;
	} else if (i > 1 ) { /* possibly the top-level attachment is not yet done */
		WMPropList *first, *next;

		next = WMPopFromArray(plMenuNodes);
		first = WMPopFromArray(plMenuNodes);
		WMAddToPLArray(first, next);
		WMAddToArray(plMenuNodes, first);
	}

	puts(WMGetPropListDescription((WMPropList *)WMGetFromArray(plMenuNodes, 0), True));

	return 0;
}