銀河の歴史がまた1ページ(日記)

Last Update (2020/07/23 16:06:54)
1997.09.06から数えて counter 番目のアクセスです。

ミラーサイト [www.ceres.dti.ne.jp] [yk.rim.or.jp]

[ホームページ] [日記] [日記ファイル一覧] [読んでいる日記] [FreeBSD] [FreeBSD LINK] [検索]

ページ内目次


■ 宇宙暦 2017.02.01

http://www.ceres.dti.ne.jp/~george/jdiaryB70201.html#20170201

2017.02.01(水) 懐かしのtypist(キーボード練習用ソフト)

現在のFreeBSD portsではGNU typistしかないようだが、これだと日本語用の学習素材がイマイチ。 日本語106キーボード設定もないみたい。

検索して、すんげー昔のportsにあったjapanese/typistらしきものを見つけた。

面白がってコンパイルしてみたww

termios.hじゃなくてtermio.hの時代かー。 なんかこう、termcapとかterminfoでコンパイルがコケてた遠い遠い記憶がwww 今回は-ltermcapでコンパイル。 構造体名をtermioからtermiosに書き換えるだけで済んだ。

libc.hってなんだろ? Borland CとかMINGW用の奴か。unistd.hを読ませておけば良さそう。

ソースコードに生SJIS文字リテラルがあると警告が出るのか。-Wno-invalid-source-encoding で抑止しておく。

ソースと学習用教本はSJISだったのでEUC-JPに変更。 デフォルトキーボードタイプはUS-ASCII(101キーボードタイプ)に変更。

ふふふ。野良コンパイルのtypistができた。

しかし、これのports作るの大変そうだな...。つか原作ソース取得できないし...。

今風にするならpkg用バイナリにしないといけないけど、出力文字コードでSJIS/EUC-JP/UTF-8の3種類ができちゃうな。

以下、超雑な差分。

diff -u10 -r typist-master.orig.euc-jp/src/base.h typist-master/src/base.h
--- typist-master.orig.euc-jp/src/base.h        2017-02-01 02:07:21.901109000 +0900
+++ typist-master/src/base.h    2017-02-01 00:33:33.666369000 +0900
@@ -10,27 +10,29 @@
 #define  JPN           1       /* Japanese MODE (don't remove) */
 #if defined(MACKEYBOARD) && !defined(KANA_LESSON)
 # define  KANA_LESSON  1
 #endif
 /* #define KANA_LESSON 1  ...  If you use Kana Lessons */
 /* Without Japanese Input Program, JIS106 keyboard doesn't generate
    any code with Shift+'0' (especially Windows systems).
    This is for kana character 'WO'.
 */

+#if ! defined(__FREEBSD11__) /* for FreeBSD11 */
 #if 1 /* for Windows XP */
 #define  KANA_CODE     1       /* ShiftJIS */
 #if !defined(WinXP)
 # define  WinXP                1
 # define  USE_WINSOCK   1
 #endif
 #endif /* for Windows XP */
+#endif /* for FreeBSD11 */

 #define   STR_SIZE     255     /* was 1024 */
 typedef char StrType[STR_SIZE + 1];
 typedef unsigned char BoolType;

 #if !defined(FALSE)
 # define  FALSE                0
 #endif
 #if !defined(TRUE)
 # define  TRUE         1
diff -u10 -r typist-master.orig.euc-jp/src/dictionary.c typist-master/src/dictionary.c
--- typist-master.orig.euc-jp/src/dictionary.c  2017-02-01 02:07:21.908003000 +0900
+++ typist-master/src/dictionary.c      2017-02-01 02:20:37.876964000 +0900
@@ -1,13 +1,15 @@
 #include <string.h>
 #include <stdlib.h>
-#if !defined(__BORLANDC__)
+#if defined(__FREEBSD11__)
+# include <unistd.h>
+#elif !defined(__BORLANDC__)
 # include <libc.h>
 #endif
 #include "base.h"

 typedef struct _entry {
        char *key;
        char *val;
        /* struct _entry *next;
        If you want to use list. You can use hash table, of course */
 } entry;
