]> git.ozlabs.org Git - yaboot.git/blob - second/cmdline.c
Commit yaboot 1.3.6-pre2
[yaboot.git] / second / cmdline.c
1 /* Prompt handling
2    
3    Copyright (C) 1996 Maurizio Plaza
4                  1996 Jakub Jelinek
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #include "types.h"
21 #include "stdarg.h"
22 #include "prom.h"
23 #include "string.h"
24 #include "cfg.h"
25
26 #define CMD_LENG        512
27 char cbuff[CMD_LENG];
28 char passwdbuff[CMD_LENG];
29 extern int useconf;
30
31 void cmdinit()
32 {
33     cbuff[0] = 0;
34     passwdbuff[0] = 0;
35 }
36
37 void cmdedit (void (*tabfunc) (void), int password)
38 {
39      int x, c;
40      char *buff = password ? passwdbuff : cbuff;
41      for (x = 0; x < CMD_LENG - 1; x++) {
42           if (buff[x] == 0)
43                break;
44           else if (password)
45                prom_printf("*");
46      }
47      if (!password)
48           prom_printf(buff, x);
49      
50      for (;;) {
51           c = prom_getchar ();
52           if (c == -1)
53                break;
54           if (c == '\n' || c == '\r') {
55                break;
56           }
57           if (c == '\t' && !x && tabfunc)
58                (*tabfunc) ();
59           if (c == '\b' || c == 0x7F) {
60                if (x > 0) {
61                     --x;
62                     buff[x] = 0;
63                     prom_printf("\b \b");
64                }
65           } else if ((c & 0xE0) != 0) {
66                if (x < CMD_LENG - 1) {
67                     buff[x] = c;
68                     buff[x + 1] = 0;
69                     if (password)
70                          prom_printf("*");
71                     else
72                          prom_printf(buff + x);
73                     x++;
74                }
75                if (x == 1 && !password && useconf) {
76                     if (cfg_get_flag (cbuff, "single-key"))
77                          break;
78                }
79           }
80      }
81      buff[x] = 0;
82 }