#include <ctype.h>
#endif
-#if defined(__BORLANDC__) && !defined(WIN32)
+#if (defined(__BORLANDC__) || defined(__CYGWIN__)) && !defined(WIN32)
/* If this is DOS or win16, we'll fail anyway. */
/* Might as well assume win32. */
# define WIN32
/* Current cursor position. Always within file. */
-int line = 0;
+int line = 0;
int col = 0;
size_t file_pos = 0; /* Character position corresponding to cursor. */
{
line_map map = current_map;
int start_line = map -> line;
-
+
current_map_size = 0;
for(; map != 0; map = map -> previous) {
current_map_size++;
void add_map(int line, size_t pos)
{
line_map new_map = GC_NEW(struct LineMapRep);
-
+
if (current_map_size >= MAX_MAP_SIZE) prune_map();
new_map -> line = line;
new_map -> pos = pos;
size_t cur;
size_t next;
line_map map = current_map;
-
+
while (map -> line > i) map = map -> previous;
if (map -> line < i - 2) /* rebuild */ invalidate_map(i);
for (j = map -> line, cur = map -> pos; j < i;) {
void add_hist(CORD s)
{
history new_file = GC_NEW(struct HistoryRep);
-
+
new_file -> file_contents = current = s;
current_len = CORD_len(s);
new_file -> previous = now;
register int c;
CORD_pos p;
size_t len = CORD_len(s);
-
+
if (screen == 0 || LINES > screen_size) {
screen_size = LINES;
screen = (CORD *)GC_MALLOC(screen_size * sizeof(CORD));
/* avoids scanning very long lines */
int eol = CORD_chr(candidate, 0, '\n');
int len;
-
+
if (eol == CORD_NOT_FOUND) eol = CORD_len(candidate);
len = (int)eol - (int)column;
if (len < 0) len = 0;
CORD retrieve_screen_line(int i)
{
register size_t pos;
-
+
invalidate_map(dis_line + LINES); /* Prune search */
pos = line_pos(dis_line + i, 0);
if (pos == CORD_NOT_FOUND) return(CORD_EMPTY);
void redisplay(void)
{
register int i;
-
+
invalidate_map(dis_line + LINES); /* Prune search */
for (i = 0; i < LINES; i++) {
if (need_redisplay == ALL || need_redisplay == i) {
register size_t pos = line_pos(dis_line + i, 0);
-
+
if (pos == CORD_NOT_FOUND) break;
replace_line(i, retrieve_line(current, pos, dis_col));
if (need_redisplay == i) goto done;
{
int old_line = dis_line;
int old_col = dis_col;
-
+
dis_granularity = 1;
if (LINES > 15 && COLS > 15) dis_granularity = 2;
while (dis_line > line) dis_line -= dis_granularity;
void fix_pos()
{
int my_col = col;
-
+
if ((size_t)line > current_len) line = current_len;
file_pos = line_pos(line, &my_col);
if (file_pos == CORD_NOT_FOUND) {
}
#if defined(WIN32)
-# define beep() Beep(1000 /* Hz */, 300 /* msecs */)
+# define beep() Beep(1000 /* Hz */, 300 /* msecs */)
#elif defined(MACINTOSH)
# define beep() SysBeep(1)
#else
int i;
int need_fix_pos;
FILE * out;
-
+
if ( c == '\r') c = '\n';
if (locate_mode) {
size_t new_pos;
-
+
if (c == LOCATE) {
locate_mode = 0;
locate_string = CORD_EMPTY;
{
CORD left_part = CORD_substr(current, 0, file_pos);
CORD right_part = CORD_substr(current, file_pos, current_len);
-
+
add_hist(CORD_cat(CORD_cat_char(left_part, (char)c),
right_part));
invalidate_map(line);
{
FILE * f;
CORD initial;
-
+
if ((f = fopen(arg_file_name, "rb")) == NULL) {
initial = "\n";
} else {
argc = ccommand(&argv);
#endif
GC_INIT();
-
+
if (argc != 2) goto usage;
arg_file_name = argv[1];
setvbuf(stdout, GC_MALLOC_ATOMIC(8192), _IOFBF, 8192);