Subversion Repositories SvarDOS

Rev

Rev 1282 | Rev 1284 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1282 Rev 1283
-
 
1
/* Sved, the SvarDOS editor
-
 
2
 *
-
 
3
 * Copyright (C) 2023 Mateusz Viste
-
 
4
 *
-
 
5
 * Sved is released under the terms of the MIT license.
-
 
6
 *
-
 
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
-
 
8
 * of this software and associated documentation files (the "Software"), to
-
 
9
 * deal in the Software without restriction, including without limitation the
-
 
10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-
 
11
 * sell copies of the Software, and to permit persons to whom the Software is
-
 
12
 * furnished to do so, subject to the following conditions:
-
 
13
 *
-
 
14
 * The above copyright notice and this permission notice shall be included in
-
 
15
 * all copies or substantial portions of the Software.
-
 
16
 *
-
 
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-
 
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-
 
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-
 
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-
 
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-
 
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-
 
23
 * IN THE SOFTWARE.
1
/* */
24
 */
2
 
25
 
3
#include <dos.h>
26
#include <dos.h>
4
#include <fcntl.h>
27
#include <fcntl.h>
5
#include <stdlib.h>
28
#include <stdlib.h>
6
#include <string.h>
29
#include <string.h>
7
 
30
 
8
#include "mdr\cout.h"
31
#include "mdr\cout.h"
9
#include "mdr\keyb.h"
32
#include "mdr\keyb.h"
10
 
33
 
11
#include "svarlang\svarlang.h"
34
#include "svarlang\svarlang.h"
12
 
35
 
13
#define COL_TXT        0
36
#define COL_TXT        0
14
#define COL_STATUSBAR1 1
37
#define COL_STATUSBAR1 1
15
#define COL_STATUSBAR2 2
38
#define COL_STATUSBAR2 2
16
#define COL_SCROLLBAR  3
39
#define COL_SCROLLBAR  3
17
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
40
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
18
static unsigned char scheme[] = {0x07, 0x70, 0x70, 0x70};
41
static unsigned char scheme[] = {0x07, 0x70, 0x70, 0x70};
19
 
42
 
20
#define SCROLL_CURSOR 0xB1
43
#define SCROLL_CURSOR 0xB1
21
 
44
 
22
 
45
 
23
struct line {
46
struct line {
24
  struct line *prev;
47
  struct line *prev;
25
  struct line *next;
48
  struct line *next;
26
  unsigned short len;
49
  unsigned short len;
27
  char payload[1];
50
  char payload[1];
28
};
51
};
29
 
52
 
30
struct linedb {
53
struct linedb {
31
  struct line *topscreen;
54
  struct line *topscreen;
32
  struct line *cursor;
55
  struct line *cursor;
33
  unsigned short xoffset;
56
  unsigned short xoffset;
34
};
57
};
35
 
58
 
36
 
59
 
37
void line_add(struct linedb *db, const char *line) {
60
void line_add(struct linedb *db, const char *line) {
38
  unsigned short slen = strlen(line);
61
  unsigned short slen = strlen(line);
39
  struct line *l;
62
  struct line *l;
40
 
63
 
41
  /* trim out CR/LF line endings */
64
  /* trim out CR/LF line endings */
42
  if ((slen >= 2) && (line[slen - 2] == '\r')) {
65
  if ((slen >= 2) && (line[slen - 2] == '\r')) {
43
    slen -= 2;
66
    slen -= 2;
44
  } else if ((slen >= 1) && (line[slen - 1] == '\n')) {
67
  } else if ((slen >= 1) && (line[slen - 1] == '\n')) {
45
    slen--;
68
    slen--;
46
  }
69
  }
47
 
70
 
48
  l =  calloc(1, sizeof(struct line) + slen + 1);
71
  l =  calloc(1, sizeof(struct line) + slen + 1);
49
  l->prev = db->cursor;
72
  l->prev = db->cursor;
50
  if (db->cursor) {
73
  if (db->cursor) {
51
    l->next = db->cursor->next;
74
    l->next = db->cursor->next;
52
    db->cursor->next = l;
75
    db->cursor->next = l;
53
    l->next->prev = l;
76
    l->next->prev = l;
54
  }
77
  }
55
  db->cursor = l;
78
  db->cursor = l;
56
  memcpy(l->payload, line, slen);
79
  memcpy(l->payload, line, slen);
57
  l->len = slen;
80
  l->len = slen;
58
}
81
}
59
 
