|
|
| version 1.15, 2005/03/24 04:40:33 | version 1.16, 2005/04/01 15:35:49 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #include "strres.h" | #include "strres.h" |
| #include "dosio.h" | |
| #include "textfile.h" | #include "textfile.h" |
| #include "profile.h" | #include "profile.h" |
| #if defined(SUPPORT_TEXTCNV) | |
| #include "textcnv.h" | |
| #endif | |
| #include "dosio.h" | |
| static void strdelspace(OEMCHAR **buf, int *size) { | static void strdelspace(OEMCHAR **buf, int *size) { |
| Line 109 gden_err0: | Line 112 gden_err0: |
| const OEMCHAR *profile_getarg(const OEMCHAR *str, OEMCHAR *buf, UINT leng) { | const OEMCHAR *profile_getarg(const OEMCHAR *str, OEMCHAR *buf, UINT leng) { |
| UINT8 c; | OEMCHAR c; |
| if (leng) { | if (leng) { |
| leng--; | leng--; |
| Line 118 const OEMCHAR *profile_getarg(const OEMC | Line 121 const OEMCHAR *profile_getarg(const OEMC |
| buf = NULL; | buf = NULL; |
| } | } |
| if (str) { | if (str) { |
| c = (UINT8)*str; | c = *str; |
| while(((c - 1) & 0xff) < 0x20) { | while((c > 0) && (c <= 0x20)) { |
| str++; | str++; |
| c = (UINT8)*str; | c = *str; |
| } | } |
| if (c == 0) { | if (c == 0) { |
| str = NULL; | str = NULL; |
| } | } |
| } | } |
| if (str) { | if (str) { |
| c = (UINT8)*str; | c = *str; |
| while(c > 0x20) { | while((c < 0) || (c > 0x20)) { |
| if (leng) { | if (leng) { |
| *buf++ = c; | *buf++ = c; |
| leng--; | leng--; |
| } | } |
| str++; | str++; |
| c = (UINT8)*str; | c = *str; |
| } | } |
| } | } |
| if (buf) { | if (buf) { |
| Line 317 static BRESULT replace(PFILEH hdl, UINT | Line 320 static BRESULT replace(PFILEH hdl, UINT |
| static PFILEH registfile(FILEH fh) { | static PFILEH registfile(FILEH fh) { |
| UINT hdrsize; | |
| UINT srcwidth; | |
| BOOL xendian; | |
| UINT rsize; | UINT rsize; |
| #if defined(SUPPORT_TEXTCNV) | |
| TCINF inf; | |
| #endif | |
| UINT hdrsize; | |
| UINT width; | |
| UINT8 hdr[4]; | UINT8 hdr[4]; |
| UINT size; | UINT size; |
| UINT newsize; | UINT newsize; |
| OEMCHAR *buf; | void *buf; |
| #if defined(SUPPORT_TEXTCNV) | |
| void *buf2; | |
| #endif | |
| PFILEH ret; | PFILEH ret; |
| hdrsize = 0; | |
| srcwidth = 1; | |
| xendian = FALSE; | |
| rsize = file_read(fh, hdr, sizeof(hdr)); | rsize = file_read(fh, hdr, sizeof(hdr)); |
| #if defined(SUPPORT_TEXTCNV) | |
| if (textcnv_getinfo(&inf, hdr, rsize) == 0) { | |
| goto rf_err1; | |
| } | |
| if (!(inf.caps & TEXTCNV_READ)) { | |
| goto rf_err1; | |
| } | |
| if ((inf.width != 1) && (inf.width != 2)) { | |
| goto rf_err1; | |
| } | |
| hdrsize = inf.hdrsize; | |
| width = inf.width; | |
| #else | |
| hdrsize = 0; | |
| width = 1; | |
| if ((rsize >= 3) && | if ((rsize >= 3) && |
| (hdr[0] == 0xef) && (hdr[1] == 0xbb) && (hdr[2] == 0xbf)) { | (hdr[0] == 0xef) && (hdr[1] == 0xbb) && (hdr[2] == 0xbf)) { |
| // UTF-8 | // UTF-8 |
| Line 339 static PFILEH registfile(FILEH fh) { | Line 359 static PFILEH registfile(FILEH fh) { |
| else if ((rsize >= 2) && (hdr[0] == 0xff) && (hdr[1] == 0xfe)) { | else if ((rsize >= 2) && (hdr[0] == 0xff) && (hdr[1] == 0xfe)) { |
| // UCSLE | // UCSLE |
| hdrsize = 2; | hdrsize = 2; |
| srcwidth = 2; | width = 2; |
| #if defined(BYTESEX_BIG) | #if defined(BYTESEX_BIG) |
| xendian = TRUE; | goto rf_err1; |
| #endif | #endif |
| } | } |
| else if ((rsize >= 2) && (hdr[0] == 0xfe) && (hdr[1] == 0xff)) { | else if ((rsize >= 2) && (hdr[0] == 0xfe) && (hdr[1] == 0xff)) { |
| // UCS2BE | // UCS2BE |
| hdrsize = 2; | hdrsize = 2; |
| srcwidth = 2; | width = 2; |
| #if defined(BYTESEX_LITTLE) | #if defined(BYTESEX_LITTLE) |
| xendian = TRUE; | goto rf_err1; |
| #endif | #endif |
| } | } |
| if (width != sizeof(OEMCHAR)) { | |
| if (srcwidth != sizeof(OEMCHAR)) { | |
| goto rf_err1; | goto rf_err1; |
| } | } |
| #endif | |
| size = file_getsize(fh); | size = file_getsize(fh); |
| if (size < hdrsize) { | if (size < hdrsize) { |
| goto rf_err1; | goto rf_err1; |
| Line 363 static PFILEH registfile(FILEH fh) { | Line 384 static PFILEH registfile(FILEH fh) { |
| if (file_seek(fh, (long)hdrsize, FSEEK_SET) != (long)hdrsize) { | if (file_seek(fh, (long)hdrsize, FSEEK_SET) != (long)hdrsize) { |
| goto rf_err1; | goto rf_err1; |
| } | } |
| size = (size - hdrsize) / srcwidth; | size = (size - hdrsize) / width; |
| newsize = (size & (~(PFBUFSIZE - 1))) + PFBUFSIZE; | newsize = (size & (~(PFBUFSIZE - 1))) + PFBUFSIZE; |
| buf = (OEMCHAR *)_MALLOC(newsize * srcwidth, "profile"); | buf = _MALLOC(newsize * width, "profile"); |
| if (buf == NULL) { | if (buf == NULL) { |
| goto rf_err1; | goto rf_err1; |
| } | } |
| rsize = file_read(fh, buf, newsize * srcwidth) / srcwidth; | rsize = file_read(fh, buf, newsize * width) / width; |
| #if defined(SUPPORT_TEXTCNV) | |
| if (inf.xendian) { | |
| textcnv_swapendian16(buf, rsize); | |
| } | |
| if (inf.tooem) { | |
| size = (inf.tooem)(NULL, 0, buf, rsize); | |
| newsize = (size & (~(PFBUFSIZE - 1))) + PFBUFSIZE; | |
| buf2 = _MALLOC(newsize * sizeof(OEMCHAR), "profile tmp"); | |
| if (buf2 == NULL) { | |
| goto rf_err2; | |
| } | |
| (inf.tooem)(buf2, size, buf, rsize); | |
| _MFREE(buf); | |
| buf = buf2; | |
| rsize = size; | |
| } | |
| #endif // defined(SUPPORT_TEXTCNV) | |
| ret = (PFILEH)_MALLOC(sizeof(_PFILEH), "profile"); | ret = (PFILEH)_MALLOC(sizeof(_PFILEH), "profile"); |
| if (ret == NULL) { | if (ret == NULL) { |
| Line 454 PFILEH profile_open(const OEMCHAR *filen | Line 492 PFILEH profile_open(const OEMCHAR *filen |
| void profile_close(PFILEH hdl) { | void profile_close(PFILEH hdl) { |
| void *buf; | |
| UINT bufsize; | |
| #if defined(SUPPORT_TEXTCNV) | |
| TCINF inf; | |
| void *buf2; | |
| UINT buf2size; | |
| #endif | |
| UINT hdrsize; | |
| UINT width; | |
| FILEH fh; | FILEH fh; |
| if (hdl) { | if (hdl == NULL) { |
| if (hdl->flag & PFILEH_MODIFY) { | return; |
| fh = file_create(hdl->path); | } |
| if (fh != FILEH_INVALID) { | buf = hdl->buffer; |
| file_write(fh, hdl->hdr, hdl->hdrsize); | bufsize = hdl->size; |
| file_write(fh, hdl->buffer, hdl->size * sizeof(OEMCHAR)); | if (hdl->flag & PFILEH_MODIFY) { |
| file_close(fh); | #if defined(SUPPORT_TEXTCNV) |
| } | if (textcnv_getinfo(&inf, hdl->hdr, hdl->hdrsize) == 0) { |
| goto wf_err1; | |
| } | |
| if (!(inf.caps & TEXTCNV_WRITE)) { | |
| goto wf_err1; | |
| } | |
| if ((inf.width != 1) && (inf.width != 2)) { | |
| goto wf_err1; | |
| } | |
| if (inf.fromoem) { | |
| buf2size = (inf.fromoem)(NULL, 0, buf, bufsize); | |
| buf2 = _MALLOC(buf2size * inf.width, "profile tmp"); | |
| if (buf2 == NULL) { | |
| goto wf_err1; | |
| } | |
| (inf.fromoem)(buf2, buf2size, buf, bufsize); | |
| _MFREE(buf); | |
| buf = buf2; | |
| bufsize = buf2size; | |
| } | |
| if (inf.xendian) { | |
| textcnv_swapendian16(buf, bufsize); | |
| } | |
| hdrsize = inf.hdrsize; | |
| width = inf.width; | |
| #else // defined(SUPPORT_TEXTCNV) | |
| hdrsize = hdl->hdrsize; | |
| width = sizeof(OEMCHAR); | |
| #endif // defined(SUPPORT_TEXTCNV) | |
| fh = file_create(hdl->path); | |
| if (fh == FILEH_INVALID) { | |
| goto wf_err1; | |
| } | } |
| _MFREE(hdl); | if (hdrsize) { |
| file_write(fh, hdl->hdr, hdrsize); | |
| } | |
| file_write(fh, buf, bufsize * width); | |
| file_close(fh); | |
| } | |
| wf_err1: | |
| if (buf) { | |
| _MFREE(buf); | |
| } | } |
| _MFREE(hdl); | |
| } | } |
| BRESULT profile_read(const OEMCHAR *app, const OEMCHAR *key, | BRESULT profile_read(const OEMCHAR *app, const OEMCHAR *key, |