もし、死後の世界で閻魔様に 「おまえは生前、何を考えて生きてきたか?」と言われて

「はい、如何に血糖値を正常化するか。そのために、低糖質な献立を常に考えていました。」

もし、そう答えたならば

それは余りにも悲しい人生であったと言う他は無いかも知れません。

 

何のための血糖値コントロールなのか?

「はい、少しでも健康で長生きしたいからです。」

 

何のための健康・長生きか?

この答えは人それぞれであって、一概には言えないのです。

仮に 「自分の人生を楽しみたいからです。」 と答えたとしましょう。

 

私の楽しみはいろいろありますが、「ボケ防止のためのプログラミング」というのがあります。

他人から見れば 「なんでそんなに、根を詰めるシンドイことが楽しいの?」 と言われそうです。

楽しさなんて、本人にしかわからないものです。

 

では、その「ボケ防止」のための作業とは。

次をご覧ください。

 

 

 

 

 

なんだ。既に ソースコードが書いてあるやん。

 

そうではないのです。

これは 今から28年前に書かれたソースコードであり 動作検証は 今では入手が困難なハードウェア (NEC EWS-UX/V)で行われました。

このソースコードをそのまま使っても 今では正常な動作が困難だったりします。

そのために、ソースコードにいろいろと修正を加えていきます。

 

動作検証は、次の4種類の環境で行いました。

 

(1) Windows7 上での cygwin

 

homeuser@PrimePC ~# uname -a
CYGWIN_NT-6.1 PrimePC 3.1.5(0.340/5/3) 2020-06-01 08:55 i686 Cygwin
homeuser@PrimePC ~# gcc -v
組み込み spec を使用しています。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-cygwin/9.3.0/lto-wrapper.exe
ターゲット: i686-pc-cygwin
configure 設定: /cygdrive/i/szsz/tmpp/gcc/gcc-9.3.0-2.i686/src/gcc-9.3.0/configure --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-9.3.0-2.i686/src/gcc-9.3.0 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=i686-pc-cygwin --host=i686-pc-cygwin --target=i686-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-arch=i686 --with-tune=generic --disable-sjlj-exceptions --enable-languages=c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --enable-libquadmath --enable-libquadmath-support --disable-libssp --enable-libada --disable-symvers --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts
スレッドモデル: posix
gcc バージョン 9.3.0 (GCC)
homeuser@PrimePC ~# which ls
/usr/bin/ls
homeuser@PrimePC ~#

 

(2) CentOS5 (Linux)

 

[homeuser@torvalds ~]$ uname -a
Linux torvalds.server.com 2.6.18-398.el5 #1 SMP Tue Sep 16 20:51:48 EDT 2014 i686 i686 i386 GNU/Linux
[homeuser@torvalds ~]$ gcc -v
Using built-in specs.
Target: i386-redhat-linux
コンフィグオプション: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --disable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
スレッドモデル: posix
gcc バージョン 4.1.2 20080704 (Red Hat 4.1.2-55)
[homeuser@torvalds ~]$ which ls
ls='ls --color=tty'
        /bin/ls
[homeuser@torvalds ~]$

 

(3) FreeBSD 4.4-RELEASE

 

[homeuser@freebsd44 ~]$ uname -a
FreeBSD freebsd44.pcunix.com 4.4-RELEASE FreeBSD 4.4-RELEASE #0: Tue Sep 18 11:57:08 PDT 2001     murray@builder.FreeBSD.org:/usr/src/sys/compile/GENERIC  i386
[homeuser@freebsd44 ~]$ gcc -v
Using builtin specs.
gcc version 2.95.3 20010315 (release) [FreeBSD]
[homeuser@freebsd44 ~]$ which ls
/bin/ls
[homeuser@freebsd44 ~]$

 

(4) OpenBSD 6.6

 

[homeuser@pcunix ~]$ uname -a
OpenBSD pcunix.raadt.com 6.6 GENERIC.MP#8 i386
[homeuser@pcunix ~]$ clang -v
OpenBSD clang version 8.0.1 (tags/RELEASE_801/final) (based on LLVM 8.0.1)
Target: i386-unknown-openbsd6.6
Thread model: posix
InstalledDir: /usr/bin
[homeuser@pcunix ~]$ which ls
/bin/ls
[homeuser@pcunix ~]$

 

 

まずは、これが当時のオリジナルのソースコード

 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
//------------------------------------------------
#define CMPLT 0
//------------------------------------------------
#define SP 0
#define NOSP 1
//------------------------------------------------

getarg(argv, p)
char *argv[];
char *p;
{
        int i,sp_flg;
        sp_flg=SP;
        for(i=0;*p!='\0';p++){
                if(sp_flg==SP && *p!=' '){
                        argv[i]=p;
                        i++;
                        sp_flg=NOSP;
                }
                if(*p==' '){
                        *p='\0';
                        sp_flg=SP;
                }
        }
        argv[i]=(char *)0;
        return(i);
}

//------------------------------------------------