82
 
60
 
83
 
61
void db_rewind(struct linedb *db) {
84
void db_rewind(struct linedb *db) {
62
  if (db->cursor == NULL) return;
85
  if (db->cursor == NULL) return;
63
  while (db->cursor->prev) db->cursor = db->cursor->prev;
86
  while (db->cursor->prev) db->cursor = db->cursor->prev;
64
  db->topscreen = db->cursor;
87
  db->topscreen = db->cursor;
65
}
88
}
66
 
89
 
67
 
90
 
68
void load_colorscheme(void) {
91
void load_colorscheme(void) {
69
  scheme[COL_TXT] = 0x17;
92
  scheme[COL_TXT] = 0x17;
70
  scheme[COL_STATUSBAR1] = 0x70;
93
  scheme[COL_STATUSBAR1] = 0x70;
71
  scheme[COL_STATUSBAR2] = 0x78;
94
  scheme[COL_STATUSBAR2] = 0x78;
72
  scheme[COL_SCROLLBAR] = 0x70;
95
  scheme[COL_SCROLLBAR] = 0x70;
73
}
96
}
74
 
97
 
75
 
98
 
76
static void ui_basic(unsigned char screenw, unsigned char screenh, const char *fname) {
99
static void ui_basic(unsigned char screenw, unsigned char screenh, const char *fname) {
77
  unsigned char i;
100
  unsigned char i;
78
  const char *s = "HELP";
101
  const char *s = "HELP";
79
  unsigned char helpcol = screenw - (strlen(s) + 4);
102
  unsigned char helpcol = screenw - (strlen(s) + 4);
80
 
103
 
81
  /* clear screen */
104
  /* clear screen */
82
  mdr_cout_cls(scheme[COL_TXT]);
105
  mdr_cout_cls(scheme[COL_TXT]);
83
 
106
 
84
  /* status bar */
107
  /* status bar */
85
  for (i = 0; i < helpcol; i++) {
108
  for (i = 0; i < helpcol; i++) {
86
    mdr_cout_char(screenh - 1, i, *fname, scheme[COL_STATUSBAR1]);
109
    mdr_cout_char(screenh - 1, i, *fname, scheme[COL_STATUSBAR1]);
87
    if (*fname != 0) fname++;
110
    if (*fname != 0) fname++;
88
  }
111
  }
89
  mdr_cout_str(screenh - 1, helpcol, " F1=", scheme[COL_STATUSBAR2], 40);
112
  mdr_cout_str(screenh - 1, helpcol, " F1=", scheme[COL_STATUSBAR2], 40);
90
  mdr_cout_str(screenh - 1, helpcol + 4, s, scheme[COL_STATUSBAR2], 40);
113
  mdr_cout_str(screenh - 1, helpcol + 4, s, scheme[COL_STATUSBAR2], 40);
91
 
114
 
92
  /* scroll bar */
115
  /* scroll bar */
93
  for (i = 0; i < (screenh - 1); i++) {
116
  for (i = 0; i < (screenh - 1); i++) {
94
    mdr_cout_char(i, screenw - 1, SCROLL_CURSOR, scheme[COL_SCROLLBAR]);
117
    mdr_cout_char(i, screenw - 1, SCROLL_CURSOR, scheme[COL_SCROLLBAR]);
95
  }
118
  }
96
}
119
}
97
 
120
 
98
 
121
 
