OSDN Git Service

VER0.1.0 final? VER0.1.0
authorwww <www@dev.minakoe.jp>
Sat, 4 Sep 2010 22:18:53 +0000 (18:18 -0400)
committerwww <www@dev.minakoe.jp>
Sat, 4 Sep 2010 22:18:53 +0000 (18:18 -0400)
19 files changed:
1stclass.h
1stclass.hpp
LICENSE [new file with mode: 0755]
Makefile
README [new file with mode: 0755]
add_version.pl
host2ip.c
is_num.c
itoa.c
rel2abs.c [new file with mode: 0755]
remove_not_file_char.c [new file with mode: 0755]
remove_path.c
remove_special_char.c [deleted file]
reverse_char.c
rmkdir.c
safe_strcat.c
safe_strncat.c
shmf.c
t/test.cpp

index 627659b..b08cde7 100755 (executable)
@@ -1,3 +1,10 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -7,8 +14,9 @@ int is_num(const char *moji);
 int itoa(int n, char s[]);
 int reverse_char(char s[]);
 int rmkdir(const char *check_dir);
+int rel2abs(const char *rel_path, char *abs_path);
 int remove_path(const char *path);
-int remove_special_char(const char *str, char *dst);
+int remove_not_file_char(const char *str, char *dst);
 int safe_strcat(char *dst, const char *append);
 int safe_strncat(char *dst, const char *append, const unsigned int len);
 int shmf(const char *file, char *shmfile);
index e2065aa..9967ebd 100755 (executable)
@@ -1,8 +1,12 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
 #ifndef INCLUDED_1stclass
 #define INCLUDED_1stclass