diff -u10 -r typist-master.orig.euc-jp/src/http.c typist-master/src/http.c
--- typist-master.orig.euc-jp/src/http.c        2017-02-01 02:07:21.934792000 +0900
+++ typist-master/src/http.c    2017-02-01 00:45:52.931562000 +0900
@@ -6,21 +6,23 @@

 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include "base.h"
 #if defined(USE_WINSOCK)
 # include <io.h>
 # include <winsock2.h>
 #else
+#if !defined (__FREEBSD11__)
 # include <libc.h>
+#endif
 # include <sys/socket.h>
 # include <netdb.h>
 # include <netinet/in.h>
 #endif
 #include <limits.h>
 #include <sys/types.h>
 #include "http.h"

 #ifndef BUFSIZ
 #define BUFSIZ 512
diff -u10 -r typist-master.orig.euc-jp/src/makefile.unix typist-master/src/makefile.unix
--- typist-master.orig.euc-jp/src/makefile.unix 2017-02-01 02:07:22.052858000 +0900
+++ typist-master/src/makefile.unix     2017-02-01 02:23:41.653756000 +0900
@@ -36,55 +36,60 @@
 #LIBS=
 #DEBUG=-O

 # following options for HP-UX
 #LIBS=
 #DEBUG=-O

 # following options for LINUX
 #LIBS=-ltermcap

+# following options for FreeBSD11
+LIBS=-ltermcap
+DEBUG=-O -D__FREEBSD11__ -DTERMIOS  -Wno-invalid-source-encoding
+
 # following options for NeXT Mach
 #LIBS=-ltermcap
 #DEBUG=-O -s -Wall
 #MAB=-arch m68k -arch i386 -arch hppa -arch sparc

 # following options for SGI IRIX
 #LIBS=-ltermcap
 #DEBUG=-O -s

 # following options for MinGW
 #LIBS=-lpdcurses
 #DEBUG=-mno-cygwin -g -O

 ##### INSTALL PARAMETERS #####
-LIBS=-ltermcap
-DEBUG=-O -s -Wall -ansi
+#LIBS=-ltermcap
+#DEBUG=-O -s -Wall -ansi
 LESSONDIR=/usr/local/lib/typist
 TARGETDIR=/usr/local/bin
 MANPATH=/usr/local/man
 # 0=Unicode, 1=ShiftJIS, 2=EUC_JP
-JPNCODE=-DKANA_CODE=1
+JPNCODE=-DKANA_CODE=2
 # Apple / NeXT ONLY!!  To make FAT binary.
 MAB=
 #-arch i386 -arch ppc

-CFLAGS=$(DEBUG) $(MAB) $(JPNCODE) -DMACKEYBOARD
+CFLAGS=$(DEBUG) $(MAB) $(JPNCODE) -DMACKEYBOARD -DKEYTYPE=\"e\"
 # -DTERMIO
 # -DKEYTYPE=\"e\"
 # -DLESSONDIR=\"$(LESSONDIR)\"
 # -DVANISHCHAR

 ## -DLESSONDIR         if (LESSONDIR != /usr/local/lib/typist) set this!
 ## -DKEYTYPE           if you want to set keyboard type (default == "j")
 ## -DMSDOS             for MSDOS system
 ## -DTERMIO            for SYS/V Unix with termio(7).
+## -DTERMIOS           for FreeBSD11 Unix with termios(7).
 ## -DSILENT            if you hate click beep
 ## -DVANISHCHAR                if the character after an error vanishes.
 ## -DMACKEYBOARD       if you use Kana-Lessens with Apple Mac's keyboard

 LDFLAGS=$(DEBUG) $(MAB)
 CC=cc

 #-----------------------------------------------------------------------

 SRCFILES=main.c tutor.c kanatutor.c lesson.c lineio.c \
