ホーム » Linux (ページ 3)

Linux」カテゴリーアーカイブ

2024年5月
 1234
567891011
12131415161718
19202122232425
262728293031  

カテゴリー

アーカイブ

ブログ統計情報

  • 80,898 アクセス



AS5202T 再セットアップ – 9

Linux Center を入れて Debian 10 Desktop をインストール.
AS5202T Linux Center
次のページを参考にさせてもらって日本語化.
https://www.server-world.info/query?os=Debian_10&p=japanese
WSLのDebian環境を日本語化する
sudo apt -y install task-japanese locales-all
sudo apt -y install task-japanese-desktop
再起動させて日本語になった.
AS5202T Debian 10 Desktop 日本語化


2020/05/05
gcc のインストール.
sudo apt install build-essential
glut のインストール.
sudo apt install freeglut3 freeglut3-dev
他によく使う tree のインストール.
sudo apt install tree
AS5202T Debian glut
https://dev.mish.work/wordpress/2019/08/16/glut-install/
https://jml.mish.work/index.php/cpp/install-glut.html
https://jml.mish.work/index.php/cpp/glut.html


2020/05/06
Debian の環境の実体は以下に存在している.
/volume1/.@plugins/AppCentral/linux-center/containers/debian10/rootfs/home/admin
AS5202T Linux Center  Debian10 rootfs

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

PHP から iconv コマンド呼び出し

シフトJIS のデータファイルをアップロードして WebGL で表示のテスト.
PHP から作成した .out を呼び出しているが,その中で文字コードの変換がうまく機能していない.
.out の中では iconv ライブラリを呼び出す.うまく機能しない時は iconv または uconv コマンド.
.out をコンソールから実行した時はうまく機能している.


いろいろと動作を調べていると,次の様なコマンドが PHP から呼出された時うまく機能していない様子.
iconv -f CP932 shiftjis.txt > out_file.txt
コンソールでは OK .
ここまで絞り込むのに 1 日かかった


今回の修正前 Synology NAS では次の様にしていた.
uconv -f sjis -t utf8 shiftjis.txt -o out_file.txt


先日テストしていた時 ASUSTOR NAS ではエラーになったので,単純に -t オプションを取ってしまった.

Iwao@AS5202T:/volume1/Web/Test/mics/tc_xconv $ iconv -f CP932 -t utf8 shiftjis.txt
iconv: conversion to utf8 unsupported
iconv: try 'iconv -l' to get the list of supported encodings
Iwao@AS5202T:/volume1/Web/Test/mics/tc_xconv $

iconv -l を幾つかの環境で調べていると “utf8” の指定がうまくない.
いろいろな環境でうまく機能しそうなのは “UTF-8” .
Fedora iconv -l | grep -i utf
Raspberry Pi iconv -l | grep -i utf
DS116 uconv -l | grep -i utf
AS5202T iconv -l | grep -i utf


-t オプションを指定しないとうまくないみたいで,次の様に変更.
iconv -f CP932 -t UTF-8 shiftjis.txt > out_file.txt
これで意図した動作になった.


2020/09/08 変換できない文字が存在した時に止まらない様な指定を追加.
https://mish.myds.me/wordpress/dev/2020/09/07/upload-mbcs-name/
exec_ic.hxx
text_gnc.hxx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

ASUSTOR NAS 上の iconv , whois

ASUSTOR NAS の iconv は Fedora や Synology NAS uconv の -o(出力ファイルの指定)がない.

[Iwao@fedora ~]$ iconv --help
使用法: iconv [OPTION...] [FILE...]
与えられたファイルのエンコーディングをあるエンコーディングから別のエンコーディングに変換します。
 入力/出力形式の指定:
  -f, --from-code=NAME       元のテキストのエンコーディング
  -t, --to-code=NAME         出力用のエンコーディング
 情報:
  -l, --list
                             全ての既知の符号化された文字集合を一覧表示します
 出力制御:
  -c                         出力から無効な文字を取り除く
  -o, --output=FILE          出力ファイル
  -s, --silent               警告を抑制する
      --verbose              経過情報を表示する

  -?, --help                 このヘルプ一覧を表示する
      --usage                短い使用方法を表示する
  -V, --version              プログラムのバージョンを表示する
長い形式のオプションで必須または任意の引数は、それに対応する短い形式のオプションでも同様に必須または任意です。
For bug reporting instructions, please see:
.
[Iwao@fedora ~]$ iconv --version
iconv (GNU libc) 2.30
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
作者 Ulrich Drepper。
[Iwao@fedora ~]$ 
Iwao@AS5202T:/volume1/home/Iwao $ iconv --help
Usage: iconv [OPTION...] [-f ENCODING] [-t ENCODING] [INPUTFILE...]
or:    iconv -l
Converts text from one encoding to another encoding.
Options controlling the input and output format:
  -f ENCODING, --from-code=ENCODING
                              the encoding of the input
  -t ENCODING, --to-code=ENCODING
                              the encoding of the output
Options controlling conversion problems:
  -c                          discard unconvertible characters
  --unicode-subst=FORMATSTRING
                              substitution for unconvertible Unicode characters
  --byte-subst=FORMATSTRING   substitution for unconvertible bytes
  --widechar-subst=FORMATSTRING
                              substitution for unconvertible wide characters
Options controlling error output:
  -s, --silent                suppress error messages about conversion problems
Informative output:
  -l, --list                  list the supported encodings
  --help                      display this help and exit
  --version                   output version information and exit
Report bugs to .
Iwao@AS5202T:/volume1/home/Iwao $ iconv --version
iconv (GNU libiconv 1.14)
Copyright (C) 2000-2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Bruno Haible.
Iwao@AS5202T:/volume1/home/Iwao $

AS5202T iconv help
次の様にリダイレクトして指定すれば良い.
iconv -f CP932 sjis_file.txt > out_file.txt
他にも whois はサーバを指定しないとうまく機能しない?
whois -h whois.apnic.net 27.92.169….

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

std::fixed でアプリケーションエラー

先日やっていた計算式のコード.これをテストしていてエラーに.
エラーとなるコードの場所は数値を文字列に変換する所.
その部分だけを抜き出したコードは次の様なもの.

bool	test	(c_tstring& str_)
{
	tstring	str = str_ ;
	{
		TCHAR*	endPtr = 0 ;
		double	val = double(_tcstod(str.c_str(),&endPtr)) ;
							std::tout << std::fixed      << val << std::endl ;
	//	if (-1e50 < val && val < 1e50)	{	std::tout << std::fixed      << val << std::endl ;	}
	//	else				{	std::tout << std::scientific << val << std::endl ;	}
		}
	return	true ;
	}

