Exemplo n.º 1
0
static int
readnewmapfromfile(int fd, char *mfil, char *buf, unsigned short *ubuf) {
	FILE *fp;
	struct stat stbuf;
	int u = 0;
	int lineno;

	if ((fp = findfile(mfil, mapdirpath, mapsuffixes)) == NULL) {
	        fprintf(stderr, _("mapscrn: cannot open map file _%s_\n"),
			mfil);
		exit(1);
	}
	if (stat(pathname, &stbuf)) {
		perror(pathname);
		fprintf(stderr, _("Cannot stat map file"));
		exit(1);
	}
	if (stbuf.st_size == E_TABSZ) {
		if (verbose)
			printf(_("Loading binary direct-to-font screen map "
				 "from file %s\n"),
			       pathname);
		if (fread(buf,E_TABSZ,1,fp) != 1) {
			fprintf(stderr,
				_("Error reading map from file `%s'\n"),
				pathname);
			exit(1);
		}
	} else if (stbuf.st_size == 2*E_TABSZ) {
		if (verbose)
			printf(_("Loading binary unicode screen map "
				 "from file %s\n"),
			       pathname);
		if (fread(ubuf,2*E_TABSZ,1,fp) != 1) {
			fprintf(stderr,
				_("Error reading map from file `%s'\n"),
				pathname);
			exit(1);
		}
		u = 1;
	} else 	{
		if (verbose)
			printf(_("Loading symbolic screen map from file %s\n"),
			       pathname);
		if (parsemap(fp,buf,ubuf,&u,&lineno)) {
			fprintf(stderr,
				_("Error parsing symbolic map "
				  "from `%s', line %d\n"),
				pathname, lineno);
			exit(1);
		}
	}
	fpclose(fp);
	return u;
}
Exemplo n.º 2
0
void
loadunicodemap(int fd, char *tblname) {
	FILE *mapf;
	char buffer[65536];
	char *p;

	mapf = findfile(tblname, unidirpath, unisuffixes);
	if ( !mapf ) {
		perror(tblname);
		exit(EX_NOINPUT);
	}

	if (verbose)
		printf(_("Loading unicode map from file %s\n"), pathname);

	while ( fgets(buffer, sizeof(buffer), mapf) != NULL ) {
		if ( (p = strchr(buffer, '\n')) != NULL )
			*p = '\0';
		else
			fprintf(stderr, _("%s: %s: Warning: line too long\n"),
				progname, tblname);

		parseline(buffer, tblname);
	}

	fpclose(mapf);

	if (listct == 0 && !force) {
		fprintf(stderr,
			_("%s: not loading empty unimap\n"
			  "(if you insist: use option -f to override)\n"),
			progname);
	} else {
		descr.entry_ct = listct;
		descr.entries = list;
		if (loadunimap (fd, NULL, &descr))
			exit(1);
		listct = 0;
	}
}