@@ -102,22 +107,22 @@
        $(CC) $(LDFLAGS) -o typist $(OBJFILES) $(LIBS)

 clean:
        rm -f *.o

 install: typist $(LESSONDIR)
        cp -p typist $(TARGETDIR)
        chmod 755 $(TARGETDIR)/typist
        cp -p ../lib/* $(LESSONDIR)
        chmod 644 $(LESSONDIR)/*
-       cp -p ../doc/typist.1 $(MANPATH)/man1
-       chmod 644 $(MANPATH)/man1/typist.1
+#      cp -p ../doc/typist.1 $(MANPATH)/man1
+#      chmod 644 $(MANPATH)/man1/typist.1

 $(LESSONDIR):
        mkdir $(LESSONDIR)
        chmod 755 $(LESSONDIR)

 main.o: base.h typist.h fileinfo.h kana.h
 fileinfo.o: base.h typist.h fileinfo.h http.h
 kanamap.o: base.h typist.h kana.h http.h
 lesson.o: base.h typist.h fileinfo.h lineio.h dictionary.h screen.h http.h
 lineio.o: base.h typist.h lineio.h dictionary.h http.h
diff -u10 -r typist-master.orig.euc-jp/src/screen.c typist-master/src/screen.c
--- typist-master.orig.euc-jp/src/screen.c      2017-02-01 02:07:22.117039000 +0900
+++ typist-master/src/screen.c  2017-02-01 02:10:13.161162000 +0900
@@ -2,21 +2,24 @@
        screen.c  fot typist
 ---------------------------------------------------------
        Ver.2.0   1997-05-20    Kana Exercise
        by Takeshi Ogihara
        Modification for MinGW   May 2007   by OHKUBO Takuya
        Ver.3.0   2007-07-19    by Takeshi Ogihara
 ------------------------------------------------------ */

 #include <stdio.h>
 #include <stdlib.h>
-#if !defined(__BORLANDC__)
+#if defined(__FREEBSD11__)
+# include <unistd.h>
+# include <string.h>
+#elif !defined(__BORLANDC__)
 # include <libc.h>
 #endif

 #include "screen.h"
 #include "base.h"

 #if !defined(__MINGW32__) && !defined(__BORLANDC__)

 /* write 1 char into 2nd channel */
 int add_ch(int cc)
@@ -171,21 +174,23 @@


 #if defined(UNIX_CURSES)
 /* =================================================== */

 #define  TERMENTRY     2048
 #define  TERMBUFFER    1024
 #define  MIN_WIDTH     80
 #define  MIN_HEIGHT    24

-#ifdef TERMIO
+#if defined(TERMIOS)
+# include <termios.h>
+#elif defined(TERMIO)
 # include <termio.h>
 #else
 # include <sgtty.h>
 #endif

 #ifdef TIOCGWINSZ
 # include <sys/ioctl.h>
 #endif

 char *tgetstr(char *, char **);
@@ -207,21 +212,49 @@
 static char    *tc_bo_on;      /* Bold ON */
 static char    *tc_bo_off;     /* Bold OFF */
 static char    *tc_backspace;  /* Backspace */
 static char    *tc_init;       /* Terminal initialize */
 static char    *tc_restore;    /* Exit terminal de-intialization */
 extern char    PC;             /* Padding char */

 static int screen_width = MIN_WIDTH, screen_height = MIN_HEIGHT;