1e300 などの値を std::fixed で表示すると,限られた環境でビルドした exe でエラーになる.
エラーが確認できたのは VC 6 で MFC を使用しないでビルドしたもの.
VC 6 でも DLL でリンクしている場合は,ランタイムの DLL のバージョンにより大丈夫.

Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/mba_20/chk_big $ c++ chk_big.cpp  -Wall
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/mba_20/chk_big $ ./a.out
value ? =1e10
10000000000.000000
value ? =1e100
10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104.000000
value ? =1e200
99999999999999996973312221251036165947450327545502362648241750950346848435554075534196338404706251868027512415973882408182135734368278484639385041047239877871023591066789981811181813306167128854888448.000000
value ? =1e300
1000000000000000052504760255204420248704468581108159154915854115511802457988908195786371375080447864043704443832883878176942523235360430575644792184786706982848387200926575803737830233794788090059368953234970799945081119038967640880074652742780142494579258788820056842838115669472196386865459400540160.000000
value ? =1e400
inf
value ? =1e307
9999999999999999860310597602564577717002641838126363875249660735883565852672743849064846414228960666786379280392654615393353172850252103336275952370615397010730691664689375178569039851073146339641623266071126720011020169553304018596457812688561947201171488461172921822139066929851282122002676667750021070848.000000
value ? =1e308
100000000000000001097906362944045541740492309677311846336810682903157585404911491537163328978494688899061249669721172515611590283743140088328307009198146046031271664502933027185697489699588559043338384466165001178426897626212945177628091195786707458122783970171784415105291802893207873272974885715430223118336.000000
value ? =1e309
inf
value ? =-1e100
-10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104.000000
value ? =-1e307
-9999999999999999860310597602564577717002641838126363875249660735883565852672743849064846414228960666786379280392654615393353172850252103336275952370615397010730691664689375178569039851073146339641623266071126720011020169553304018596457812688561947201171488461172921822139066929851282122002676667750021070848.000000
value ? =-1e308
-100000000000000001097906362944045541740492309677311846336810682903157585404911491537163328978494688899061249669721172515611590283743140088328307009198146046031271664502933027185697489699588559043338384466165001178426897626212945177628091195786707458122783970171784415105291802893207873272974885715430223118336.000000
value ? =-1e309
-inf
value ? =1.e-100
0.000000
value ? =1.e-300
0.000000

ASUSTOR NAS で大きな数値の表示

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Freespire 6 インストール

先日 Twitter で見かけてブックマークしておいたサイト.
https://www.freespirelinux.com/2020/02/freespire-60-released.html
2020/06/22 https://www.freespire.net/
時間が空いたので VirtualBox の環境にインストールしてみた.
ちょっと手順がわかりにくい部分があったのでメモ.


仮想マシンの作成.
仮想マシンの作成
仮想ハードディスクの作成.
仮想ハードディスクの作成
ダウンロードした freespire-6.iso を選択.
freespire-6.iso を選択
仮想マシンの起動.
仮想マシンの起動
起動するとこんな感じ.
Freespire  CD から起動したデスクトップ
デスクトップにある「Install freespire 18.04」を開いてインストール開始.
Freespire インストール
インストーラの起動後,一番下に「日本語」がある.あとは表示に従い操作すれば OK .
Freespire インストールを完了するために再起動


日本語のフォルダが幾つかできているので変更.
LANG=C xdg-user-dirs-gtk-update
フォルダの日本語名を変更


2020/05/06
glut インストール.
sudo apt install freeglut3 freeglut3-dev
Freespire glut インストール

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

NAS g++ で a.out が作成されない?

warning はあるが,エラーの表示はない状態まで修正して g++ .

Iwao@DS116:~/gcc_test/Test/t_linux/t_calc$ g++ t_calc.cpp -Wall
In file included from /volume1/public/C_Sync/GoogleD/Develop/_.SRC/_gcc/V2_FuncA.hxx:1:0,
                 from Calc_16.cpp:46,
                 from t_calc.cpp:29:
/volume1/public/C_Sync/GoogleD/Develop/_.SRC/__CPR_/v2_funca.hxx: In constructor 'vd2_arc::vd2_arc()':
/volume1/public/C_Sync/GoogleD/Develop/_.SRC/__CPR_/v2_funca.hxx:28:9: warning: 'vd2_arc::tc' will be initialized after [-Wreorder]
  double tc ;
         ^~
/volume1/public/C_Sync/GoogleD/Develop/_.SRC/__CPR_/v2_funca.hxx:27:9: warning:   'double vd2_arc::ts' [-Wreorder]
  double ts ;
         ^~
/volume1/public/C_Sync/GoogleD/Develop/_.SRC/__CPR_/v2_funca.hxx:23:2: warning:   when initialized here [-Wreorder]
  vd2_arc () : lr(0) , tc(0) , ts(0) {}
  ^~~~~~~
/volume1/public/C_Sync/GoogleD/Develop/_.SRC/__CPR_/v2_funca.hxx: In function 'Vd2 get_point_pie(const Vd2&, const Vd2&, double, double)':
/volume1/public/C_Sync/GoogleD/Develop/_.SRC/__CPR_/v2_funca.hxx:263:6: warning: variable 'lm' set but not used [-Wunused-but-set-variable]
  Vd2 lm = (le-ls) / 2 ;
      ^~
In file included from t_calc.cpp:29:0:
Calc_16.cpp: In member function 'virtual int VarCnv::SetError(LPCTSTR, ...)':
Calc_16.cpp:1319:7: warning: variable 'cnt' set but not used [-Wunused-but-set-variable]
  int  cnt ;
       ^~~
Iwao@DS116:~/gcc_test/Test/t_linux/t_calc$ ls
Calc_16.BAK  Calc_16.cpp  Calc_16.hpp  t_calc.BAK  t_calc.cpp  t_calc.dsp
Iwao@DS116:~/gcc_test/Test/t_linux/t_calc$ g++ t_calc.cpp
Iwao@DS116:~/gcc_test/Test/t_linux/t_calc$ ls
Calc_16.BAK  Calc_16.cpp  Calc_16.hpp  t_calc.BAK  t_calc.cpp  t_calc.dsp
Iwao@DS116:~/gcc_test/Test/t_linux/t_calc$ ll
total 248
drwxrwxrwx+  2 Iwao users   4096 Feb  6 11:46 .
drwxrwxrwx+ 16 Iwao users   4096 Feb  6 10:18 ..
-rwxrwxrwx+  1 Iwao users 103036 Feb  6 11:45 Calc_16.BAK
-rwxrwxrwx+  1 Iwao users 103032 Feb  6 11:46 Calc_16.cpp
-rwxrwxrwx+  1 Iwao users  11608 Feb  5 18:53 Calc_16.hpp
-rwxrwxrwx+  1 Iwao users   2756 Feb  6 11:18 t_calc.BAK
-rwxrwxrwx+  1 Iwao users   2420 Feb  6 11:43 t_calc.cpp
-rwxrwxrwx+  1 Iwao users   4420 Feb  5 16:39 t_calc.dsp
Iwao@DS116:~/gcc_test/Test/t_linux/t_calc$ 

なのに a.out が作成されない.
Raspberry Pi で同様に動かすと

pi@raspberrypi:~/projects/t_calc $ g++ t_calc.cpp
In file included from t_calc.cpp:29:
Calc_16.cpp: In function ‘int ExpDel_Bracket1(TCHAR*, size_t, int, int, char)’:
Calc_16.cpp:2152:6: error: ‘_tcspbrk’ was not declared in this scope
  if (_tcspbrk(val,bracket)==NULL){ return FALSE ; } // ���ʂ����݂��Ȃ����͉������Ȃ�
      ^~~~~~~~
