-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestC.c
More file actions
83 lines (72 loc) · 1.42 KB
/
TestC.c
File metadata and controls
83 lines (72 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
Grady Martin
2015年09月01日、17時46分
Curses Prototyping Suite: Test (C)
*/
#include <ncurses.h>
#include <stdlib.h>
#include <stdio.h>
void Gtfo (unsigned long luLine, const char *cpMessage, ...)
{
/*
Tits or this.
*/
endwin ();
va_list args;
va_start (args, cpMessage);
vfprintf (stderr, cpMessage, args);
va_end (args);
fprintf (stderr, "\n%lu行目にエラーが発生しました。\n", luLine);
exit ((int) luLine);
}
int main (const int argc, const char * const * argv)
{
if (argc < 2)
{
Gtfo (__LINE__, "読み取るパッドが渡されませんでした。");
}
initscr ();
keypad (stdscr, TRUE);
noecho ();
start_color ();
curs_set (0);
int nMaxY, nMaxX;
getmaxyx (stdscr, nMaxY, nMaxX);
nMaxY--;
nMaxX--;
FILE * file = fopen (argv[1], "r");
if (file == NULL)
{
Gtfo (__LINE__, "%sを読み取れませんでした。", argv[1]);
}
// Load window and store dimensions.
WINDOW * pad = getwin (file);
int nPadH, nPadW;
getmaxyx (pad, nPadH, nPadW);
int nPadBegY, nPadBegX;
getbegyx (pad, nPadBegY, nPadBegX);
nPadH -= nPadBegY;
nPadW -= nPadBegX;
bool bEnd = false;
unsigned uPosY = 0;
while (!bEnd)
{
int n = getch ();
switch (n)
{
case 'j':
if (! (uPosY + 1 + nMaxY >= nPadH))
uPosY++;
break;
case 'k':
if (uPosY)
uPosY--;
break;
case 'q':
bEnd = true;
break;
}
prefresh (pad, uPosY, 0, 0, 0, nMaxY, nMaxX);
}
endwin ();
}