|
|
| version 1.13, 2005/03/20 06:09:16 | 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 265 static BRESULT seakey(PFILEH hdl, PFPOS | Line 268 static BRESULT seakey(PFILEH hdl, PFPOS |
| static BRESULT replace(PFILEH hdl, UINT pos, UINT size1, UINT size2) { | static BRESULT replace(PFILEH hdl, UINT pos, UINT size1, UINT size2) { |
| UINT cnt; | UINT cnt; |
| UINT size; | |
| UINT newsize; | UINT newsize; |
| OEMCHAR *p; | OEMCHAR *p; |
| OEMCHAR *q; | OEMCHAR *q; |
| Line 276 static BRESULT replace(PFILEH hdl, UINT | Line 280 static BRESULT replace(PFILEH hdl, UINT |
| } | } |
| cnt = hdl->size - size1; | cnt = hdl->size - size1; |
| if (size1 < size2) { | if (size1 < size2) { |
| newsize = hdl->size + size2 - size1; | size = hdl->size + size2 - size1; |
| if (newsize > hdl->buffers) { | if (size > hdl->buffers) { |
| newsize = (newsize & (PFBUFSIZE - 1)) + PFBUFSIZE; | newsize = (size & (~(PFBUFSIZE - 1))) + PFBUFSIZE; |
| p = (OEMCHAR *)_MALLOC(newsize * sizeof(OEMCHAR), "profile"); | p = (OEMCHAR *)_MALLOC(newsize * sizeof(OEMCHAR), "profile"); |
| if (p == NULL) { | if (p == NULL) { |
| return(FAILURE); | return(FAILURE); |
| } | } |
| CopyMemory(p, hdl->buffer, hdl->buffers * sizeof(OEMCHAR)); | |
| if (hdl->buffer) { | if (hdl->buffer) { |
| CopyMemory(p, hdl->buffer, hdl->buffers * sizeof(OEMCHAR)); | |
| _MFREE(hdl->buffer); | _MFREE(hdl->buffer); |
| } | } |
| hdl->buffer = p; | hdl->buffer = p; |
| hdl->buffers = newsize; | hdl->buffers = newsize; |
| } | } |
| hdl->size = newsize; | hdl->size = size; |
| if (cnt) { | if (cnt) { |
| p = hdl->buffer + size1; | p = hdl->buffer + size1; |
| q = hdl->buffer + size2; | q = hdl->buffer + size2; |
| Line 316 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 338 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 362 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 453 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, |
| Line 512 BRESULT profile_write(const OEMCHAR *app | Line 601 BRESULT profile_write(const OEMCHAR *app |
| } | } |
| buf = hdl->buffer + pfp.pos; | buf = hdl->buffer + pfp.pos; |
| *buf++ = '['; | *buf++ = '['; |
| CopyMemory(buf, app, pfp.applen); | CopyMemory(buf, app, pfp.applen * sizeof(OEMCHAR)); |
| buf += pfp.applen; | buf += pfp.applen; |
| *buf++ = ']'; | *buf++ = ']'; |
| #if defined(OSLINEBREAK_CR) || defined(OSLINEBREAK_CRLF) | #if defined(OSLINEBREAK_CR) || defined(OSLINEBREAK_CRLF) |
| Line 535 BRESULT profile_write(const OEMCHAR *app | Line 624 BRESULT profile_write(const OEMCHAR *app |
| return(FAILURE); | return(FAILURE); |
| } | } |
| buf = hdl->buffer + pfp.pos; | buf = hdl->buffer + pfp.pos; |
| CopyMemory(buf, key, pfp.keylen); | CopyMemory(buf, key, pfp.keylen * sizeof(OEMCHAR)); |
| buf += pfp.keylen; | buf += pfp.keylen; |
| *buf++ = '='; | *buf++ = '='; |
| CopyMemory(buf, data, datalen); | CopyMemory(buf, data, datalen * sizeof(OEMCHAR)); |
| buf += datalen; | buf += datalen; |
| #if defined(OSLINEBREAK_CR) || defined(OSLINEBREAK_CRLF) | #if defined(OSLINEBREAK_CR) || defined(OSLINEBREAK_CRLF) |
| *buf++ = '\r'; | *buf++ = '\r'; |
| Line 645 const PFTBL *pterm; | Line 734 const PFTBL *pterm; |
| == SUCCESS) { | == SUCCESS) { |
| switch(p->itemtype & PFTYPE_MASK) { | switch(p->itemtype & PFTYPE_MASK) { |
| case PFTYPE_STR: | case PFTYPE_STR: |
| milstr_ncpy(p->value, work, p->arg); | milstr_ncpy((OEMCHAR *)p->value, work, p->arg); |
| break; | break; |
| case PFTYPE_BOOL: | case PFTYPE_BOOL: |