-#include <string>
-#include <iostream>
-
 using namespace std;
 
 class firstclass {
@@ -11,8 +15,9 @@ public:
   int is_num(const string moji);
   int itoa(int n, char s[]);
   int rmkdir(const string check_dir);
+  string rel2abs(const string in_rel_path);
   int remove_path(const string path);
-  int remove_special_char(string &str);
+  string remove_not_file_char(const string *str);
   int reverse_char(char s[]);
   int safe_strcat(char *dst, const char *append);
   int safe_strncat(char *dst, const char *append, const unsigned int len);
diff --git a/LICENSE b/LICENSE
new file mode 100755 (executable)
index 0000000..2fbbf3a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,58 @@
+/*
+lib1stclass
+Copyright 2010-: 1stclass.co.jp & Hajime Kurita
+Created by: Hajime Kurita
+
+<<LICENSE (English)>>
+
+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; version 3
+of the License.
+
+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 this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+<<ライセンス(Japanese)>>
+このソフトはGNU General Public Lincenseバージョン3に基づいて提供されています。
+GPL3の条件に従って利用する事が出来ます。
+
+以下Wikipediaからの説明
+http://ja.wikipedia.org/wiki/GNU_General_Public_License
+
+[GPLの主な特徴]
+GPLは、プログラムの著作物の複製物を所持している者に対し、概ね以下のことを許諾するライセンスである。
+・プログラムの実行
+・プログラムの動作を調べ、それを改変すること(ソースコードへのアクセスは、その前提になる)
+・複製物の再頒布
+・プログラムを改良し、改良を公衆にリリースする権利(ソースコードへのアクセスは、その前提になる)
+GPLと、より制限の緩いフリーソフトウェア・ライセンス(BSDライセンスなど)との間の主な違いは、GPLが二次的著作物(派生的著作物)についても、上記の4点の制約を保存しようとする点である。
+この仕組みはコピーレフトと呼ばれ、GPLでライセンスされた著作物は、その二次的著作物に関してもGPLでライセンスされなければならない。
+これは、BSDライセンスが、二次的著作物を独占的なものとして再頒布することを許しているのとは対照的である。
+
+[条項と条件]
+GPLは、ソフトウェアの利用者に対し無制限に再頒布権を与えているわけではない。
+再頒布権が与えられるのは、頒布物にあらゆる修正を含めたソースコードを含んでいるか、ソースコードを提供する旨の法的申し出が添えられているときだけである。
+この要件は、コピーレフト (copyleft) といって、プログラムが著作権の対象になり、かつ著作権者が他者に対して権利を設定できることが法的に認められているという事実から、その法的な効力を得ている。
+通常はGPLで認められた場合を除き、利用者には再頒布の権利がない。
+そのため、著作権者以外が再頒布を行うには、GPLの条項に従うことが必要になる。
+逆に、GPLの条項を守らずに (たとえばソースコードを秘密にしたまま) 複製物を頒布すると、著作権者から頒布の差止を求められる場合がある。
+コピーレフトは、著作権法を通常使用される目的とは反対の目的を実現するために用いている。
+制限を課す代わりに、権利が後でなくならないような方法で、他の人へ利用を許諾する。そのため、GPLは"copyright hack" だといわれる。
+多くの場合、ソースコードと実行ファイルは同時に頒布されている。
+コピーレフトを満たすもう一つの方法は、(CDのような) 物理媒体でソースコードを提供する旨の書面を出すことである。
+インターネットでの頒布は、ライセンスに適合する。
+コピーレフトは、だれかがプログラムを再頒布しようとするときにだけ適用される。
+私的な修正版を作ることはだれにも許されていて、修正版を頒布しない限り、修正されたソースコードを開示する義務はない。
+コピーレフトは、ソフトウェアに適用されるだけで、その出力にではない (出力自体がプログラムから派生したものでなければ)。
+たとえば、GPLにされたCMS (content management system) を修正した派生版で動いている公開ウェブ・ポータルは、土台としたソフトウェアを頒布する必要はない。
+GPL第3版ではこの規定の改定が提案されている。
+なお、GPLのもとでリリースされたプログラムの著作物の著作権は、譲渡行為が無ければ個々のコードの著作者が保有している。
+GPLを無視した再頒布に対して、頒布の差し止めやGPLの強制などを請求する権利があるのは、通常著作権者だけであり、一般の利用者にはない。
+*/
\ No newline at end of file
index 52099d5..8474fc3 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -1,81 +1,87 @@
 all: lib1stclass.a libb1stclass.so lib1stclass_cxx.a lib1stclass_cxx.so t/test
 
-lib1stclass_cxx.a: host2ip_cxx.o is_num_cxx.o remove_path_cxx.o remove_special_char_cxx.o rmkdir_cxx.o 1stclass.hpp safe_strcat_cxx.o safe_strncat_cxx.o shmf_cxx.o itoa_cxx.o reverse_char_cxx.o
-       ar rvs lib1stclass_cxx.a host2ip_cxx.o is_num_cxx.o remove_path_cxx.o remove_special_char_cxx.o rmkdir_cxx.o safe_strcat_cxx.o safe_strncat_cxx.o shmf_cxx.o itoa_cxx.o reverse_char_cxx.o
+lib1stclass_cxx.a: host2ip_cxx.o is_num_cxx.o remove_path_cxx.o remove_not_file_char_cxx.o rmkdir_cxx.o 1stclass.hpp safe_strcat_cxx.o safe_strncat_cxx.o shmf_cxx.o itoa_cxx.o reverse_char_cxx.o rel2abs_cxx.o
+       ar rvs lib1stclass_cxx.a host2ip_cxx.o is_num_cxx.o remove_path_cxx.o remove_not_file_char_cxx.o rmkdir_cxx.o safe_strcat_cxx.o safe_strncat_cxx.o shmf_cxx.o itoa_cxx.o reverse_char_cxx.o rel2abs_cxx.o
        ranlib lib1stclass_cxx.a;
 
-lib1stclass_cxx.so: host2ip_cxx.o is_num_cxx.o remove_path_cxx.o remove_special_char_cxx.o rmkdir_cxx.o 1stclass.hpp safe_strcat_cxx.o safe_strncat_cxx.o shmf_cxx.o reverse_char_cxx.o
-       g++ -shared -fPIC -o lib1stclass_cxx.so host2ip_cxx.o is_num_cxx.o remove_path_cxx.o remove_special_char_cxx.o rmkdir_cxx.o safe_strcat_cxx.o safe_strncat_cxx.o shmf_cxx.o reverse_char_cxx.o
+lib1stclass_cxx.so: host2ip_cxx.o is_num_cxx.o remove_path_cxx.o remove_not_file_char_cxx.o rmkdir_cxx.o 1stclass.hpp safe_strcat_cxx.o safe_strncat_cxx.o shmf_cxx.o reverse_char_cxx.o rel2abs_cxx.o
+       g++ -shared -fPIC -o lib1stclass_cxx.so host2ip_cxx.o is_num_cxx.o remove_path_cxx.o remove_not_file_char_cxx.o rmkdir_cxx.o safe_strcat_cxx.o safe_strncat_cxx.o shmf_cxx.o reverse_char_cxx.o rel2abs_cxx.o
 
-lib1stclass.a: host2ip.o rmkdir.o safe_strcat.o safe_strncat.o is_num.o itoa.o remove_path.o remove_special_char.o shmf.o reverse_char.o 1stclass.h
-       ar rvs lib1stclass.a host2ip.o itoa.o rmkdir.o safe_strcat.o safe_strncat.o is_num.o remove_path.o remove_special_char.o shmf.o reverse_char.o
+lib1stclass.a: host2ip.o rmkdir.o safe_strcat.o safe_strncat.o is_num.o itoa.o remove_path.o remove_not_file_char.o shmf.o reverse_char.o rel2abs.o
+       ar rvs lib1stclass.a host2ip.o itoa.o rmkdir.o safe_strcat.o safe_strncat.o is_num.o remove_path.o remove_not_file_char.o shmf.o reverse_char.o rel2abs.o
        ranlib lib1stclass.a;
 
-libb1stclass.so: host2ip.o rmkdir.o safe_strcat.o safe_strncat.o is_num.o itoa.o remove_path.o remove_special_char.o shmf.o reverse_char.o 1stclass.h
-       g++ -shared -fPIC -o lib1stclass.so host2ip.o itoa.o rmkdir.o safe_strcat.o safe_strncat.o is_num.o remove_path.o remove_special_char.o shmf.o reverse_char.o
+libb1stclass.so: host2ip.o rmkdir.o safe_strcat.o safe_strncat.o is_num.o itoa.o remove_path.o remove_not_file_char.o shmf.o reverse_char.o rel2abs.o
+       g++ -shared -fPIC -o lib1stclass.so host2ip.o itoa.o rmkdir.o safe_strcat.o safe_strncat.o is_num.o remove_path.o remove_not_file_char.o shmf.o reverse_char.o rel2abs.o
 
 host2ip.o: host2ip.c
-       gcc -Wall -c host2ip.c;
+       gcc -Wall -O3 -finline-functions -c host2ip.c;
 
 host2ip_cxx.o: host2ip.c
-       g++ -Wall -o host2ip_cxx.o -c host2ip.c;
+       g++ -Wall -O3 -finline-functions -o host2ip_cxx.o -c host2ip.c;
 
 is_num.o: is_num.c
-       gcc -Wall -c is_num.c;
+       gcc -Wall -O3 -finline-functions -c is_num.c;
 
 is_num_cxx.o: is_num.c
-       g++ -Wall -o is_num_cxx.o -c is_num.c;
+       g++ -Wall -O3 -finline-functions -o is_num_cxx.o -c is_num.c;
 
 itoa.o: itoa.c
-       gcc -Wall -c itoa.c
+       gcc -Wall -O3 -finline-functions -c itoa.c
 
 itoa_cxx.o: itoa.c
-       g++ -Wall -o itoa_cxx.o -c itoa.c
+       g++ -Wall -O3 -finline-functions -o itoa_cxx.o -c itoa.c
 
 reverse_char.o: reverse_char.c;
-       gcc -Wall -c reverse_char.c;
+       gcc -Wall -O3 -finline-functions -c reverse_char.c;
 
 reverse_char_cxx.o: reverse_char.c;
-       g++ -Wall -o reverse_char_cxx.o -c reverse_char.c;
+       g++ -Wall -O3 -finline-functions -o reverse_char_cxx.o -c reverse_char.c;
 
-remove_special_char.o: remove_special_char.c;
-       gcc -Wall -c remove_special_char.c;
+remove_not_file_char.o: remove_not_file_char.c;
+       gcc -Wall -O3 -finline-functions -c remove_not_file_char.c;
 
-remove_special_char_cxx.o: remove_special_char.c;
-       g++ -Wall -o remove_special_char_cxx.o -c remove_special_char.c;
+remove_not_file_char_cxx.o: remove_not_file_char.c;
+       g++ -Wall -O3 -finline-functions -o remove_not_file_char_cxx.o -c remove_not_file_char.c;
 
 remove_path.o: remove_path.c
-       gcc -Wall -c remove_path.c;
+       gcc -Wall -O3 -finline-functions -c remove_path.c;
 
 remove_path_cxx.o: remove_path.c
-       g++ -Wall -o remove_path_cxx.o -c remove_path.c;
+       g++ -Wall -O3 -finline-functions -o remove_path_cxx.o -c remove_path.c;
+
+rel2abs.o: rel2abs.c
+       gcc -Wall -O3 -finline-functions -c rel2abs.c;
+
+rel2abs_cxx.o: rel2abs.c
+       g++ -Wall -O3 -finline-functions -o rel2abs_cxx.o -c rel2abs.c;
 
 rmkdir.o: rmkdir.c
-       gcc -Wall -c rmkdir.c;
+       gcc -Wall -O3 -finline-functions -c rmkdir.c;
 
 rmkdir_cxx.o: rmkdir.c
-       g++ -Wall -o rmkdir_cxx.o -c rmkdir.c;
+       g++ -Wall -O3 -finline-functions -o rmkdir_cxx.o -c rmkdir.c;
 
 safe_strcat.o: safe_strcat.c
-       gcc -Wall -c safe_strcat.c;
+       gcc -Wall -O3 -finline-functions -c safe_strcat.c;
 
 safe_strcat_cxx.o: safe_strcat.c
-       g++ -Wall -o safe_strcat_cxx.o -c safe_strcat.c;
+       g++ -Wall -O3 -finline-functions -o safe_strcat_cxx.o -c safe_strcat.c;
 
 safe_strncat.o: safe_strncat.c
-       gcc -Wall -c safe_strncat.c;
+       gcc -Wall -O3 -finline-functions -c safe_strncat.c;
 
 safe_strncat_cxx.o: safe_strncat.c
-       g++ -Wall -o safe_strncat_cxx.o -c safe_strncat.c;
+       g++ -Wall -O3 -finline-functions -o safe_strncat_cxx.o -c safe_strncat.c;
 
 shmf.o: shmf.c
-       gcc -Wall -c shmf.c;
+       gcc -Wall -O3 -finline-functions -c shmf.c;
 
 shmf_cxx.o: shmf.c
-       g++ -Wall -o shmf_cxx.o -c shmf.c;
+       g++ -Wall -O3 -finline-functions -o shmf_cxx.o -c shmf.c;
 
 t/test: t/test.cpp lib1stclass_cxx.a lib1stclass.a;
-       g++ -Wall -o t/test.o -c t/test.cpp;
+       g++ -Wall -O3 -finline-functions -o t/test.o -c t/test.cpp;
        g++ -o t/test t/test.o lib1stclass_cxx.a lib1stclass.a;
        chmod 755 t/test;
 
@@ -95,7 +101,7 @@ clean:
        rm *.a -f *.a;
        rm *.so -f *.so;
        rm t/test -f test;
-       rm t/*.o -f t/*.o
+       rm t/*.o -f t/*.o;
 
 real_clean:
        rm t/*~ -f t/*~;
@@ -104,7 +110,8 @@ real_clean:
        rm *.a -f *.a;
        rm *.so -f *.so;
        rm t/test -f test;
-       rm t/*.o -f t/*.o
+       rm t/*.o -f t/*.o;
+       rm *.tar.gz -f *.tar.gz;
 
 test:
        t/test;
diff --git a/README b/README
new file mode 100755 (executable)
index 0000000..c12a2e3
--- /dev/null
+++ b/README
@@ -0,0 +1,34 @@
+[About this module]\r
+This library offers the procedure which you want to use in many cases when you are developing, especially when you are developing for web application or backend application for it.\r
+This library is created by Hajime Kurita.\r
+The name 1stclass derives from the fact that the code is used for web application of http://www.1stclass.co.jp/\r
+\r
+Example:\r
+Blog search & analysis system: http://minakoe.jp/\r
+Japanese works database: http://www.accessup.org/anime/\r
+\r
+The code is distributed on http://sourceforge.jp/projects/lib1stclass/\r
+More detailed information is avaiable on blog.\r
+Japanese: http://www.accessup.org/pj/6_B4C9CDFDBFCDA4B5A4F3/5/list.html\r
+\r
+[License]\r
+You can use this under the license of GPL ver.3.\r
+\r
+[Install]\r
+make clean;\r
+make;\r
+make test;\r
+make install;\r
+\r
+[Usage]\r
+For C,\r
+lib1stclass.so\r
+lib1stclass.a\r
+\r
+For C++,\r
+lib1stclass_cxx.so\r
+lib1stclass_cxx.a\r
+\r
+are available.\r
+\r
+You can find functions, methods and how to use this library by reading the source code of t/test.cpp.\r
index 76b6861..24b4fbc 100755 (executable)
@@ -22,7 +22,7 @@ if(my $fh=new FileHandle("Changes")){
 if($version){\r
   if($release){\r
     my $dir='lib1stclass-'.$version;\r
-    my @cm=('mkdir '.$dir, 'cp *.c '.$dir, 'cp *.cpp '.$dir, 'cp *.h '.$dir, 'cp *.hpp '.$dir, 'cp *.pl '.$dir, 'cp Makefile '.$dir, 'cp Changes '.$dir, 'cp README '.$dir, 'mkdir -p '.$dir.'/t', 'cp t/*.cpp '.$dir.'/t', 'cp t/*.c '.$dir.'/t', 'tar cvf '.$dir.'.tar '.$dir, 'gzip '.$dir.'.tar');\r
+    my @cm=('mkdir '.$dir, 'cp *.c '.$dir, 'cp *.cpp '.$dir, 'cp *.h '.$dir, 'cp *.hpp '.$dir, 'cp *.pl '.$dir, 'cp Makefile '.$dir, 'cp Changes '.$dir, 'cp README '.$dir, 'mkdir -p '.$dir.'/t', 'cp t/*.cpp '.$dir.'/t', 'cp t/*.c '.$dir.'/t', 'tar cvf '.$dir.'.src.tar '.$dir, 'gzip '.$dir.'.tar', 'rm -rf '.$dir);\r
     foreach my $cm (@cm){\r
       print $cm."\n";\r
       system($cm);\r
index cfc61b9..cdedeff 100755 (executable)
--- a/host2ip.c
+++ b/host2ip.c
@@ -1,3 +1,10 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
 #include <stdio.h>
 #include <string.h>
 #include <sys/socket.h>
@@ -9,7 +16,10 @@
 #include "1stclass.hpp"
 string firstclass::host2ip(const string server_str){
   char ip[32]="";
-  char server[128]="";
+  char *server=NULL;
+  try{
+  server=new char[sizeof(char)*(server.length()+1)];
+  server[0]='\0';
   safe_strcat(server, server_str.c_str());
 #else
 #include "lib1stclass.h"
@@ -30,6 +40,7 @@ int host2ip(const char *server, char *ip){
     fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error));
 
 #ifdef __cplusplus
+    delete[] server;
     return "";
 #else
     return 1;
@@ -56,12 +67,18 @@ int host2ip(const char *server, char *ip){
   freeaddrinfo(res); // free the linked list
   
 #ifdef __cplusplus
-  firstclass::safe_strcat(ip, ipstr);
-  string last_ip(ip);
-  return last_ip;
+    delete[] server;
+    firstclass::safe_strcat(ip, ipstr);
+    string last_ip(ip);
+    return last_ip;
+  }
+  catch(...){
+    if(server!=NULL)
+      delete[] server;
+    return "";
+  }
 #else
   safe_strcat(ip, ipstr);
   return 0;
 #endif
-
 }
index f742126..03d8032 100755 (executable)
--- a/is_num.c
+++ b/is_num.c
@@ -1,3 +1,10 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
 #ifdef __cplusplus
 
 #include "1stclass.hpp"
@@ -7,8 +14,8 @@ int firstclass::is_num(const string in_moji){
   int is_num_flag=0;
   
   try{
-    
     moji=new char[sizeof(char)*(in_moji.length()+1)];
+    moji[0]='\0';
     safe_strcat(moji, in_moji.c_str());
     
 #else
@@ -23,7 +30,7 @@ int is_num(const char *moji){
     if( (moji[i] < '0') || (moji[i] > '9') ){
       
 #ifdef __cplusplus
-      delete moji;
+      delete[] moji;
 #endif
       return 0;
     }
@@ -35,11 +42,11 @@ int is_num(const char *moji){
   }
   
 #ifdef __cplusplus
-    delete moji;
+    delete[] moji;
   }
   catch(...){
     if(moji!=NULL)
-      delete moji;
+      delete[] moji;
   }
 #endif
 
diff --git a/itoa.c b/itoa.c
index 8715c71..a20f7e6 100755 (executable)
--- a/itoa.c
+++ b/itoa.c
@@ -1,3 +1,10 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
 #include <string.h>
 
 #ifdef __cplusplus
diff --git a/rel2abs.c b/rel2abs.c
new file mode 100755 (executable)
index 0000000..87bf022
--- /dev/null
+++ b/rel2abs.c
@@ -0,0 +1,76 @@
+/*\r
+* See the file LICENSE for redistribution information.\r
+*\r
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.\r
+*\r
+* Created by Hajime Kurita\r
+*/\r
+#include <limits.h>\r
+#include <stdlib.h>\r
+\r
+#ifdef __cplusplus\r
+#include "1stclass.hpp"\r
+\r
+string firstclass::rel2abs(const string in_rel_path){\r
+  char rel_path[1024]="";;\r
+  safe_strcat(rel_path, in_rel_path.c_str());\r
+  char abs_path[1024]="";\r
+#else\r
+#include "1stclass.h"\r
+int rel2abs(const char *rel_path, char *abs_path){\r
+#endif\r
+  if(rel_path[0]=='/'){\r
+    safe_strcat(abs_path, rel_path);\r
+  }\r
+  else if(rel_path[0]=='.'){\r
+    char in_real[512]="";\r
+    char tail[1024]="";\r
+    int found=0;\r
+    int found_i=0;\r
+    int i=0;\r
+    int tail_i=0;\r
+    for(i=0;i<=1024;i++){\r
+      if(rel_path[i]=='\0'){\r
+        tail[tail_i]='\0';\r
+        break;\r
+      }\r
+      if(found){\r
+        tail[tail_i]=rel_path[i];\r
+        tail_i++;\r
+      }\r
+      else{\r
+        if(rel_path[i] == '.' || rel_path[i] == '/'){\r
+          in_real[i]=rel_path[i];\r
+        }\r
+        else{\r
+          tail[tail_i]=rel_path[i];\r
+          tail_i++;\r
+          found++;\r
+          found_i=i;\r
+        }\r
+      }\r
+    }\r
+    in_real[found_i]='\0';\r
+    if(in_real[found_i-1]=='/'){\r
+      in_real[found_i-1]='\0';\r
+    }\r
+    \r
+    char real_path[1024]="";\r
+    realpath(in_real, real_path);\r
+    safe_strcat(abs_path, real_path);\r
+    safe_strcat(abs_path, "/");\r
+    safe_strcat(abs_path, tail);\r
+  }\r
+  else{\r
+    char real_path[1024]="";\r
+    realpath(".", real_path);\r
+    safe_strcat(abs_path, real_path);\r
+    safe_strcat(abs_path, "/");\r
+    safe_strcat(abs_path, rel_path);\r
+  }\r
+  \r
+#ifdef __cplusplus\r
+  string result(abs_path);\r
+  return result;\r
+#endif\r
+}\r
diff --git a/remove_not_file_char.c b/remove_not_file_char.c
new file mode 100755 (executable)
index 0000000..a110998
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
+#include<string.h>
+#include<stdio.h>
+
+#ifdef __cplusplus
+#include<string>
+#include "1stclass.hpp"
+string firstclass::remove_not_file_char(const string *in_str){
+  char *str=NULL;
+  char *dst=NULL;
+  try {
+    str=new char[sizeof(char)*(in_str->length()+1)];
+    dst=new char[sizeof(char)*(in_str->length()+1)];
+    str[0]='\0';
+    dst[0]='\0';
+    safe_strcat(str, in_str->c_str());
+#else
+#include "lib1stclass.h"
+int remove_not_file_char(const char *str, char *dst){
+#endif
+  if(sizeof(dst)<sizeof(str)){
+    printf("Bad parameter for remove_not_file_character\n");
+#ifdef __cplusplus
+    if(str!=NULL)
+      delete[] str;
+    if(dst!=NULL)
+      delete[] dst;
+    return "";
+#else
+    return 1;
+#endif
+  }
+  if((strrchr(str, '\0'))==NULL){
+    printf("\\0 is missing for the input parameter of remove_not_file_character\n");
+#ifdef __cplusplus
+    if(str!=NULL)
+      delete[] str;
+    if(dst!=NULL)
+      delete[] dst;
+    return "";
+#else
+    return 1;
+#endif
+  }
+  unsigned int i=0;
+  for(i=0;i<=strlen(str);i++){
+    if(str[i]=='\\' || str[i]=='/' || str[i]==':' || str[i]=='*' || str[i]=='?' || str[i]=='"' || str[i]=='<' || str[i]=='>' || str[i]=='|'){
+      dst[i]='_';
+    }
+    else if(str[i] == '\0'){
+      dst[i]='\0';
+      break;
+    }
+    else{
+      dst[i]=str[i];
+    }
+  }
+    
+#ifdef __cplusplus
+  
+    string result(dst);
+  if(str!=NULL)
+    delete[] str;
+  if(dst!=NULL)
+    delete[] dst;
+    return result;
+  }
+  catch(...){
+    if(str!=NULL)
+      delete[] str;
+    if(dst!=NULL)
+      delete[] dst;
+    return "";
+  }
+#else
+  return 0;
+#endif
+}
index 938d828..7f55d11 100755 (executable)
@@ -1,3 +1,10 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
 #include <stdio.h>
 #include <dirent.h>
 #include <unistd.h>
@@ -10,6 +17,7 @@ int firstclass::remove_path(const string in_path){
   char *path=NULL;
   try {
     path=new char[sizeof(char)*(in_path.length()+1)];
+    path[0]='\0';
     safe_strcat(path, in_path.c_str());
   
 #else
@@ -24,7 +32,7 @@ int remove_path(const char *path){
   if((dirp = opendir(path))==NULL){
     
 #ifdef __cplusplus
-    delete path;
+    delete[] path;
 #endif
     
     return 0;
@@ -45,11 +53,11 @@ int remove_path(const char *path){
     rmdir(path);
   }
 #ifdef __cplusplus
-    delete(path);
+    delete[] path;
   }
   catch (...) {
     if(path!=NULL)
-      delete(path);
+      delete[] path;
     return 1;
   }
 #endif
diff --git a/remove_special_char.c b/remove_special_char.c
deleted file mode 100755 (executable)
index 3f9b629..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#include<string.h>
-#include<stdio.h>
-
-#ifdef __cplusplus
-#include "1stclass.hpp"
-int firstclass::remove_special_char(string &in_str){
-  char *str=NULL;
-  char *dst=NULL;
-  str=new char[sizeof(char)*(in_str.length()+1)];
-  dst=new char[sizeof(char)*(in_str.length()+1)];
-  try {
-  safe_strcat(str, in_str.c_str());
-#else
-#include "lib1stclass.h"
-int remove_special_char(const char *str, char *dst){
-#endif
-  int zero=0;
-  if(sizeof(dst)<sizeof(str)){
-    printf("Bad parameter for remove_special_character\n");
-#ifdef __cplusplus
-  free(str);
-  free(dst);
-#endif
-    return 1;
-  }
-  if((strrchr(str, '\0'))==NULL){
-    printf("\\0 is missing for the input parameter of remove_special_character\n");
-#ifdef __cplusplus
-  free(str);
-  free(dst);
-#endif
-    return 1;
-  }
-  for( ; *str!='\0'; str++, dst++){ 
-    if(*str == '/' || *str == ':' || *str == '?' || *str == '%'){
-      *dst='_';
-    }
-    else if(*str == '\0'){
-      *dst=*str;
-      zero++;
-      break;
-    }
-    else{
-      *dst=*str;
-    }
-  }
-  *dst='\0';
-#ifdef __cplusplus
-  string result(dst);
-  free(str);
-  free(dst);
-  in_str=result;
-  }
-  catch(...){
-    if(str!=NULL)
-      free(str);
-    if(dst!=NULL)
-      free(dst);
-  }
-#endif
-  return 0;
-}
index 3338bda..af3047c 100755 (executable)
@@ -1,3 +1,10 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
 #include <string.h>
 #ifdef __cplusplus
 #include "1stclass.hpp"
index aa4ebe3..c8f0796 100755 (executable)
--- a/rmkdir.c
+++ b/rmkdir.c
@@ -1,3 +1,10 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
 #include <stdio.h>
 #include <sys/stat.h>
 #include <dirent.h>
 #ifdef __cplusplus
 #include "1stclass.hpp"
 int firstclass::rmkdir(const string in_dir){
-  char *check_dir=NULL;
-  try{
-  check_dir=new char[sizeof(char)*(in_dir.length()+1)];
-  safe_strcat(check_dir, in_dir.c_str());
+  char abs_dir[2048]="";
+  string abs_dir_str=rel2abs(in_dir);
+  safe_strcat(abs_dir, abs_dir_str.c_str());
 #else
 #include "1stclass.h"
 int rmkdir(const char *check_dir){
+  char abs_dir[2048]="";
+  rel2abs(check_dir, abs_dir);
 #endif
-
+  
   struct stat st;
   char *token_p=NULL;
-  char dir_path[512]="";
-  char moto[512]="";
-  if(stat(check_dir, &st)!=0){
-    if(mkdir(check_dir, 0755)==0){
+  char dir_path[2048]="";
+  char moto[2048]="";
+  if(stat(abs_dir, &st)!=0){
+    if(mkdir(abs_dir, 0755)==0){
     }
     else{
-      safe_strcat(moto, check_dir);
+      safe_strcat(moto, abs_dir);
       token_p=strtok(moto, "/");
       safe_strcat(dir_path, "/");
       safe_strcat(dir_path, token_p);
@@ -31,9 +39,6 @@ int rmkdir(const char *check_dir){
         if(mkdir(dir_path, 0755)==0){
         }
         else{
-#ifdef __cplusplus
-  delete check_dir;
-#endif
           return 1;
         }
       }
@@ -44,23 +49,11 @@ int rmkdir(const char *check_dir){
           if(mkdir(dir_path, 0755)==0){
           }
           else{
-#ifdef __cplusplus
-  delete check_dir;
-#endif
             return 1;
           }
         }
       }
     }
   }
-#ifdef __cplusplus
-  delete check_dir;
-  }
-  catch(...){
-    if(check_dir!=NULL)
-      delete check_dir;
-    return 1;
-  }
-#endif
   return 0;
 }
index 791ecbd..7fd8013 100755 (executable)
@@ -1,3 +1,10 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
 #include <stdio.h>
 #include <string.h>
 
index d6f4672..7b36e52 100755 (executable)
@@ -1,3 +1,10 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
 #include <stdio.h>
 #include <string.h>
 
diff --git a/shmf.c b/shmf.c
index 530aa1e..5809552 100755 (executable)
--- a/shmf.c
+++ b/shmf.c
@@ -1,3 +1,10 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
 #include <string.h>
 
 #ifdef __cplusplus
index 01a75b7..94c900d 100755 (executable)
@@ -1,3 +1,10 @@
+/*
+* See the file LICENSE for redistribution information.
+*
+* Copyright: 2010- 1stclass.co.jp.  All rights reserved.
+*
+* Created by Hajime Kurita
+*/
 #include <string>
 #include <string.h>
 #include <sys/stat.h>
@@ -18,6 +25,8 @@ private:
 void tester::test(){
   firstclass fst;
   struct stat st;
+// is_num: 数字かどうかの判別
+// Judge whether this is number or not
   if(fst.is_num("2") && fst.is_num("test")==0){
     cout << "is_num/C++: ok "<< endl;
     ok++;
@@ -35,7 +44,9 @@ void tester::test(){
     cout << "is_num/C: bad" << endl;
     bad++;
   }
-  
+
+// ホスト名からIPを得る
+// Get IP from host name
   string server="www.yahoo.co.jp";
   string ip=fst.host2ip(server);
   if( (ip.at(0) - '1'>=0) && (ip.at(0) - '1'<=9) ){
@@ -58,11 +69,87 @@ void tester::test(){
     cout << "host2ip/C: bad" << endl;
     bad++;
   }
+
+// 相対パスから絶対パスを得る
+// Get absolute path from relative path
+  string rel_path="../lib1stclass/1/2/3";
+  string abs_path=fst.rel2abs(rel_path);
+  if( abs_path.find("/")==0 &&  abs_path.find("lib1stclass/1/2/3")!=string::npos){
+    cout << "rel2abs/C++: ok" << endl;
+    ok++;
+  }
+  else{
+    cout << "rel2abs/C++: bad" << endl;
+    bad++;
+  }
+  
+  char rel_path_char[]="../lib1stclass/1/2/3";
+  char abs_path_char[1024]="";
+  rel2abs(rel_path_char, abs_path_char);
+  if( abs_path_char[0]=='/' && strstr(abs_path_char, "lib1stclass/1/2/3")!=NULL){
+    cout << "rel2abs/C: ok" << endl;
+    ok++;
+  }
+  else{
+    cout << "rel2abs/C: bad" << endl;
+    bad++;
+  }
+
+  string rel_path2="lib1stclass/1/2/3";
+  string abs_path2=fst.rel2abs(rel_path2);
+  if( abs_path2.find("/")==0 &&  abs_path2.find("/lib1stclass/1/2/3")!=string::npos){
+    cout << "rel2abs/C++: ok" << endl;
+    ok++;
+  }
+  else{
+    cout << "rel2abs/C++: bad" << endl;
+    bad++;
+  }
+  
+  char rel_path_char2[]="lib1stclass/1/2/3";
+  char abs_path_char2[1024]="";
+  rel2abs(rel_path_char2, abs_path_char2);
+  if( abs_path_char2[0]=='/' && strstr(abs_path_char2, "/lib1stclass/1/2/3")!=NULL){
+    cout << "rel2abs 2/C: ok" << endl;
+    ok++;
+  }
+  else{
+    cout << "rel2abs 2/C: bad" << endl;
+    bad++;
+  }
+  
+  string rel_path3="/tmp/1/2/3";
+  string abs_path3=fst.rel2abs(rel_path3);
+  if( abs_path3=="/tmp/1/2/3"){
+    cout << "rel2abs 3/C++: ok" << endl;
+    ok++;
+  }
+  else{
+    cout << "rel2abs 3/C++: bad" << endl;
+    bad++;
+  }
+  
+  char rel_path_char3[]="/tmp/1/2/3";
+  char abs_path_char3[1024]="";
+  rel2abs(rel_path_char3, abs_path_char3);
+  if( strcmp(abs_path_char3, "/tmp/1/2/3")==0){
+    cout << "rel2abs 3/C: ok" << endl;
+    ok++;
+  }
+  else{
+    cout << "rel2abs 3/C: bad" << endl;
+    bad++;
+  }
   
-  fst.rmkdir("test_dir");
-  if(stat("test_dir", &st)==0){
+// ディレクトリを再帰的に作る
+// mkdir recursively
+  fst.rmkdir("test_dir/depth2");
+  if(stat("test_dir/depth2", &st)==0){
     cout << "rmkdir/C++: ok" << endl;
     ok++;
+
+// パス全体を消去(ディレクトリを再帰的に消去)
+// Remove path completely
     fst.remove_path("test_dir");
     if(stat("test_dir", &st)!=0){
       cout << "remove_path/C++: ok" << endl;
@@ -78,8 +165,8 @@ void tester::test(){
     bad++;
   }
 
-  rmkdir("test_dir");
-  if(stat("test_dir", &st)==0){
+  rmkdir("test_dir/depth_2");
+  if(stat("test_dir/depth_2", &st)==0){
     cout << "rmkdir/C: ok" << endl;
     ok++;
     remove_path("test_dir");
@@ -96,7 +183,9 @@ void tester::test(){
     cout << "rmkdir/C: bad" << endl;
     bad++;
   }
-  
+
+// int型をchar型に変換
+// Convert int to char
   int integer=12345;
   char itoa_str[6]="";
 
@@ -121,6 +210,8 @@ void tester::test(){
     bad++;
   }
 
+// 文字を逆並びにする
+// Reverse char
   char example1[]="1234";
   fst.reverse_char(example1);
   if (strcmp(example1,"4321") == 0){
@@ -142,6 +233,32 @@ void tester::test(){
     cout << "reverse_char/C: bad" << endl;
     bad++;
   }
+
+
+// ファイルシステムに使えないアスキー文字を「_」に変換
+// Convert ascii characters which cannot be used for file name into "_"
+  string not_file_str="bk\\sl/sm:as*qt?dq\"lt<rt>vt|";
+  string file_str=fst.remove_not_file_char(&not_file_str);
+  if (file_str=="bk_sl_sm_as_qt_dq_lt_rt_vt_"){
+    cout << "remove_not_file_char/C++: ok" << endl;
+    ok++;
+  }
+  else{
+    cout << "remove_not_file_char/C++: bad" << endl;
+    bad++;
+  }
+
+  char not_file_char[]="bk\\sl/sm:as*qt?dq\"lt<rt>vt|";
+  char file_char[1024]="";
+  remove_not_file_char(not_file_char, file_char);
+  if (strcmp(file_char,"bk_sl_sm_as_qt_dq_lt_rt_vt_")==0){
+    cout << "remove_not_file_char/C: ok" << endl;
+    ok++;
+  }
+  else{
+    cout << "remove_not_file_char/C: bad" << endl;
+    bad++;
+  }
 }
 
 void tester::report(){