• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

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

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

*NIX用コマンドライン手順書自動作成ツール開発


コミットメタ情報

リビジョン8d92afd7aceb496d99b2590989fbec4b254d573b (tree)
日時2016-09-13 21:50:16
作者Koine Yuusuke(koinec) <koinec@user...>
コミッターKoine Yuusuke(koinec)

ログメッセージ

* AddFiles: STDIN garbage data sink program "sink" sourcecode. (sink.c)

変更サマリ

差分

--- a/Makefile
+++ b/Makefile
@@ -31,12 +31,14 @@
3131 #PrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcE
3232
3333 MAKE = make
34-TARGET = procedure
35-OBJS = procedure.o \
34+TARGET_PROCEDURE = procedure
35+TARGET_SINK = sink
36+OBJS_PROCEDURE = procedure.o \
3637 master.o
37-PARTS_OBJS = cmdline.o \
38+OBJS_PARTS = cmdline.o \
3839 outbuffer.o \
3940 depend_freebsd.o
41+OBJS_SINK = sink.o
4042 HEADERS = procedure.h \
4143 config.h \
4244 master.h \
@@ -56,8 +58,8 @@ TEST_OBJS = test_procedure.o \
5658 TEST_HEADERS = test_procedure.h
5759
5860
59-all: $(TARGET) test
60-build: $(TARGET)
61+all: $(TARGET_SINK) $(TARGET_PROCEDURE) test
62+build: $(TARGET_SINK) $(TARGET_PROCEDURE)
6163 test: $(TEST_TARGET)
6264 ./$(TEST_TARGET)
6365
@@ -72,9 +74,14 @@ procedure.o: procedure.c $(HEADERS)
7274 depend_freebsd.o: depend_freebsd.c $(HEADERS)
7375 $(CC) -c -o depend_freebsd.o $(FLAGS_DEBUG) $(CFLAGS) depend_freebsd.c
7476
75-$(TARGET): $(OBJS) $(PARTS_OBJS)
76- $(CC) -o $(TARGET) $(OBJS) $(PARTS_OBJS) $(FLAGS_LIB)
77+$(TARGET_PROCEDURE): $(OBJS_PROCEDURE) $(OBJS_PARTS)
78+ $(CC) -o $(TARGET_PROCEDURE) $(OBJS_PROCEDURE) $(OBJS_PARTS) $(FLAGS_LIB)
7779
80+sink.o: sink.c $(HEADERS)
81+ $(CC) -c -o sink.o $(FLAGS_DEBUG) $(CFLAGS) sink.c
82+$(TARGET_SINK): $(OBJS_SINK)
83+ $(CC) -o $(TARGET_SINK) $(OBJS_SINK) $(FLAGS_LIB)
84+ strip $(TARGET_SINK)
7885
7986 test_procedure.o: test_procedure.c $(HEADERS) $(TEST_HEADERS)
8087 $(CC) -c -o test_procedure.o $(FLAGS_DEBUG) $(CFLAGS) $(TEST_FLAGS_COMPILE) \
@@ -86,13 +93,14 @@ test_outbuffer.o: test_outbuffer.c $(HEADERS) $(TEST_HEADERS)
8693 $(CC) -c -o test_outbuffer.o $(FLAGS_DEBUG) $(CFLAGS) $(TEST_FLAGS_COMPILE) \
8794 test_outbuffer.c
8895
89-$(TEST_TARGET): $(TEST_OBJS) $(PARTS_OBJS)
96+$(TEST_TARGET): $(TEST_OBJS) $(OBJS_PARTS)
9097 $(CC) -o $(TEST_TARGET) $(FLAGS_DEBUG) $(TEST_FLAGS_LIB) $(FLAGS_LIB) \
91- $(TEST_OBJS) $(PARTS_OBJS)
98+ $(TEST_OBJS) $(OBJS_PARTS)
9299
93100 clean:
94101 rm -f *.o
95- rm -f $(TARGET)
102+ rm -f $(TARGET_SINK)
103+ rm -f $(TARGET_PROCEDURE)
96104 rm -f $(TEST_TARGET)
97105 rm -f *.xml
98106 rm -f procedure.txt
--- /dev/null
+++ b/sink.c
@@ -0,0 +1,52 @@
1+#include <sys/types.h>
2+#include <stdio.h>
3+#include <stdlib.h>
4+#include <unistd.h>
5+#include <fcntl.h>
6+#include <poll.h>
7+#include <termios.h>
8+#include <limits.h>
9+
10+int
11+ main(
12+ int argc,
13+ char *argv[] )
14+{
15+ int i_status = 0;
16+ long l_value;
17+ ssize_t sz_read;
18+ unsigned char b_data[BUFSIZ];
19+ char *pstr_end;
20+ struct pollfd t_polllst = { 0, POLLIN | POLLRDNORM, 0};
21+ struct termios t_term;
22+ struct termios t_default;
23+
24+ if( 2 == argc ) {
25+ l_value = strtol( argv[1], &pstr_end, 10 );
26+
27+ if( argv[1] != pstr_end ) {
28+ i_status = (int)l_value;
29+ }
30+ }
31+
32+ tcgetattr( fileno(stdin), &t_term );
33+ t_default = t_term;
34+
35+ t_term.c_lflag &= ~ICANON;
36+ tcsetattr( fileno(stdin), TCSANOW, &t_term );
37+
38+ poll( &t_polllst, 1, 0 );
39+ while( POLLIN & t_polllst.revents ) {
40+ do {
41+ sz_read = read( 0, b_data, BUFSIZ );
42+ } while( BUFSIZ == sz_read );
43+
44+ t_polllst.revents = 0;
45+ poll( &t_polllst, 1, 0 );
46+ }
47+
48+ tcsetattr( fileno(stdin), TCSANOW, &t_default );
49+
50+ return i_status;
51+}
52+