Subversion Repositories SvarDOS

Rev

Rev 1353 | Rev 1355 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1353 Rev 1354
Line 39... Line 39...
39
 * global variables and definitions                                          *
39
 * global variables and definitions                                          *
40
 *****************************************************************************/
40
 *****************************************************************************/
41
 
41
 
42
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
42
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
43
static unsigned char SCHEME_TEXT   = 0x07,
43
static unsigned char SCHEME_TEXT   = 0x07,
-
 
44
                     SCHEME_MENU   = 0x70,
-
 
45
                     SCHEME_MENU_CUR= 0x0f,
-
 
46
                     SCHEME_MENU_SEL= 0x00,
44
                     SCHEME_STBAR1 = 0x70,
47
                     SCHEME_STBAR1 = 0x70,
45
                     SCHEME_STBAR2 = 0x70,
48
                     SCHEME_STBAR2 = 0x70,
46
                     SCHEME_STBAR3 = 0xf0,
49
                     SCHEME_STBAR3 = 0xf0,
47
                     SCHEME_SCROLL = 0x70,
50
                     SCHEME_SCROLL = 0x70,
48
                     SCHEME_MSG    = 0x70,
51
                     SCHEME_MSG    = 0x70,
Line 263... Line 266...
263
 
266
 
264
  return(1);
267
  return(1);
265
}
268
}
266
 
269
 
267
 
270
 
268
static void ui_help(void) {
-
 
269
#define MAXLINLEN 39
-
 
270
  unsigned short i, offset;
-
 
271
  offset = (screenw - MAXLINLEN) >> 1;
-
 
272
 
-
 
273
  for (i = 3; i < 25; i++) {
-
 
274
    const char *s = svarlang_str(8, i);
-
 
275
    if (s[0] == 0) break;
-
 
276
    mdr_cout_char_rep(i, offset, ' ', SCHEME_STBAR1, MAXLINLEN);
-
 
277
    if (s[0] == '.') continue;
-
 
278
    mdr_cout_locate(i, offset + 2 + mdr_cout_str(i, offset + 2, s, SCHEME_STBAR1, MAXLINLEN - 2));
-
 
279
  }
-
 
280
 
-
 
281
  keyb_getkey();
-
 
282
#undef MAXLINLEN
-
 
283
}
-
 
284
 
-
 
285
 
-
 
286
static void ui_refresh(const struct file *db) {
271
static void ui_refresh(const struct file *db) {
287
  unsigned char x;
272
  unsigned char x;
288
  const struct line far *l;
273
  const struct line far *l;
289
  unsigned char y = db->cursorposy;
274
  unsigned char y = db->cursorposy;
290
 
275
 
Line 707... Line 692...
707
    l = l->prev;
692
    l = l->prev;
708
  }
693
  }
709
}
694
}
710
 
695
 
711
 
696
 
-
 
697
enum MENU_ACTION {
-
 
698
  MENU_NONE = 0,
-
 
699
  MENU_NEW = 1,
-
 
700
  MENU_OPEN = 2,
-
 
701
  MENU_SAVE = 3,
-
 
702
  MENU_SAVEAS = 4,
-
 
703
  MENU_CHGEOL = 5,
-
 
704
  MENU_QUIT = 6
-
 
705
};
-
 
706
 
-
 