Calc_16.cpp:2152:6: note: suggested alternative: ‘wcspbrk’
  if (_tcspbrk(val,bracket)==NULL){ return FALSE ; } // ���ʂ����݂��Ȃ����͉������Ȃ�
      ^~~~~~~~
      wcspbrk
Calc_16.cpp:2161:21: error: ‘_tcsrchr’ was not declared in this scope
  LPTSTR equStartB = _tcsrchr(tmpLeft,startB) ; // �ŏ��� ')' �ɑΉ����� '(' �̈ʒu�����߂�
                     ^~~~~~~~
Calc_16.cpp:2161:21: note: suggested alternative: ‘_tcschr’
  LPTSTR equStartB = _tcsrchr(tmpLeft,startB) ; // �ŏ��� ')' �ɑΉ����� '(' �̈ʒu�����߂�
                     ^~~~~~~~
                     _tcschr
pi@raspberrypi:~/projects/t_calc $ 

どうも ShiftJIS のコメントが邪魔してかエラーが表示されてないだけみたい.
Raspberry Pi でコンパイルするとエラーが表示される
未定義となっているので正しく宣言して対応.


次は warning .

.../v2_funca.hxx:28:9: warning: 'vd2_arc::tc' will be initialized after [-Wreorder]      double tc ;
.../v2_funca.hxx:27:9: warning:   'double vd2_arc::ts' [-Wreorder]                       double ts ;
.../v2_funca.hxx:23:2: warning:   when initialized here [-Wreorder]                      vd2_arc () : lr(0) , tc(0) , ts(0) {}

これは,クラス内の変数の宣言と初期化の順番が異なる場合のものらしい.
もう一つの [-Wunused-but-set-variable] は戻り値を使用していないもの.

warning: variable 'lm' set but not used [-Wunused-but-set-variable]

変数を削除して対応.


前後するが 先日のツール で ShiftJIS のソースを UTF-8 に.

Iwao@DS116:~/gcc_test/Test/t_linux/t_calc$ cd test_sj/
Iwao@DS116:~/gcc_test/Test/t_linux/t_calc/test_sj$ ls
Calc_16.cpp  Calc_16.hpp  t_calc.BAK  t_calc.cpp
Iwao@DS116:~/gcc_test/Test/t_linux/t_calc/test_sj$ g++ t_calc.cpp -Wall
Iwao@DS116:~/gcc_test/Test/t_linux/t_calc/test_sj$ ll
total 132
drwxrwxrwx+ 2 Iwao users   4096 Feb  6 16:39 .
drwxrwxrwx+ 3 Iwao users   4096 Feb  6 16:38 ..
-rwxrwxrwx+ 1 Iwao users 103036 Feb  6 14:41 Calc_16.cpp
-rwxrwxrwx+ 1 Iwao users  11608 Feb  5 18:53 Calc_16.hpp
-rwxrwxrwx+ 1 Iwao users   1821 Feb  6 16:04 t_calc.BAK
-rwxrwxrwx+ 1 Iwao users   1841 Feb  6 16:39 t_calc.cpp
Iwao@DS116:~/gcc_test/Test/t_linux/t_calc/test_sj$ g++ t_calc.cpp -Wall -finput-charset=SJIS
cc1plus: error: conversion from SJIS to UTF-8 not supported by iconv
Iwao@DS116:~/gcc_test/Test/t_linux/t_calc/test_sj$ g++ t_calc.cpp -Wall
In file included from t_calc.cpp:27:0:
Calc_16.cpp: In function 'int ExpDel_Bracket1(TCHAR*, size_t, int, int, char)':
Calc_16.cpp:2152:26: error: '_tcspbrk' was not declared in this scope
  if (_tcspbrk(val,bracket)==NULL){ return FALSE ; } // 括弧が存在しない時は何もしない
                          ^
Iwao@DS116:~/gcc_test/Test/t_linux/t_calc/test_sj$ ll
total 136
drwxrwxrwx+ 3 Iwao users   4096 Feb  6 16:46 .
drwxrwxrwx+ 3 Iwao users   4096 Feb  6 16:38 ..
-rwxrwxrwx+ 1 Iwao users 108716 Feb  6 14:41 Calc_16.cpp
-rwxrwxrwx+ 1 Iwao users  12170 Feb  5 18:53 Calc_16.hpp
drwxrwxrwx+ 2 Iwao users   4096 Feb  6 16:45 org
-rwxrwxrwx+ 1 Iwao users   1841 Feb  6 16:39 t_calc.cpp
Iwao@DS116:~/gcc_test/Test/t_linux/t_calc/test_sj$

エラーが表示される.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Linux でのメモリの空き容量の取得

C++ のコードで Linux 環境でのメモリの使用状況 を知りたくなった.
コマンドでは free などがあるが,それと同等のものを取得する関数.

Iwao@DS116:~/gcc_test/Test/t_linux/T_mem/t_mem$ free -h
              total        used        free      shared  buff/cache   available
Mem:           1.0G        695M         29M         49M        281M        162M
Swap:          2.0G        1.0G        1.0G
Iwao@DS116:~/gcc_test/Test/t_linux/T_mem/t_mem$ cat /proc/meminfo
MemTotal:        1030632 kB
MemFree:           16720 kB
Buffers:            9392 kB
Cached:           203592 kB
SwapCached:       227532 kB
Active:           393336 kB
Inactive:         489268 kB
Active(anon):     322836 kB
Inactive(anon):   397436 kB
Active(file):      70500 kB
Inactive(file):    91832 kB
Unevictable:        1408 kB
Mlocked:            1408 kB
SwapTotal:       2097148 kB
SwapFree:        1060108 kB
Dirty:               200 kB
Writeback:             0 kB
AnonPages:        538800 kB
Mapped:            71992 kB
Shmem:             50524 kB
Slab:              89312 kB
SReclaimable:      17608 kB
SUnreclaim:        71704 kB
KernelStack:        4368 kB
PageTables:        14768 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     2612464 kB
Committed_AS:    4943664 kB
VmallocTotal:    1039360 kB
VmallocUsed:        6916 kB
VmallocChunk:     961204 kB
Iwao@DS116:~/gcc_test/Test/t_linux/T_mem/t_mem$ ./a.out
16474112
1055367168
Iwao@DS116:~/gcc_test/Test/t_linux/T_mem/t_mem$ cat main.cpp

#include        <iostream>
#include        <sys/sysinfo.h>

int     main    ()
{
        {
                struct  sysinfo meminfo ;
                ::sysinfo(&meminfo);
                std::cout << meminfo.freeram  << std::endl;
                std::cout << meminfo.totalram << std::endl;
                }
        return 0;
        }

Iwao@DS116:~/gcc_test/Test/t_linux/T_mem/t_mem$

Synology NAS DS116 ::sysinfo
最初 getrusage を見つけたが,マニュアルにある様にこの目的では使えない.値は 0 で返ってくる.
次に見つけたのが sysinfo
Fedora や Raspberry Pi ,Synology NAS で動作することを確認.

-		meminfo	{...}			sysinfo
		uptime		17198		__kernel_long_t
