| 17 |
|
|
| 18 |
#include "io.h" |
#include "io.h" |
| 19 |
|
|
| 20 |
|
int screen_lines = 24; |
| 21 |
|
|
| 22 |
void |
void |
| 23 |
moveto (int row, int col) |
moveto (int row, int col) |
| 24 |
{ |
{ |
| 41 |
} |
} |
| 42 |
|
|
| 43 |
void |
void |
| 44 |
|
clrline (int line_begin, int line_end) |
| 45 |
|
{ |
| 46 |
|
int i; |
| 47 |
|
|
| 48 |
|
for (i = line_begin; i <= line_end; i++) |
| 49 |
|
{ |
| 50 |
|
moveto (i, 0); |
| 51 |
|
prints ("\033[K"); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
iflush(); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
void |
| 58 |
clearscr() |
clearscr() |
| 59 |
{ |
{ |
| 60 |
prints ("\33[2J"); |
prints ("\33[2J"); |
| 122 |
} |
} |
| 123 |
|
|
| 124 |
int |
int |
| 125 |
display_file(const char* filename) |
display_file(const char* filename, int clear, int begin_line) |
| 126 |
{ |
{ |
| 127 |
char buffer[260]; |
char buffer[260]; |
| 128 |
FILE *fin; |
FILE *fin; |
| 129 |
int i; |
int i, line; |
| 130 |
|
|
| 131 |
|
if (clear) |
| 132 |
|
{ |
| 133 |
|
clrline(begin_line, screen_lines - 1); |
| 134 |
|
line = begin_line; |
| 135 |
|
moveto (line, 0); |
| 136 |
|
} |
| 137 |
|
|
| 138 |
if ((fin = fopen(filename, "r")) != NULL) |
if ((fin = fopen(filename, "r")) != NULL) |
| 139 |
{ |
{ |
| 140 |
while (fgets(buffer, 255, fin)) |
while (fgets(buffer, 255, fin)) |
| 141 |
{ |
{ |
| 142 |
|
if (line == screen_lines - 1) |
| 143 |
|
{ |
| 144 |
|
moveto (screen_lines - 1, 0); |
| 145 |
|
press_any_key(); |
| 146 |
|
clrline(begin_line, screen_lines - 1); |
| 147 |
|
line = begin_line; |
| 148 |
|
moveto (line, 0); |
| 149 |
|
} |
| 150 |
|
|
| 151 |
i = strlen(buffer); |
i = strlen(buffer); |
| 152 |
if (buffer[i-1] == '\n' && buffer[i-2] != '\r') |
if (buffer[i-1] == '\n' && buffer[i-2] != '\r') |
| 153 |
{ |
{ |
| 157 |
} |
} |
| 158 |
prints (buffer); |
prints (buffer); |
| 159 |
iflush (); |
iflush (); |
| 160 |
|
|
| 161 |
|
line ++; |
| 162 |
} |
} |
| 163 |
fclose (fin); |
fclose (fin); |
| 164 |
|
|
| 183 |
int |
int |
| 184 |
press_any_key() |
press_any_key() |
| 185 |
{ |
{ |
| 186 |
prints (" \033[1;33m按任意键盘继续...\033[0;37m"); |
prints (" \033[1;33m按任意键盘继续...\033[0;37m"); |
| 187 |
iflush(); |
iflush(); |
| 188 |
|
|
| 189 |
return igetch (); |
return igetch (); |