Article View: fj.editor.xemacs
Article #190Re: Japanese text in HTML
From: Seiichi Namba
Date: Mon, 24 Sep 2001 05:39
Date: Mon, 24 Sep 2001 05:39
177 lines
6378 bytes
6378 bytes
Taka Fukuda <fukuda@computer.org> さん writes:
> > 編集するソース(a)と、実際に使う HTML(b) を別にして、(a)->(b)
> > への filter を記述しています。結構やるべきことがあるので、
> > その方がいいみたい。
>
> 成程。さしつかえなければ、そのフィルターを参考にさせて頂
> けないでしょうか。
ご指摘の html の行末に関する問題は、
・emacs で編集中は好きな位置に改行を入れたい。
・最終形では1段落一行(DOS のテキストファイル的な)にしたい。
という問題と考えていいですか。
DOS の上で microemacs を使い始めたころ、DOS のテキストファイル形式と、
emacs の前提としている unix 的なテキストファイルの形式の不一致を
吸収するため、下記のようなフィルタを書きました。仕様は
入力ストリーム中の n (n=1,2…) 個の連続する改行の数を n-1 に
減らしたり (lf -)、n+1 に増やしたりする (lf +) する
というようなものです。
たとえば、lf - [file] で連続する改行の数を1つづつ減らします(
1個のものは0個に、2個のものは1個に、… 3、4個以上
の連続はループで適当に処理しているようです)。
lf + [file] では逆に増やします(ダブルスペースを作る時に使ってた)。
引数無しの場合は cat と同じのようです。
私は DOS ユーザにテキスト原稿を渡す時は、
好きな位置に改行を入れて書き(段落の終りは改行2個)、
最終形を作る時に lf - を通したものを渡しています。
ご要望は html なのでそれと合うのかどうか判りませんが。
どうも面妖なマクロを使ってテキトーに書いてあるので読み易くはないですな。
私は lf - の出力は別ファイルに落してますが、emacs の上で処理したい時は
C-x h C-u M-| lf - RET
とでもすれば良いかな…。
当時 DOS の上で書いたので C ですが、どなたか 上の仕様の perl 版
(ruby/bison 何でもいいですが)か何か書いていただけると幸いです。
コンパイルは cc -o lf -s lf.c みたいな感じでいいでしょう。
なお、逆に DOS ユーザからテキストを貰う時は
#!/usr/bin/sed -f
s/\([、。】]]\)/\1\
/g
のような事をしています。実際にはこれの elisp 版(query-replace-regexp)を
使ってますが。
/*
* Name: lf.c
* Synopsys: lf {+|-} [file]
* Description: Increases (+) or decrease (-)
* continuous occurance
* of newline (\n) in stream.
* Warning: Using queer preprocessor macro. See #define.
* 2/16/90 S.Namba
*/
#include <stdio.h>
#include <string.h>
#define std_err(s) fputs((s),stderr)
const char dst='\n'; /* extern var : target */
/*==================================*
* Subroutines. Filter main bodies
*==================================*/
#define IfNotDst if((c=getc(stm))==EOF)break;\
else if (c != dst)
/*
* Increaser:
* increases target occurance.
*/
void
incr(stm)
FILE *stm;
{
int c;
while(1)
IfNotDst putchar(c); /* not target */
else IfNotDst{ putchar(dst); putchar(dst); /* 1+1 */
putchar(c); }
else IfNotDst{ putchar(dst); putchar(dst); /* 2+1 */
putchar(dst); putchar(c); }
else { putchar(dst); putchar(dst); /* 3+1 */
putchar(dst); putchar(dst); } /* 4th is by loop */
putchar(dst); /* last one */
putchar(dst); /* one more */
}
/*
* Decreaser:
* decreases target occurance.
*/
void
decr(stm)
FILE *stm;
{
int c;
while(1)
IfNotDst putchar(c); /* not target */
else IfNotDst putchar(c); /* 1-1 */
else IfNotDst{ putchar(dst); /* 2-1 */
putchar(c);}
else { putchar(dst);
putchar(dst);} /* 3-1 */
putchar(dst); /* last one */
}
/*
* Concatenator:
* just copies in-to-out
* like 'cat' command.
*/
void
cat(stm)
FILE *stm;
{
int c;
while ((c=getc(stm)) != EOF)
putchar(c);
}
int
main(ac, av)
int ac;
char **av;
{
char *progname = av[0];
void (*func)(); /* function selector */
FILE *fp; /* stream pointer */
int i;
#if 0
strlwr(progname); /* unix style */
#endif
/*
* Args control.
* No err out.
*/
func = cat; /* for safty */
for ( ;ac>1 && (av[1][0]=='+'||av[1][0]=='-'); ac--, av++)
switch (av[1][0]) {
case '+': /* no line no. print */
func=incr;
break;
case '-': /* no line no. print */
func=decr;
break;
default:
break;
}
/*
* Handles multi file.
*/
if (ac == 1)
(*func)(stdin);
else for (i = 1; i < ac; i++) {
if ((fp=fopen(av[i],"r")) == NULL) {
std_err(progname);
std_err(": can't open ");
std_err(av[1]);
std_err("\n");
exit(1);
} else {
(*func)(fp);
fclose(fp);
}
}
exit(0);
}
Technical Details
Message-ID:
<9omgts$ivl$1@sn.asahi-net.email.ne.jp>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!feed.textport.net!newsfeed.media.kyoto-u.ac.jp!Q.T.Honey!nf.asahi-net.or.jp!not-for-mailReferences:
<86n13mzya1.wl@goliath.otacky.jp> <9781.1001223010@insigna.ie.u-ryukyu.ac.jp> <86iteayvy1.wl@goliath.otacky.jp>Show Full Headers
Complete Article Headers
X-Google-Language: Japanese,JIS X-Google-Thread: 1107f7,8ed34cf8603aa849 X-Google-Attributes: gid1107f7,public X-Google-ArrivalTime: 2001-09-23 22:40:43 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!feed.textport.net!newsfeed.media.kyoto-u.ac.jp!Q.T.Honey!nf.asahi-net.or.jp!not-for-mail From: Seiichi Namba <sn@asahi-net.email.ne.jp> Newsgroups: fj.editor.xemacs Subject: Re: Japanese text in HTML Date: 24 Sep 2001 14:39:07 +0900 Organization: Smoke Message-ID: <9omgts$ivl$1@sn.asahi-net.email.ne.jp> References: <86n13mzya1.wl@goliath.otacky.jp> <9781.1001223010@insigna.ie.u-ryukyu.ac.jp> <86iteayvy1.wl@goliath.otacky.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp Content-Transfer-Encoding: 8bit Lines: 177 NNTP-Posting-Host: g032115.ppp.asahi-net.or.jp X-Trace: 1001310042 news3.asahi-net.or.jp 2885 211.132.32.115 X-Complaints-To: ap-net@asahi-net.or.jp