Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a LOOOOOT of errors in the code. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
459 changes: 239 additions & 220 deletions hash-editor/src/che.c

Large diffs are not rendered by default.

36 changes: 0 additions & 36 deletions hash-editor/src/che.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,3 @@ enum {
ORIGFREQ_COLUMN,
N_COLUMNS
};

GtkTreeStore *store;
GtkTreeIter iter;
gboolean is_editing_existing_phrase;
GtkTreeSelection *selection;
GtkTreeView *main_tree_view;
gchar current_filename[1024];
GtkWidget *editor_dialog;
GtkWidget *search_dialog;

GtkWidget *che_create_tree( GtkWindow* );
GtkWidget *che_create_menu( GtkWindow* );
void che_read_hash(gchar *filename);
void convert(char*, char*, int);
void che_select_prev_phrase();
void che_select_next_phrase();

struct zhuindict *zhuin_dictionary;

gboolean is_file_saved;
gchar prev_search_text[0xff] = {};
uint32_t chewing_lifetime = 0;

/* callback */
void che_quit(GtkWindow*);
void file_open( GtkWindow* );
void file_save_as( GtkWindow* );
void file_save( gchar* );
void file_export(void*);
void file_import(void*);
void cell_edited(GtkCellRendererText *cellrenderertext, gchar *arg1, gchar *arg2, gpointer column);
void che_new_phrase_dlg( GtkWidget* );
void che_save_phrase(GtkWidget *obj, gpointer vbox);
void che_remove_phrase(GtkWidget *menu);
void che_show_search_dlg(GtkWidget *widget);
void che_show_about_dlg(GtkWidget *widget);
31 changes: 15 additions & 16 deletions hash-editor/src/chewing-utf8-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ static char utf8len_tab[256] =
};