707
static enum MENU_ACTION ui_menu(void) {
-
 
708
  unsigned short i, curchoice, attr, x, slen;
-
 
709
  uidirty.from = 0;
-
 
710
  uidirty.to = 0xff;
-
 
711
  uidirty.statusbar = 1;
-
 
712
 
-
 
713
  /* find out the longest string */
-
 
714
  slen = 0;
-
 
715
  for (i = MENU_NEW; i <= MENU_QUIT; i++) {
-
 
716
    x = strlen(svarlang_str(8, i));
-
 
717
    if (x > slen) slen = x;
-
 
718
  }
-
 
719
 
-
 
720
  curchoice = MENU_NEW;
-
 
721
  for (;;) {
-
 
722
    /* render menu */
-
 
723
    for (i = MENU_NONE; i <= MENU_QUIT + 1; i++) {
-
 
724
      mdr_cout_char_rep(i, 0, ' ', SCHEME_MENU, slen+4);
-
 
725
      if (i == curchoice) {
-
 
726
        attr = SCHEME_MENU_CUR;
-
 
727
        mdr_cout_char(i, 1, '>', SCHEME_MENU_SEL);
-
 
728
      } else {
-
 
729
        attr = SCHEME_MENU;
-
 
730
      }
-
 
731
      x = mdr_cout_str(i, 2, svarlang_str(8, i), attr, slen);
-
 
732
      if (i == curchoice) {
-
 
733
        mdr_cout_char_rep(i, x + 2, ' ', SCHEME_MENU_SEL, slen - x + 1);
-
 
734
        mdr_cout_locate(i, x + 2);
-
 
735
      }
-
 
736
    }
-
 
737
    /* wait for key */
-
 
738
    switch (keyb_getkey()) {
-
 
739
      case '\r': return(curchoice); /* ENTER */
-
 
740
      case 0x150: /* down */
-
 
741
        if (curchoice == MENU_QUIT) {
-
 
742
          curchoice = MENU_NEW;
-
 
743
        } else {
-
 
744
          curchoice++;
-
 
745
        }
-
 
746
        break;
-
 
747
      case 0x148: /* up */
-
 
748
        if (curchoice == MENU_NEW) {
-
 
749
          curchoice = MENU_QUIT;
-
 
750
        } else {
-
 
751
          curchoice--;
-
 
752
        }
-
 
753
        break;
-
 
754
      default: return(MENU_NONE);
-
 
755
    }
-
 
756
  }
-
 
757
}
-
 
758
 
-
 
759
 
712
/* main returns nothing, ie. sved always exits with a zero exit code
760
/* main returns nothing, ie. sved always exits with a zero exit code
713
 * (this saves 20 bytes of executable footprint) */
761
 * (this saves 20 bytes of executable footprint) */