-#ifdef TERMIO
+#if defined(TERMIOS)
+
+void raw_mode(int sw)
+{
+       static int      firsttime = 1;
+       struct termios *s;
+       static struct termios save_term;
+       static struct termios raw_term;
+
+       if (sw) {
+               s = &raw_term;
+               if (firsttime) {
+                       tcgetattr(2, s);
+                       firsttime = 0;
+                       save_term = *s;
+                       s->c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
+                       s->c_oflag |=  (OPOST|ONLCR);
+                       s->c_oflag &= ~(OCRNL|ONOCR|ONLRET);
+                       s->c_cc[VMIN] = 1;
+                       s->c_cc[VTIME] = 0;
+               }
+       }else if (firsttime)
+               return;
+       else
+               s = &save_term;
+       tcsetattr(2, TCSANOW, s);
+}
+
+#elif defined(TERMIO)

 void raw_mode(int sw)
 {
        static int      firsttime = 1;
        struct termio *s;
        static struct termio save_term;
        static struct termio raw_term;

        if (sw) {
                s = &raw_term;

■ 宇宙暦 2017.02.06

http://www.ceres.dti.ne.jp/~george/jdiaryB70201.html#20170206

2017.02.06(月) Amazon Lightsail (VPS) は結局 1GB (月額10ドル) のインスタンスに変更

Amazon Lightsail (VPS) は、512MB RAMだと足りなくて、結局 1GB RAM (月額10ドル) のインスタンスに建て直し。

Tomcatはやっぱりメモリ食いだなぁ...クラウド時代には厳しいなぁ...と思い知らされた。 (Jetty組み込みにしてみようかしらん。)

月額10ドルまで行くと、自宅サーバで良くね?みたいな疑念がもくもくと湧いてくるw

Docker入れて遊ぼうとか思うと1GBでも足りない気がしてきた。ぐぬぬぬ。

Lightsail使ってみた感想だけど、壊れてインスタンスが消し飛ぶような事件は起きていない。

CPUは(Atomと比較すれば)結構速く感じる。

SSDはddで70MB/sec程度の書き込み速度。

ネットワークは自宅からのscpアップロードは遅い。200KB/secも出ない感じ。

Amazonインスタンス間のscpコピーは高速だったので、外界との線が細いのかな。

オレ専用wiki(tomcat用のJSP/Servletアプリ)を動かしていると、数MBの画像が存在すると自宅鯖より遅い感じになる。 (chunkedデータの取り扱いはブラウザによってかなり違いがあるみたいで、ネットワーク速度ははっきりしないんだけども)


■ 宇宙暦 2017.02.08

http://www.ceres.dti.ne.jp/~george/jdiaryB70201.html#20170208

2017.02.08(水) FreeBSD 11 net/netcat と apache と \n\n と \r\n\r\n

netcat(コマンド名はnc)をインストールしてみた。

ファイルの内容をネットワークの先に送り付ける時なんかに便利。

自鯖のapacheに試してみる。

ssh george@n3050 ~ $   printf "GET / HTTP/1.0\n\n" | nc localhost 80
HTTP/1.1 400 Bad Request
Date: Wed, 08 Feb 2017 12:56:25 GMT
Server: Apache/2.4.25 (FreeBSD)
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>
ssh george@n3050 ~ $

あれ?なぜにbad request...?

ssh george@n3050 ~ $ printf "GET / HTTP/1.0\r\n\r\n" | nc localhost 80
<html><body><h1>It works!</h1></body></html>
ssh george@n3050 ~ $

\r\nなら通る。通信相手サーバがwww.yahoo.co.jpとかなら\n\nでも内容が取得できるけど。

一応、RFC 7230をちらっと見た限りでは、HTTPメッセージの改行は\r\nが正式な模様。

ガチでエラーにしてくるFreeBSD の apache-2.4.25おそるべし。

p.s.

ちなみに、Amazon Lightsail で借りてる Ubuntu 16.04-LTS の apache 2.4.18 だと、 printf "GET / HTTP/1.0\n\n" | nc localhost 80 で内容が取得できた。


■ 宇宙暦 2017.02.26

http://www.ceres.dti.ne.jp/~george/jdiaryB70201.html#20170226

2017.02.26(日) Amazon Lightsail (VPS) 無料枠超えてしまって通常課金始まったw

2月はじめにメモリ1GBインスタンスに変更したのだが、これで無料枠を超えてしまったようだ。

Amazon AWSのサインアップ後1年間の無料枠は以下。

Lightsailの場合は特に記載はないけど512MBの最小インスタンスじゃないと無料はダメみたいね。

余談だが、Lightsailの比較記事で良いのがあったのでメモ。


日記ファイルリスト


Copyright(c) 1996-2020 George(小濱 純). All rights reserved.
私の作成したページへのリンクはご自由にどうぞ。
このページに間違いや要望などがありましたら george@yk.rim.or.jp まで御連絡ください。
メール本文に 6020-5440-3372 と書いて頂くと、ウチのSPAMフィルタを通過できます(2009-06-14から2020-12-31まで)。

[ホームページ] [日記] [日記ファイル一覧] [読んでいる日記] [FreeBSD] [FreeBSD LINK] [検索]

home: <george@yk.rim.or.jp> or <george@ceres.dti.ne.jp>
(I am using white list SPAM filter. To avoid it, please write 6020-5440-3372 in mail body. This key word is valid since 2009-06-14 until 2015-12-31.)