-		loads				__kernel_ulong_t [3]
		[0]		35520		__kernel_ulong_t
		[1]		30240		__kernel_ulong_t
		[2]		26880		__kernel_ulong_t
		totalram	2078154752	__kernel_ulong_t
		freeram 	107687936	__kernel_ulong_t
		sharedram	19849216	__kernel_ulong_t
		bufferram	145534976	__kernel_ulong_t
		totalswap	2227171328	__kernel_ulong_t
		freeswap	2206625792	__kernel_ulong_t
		procs   	468		__u16
		pad     	0		__u16
		totalhigh	0		__kernel_ulong_t
		freehigh	0		__kernel_ulong_t
		mem_unit	1		__u32
		_f				char [0]

memstat.hxx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

NAS のシャットダウン,再起動

Synology NAS なのであまり使用することはないが,SSH などで接続したコンソールから

シャットダウン sudo shutdown -h now sudo poweroff
再起動 sudo shutdown -r now sudo reboot
Synology NAS は,shutdown と poweroff ,reboot 共に可能
ASUSTOR NAS は, poweroff ,reboot が可能
QNAP NAS は,admin で入った端末から poweroff と reboot

Synology NAS DS115j コンソールからの「再起動」
DS115j reboot NOW


2020/12 poweroff ,reboot の追加.
https://dev.mish.work/wordpress/2020/12/01/nas-poweroff-reboot/



2021/09/03
NAS によって,起動中アプリのシャットダウン動作が異なるので注意が必要.
NAS の再起動などのスケージュール


https://jml.mish.work/various/nas.html

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

漢字を含むソースのテスト – 2

前回のコードで,文字列の部分を #define で指定.

Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_2$ uconv -f SJIS cc_ml_2.cpp

#include        <clocale>
#include        <iostream>
#include        "i_define.hxx"
#include        "_tdefine.hxx"
#include        "ccc_mlg.hxx"

#define Name_1_         _T("Name_1")
#define Name_2_         _T("Name_2")
#define Name_3_         _T("Name_3")
#define Name_4_         _T("Name_4")
#define Name_5_         _T("Name_5")
#define Name_1J         _T("名称 1")
#define Name_2J         _T("名称 2")
#define Name_3J         _T("名称 3")
#define Name_4J         _T("名称 4")
#define Name_5J         _T("名称 5")

bool    test    (void)
{
        {
                ccc_mlg*        cm = ::get_ccc_mlg() ;
                {
                        ccc_mlg_1       cm_1 ;  cm_1.Name = Name_1_ ;   cm_1.JPN = Name_1J ;
                        ccc_mlg_1       cm_2 ;  cm_2.Name = Name_2_ ;   cm_2.JPN = Name_2J ;
                        ccc_mlg_1       cm_3 ;  cm_3.Name = Name_3_ ;   cm_3.JPN = Name_3J ;
                        ccc_mlg_1       cm_4 ;  cm_4.Name = Name_4_ ;   cm_4.JPN = Name_4J ;
                        ccc_mlg_1       cm_5 ;  cm_5.Name = Name_5_ ;   cm_5.JPN = Name_5J ;
                        cm->push_back(cm_1) ;
                        cm->push_back(cm_2) ;
                        cm->push_back(cm_3) ;
                        cm->push_back(cm_4) ;
                        cm->push_back(cm_5) ;
                        }
                std::tout << ccc("Name_2") << std::endl ;
                }
        return  true ;
        }

int _tmain(int argc, TCHAR* argv[])
{
        _tsetlocale(LC_ALL,_T("")) ;
        test() ;
        return 0 ;
        }

Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_2$ uconv -f SJIS cc_ml_2.cpp  > dd.cpp
Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_2$ g++ dd.cpp -Wall
Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_2$ ./a.out
名称 2
Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_2$  

文字列の部分を #define で定義 Synology NAS 上でコンパイル


#define の部分を別のファイルとして保存.test_ccc.hpp
“㎥” を次の様に指定してみたが,Windows コンソール AP ではうまくいかない.

#define	Unit_M_				"Unit_M^3"
#ifdef	_MSC_VER
	#ifdef	_UNICODE
		#define	Unit_MJ		L"\x7acb "		L" \x33a5 "		L" \x7c73"
	#else
		#define	Unit_MJ		"立米"
	#endif
#else
		#define	Unit_MJ		"\xE3\x8E\xA5"
#endif

Synology NAS では OK .


文字コードを検索できるサイト
https://www.fileformat.info/info/unicode/char/search.htm


2020/01/20
Windows AP の場合のコードを少し変更.

	std::tout << ccc(Name_3_) << std::endl ;
	std::tout << ccc(Unit_M_) << std::endl ;
	tstring	ccc_str ;
	ccc_str += ccc(Name_3_) + _T("\r\n") ;
	ccc_str += ccc(Unit_M_) + _T("\r\n") ;
	::MessageBox(NULL,ccc_str.c_str(),_T("Test"),MB_OK) ;

「㎥」を含む ::MessageBox での表示
::MessageBox で意図した表示となることを確認.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

漢字を含むソースのテスト

’90 年代前半の頃は JIS と シフトJIS のソースを扱っていた.
そのプロジェクトの最初の頃は,ターゲット環境のみでソースを管理していた.
0x1c 0x2d 漢字 0x1c 0x2e の形式.wiki 漢字シフトコード
途中からソース管理は PC-9801DA などに移行してシフトJIS になった.
ターゲット環境に移す時,ソースのコピーとシフトJIS から JIS への変換を行っていた.


Linux 環境を意識し始めてから新規に書いた共通のコードは 7 ビットの範囲にしている.
Windows AP であれば rc ファイルの STRINGTABLE が使用できるが,これにあたるものをどうするか?
まず一番簡単な方法の漢字を含むソースでの動作をテストしてみた.
この中の ccc(const char* s) の部分はまだ暫定的なコードで,登録されたテーブルから対応する JPN を求めるもの.

#include	<clocale>
#include	<iostream>
#include	"i_define.hxx"
#include	"_tdefine.hxx"
#include	"ccc_mlg.hxx"

bool	test	(void)
{
	ccc_mlg*	cm = ::get_ccc_mlg() ;
	{
		ccc_mlg_1	cm_1 ;	cm_1.Name = _T("Name_1") ;	cm_1.JPN = _T("名称 1") ;
		ccc_mlg_1	cm_2 ;	cm_2.Name = _T("Name_2") ;	cm_2.JPN = _T("名称 2") ;
		ccc_mlg_1	cm_3 ;	cm_3.Name = _T("Name_3") ;	cm_3.JPN = _T("名称 3") ;
		ccc_mlg_1	cm_4 ;	cm_4.Name = _T("Name_4") ;	cm_4.JPN = _T("名称 4") ;
		ccc_mlg_1	cm_5 ;	cm_5.Name = _T("Name_5") ;	cm_5.JPN = _T("名称 5") ;
		cm->push_back(cm_1) ;
		cm->push_back(cm_2) ;
		cm->push_back(cm_3) ;
		cm->push_back(cm_4) ;
		cm->push_back(cm_5) ;
		}
	std::tout << ccc("Name_3") << std::endl ;
	return	true ;
	}

int _tmain(int argc, TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	test() ;
	return 0 ;
	}

gcc 漢字 shiftjis」で検索すると -finput-charset で文字コードを指定できるとある.