99
static void ui_refresh(const struct linedb *db, unsigned char screenw, unsigned char screenh, unsigned char uidirtyfrom, unsigned char uidirtyto) {
122
static void ui_refresh(const struct linedb *db, unsigned char screenw, unsigned char screenh, unsigned char uidirtyfrom, unsigned char uidirtyto) {
100
  unsigned char y = 0;
123
  unsigned char y = 0;
101
  unsigned char len;
124
  unsigned char len;
102
  struct line *l;
125
  struct line *l;
103
 
126
 
104
  /* DEBUG TODO FIXME */
127
  /* DEBUG TODO FIXME */
105
  static char m = 'a';
128
  static char m = 'a';
106
  m++;
129
  m++;
107
  if (m > 'z') m = 'a';
130
  if (m > 'z') m = 'a';
108
 
131
 
109
  for (l = db->topscreen; l != NULL; l = l->next) {
132
  for (l = db->topscreen; l != NULL; l = l->next) {
110
 
133
 
111
    /* skip lines that do not to be refreshed */
134
    /* skip lines that do not to be refreshed */
112
    if ((y < uidirtyfrom) || (y > uidirtyto)) continue;
135
    if ((y < uidirtyfrom) || (y > uidirtyto)) continue;
113
 
136
 
114
    if (db->xoffset < l->len) {
137
    if (db->xoffset < l->len) {
115
      len = mdr_cout_str(y, 0, l->payload + db->xoffset, scheme[COL_TXT], screenw - 1);
138
      len = mdr_cout_str(y, 0, l->payload + db->xoffset, scheme[COL_TXT], screenw - 1);
116
    } else {
139
    } else {
117
      len = 0;
140
      len = 0;
118
    }
141
    }
119
    while (len < screenw - 1) mdr_cout_char(y, len++, ' ', scheme[COL_TXT]);
142
    while (len < screenw - 1) mdr_cout_char(y, len++, ' ', scheme[COL_TXT]);
120
 
143
 
121
    /* FIXME DEBUG */
144
    /* FIXME DEBUG */
122
    mdr_cout_char(y, 0, m, scheme[COL_STATUSBAR1]);
145
    mdr_cout_char(y, 0, m, scheme[COL_STATUSBAR1]);
123
 
146
 
124
    if (y == screenh - 2) break;
147
    if (y == screenh - 2) break;
125
    y++;
148
    y++;
126
  }
149
  }
127
}
150
}
128
 
151
 
129
 
152
 
130
static void check_cursor_not_after_eol(struct linedb *db, unsigned char *cursorpos, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
153
static void check_cursor_not_after_eol(struct linedb *db, unsigned char *cursorpos, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
131
  if (db->xoffset + *cursorpos <= db->cursor->len) return;
154
  if (db->xoffset + *cursorpos <= db->cursor->len) return;
132
 
155
 
133
  if (db->cursor->len < db->xoffset) {
156
  if (db->cursor->len < db->xoffset) {
134
    *cursorpos = 0;
157
    *cursorpos = 0;
135
    db->xoffset = db->cursor->len;
158
    db->xoffset = db->cursor->len;
136
    *uidirtyfrom = 0;
159
    *uidirtyfrom = 0;
137
    *uidirtyto = 0xff;
160
    *uidirtyto = 0xff;
138
  } else {
161
  } else {
139
    *cursorpos = db->cursor->len - db->xoffset;
162
    *cursorpos = db->cursor->len - db->xoffset;
140
  }
163
  }
141
}
164
}
142
 
165
 
143
 
166
 
144
static void cursor_up(struct linedb *db, unsigned char *cursorposy, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
167
static void cursor_up(struct linedb *db, unsigned char *cursorposy, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
145
  if (db->cursor->prev != NULL) {
168
  if (db->cursor->prev != NULL) {
146
    db->cursor = db->cursor->prev;
169
    db->cursor = db->cursor->prev;
147
    if (*cursorposy == 0) {
170
    if (*cursorposy == 0) {
148
      db->topscreen = db->cursor;
171
      db->topscreen = db->cursor;
149
      *uidirtyfrom = 0;
172
      *uidirtyfrom = 0;
150
      *uidirtyto = 0xff;
173
      *uidirtyto = 0xff;
151
    } else {
174
    } else {
152
      *cursorposy -= 1;
175
      *cursorposy -= 1;
153
    }
176
    }
154
  }
177
  }
155
}
178
}
156
 
179
 
157
 
180
 
158
static void cursor_eol(struct linedb *db, unsigned char *cursorposx, unsigned char screenw, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
181
static void cursor_eol(struct linedb *db, unsigned char *cursorposx, unsigned char screenw, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
159
  /* adjust xoffset to make sure eol is visible on screen */
182
  /* adjust xoffset to make sure eol is visible on screen */
160
  if (db->xoffset > db->cursor->len) {
183
  if (db->xoffset > db->cursor->len) {
161
    db->xoffset = db->cursor->len - 1;
184
    db->xoffset = db->cursor->len - 1;
162
    *uidirtyfrom = 0;
185
    *uidirtyfrom = 0;
163
    *uidirtyto = 0xff;
186
    *uidirtyto = 0xff;
164
  }
187
  }
165
 
188
 
166
  if (db->xoffset + screenw - 1 <= db->cursor->len) {
189
  if (db->xoffset + screenw - 1 <= db->cursor->len) {
167
    db->xoffset = db->cursor->len - screenw + 2;
190
    db->xoffset = db->cursor->len - screenw + 2;
168
    *uidirtyfrom = 0;
191
    *uidirtyfrom = 0;
169
    *uidirtyto = 0xff;
192
    *uidirtyto = 0xff;
170
  }
193
  }
171
  *cursorposx = db->cursor->len - db->xoffset;
194
  *cursorposx = db->cursor->len - db->xoffset;
172
}
195
}
173
 
