• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

oga's tools


Commit MetaInfo

Revision44e9b62c8b7673f8c9b2895b8390502ae2cea081 (tree)
Zeit2014-02-11 19:08:45
Autoroga <hyperoga@gmai...>
Commiteroga

Log Message

find2.c 2013/12/12 V0.13 support X68K & Linux

Ändern Zusammenfassung

Diff

--- a/Makefile.linux
+++ b/Makefile.linux
@@ -26,7 +26,7 @@ TARGETS=$(VP)/age $(VP)/cal2 $(VP)/cgrep $(VP)/cmem $(VP)/cpkt $(VP)/cpuid \
2626 $(VP)/peke2 $(VP)/peke $(VP)/perfan $(VP)/strings2 $(VP)/t64an \
2727 $(VP)/tolower $(VP)/txt2vnt $(VP)/upload $(VP)/wavana $(VP)/wavcut2 \
2828 $(VP)/wavcut $(VP)/welcome $(VP)/whichx $(VP)/wwstat $(VP)/xalloc \
29- $(VP)/zusa $(VP)/rand2 $(VP)/usleep
29+ $(VP)/zusa $(VP)/rand2 $(VP)/usleep $(VP)/find2
3030
3131 TARGET_X=$(VP)/qix $(VP)/xmem $(VP)/xpkt $(VP)/xpstat
3232
@@ -45,7 +45,7 @@ $(VP)/base64 : $(TOOL)/base64.c
4545 ${CC} $? -o $@ -O
4646
4747 $(VP)/cal2 : $(TOOL)/cal.c
48- ${CC} $? -o $@ -O
48+ ${CC} $? -o $@ -O -DLINUX
4949
5050 $(VP)/cgrep : $(TOOL)/cgrep.c
5151 ${CC} $? -o $@ -O
@@ -100,6 +100,9 @@ $(VP)/enews : $(TOOL)/enews.c
100100 $(VP)/filer : $(TOOL)/filer.c
101101 ${CC} $? -o $@ -O -DLINUX -I/usr/include/ncursesw -L/usr/lib/arm-linux-gnueabihf -lncursesw
102102
103+$(VP)/find2 : $(TOOL)/find2.c
104+ ${CC} $? -o $@ -O -DLINUX
105+
103106 $(VP)/galaxian : $(TOOL)/galaxian.c
104107 ${CC} $? -o $@ -O -DX3050RX -I/usr/include/ncursesw -L/usr/lib/arm-linux-gnueabihf -lncursesw
105108
--- a/find2.c
+++ b/find2.c
@@ -2,19 +2,30 @@
22 * find2 : ファイル/ディレクトリの検索 (日本語対応版)
33 * for WIN Only
44 *
5- * 表示形式
6- *
75 * 2003/05/16 V0.10 by oga.
86 * 2003/05/21 V0.11 fix find2 c:\ => c:\/xxx
97 * 2009/04/04 V0.12 support -mtime
8+ * 2013/12/12 V0.13 support X68K & Linux
9+ *
10+ * CFLAG
11+ * Linux: -DX68K -DLINUX
12+ *
13+ *
1014 */
15+#ifdef _WIN32
1116 #include <windows.h>
17+#else /* X68K, LINUX */
1218 #include <stdio.h>
19+#include <string.h>
20+#include <stdlib.h>
21+#include <dirent.h>
22+#endif /* X68K, LINUX */
1323 #include <sys/types.h>
1424 #include <sys/stat.h>
25+#include <errno.h>
1526
1627 /* macros */
17-#define VER "0.12"
28+#define VER "0.13"
1829 #define IS_DOT(str) (!strcmp(str,".") || !strcmp(str,".."))
1930
2031 #define dprintf if (vf) printf
@@ -32,6 +43,163 @@ int vf = 0; /* -v */
3243 int depth = 0;
3344 time_t cur_tt = 0; /* current time_t V0.12-A */
3445
46+#ifdef LINUX
47+#define stricmp strcasecmp
48+#endif
49+
50+#if defined X68K || defined LINUX
51+int errno2 = 0;
52+
53+#define INVALID_HANDLE_VALUE NULL
54+#define MAX_PATH PATH_MAX
55+#define TRUE 1
56+#define FALSE 0
57+
58+/* #define PDELM "\\" */
59+
60+typedef int DWORD;
61+typedef int BOOL;
62+typedef char CHAR;
63+
64+typedef struct _DIR2 {
65+ DIR *dirp;
66+ char path[MAX_PATH];
67+} DIR2, *HANDLE;
68+
69+typedef struct _WIN32_FIND_DATA {
70+ DWORD dwFileAttributes;
71+ DWORD nFileSizeHigh;
72+ DWORD nFileSizeLow;
73+ CHAR cFileName[ MAX_PATH ];
74+
75+ /* FILETIME ftCreationTime; */
76+ /* FILETIME ftLastAccessTime; */
77+ /* FILETIME ftLastWriteTime; */
78+ /* DWORD dwReserved0; */
79+ /* DWORD dwReserved1; */
80+ /* CHAR cAlternateFileName[ 16 ]; */
81+} WIN32_FIND_DATA;
82+
83+/* available attr */
84+#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 /* ディレクトリ */
85+#define FILE_ATTRIBUTE_NORMAL 0x00000080 /* 通常ファイル */
86+
87+/* not support attr */
88+#define FILE_ATTRIBUTE_READONLY 0x00000001 /* 読み取り専用属性 */
89+#define FILE_ATTRIBUTE_HIDDEN 0x00000002 /* 隠しファイル属性 */
90+#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 /* アーカイブ属性 */
91+#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 /* 関連リパースポイントがある */
92+#define FILE_ATTRIBUTE_COMPRESSED 0x00000800 /* 圧縮属性。 */
93+#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 /* 暗号化属性。 */
94+#define FILE_ATTRIBUTE_OFFLINE 0x00001000 /* 利用可能ではない */
95+
96+/* FindNextFile error reason */
97+#define ERROR_NO_MORE_FILES ENOENT;
98+
99+
100+HANDLE FindFirstFile(char *path, WIN32_FIND_DATA *pwfd)
101+{
102+ DIR *dirp;
103+ DIR2 *dir2p; /* DIR with path */
104+ struct dirent *dp;
105+ struct stat stbuf;
106+ char path2[MAX_PATH];
107+
108+ /* delete wild card */
109+ strcpy(path2, path);
110+ if (path2[strlen(path2)-1] == '*') {
111+ path2[strlen(path2)-1] = '\0';
112+ }
113+ if (path2[strlen(path2)-1] == '/') {
114+ if (strlen(path2) >= 2 && path2[strlen(path2)-2] == ':') {
115+ /* if "a:/" ... don't delete "/" */
116+ } else {
117+ /* delete "/" */
118+ path2[strlen(path2)-1] = '\0';
119+ }
120+ }
121+
122+ memset(pwfd, 0, sizeof(WIN32_FIND_DATA));
123+
124+ if (vf) printf("opendir = [%s]\n", path2);
125+ dirp = opendir(path2);
126+ if (!dirp) {
127+ errno2 = errno;
128+ perror("opendir");
129+ printf("path = [%s]\n", path);
130+ return INVALID_HANDLE_VALUE;
131+ }
132+
133+ dir2p = (DIR2 *)malloc(sizeof(DIR2));
134+ if (dir2p == NULL) {
135+ errno2 = errno;
136+ perror("malloc");
137+ return INVALID_HANDLE_VALUE;
138+ }
139+
140+ dir2p->dirp = dirp;
141+ strcpy(dir2p->path, path2);
142+
143+ if (FindNextFile(dir2p, pwfd) == FALSE) {
144+ /* EOF or Error */
145+ return dir2p;
146+ }
147+ return dir2p;
148+}
149+
150+BOOL FindNextFile(HANDLE dir2p, WIN32_FIND_DATA *pwfd)
151+{
152+ struct dirent *dp;
153+ struct stat stbuf;
154+ char wkpath[MAX_PATH];
155+
156+ if (vf) printf("FindNextFile: start readdir(%s)\n", dir2p->path); /* debug */
157+
158+ memset(pwfd, 0, sizeof(WIN32_FIND_DATA));
159+
160+ if (vf) printf("FindNextFile: ----\n"); /* debug */
161+
162+ dp = readdir(dir2p->dirp);
163+ if (!dp) {
164+ /* end of entry */
165+ errno2 = ERROR_NO_MORE_FILES;
166+ return FALSE;
167+ }
168+ strcpy(pwfd->cFileName, dp->d_name);
169+ strcpy(wkpath, dir2p->path);
170+ strcat(wkpath, "/");
171+ strcat(wkpath, dp->d_name);
172+ if (vf) printf("FindNextFile: start stat(%s)\n", wkpath); /* debug */
173+ if (stat(wkpath, &stbuf) == 0) {
174+ if (stbuf.st_mode & S_IFDIR) {
175+ pwfd->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
176+ if (vf >= 2) printf("# %s is dir. 0x%08x\n", wkpath, pwfd->dwFileAttributes);
177+ } else {
178+ /* とりあえずディレクトリ以外はNORMALにたおす */
179+ pwfd->dwFileAttributes |= FILE_ATTRIBUTE_NORMAL;
180+ if (vf >= 2) printf("# %s is file. 0x%08x\n", wkpath, pwfd->dwFileAttributes);
181+ }
182+ pwfd->nFileSizeHigh = 0;
183+ pwfd->nFileSizeLow = stbuf.st_size;
184+ }
185+ return TRUE;
186+}
187+
188+BOOL FindClose(HANDLE dir2p)
189+{
190+ closedir(dir2p->dirp); /* void */
191+ free(dir2p);
192+
193+ return TRUE;
194+}
195+
196+int GetLastError()
197+{
198+ return errno2;
199+}
200+
201+#endif /* X68K || LINUX */
202+
35203 void Usage()
36204 {
37205 printf("find Verson %s by oga.\n",VER);
@@ -40,7 +208,7 @@ void Usage()
40208 printf(" -type {d|f} : dir or file only\n");
41209 printf(" -name <name> : name match (ignore case)\n");
42210 printf(" -mtime <n> : file's data was last modified n*24 hours ago.\n");
43- //printf(" -mmin <n> : file's data was last modified n*24 hours ago.\n");
211+ /*printf(" -mmin <n> : file's data was last modified n*24 hours ago.\n"); */
44212 }
45213
46214 /*
@@ -95,6 +263,7 @@ void Find(char *path)
95263 char *pt;
96264
97265 depth++;
266+ if (vf) printf("[%d]Find start.\n", depth); /* debug */
98267
99268 /* ディレクトリ表示 */
100269 if ((ftype & F_TYPE_FILE) == 0) {
@@ -201,6 +370,7 @@ void Find(char *path)
201370 if (strlen(wk) && wk[strlen(wk)-1] != '/') strcat(wk,"/");
202371 strcat(wk,wfd.cFileName); /* make new path */
203372 Find(wk);
373+ if (vf) printf("[%d]Find return.\n", depth); /* debug */
204374 } else {
205375 /* ファイルの場合すぐ表示(-type d指定のない場合) */
206376 if ((ftype & F_TYPE_DIR) == 0) {
@@ -208,10 +378,14 @@ void Find(char *path)
208378 }
209379 }
210380 }
381+ if (vf) printf("[%d]Find end.\n", depth); /* debug */
211382 FindClose(fh);
383+ if (vf) printf("[%d]Find end. (FindClose end)\n", depth); /* debug */
212384
213385 depth--;
214386
387+ return;
388+
215389 } /* End Find() */
216390
217391 int main(int a, char *b[])
@@ -272,5 +446,7 @@ int main(int a, char *b[])
272446 return 0;
273447 }
274448
449+/* vim:ts=8:sw=4:
450+ */
275451
276452