pi@raspberrypi:~/projects/cc_ml_1 $ g++ cc_ml_1.cpp 
pi@raspberrypi:~/projects/cc_ml_1 $ ./a.out 
���� 3
pi@raspberrypi:~/projects/cc_ml_1 $ g++ -finput-charset=SJIS-WIN cc_ml_1.cpp 
pi@raspberrypi:~/projects/cc_ml_1 $ ./a.out 
名称 3
pi@raspberrypi:~/projects/cc_ml_1 $ 

g++ -finput-charset=SJIS-WIN
-finput-charset=SJIS ではよくわからないエラーになる.
g++ -finput-charset=SJIS
cp932 でも良さそう.


Synology NAS DS116 は g++ の-finput-charset の指定では変換できないみたい.

Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_1$ g++ cc_ml_1.cpp -Wall
Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_1$ ll
total 72
drwxrwxrwx+  3 Iwao users  4096 Jan 16 22:01 .
drwxrwxrwx+ 10 Iwao users  4096 Jan 16 21:36 ..
-rwxrwxrwx   1 Iwao users 50452 Jan 16 22:01 a.out
drwxrwxrwx+  2 Iwao users  4096 Jan 16 21:53 bak
-rwxrwxrwx+  1 Iwao users  2001 Jan 16 22:00 cc_ml_1.cpp
Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_1$ ./a.out
 3
Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_1$ uconv -f sjis cc_ml_1.cpp > dd.cpp
Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_1$ g++ dd.cpp
Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_1$ ./a.out
名称 3
Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_1$ g++ -finput-charset=SJIS cc_ml_1.cpp
cc1plus: error: conversion from SJIS to UTF-8 not supported by iconv
Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_1$ g++ -finput-charset=sjis cc_ml_1.cpp
cc1plus: error: conversion from sjis to UTF-8 not supported by iconv
Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_1$ iconv
-sh: iconv: command not found
Iwao@DS116:~/gcc_test/Test/t_linux/cc_ml_1$
Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Linux での cp コマンド

ssh 接続 した linux 環境で,ファイルをコピーしようとして cp コマンドを使用.
その時,更新日時が変更されることに気付いた.

[Iwao@fedora ~]$ cp --help
使用法: cp [OPTION]... [-T] SOURCE DEST
または: cp [OPTION]... SOURCE... DIRECTORY
または: cp [OPTION]... -t DIRECTORY SOURCE...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

Mandatory arguments to long options are mandatory for short options too.
  -a, --archive                -dR --preserve=all と同様
      --attributes-only        ファイルのデータをコピーせず、ファイルの属性のみコピーする
      --backup[=CONTROL]       コピー先ファイルが存在する時にバックアップを作成する
  -b                           --backup と同様だが引数を受け付けない
      --copy-contents          再帰時に特殊ファイルの内容をコピーする
  -d                           --no-dereference --preserve=links と同様
  -f, --force                  if an existing destination file cannot be
                                 opened, remove it and try again (this option
                                 is ignored when the -n option is also used)
  -i, --interactive            prompt before overwrite (overrides a previous -n option)
  -H                           follow command-line symbolic links in SOURCE
  -l, --link                   コピーの代わりにファイルのハードリンクを作成する
  -L, --dereference            SOURCE にあるシンボリックリンクを常にたどる
  -n, --no-clobber             存在するファイルを上書きしない (前に指定した
                                 -i オプションを上書きする)
  -P, --no-dereference         SOURCE にあるシンボリックリンクを決してたどらない
  -p                           --preserve=mode,ownership,timestamps と同様
      --preserve[=ATTR_LIST]   指定した属性を保護する (デフォルト: mode,ownership,timestamps)。
                                 追加可能な属性: context, links, xattr, all
  -c                           deprecated, same as --preserve=context
      --no-preserve=ATTR_LIST  指定した属性を保護しない
      --parents                DIRECTORY 配下で SOURCE ファイルのフルパス名を使用する
  -R, -r, --recursive          再帰的にディレクトリをコピーする
      --reflink[=WHEN]         clone/CoW コピーを制御する。下記を参照
      --remove-destination     コピー先にファイルが存在する場合、開く前に削除する (--force と対照的)
      --sparse=WHEN            スパースファイル作成を制御する。下記を参照
      --strip-trailing-slashes  各 SOURCE 引数から末尾のスラッシュを全て削除する
  -s, --symbolic-link          コピーの代わりにシンボリックリンクを作成する
  -S, --suffix=SUFFIX          通常のバックアップ接尾辞を上書きする
  -t, --target-directory=DIRECTORY  全ての SOURCE 引数を DIRECTORY にコピーする
  -T, --no-target-directory    DEST を通常ファイルとして扱う
  -u, --update                 SOURCE ファイルがコピー先ファイルより新しいか存在しない時だけコピーする
  -v, --verbose                実行していることを説明する
  -x, --one-file-system        このファイルシステムだけで実行する
  -Z                           set SELinux security context of destination file to default type
      --context[=CTX]          like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX
      --help     この使い方を表示して終了する
      --version  バージョン情報を表示して終了する

Fedora での cp コマンドの --help
-p オプションで意図した動作となる.
また GUI 版の「ファイルマネージャ」などでは更新日時などは引き継がれる.
mv コマンドは更新日時は引き継がれる.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Linux 文字コード変換のコード

iconv を使用した方法

std::string	SJIS_to_UTF8	(const std::string& sj_str)
{
	tstring	u8_str ;
	iconv_t	icd = ::iconv_open("UTF8","Shift_JIS") ;
	if (icd == (iconv_t)-1) {
		u8_str = ::iconv_SJIS_UTF8(sj_str) ;
		}
	else {
		{
			size_t	sj_size = sj_str.length() ;
			size_t	u8_size = sj_str.length()*3 + 1024 ;
			u8_str.resize(u8_size) ;
			char*	sj_ptr = (char*)(&sj_str[0]) ;
			char*	u8_ptr = (char*)(&u8_str[0]) ;
			::iconv(icd,&sj_ptr,&sj_size,&u8_ptr,&u8_size) ;
			}
		::iconv_close(icd) ;
		}
	return	u8_str.c_str() ;
	}

iconv,uconv の部分

#define	cmd_iconv		_T("iconv")		//	linux
#define	cmd_uconv		_T("uconv")		//	DS116
 
bool	exec_x_conv	(const tstring& s_j_name,const tstring& u_8_name)
{
	tstring	sj_name = ::QuotM_Add_Auto(s_j_name) ;
	tstring	u8_name = ::QuotM_Add_Auto(u_8_name) ;
	tstring	param = _T(" -f sjis -t utf8 ") + sj_name + _T(" -o ") + u8_name ;
	if (::which( cmd_iconv)) {
		tstring	 exe_iconv = cmd_iconv	_T(" ") + param ;
		_tsystem(exe_iconv.c_str()) ;
		return	true ;
		}
	if (::which( cmd_uconv)) {
		tstring	 exe_uconv = cmd_uconv	_T(" ") + param ;
		_tsystem(exe_uconv.c_str()) ;
		return	true ;
		}
	return	false ;
	}
 