196
 
174
 
197
 
175
static void cursor_down(struct linedb *db, unsigned char *cursorposy, unsigned char screenh, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
198
static void cursor_down(struct linedb *db, unsigned char *cursorposy, unsigned char screenh, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
176
  if (db->cursor->next != NULL) {
199
  if (db->cursor->next != NULL) {
177
    db->cursor = db->cursor->next;
200
    db->cursor = db->cursor->next;
178
    if (*cursorposy < screenh - 2) {
201
    if (*cursorposy < screenh - 2) {
179
      *cursorposy += 1;
202
      *cursorposy += 1;
180
    } else {
203
    } else {
181
      db->topscreen = db->topscreen->next;
204
      db->topscreen = db->topscreen->next;
182
      *uidirtyfrom = 0;
205
      *uidirtyfrom = 0;
183
      *uidirtyto = 0xff;
206
      *uidirtyto = 0xff;
184
    }
207
    }
185
  }
208
  }
186
}
209
}
187
 
210
 
188
 
211
 
189
static void cursor_home(struct linedb *db, unsigned char *cursorposx, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
212
static void cursor_home(struct linedb *db, unsigned char *cursorposx, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
190
  *cursorposx = 0;
213
  *cursorposx = 0;
191
  if (db->xoffset != 0) {
214
  if (db->xoffset != 0) {
192
    db->xoffset = 0;
215
    db->xoffset = 0;
193
    *uidirtyfrom = 0;
216
    *uidirtyfrom = 0;
194
    *uidirtyto = 0xff;
217
    *uidirtyto = 0xff;
195
  }
218
  }
196
}
219
}
197
 
220
 
198
 
221
 
