File: charmap.h

package info (click to toggle)
jupp 3.1.38-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,420 kB
  • sloc: ansic: 31,382; sh: 4,199; makefile: 431
file content (91 lines) | stat: -rw-r--r-- 2,555 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 *	Character sets
 *	Copyright
 *		(C) 2004 Joseph H. Allen
 *
 *	This file is part of JOE (Joe's Own Editor)
 */

#ifndef _Icharmap
#define _Icharmap 1

#ifdef EXTERN
__RCSID("$MirOS: contrib/code/jupp/charmap.h,v 1.12 2017/12/20 23:33:56 tg Exp $");
#endif

/* For sorted from_map entries */

struct pair {
	int first;			/* Unicode */
	int last;			/* Byte */
};

/* A character set */

struct charmap {
	struct charmap *next;		/* Linked list of loaded character maps */
	const unsigned char *name;	/* Name of this one */

	int type;			/* 0=byte, 1=UTF-8 */

	/* Character predicate functions */

	int (*is_punct)(struct charmap *map,int c);
	int (*is_print)(struct charmap *map,int c);
	int (*is_space)(struct charmap *map,int c);
	int (*is_alphx)(struct charmap *map,int c);
	int (*is_alnux)(struct charmap *map,int c);

	/* Character conversion functions */

	int (*to_lower)(struct charmap *map,int c);
	int (*to_upper)(struct charmap *map,int c);
	int (*to_uni)(struct charmap *map,int c);
	int (*from_uni)(struct charmap *map,int c);

	/* Information for byte-oriented character sets */

	const int *to_map;		/* Convert byte to unicode */

	unsigned char lower_map[256];	/* Convert to lower case */
	unsigned char upper_map[256];

	struct pair from_map[256 + 2];	/* Convert from unicode to byte */

	int from_size;			/* No. pairs in from_map */

	unsigned char print_map[32];	/* Bit map of printable characters */
	unsigned char alphx_map[32];	/* Bit map of alphabetic characters and _ */
	unsigned char alnux_map[32];	/* Bit map of alphanumeric characters and _ */
};

/* Predicates */

#define joe_ispunct(map,c) ((map)->is_punct((map),(c)))
#define joe_isprint(map,c) ((map)->is_print((map),(c)))
#define joe_isspace(map,c) ((map)->is_space((map),(c)))
#define joe_isalphx(map,c) ((map)->is_alphx((map),(c)))
#define joe_isalnux(map,c) ((map)->is_alnux((map),(c)))
int joe_isblank(struct charmap *map,int c);
int joe_isspace_eof(struct charmap *map,int c);

/* Conversion functions */

#define joe_tolower(map,c) ((map)->to_lower((map),(c)))
#define joe_toupper(map,c) ((map)->to_upper((map),(c)))
#define joe_to_uni(map,c) ((map)->to_uni((map),(c)))
#define joe_from_uni(map,c) ((map)->from_uni((map),(c)))
unsigned char *joe_strtolower(unsigned char *s);

/* Find (load if necessary) a character set */
struct charmap *find_charmap(const unsigned char *name);

/* Get available encodings */
unsigned char **get_encodings(void);

int to_uni(struct charmap *cset, int c);
int from_uni(struct charmap *cset, int c);

#include "utf8.h"

#endif