Format source code

This commit is contained in:
Nishi 2026-06-18 13:40:14 +09:00
commit d0be6165c0
165 changed files with 30306 additions and 33687 deletions

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 1994 Sony Corporation
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@ -8,10 +8,10 @@
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@ -19,7 +19,7 @@
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
* Except as contained in this notice, the name of Sony Corporation
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
@ -28,12 +28,11 @@
*/
/*
* $SonyRCSfile: wc16_str.c,v $
* $SonyRevision: 1.3 $
* $SonyRCSfile: wc16_str.c,v $
* $SonyRevision: 1.3 $
* $SonyDate: 1994/11/17 06:49:21 $
*/
#include "sj_sysvdef.h"
#include <stdio.h>
#include <locale.h>
@ -50,119 +49,112 @@
#define FALSE (0)
#endif
#ifndef __sony_news
#define sjis2euc sj3_sjis2euc
#define euc2sjis sj3_euc2sjis
#ifndef __sony_news
#define sjis2euc sj3_sjis2euc
#define euc2sjis sj3_euc2sjis
#define issjis1(c) (((0x81 <= (c)) && ((c) <= 0x9f)) || \
((0xe0 <= (c)) && ((c) <= 0xfc)))
#define iseuc(c) ((0xa1 <= (c)) && ((c) <= 0xfe))
#define iskana(c) ((0xa1 <= (c)) && ((c) <= 0xdf))
#define issjis1(c) (((0x81 <= (c)) && ((c) <= 0x9f)) || \
((0xe0 <= (c)) && ((c) <= 0xfc)))
#define iseuc(c) ((0xa1 <= (c)) && ((c) <= 0xfe))
#define iskana(c) ((0xa1 <= (c)) && ((c) <= 0xdf))
#endif
extern int current_locale;
int
sj3_iswcntrl16(wc)
int sj3_iswcntrl16(wc)
wchar16_t wc;
{
if ((wc < 0x20) || (wc == 0x7f)) return TRUE;
if((wc < 0x20) || (wc == 0x7f)) return TRUE;
return FALSE;
}
int
sj3_iswupper16(wc)
int sj3_iswupper16(wc)
wchar16_t wc;
{
if (((0x40 < wc) && (wc < 0x5b)) ||
((0xa3c0 < wc) && (wc < 0xa3db))) return TRUE;
if(((0x40 < wc) && (wc < 0x5b)) ||
((0xa3c0 < wc) && (wc < 0xa3db))) return TRUE;
return FALSE;
}
int
sj3_iswdigit16(wc)
int sj3_iswdigit16(wc)
wchar16_t wc;
{
if (((0x29 < wc) && (wc < 0x3a)) ||
((0xa3af < wc) && (wc < 0xa3ba))) return TRUE;
if(((0x29 < wc) && (wc < 0x3a)) ||
((0xa3af < wc) && (wc < 0xa3ba))) return TRUE;
return FALSE;
}
int
sj3_iswxdigit16(wc)
int sj3_iswxdigit16(wc)
wchar16_t wc;
{
if (((0x29 < wc) && (wc < 0x3a)) ||
((0xa3af < wc) && (wc < 0xa3ba))) return TRUE;
if(((0x29 < wc) && (wc < 0x3a)) ||
((0xa3af < wc) && (wc < 0xa3ba))) return TRUE;
if (((0x60 < wc) && (wc < 0x67)) ||
((0x40 < wc) && (wc < 0x47))) return TRUE;
if (((0xa3c0 < wc) && (wc < 0xa3c7)) ||
((0xa3e0 < wc) && (wc < 0xa3e6))) return TRUE;
if(((0x60 < wc) && (wc < 0x67)) ||
((0x40 < wc) && (wc < 0x47))) return TRUE;
if(((0xa3c0 < wc) && (wc < 0xa3c7)) ||
((0xa3e0 < wc) && (wc < 0xa3e6))) return TRUE;
return FALSE;
}
int
sj3_wslen16(ws)
wchar16_t *ws;
int sj3_wslen16(ws)
wchar16_t* ws;
{
int i=0;
int i = 0;
if (!ws) return 0;
if(!ws) return 0;
while (*ws++) i++;
while(*ws++) i++;
return i;
}
int
sj3_wscmp16(ws1, ws2)
int sj3_wscmp16(ws1, ws2)
wchar16_t *ws1, *ws2;
{
while ((*ws1 && *ws2) && (*ws1 == *ws2)) {
while((*ws1 && *ws2) && (*ws1 == *ws2)) {
ws1++;
ws2++;
}
if (!*ws1 && !*ws2) return 0;
if (!*ws1) return -1;
if (!*ws2) return 1;
if (*ws1 < *ws2) return -1;
return 1;
}
int
sj3_wsncmp16(ws1, ws2, n)
wchar16_t *ws1, *ws2;
int n;
{
int i=0;
while ((*ws1 && *ws2) && (*ws1 == *ws2) && (i < n)) {
ws1++;
ws2++;
i++;
}
if (!*ws1 && !*ws2) return 0;
if (i == n) return 0;
if (!*ws1) return -1;
if (!*ws2) return 1;
if (*ws1 < *ws2) return -1;
if(!*ws1 && !*ws2) return 0;
if(!*ws1) return -1;
if(!*ws2) return 1;
if(*ws1 < *ws2) return -1;
return 1;
}
wchar16_t *
sj3_wscpy16(ws1, ws2)
int sj3_wsncmp16(ws1, ws2, n)
wchar16_t *ws1, *ws2;
int n;
{
int i = 0;
while((*ws1 && *ws2) && (*ws1 == *ws2) && (i < n)) {
ws1++;
ws2++;
i++;
}
if(!*ws1 && !*ws2) return 0;
if(i == n) return 0;
if(!*ws1) return -1;
if(!*ws2) return 1;
if(*ws1 < *ws2) return -1;
return 1;
}
wchar16_t*
sj3_wscpy16(ws1, ws2)
wchar16_t *ws1, *ws2;
{
wchar16_t *ws;
wchar16_t* ws;
if (!ws2) return NULL;
if(!ws2) return NULL;
ws = ws1;
while (*ws2) {
while(*ws2) {
*ws++ = *ws2++;
}
*ws = 0;
@ -170,38 +162,38 @@ wchar16_t *ws1, *ws2;
return ws1;
}
wchar16_t *
sj3_wsncpy16(ws1, ws2, n)
wchar16_t*
sj3_wsncpy16(ws1, ws2, n)
wchar16_t *ws1, *ws2;
int n;
int n;
{
wchar16_t *ws;
int i=0;
wchar16_t* ws;
int i = 0;
if (!ws2) return NULL;
if(!ws2) return NULL;
ws = ws1;
while (*ws2 && (i < n)) {
while(*ws2 && (i < n)) {
*ws++ = *ws2++;
i++;
}
if (i < n) *ws = 0;
if(i < n) *ws = 0;
return ws1;
}
wchar16_t *
sj3_wscat16(ws1, ws2)
wchar16_t*
sj3_wscat16(ws1, ws2)
wchar16_t *ws1, *ws2;
{
wchar16_t *ws;
wchar16_t* ws;
if (!ws1) return NULL;
if (!ws2) return NULL;
if(!ws1) return NULL;
if(!ws2) return NULL;
ws = ws1;
while (*ws) ws++;
while (*ws2) {
while(*ws) ws++;
while(*ws2) {
*ws++ = *ws2++;
}
*ws = 0;
@ -209,33 +201,32 @@ wchar16_t *ws1, *ws2;
return ws1;
}
wchar16_t
sj3_euc2wc16(code)
sj3_euc2wc16(code)
unsigned int code;
{
wchar16_t wc = 0;
if (((code >> 16) & 0xff) == SS3) {
if(((code >> 16) & 0xff) == SS3) {
wc = code & 0xff7f;
} else if (((code >> 8) & 0xff) == SS2) {
} else if(((code >> 8) & 0xff) == SS2) {
wc = code & 0xff;
} else {
wc = code;
}
}
return wc;
}
wchar16_t
sj3_sjis2wc16(code)
wchar16_t
sj3_sjis2wc16(code)
unsigned int code;
{
unsigned short ch;
if ((code >> 8) & 0xff) {
if((code >> 8) & 0xff) {
ch = sjis2euc(code);
} else if (code & MSB) {
} else if(code & MSB) {
ch = (SS2 << 8) + (code & 0xff);
} else {
return code;
@ -244,21 +235,21 @@ unsigned int code;
}
unsigned int
sj3_wc2euc16(wc)
sj3_wc2euc16(wc)
wchar16_t wc;
{
unsigned int code = 0;
unsigned int code = 0;
unsigned char tmp;
tmp = (wc >> 8) & 0xff;
if (tmp) {
if (wc & MSB) {
if(tmp) {
if(wc & MSB) {
code = wc;
} else {
code = (SS3 << 16) + wc + MSB;
}
} else {
if (wc & MSB) {
if(wc & MSB) {
code = (SS2 << 8) + wc;
} else {
code = wc;
@ -269,53 +260,52 @@ wchar16_t wc;
}
unsigned int
sj3_wc2sjis16(wc)
sj3_wc2sjis16(wc)
wchar16_t wc;
{
unsigned int ch;
ch = sj3_wc2euc16(wc);
if ((ch >> 16) == SS3) {
if((ch >> 16) == SS3) {
return 0;
} else if ((ch >> 8) == SS2) {
} else if((ch >> 8) == SS2) {
return (ch & 0xff);
} else if ((ch >> 8) & 0xff) {
} else if((ch >> 8) & 0xff) {
return euc2sjis(ch);
} else {
return wc;
}
}
int
sj3_wcs2eucs16(mb, ws, n)
unsigned char *mb;
wchar16_t *ws;
int n;
int sj3_wcs2eucs16(mb, ws, n)
unsigned char* mb;
wchar16_t* ws;
int n;
{
int i = 0;
unsigned int code;
int i = 0;
unsigned int code;
unsigned char c;
while (*ws && (i < n)) {
while(*ws && (i < n)) {
code = sj3_wc2euc16(*ws);
if (c = ((code >> 16) & 0xff)) {
if(c = ((code >> 16) & 0xff)) {
*mb++ = c;
i++;
if (i == n) break;
if(i == n) break;
*mb++ = ((code >> 8) & 0xff);
i++;
if (i == n) break;
if(i == n) break;
*mb++ = code & 0xff;
i++;
if (i == n) break;
} else if (c = ((code >> 8) & 0xff)) {
i++;
if(i == n) break;
} else if(c = ((code >> 8) & 0xff)) {
*mb++ = c;
i++;
if (i == n) break;
if(i == n) break;
*mb++ = code & 0xff;
i++;
if (i == n) break;
} else if (c = (code & 0xff)) {
i++;
if(i == n) break;
} else if(c = (code & 0xff)) {
*mb++ = c;
i++;
} else {
@ -324,33 +314,32 @@ int n;
ws++;
}
if (!*ws) {
if(!*ws) {
*mb = '\0';
}
return i;
}
int
sj3_wcs2sjiss16(mb, ws, n)
unsigned char *mb;
wchar16_t *ws;
int n;
int sj3_wcs2sjiss16(mb, ws, n)
unsigned char* mb;
wchar16_t* ws;
int n;
{
int i = 0;
unsigned int code;
int i = 0;
unsigned int code;
unsigned char c;
while (*ws && (i < n)) {
while(*ws && (i < n)) {
code = sj3_wc2sjis16(*ws);
if (c = ((code >> 8) & 0xff)) {
if(c = ((code >> 8) & 0xff)) {
*mb++ = c;
i++;
if (i == n) break;
if(i == n) break;
*mb++ = code & 0xff;
i++;
if (i == n) break;
} else if (c = (code & 0xff)) {
if(i == n) break;
} else if(c = (code & 0xff)) {
*mb++ = c;
i++;
} else {
@ -359,95 +348,89 @@ int n;
ws++;
}
if (!*ws) {
if(!*ws) {
*mb = '\0';
}
return i;
}
int
sj3_eucs2wcs16(ws, mb, n)
wchar16_t *ws;
unsigned char *mb;
int n;
int sj3_eucs2wcs16(ws, mb, n)
wchar16_t* ws;
unsigned char* mb;
int n;
{
int i = 0;
int i = 0;
unsigned int code;
while (*mb && (i < n)) {
if (*mb == SS3) {
while(*mb && (i < n)) {
if(*mb == SS3) {
code = *mb++ << 16;
code += *mb++ << 8;
code += *mb++;
} else if ((*mb == SS2) || (*mb & 0x80)) {
} else if((*mb == SS2) || (*mb & 0x80)) {
code = *mb++ << 8;
code += *mb++;
} else {
code = *mb++;
}
*ws = sj3_euc2wc16(code);
if (!*ws) return -1;
if(!*ws) return -1;
ws++;
i++;
}
if (!*mb) {
if(!*mb) {
*ws = 0;
}
return i;
}
int
sj3_sjiss2wcs16(ws, mb, n)
wchar16_t *ws;
unsigned char *mb;
int n;
int sj3_sjiss2wcs16(ws, mb, n)
wchar16_t* ws;
unsigned char* mb;
int n;
{
int i = 0;
int i = 0;
unsigned int code;
while (*mb && (i < n)) {
if (issjis1(*mb)) {
while(*mb && (i < n)) {
if(issjis1(*mb)) {
code = *mb++ << 8;
code += *mb++;
} else {
code = *mb++;
}
*ws = sj3_sjis2wc16(code);
if (!*ws) return -1;
if(!*ws) return -1;
ws++;
i++;
}
if (!*mb) {
if(!*mb) {
*ws = 0;
}
return i;
}
int
sj3_mbstowcs16(ws, mb, n)
wchar16_t *ws;
unsigned char *mb;
int n;
int sj3_mbstowcs16(ws, mb, n)
wchar16_t* ws;
unsigned char* mb;
int n;
{
if (current_locale == LC_CTYPE_EUC)
return sj3_eucs2wcs16(ws, mb, n);
else
return sj3_sjiss2wcs16(ws, mb, n);
}
int
sj3_wcstombs16(mb, ws, n)
unsigned char *mb;
wchar16_t *ws;
int n;
{
if (current_locale == LC_CTYPE_EUC)
return sj3_wcs2eucs16(mb, ws, n);
if(current_locale == LC_CTYPE_EUC)
return sj3_eucs2wcs16(ws, mb, n);
else
return sj3_wcs2sjiss16(mb, ws, n);
return sj3_sjiss2wcs16(ws, mb, n);
}
int sj3_wcstombs16(mb, ws, n)
unsigned char* mb;
wchar16_t* ws;
int n;
{
if(current_locale == LC_CTYPE_EUC)
return sj3_wcs2eucs16(mb, ws, n);
else
return sj3_wcs2sjiss16(mb, ws, n);
}