diff --git a/charset.c b/charset.c index 9473c12..9175f48 100644 --- a/charset.c +++ b/charset.c @@ -21,7 +21,8 @@ #include "qe.h" -QECharset *first_charset; +/* XXX: Should move this to QEmacsState, and find a way for html2png */ +struct QECharset *first_charset; /* Unicode utilities */ @@ -116,7 +117,7 @@ static u8 *encode_raw(__unused__ QECharset *charset, u8 *p, int c) } } -QECharset charset_raw = { +struct QECharset charset_raw = { "raw", "binary|none", NULL, @@ -188,7 +189,7 @@ static u8 *encode_8859_1(__unused__ QECharset *charset, u8 *p, int c) } } -QECharset charset_8859_1 = { +struct QECharset charset_8859_1 = { "8859-1", "ISO-8859-1|iso-ir-100|latin1|l1|819", probe_8859_1, @@ -220,7 +221,7 @@ static u8 *encode_vt100(__unused__ QECharset *charset, u8 *p, int c) } } -QECharset charset_vt100 = { +struct QECharset charset_vt100 = { "vt100", NULL, NULL, @@ -247,7 +248,7 @@ static u8 *encode_7bit(__unused__ QECharset *charset, u8 *p, int c) } } -static QECharset charset_7bit = { +static struct QECharset charset_7bit = { "7bit", "us-ascii|ascii|7-bit|iso-ir-6|ANSI_X3.4|646", NULL, @@ -547,7 +548,7 @@ static int charset_goto_char_utf8(CharsetDecodeState *s, return buf_ptr - buf; } -QECharset charset_utf8 = { +struct QECharset charset_utf8 = { "utf-8", "utf8", probe_utf8, @@ -816,7 +817,7 @@ static int charset_goto_char_ucs2(CharsetDecodeState *s, return (const u8*)buf_ptr - buf; } -QECharset charset_ucs2le = { +struct QECharset charset_ucs2le = { "ucs2le", "utf16le|utf-16le", probe_ucs2le, @@ -830,7 +831,7 @@ QECharset charset_ucs2le = { 2, 0, 0, 10, 0, 0, NULL, NULL, }; -QECharset charset_ucs2be = { +struct QECharset charset_ucs2be = { "ucs2be", "ucs2|utf16|utf-16|utf16be|utf-16be", probe_ucs2be, @@ -1088,7 +1089,7 @@ static int charset_goto_char_ucs4(CharsetDecodeState *s, return (const u8*)buf_ptr - buf; } -QECharset charset_ucs4le = { +struct QECharset charset_ucs4le = { "ucs4le", "utf32le|utf-32le", probe_ucs4le, @@ -1102,7 +1103,7 @@ QECharset charset_ucs4le = { 4, 0, 0, 10, 0, 0, NULL, NULL, }; -QECharset charset_ucs4be = { +struct QECharset charset_ucs4be = { "ucs4be", "ucs4|utf32|utf-32|utf32be|utf-32be", probe_ucs4be, @@ -1119,9 +1120,9 @@ QECharset charset_ucs4be = { /********************************************************/ /* generic charset functions */ -void qe_register_charset(QECharset *charset) +void qe_register_charset(struct QECharset *charset) { - QECharset **pp; + struct QECharset **pp; if (!charset->aliases) charset->aliases = ""; diff --git a/charsetjis.c b/charsetjis.c index 4ad65ed..5bc2359 100644 --- a/charsetjis.c +++ b/charsetjis.c @@ -142,7 +142,7 @@ static unsigned char *encode_euc_jp(__unused__ QECharset *s, return q; } -static QECharset charset_euc_jp = { +static struct QECharset charset_euc_jp = { "euc-jp", NULL, NULL, @@ -222,7 +222,7 @@ static unsigned char *encode_sjis(__unused__ QECharset *s, return q; } -static QECharset charset_sjis = { +static struct QECharset charset_sjis = { "sjis", NULL, NULL, diff --git a/charsetmore.c b/charsetmore.c index ccf42e3..d99f2ea 100644 --- a/charsetmore.c +++ b/charsetmore.c @@ -45,7 +45,7 @@ static const unsigned short table_8859_2[95] = { 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9, }; -static QECharset charset_8859_2 = { +static struct QECharset charset_8859_2 = { "8859-2", "ISO-8859-2|iso-ir-101|latin2|l2|iso-latin2", NULL, @@ -88,7 +88,7 @@ static const unsigned short table_8859_3[95] = { 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9, }; -static QECharset charset_8859_3 = { +static struct QECharset charset_8859_3 = { "8859-3", "ISO-8859-3", NULL, @@ -131,7 +131,7 @@ static const unsigned short table_8859_4[95] = { 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9, }; -static QECharset charset_8859_4 = { +static struct QECharset charset_8859_4 = { "8859-4", "ISO-8859-4|iso-ir-110|latin4|l4|iso-latin4", NULL, @@ -174,7 +174,7 @@ static const unsigned short table_8859_5[95] = { 0x0459, 0x045a, 0x045b, 0x045c, 0x00a7, 0x045e, 0x045f, }; -static QECharset charset_8859_5 = { +static struct QECharset charset_8859_5 = { "8859-5", "ISO-8859-5", NULL, @@ -214,7 +214,7 @@ static const unsigned short table_8859_6[71] = { 0x064c, 0x064d, 0x064e, 0x064f, 0x0650, 0x0651, 0x0652, }; -static QECharset charset_8859_6 = { +static struct QECharset charset_8859_6 = { "8859-6", "ISO-8859-6", NULL, @@ -257,7 +257,7 @@ static const unsigned short table_8859_7[94] = { 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, }; -static QECharset charset_8859_7 = { +static struct QECharset charset_8859_7 = { "8859-7", "ISO-8859-7|iso-ir-126|elot-928", NULL, @@ -299,7 +299,7 @@ static const unsigned short table_8859_8[85] = { 0x05ea, 0x00fb, 0x00fc, 0x200e, 0x200f, }; -static QECharset charset_8859_8 = { +static struct QECharset charset_8859_8 = { "8859-8", "ISO-8859-8", NULL, @@ -336,7 +336,7 @@ static const unsigned short table_8859_9[47] = { 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, }; -static QECharset charset_8859_9 = { +static struct QECharset charset_8859_9 = { "8859-9", "ISO-8859-9", NULL, @@ -379,7 +379,7 @@ static const unsigned short table_8859_10[95] = { 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x0138, }; -static QECharset charset_8859_10 = { +static struct QECharset charset_8859_10 = { "8859-10", "ISO-8859-10", NULL, @@ -422,7 +422,7 @@ static const unsigned short table_8859_11[91] = { 0x0e59, 0x0e5a, 0x0e5b, }; -static QECharset charset_8859_11 = { +static struct QECharset charset_8859_11 = { "8859-11", "ISO-8859-11", NULL, @@ -465,7 +465,7 @@ static const unsigned short table_8859_13[95] = { 0x0142, 0x015b, 0x016b, 0x00fc, 0x017c, 0x017e, 0x2019, }; -static QECharset charset_8859_13 = { +static struct QECharset charset_8859_13 = { "8859-13", "ISO-8859-13|iso-ir-179|latin7|l7|iso-latin7", NULL, @@ -508,7 +508,7 @@ static const unsigned short table_8859_14[94] = { 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x0177, }; -static QECharset charset_8859_14 = { +static struct QECharset charset_8859_14 = { "8859-14", "ISO-8859-14", NULL, @@ -543,7 +543,7 @@ static const unsigned short table_8859_15[27] = { 0x0152, 0x0153, 0x0178, }; -static QECharset charset_8859_15 = { +static struct QECharset charset_8859_15 = { "8859-15", "ISO-8859-15|latin9|l9|latin0|l0", NULL, @@ -586,7 +586,7 @@ static const unsigned short table_8859_16[94] = { 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0119, 0x021b, }; -static QECharset charset_8859_16 = { +static struct QECharset charset_8859_16 = { "8859-16", "ISO-8859-16|latin10|l10", NULL, @@ -633,7 +633,7 @@ static const unsigned short table_cp437[128] = { 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0, }; -static QECharset charset_cp437 = { +static struct QECharset charset_cp437 = { "cp437", "437", NULL, @@ -680,7 +680,7 @@ static const unsigned short table_cp737[128] = { 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0, }; -static QECharset charset_cp737 = { +static struct QECharset charset_cp737 = { "cp737", "737", NULL, @@ -727,7 +727,7 @@ static const unsigned short table_cp850[128] = { 0x00b0, 0x00a8, 0x00b7, 0x00b9, 0x00b3, 0x00b2, 0x25a0, 0x00a0, }; -static QECharset charset_cp850 = { +static struct QECharset charset_cp850 = { "cp850", "850", NULL, @@ -774,7 +774,7 @@ static const unsigned short table_cp852[128] = { 0x00b0, 0x00a8, 0x02d9, 0x0171, 0x0158, 0x0159, 0x25a0, 0x00a0, }; -static QECharset charset_cp852 = { +static struct QECharset charset_cp852 = { "cp852", "852", NULL, @@ -821,7 +821,7 @@ static const unsigned short table_cp866[128] = { 0x00b0, 0x2219, 0x00b7, 0x221a, 0x2116, 0x00a4, 0x25a0, 0x00a0, }; -static QECharset charset_cp866 = { +static struct QECharset charset_cp866 = { "cp866", "866", NULL, @@ -868,7 +868,7 @@ static const unsigned short table_cp1125[128] = { 0x0407, 0x0457, 0x00b7, 0x221a, 0x2116, 0x00a4, 0x25a0, 0x00a0, }; -static QECharset charset_cp1125 = { +static struct QECharset charset_cp1125 = { "cp1125", "x-cp866-u|ruscii|1125", NULL, @@ -915,7 +915,7 @@ static const unsigned short table_cp1250[128] = { 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9, }; -static QECharset charset_cp1250 = { +static struct QECharset charset_cp1250 = { "cp1250", "windows-1250|1250", NULL, @@ -962,7 +962,7 @@ static const unsigned short table_cp1251[128] = { 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f, }; -static QECharset charset_cp1251 = { +static struct QECharset charset_cp1251 = { "cp1251", "windows-1251|1251", NULL, @@ -997,7 +997,7 @@ static const unsigned short table_cp1252[32] = { 0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x0000, 0x017e, 0x0178, }; -static QECharset charset_cp1252 = { +static struct QECharset charset_cp1252 = { "cp1252", "windows-1252|1252", NULL, @@ -1044,7 +1044,7 @@ static const unsigned short table_cp1256[128] = { 0x0651, 0x00f9, 0x0652, 0x00fb, 0x00fc, 0x200e, 0x200f, 0x06d2, }; -static QECharset charset_cp1256 = { +static struct QECharset charset_cp1256 = { "cp1256", "windows-1256|1256", NULL, @@ -1091,7 +1091,7 @@ static const unsigned short table_cp1257[128] = { 0x0173, 0x0142, 0x015b, 0x016b, 0x00fc, 0x017c, 0x017e, 0x02d9, }; -static QECharset charset_cp1257 = { +static struct QECharset charset_cp1257 = { "cp1257", "windows-1257|1257", NULL, @@ -1138,7 +1138,7 @@ static const unsigned short table_mac_latin2[128] = { 0x00dd, 0x00fd, 0x0137, 0x017b, 0x0141, 0x017c, 0x0122, 0x02c7, }; -static QECharset charset_mac_latin2 = { +static struct QECharset charset_mac_latin2 = { "mac-latin2", "x-mac-ce|mac-ce|macce|10029", NULL, @@ -1185,7 +1185,7 @@ static const unsigned short table_mac_roman[128] = { 0x00af, 0x02d8, 0x02d9, 0x02da, 0x00b8, 0x02dd, 0x02db, 0x02c7, }; -QECharset charset_mac_roman = { +struct QECharset charset_mac_roman = { "mac-roman", "x-mac|mac", NULL, @@ -1232,7 +1232,7 @@ static const unsigned short table_kamen[128] = { 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0, }; -static QECharset charset_kamen = { +static struct QECharset charset_kamen = { "kamen", "x-kam-cs|kam|867|869", NULL, @@ -1279,7 +1279,7 @@ static const unsigned short table_koi8_r[128] = { 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a, }; -static QECharset charset_koi8_r = { +static struct QECharset charset_koi8_r = { "koi8-r", "", NULL, @@ -1326,7 +1326,7 @@ static const unsigned short table_koi8_u[128] = { 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a, }; -static QECharset charset_koi8_u = { +static struct QECharset charset_koi8_u = { "koi8-u", "", NULL, @@ -1389,7 +1389,7 @@ static const unsigned short table_tcvn[255] = { 0x1ef1, 0x1ef3, 0x1ef7, 0x1ef9, 0x00fd, 0x1ef5, 0x1ed0, }; -static QECharset charset_tcvn = { +static struct QECharset charset_tcvn = { "tcvn", "TCVN-5712|TCVN|TCVN-0|TCVN-1", NULL, @@ -1452,7 +1452,7 @@ static const unsigned short table_viscii[254] = { 0x00fa, 0x0169, 0x1ee7, 0x00fd, 0x1ee3, 0x1eee, }; -static QECharset charset_viscii = { +static struct QECharset charset_viscii = { "viscii", "VISCII|VISCII-1|VISCII 1.1|VISCII-1.1|VISCII1.1-1", NULL, @@ -1515,7 +1515,7 @@ static const unsigned short table_cp037[252] = { 0x00dc, 0x00d9, 0x00da, 0x009f, }; -static QECharset charset_cp037 = { +static struct QECharset charset_cp037 = { "cp037", "037|ebcdic-037", NULL, @@ -1578,7 +1578,7 @@ static const unsigned short table_cp424[252] = { 0x0000, 0x0000, 0x0000, 0x009f, }; -static QECharset charset_cp424 = { +static struct QECharset charset_cp424 = { "cp424", "424|ebcdic-424", NULL, @@ -1641,7 +1641,7 @@ static const unsigned short table_cp500[252] = { 0x00dc, 0x00d9, 0x00da, 0x009f, }; -static QECharset charset_cp500 = { +static struct QECharset charset_cp500 = { "cp500", "500|ebcdic-500", NULL, @@ -1704,7 +1704,7 @@ static const unsigned short table_cp875[252] = { 0x001a, 0x001a, 0x00bb, 0x009f, }; -static QECharset charset_cp875 = { +static struct QECharset charset_cp875 = { "cp875", "875|ebcdic-875", NULL, @@ -1767,7 +1767,7 @@ static const unsigned short table_cp1026[252] = { 0x0022, 0x00d9, 0x00da, 0x009f, }; -static QECharset charset_cp1026 = { +static struct QECharset charset_cp1026 = { "cp1026", "1026|ebcdic-1026", NULL, @@ -1814,7 +1814,7 @@ static const unsigned short table_atarist[128] = { 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x00b3, 0x00af, }; -static QECharset charset_atarist = { +static struct QECharset charset_atarist = { "atarist", "atari-st", NULL, diff --git a/cptoqe.c b/cptoqe.c index 20f524d..e334a5e 100644 --- a/cptoqe.c +++ b/cptoqe.c @@ -211,7 +211,7 @@ static void handle_cp(FILE *f0, const char *name, const char *fname) if (strcmp(name_id, "mac_roman")) printf("static "); - printf("QECharset charset_%s = {\n" + printf("struct QECharset charset_%s = {\n" " \"%s\",\n", name_id, name); diff --git a/qe.h b/qe.h index 47a2d8b..958bc4f 100644 --- a/qe.h +++ b/qe.h @@ -85,6 +85,8 @@ #define ssizeof(a) ((int)(sizeof(a))) #endif +#define OWNED /* ptr attribute for allocated data owned by a structure */ + /* prevent gcc warning about shadowing a global declaration */ #define index index__ @@ -136,6 +138,8 @@ typedef struct ModeDef ModeDef; typedef struct QETimer QETimer; typedef struct QEColorizeContext QEColorizeContext; typedef struct KeyDef KeyDef; +typedef struct InputMethod InputMethod; +typedef struct ISearchState ISearchState; static inline char *s8(u8 *p) { return (char*)p; } static inline const char *cs8(const u8 *p) { return (const char*)p; } @@ -535,7 +539,7 @@ int buf_put_keys(buf_t *out, unsigned int *keys, int nb_keys); #define MAX_CHAR_BYTES 6 typedef struct CharsetDecodeState CharsetDecodeState; -typedef struct QECharset QECharset; +typedef const struct QECharset QECharset; struct QECharset { const char *name; @@ -561,15 +565,15 @@ struct QECharset { struct QECharset *next; }; -extern QECharset *first_charset; +extern struct QECharset *first_charset; /* predefined charsets */ -extern QECharset charset_raw; -extern QECharset charset_8859_1; -extern QECharset charset_utf8; -extern QECharset charset_vt100; /* used for the tty output */ -extern QECharset charset_ucs2le, charset_ucs2be; -extern QECharset charset_ucs4le, charset_ucs4be; -extern QECharset charset_mac_roman; +extern struct QECharset charset_raw; +extern struct QECharset charset_8859_1; +extern struct QECharset charset_utf8; +extern struct QECharset charset_vt100; /* used for the tty output */ +extern struct QECharset charset_ucs2le, charset_ucs2be; +extern struct QECharset charset_ucs4le, charset_ucs4be; +extern struct QECharset charset_mac_roman; typedef enum EOLType { EOL_UNIX = 0, @@ -598,7 +602,7 @@ void charset_init(void); int charset_more_init(void); int charset_jis_init(void); -void qe_register_charset(QECharset *charset); +void qe_register_charset(struct QECharset *charset); extern unsigned char utf8_length[256]; static inline int utf8_is_trailing_byte(int c) { return (c & 0xC0) == 0x80; } @@ -857,7 +861,7 @@ typedef struct EditBufferDataType { #define BF_STYLE4 0x3000 /* buffer has 4 byte styles */ struct EditBuffer { - Page *page_table; + OWNED Page *page_table; int nb_pages; int mark; /* current mark (moved with text) */ int total_size; /* total size of the buffer */ @@ -910,7 +914,7 @@ struct EditBuffer { int style_shift; /* modification callbacks */ - EditBufferCallbackList *first_callback; + OWNED EditBufferCallbackList *first_callback; #if 0 /* asynchronous loading/saving support */ @@ -925,7 +929,7 @@ struct EditBuffer { */ struct ModeDef *default_mode; struct ModeDef *saved_mode; - struct ModeSavedData *saved_data; + OWNED struct ModeSavedData *saved_data; /* default mode stuff when buffer is detached from window */ int offset; @@ -934,7 +938,7 @@ struct EditBuffer { int fill_column; EOLType eol_type; - EditBuffer *next; /* next editbuffer in qe_state buffer list */ + OWNED EditBuffer *next; /* next editbuffer in qe_state buffer list */ int st_mode; /* unix file mode */ char name[MAX_BUFFERNAME_SIZE]; /* buffer name */ @@ -1165,12 +1169,12 @@ struct EditState { /* after this limit, the fields are not saved into the buffer */ int end_of_saved_data; - /* mode specific info */ - struct ModeDef *mode; - void *mode_data; /* mode private data */ - EditBuffer *b; + /* mode specific info */ + ModeDef *mode; + void *mode_data; /* mode private data */ + /* state before line n, one short per line */ unsigned short *colorize_states; int colorize_nb_lines; @@ -1202,22 +1206,22 @@ struct EditState { #define WF_MODELINE 0x0002 /* mode line must be displayed */ #define WF_RSEPARATOR 0x0004 /* right window separator */ - char *prompt; + OWNED char *prompt; /* optional window prompt, utf8, owned by the window */ //const char *mode_line; //const char *title; struct QEmacsState *qe_state; struct QEditScreen *screen; /* copy of qe_state->screen */ /* display shadow to optimize redraw */ char modeline_shadow[MAX_SCREEN_WIDTH]; - QELineShadow *line_shadow; /* per window shadow */ + OWNED QELineShadow *line_shadow; /* per window shadow */ int shadow_nb_lines; /* compose state for input method */ - struct InputMethod *input_method; /* current input method */ - struct InputMethod *selected_input_method; /* selected input method (used to switch) */ + InputMethod *input_method; /* current input method */ + InputMethod *selected_input_method; /* selected input method (used to switch) */ int compose_len; int compose_start_offset; unsigned int compose_buf[20]; - EditState *next_window; + OWNED EditState *next_window; }; /* Ugly patch for saving/restoring window data upon switching buffer */ @@ -1264,7 +1268,7 @@ struct ModeDef { int instance_size; /* size of malloced instance */ /* return the percentage of confidence */ - int (*mode_probe)(ModeDef *, ModeProbeData *); + int (*mode_probe)(ModeDef *m, ModeProbeData *pd); int (*mode_init)(EditState *s, EditBuffer *b, int flags); void (*mode_close)(EditState *s); @@ -1374,7 +1378,7 @@ struct QEmacsState { //struct QECharset *first_charset; //struct QETimer *first_timer; struct VarDef *first_variable; - struct InputMethod *input_methods; + InputMethod *input_methods; EditState *first_window; EditState *active_window; /* window in which we edit */ EditBuffer *first_buffer; @@ -1667,7 +1671,7 @@ static inline void clear_color(unsigned int *p, int count) { #define INPUTMETHOD_NOMATCH (-1) #define INPUTMETHOD_MORECHARS (-2) -typedef struct InputMethod { +struct InputMethod { const char *name; /* input match returns: n > 0: number of code points in replacement found for a sequence @@ -1681,8 +1685,8 @@ typedef struct InputMethod { int *match_len_ptr, const u8 *data, const unsigned int *buf, int len); const u8 *data; - struct InputMethod *next; -} InputMethod; + InputMethod *next; +}; void register_input_method(InputMethod *m); void do_set_input_method(EditState *s, const char *method); diff --git a/search.c b/search.c index ec36e23..6eaa002 100644 --- a/search.c +++ b/search.c @@ -164,7 +164,7 @@ static int search_abort_func(__unused__ void *opaque) return is_user_input_pending(); } -typedef struct ISearchState { +struct ISearchState { EditState *s; int saved_mark; int start_offset; @@ -175,7 +175,7 @@ typedef struct ISearchState { int search_flags; int found_offset, found_end; unsigned int search_u32[SEARCH_LENGTH]; -} ISearchState; +}; static void buf_encode_search_u32(buf_t *out, const unsigned int *str, int len) {