Subversion Repositories SvarDOS

Rev

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

Rev 1665 Rev 1666
Line 161... Line 161...
161
  if (fd2 != NULL) fclose(fd2);
161
  if (fd2 != NULL) fclose(fd2);
162
  return(res);
162
  return(res);
163
}
163
}
164
 
164
 
165
 
165
 
-
 
166
/* display a menu with items and return user's choice.
-
 
167
 * ypos: starting line where the menu is drawn
-
 
168
 * height: number of items to display inside the menu
-
 
169
 * list: NULL-terminated list of items
-
 
170
 * maxlistlen: limit list to this many items tops */
166
static int menuselect(unsigned char ypos, unsigned char height, const char **list, int maxlistlen) {
171
static int menuselect(unsigned char ypos, unsigned char height, const char **list, int maxlistlen) {
167
  int i, offset = 0, res = 0, count;
172
  int i, offset = 0, res = 0, count;
168
  unsigned char y, xpos, width = 0;
173
  unsigned char y, xpos, width = 0;
169
 
174
 
170
  /* count how many positions there is, and check their width */
175
  /* count how many positions there are, and check their width */
171
  for (count = 0; (list[count] != NULL) && (count != maxlistlen); count++) {
176
  for (count = 0; (list[count] != NULL) && (count != maxlistlen); count++) {
172
    int len = strlen(list[count]);
177
    int len = strlen(list[count]);
173
    if (len > width) width = len;
178
    if (len > width) width = len;
174
  }
179
  }
-
 
180
  width++; /* it's nice to have a small margin to the right of the widest item */
175
 
181
 
176
  /* if xpos negative, means 'center out' */
182
  /* if xpos negative, means 'center out' */
177
  xpos = 39 - (width >> 1);
183
  xpos = 39 - (width >> 1);
178
 
184
 
-
 
185
  mdr_cout_char_rep(ypos, xpos, 0xC4, COLOR_SELECT, width + 2);  /* top line */
179
  mdr_cout_char(ypos, xpos+width+2, 0xBF, COLOR_SELECT);         /*       \ */
186
  mdr_cout_char(ypos, xpos+width+2, 0xBF, COLOR_SELECT);         /*       \ */
180
  mdr_cout_char(ypos, xpos-1, 0xDA, COLOR_SELECT);               /*  /      */
187
  mdr_cout_char(ypos, xpos-1, 0xDA, COLOR_SELECT);               /*  /      */
181
  mdr_cout_char(ypos+height-1, xpos-1, 0xC0, COLOR_SELECT);      /*  \      */
188
  ypos++; /* from now on ypos relates to the position of the content */
182
  mdr_cout_char(ypos+height-1, xpos+width+2, 0xD9, COLOR_SELECT);/*      /  */
189
  mdr_cout_char(ypos+height, xpos-1, 0xC0, COLOR_SELECT);      /*  \      */
183
  mdr_cout_char_rep(ypos, xpos, 0xC4, COLOR_SELECT, width + 2);
190
  mdr_cout_char(ypos+height, xpos+width+2, 0xD9, COLOR_SELECT);/*      /  */
184
  mdr_cout_char_rep(ypos+height-1, xpos, 0xC4, COLOR_SELECT, width + 2);
191
  mdr_cout_char_rep(ypos+height, xpos, 0xC4, COLOR_SELECT, width + 2);
185
 
-
 
186
  for (y = ypos + 1; y < (ypos + height - 1); y++) {
-
 
187
    mdr_cout_char(y, xpos-1, 0xB3, COLOR_SELECT);
-
 
188
    mdr_cout_char(y, xpos+width+2, 0xB3, COLOR_SELECT);
-
 
189
  }
-
 
190
 
192
 
191
  for (;;) {
193
  for (;;) {
192
    int key;
194
    int key;
-
 
195
 
-
 
196
    /* draw side borders of the menu + the cursor */
-
 
197
    if (count <= height) { /* no need for a cursor, all fits on one page */
-
 
198
      i = 255;
-
 
199
    } else {
-
 
200
      i = offset * (height - 1) / (count - height);
-
 
201
    }
-
 
202
    mdr_cout_char(0, 0, '0' + (i / 10), COLOR_SELECT);
-
 
203
    mdr_cout_char(0, 1, '0' + (i % 10), COLOR_SELECT);
-
 
204
 
-
 
205
    for (y = ypos; y < (ypos + height); y++) {
-
 
206
      mdr_cout_char(y, xpos-1, 0xB3, COLOR_SELECT); /* left side */
-
 
207
      if (y - ypos == i) {
-
 
208
        mdr_cout_char(y, xpos+width+2, '@', COLOR_SELECT); /* cursor */
-
 
209
      } else {
-
 
210
        mdr_cout_char(y, xpos+width+2, 0xB3, COLOR_SELECT); /* right side */
-
 
211
      }
-
 
212
    }
-
 
213
 
193
    /* list of selectable items */
214
    /* list of selectable items */
194
    for (i = 0; i < height - 2; i++) {
215
    for (i = 0; i < height; i++) {
195
      if (i + offset == res) {
216
      if (i + offset == res) {
196
        mdr_cout_char(ypos + 1 + i, xpos, 16, COLOR_SELECTCUR);
217
        mdr_cout_char(ypos + i, xpos, 16, COLOR_SELECTCUR);
197
        mdr_cout_char(ypos + 1 + i, xpos+width+1, 17, COLOR_SELECTCUR);
218
        mdr_cout_char(ypos + i, xpos+width+1, 17, COLOR_SELECTCUR);
198
        mdr_cout_locate(ypos + 1 + i, xpos);
219
        mdr_cout_locate(ypos + i, xpos);
199
        video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECTCUR, list[i + offset], width);
220
        video_putstringfix(ypos + i, xpos+1, COLOR_SELECTCUR, list[i + offset], width);
200
      } else if (i + offset < count) {
221
      } else if (i + offset < count) {
201
        mdr_cout_char(ypos + 1 + i, xpos, ' ', COLOR_SELECT);
222
        mdr_cout_char(ypos + i, xpos, ' ', COLOR_SELECT);
202
        mdr_cout_char(ypos + 1 + i, xpos+width+1, ' ', COLOR_SELECT);
223
        mdr_cout_char(ypos + i, xpos+width+1, ' ', COLOR_SELECT);
203
        video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECT, list[i + offset], width);
224
        video_putstringfix(ypos + i, xpos+1, COLOR_SELECT, list[i + offset], width);
204
      } else {
225
      } else {
205
        mdr_cout_char_rep(ypos + 1 + i, xpos, ' ', COLOR_SELECT, width+2);
226
        mdr_cout_char_rep(ypos + i, xpos, ' ', COLOR_SELECT, width+2);
206
      }
227
      }
207
    }
228
    }
208
    key = mdr_dos_getkey();
229
    key = mdr_dos_getkey();
209
    if (key == 0x0D) { /* ENTER */
230
    if (key == 0x0D) { /* ENTER */
210
      return(res);
231
      return(res);
Line 214... Line 235...
214
        if (res < offset) offset = res;
235
        if (res < offset) offset = res;
215
      }
236
      }
216
    } else if (key == 0x150) { /* down */
237
    } else if (key == 0x150) { /* down */
217
      if (res+1 < count) {
238
      if (res+1 < count) {
218
        res++;
239
        res++;
219
        if (res > offset + height - 3) offset = res - (height - 3);
240
        if (res > offset + height - 1) offset = res - (height - 1);
220
      }
241
      }
221
    } else if (key == 0x147) { /* home */
242
    } else if (key == 0x147) { /* home */
222
      res = 0;
243
      res = 0;
223
      offset = 0;
244
      offset = 0;
224
    } else if (key == 0x14F) { /* end */
245
    } else if (key == 0x14F) { /* end */
225
      res = count - 1;
246
      res = count - 1;
226
      if (res > offset + height - 3) offset = res - (height - 3);
247
      if (res > offset + height - 1) offset = res - (height - 1);
227
    } else if (key == 0x1B) {  /* ESC */
248
    } else if (key == 0x1B) {  /* ESC */
228
      return(-1);
249
      return(-1);
229
    }/* else {
250
    }/* else {
230
      char buf[8];
251
      char buf[8];
231
      snprintf(buf, sizeof(buf), "0x%02X ", key);
252
      snprintf(buf, sizeof(buf), "0x%02X ", key);
Line 303... Line 324...
303
    putstringwrap(8, 1, COLOR_BODY, msg);
324
    putstringwrap(8, 1, COLOR_BODY, msg);
304
  } else {
325
  } else {
305
    mdr_cout_str(8, 40 - (strlen(msg) / 2), msg, COLOR_BODY, 80);
326
    mdr_cout_str(8, 40 - (strlen(msg) / 2), msg, COLOR_BODY, 80);
306
  }
327
  }
307
 
328
 
308
  choice = menuselect(11, 11, langlist, -1);
329
  choice = menuselect(11, 9, langlist, -1);
309
  if (choice < 0) return(MENUPREV);
330
  if (choice < 0) return(MENUPREV);
310
  /* populate locales with default values */
331
  /* populate locales with default values */
311
  memset(locales, 0, sizeof(struct slocales));
332
  memset(locales, 0, sizeof(struct slocales));
312
  switch (choice) {
333
  switch (choice) {
313
    case 1:
334
    case 1:
Line 371... Line 392...
371
static int selectkeyb(struct slocales *locales) {
392
static int selectkeyb(struct slocales *locales) {
372
  int menuheight, choice;
393
  int menuheight, choice;
373
  if (locales->keyblen == 1) return(MENUNEXT); /* do not ask for keyboard layout if only one is available for given language */
394
  if (locales->keyblen == 1) return(MENUNEXT); /* do not ask for keyboard layout if only one is available for given language */
374
  newscreen(0);
395
  newscreen(0);
375
  putstringnls(5, 1, COLOR_BODY, 1, 5); /* "SvarDOS supports different keyboard layouts */
396
  putstringnls(5, 1, COLOR_BODY, 1, 5); /* "SvarDOS supports different keyboard layouts */
376
  menuheight = locales->keyblen + 2;
397
  menuheight = locales->keyblen;
377
  if (menuheight > 13) menuheight = 13;
398
  if (menuheight > 11) menuheight = 11;
378
  choice = menuselect(10, menuheight, &(kblayouts[locales->keyboff]), locales->keyblen);
399
  choice = menuselect(10, menuheight, &(kblayouts[locales->keyboff]), locales->keyblen);
379
  if (choice < 0) return(MENUPREV);
400
  if (choice < 0) return(MENUPREV);
380
  /* (re)load the keyboard layout & codepage setup */
401
  /* (re)load the keyboard layout & codepage setup */
381
  locales->keyboff += choice;
402
  locales->keyboff += choice;
382
  kblay2slocal(locales);
403
  kblay2slocal(locales);
Line 391... Line 412...
391
  choice[0] = svarlang_strid(0x0001);
412
  choice[0] = svarlang_strid(0x0001);
392
  choice[1] = svarlang_strid(0x0002);
413
  choice[1] = svarlang_strid(0x0002);
393
  choice[2] = NULL;
414
  choice[2] = NULL;
394
  newscreen(0);
415
  newscreen(0);
395
  putstringnls(4, 1, COLOR_BODY, 2, 0); /* "You are about to install SvarDOS */
416
  putstringnls(4, 1, COLOR_BODY, 2, 0); /* "You are about to install SvarDOS */
396
  c = menuselect(13, 4, choice, -1);
417
  c = menuselect(13, 2, choice, -1);
397
  if (c < 0) return(MENUPREV);
418
  if (c < 0) return(MENUPREV);
398
  if (c == 0) return(MENUNEXT);
419
  if (c == 0) return(MENUNEXT);
399
  return(MENUQUIT);
420
  return(MENUQUIT);
400
}
421
}
401
 
422
 
Line 545... Line 566...
545
      list[0] = svarlang_str(0, 3); /* Create a partition automatically */
566
      list[0] = svarlang_str(0, 3); /* Create a partition automatically */
546
      list[1] = svarlang_str(0, 4); /* Run the FDISK tool */
567
      list[1] = svarlang_str(0, 4); /* Run the FDISK tool */
547
      list[2] = svarlang_str(0, 2); /* Quit to DOS */
568
      list[2] = svarlang_str(0, 2); /* Quit to DOS */
548
      list[3] = NULL;
569
      list[3] = NULL;
549
      snprintf(buff, sizeof(buff), svarlang_strid(0x0300), cselecteddrive, SVARDOS_DISK_REQ); /* "ERROR: Drive %c: could not be found. Note, that SvarDOS requires at least %d MiB of available disk space */
570
      snprintf(buff, sizeof(buff), svarlang_strid(0x0300), cselecteddrive, SVARDOS_DISK_REQ); /* "ERROR: Drive %c: could not be found. Note, that SvarDOS requires at least %d MiB of available disk space */
550
      switch (menuselect(6 + putstringwrap(4, 1, COLOR_BODY, buff), 5, list, -1)) {
571
      switch (menuselect(6 + putstringwrap(4, 1, COLOR_BODY, buff), 3, list, -1)) {
551
        case 0:
572
        case 0:
552
          sprintf(buff, "FDISK /PRI:MAX %d", driveid);
573
          sprintf(buff, "FDISK /PRI:MAX %d", driveid);
553
          system(buff);
574
          system(buff);
554
          break;
575
          break;
555
        case 1:
576
        case 1:
Line 590... Line 611...
590
      snprintf(buff, sizeof(buff), svarlang_strid(0x0007), cselecteddrive); /* "Format drive %c:" */
611
      snprintf(buff, sizeof(buff), svarlang_strid(0x0007), cselecteddrive); /* "Format drive %c:" */
591
      list[0] = buff;
612
      list[0] = buff;
592
      list[1] = svarlang_strid(0x0002); /* "Quit to DOS" */
613
      list[1] = svarlang_strid(0x0002); /* "Quit to DOS" */
593
      list[2] = NULL;
614
      list[2] = NULL;
594
 
615
 
595
      choice = menuselect(12, 4, list, -1);
616
      choice = menuselect(12, 2, list, -1);
596
      if (choice < 0) return(MENUPREV);
617
      if (choice < 0) return(MENUPREV);
597
      if (choice == 1) return(MENUQUIT);
618
      if (choice == 1) return(MENUQUIT);
598
      mdr_cout_cls(0x07);
619
      mdr_cout_cls(0x07);
599
      mdr_cout_locate(0, 0);
620
      mdr_cout_locate(0, 0);
600
      snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
621
      snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
Line 623... Line 644...
623
      snprintf(buff, sizeof(buff), svarlang_strid(0x0007), cselecteddrive); /* "Format drive %c:" */
644
      snprintf(buff, sizeof(buff), svarlang_strid(0x0007), cselecteddrive); /* "Format drive %c:" */
624
      list[0] = buff;
645
      list[0] = buff;
625
      list[1] = svarlang_strid(0x0002); /* "Quit to DOS" */
646
      list[1] = svarlang_strid(0x0002); /* "Quit to DOS" */
626
      list[2] = NULL;
647
      list[2] = NULL;
627
 
648
 
628
      choice = menuselect(++y, 4, list, -1);
649
      choice = menuselect(++y, 2, list, -1);
629
      if (choice < 0) return(MENUPREV);
650
      if (choice < 0) return(MENUPREV);
630
      if (choice == 1) return(MENUQUIT);
651
      if (choice == 1) return(MENUQUIT);
631
      mdr_cout_cls(0x07);
652
      mdr_cout_cls(0x07);
632
      mdr_cout_locate(0, 0);
653
      mdr_cout_locate(0, 0);
633
      snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
654
      snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
Line 639... Line 660...
639
      list[0] = svarlang_strid(0x0001); /* Install SvarDOS */
660
      list[0] = svarlang_strid(0x0001); /* Install SvarDOS */
640
      list[1] = svarlang_strid(0x0002); /* Quit to DOS */
661
      list[1] = svarlang_strid(0x0002); /* Quit to DOS */
641
      list[2] = NULL;
662
      list[2] = NULL;
642
      snprintf(buff, sizeof(buff), svarlang_strid(0x0306), cselecteddrive); /* "The installation of SvarDOS to %c: is about to begin." */
663
      snprintf(buff, sizeof(buff), svarlang_strid(0x0306), cselecteddrive); /* "The installation of SvarDOS to %c: is about to begin." */
643
      mdr_cout_str(7, 40 - strlen(buff), buff, COLOR_BODY, 80);
664
      mdr_cout_str(7, 40 - strlen(buff), buff, COLOR_BODY, 80);
644
      choice = menuselect(10, 4, list, -1);
665
      choice = menuselect(10, 2, list, -1);
645
      if (choice < 0) return(MENUPREV);
666
      if (choice < 0) return(MENUPREV);
646
      if (choice == 1) return(MENUQUIT);
667
      if (choice == 1) return(MENUQUIT);
647
      snprintf(buff, sizeof(buff), "SYS %c: %c: > NUL", sourcedrv, cselecteddrive);
668
      snprintf(buff, sizeof(buff), "SYS %c: %c: > NUL", sourcedrv, cselecteddrive);
648
      system(buff);
669
      system(buff);
649
      sprintf(buff, "FDISK /MBR %d", driveid);
670
      sprintf(buff, "FDISK /MBR %d", driveid);