std::string	iconv_SJIS_UTF8(const std::string& sj_str)
{
	tstring	tmp_path = ::Get_i_Tools_tmp_date() ;
	tstring	now_str  = ::Now_Format(_T("%M%S")) ;
	tstring	s_j_name = ::Path_AddLastSP(tmp_path) + _T("sj_") + now_str + _T(".txt") ;
	tstring	u_8_name = ::Path_AddLastSP(tmp_path) + _T("u8_") + now_str + _T(".txt") ;
		s_j_name = ::CreateUniqueEmpty(s_j_name.c_str()) ;
		u_8_name = ::CreateUniqueEmpty(u_8_name.c_str()) ;
	std::string	u8_str ;
	{
		v_char	v_c_u8 ;
		v_char	v_c_sj = ::To_v_char(sj_str.c_str()) ;
				 ::v_c_SaveText(s_j_name.c_str(),v_c_sj) ;
		{
				 ::exec_x_conv(s_j_name,u_8_name) ;
			}
		v_c_u8 = ::v_c_Load (u_8_name.c_str()) ;
		u8_str = ::To_tstring( v_c_u8   ).c_str() ;
		}
	return	u8_str.c_str() ;
	}

Fedora  iconv コマンドでの変換


うまく置き換わっていない文字があった.
‘~'(0x7e) が ‘‾'(0x203e) になってしまっていた.
他にも ‘\'(0x5c) が ‘¥'(0xa5) .
http://ossforum.jp/jossfiles/Linux_SJIS_Support.pdf
幾つか違う文字があるようで,iconv の -f sjis を SJIS-WIN でうまくいった.

	tstring	i_param = _T(" -f SJIS-WIN -t utf8 ") + sj_name + _T(" -o ") + u8_name ;
	tstring	u_param = _T(" -f sjis     -t utf8 ") + sj_name + _T(" -o ") + u8_name ;

2020/04/30 ASUSTOR NAS に対応
text_gnc.hxx exec_ic.hxx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Linux で文字コードの変換

Windows での文字コードの変換部分は MultiByteToWideChar,WideCharToMultiByte でうまく機能している.

 exe \ 入力 シフトJIS UTF-16 UTF-8
_UNICODE → WideChar そのまま → WideChar(CP_UTF8)
_MBCS そのまま → MultiByte → WideChar(CP_UTF8) → MultiByte

MultiByteToWideCharWideCharToMultiByte の使い方は C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\crt\src\ などの mbstowcs.c,wcstombs.c を参照.


MSDN で見つけた記事
C++ – STL の文字列クラスと Win32 API による Unicode エンコーディングの変換


Linux 環境での動作は 2014/03 に一度調べていたみたいで ” gcc iconv ” とコメントになっている.
それで https://ja.wikipedia.org/wiki/Iconv にあるコードを Raspberry Pi 環境で実行するとうまく変換できる.
コンパイルエラーになったので string.h のインクルードが必要かも?
同じコードを Synology NAS の DS116 でコンパイルして実行するとうまく動作しない
(そのままのコードでは止まってしまう).
iconv_open で (iconv_t)-1 が返されていて errno は EINVAL になってしまう.


iconv コマンドを試すと Raspberry Pi では OK .
Synology NAS は iconv が存在しない.
検索すると uconv が使えると書かれている.
https://forum.synology.com/enu/viewtopic.php?t=82591


Iwao@DS116:~$ uconv -L
ASCII-Latin Accents-Any Amharic-Latin/BGN Any-Accents Any-Publishing Arabic-Latin Arabic-Latin/BGN Armenian-Latin Armenian-Latin/BGN Azerbaijani-Latin/BGN Belarusian-Latin/BGN Bengali-Devanagari Bengali-Gujarati Bengali-Gurmukhi Bengali-Kannada Bengali-Latin Bengali-Malayalam Bengali-Oriya Bengali-Tamil Bengali-Telugu Bopomofo-Latin Bulgarian-Latin/BGN Cyrillic-Latin Devanagari-Bengali Devanagari-Gujarati Devanagari-Gurmukhi Devanagari-Kannada Devanagari-Latin Devanagari-Malayalam Devanagari-Oriya Devanagari-Tamil Devanagari-Telugu Digit-Tone Fullwidth-Halfwidth Georgian-Latin Georgian-Latin/BGN Greek-Latin Greek-Latin/BGN Greek-Latin/UNGEGN Gujarati-Bengali Gujarati-Devanagari Gujarati-Gurmukhi Gujarati-Kannada Gujarati-Latin Gujarati-Malayalam Gujarati-Oriya Gujarati-Tamil Gujarati-Telugu Gurmukhi-Bengali Gurmukhi-Devanagari Gurmukhi-Gujarati Gurmukhi-Kannada Gurmukhi-Latin Gurmukhi-Malayalam Gurmukhi-Oriya Gurmukhi-Tamil Gurmukhi-Telugu Halfwidth-Fullwidth Han-Latin Han-Latin/Names Hangul-Latin Hans-Hant Hant-Hans Hebrew-Latin Hebrew-Latin/BGN Hiragana-Katakana Hiragana-Latin IPA-XSampa Jamo-Latin Kannada-Bengali Kannada-Devanagari Kannada-Gujarati Kannada-Gurmukhi Kannada-Latin Kannada-Malayalam Kannada-Oriya Kannada-Tamil Kannada-Telugu Katakana-Hiragana Katakana-Latin Katakana-Latin/BGN Kazakh-Latin/BGN Kirghiz-Latin/BGN Korean-Latin/BGN Latin-ASCII Latin-Arabic Latin-Armenian Latin-Bengali Latin-Bopomofo Latin-Cyrillic Latin-Devanagari Latin-Georgian Latin-Greek Latin-Greek/UNGEGN Latin-Gujarati Latin-Gurmukhi Latin-Hangul Latin-Hebrew Latin-Hiragana Latin-Jamo Latin-Kannada Latin-Katakana Latin-Malayalam Latin-NumericPinyin Latin-Oriya Latin-Syriac Latin-Tamil Latin-Telugu Latin-Thaana Latin-Thai Macedonian-Latin/BGN Malayalam-Bengali Malayalam-Devanagari Malayalam-Gujarati Malayalam-Gurmukhi Malayalam-Kannada Malayalam-Latin Malayalam-Oriya Malayalam-Tamil Malayalam-Telugu Maldivian-Latin/BGN Mongolian-Latin/BGN NumericPinyin-Latin NumericPinyin-Pinyin Oriya-Bengali Oriya-Devanagari Oriya-Gujarati Oriya-Gurmukhi Oriya-Kannada Oriya-Latin Oriya-Malayalam Oriya-Tamil Oriya-Telugu Pashto-Latin/BGN Persian-Latin/BGN Pinyin-NumericPinyin Publishing-Any Russian-Latin/BGN Serbian-Latin/BGN Simplified-Traditional Syriac-Latin Tamil-Bengali Tamil-Devanagari Tamil-Gujarati Tamil-Gurmukhi Tamil-Kannada Tamil-Latin Tamil-Malayalam Tamil-Oriya Tamil-Telugu Telugu-Bengali Telugu-Devanagari Telugu-Gujarati Telugu-Gurmukhi Telugu-Kannada Telugu-Latin Telugu-Malayalam Telugu-Oriya Telugu-Tamil Thaana-Latin Thai-Latin Tone-Digit Traditional-Simplified Turkmen-Latin/BGN Ukrainian-Latin/BGN Uzbek-Latin/BGN XSampa-IPA am-am_FONIPA az-Lower az-Title az-Upper ch-ch_FONIPA cs-cs_FONIPA cs-ja cs-ko cs_FONIPA-ja cs_FONIPA-ko dsb-dsb_FONIPA el-Lower el-Title el-Upper eo-eo_FONIPA es-am es-es_FONIPA es-ja es-zh es_419-ja es_419-zh es_FONIPA-am es_FONIPA-es_419_FONIPA es_FONIPA-ja es_FONIPA-zh ia-ia_FONIPA it-am it-ja ja_Latn-ko ja_Latn-ru ky-ky_FONIPA la-la_FONIPA lt-Lower lt-Title lt-Upper nl-Title pl-ja pl-pl_FONIPA pl_FONIPA-ja ro-ja ro-ro_FONIPA ro_FONIPA-ja ru-ja ru-zh sk-ja sk-sk_FONIPA sk_FONIPA-ja tlh-tlh_FONIPA tr-Lower tr-Title tr-Upper uz_Cyrl-uz_Latn uz_Latn-uz_Cyrl yo-yo_BJ zh_Latn_PINYIN-ru Any-Null Any-Lower Any-Upper Any-Title Any-Name Name-Any Any-Remove Any-Hex/Unicode Any-Hex/Java Any-Hex/C Any-Hex/XML Any-Hex/XML10 Any-Hex/Perl Any-Hex Hex-Any/Unicode Hex-Any/Java Hex-Any/C Hex-Any/XML Hex-Any/XML10 Hex-Any/Perl Hex-Any Any-NFC Any-NFKC Any-NFD Any-NFKD Any-FCD Any-FCC Any-ch_FONIPA Any-Latin Any-Telugu Any-Gurmukhi Any-Gujarati Any-Malayalam Any-Oriya Any-Devanagari Any-Kannada Any-Tamil Any-cs_FONIPA Any-ru Any-Bengali Any-uz_Latn Any-Katakana Any-ro_FONIPA Any-ky_FONIPA Any-zh Any-yo_BJ Any-am Any-es_419_FONIPA Any-eo_FONIPA Any-es_FONIPA Any-sk_FONIPA Any-Hant Any-Hans Any-Hiragana Any-la_FONIPA Any-Syriac Any-Greek Any-Greek/UNGEGN Any-Cyrillic Any-Hangul Any-Bopomofo Any-Arabic Any-Thai Any-Armenian Any-Thaana Any-Georgian Any-Hebrew Any-am_FONIPA Any-dsb_FONIPA Any-ia_FONIPA Any-uz_Cyrl Any-pl_FONIPA
Iwao@DS116:~$
DS116 で uconv -L


