| 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 |
{ |
{ |
| 30 |
{ |
{ |
| 31 |
prints ("\r"); |
prints ("\r"); |
| 32 |
} |
} |
| 33 |
|
iflush(); |
| 34 |
} |
} |
| 35 |
|
|
| 36 |
void |
void |
| 37 |
clrtoeol () |
clrtoeol () |
| 38 |
{ |
{ |
| 39 |
prints ("\033[K"); |
prints ("\033[K"); |
| 40 |
|
iflush(); |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
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() |
| 59 |
|
{ |
| 60 |
|
prints ("\33[2J"); |
| 61 |
|
moveto (0,0); |
| 62 |
|
iflush(); |
| 63 |
} |
} |
| 64 |
|
|
| 65 |
int |
int |
| 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[256]; |
char buffer[260]; |
| 128 |
FILE *fin; |
FILE *fin; |
| 129 |
|
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); |
| 152 |
|
if (buffer[i-1] == '\n' && buffer[i-2] != '\r') |
| 153 |
|
{ |
| 154 |
|
buffer[i-1] = '\r'; |
| 155 |
|
buffer[i] = '\n'; |
| 156 |
|
buffer[i+1] = '\0'; |
| 157 |
|
} |
| 158 |
prints (buffer); |
prints (buffer); |
| 159 |
iflush (); |
iflush (); |
| 160 |
|
|
| 161 |
|
line ++; |
| 162 |
} |
} |
| 163 |
fclose (fin); |
fclose (fin); |
| 164 |
|
|
| 179 |
{ |
{ |
| 180 |
return 0; |
return 0; |
| 181 |
} |
} |
| 182 |
|
|
| 183 |
|
int |
| 184 |
|
press_any_key() |
| 185 |
|
{ |
| 186 |
|
prints (" \033[1;33m°´ÈÎÒâ¼üÅ̼ÌÐø...\033[0;37m"); |
| 187 |
|
iflush(); |
| 188 |
|
|
| 189 |
|
return igetch (); |
| 190 |
|
} |