• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

oga's tools


コミットメタ情報

リビジョンd2bcbda77fa3d93a8c41cc8463aded92f9d4b317 (tree)
日時2014-12-06 10:25:32
作者oga <oga@mxg....>
コミッターoga

ログメッセージ

V0.13-2 sum fix for win

変更サマリ

差分

--- a/cgrep.c
+++ b/cgrep.c
@@ -11,9 +11,44 @@
1111 #include <string.h>
1212
1313 #ifdef _WIN32
14+#include <windows.h> /* V0.13-A */
15+
1416 #if !defined(strncasecmp)
1517 #define strncasecmp strnicmp
1618 #endif
19+
20+/* 0.13-A start */
21+#define BLACK ( FOREGROUND_INTENSITY) /* black */
22+#define BLUE (FOREGROUND_BLUE | FOREGROUND_INTENSITY) /* blue */
23+#define GREEN (FOREGROUND_GREEN | FOREGROUND_INTENSITY) /* green */
24+#define CYAN (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY) /* cyan */
25+#define RED (FOREGROUND_RED | FOREGROUND_INTENSITY) /* red */
26+#define MAGENTA (FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY) /* magenta */
27+#define YELLOW (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY) /* yellow */
28+#define WHITE (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY) /* white */
29+#define NORMAL (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED) /* normal */
30+
31+typedef struct _coltbl {
32+ char *escsec;
33+ unsigned short color;
34+} coltbl_t;
35+
36+coltbl_t col_tbl[] = {
37+ { "", BLACK },
38+ { "", RED },
39+ { "", GREEN },
40+ { "", YELLOW },
41+ { "", BLUE },
42+ { "", MAGENTA},
43+ { "", CYAN },
44+ { "", WHITE },
45+ { "" , NORMAL }
46+};
47+
48+unsigned short colorbk = 0xffff;
49+char msg[4096];
50+/* 0.13-A end */
51+
1752 #endif
1853
1954 enum {COL_ESC, COL_BS};
@@ -34,7 +69,7 @@ void backup_color()
3469 GetStdHandle(STD_OUTPUT_HANDLE),
3570 &scrinfo)) {
3671 colorbk = scrinfo.wAttributes;
37- if (vf) printf("backup color: 0x%04x\n", colorbk);
72+ if (vf) printf("[backup color: 0x%04x]\n", colorbk);
3873 }
3974 #endif /* DOS */
4075 return;
@@ -45,7 +80,7 @@ void restore_color()
4580 #ifdef _WIN32
4681 /* restore color */
4782 if (colorbk != 0xffff) {
48- if (vf) printf("restore color.\n");
83+ if (vf) printf("[restore color. to 0x%04x]\n", colorbk);
4984 SetConsoleTextAttribute(
5085 GetStdHandle(STD_OUTPUT_HANDLE),
5186 colorbk);
@@ -64,6 +99,12 @@ void printf_nt(char *str)
6499 if (str[i] == 27) { /* ESC */
65100 for (j = 0; j < sizeof(col_tbl)/sizeof(coltbl_t); j++) {
66101 if (!strncmp(&str[i], col_tbl[j].escsec, strlen(col_tbl[j].escsec))) {
102+ //if (col_tbl[j].color == NORMAL) {
103+ // restore_color();
104+ //} else {
105+ // backup_color();
106+ //}
107+ //if (vf) printf("[set color: 0x%04x]\n", colorbk);
67108 SetConsoleTextAttribute(
68109 GetStdHandle(STD_OUTPUT_HANDLE),
69110 col_tbl[j].color);
@@ -220,6 +261,10 @@ int main(int a, char *b[])
220261 ncf = 1;
221262 continue;
222263 }
264+ if (!strcmp(b[i],"-v")) {
265+ ++vf;
266+ continue;
267+ }
223268 /* V0.13-A end */
224269
225270 if (key == NULL) {
@@ -234,6 +279,11 @@ int main(int a, char *b[])
234279 return 1;
235280 }
236281
282+ backup_color(); /* V0.13-A */
283+#ifdef _WIN32
284+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), NORMAL);
285+#endif /* _WIN32 */
286+
237287 x = 0;
238288 do {
239289 if (files) {
@@ -253,11 +303,13 @@ int main(int a, char *b[])
253303 pt = strstr(buf, key);
254304 }
255305 if (pt) {
256- if (!ncf) ChangeBold(buf, key, ctype); /* V0.13-C */
306+ if (!ncf) ChangeBold(buf, key, ctype); /* V0.13-C */
257307 if (files > 1) {
258- printf("%s:%s", filename[x], buf);
308+ sprintf(msg, "%s:%s", filename[x], buf); /* V0.13-C */
309+ printf_nt(msg); /* V0.13-A */
259310 } else {
260- printf("%s", buf);
311+ sprintf(msg, "%s", buf); /* V0.13-C */
312+ printf_nt(msg); /* V0.13-A */
261313 }
262314 }
263315 }
@@ -265,6 +317,8 @@ int main(int a, char *b[])
265317 if (files) fclose(fp);
266318 } while ( ++x < files);
267319
320+ restore_color(); /* V0.13-A */
321+
268322 return 0;
269323 }
270324