• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

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

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

コミットメタ情報

リビジョン8392bbbb41ec3dcdc82038de415bd42b417a684d (tree)
日時2023-09-07 14:58:03
作者tarancho <tfuruka1@nift...>
コミッターtarancho

ログメッセージ

作成時点で関数として定義されていなかったものが現在では定義されているので実装を変更しました。

変更サマリ

差分

--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,6 +2,8 @@ cmake_minimum_required (VERSION 3.10)
22
33 project(garakuta C)
44
5+set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/..")
6+
57 add_subdirectory(batkey)
68 add_subdirectory(CPU100)
79 add_subdirectory(crlf)
--- a/src/CPU100/CMakeLists.txt
+++ b/src/CPU100/CMakeLists.txt
@@ -4,11 +4,14 @@ project(cpu100 C)
44
55 set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
66
7-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -W -Wformat=2 -Wcast-qual")
8-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align -Wwrite-strings")
9-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wfloat-equal")
10-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith")
11-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --exec-charset=cp932")
12-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --input-charset=utf-8")
7+add_compile_options(-g -Wall -W -Wformat=2 -Wcast-qual)
8+add_compile_options(-Wcast-align -Wwrite-strings)
9+add_compile_options(-Wconversion -Wfloat-equal)
10+add_compile_options(-Wpointer-arith)
11+add_compile_options(--input-charset=utf-8)
12+add_compile_options(--exec-charset=cp932)
13+
14+set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../..")
1315
1416 add_executable(cpu100.exe main.c)
17+INSTALL(TARGETS cpu100.exe RUNTIME DESTINATION bin)
--- a/src/CPU100/main.c
+++ b/src/CPU100/main.c
@@ -1,228 +1,251 @@
1-/* $Id: main.c 1313 2013-03-19 00:10:02Z tfuruka1 $
2- *
3- * CPU 使用率を100%にするツール
4- *
5- * CPU使用率を100%にしますが、システムの負荷は軽いです。
6- */
7-#include <windows.h>
8-#include <stdio.h>
9-
10-#define VERSION "R0.1.0.0 ($Rev: 1313 $)"
11-
12-#define LINE_STR "━━━━━━━━━━━━━━━━━"\
13- "━━━━━━━━━━━━━━━━━━"
14-
15-BOOL (WINAPI *lpGetSystemTimes)(LPFILETIME lpIdleTime,
16- LPFILETIME lpKernelTime,
17- LPFILETIME lpUserTime);
18-
19-static LPCTSTR
20-GetProcessorArchitectureStr(WORD wPA)
21-{
22- static char szBuf[256];
23-
24- switch (wPA) {
25- case PROCESSOR_ARCHITECTURE_INTEL:
26- strcpy(szBuf, "INTEL");
27- break;
28- case PROCESSOR_ARCHITECTURE_MIPS:
29- strcpy(szBuf, "MIPS");
30- break;
31- case PROCESSOR_ARCHITECTURE_ALPHA:
32- strcpy(szBuf, "ALPHA");
33- break;
34- case PROCESSOR_ARCHITECTURE_PPC:
35- strcpy(szBuf, "POWER-PC");
36- break;
37- case PROCESSOR_ARCHITECTURE_SHX:
38- strcpy(szBuf, "SH");
39- break;
40- case PROCESSOR_ARCHITECTURE_ARM:
41- strcpy(szBuf, "ARM");
42- break;
43- case PROCESSOR_ARCHITECTURE_IA64:
44- strcpy(szBuf, "INTEL-64");
45- break;
46- case PROCESSOR_ARCHITECTURE_ALPHA64:
47- strcpy(szBuf, "ALPHA-64");
48- break;
49- case PROCESSOR_ARCHITECTURE_UNKNOWN:
50- strcpy(szBuf, "UNKNOWN");
51- break;
52- default:
53- sprintf(szBuf, "UNKNOWN: %x", wPA);
54- break;
55- }
56- return szBuf;
57-}
58-
59-static LPCTSTR
60-GetProcessorTypeStr(DWORD dwPt)
61-{
62- static char szBuf[256];
63-
64- switch (dwPt) {
65- case PROCESSOR_INTEL_386:
66- sprintf(szBuf, "INTEL386(%lu)", dwPt);
67- break;
68- case PROCESSOR_INTEL_486:
69- sprintf(szBuf, "INTEL486(%lu)", dwPt);
70- break;
71- case PROCESSOR_INTEL_PENTIUM:
72- sprintf(szBuf, "INTEL PENTIUM(%lu)", dwPt);
73- break;
74- case PROCESSOR_MIPS_R4000:
75- sprintf(szBuf, "MIPS R4000(%lu", dwPt);
76- break;
77- case PROCESSOR_ALPHA_21064:
78- sprintf(szBuf, "ALPHA 21064(%lu)", dwPt);
79- break;
80- default:
81- sprintf(szBuf, "UNKNOWn(%lu)", dwPt);
82- break;
83- }
84- return szBuf;
85-}
86-
87-static LPCTSTR
88-GetActiveProcessorMaskStr(DWORD dwAPM)
89-{
90- static char szBuf[36];
91- int i;
92-
93- szBuf[0] = '\0';
94- for (i = 0; i < 32; i++) {
95- strcat(szBuf, ((dwAPM >> i) & 1) ? "*" : ".");
96- }
97- return szBuf;
98-}
99-
100-static DWORD WINAPI
101-ThreadFunc(LPVOID lpPara)
102-{
103- printf("CPU %d 占有開始...\n", *(int *) lpPara);
104- while (TRUE) {
105- }
106- return 0;
107-}
108-
109-static void
110-selfLoop()
111-{
112- unsigned char kaiten[] = "―\|/";
113-
114- unsigned char wk[4];
115- unsigned int i = 0;
116- unsigned int j;
117- unsigned int iSleep = 1000;
118-
119- LONGLONG ftOldIdle = 0;
120- LONGLONG ftOldKernel = 0;
121- LONGLONG ftOldUser = 0;
122-
123- LONGLONG ftIdle;
124- LONGLONG ftKernel;
125- LONGLONG ftUser;
126-
127- HANDLE lpLib = LoadLibrary("kernel32.dll");
128- printf("Library Handle: %llx\n", (ULONGLONG) lpLib);
129- if (!lpLib) {
130- return;
131- }
132- lpGetSystemTimes = GetProcAddress(lpLib, "GetSystemTimes");
133-
134- printf("GetSystemTimes API Address: %lx\n", (ULONG) lpGetSystemTimes);
135- if (!lpGetSystemTimes) {
136- return;
137- }
138- printf("終了する場合は CTRL-C を押下して下さい。\n\n");
139-
140- while (TRUE) {
141- j = i++ % 4;
142- wk[0] = kaiten[j * 2];
143- wk[1] = kaiten[j * 2 + 1];
144- wk[2] = '\0';
145-
146- lpGetSystemTimes((LPFILETIME)&ftIdle,
147- (LPFILETIME)&ftKernel,
148- (LPFILETIME)&ftUser);
149- if (0 != ftOldIdle) {
150- LONGLONG llIdle = ftIdle - ftOldIdle;
151- LONGLONG llKernel = ftKernel - ftOldKernel;
152- LONGLONG llUser = ftUser - ftOldUser;
153- LONGLONG llTotal = llIdle + llKernel + llUser;
154- TCHAR szBuf[1024];
155-
156- sprintf(szBuf,
157- "[%s] %5.1f%% user, %5.1f%% system, %5.1f%% idle",
158- wk,
159- ((LONGLONG) 1000 * llUser / llTotal) / 10.0,
160- ((LONGLONG) 1000 * llKernel / llTotal) / 10.0,
161- ((LONGLONG) 1000 * llIdle / llTotal) / 10.0);
162- printf("\r%s", szBuf);
163- fflush(stdout);
164-
165- SetConsoleTitle(szBuf);
166- }
167- ftOldIdle = ftIdle;
168- ftOldKernel = ftKernel;
169- ftOldUser = ftUser;
170-
171- Sleep(iSleep);
172- if (50 < iSleep) {
173- iSleep -= 1;
174- }
175- }
176-}
177-
178-int
179-main(int argc, char *argv[])
180-{
181- SYSTEM_INFO si;
182- int i;
183-
184- GetSystemInfo(&si);
185-
186- printf("$Id: main.c 1313 2013-03-19 00:10:02Z tfuruka1 $\n");
187- printf("CPU使用率100%% %s[Build:" __DATE__ " " __TIME__ "]\n", VERSION);
188- printf(LINE_STR "\n");
189- printf("OEM-ID : %lx\n", si.dwOemId);
190- printf("Processor architecture : %s\n",
191- GetProcessorArchitectureStr(si.wProcessorArchitecture));
192- printf("Page size : %ld\n", si.dwPageSize);
193- printf("Minimun application address: %lx\n",
194- (ULONG) si.lpMinimumApplicationAddress);
195- printf("Maximum application address: %lx\n",
196- (ULONG) si.lpMaximumApplicationAddress);
197- printf("Active processor mask : 0123456789*123456789*123456789*1\n");
198- printf(" : %s\n",
199- GetActiveProcessorMaskStr(si.dwActiveProcessorMask));
200- printf("Number of processors : %ld\n", si.dwNumberOfProcessors);
201- printf("Processor type : %s\n",
202- GetProcessorTypeStr(si.dwProcessorType));
203- printf("Allocation granularity : %ld\n", si.dwAllocationGranularity);
204- printf("Processor level : %d\n", si.wProcessorLevel);
205- printf("Processor revision : %x.%x\n",
206- (si.wProcessorRevision >> 8) & 0xff,
207- si.wProcessorRevision & 0xff);
208- printf(LINE_STR "\n");
209-
210- for (i = 0; i < si.dwNumberOfProcessors; i++) {
211- DWORD dwThreadId;
212- HANDLE hThread = CreateThread(NULL, 0, ThreadFunc, (LPVOID) &i, 0,
213- &dwThreadId);
214- // ハンドルは使用しないのでクローズ
215- CloseHandle(hThread);
216- Sleep(1000);
217- }
218- selfLoop();
219-
220- return 0;
221-}
222-
223-/*
224- * Local Variables:
225- * mode: c
226- * coding: utf-8
227- * End:
228- */
1+/* $Id: main.c 1313 2013-03-19 00:10:02Z tfuruka1 $
2+ *
3+ * CPU 使用率を100%にするツール
4+ *
5+ * CPU使用率を100%にしますが、システムの負荷は軽いです。
6+ */
7+#include <windows.h>
8+#include <processthreadsapi.h>
9+#include <stdio.h>
10+
11+#define VERSION "R0.1.0.0 ($Rev: 1313 $)"
12+
13+#define LINE_STR "━━━━━━━━━━━━━━━━━"\
14+ "━━━━━━━━━━━━━━━━━━"
15+
16+/* 現在は通常通りリンクできるので不要なコードとなりました
17+BOOL (WINAPI *lpGetSystemTimes)(LPFILETIME lpIdleTime,
18+ LPFILETIME lpKernelTime,
19+ LPFILETIME lpUserTime);
20+*/
21+static LPCTSTR
22+GetProcessorArchitectureStr(WORD wPA)
23+{
24+ static char szBuf[256];
25+
26+ switch (wPA) {
27+ case PROCESSOR_ARCHITECTURE_INTEL:
28+ strcpy(szBuf, "INTEL");
29+ break;
30+ case PROCESSOR_ARCHITECTURE_MIPS:
31+ strcpy(szBuf, "MIPS");
32+ break;
33+ case PROCESSOR_ARCHITECTURE_ALPHA:
34+ strcpy(szBuf, "ALPHA");
35+ break;
36+ case PROCESSOR_ARCHITECTURE_PPC:
37+ strcpy(szBuf, "POWER-PC");
38+ break;
39+ case PROCESSOR_ARCHITECTURE_SHX:
40+ strcpy(szBuf, "SH");
41+ break;
42+ case PROCESSOR_ARCHITECTURE_ARM:
43+ strcpy(szBuf, "ARM");
44+ break;
45+ case PROCESSOR_ARCHITECTURE_ARM64:
46+ strcpy(szBuf, "ARM64");
47+ break;
48+ case PROCESSOR_ARCHITECTURE_IA64:
49+ strcpy(szBuf, "INTEL-64");
50+ break;
51+ case PROCESSOR_ARCHITECTURE_ALPHA64:
52+ strcpy(szBuf, "ALPHA-64");
53+ break;
54+ case PROCESSOR_ARCHITECTURE_AMD64:
55+ strcpy(szBuf, "x64(AMD or Intel)");
56+ break;
57+ case PROCESSOR_ARCHITECTURE_UNKNOWN:
58+ strcpy(szBuf, "UNKNOWN");
59+ break;
60+ default:
61+ sprintf(szBuf, "UNKNOWN: %x", wPA);
62+ break;
63+ }
64+ return szBuf;
65+}
66+
67+static LPCTSTR
68+GetProcessorTypeStr(DWORD dwPt)
69+{
70+ static char szBuf[256];
71+
72+ switch (dwPt) {
73+ case PROCESSOR_INTEL_386:
74+ sprintf(szBuf, "INTEL386(%lu)", dwPt);
75+ break;
76+ case PROCESSOR_INTEL_486:
77+ sprintf(szBuf, "INTEL486(%lu)", dwPt);
78+ break;
79+ case PROCESSOR_INTEL_PENTIUM:
80+ sprintf(szBuf, "INTEL PENTIUM(%lu)", dwPt);
81+ break;
82+ case PROCESSOR_MIPS_R4000:
83+ sprintf(szBuf, "MIPS R4000(%lu", dwPt);
84+ break;
85+ case PROCESSOR_ALPHA_21064:
86+ sprintf(szBuf, "ALPHA 21064(%lu)", dwPt);
87+ break;
88+ case PROCESSOR_INTEL_IA64:
89+ sprintf(szBuf, "INTEL IA64(%lu)", dwPt);
90+ break;
91+ case PROCESSOR_AMD_X8664:
92+ sprintf(szBuf, "AMD X8664(%lu)", dwPt);
93+ break;
94+ case PROCESSOR_ARM720:
95+ sprintf(szBuf, "ARM(%lu)", dwPt);
96+ break;
97+ default:
98+ sprintf(szBuf, "UNKNOWn(%lu)", dwPt);
99+ break;
100+ }
101+ return szBuf;
102+}
103+
104+static LPCTSTR
105+GetActiveProcessorMaskStr(DWORD_PTR dwAPM)
106+{
107+ static char szBuf[36];
108+ int i;
109+
110+ szBuf[0] = '\0';
111+ for (i = 0; i < 32; i++) {
112+ strcat(szBuf, ((dwAPM >> i) & 1) ? "*" : ".");
113+ }
114+ return szBuf;
115+}
116+
117+static DWORD WINAPI
118+ThreadFunc(LPVOID lpPara)
119+{
120+ printf("CPU %d 占有開始...\n", *(int *) lpPara);
121+ while (TRUE) {
122+ }
123+ return 0;
124+}
125+
126+static void
127+selfLoop()
128+{
129+ unsigned char kaiten[] = "―\|/";
130+
131+ unsigned char wk[4];
132+ unsigned int i = 0;
133+ unsigned int j;
134+ unsigned int iSleep = 1000;
135+
136+ LONGLONG ftOldIdle = 0;
137+ LONGLONG ftOldKernel = 0;
138+ LONGLONG ftOldUser = 0;
139+
140+ LONGLONG ftIdle;
141+ LONGLONG ftKernel;
142+ LONGLONG ftUser;
143+
144+/* 現在は通常通りリンクできるので不要なコードとなりました。
145+ HANDLE lpLib = LoadLibrary("kernel32.dll");
146+ printf("Library Handle: %llx\n", (ULONGLONG) lpLib);
147+ if (!lpLib) {
148+ return;
149+ }
150+
151+ lpGetSystemTimes = GetProcAddress(lpLib, "GetSystemTimes");
152+
153+ printf("GetSystemTimes API Address: %lx\n", (ULONG) lpGetSystemTimes);
154+ if (!lpGetSystemTimes) {
155+ return;
156+ }
157+*/
158+ printf("終了する場合は CTRL-C を押下して下さい。\n\n");
159+
160+ while (TRUE) {
161+ j = i++ % 4;
162+ wk[0] = kaiten[j * 2];
163+ wk[1] = kaiten[j * 2 + 1];
164+ wk[2] = '\0';
165+
166+ GetSystemTimes((LPFILETIME)&ftIdle,
167+ (LPFILETIME)&ftKernel,
168+ (LPFILETIME)&ftUser);
169+ if (0 != ftOldIdle) {
170+ LONGLONG llIdle = ftIdle - ftOldIdle;
171+ LONGLONG llKernel = ftKernel - ftOldKernel;
172+ LONGLONG llUser = ftUser - ftOldUser;
173+ LONGLONG llTotal = llIdle + llKernel + llUser;
174+ TCHAR szBuf[1024];
175+
176+ sprintf(szBuf,
177+ "[%s] %5.1f%% user, %5.1f%% system, %5.1f%% idle",
178+ wk,
179+ (double) ((LONGLONG) 1000 * llUser / llTotal) / 10.0,
180+ (double) ((LONGLONG) 1000 * llKernel / llTotal) / 10.0,
181+ (double) ((LONGLONG) 1000 * llIdle / llTotal) / 10.0);
182+ printf("\r%s", szBuf);
183+ fflush(stdout);
184+
185+ SetConsoleTitle(szBuf);
186+ }
187+ ftOldIdle = ftIdle;
188+ ftOldKernel = ftKernel;
189+ ftOldUser = ftUser;
190+
191+ Sleep(iSleep);
192+ if (50 < iSleep) {
193+ iSleep -= 1;
194+ }
195+ }
196+}
197+
198+int
199+main(int argc, char *argv[])
200+{
201+ SYSTEM_INFO si;
202+ int i;
203+
204+ (void) argc;
205+ (void) argv;
206+
207+ GetSystemInfo(&si);
208+
209+ printf("$Id: main.c 1313 2013-03-19 00:10:02Z tfuruka1 $\n");
210+ printf("CPU使用率100%% %s[Build:" __DATE__ " " __TIME__ "]\n", VERSION);
211+ printf(LINE_STR "\n");
212+ printf("OEM-ID : %lx\n", si.dwOemId);
213+ printf("Processor architecture : %s\n",
214+ GetProcessorArchitectureStr(si.wProcessorArchitecture));
215+ printf("Page size : %ld\n", si.dwPageSize);
216+ printf("Minimun application address: %p\n",
217+ si.lpMinimumApplicationAddress);
218+ printf("Maximum application address: %p\n",
219+ si.lpMaximumApplicationAddress);
220+ printf("Active processor mask : 0123456789*123456789*123456789*1\n");
221+ printf(" : %s\n",
222+ GetActiveProcessorMaskStr(si.dwActiveProcessorMask));
223+ printf("Number of processors : %ld\n", si.dwNumberOfProcessors);
224+ printf("Processor type : %s\n",
225+ GetProcessorTypeStr(si.dwProcessorType));
226+ printf("Allocation granularity : %ld\n", si.dwAllocationGranularity);
227+ printf("Processor level : %d\n", si.wProcessorLevel);
228+ printf("Processor revision : %x.%x\n",
229+ (si.wProcessorRevision >> 8) & 0xff,
230+ si.wProcessorRevision & 0xff);
231+ printf(LINE_STR "\n");
232+
233+ for (i = 0; i < (int) si.dwNumberOfProcessors; i++) {
234+ DWORD dwThreadId;
235+ HANDLE hThread = CreateThread(NULL, 0, ThreadFunc, (LPVOID) &i, 0,
236+ &dwThreadId);
237+ // ハンドルは使用しないのでクローズ
238+ CloseHandle(hThread);
239+ Sleep(1000);
240+ }
241+ selfLoop();
242+
243+ return 0;
244+}
245+
246+/*
247+ * Local Variables:
248+ * mode: c
249+ * coding: utf-8
250+ * End:
251+ */
--- a/src/batkey/CMakeLists.txt
+++ b/src/batkey/CMakeLists.txt
@@ -4,11 +4,11 @@ project(batkey C)
44
55 set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
66
7-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -W -Wformat=2 -Wcast-qual")
8-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align -Wwrite-strings")
9-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wfloat-equal")
10-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith")
11-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --exec-charset=cp932")
12-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --input-charset=utf-8")
7+add_compile_options(-g -Wall -W -Wformat=2 -Wcast-qual)
8+add_compile_options(-Wcast-align -Wwrite-strings)
9+add_compile_options(-Wconversion -Wfloat-equal)
10+add_compile_options(-Wpointer-arith)
11+add_compile_options(--input-charset=utf-8)
12+add_compile_options(--exec-charset=cp932)
1313
1414 add_executable(batkey.exe main.c)