iconv_open で失敗した場合,iconv コマンドまたは uconv コマンドとするか?


Linux 文字コード変換のコード


2022/07/15
SynoCli File Tools v2.6-16 で iconv が追加された.
SynoCli File Tools などのインストール方法は次の所に書いています.
https://dev.mish.work/wordpress/2022/06/15/ds116-entware/

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Windows , Linux 共通の c++ コード

3 年位前から,少しずつ Windows や Linux に依存しない c++ のコードを書く様にしている.
ソースファイルの文字コードと改行コードは 7 ビットの範囲で crlf にしている.
.sh などは lf でないとうまくない.
html などの場合は UTF-8 .
扱うファイル名も 7 ビットの範囲に限定している.
これで UI を伴わない範囲ではほぼうまく機能している.
次のページからのリンク先で WebGL を使用したサーバのコードはソースレベルで互換性あり.
https://itl.mydns.jp/i_Tools/

他に Windows 専用のコードとの区別のため,ファイル名を小文字に.
これは Linux では大文字,小文字が区別されるため.


今回既存の AP ドキュメントを扱うことに.
Windows でいう「シフト JIS」と「UNICODE」のテキストファイル.
他に UTF-8 のファイルもあるが対応する必要性は未定.
UTF-8 ファイルは Windows のコードでは書いているが,テスト用に存在するのみ.


今までの Windows のコード(tstrmbwc.hxx)では _T や _UNICODE の有無でうまく機能している.
読み込んだ時に _UNICODE の有無でそれぞれの文字コードで保持すればほぼ OK .
「ほぼ」というのは「㎥」の様にシフト JIS にない文字は失われてしまうため.
他にもサロゲートペアにはうまく対応できていない.


Linux でも同様に考えると,読み込んだ時に UTF-8 にすれば良さそう.
wchar_t もあるみたいだが今の時点では考慮しないことにする.
と,思ってテスト用のコードを書いてみたがうまく動作しない.
恐らく変換関連の考え方が理解できていないため.


2020/02 「文字コードを変更してコピー」するツール
https://i–tools.blogspot.com/2020/02/copycc202001.html
「文字コードを変換してコピー」するツール

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Win10 に IIS と PHP – 3

どこかに設定があるのかもしれないが,
PHP でのエラーなどのログファイル.
場所は c:\Windows\Temp\ .
Win10 IIS PHP のログファイル
今回テストした PHP のコード

<?php
	$tempfile =             $_FILES['fname']['tmp_name'];
	$filename = './data/' . $_FILES['fname']['name'] ;
	$up_status = false ;
	if (is_uploaded_file($tempfile)) {
		$up_status = move_uploaded_file($tempfile , $filename) ;
		}
	$link	= "" ;
	if ($up_status) {
		$p_info = pathinfo($filename) ;
		$pi_ext = $p_info['extension'] ;
		$bmp_name = $filename . ".bmp" ;
		$to_bmp = FALSE ;
		if  	($pi_ext == "png")  {	$img = imagecreatefrompng ($filename) ;   $to_bmp = imagebmp($img,$bmp_name) ;	}
		else if	($pi_ext == "jpg")  {	$img = imagecreatefromjpeg($filename) ;   $to_bmp = imagebmp($img,$bmp_name) ;	}
		else if ($pi_ext == "bmp")  {	$bmp_name = $filename ;                   $to_bmp = TRUE ;                 	}
		if ($to_bmp) {
			$cmd_to	= ("rsz_bmp.exe") . " " . $bmp_name ;
			exec	($cmd_to,$out,$ret) ;
			}
		if ($ret == 0) {
			$rsz_file = $out[count($out)-1] ;
			$bak_file = $filename . ".bak." . $pi_ext ;
			rename($filename,$bak_file) ;
			$rsz_name = pathinfo($rsz_file)['basename'] ;
			$file_rsz = $p_info['dirname'] . "/" . $rsz_name ;
			rename($rsz_file,$file_rsz) ;
			if    	($pi_ext == "png")  {	$img_bmp = imagecreatefrombmp($file_rsz) ;   imagepng ($img_bmp,$filename) ;	}
			else if	($pi_ext == "jpg")  {	$img_bmp = imagecreatefrombmp($file_rsz) ;   imagejpeg($img_bmp,$filename) ;	}
			else if ($pi_ext == "bmp")  {	copy($file_rsz,$filename) ;                                             	}
			if (!file_exists($filename)) {
				$filename = $file_rsz ;
				}
			}
		if (file_exists($filename)) {
			$link .= "<hr/>" ;
			$link .= "<a href='" ;
			$link .= $filename ;
			$link .= "'>" ;
			$link .= $filename ;
			$link .= "</a>" ;
			$link .= "<br/>" ;
			$link .= "<img src='" ;
			$link .= $filename ;
			$link .= "'>" ;
			}
		}
	?>