/* Return length of UTF-8 string */
int
chewing_utf8_strlen(char *str)
size_t
chewing_utf8_strlen(const char *str)
{
int length = 0;
char *strptr = str;
size_t length = 0;
const char *strptr = str;

while (strptr[0] != '\0')
{
strptr += chewing_utf8_byte2len(strptr[0]);
Expand All @@ -31,53 +31,52 @@ chewing_utf8_strlen(char *str)
}

/* Return bytes of a UTF-8 character */
int
size_t
chewing_utf8_byte2len(unsigned char b)
{
return utf8len_tab[b];
}

/* Return how many bytes was copied */
int
size_t
chewing_utf8_strncpy(char *dest, const char *src, int n, int end)
{
int i = 0, len = 0;
char *iter = (char*)src;
const char *iter = src;
for( i = 0; i < n; i++ )
{
len += chewing_utf8_byte2len(iter[len]);
}
memcpy(dest, iter, len);
if( end == 1)
((char*)dest)[len] = '\0';
dest[len] = '\0';
return len;
}

void*
chewing_utf8_strseek(char *src, size_t n)
char*
chewing_utf8_strseek(const char *src, size_t n)
{
int i = 0;
char *iter = (char*)src;
const char *iter = src;
for( i = 0; i < n; i++ )
{
iter += chewing_utf8_byte2len(iter[0]);
}
return (void*)iter;
return (char*)iter;
}


int chewing_utf8_is_valid_str(char *str)
int chewing_utf8_is_valid_str(const char *str)
{
if ( str == NULL || *str == '\0' ) {
return 0;
}
while ( *str != '\0' ) {
int len = utf8len_tab[(unsigned char) *str];
int len = utf8len_tab[(unsigned char)*str];
if ( len <= 1 ) {
return 0;
}
str += len;
};
return 1;
}

12 changes: 7 additions & 5 deletions hash-editor/src/chewing-utf8-util.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <stdlib.h>

#ifndef CHEWING_UTF8_UTIL_H
#define CHEWING_UTF8_UTIL_H

int chewing_utf8_strlen(char *str);
int chewing_utf8_byte2len(unsigned char b);
int chewing_utf8_strncpy(char *dest, const char *src, int n, int end);
int chewing_utf8_is_valid_str(char *str);
int chewing_utf8_strlen(char *str);
size_t chewing_utf8_strlen(const char *str);
size_t chewing_utf8_byte2len(unsigned char b);
size_t chewing_utf8_strncpy(char *dest, const char *src, int n, int end);
int chewing_utf8_is_valid_str(const char *str);
char *chewing_utf8_strseek(const char *src, size_t n);

#endif /* CHEWING_UTF8_UTIL_H */
65 changes: 33 additions & 32 deletions hash-editor/src/key2pho-utf8.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//#include "global.h"
//#include "zhuin.h"
#include "chewing-utf8-util.h"
#include "key2pho-utf8.h"
#include <string.h>

const char *zhuin_tab[] = {
static const char *zhuin_tab[] = {
"ㄅㄆㄇㄈㄉㄊㄋㄌㄍㄎㄏㄐㄑㄒㄓㄔㄕㄖㄗㄘㄙ",
"ㄧㄨㄩ",
"ㄚㄛㄜㄝㄞㄟㄠㄡㄢㄣㄤㄥㄦ",
Expand All @@ -13,7 +14,7 @@ static const int zhuin_tab_num[] = {
22, 4, 14, 6
};
static const int shift[] = { 9, 7, 3, 0 };
const static int sb[] = { 31, 3, 15, 7 };
static const int sb[] = { 31, 3, 15, 7 };

//static const char *ph_str =
//"ㄅㄆㄇㄈㄉㄊㄋㄌㄍㄎㄏㄐㄑㄒㄓㄔㄕㄖㄗㄘㄙㄧㄨㄩㄚㄛㄜㄝㄞㄟㄠㄡㄢㄣㄤㄥㄦ˙ˊˇˋ" ;
Expand All @@ -33,16 +34,16 @@ const static int sb[] = { 31, 3, 15, 7 };
/* Read one zhuin string,
return the number it means */
int
zhuin_to_inx( char *zhuin )
zhuin_to_inx(const char *zhuin)
{
char *iter = zhuin, *pos;
const char *iter = zhuin, *pos;
char buf[4];
int len, result = 0;
int i;
/* Here the constant 4 is the number

/* Here the constant 4 is the number
of zhuin_tab and zhuin_tab_num */
/* for( i = 0; i < 3; i++ ) */
/* for( i = 0; i < 3; i++ ) */
for( i = 0; i < 4; i++ )
{
len = chewing_utf8_byte2len( iter[0] );
Expand All @@ -60,17 +61,35 @@ zhuin_to_inx( char *zhuin )
return result;
}

int Uint2PhoneUTF8(char *phone, long seq)
{
int i, j, k;
const char *pos;
char buffer[5];
for ( i = 0, j = 0; i < 4; i++) {
k = ((seq >> shift[ i ]) & sb[ i ] ) - 1;
if ( k >= 0 && (pos = chewing_utf8_strseek( zhuin_tab[ i ], k )) )
{
chewing_utf8_strncpy(buffer, pos, 1, 1);
strcat(phone, buffer);
j++;
}
}
return j;
}

#if 0
/* Read one zhuin string,
return the number of tones*/
int
zhuin_to_tone( char *zhuin )
static int
zhuin_to_tone(const char *zhuin)
{
char *iter = zhuin, *pos = 0;
char buf[4];
int len, result = 0;
int i;
/* Here the constant 4 is the number

/* Here the constant 4 is the number
of zhuin_tab and zhuin_tab_num */
for( i = 0; i < 4; i++ )
{
Expand All @@ -88,24 +107,6 @@ zhuin_to_tone( char *zhuin )
return result;
}

int Uint2PhoneUTF8( char *phone, long seq )
{
int i, j, k;
char *pos;
char buffer[5];
for ( i = 0, j = 0; i < 4; i++) {
k = ((seq >> shift[ i ]) & sb[ i ] ) - 1;
if ( k >= 0 && (pos = chewing_utf8_strseek( zhuin_tab[ i ], k )) )
{
chewing_utf8_strncpy(buffer, pos, 1, 1);
strcat(phone, buffer);
j++;
}
}
return j;
}

#if 0
int Key2PhoneInxUTF8( int key, int type, int kbtype, int searchTimes )
{
char keyStr[ 5 ], bgStr[ 10 ], *p;
Expand Down Expand Up @@ -136,9 +137,9 @@ int Key2PhoUTF8( char *pho, const char *inputkey, int kbtype, int searchTimes )
char *findptr = NULL;
int index;

for (
s = 0, pTarget = key_str[ kbtype ];
s < searchTimes;
for (
s = 0, pTarget = key_str[ kbtype ];
s < searchTimes;
s++, pTarget = findptr + 1 ) {
findptr = strchr( pTarget, inputkey[ i ] );
if ( ! findptr ) {
Expand Down
3 changes: 2 additions & 1 deletion hash-editor/src/key2pho-utf8.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef KEY2PHO_UTF8_H
#define KEY2PHO_UTF8_H

int Uint2PhoneUTF8( char *phone, long seq );
int Uint2PhoneUTF8(char *phone, long seq);
int zhuin_to_inx(const char *zhuin);

#endif /* KEY2PHO_UTF8_H */
6 changes: 3 additions & 3 deletions hash-editor/src/key2pho8.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "key2pho8.h"

const static int shift[] = { 9, 7, 3, 0 };
const static int sb[] = { 31, 3, 15, 7 };
const char *ph_pho[] = { /* number of bits */
static const int shift[] = { 9, 7, 3, 0 };
static const int sb[] = { 31, 3, 15, 7 };
static const char *ph_pho[] = { /* number of bits */
" ㄅㄆㄇㄈㄉㄊㄋㄌㄍㄎㄏㄐㄑㄒㄓㄔㄕㄖㄗㄘㄙ", /* 5 */
" ㄧㄨㄩ", /* 2 */
" ㄚㄛㄜㄝㄞㄟㄠㄡㄢㄣㄤㄥㄦ", /* 4 */
Expand Down
2 changes: 1 addition & 1 deletion hash-editor/src/zhuindict.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct zhuindict*
zhuindict_load_default_dict()
{
int i;
struct entry *p_entry = default_data;
const struct entry *p_entry = default_data;
struct zhuindict *ptr = zhuindict_new();
for (i=0; i<default_data_len; i++) {
zhuindict_addentry_idx(ptr, p_entry->p_char, p_entry->zhuin);
Expand Down