199
int main(int argc, char **argv) {
222
int main(int argc, char **argv) {
200
  int fd;
223
  int fd;
201
  const char *fname = NULL;
224
  const char *fname = NULL;
202
  char buff[1024];
225
  char buff[1024];
203
  struct linedb db;
226
  struct linedb db;
204
  unsigned char screenw = 0, screenh = 0;
227
  unsigned char screenw = 0, screenh = 0;
205
  unsigned char cursorposx = 0, cursorposy = 0;
228
  unsigned char cursorposx = 0, cursorposy = 0;
206
  unsigned char uidirtyfrom = 0, uidirtyto = 0xff; /* make sure to redraw entire UI at first run */
229
  unsigned char uidirtyfrom = 0, uidirtyto = 0xff; /* make sure to redraw entire UI at first run */
207
 
230
 
208
  bzero(&db, sizeof(db));
231
  bzero(&db, sizeof(db));
209
 
232
 
210
  svarlang_autoload_nlspath("sved");
233
  svarlang_autoload_nlspath("sved");
211
 
234
 
212
  if ((argc != 2) || (argv[1][0] == '/')) {
235
  if ((argc != 2) || (argv[1][0] == '/')) {
213
    mdr_coutraw_puts("usage: sved file.txt");
236
    mdr_coutraw_puts("usage: sved file.txt");
214
    return(0);
237
    return(0);
215
  }
238
  }
216
 
239
 
217
  fname = argv[1];
240
  fname = argv[1];
218
 
241
 
219
  mdr_coutraw_puts("");
242
  mdr_coutraw_puts("");
220
 
243
 
221
  if (_dos_open(fname, O_RDONLY, &fd) != 0) {
244
  if (_dos_open(fname, O_RDONLY, &fd) != 0) {
222
    mdr_coutraw_puts("Failed to open file:");
245
    mdr_coutraw_puts("Failed to open file:");
223
    mdr_coutraw_puts(fname);
246
    mdr_coutraw_puts(fname);
224
    return(1);
247
    return(1);
225
  }
248
  }
226
 
249
 
227
  /* load file */
250
  /* load file */
228
  {
251
  {
229
    unsigned int prevlen = 0, len, llen;
252
    unsigned int prevlen = 0, len, llen;
230
 
253
 
231
    do {
254
    do {
232
      if (_dos_read(fd, buff + prevlen, sizeof(buff) - prevlen, &len) != 0) break;
255
      if (_dos_read(fd, buff + prevlen, sizeof(buff) - prevlen, &len) != 0) break;
233
      len += prevlen;
256
      len += prevlen;
234
 
257
 
235
      /* look for nearest \n and replace with 0*/
258
      /* look for nearest \n and replace with 0*/
236
      for (llen = 0; buff[llen] != '\n'; llen++) {
259
      for (llen = 0; buff[llen] != '\n'; llen++) {
237
        if (llen == sizeof(buff)) break;
260
        if (llen == sizeof(buff)) break;
238
      }
261
      }
239
      buff[llen] = 0;
262
      buff[llen] = 0;
240
      if ((llen > 0) && (buff[llen - 1])) buff[llen - 1] = 0; /* trim \r if line ending is cr/lf */
263
      if ((llen > 0) && (buff[llen - 1])) buff[llen - 1] = 0; /* trim \r if line ending is cr/lf */
241
      line_add(&db, buff);
264
      line_add(&db, buff);
242
 
265
 
243
      len -= llen + 1;
266
      len -= llen + 1;
244
      memmove(buff, buff + llen + 1, len);
267
      memmove(buff, buff + llen + 1, len);
245
      prevlen = len;
268
      prevlen = len;
246
    } while (len > 0);
269
    } while (len > 0);
247
 
270
 
248
  }
271
  }
249
 
272
 
250
  /* add an empty line at end if not present already */
273
  /* add an empty line at end if not present already */
251
  if (db.cursor->len != 0) line_add(&db, "");
274
  if (db.cursor->len != 0) line_add(&db, "");
252
 
275
 
253
  _dos_close(fd);
276
  _dos_close(fd);
254
 
277
 
255
  if (mdr_cout_init(&screenw, &screenh)) load_colorscheme();
278
  if (mdr_cout_init(&screenw, &screenh)) load_colorscheme();
256
  ui_basic(screenw, screenh, fname);
279
  ui_basic(screenw, screenh, fname);
257
 
280
 
258
  db_rewind(&db);
281
  db_rewind(&db);
259
 
282
 
260
  for (;;) {
283
  for (;;) {
261
    int k;
284
    int k;
262
 
285
 
263
    check_cursor_not_after_eol(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
286
    check_cursor_not_after_eol(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
264
    mdr_cout_locate(cursorposy, cursorposx);
287
    mdr_cout_locate(cursorposy, cursorposx);
265
 
288
 
266
    if (uidirtyfrom != 0xff) {
289
    if (uidirtyfrom != 0xff) {
267
      ui_refresh(&db, screenw, screenh, uidirtyfrom, uidirtyto);
290
      ui_refresh(&db, screenw, screenh, uidirtyfrom, uidirtyto);
268
      uidirtyfrom = 0xff;
291
      uidirtyfrom = 0xff;
269
    }
292
    }
270
 
293
 
271
    k = keyb_getkey();
294
    k = keyb_getkey();
272
 
295
 
273
    if (k == 0x150) { /* down */
296
    if (k == 0x150) { /* down */
274
      cursor_down(&db, &cursorposy, screenh, &uidirtyfrom, &uidirtyto);
297
      cursor_down(&db, &cursorposy, screenh, &uidirtyfrom, &uidirtyto);
275
 
298
 
276
    } else if (k == 0x148) { /* up */
299
    } else if (k == 0x148) { /* up */
277
      cursor_up(&db, &cursorposy, &uidirtyfrom, &uidirtyto);
300
      cursor_up(&db, &cursorposy, &uidirtyfrom, &uidirtyto);
278
 
301
 
279
    } else if (k == 0x14D) { /* right */
302
    } else if (k == 0x14D) { /* right */
280
      if (db.cursor->len > db.xoffset + cursorposx) {
303
      if (db.cursor->len > db.xoffset + cursorposx) {
281
        if (cursorposx < screenw - 2) {
304
        if (cursorposx < screenw - 2) {
282
          cursorposx++;
305
          cursorposx++;
283
        } else {
306
        } else {
284
          db.xoffset++;
307
          db.xoffset++;
285
          uidirtyfrom = 0;
308
          uidirtyfrom = 0;
286
          uidirtyto = 0xff;
309
          uidirtyto = 0xff;
287
        }
310
        }
288
      } else {
311
      } else {
289
        cursor_down(&db, &cursorposy, screenh, &uidirtyfrom, &uidirtyto);
312
        cursor_down(&db, &cursorposy, screenh, &uidirtyfrom, &uidirtyto);
290
        cursor_home(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
313
        cursor_home(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
291
      }
314
      }
292
 
315
 
293
    } else if (k == 0x14B) { /* left */
316
    } else if (k == 0x14B) { /* left */
294
      if (cursorposx > 0) {
317
      if (cursorposx > 0) {
295
        cursorposx--;
318
        cursorposx--;
296
      } else if (db.xoffset > 0) {
319
      } else if (db.xoffset > 0) {
297
        db.xoffset--;
320
        db.xoffset--;
298
        uidirtyfrom = 0;
321
        uidirtyfrom = 0;
299
        uidirtyto = 0xff;
322
        uidirtyto = 0xff;
300
      } else if (db.cursor->prev != NULL) { /* jump to end of line above */
323
      } else if (db.cursor->prev != NULL) { /* jump to end of line above */
301
        cursor_up(&db, &cursorposy, &uidirtyfrom, &uidirtyto);
324
        cursor_up(&db, &cursorposy, &uidirtyfrom, &uidirtyto);
302
        cursor_eol(&db, &cursorposx, screenw, &uidirtyfrom, &uidirtyto);
325
        cursor_eol(&db, &cursorposx, screenw, &uidirtyfrom, &uidirtyto);
303
      }
326
      }
304
 
327
 
305
    } else if (k == 0x149) { /* pgup */
328
    } else if (k == 0x149) { /* pgup */
306
      // TODO
329
      // TODO
307
 
330
 
308
    } else if (k == 0x151) { /* pgdown */
331
    } else if (k == 0x151) { /* pgdown */
309
      // TODO
332
      // TODO
310
 
333
 
311
    } else if (k == 0x147) { /* home */
334
    } else if (k == 0x147) { /* home */
312
       cursor_home(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
335
       cursor_home(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
313
 
336
 
314
    } else if (k == 0x14F) { /* end */
337
    } else if (k == 0x14F) { /* end */
315
       cursor_eol(&db, &cursorposx, screenw, &uidirtyfrom, &uidirtyto);
338
       cursor_eol(&db, &cursorposx, screenw, &uidirtyfrom, &uidirtyto);
316
 
339
 
317
    } else if (k == 0x1B) { /* ESC */
340
    } else if (k == 0x1B) { /* ESC */
318
      break;
341
      break;
319
 
342
 
320
    } else { /* UNHANDLED KEY - TODO IGNORE THIS IN PRODUCTION RELEASE */
343
    } else { /* UNHANDLED KEY - TODO IGNORE THIS IN PRODUCTION RELEASE */
321
      char buff[4];
344
      char buff[4];
322
      const char *HEX = "0123456789ABCDEF";
345
      const char *HEX = "0123456789ABCDEF";
323
      buff[0] = HEX[(k >> 8) & 15];
346
      buff[0] = HEX[(k >> 8) & 15];
324
      buff[1] = HEX[(k >> 4) & 15];
347
      buff[1] = HEX[(k >> 4) & 15];
325
      buff[2] = HEX[k & 15];
348
      buff[2] = HEX[k & 15];
326
      mdr_cout_str(screenh - 1, 0, "UNHANDLED KEY: 0x", scheme[COL_STATUSBAR1], 17);
349
      mdr_cout_str(screenh - 1, 0, "UNHANDLED KEY: 0x", scheme[COL_STATUSBAR1], 17);
327
      mdr_cout_str(screenh - 1, 17, buff, scheme[COL_STATUSBAR1], 3);
350
      mdr_cout_str(screenh - 1, 17, buff, scheme[COL_STATUSBAR1], 3);
328
      keyb_getkey();
351
      keyb_getkey();
329
      break;
352
      break;
330
    }
353
    }
331
  }
354
  }
332
 
355
 
333
  mdr_cout_close();
356
  mdr_cout_close();
334
 
357
 
335
  /* TODO free memory */
358
  /* TODO free memory */
336
 
359
 
337
  return(0);
360
  return(0);
338
}
361
}
339
 
362