* fix issue#46 - "unable to input after a fresh install": use open() instead of fopen()
* kill compiler warnings
* add error handling for open() failure
--- a/sunpinyin2/src/ime-core/ic_history.cpp Thu Nov 12 20:59:45 2009 +0800
+++ b/sunpinyin2/src/ime-core/ic_history.cpp Fri Nov 13 22:15:06 2009 +0800
@@ -39,10 +39,12 @@
#include <config.h>
#endif
+#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <cassert>
#include <sys/stat.h>
+#include <sys/types.h>
#include <algorithm>
#include "ic_history.h"
@@ -228,28 +230,31 @@
return false;
}
-bool CBigramHistory::loadFromFile (const char *fname) {
+bool CBigramHistory::loadFromFile (const char *fname)
+{
+
bool suc = false;
- FILE* fp = fopen (fname, "r+");
-
- if (fp) {
- struct stat info;
-
- fstat (fileno(fp), &info);
- void* buf = malloc (info.st_size);
-
- if (buf) {
- fread (buf, info.st_size, 1, fp);
- suc = loadFromBuffer (buf, info.st_size);
- free (buf);
- }
-
- fclose (fp);
+ int fd = open (fname, O_CREAT, 0600);
+ if (fd == -1) {
+ perror("fopen bi-gram");
+ return suc;
+ }
+
+ struct stat info;
+ fstat (fd, &info);
+ void* buf = malloc (info.st_size);
+
+ if (buf) {
+ read (fd, buf, info.st_size);
+ suc = loadFromBuffer (buf, info.st_size);
+ free (buf);
}
+ close (fd);
return suc;
}
-bool CBigramHistory::saveToFile(const char *fname) {
+bool CBigramHistory::saveToFile(const char *fname)
+{
bool suc = false;
size_t sz = 0;
void* buf = NULL;
--- a/sunpinyin2/src/ime-core/imi_option_event.h Thu Nov 12 20:59:45 2009 +0800
+++ b/sunpinyin2/src/ime-core/imi_option_event.h Fri Nov 13 22:15:06 2009 +0800
@@ -69,7 +69,7 @@
* @return true if the event is consumed, and not intented to be
* sent to another event listener, false otherwise.
*/
- virtual bool onConfigChanged(const COptionEvent& event) { return false; }
+ virtual bool onConfigChanged(const COptionEvent&) { return false; }
void addRef();
void release();
--- a/sunpinyin2/src/ime-core/imi_options.cpp Thu Nov 12 20:59:45 2009 +0800
+++ b/sunpinyin2/src/ime-core/imi_options.cpp Fri Nov 13 22:15:06 2009 +0800
@@ -131,7 +131,7 @@
while (p = strchr(p+1, '/')) {
*p = 0;
if (access(path, F_OK) != 0 && mkdir(path, S_IRWXU) != 0) {
- perror("unabled to mkdir() for user history.\n");
+ perror("unabled to mkdir() for user history");
return false;
}
*p = '/';
--- a/sunpinyin2/src/ime-core/imi_view.h Thu Nov 12 20:59:45 2009 +0800
+++ b/sunpinyin2/src/ime-core/imi_view.h Fri Nov 13 22:15:06 2009 +0800
@@ -178,7 +178,7 @@
void setCandiWindowSize (unsigned size) {m_candiWindowSize = size<10? size: 10;}
virtual unsigned clearIC(void) {m_pIC->clear(); return 0;}
- virtual bool onKeyEvent(const CKeyEvent& key) {return false;}
+ virtual bool onKeyEvent(const CKeyEvent&) {return false;}
virtual void setStatusAttrValue(int key, int value);
virtual int getStatusAttrValue(int key);
--- a/sunpinyin2/src/slm/slm.cpp Thu Nov 12 20:59:45 2009 +0800
+++ b/sunpinyin2/src/slm/slm.cpp Fri Nov 13 22:15:06 2009 +0800
@@ -57,6 +57,11 @@
CThreadSlm::load(const char* fname, bool MMap)
{
int fd = open(fname, O_RDONLY);
+ if (fd == -1) {
+ perror("open lm");
+ return false;
+ }
+
m_bufSize = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
@@ -95,6 +100,7 @@
return false;
}
if (read(fd, m_buf, m_bufSize) != m_bufSize) {
+ perror("read lm");
delete [] m_buf; m_buf = NULL;
close(fd);
return false;
--- a/sunpinyin2/wrapper/ibus/src/debug.h Thu Nov 12 20:59:45 2009 +0800
+++ b/sunpinyin2/wrapper/ibus/src/debug.h Fri Nov 13 22:15:06 2009 +0800
@@ -4,6 +4,7 @@
#include <iostream>
#include <iomanip>
#include <fstream>
+#include <cerrno>
namespace ibus
{
--- a/sunpinyin2/wrapper/ibus/src/engine_impl.cpp Thu Nov 12 20:59:45 2009 +0800
+++ b/sunpinyin2/wrapper/ibus/src/engine_impl.cpp Fri Nov 13 22:15:06 2009 +0800
@@ -90,7 +90,7 @@
}
static CKeyEvent
-translate_key(guint key_val, guint key_code, guint modifiers)
+translate_key(guint key_val, guint /*key_code*/, guint modifiers)
{
// XXX: may need to move this logic into CKeyEvent
if (isprint(key_val) && !isspace(key_val) && !(modifiers & IM_CTRL_MASK)) {
@@ -163,7 +163,7 @@
}
void
-EngineImpl::property_activate (const std::string& property, unsigned state)
+EngineImpl::property_activate (const std::string& property, unsigned /*state*/)
{
if (m_status_prop->toggle(property)) {
m_pv->setStatusAttrValue(CIMIWinHandler::STATUS_ID_CN,