714
void main(void) {
762
void main(void) {
715
  static struct file dbarr[1];
763
  static struct file dbarr[12];
716
  const char *fname;
764
  const char *fname;
717
  struct file *db = dbarr;
765
  struct file *db = dbarr;
718
 
766
 
719
  {
767
  {
720
    char nlspath[128], lang[8];
768
    char nlspath[128], lang[8];
Line 741... Line 789...
741
  }
789
  }
742
 
790
 
743
  if (mdr_cout_init(&screenw, &screenh)) {
791
  if (mdr_cout_init(&screenw, &screenh)) {
744
    /* load color scheme if mdr_cout_init returns a color flag */
792
    /* load color scheme if mdr_cout_init returns a color flag */
745
    SCHEME_TEXT = 0x17;
793
    SCHEME_TEXT = 0x17;
-
 
794
    SCHEME_MENU = 0x70;
-
 
795
    SCHEME_MENU_CUR = 0x2f;
-
 
796
    SCHEME_MENU_SEL = 0x22;
746
    SCHEME_STBAR1 = 0x70;
797
    SCHEME_STBAR1 = 0x70;
747
    SCHEME_STBAR2 = 0x78;
798
    SCHEME_STBAR2 = 0x78;
748
    SCHEME_STBAR3 = 0xf0;
799
    SCHEME_STBAR3 = 0xf0;
749
    SCHEME_SCROLL = 0x70;
800
    SCHEME_SCROLL = 0x70;
750
    SCHEME_MSG = 0xf0;
801
    SCHEME_MSG = 0xf0;
Line 836... Line 887...
836
 
887
 
837
    } else if (k == 0x14F) { /* end */
888
    } else if (k == 0x14F) { /* end */
838
       cursor_eol(db);
889
       cursor_eol(db);
839
 
890
 
840
    } else if (k == 0x1B) { /* ESC */
891
    } else if (k == 0x1B) { /* ESC */
-
 
892
      int quitnow = 0;
-
 
893
      char fname[25];
-
 
894
      int saveflag = 0;
-
 
895
 
-
 
896
      switch (ui_menu()) {
-
 
897
 
-
 
898
        case MENU_NONE:
-
 
899
          break;
-
 
900
 
-
 
901
        case MENU_NEW:
841
      if (ui_confirm_if_unsaved(db) == 0) break;
902
          if (ui_confirm_if_unsaved(db) == 0) {
-
 
903
            clear_file(db);
-
 
904
            /* add a single empty line */
-
 
905
            line_add(db, NULL, 0);
-
 
906
          }
-
 
907
          uidirty.statusbar = 1;
-
 
908
          break;
-
 
909
 
-
 
910
        case MENU_OPEN:
-
 
911
          /* display a warning if unsaved changes are pending */
-
 
912
          if (db->modflag != 0) ui_msg(svarlang_str(0,4), svarlang_str(0,8), SCHEME_MSG);
-
 
913
 
-
 
914
          /* ask for filename */
-
 
915
          ui_getstring(svarlang_str(0,7), fname, sizeof(fname));
-
 
916
          if (fname[0] != 0) {
-
 
917
            unsigned char err;
-
 
918
            clear_file(db);
-
 
919
            err = loadfile(db, fname);
-
 
920
            if (err != 0) {
-
 
921
              if (err == 1) {
-
 
922
                ui_msg(svarlang_str(0,11), NULL, SCHEME_ERR); /* file not found */
-
 
923
              } else {
-
 
924
                ui_msg(svarlang_str(0,10), NULL, SCHEME_ERR);  /* ERROR */
-
 
925
              }
-
 
926
              mdr_bios_tickswait(44); /* 3s */
-
 
927
              clear_file(db);
-
 
928
            }
-
 
929
          }
-
 
930
          break;
-
 
931
 
-
 
932
        case MENU_SAVEAS:
-
 
933
          saveflag = 1;
-
 
934
          /* FALLTHRU */
-
 
935
        case MENU_SAVE:
-
 
936
          if ((saveflag != 0) || (db->fname[0] == 0)) { /* save as... */
-
 
937
            ui_getstring(svarlang_str(0,6), fname, sizeof(fname));
-
 
938
            if (*fname == 0) break;
-
 
939
            saveflag = savefile(db, fname);
-
 
940
            if (saveflag == 0) memcpy(db->fname, fname, sizeof(fname));
-
 
941
          } else {
-
 
942
            saveflag = savefile(db, NULL);
-
 
943
          }
-
 
944
 
-
 
945
          if (saveflag == 0) {
-
 
946
            db->modflag = 0;
-
 
947
            ui_msg(svarlang_str(0, 2), NULL, SCHEME_MSG);
-
 
948
            mdr_bios_tickswait(11); /* 11 ticks is about 600 ms */
-
 
949
          } else {
-
 
950
            ui_msg(svarlang_str(0, 3), NULL, SCHEME_ERR);
-
 
951
            mdr_bios_tickswait(36); /* 2s */
-
 
952
          }
-
 
953
          break;
-
 
954
 
-
 
955
        case MENU_CHGEOL:
-
 
956
          db->modflag = '*';
-
 
957
          db->lfonly ^= 1;
-
 
958
          break;
-
 
959
 
-
 
960
        case MENU_QUIT:
-
 
961
          if (ui_confirm_if_unsaved(db) == 0) quitnow = 1;
-
 
962
          break;
-
 
963
      }
-
 
964
 
-
 
965
      if (quitnow) break;
842
 
966
 
843
    } else if (k == 0x0D) { /* ENTER */
967
    } else if (k == 0x0D) { /* ENTER */
844
      unsigned short off = db->xoffset + db->cursorposx;
968
      unsigned short off = db->xoffset + db->cursorposx;
845
      /* add a new line */
969
      /* add a new line */
846
      if (line_add(db, db->cursor->payload + off, db->cursor->len - off) == 0) {
970
      if (line_add(db, db->cursor->payload + off, db->cursor->len - off) == 0) {
Line 869... Line 993...
869
      insert_in_line(db, &c, 1);
993
      insert_in_line(db, &c, 1);
870
 
994
 
871
    } else if (k == 0x009) { /* TAB */
995
    } else if (k == 0x009) { /* TAB */
872
      insert_in_line(db, "        ", 8);
996
      insert_in_line(db, "        ", 8);
873
 
997
 
874
    } else if (k == 0x13b) { /* F1 */
998
    } else if ((k >= 0x13b) && (k <= 0x146)) { /* F1..F12 */
875
      ui_help();
-
 
876
      uidirty.from = 0;
-
 
877
      uidirty.to = 0xff;
-
 
878
 
-
 
879
    } else if (k == 0x13c) { /* F2 (new file) */
-
 
880
      if (ui_confirm_if_unsaved(db) == 0) {
-
 
881
        clear_file(db);
-
 
882
        /* add a single empty line */
-
 
883
        line_add(db, NULL, 0);
-
 
884
      }
-
 
885
      uidirty.from = 0;
999
      uidirty.from = 0;
886
      uidirty.to = 0xff;
1000
      uidirty.to = 0xff;
887
      uidirty.statusbar = 1;
-
 
888
 
-
 
889
    } else if (k == 0x13d) { /* F3 (load file) */
-
 
890
      char fname[25];
-
 
891
 
-
 
892
      /* display a warning if unsaved changes are pending */
-
 
893
      if (db->modflag != 0) ui_msg(svarlang_str(0,4), svarlang_str(0,8), SCHEME_MSG);
-
 
894
 
-
 
895
      /* ask for filename */
-
 
896
      ui_getstring(svarlang_str(0,7), fname, sizeof(fname));
-
 
897
      if (fname[0] != 0) {
-
 
898
        unsigned char err;
-
 
899
        clear_file(db);
-
 
900
        err = loadfile(db, fname);
-
 
901
        if (err != 0) {
-
 
902
          if (err == 1) {
-
 
903
            ui_msg(svarlang_str(0,11), NULL, SCHEME_ERR); /* file not found */
-
 
904
          } else {
-
 
905
            ui_msg(svarlang_str(0,10), NULL, SCHEME_ERR);  /* ERROR */
-
 
906
          }
-
 
907
          mdr_bios_tickswait(44); /* 3s */
-
 
908
          clear_file(db);
-
 
909
        }
-
 
910
      }
-
 
911
      uidirty.from = 0;
-
 
912
      uidirty.to = 0xff;
-
 
913
      uidirty.statusbar = 1;
-
 
914
 
-
 
915
    } else if ((k == 0x13f) || (k == 0x140)) { /* F5 or F6 */
-
 
916
      int saveres;
-
 
917
 
-
 
918
      if ((k == 0x140) || (db->fname[0] == 0)) { /* save as... */
-
 
919
        char fname[25];
-
 
920
        ui_getstring(svarlang_str(0,6), fname, sizeof(fname));
-
 
921
        if (*fname == 0) continue;
-
 
922
        saveres = savefile(db, fname);
-
 
923
        if (saveres == 0) memcpy(db->fname, fname, sizeof(fname));
-
 
924
      } else {
-
 
925
        saveres = savefile(db, NULL);
-
 
926
      }
-
 
927
 
-
 
928
      if (saveres == 0) {
-
 
929
        db->modflag = 0;
-
 
930
        ui_msg(svarlang_str(0, 2), NULL, SCHEME_MSG);
-
 
931
        mdr_bios_tickswait(11); /* 11 ticks is about 600 ms */
-
 
932
      } else {
-
 
933
        ui_msg(svarlang_str(0, 3), NULL, SCHEME_ERR);
-
 
934
        mdr_bios_tickswait(36); /* 2s */
-
 
935
      }
-
 
936
 
-
 
937
      ui_refresh(db);
-
 
938
      uidirty.statusbar = 1;
-
 
939
 
-
 
940
    } else if (k == 0x144) { /* F10 */
-
 
941
      db->modflag = '*';
-
 
942
      db->lfonly ^= 1;
-
 
943
      uidirty.statusbar = 1;
-
 
944
      uidirty.from = 0;
-
 
945
      uidirty.to = 0;
-
 
946
 
1001
 
947
    } else if (k == 0x174) { /* CTRL+ArrRight - jump to next word */
1002
    } else if (k == 0x174) { /* CTRL+ArrRight - jump to next word */
948
      /* if currently cursor is on a non-space, then fast-forward to nearest space or EOL */
1003
      /* if currently cursor is on a non-space, then fast-forward to nearest space or EOL */
949
      for (;;) {
1004
      for (;;) {
950
        if (db->xoffset + db->cursorposx == db->cursor->len) break;
1005
        if (db->xoffset + db->cursorposx == db->cursor->len) break;