サブジウ3校クト欄の生JIS投稿時の問題点(Re: get out !!! (Re: ))

6 views
Skip to first unread message

Shuichi ICHIKAWA /

unread,
Apr 26, 1996, 3:00:00 AM4/26/96
to

Subjectiso-2022-jp(JIS)
(1) newsreader
(2) ESC
rjis

(2)rjisnewsreader(
)Subjectiso-2022-jp
ESCiso-2022-jp
Subjectrjis
patch
ESCnewsreadertinktin
patchUMAmush,elm
patchfj.sourcesInternet

(^.^)


patch

newsreaderport

newsreaderFollowup-Tofj.news.reader


http://www.shimada.nuee.nagoya-u.ac.jp/~ichikawa/software.html

--
(Shuichi ICHIKAWA) <ichi...@nuee.nagoya-u.ac.jp>

Masaki Ishido

unread,
Apr 26, 1996, 3:00:00 AM4/26/96
to

WinVN(^^;;

In article <4lpb34$4...@echonfs.echo.nuee.nagoya-u.ac.jp>, ichi...@nuee.nagoya-u.ac.jp says...


>
>patch
>
>newsreaderport
>

mmdec.c rjis WinVN

ESC Subject



--
Masaki Ishido
a Viola player
ish...@jpn.hp.com


Shuichi ICHIKAWA /

unread,
Apr 30, 1996, 3:00:00 AM4/30/96
to

Masaki Ishido (ish...@jpn.hp.com) wrote:
:
: mmdec.c rjis WinVN

:
: ESC Subject
:

newsreaderpatch
mmdec iso-2022-jp ESC
rjis
mmdecrjissource(mmdec.c)

mimebase64encodeiso-2022-jp headerdecode
-riso-2022-jpESC
fj.sources

--
(Shuichi ICHIKAWA) <ichi...@nuee.nagoya-u.ac.jp>

-- mmdec.c follows --
/*
* ISO-2022-JP handling routines
* &
* MIME decode routines (quick hack just for ISO-2022-JP)
*
* Thu Jan 25 10:11:42 JST 1996
*
* Copyright (C) 1994, 1995, 1996
* Shuichi Ichikawa (ichi...@nuee.nagoya-u.ac.jp)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either versions 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SKK, see the file COPYING. If not, write to the Free
* Software Foundation Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <stdio.h>
#include <string.h>

/*
* MIME decoding routines
*
* Written by S. Ichikawa,
* partially inspired by encdec.c of <j...@efd.lth.se>.
*/
#define BUFLEN 1024
#define ESC (0x1b)

static char mm64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" ;
static char mmquote[] = "0123456789ABCDEF";
static int mmcont = 0;

void
mmdec_base64(t, s)
char *t, *s;
{
int d, count, j, val;
char buf[BUFLEN], *bp, nw[4], *p;

for (bp = buf; *s; s += 4) {
val = 0;
if (s[2] == '=') count = 1;
else if (s[3] == '=') count = 2;
else count = 3;

for (j = 0; j <= count; j++) {
if (!(p = strchr(mm64, s[j]))) {
return;
}
d = p - mm64;
d <<= (3-j)*6;
val += d;
}
for (j = 2; j >= 0; j--) {
nw[j] = val & 255;
val >>= 8;
}
if (count--) *bp++ = nw[0];
if (count--) *bp++ = nw[1];
if (count) *bp++ = nw[2];
}
*bp = '\0';
strcpy(t, buf);
}

void
mmdec_quote(t, s)
char *t, *s;
{
char buf[BUFLEN], cval, *bp, *p;

for (bp = buf; *s; ) {
if (*s == '=') {
cval = 0;
if (s[1] && (p = strchr(mmquote, s[1]))) {
cval += (p - mmquote);
} else {
*bp++ = *s++;
continue;
}
if (s[2] && (p = strchr(mmquote, s[2]))) {
cval <<= 4;
cval += (p - mmquote);
*bp++ = cval;
s += 3;
} else {
*bp++ = *s++;
}
} else if (*s == '_') {
*bp++ = 0x20;
s++;
} else {
*bp++ = *s++;
}
}
*bp = '\0';
strcpy(t, buf);
}

void
mmdecode(trg, str)
char *trg, *str;
{
char buf[BUFLEN], mmbuf[BUFLEN];
char *s, *t, *u;
int base64, quote;

buf[0] = '\0';

for (s = str, u = buf; *s; ) {
if (!strncasecmp(s, "=?ISO-2022-JP?B?", 16)) {
base64 = 1;
} else {
base64 = 0;
}
if (!strncasecmp(s, "=?ISO-2022-JP?Q?", 16)) {
quote = 1;
} else {
quote = 0;
}
if (base64 || quote) {
if (mmcont) {
for (t = s - 1;
t >= str && (*t == ' ' || *t == '\t'); t--) {
u--;
}
}
for (s += 16, t = mmbuf; *s; ) {
if (s[0] == '?' && s[1] == '=') {
break;
} else {
*t++ = *s++;
}
}
if (s[0] != '?' || s[1] != '=') {
goto end;
} else {
s += 2;
*t = '\0';
}
if (base64) mmdec_base64(mmbuf, mmbuf);
if (quote) mmdec_quote(mmbuf, mmbuf);
for (t = mmbuf; *t; ) *u++ = *t++;
mmcont = 1;
/* if (*s == ' ' || *s == '\t') *u++ = *s; */
/* for ( ; *s == ' ' || *s == '\t'; s++) ; */
} else {
if (*s != ' ' && *s != '\t') mmcont = 0;
*u++ = *s++;
}
}
*u = '\0';
end:
strcpy(trg, buf);
}

int
main(ac, av)
int ac;
char **av;
{
FILE *fp;
char buf[BUFLEN];
char header = 1, body = 0, r_jis = 0;
int i, c;

for (i = 1; i < ac; i++) {
if (strcmp(av[i], "-B") == NULL) body = 1;
else if (strcmp(av[i], "-r") == NULL) r_jis = 1;
else break;
}

if (i >= ac) {
fp = stdin;
} else {
if ((fp = fopen(av[i], "r")) == NULL) {
fprintf(stderr, "%s: cannot open %s\n", av[0], av[i]);
exit(1);
}
}

while (fgets(buf, BUFLEN, fp)) {
if (buf[0] == '\n' && buf[1] == '\0') header = 0;
if (header) {
c = fgetc(fp);
if (c == ' ' || c == '\t') {
buf[strlen(buf)-1] = '\0';
ungetc(c, fp);
} else {
ungetc(c, fp);
}
}
if (header || body) mmdecode(buf, buf);
if (r_jis) rjis(buf, buf);
fprintf(stdout, "%s", buf);
}

close(fp);
exit(0);
}

/*
* Insert ESC where it seems lost.
* (The author of this function "rjis" is S. Ichikawa.)
*/
int
rjis(t, s)
char *t, *s;
{
char *p, buf[BUFLEN];
int kanji = 0;

if (strchr(s, ESC) || !strchr(s, '$')) {
if (s != t) strcpy(t, s);
return 1;
}
for (p = buf; *s; ) {
if (!kanji && s[0] == '$' && (s[1] == '@' || s[1] == 'B')) {
if (maybekanji((int)s[2], (int)s[3])) {
kanji = 1;
*p++ = ESC;
*p++ = *s++;
*p++ = *s++;
*p++ = *s++;
*p++ = *s++;
continue;
}
*p++ = *s++;
continue;
}
if (kanji && s[0] == '(' && (s[1] == 'J' || s[1] == 'B')) {
kanji = 0;
*p++ = ESC;
*p++ = *s++;
*p++ = *s++;
continue;
}
*p++ = *s++;
}
*p = *s; /* terminate string */

strcpy(t, buf);
return 0;
}

/*
* The following function "maybekanji" is derived from
* RJIS-1.0 by Mr. Hironobu Takahashi.
* Maybekanji() is included here under the courtesy of the author.
* The original comment of rjis.c is also included here.
*/

/*
* RJIS ( Recover JIS code from broken file )
* $Header: rjis.c,v 0.2 92/09/04 takahasi Exp $
* Copyright (C) 1992 1994
* Hironobu Takahashi (taka...@tiny.or.jp)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either versions 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SKK, see the file COPYING. If not, write to the Free
* Software Foundation Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

int maybekanji(c1, c2)
int c1;
int c2;
{

if ((c2 < 33) || (c2 > 126)) return 0;
if ((c1 < 33) || ((40 < c1) && (c1 < 48)) || (116 < c1)) return 0;
c2 -= 32;
switch(c1-32) {
case 2:
if ((14 < c2) && ( c2 < 26)) return 0;
if ((33 < c2) && ( c2 < 42)) return 0;
if ((48 < c2) && ( c2 < 60)) return 0;
if ((74 < c2) && ( c2 < 82)) return 0;
if ((89 < c2) && ( c2 < 94)) return 0;
break;
case 3:
if (c2 < 16) return 0;
if ((25 < c2) && ( c2 < 33)) return 0;
if ((58 < c2) && ( c2 < 65)) return 0;
if (90 < c2) return 0;
break;
case 4:
if (83 < c2) return 0;
break;
case 5:
if (86 < c2) return 0;
break;
case 6:
if ((24 < c2) && ( c2 < 33)) return 0;
if (56 < c2) return 0;
break;
case 7:
if ((33 < c2) && ( c2 < 49)) return 0;
if (81 < c2) return 0;
break;
case 8:
if (32 < c2) return 0;
break;
case 47:
if (51 < c2) return 0;
break;
case 84:
if (6 < c2) return 0;
break;
}
return 1;
}


Reply all
Reply to author
Forward
0 new messages