int cd ();
struct builtin{
        char cmd[256];
        int (*func)();
};
static struct builtin blt_in[]={"cd",cd,0,0};

//------------------------------------------------

showprompt()
{
        char *p_dir;
        fprintf(stderr,"%s> ",getenv("PWD"));
        fflush(stderr);
}

built_in(argv)
char *argv[];
{
        struct builtin *p;
        for(p=blt_in;*p->cmd!=0;p++){
                if(strcmp(p->cmd,argv[0])==0){
                        (p->func)(argv);
                        return CMPLT;
                }
        }
        return EOF;
}

cd(argv)
char *argv[];
{
        char e_value[256];
        if(chdir(argv[1])==EOF)return EOF;
        strcpy(e_value,"PWD=");
        strcat(e_value,argv[1]);
        putenv(e_value);
        return 0;
}

//------------------------------------------------

main()
{
        char command[256],*argv[256],*p;
        int st;
        showprompt();
        while((p=gets(command))!=NULL){
                getarg(argv,p);
                if(built_in(argv)==CMPLT){
                        showprompt();
                        continue;
                }
                if(fork()!=0){
                        wait(&st);
                        showprompt();
                } else {
                        if(execv(argv[0],argv)==EOF){
                                perror(argv[0]);
                                exit(1);
                        }
                }
        }
}

 

さあて。これを如何に最少の手数で今でも使えるようにするか?

この「ボケ防止」の作業の醍醐味は、「最少の手数で今でも使えるようにする」というものなのです。

だから、PCに向かって打ち込む時間よりも ボーっと考えている時間のほうが長いのです。

別に仕事ではありませんから、納期もなければ督促もない。

ただただ気ままに。

で、私が修正を加えたソースコード。

 

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <stdio.h>
//------------------------------------------------
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
//------------------------------------------------
#define CMPLT 0
//------------------------------------------------
#define SP 0
#define NOSP 1
//------------------------------------------------
char b_value[256];
//------------------------------------------------

int getarg(argv, p)
char *argv[];
char *p;
{
        int i,sp_flg;
        sp_flg=SP;
        for(i=0;*p!='\0';p++){
                if(sp_flg==SP && *p!=' '){
                        argv[i]=p;
                        i++;
                        sp_flg=NOSP;
                }
                if(*p==' '){
                        *p='\0';
                        sp_flg=SP;
                }
        }
        argv[i]=(char *)0;
        return(i);
}

//------------------------------------------------

int cd ();
struct builtin{
        char cmd[256];
        int (*func)();
};
static struct builtin blt_in[]={"cd",cd,0,0};

//------------------------------------------------

void showprompt()
{
        char *p_dir;
        p_dir = getenv("PWD");
        if(p_dir==NULL){
                // cygwin gcc version 9.3.0 2020/06/30
                putenv(b_value);
                p_dir = getenv("PWD");
        }
        fprintf(stderr,"%s> ",p_dir);
        fflush(stderr);
}

int built_in(argv)
char *argv[];
{
        struct builtin *p;
        for(p=blt_in;*p->cmd!=0;p++){
                if(strcmp(p->cmd,argv[0])==0){
                        (p->func)(argv);
                        return CMPLT;
                }
        }
        return EOF;
}

int cd(argv)
char *argv[];
{
        char e_value[256];
        if(chdir(argv[1])==EOF)return EOF;
        strcpy(e_value,"PWD=");
        strcat(e_value,argv[1]);
        putenv(e_value);
        strcpy(b_value,e_value);
        return 0;
}

//------------------------------------------------

char *mgets(char command[])
{
        return strtok(fgets(command,256,stdin), "\n");
}

int main()
{
        char command[256],*argv[256],*p;
        int st;
        showprompt();
        while((p=mgets(command))!=NULL){
                getarg(argv,p);
                if(built_in(argv)==CMPLT){
                        showprompt();
                        continue;
                }
                if(fork()!=0){
                        wait(&st);
                        showprompt();
                } else {
                        if(execv(argv[0],argv)==EOF){
                                perror(argv[0]);
                                exit(1);
                        }
                }
        }
        return 0;
}

 

動作検証 (1) Windows7 上での cygwin

 

homeuser@PrimePC ~# cd src/nsh2x
homeuser@PrimePC ~/src/nsh2x# make clean
rm -f *.o *~ nsh2x
homeuser@PrimePC ~/src/nsh2x# make
gcc -O4 -Wall -I/home/Ownwe/include   -c -o nsh2x.o nsh2x.c
nsh2x.c:45:32: 警告: 初期化子の周りに中括弧がありません [-Wmissing-braces]
   45 | static struct builtin blt_in[]={"cd",cd,0,0};
      |                                ^
      |                                 {      }{{ }}
