diff -uNr ls/Makefile jls/Makefile --- ls/Makefile Fri Apr 19 22:22:45 2002 +++ jls/Makefile Sat Jun 12 18:32:29 2004 @@ -1,8 +1,18 @@ # @(#)Makefile 8.1 (Berkeley) 6/2/93 # $FreeBSD$ -PROG= ls -SRCS= cmp.c ls.c print.c util.c +PREFIX?= /usr/local +BINDIR= ${PREFIX}/bin +MANDIR= ${PREFIX}/man/man + +PROG= jls +SRCS= cmp.c ls.c print.c util.c samba.c jconv.c +.if !defined(WITHOUT_CAP) +CFLAGS+= -DJAPANESE_EXTENSION -DSAMBA_CAP_EXTENSION +.else +CFLAGS+= -DJAPANESE_EXTENSION +.endif + DPADD= ${LIBM} LDADD= -lm diff -uNr ls/README jls/README --- ls/README Thu Jan 1 09:00:00 1970 +++ jls/README Sat Jun 12 18:44:54 2004 @@ -0,0 +1,43 @@ +Japanized ls. + +What's? +======= + +This is japanized ls. + + - support EUC/JIS/SJIS + - support `samba cap' ed japanese filename + +This is derived from /usr/src/bin/ls in FreeBSD distribution. + + +ChangeLog +========= + + 04 Jan 1999 + - initial version + + 06 Jan 1999 + - Release version 0.1. + - fix printlink bug + + 09 Mar 2001 + - Release version 0.2. + - fix print filename which is started with JISX0212 characters. + + 12 Oct 2001 + - Release version 0.3. + - fix conversion from Shift-JIS Hankanku Kana to EUC-JP Hankaku Kana. + - fix iskanji1st check. + - Use "^[(I" instead of SI(0x0f). + - Always use Shift-JIS coding when SAMBA cap/hex. + + 21 Feb 2002 + - Fix this bug: Always use Shift-JIS coding when SAMBA cap/hex. + + 12 Jun 2004 + - Base distribution changed over to ls in 4.9.0-RELEASE. (worked by kazami) + +--- +shige +kazami diff -uNr ls/extern.h jls/extern.h --- ls/extern.h Sun Nov 17 19:27:34 2002 +++ jls/extern.h Sat Jun 12 18:33:48 2004 @@ -62,3 +62,16 @@ extern char *attrs_off; extern char *enter_bold; #endif + +#ifdef SAMBA_CAP_EXTENSION +int samba_cap (const char *); +#endif + +#ifdef JAPANESE_EXTENSION +void sjistoeuc (const char *); +void sjistojis (const char *); +void euctosjis (const char *); +void euctojis (const char *); +void jistosjis (const char *); +void jistoeuc (const char *); +#endif diff -uNr ls/jconv.c jls/jconv.c --- ls/jconv.c Thu Jan 1 09:00:00 1970 +++ jls/jconv.c Wed Oct 17 01:01:35 2001 @@ -0,0 +1,878 @@ +/* + * Copyright (c) 1989, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Michael Fischbein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +/* + * written by shige + */ + +#include "jconv.h" +#include +#include + +static unsigned char kanji1st = 0; +static unsigned char kanji2nd = 0; +unsigned char esc_set1byte[2] = {'(', 'B'}; +unsigned char esc_set2byte[2] = {'$', 'B'}; +unsigned char esc_set1bytekana[2] = {'(', 'I'}; + +/* convert JIS code to Shift-JIS code */ +static void jistojms(unsigned char c1, unsigned char c2) +{ + if (c1 & 1) { + c1 = (c1 >> 1) + 0x71; + c2 += 0x1f; + if (c2 >= 0x7f) + c2++; + } else { + c1 = (c1 >> 1) + 0x70; + c2 += 0x7e; + } + if (c1 > 0x9f) + c1 += 0x40; + + kanji1st = c1; + kanji2nd = c2; + return; +} + +/* convert Shift-JIS code to JIS code */ +static void jmstojis(unsigned char c1, unsigned char c2) +{ + c1 -= (c1 <= 0x9f) ? 0x70 : 0xb0; + c1 <<= 1; + if (c2 < 0x9f) { + c2 -= (c2 < 0x7f) ? 0x1f : 0x20; + c1--; + } + else { + c2 -= 0x7e; + } + + kanji1st = c1; + kanji2nd = c2; + return; +} + +/* Shift-JIS to EUC */ +void sjistoeuc(char *s) +{ + unsigned char c1, c2; + char *sp, *buf; + + buf = sp = strdup(s); + while (*sp != '\0') { + c1 = (unsigned char)(*sp++); + if (c1 < 0x80) { + *s++ = (char)c1; + } else if (iskanji1st(c1)) { + c2 = (unsigned char)(*sp++); + if (c2 == '\0') { + *s++ = (char)c1; + break; + } + if (iskanji2nd(c2)) { + jmstojis(c1, c2); + *s++ = (char)(kanji1st | 0x80); + *s++ = (char)(kanji2nd | 0x80); + } else { + *s++ = (char)c1; + *s++ = (char)c2; + } + } else if (iskana(c1)) { + *s++ = 0x8e; + *s++ = (char)c1; + } else { + *s++ = (char)c1; + } + } + *s = '\0'; + + free(buf); + return; +} + +/* Shift-JIS to JIS */ +void sjistojis(char *s) +{ + unsigned char c1, c2, c3; + char state, kana; + char _7bit; + char *t; + + t = (char *)malloc(2 * strlen(s)); + strcpy(t, s); + /* _7bit = _7bitmode; */ + _7bit = 1; + state = kana = 0; + + c1 = (unsigned char)(*t++); + while (1) { + if (c1 < 0x80) { + if (state) { + /* escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + state = 0; + } + else if (kana) { +#if 0 + *s++ = SI; +#else + *s++ = ESC; + *s++ = esc_set1byte[0]; + *s++ = esc_set1byte[1]; +#endif + kana = 0; + } + *s++ = c1; + } else if (iskanji1st(c1)) { + c2 = (unsigned char)(*t++); + if (c2 == '\0') { + /* JIS end */ + if (kana) { +#if 0 + *s++ = SI; +#else + *s++ = ESC; + *s++ = esc_set1byte[0]; + *s++ = esc_set1byte[1]; +#endif + } else if (state) { + /* JIS escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + } + *s++ = c1; + break; + } + if (!state) { + if (kana) { +#if 0 + *s++ = SI; +#else + *s++ = ESC; + *s++ = esc_set1byte[0]; + *s++ = esc_set1byte[1]; +#endif + kana = 0; + } + /* escape sequence for 2 byte character */ + *s++ = ESC; + *s++ = esc_set2byte[0]; + if (esc_set2byte[1]) + *s++ = esc_set2byte[1]; + state = 1; + } + if (iskanji2nd(c2)) { + jmstojis(c1, c2); + *s++ = kanji1st; + *s++ = kanji2nd; + } else { + *s++ = c1; + *s++ = c2; + } + } else if (iskana(c1)) { + if (state) { + /* escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + state = 0; + } + if (_7bit) { + if (!kana) { +#if 0 + *s++ = SO; +#else + *s++ = ESC; + *s++ = esc_set1bytekana[0]; + *s++ = esc_set1bytekana[1]; +#endif + kana = 1; + } + c1 &= 0x7f; + } + *s++ = c1; + } else { + if (state) { + /* escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + state = 0; + } else if (kana) { +#if 0 + *s++ = SI; +#else + *s++ = ESC; + *s++ = esc_set1byte[0]; + *s++ = esc_set1byte[1]; +#endif + kana = 0; + } + *s++ = c1; + } + + /* next chars */ + c1 = (unsigned char)(*t++); + if (c1 == '\0') { + /* JIS end */ + if (kana) { +#if 0 + *s++ = SI; +#else + *s++ = ESC; + *s++ = esc_set1byte[0]; + *s++ = esc_set1byte[1]; +#endif + } else if (state) { + /* JIS escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + } + break; + } + } + *s = '\0'; + + return; +} + +/* EUC to Shift-JIS */ +void euctosjis(char *s) +{ + unsigned char c1, c2; + char *t; + + t = (char *)malloc(2 * strlen(s)); + strcpy(t, s); + + while (*t != '\0') { + c1 = (unsigned char)(*t++); + if (c1 < 0x80) { + *s++ = (char)c1; + } else if (iseuc(c1)) { + c2 = (unsigned char)(*t++); + if (c2 == '\0') { + *s++ = (char)c1; + break; + } + if (iseuc(c2)) { + jistojms(c1 & 0x7f, c2 & 0x7f); + *s++ = (char)kanji1st; + *s++ = (char)kanji2nd; + } else { + *s++ = (char)c1; + *s++ = (char)c2; + } + } else if (c1 == 0x8e) { + c2 = (unsigned char)(*t++); + if (c2 == '\0') + break; + *s++ = (char)c2; + } else if (c1 == 0x8f) { + c2 = (unsigned char)(*t++); + if (c2 == '\0') + break; + *s++ = (char)c2; + c2 = (unsigned char)(*t++); + if (c2 == '\0') + break; + *s++ = (char)c2; + } else { + *s++ = (char)c1; + } + } + *s = '\0'; + + return; +} + +/* EUC to JIS */ +void euctojis(char *s) +{ + unsigned char c1, c2, c3; + char state, kana; + char _7bit; + char *t; + + t = (char *)malloc(2 * strlen(s)); + strcpy(t, s); + /* _7bit = _7bitmode; */ + _7bit = 1; + state = kana = 0; + + c1 = (unsigned char)(*t++); + while (*t != '\0') { + if (c1 < 0x80) { + if (state) { + /* JIS escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + state = 0; + } + else if (kana) { + *s++ = SI; + kana = 0; + } + *s++ = c1; + } else if (iseuc(c1)) { + c2 = (unsigned char)(*t++); + if (c2 == '\0') { + /* JIS end */ + if (kana) { + *s++ = SI; + } else if (state) { + /* JIS escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + } + + *s++ = c1; + break; + } + if (!state) { + if (kana) { + *s++ = SI; + kana = 0; + } + /* JIS escape sequence for 2 byte character */ + *s++ = ESC; + *s++ = esc_set2byte[0]; + if (esc_set2byte[1]) + *s++ = esc_set2byte[1]; + state = 1; + } + if (iseuc(c2)) { + *s++ = (char)(c1 & 0x7f); + *s++ = (char)(c2 & 0x7f); + } else { + *s++ = (char)c1; + *s++ = (char)c2; + } + } else if (c1 == 0x8e) { + c1 = (unsigned char)(*t++); + if (c1 == '\0') { + /* JIS end */ + if (kana) { + *s++ = SI; + } else if (state) { + /* JIS escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + } + break; + } + if (state) { + /* JIS escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + state = 0; + } + if (_7bit) { + if (!kana) { + *s++ = SO; + kana = 1; + } + c1 &= 0x7f; + } + *s++ = c1; + } else if (c1 == 0x8f) { + c1 = (unsigned char)(*t++); + if (c1 == '\0') { + /* JIS end */ + if (kana) { + *s++ = SI; + } else if (state) { + /* JIS escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + } + break; + } + c2 = (unsigned char)(*t++); + if (c2 == '\0') { + /* JIS end */ + if (kana) { + *s++ = SI; + } else if (state) { + /* JIS escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + } + *s++ = c1; + break; + } + if (!state) { + if (kana) { + *s++ = SI; + kana = 0; + } + /* JIS escape sequence for 2 byte character */ + *s++ = ESC; + *s++ = esc_set2byte[0]; + if (esc_set2byte[1]) + *s++ = esc_set2byte[1]; + state = 1; + } + *s++ = c1; + *s++ = c2; + } else { + if (state) { + /* JIS escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + state = 0; + } else if (kana) { + *s++ = SI; + kana = 0; + } + *s++ = c1; + } + + /* next chars */ + c1 = (unsigned char)(*t++); + if (c1 == '\0') { + /* JIS end */ + if (kana) { + *s++ = SI; + } else if (state) { + /* JIS escape sequence for 1 byte character */ + *s++ = ESC; + *s++ = esc_set1byte[0]; + if (esc_set1byte[1]) + *s++ = esc_set1byte[1]; + } + break; + } + } + *s = '\0'; + + return; +} + +/* JIS to EUC */ +void jistoeuc(char *s) +{ + unsigned char c1, c2, c3; + char state, kana; + char _7bit; + char *t; + + t = (char *)malloc(2 * strlen(s)); + strcpy(t, s); + /* _7bit = _7bitmode; */ + _7bit = 1; + state = kana = 0; + + c1 = (unsigned char)(*t++); + while (*t != '\0') { + if (c1 == ESC) { + c2 = (unsigned char)(*t++); + if (c2 == '\0') { + *s++ = (char)c1; + break; + } + switch (c2) { + case '$': + c3 = (unsigned char)(*t++); + if (c3 == '\0') { + *s++ = (char)c1; + *s++ = (char)c2; + break; + } + if (c3 == 'B' || c3 == '@') + state = 1; + else { + *s++ = (char)c1; + *s++ = (char)c2; + c1 = c3; + continue; + } + break; + case '(': + c3 = (unsigned char)(*t++); + if (c3 == '\0') { + *s++ = (char)c1; + *s++ = (char)c2; + break; + } + if (c3 == 'J' || c3 == 'B' || c3 == 'H') + state = 0; + else { + *s++ = (char)c1; + *s++ = (char)c2; + c1 = c3; + continue; + } + break; + case 'K': + state = 1; + break; + case 'H': + state = 0; + break; + default: + *s++ = (char)c1; + continue; + } + } else if (c1 <= 0x20 || c1 == 0x7f) { + if (_7bit && (c1 == SO || c1 == SI)) + kana = c1 == SO; + else + *s++ = (char)c1; + } else if (state) { + c2 = (unsigned char)(*t++); + if (c2 == '\0') { + *s++ = (char)c1; + break; + } + if (c2 <= 0x20 || c2 == 0x7f) { + *s++ = (char)c1; + c1 = c2; + continue; + } + *s++ = (char)(c1 | 0x80); + *s++ = (char)(c2 | 0x80); + } else { + if (_7bit && kana) + c1 |= 0x80; + if (iskana(c1)) + *s++ = (char)0x8e; + *s++ = (char)c1; + } + + /* next chars */ + c1 = (unsigned char)(*t++); + if (c1 == '\0') { + break; + } + } + *s = '\0'; + + return; +} + +/* JIS to Shift-JIS */ +void jistosjis(char *s) +{ + unsigned char c1, c2, c3; + char state, kana; + char _7bit; + char *t; + + t = (char *)malloc(2 * strlen(s)); + strcpy(t, s); + /* _7bit = _7bitmode; */ + _7bit = 1; + state = kana = 0; + + c1 = (unsigned char)(*t++); + while (*t != '\0') { + if (c1 == ESC) { + c2 = (unsigned char)(*t++); + if (c2 == '\0') { + *s++ = (char)c1; + break; + } + switch (c2) { + case '$': + c3 = (unsigned char)(*t++); + if (c3 == '\0') { + *s++ = (char)c1; + *s++ = (char)c2; + break; + } + if (c3 == 'B' || c3 == '@') + state = 1; + else { + *s++ = (char)c1; + *s++ = (char)c2; + c1 = c3; + continue; + } + break; + case '(': + c3 = (unsigned char)(*t++); + if (c3 == '\0') { + *s++ = (char)c1; + *s++ = (char)c2; + break; + } + if (c3 == 'J' || c3 == 'B' || c3 == 'H') + state = 0; + else { + *s++ = (char)c1; + *s++ = (char)c2; + c1 = c3; + continue; + } + break; + case 'K': + state = 1; + break; + case 'H': + state = 0; + break; + default: + *s++ = (char)c1; + continue; + } + } else if (c1 <= 0x20 || c1 == 0x7f) { + if (_7bit && (c1 == SO || c1 == SI)) + kana = c1 == SO; + else + *s++ = (char)c1; + } else if (state) { + c2 = (unsigned char)(*t++); + if (c2 == '\0') { + *s++ = (char)c1; + break; + } + if (c2 <= 0x20) { + *s++ = (char)c1; + c1 = c2; + continue; + } + if (c1 < 0x80 && isjis(c2)) { + jistojms(c1, c2); + *s++ = (char)kanji1st; + *s++ = (char)kanji2nd; + } else { + *s++ = (char)c1; + *s++ = (char)c2; + } + } else { + if (_7bit && kana) + c1 |= 0x80; + *s++ = (char)c1; + } + + /* next chars */ + c1 = (unsigned char)(*t++); + if (c1 == '\0') { + break; + } + } + *s = '\0'; + + return; +} + +/* scan forward if Shift-JIS code or JIS code exists */ +int checkforward(p, size) +unsigned char *p; +unsigned int size; +{ + unsigned char c; + + if (size > 1024) + size = 1024; + if (size == 0) + return EUC; + c = *p++; + while (1) { + if (c == ESC) { + if (--size == 0) + break; + if ((c = *p++) == '$') { + if (--size == 0) + break; + if ((c = *p++) == 'B' || c == '@') + return JIS; + else + continue; + } + else if (c == 'K') + return JIS; + else + continue; + } + else if (c >= 0x81) { + if (c == 0x8e) { + if (--size == 0) + break; + p++; + } + else if (c <= 0x9f) { + if (--size == 0) + break; + c = *p++; + if (iskanji2nd(c)) + return SJIS; + else + continue; + } + else if (c >= 0xa1 && c <= 0xdf) { + if (--size == 0) + break; + c = *p++; + if (iskana(c)) + continue; + else if (iseuc(c)) + return EUC; + else + continue; + } + else if (c != 0xa0) + return EUC; + } + if (--size == 0) + break; + c = *p++; + } + return EUC; +} + +/* detect kanji code */ +int detectcode(buf, size) +unsigned char *buf; +unsigned int size; +{ + register unsigned char *p, c; + register unsigned int count; + int unknownstat; + + count = size; + if (count == 0) + return ASCII; + p = buf; + unknownstat = 0; + c = *p++; + while (1) { + if (c == ESC) { + if (--count == 0) + break; + if ((c = *p++) == '$') { + if (--count == 0) + break; + if ((c = *p++) == 'B' || c == '@') + return JIS; + else + continue; + } + else if (c == 'K') + return JIS; + else + continue; + } + else if (c >= 0x81) { + if (c == 0x8e) { + if (--count == 0) + break; + c = *p++; + if (iskana(c)) + unknownstat |= 1; + else if (iskanji2nd(c)) + return SJIS; + else + continue; + } + else if (c <= 0x9f) { + if (--count == 0) + break; + c = *p++; + if (iskanji2nd(c)) + return SJIS; + else + continue; + } + else if (c >= 0xa1 && c <= 0xdf || c == 0xfd || c == 0xfe) { + if (--count == 0) + break; + c = *p++; + if (iseuc(c)) + if (iskana(c)) + return checkforward(p, count - 1); + else + return EUC; + else + continue; + } + else if (c >= 0xe0 && c <= 0xfc) { + if (--count == 0) + break; + c = *p++; + if (iskanji2nd(c)) + if (iseuc(c)) + unknownstat |= 1; + else + return SJIS; + else + if (iseuc(c)) + return EUC; + else + continue; + } + } + if (--count == 0) + break; + c = *p++; + } + switch (unknownstat) { + case 1: + case 3: + return UNKNOWN; + case 2: + return SJIS; + default: + return ASCII; + } +} diff -uNr ls/jconv.h jls/jconv.h --- ls/jconv.h Thu Jan 1 09:00:00 1970 +++ jls/jconv.h Wed Oct 17 01:01:35 2001 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1989, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Michael Fischbein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +/* + * written by shige + */ + +#define SJIS 1 +#define EUC 2 +#define JIS 3 +#define ASCII 4 +#define UNKNOWN 5 +#define iskanji1st(c) (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xfc)) +#define iskanji2nd(c) ((c) >= 0x40 && (c) <= 0xfc && (c) != 0x7f) +#define iseuc(c) ((c) >= 0xa1 && (c) <= 0xfe) +#define isjis(c) ((c) >= 0x21 && (c) <= 0x7f) +#define iskana(c) ((c) >= 0xa0 && (c) <= 0xdf) + +#define ESC 0x1b +#define CTRLZ 0x1a +#define SO 0x0e +#define SI 0x0f +#define NEWJIS_K "$B" +#define NEWJIS_A "(J" +#define NEWJIS2_K "$B" +#define NEWJIS2_A "(B" +#define OLDJIS_K "$@" +#define OLDJIS_A "(J" +#define NECJIS_K "K" +#define NECJIS_A "H" diff -uNr ls/jls.1 jls/jls.1 --- ls/jls.1 Wed Aug 13 18:22:52 2003 +++ jls/jls.1 Sat Jun 12 19:13:52 2004 @@ -35,15 +35,15 @@ .\" @(#)ls.1 8.7 (Berkeley) 7/29/94 .\" $FreeBSD$ .\" -.Dd July 8, 2002 -.Dt LS 1 +.Dd July 12, 2004 +.Dt JLS 1 .Os .Sh NAME -.Nm ls +.Nm jls .Nd list directory contents .Sh SYNOPSIS .Nm -.Op Fl ABCFGHLPRTWabcdfghiklmnopqrstuwx1 +.Op Fl ABCEFGHJLPQRSTWabcdfghiklmnopqrstuwx1 .Op Ar .Sh DESCRIPTION For each operand that names a @@ -248,6 +248,15 @@ one entry per line. This is the default when output is not to a terminal. +.It Fl E +Display in EUC (Extended Unix Code) Kanji code; +this is the default. +.It Fl J +Display in JIS (Japanese Industrial Standard) Kanji code. +.It Fl S +Display in Shift-JIS (MS Kanji code) Kanji code. +.It Fl Q +Print without decode its CAP encoded filename. .El .Pp The diff -uNr ls/ls.c jls/ls.c --- ls/ls.c Sun Nov 17 19:27:34 2002 +++ jls/ls.c Sat Jun 12 18:34:01 2004 @@ -71,6 +71,9 @@ #include "ls.h" #include "extern.h" +#ifdef JAPANESE_EXTENSION +#include "jconv.h" +#endif /* * Upward approximation of the maximum number of characters needed to @@ -126,6 +129,12 @@ char *attrs_off; /* ANSI sequence to turn off attributes */ char *enter_bold; /* ANSI sequence to set color to bold mode */ #endif +#ifdef JAPANESE_EXTENSION +int f_jconv; /* output japanese character code */ +#endif +#ifdef SAMBA_CAP_EXTENSION +int f_sambacap; +#endif static int rval; @@ -135,7 +144,7 @@ static char dot[] = ".", *dotav[] = {dot, NULL}; struct winsize win; int ch, fts_options, notused; - char *p; + const char *p; #ifdef COLORLS char termcapbuf[1024]; /* termcap definition buffer */ char tcapbuf[512]; /* capability buffer */ @@ -166,7 +175,18 @@ f_listdot = 1; fts_options = FTS_PHYSICAL; - while ((ch = getopt(argc, argv, "1ABCFGHLPRTWabcdfghiklmnopqrstuwx")) + +#ifdef JAPANESE_EXTENSION + f_nonprint = 0; + f_octal = 0; + f_octal_escape = 0; + f_jconv = EUC; +#endif + +#ifdef SAMBA_CAP_EXTENSION + f_sambacap = 1; +#endif + while ((ch = getopt(argc, argv, "1ABCEFGHJLPQRSTWabcdfghiklmnopqrstuwx")) != -1) { switch (ch) { /* @@ -297,6 +317,22 @@ f_octal = 0; f_octal_escape = 0; break; +#ifdef JAPANESE_EXTENSION + case 'E': + f_jconv = EUC; + break; + case 'J': + f_jconv = JIS; + break; + case 'S': + f_jconv = SJIS; + break; +#endif +#ifdef SAMBA_CAP_EXTENSION + case 'Q': + f_sambacap = 0; + break; +#endif default: case '?': usage(); diff -uNr ls/ls.h jls/ls.h --- ls/ls.h Mon Jul 8 15:59:27 2002 +++ jls/ls.h Sat Jun 12 18:34:24 2004 @@ -60,6 +60,12 @@ #ifdef COLORLS extern int f_color; /* add type in color for non-regular files */ #endif +#ifdef JAPANESE_EXTENSION +extern int f_jconv; /* output japanese character code */ +#endif +#ifdef SAMBA_CAP_EXTENSION +extern int f_sambacap; +#endif typedef struct { FTSENT *list; diff -uNr ls/print.c jls/print.c --- ls/print.c Sun Nov 17 19:27:34 2002 +++ jls/print.c Sat Jun 12 18:34:10 2004 @@ -62,6 +62,9 @@ #endif #include "ls.h" +#ifdef JAPANESE_EXTENSION +#include "jconv.h" +#endif #include "extern.h" static int printaname(FTSENT *, u_long, u_long); @@ -75,6 +78,7 @@ #endif #define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT) +#define D_MD_ORDER 57 /* month/day order (local extension) */ #define KILO_SZ(n) (n) #define MEGA_SZ(n) ((n) * (n)) @@ -162,6 +166,9 @@ #ifdef COLORLS int color_printed = 0; #endif +#ifdef JAPANESE_EXTENSION + int encode = UNKNOWN; +#endif if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) (void)printf("total %lu\n", howmany(dp->btotal, blocksize)); @@ -169,6 +176,54 @@ for (p = dp->list; p; p = p->fts_link) { if (IS_NOPRINT(p)) continue; +#ifdef SAMBA_CAP_EXTENSION + if (f_sambacap) { + samba_cap(p->fts_name); + } +#endif +#ifdef JAPANESE_EXTENSION + encode = detectcode(p->fts_name, strlen(p->fts_name)); + switch (encode) { + case EUC: + switch (f_jconv) { + case EUC: + break; + case SJIS: + euctosjis(p->fts_name); + break; + case JIS: + euctojis(p->fts_name); + break; + } + break; + case SJIS: + switch (f_jconv) { + case EUC: + sjistoeuc(p->fts_name); + break; + case SJIS: + break; + case JIS: + sjistojis(p->fts_name); + break; + } + break; + case JIS: + switch (f_jconv) { + case EUC: + jistoeuc(p->fts_name); + break; + case SJIS: + jistosjis(p->fts_name); + break; + case JIS: + /* jistojis(p->fts_name); */ + break; + } + break; +} +#endif + sp = p->fts_statp; if (f_inode) (void)printf("%*lu ", dp->s_inode, (u_long)sp->st_ino); @@ -242,7 +297,7 @@ if (chcnt) putchar('\n'); } - + void printcol(DISPLAY *dp) { @@ -344,6 +399,9 @@ #ifdef COLORLS int color_printed = 0; #endif +#ifdef JAPANESE_EXTENSION + int encode = UNKNOWN; +#endif sp = p->fts_statp; chcnt = 0; @@ -352,6 +410,54 @@ if (f_size) chcnt += printf("%*lld ", (int)sizefield, howmany(sp->st_blocks, blocksize)); +#ifdef SAMBA_CAP_EXTENSION + if (f_sambacap) { + samba_cap(p->fts_name); + } +#endif +#ifdef JAPANESE_EXTENSION + encode = detectcode(p->fts_name, strlen(p->fts_name)); + switch (encode) { + case EUC: + switch (f_jconv) { + case EUC: + break; + case SJIS: + euctosjis(p->fts_name); + break; + case JIS: + euctojis(p->fts_name); + break; + } + break; + case SJIS: + switch (f_jconv) { + case EUC: + sjistoeuc(p->fts_name); + break; + case SJIS: + break; + case JIS: + sjistojis(p->fts_name); + break; + } + break; + case JIS: + switch (f_jconv) { + case EUC: + jistoeuc(p->fts_name); + break; + case SJIS: + jistosjis(p->fts_name); + break; + case JIS: + /* jistojis(p->fts_name); */ + break; + } + break; +} +#endif + #ifdef COLORLS if (f_color) color_printed = colortype(sp->st_mode); @@ -594,6 +700,52 @@ return; } path[lnklen] = '\0'; + +#ifdef SAMBA_CAP_EXTENSION + if (f_sambacap) + samba_cap(path); +#endif +#ifdef JAPANESE_EXTENSION + switch (detectcode(path, strlen(path))) { + case EUC: + switch (f_jconv) { + case EUC: + break; + case SJIS: + euctosjis(path); + break; + case JIS: + euctojis(path); + break; + } + break; + case SJIS: + switch (f_jconv) { + case EUC: + sjistoeuc(path); + break; + case SJIS: + break; + case JIS: + sjistojis(path); + break; + } + break; + case JIS: + switch (f_jconv) { + case EUC: + jistoeuc(path); + break; + case SJIS: + jistosjis(path); + break; + case JIS: + /* jistojis(path); */ + break; + } + break; +} +#endif (void)printf(" -> "); (void)printname(path); } diff -uNr ls/samba.c jls/samba.c --- ls/samba.c Thu Jan 1 09:00:00 1970 +++ jls/samba.c Tue Jan 5 03:02:36 1999 @@ -0,0 +1,118 @@ +/* + * Copyright (c) 1989, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Michael Fischbein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +/* + * written by shige + */ + +#include + +int samba_cap(char *s) +{ + char *sp; + int i = 0; + char tmpnum; + char tmp[FILENAME_MAX]; + + sp = s; + + while(*s != '\0') { + if (*s == ':') { + if ('9' >= *(s+1) && *(s+1) >= '0') + tmpnum = (*(s+1) - 0x30) * 16; + else if ('f' >= *(s+1) && *(s+1) >= 'a') + tmpnum = (*(s+1) - 0x60 + 9) * 16; + else { + tmp[i] = *s; + tmp[i+1] = *(s+1); + *s = '\0'; + *(s+1) = '\0'; + i += 2; + s += 2; + continue; + } + + if ('9' >= *(s+2) && *(s+2) >= '0') + tmpnum = (*(s+2) - 0x30) + tmpnum; + else if ('f' >= *(s+2) && *(s+2) >= 'a') + tmpnum = (*(s+2) - 0x60 + 9) + tmpnum; + else { + tmp[i] = *s; + tmp[i+1] = *(s+1); + tmp[i+2] = *(s+2); + *s = '\0'; + *(s+1) = '\0'; + *(s+2) = '\0'; + i += 3; + s += 3; + continue; + } + + tmp[i] = tmpnum; + *s = '\0'; + *(s+1) = '\0'; + *(s+2) = '\0'; + i++; + s += 3; + } else { + tmp[i] = *s; + *s = '\0'; + i++; + s++; + } + } + + tmp[i] = '\0'; + strcpy(sp, tmp); + + return 0; +} + +#ifdef DEBUG_TEST +int main() +{ + char *name = ":90V:82:b5:82:a2:83t:83H:83:8b:83_"; + char new[1024]; + + strcpy(new, name); + samba_cap(new); + + printf("converted: %s\n", new); + return 0; +} +#endif diff -uNr ls/test/jpfiles jls/test/jpfiles --- ls/test/jpfiles Thu Jan 1 09:00:00 1970 +++ jls/test/jpfiles Tue Jan 5 03:08:01 1999 @@ -0,0 +1,24 @@ +#!/bin/sh + +if [ "x$1" = "x" ]; then + echo "usage: `basename $0` [-m|-r]" + exit 1; +fi + +if [ "$1" = "-m" ]; then + touch :90V:82:b5:82:a2:83t:83H:83:8b:83_ + touch 'EUC・ニ・ケ・ネ' + touch 'JIS$B%F%9%H(B' + touch 'SJISテスト' + exit 0; +elif [ "$1" = "-r" ]; then + rm :90V:82:b5:82:a2:83t:83H:83:8b:83_ + rm 'EUC・ニ・ケ・ネ' + rm 'JIS$B%F%9%H(B' + rm 'SJISテスト' + exit 0; +else + echo "invalid option." + echo "usage: `basename $0` [-m|-r]" + exit 1; +fi diff -uNr ls/util.c jls/util.c --- ls/util.c Mon Jul 8 15:59:27 2002 +++ jls/util.c Sat Jun 12 18:34:18 2004 @@ -154,11 +154,34 @@ void usage(void) { - (void)fprintf(stderr, #ifdef COLORLS - "usage: ls [-ABCFGHLPRTWabcdfghiklnoqrstu1]" +# ifdef JAPANESE_EXTENSION +# ifdef SAMBA_CAP_EXTENSION + (void)fprintf(stderr, "usage: ls [-ACEFGHJLPQRSTWacdfgikloqrstuw1]" +# else + (void)fprintf(stderr, "usage: ls [-ACEFGHJLPQRSTWacdfgikloqrstu1]" +# endif +# else +# ifdef SAMBA_CAP_EXTENSION + (void)fprintf(stderr, "usage: ls [-ACFGHLPRTWacdfgikloqrstuw1]" +# else + (void)fprintf(stderr, "usage: ls [-ACFGHLPRTWacdfgikloqrstu1]" +# endif +# endif #else - "usage: ls [-ABCFHLPRTWabcdfghiklnoqrstu1]" +# ifdef JAPANESE_EXTENSION +# ifdef SAMBA_CAP_EXTENSION + (void)fprintf(stderr, "usage: ls [-ACEFHJLPQRSTWacdfgikloqrstuw1]" +# else + (void)fprintf(stderr, "usage: ls [-ACEFHJLPQRSTWacdfgikloqrstu1]" +# endif +# else +# ifdef SAMBA_CAP_EXTENSION + (void)fprintf(stderr, "usage: ls [-ACFHLPRTWacdfgikloqrstuw1]" +# else + (void)fprintf(stderr, "usage: ls [-ACFHLPRTWacdfgikloqrstu1]" +# endif +# endif #endif " [file ...]\n"); exit(1);