rsz_bmp.exe で画像ファイルを 2^n にリサイズし,その結果のファイル名を標準出力に出力する.
画像を出力する imagebmp などはあまり速くない.
同様の PHP を Synology NAS 上で.
https://itl.mydns.jp/…/tex_pow2.php
PHP のコードが悪いのか? Synology NAS では DIB から元の画像に戻すのがうまくいかない.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Raspberry Pi に ImageMagick

以前調べた時に入っていた ImageMagick
先日追加した SD の Pi 環境には入っていないのでインストール.
検索すると sudo apt install ImageMagick とある.が,入力すると,
pi@raspberrypi:~ $ sudo apt install ImageMagick
パッケージリストを読み込んでいます… 完了
依存関係ツリーを作成しています
状態情報を読み取っています… 完了
E: パッケージ ImageMagick が見つかりません
正しくは,
sudo apt install imagemagick
Raspberry Pi に ImageMagick のインストール
パッケージ名は小文字で指定する. imagemagick

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Fedora 環境で bmp が読めない

先日 GLUT でテクスチャ表示 の動作を確認していた時のこと.
Raspberry Pi ではうまく表示できることまで確認.
Raspberry Pi で GLUT テスクチャ表示
Fedora ではうまく読めない.
コードでテクスチャを生成しての表示ではうまくいく.
Fedora コードでテクスチャを作成しての表示
32 ビット色 BMP のコードは Synology NAS Web サーバなどでもそれなりに動作している.
Synology NAS で i_DIB を使用
32 bit exe ではうまく読み書きできているみたい.


Raspberry Pi (ARM) と Fedora (x64) で BITMAPFILEHEADER などを見ると 64 bit 環境でうまくない.
Raspberry Pi の BITMAPFILEHEADER BITMAPINFOHEADER
Fedora の BITMAPFILEHEADER BITMAPINFOHEADER
例えば bmih.biSize が x64 では 0x50 になっている(ARM では 0x28).


def_bmp.hxx が間違っているみたい.
どうも long の定義が Windows と Linux などでは異なるため.wiki 整数型


DWORD と LONG の定義を u_32 と i_32 に変更(u_32 ,i_32 は i_define.hxx で定義している).

//typedef unsigned long       DWORD;
typedef   u_32                DWORD;
//typedef long                LONG;
typedef   i_32                LONG;

Fedora での GLUT テクスチャ表示

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Raspberry Pi で NAS が …

以前は表示されていたと思うが…
Raspberry Pi のファイルマネージャ Pcmanfm で「移動」-「ネットワーク」で NAS などが表示されていない.
Raspberry Pi のファイルマネージャで「移動」-「ネットワーク」
しばらく対応方法がわからなかった.
「ファイルマネージャ」の「アドレス欄」に smb://ds116/ の様に入力することで接続できることを確認.
Raspberry Pi ファイルマネージャのアドレス欄に smb://ds116/

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

GLUT でテクスチャ表示

今度はテクスチャ.次の様なコードで面に貼り付け.

#include	"glut_cg.hxx"
#include	"gonsprmt.hxx"
#include	"i_dib_f.hxx"

i_DIB	tex_01 ;

int	main(int argc, char* argv[])
{
	{
		tstring	test_bmp = _T("./Tex01.bmp") ;
		//     	test_bmp = _T("/run/user/1000/gvfs/smb-share:server=ds116.local,share=web/i_Tools/Doc/blog/3D_Data/Tex01.bmp") ;
		#ifdef  _MSC_VER
		      	test_bmp = _T("//DS116/web/i_Tools/Doc/blog/3D_Data/Tex01.bmp") ;
		#endif
		tex_01 = ::DIB_Load(test_bmp.c_str()) ;
		}
	{
		GonsA	gnsa ;
		{
			Gons1	box = ::Gons_Box(Vd3(5,0,5)) ;
			box.SetColor(0xffffff) ;
			gnsa.push_back(box) ;
			}
		::set_GonsA(gnsa) ;
		::set_Extent(::GonsA_GetExtent(gnsa)) ;
		{
			C_glut*	gm = ::get_c_glut() ;
			gm->BG     = Vd4(0.9) ;
			gm->EP     = Vd3(0,-10,0) ;
			}
		}
	::glutInitWindowPosition(200,100) ;
	::glutInitWindowSize	(600,600) ;
	::glutInitDisplayMode	(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) ;
	::glutInit           	(&argc,argv) ;
	::glutCreateWindow  	(argv[0]) ;
	::glutReshapeFunc   	(cv_resize) ;
	::glutDisplayFunc   	(cg_display) ;
	::glutKeyboardFunc  	(cv_keyboard) ;
	::glutMouseFunc   	(cv_mouse) ;
	::glutMotionFunc  	(cv_motion) ;
	::cv_init       	() ;
	{
		::glPixelStorei(GL_UNPACK_ALIGNMENT,1) ;
		::glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,tex_01.GetWidth(),tex_01.GetHeight(),0,GL_RGB,GL_UNSIGNED_BYTE,tex_01.GetP_Bits()) ;
		::glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST) ;
		::glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST) ;
		::glEnable(GL_TEXTURE_2D) ;
		}
	::glutMainLoop   	() ;
	return	0 ;
	}

::glTexImage2D の指定と Tex01.bmp の形式が合っていないため
GLUT でテクスチャ表示 間違った GL_RGB の指定でずれている
32 ビット色の画像なので ::glTexImage2D の GL_RGB を GL_RGBA に.
GLUT でのテスクチャ表示 R と B  が合っていない
色の順番が違うので ::glTexImage2D を見ると GL_BGRA_EXT があったのでこれを指定.
GLUT でテクスチャ表示 GL_BGRA_EXT を指定

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

OpenGL 線を表示すると途切れる?

線の配列から連続線に変更して OpenGL で表示すると途切れた表示になってしまった.
OpenGL GL_LINES と GL_LINE_STRIP
線分として表示していた時のコード

	for (size_t lIndex=0 ; lIndex<lins.size() ; lIndex++) {
		Vl2	ln = lins[lIndex] ;
		Vd3	p0 = ::Vx_get(pnts,ln.x) ;
		Vd3	p1 = ::Vx_get(pnts,ln.y) ;
		::glBegin(GL_LINES) ;
		{
			::glVertex(p0....) ;
			::glVertex(p1....) ;
			}
		::glEnd() ;
		}

途切れてしまったコード

	for (size_t lIndex=0 ; lIndex<lins.size() ; lIndex++) {
		v_long	lin = lins[lIndex] ;
		::glBegin(GL_LINES) ;
	//	::glBegin(GL_LINE_STRIP) ;
		for (size_t vIndex=0 ; vIndex<lin.size() ; vIndex++) {
			long	ln = lin[vIndex] ;
			Vd3	pt = ::Vx_get(pnts,ln) ;
			::glVertex(pt....) ;
			}
		::glEnd() ;
		}

原因は glBegin の指定が GL_LINES のままだった.
GL_LINE_STRIP に修正して意図した表示になった.
OpenGL Programming Guide
Chapter 2 State Management and Drawing Geometric Objects

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.