gcc nsh2x.o -o nsh2x
homeuser@PrimePC ~/src/nsh2x# make install
install -s nsh2x /home/Ownwe/bin
homeuser@PrimePC ~/src/nsh2x# nsh2x
/home/Ownwe/src/nsh2x> /usr/bin/ls
Makefile  nsh2x.c  nsh2x.c.org1  nsh2x.c.org2  nsh2x.c.org3  nsh2x.c.org4  nsh2x.exe  nsh2x.o  nsh2x.xlsx
/home/Ownwe/src/nsh2x> cd /home/Ownwe
/home/Ownwe> /usr/bin/ls
bin  include  memo.txt  text.txt      デスクトップ  ドキュメント  音楽  公開
doc  lib      src       ダウンロード  テンプレート  ビデオ        画像
/home/Ownwe>
homeuser@PrimePC ~/src/nsh2x#

 

 

動作検証 (2) CentOS5 (Linux)

 

[homeuser@torvalds ~]$ cd src/nsh2x
[homeuser@torvalds ~/src/nsh2x]$ make clean
rm -f *.o *~ nsh2x
[homeuser@torvalds ~/src/nsh2x]$ make
gcc -O4 -Wall -I/home/homeuser/include   -c -o nsh2x.o nsh2x.c
nsh2x.c:45: 警告: 初期化子のまわりのブレースを欠いています
nsh2x.c:45: 警告: (near initialization for ‘blt_in[0])
gcc nsh2x.o -o nsh2x
[homeuser@torvalds ~/src/nsh2x]$ make install
install -s nsh2x /home/homeuser/bin
[homeuser@torvalds ~/src/nsh2x]$ nsh2x
/home/homeuser/src/nsh2x> /bin/ls
Makefile  nsh2x  nsh2x.c  nsh2x.o
/home/homeuser/src/nsh2x> cd /home/homeuser
/home/homeuser> /bin/ls
Desktop  Documents  Downloads  Music  Pictures  Videos  bin  include  lib  src
/hom>
[homeuser@torvalds ~/src/nsh2x]$

 

 

動作検証 (3) FreeBSD 4.4-RELEASE

 

[homeuser@freebsd44 ~/src/nsh2x]$ make
gcc -O4 -Wall -I/home/homeuser/include -c nsh2x.c
nsh2x.c:45: warning: missing braces around initializer
nsh2x.c:45: warning: (near initialization for `blt_in[0]')
gcc nsh2x.o -o nsh2x
[homeuser@freebsd44 ~/src/nsh2x]$ make install
install -s nsh2x /home/homeuser/bin
[homeuser@freebsd44 ~/src/nsh2x]$ nsh2x
/home/homeuser/src/nsh2x> /bin/ls
Makefile        nsh2x           nsh2x.c         nsh2x.core      nsh2x.o
/home/homeuser/src/nsh2x> cd /home/homeuser
/home/homeuser> /bin/ls
001.xwd                                         doc
Documents                                       include
Downloads                                       lib
GNUstep                                         src
Pictures                                        test.txt
Wharf.core                                      test.txt.bak
bin                                             windows_10_hero_4k-wallpaper-800x600.jpg
/home/homeuser>
[homeuser@freebsd44 ~/src/nsh2x]$

 

 

動作検証 (4) OpenBSD 6.6

 

[homeuser@pcunix ~]$ cd src/nsh2x
[homeuser@pcunix ~/src/nsh2x]$ make clean
rm -f *.o *~ nsh2x
[homeuser@pcunix ~/src/nsh2x]$ make
clang  -O4 -Wall -I/home/homeuser/include  -c nsh2x.c
clang: warning: -O4 is equivalent to -O3 [-Wdeprecated]
nsh2x.c:45:33: warning: suggest braces around initialization of subobject [-Wmissing-braces]
static struct builtin blt_in[]={"cd",cd,0,0};
                                ^~~~~~~
                                {      }
nsh2x.c:45:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]
static struct builtin blt_in[]={"cd",cd,0,0};
                                        ^~~
                                        {  }
nsh2x.c:45:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]
static struct builtin blt_in[]={"cd",cd,0,0};
                                        ^~~
                                        {  }
3 warnings generated.
clang  nsh2x.o -o nsh2x
[homeuser@pcunix ~/src/nsh2x]$ make install
install -s nsh2x /home/homeuser/bin
[homeuser@pcunix ~/src/nsh2x]$ nsh2x
/home/homeuser/src/nsh2x> /bin/ls
Makefile nsh2x    nsh2x.c  nsh2x.o
/home/homeuser/src/nsh2x> cd /home/homeuser
> /bin/ls
Desktop            Downloads          Workspace          dymaxionmap.core   lib                src
Documents          Pictures           bin                include            lximage-qt.core
/home/homeuser>
[homeuser@pcunix ~/src/nsh2x]$

 

まずまず、どうにか動作しました。

が、しかし。 細かいところで粗が見えたりしています。

 

どれだけ年老いても、こんなことをやっていたいものです。

たとえ、私が認知症を発症したとしても。

(2型糖尿病持ちは、認知症リスクも健常者の4倍と言われています。)

 

 

さて、今回お届けする曲は

 

Matthews' Southern Comfort 1970年のシングル ヒット曲 - Woodstock