~ubuntu-branches/ubuntu/quantal/silo/quantal

« back to all changes in this revision

Viewing changes to second/cmdline.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2007-10-25 09:28:08 UTC
  • mfrom: (15.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071025092808-1yhj12t7s4zqsfu5
Tags: 1.4.13a+git20070930-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build with -fno-stack-protector.
  - Change silo.postinst to automatically update the boot block without
    invoking siloconfig and keep asking questions on upgrades.
  - Convert silo.conf to use /dev/disk/by-uuid.
  - Ubuntu maintainer foobar.
  - Fix debian/rules call to dh_installdocs.
  - Drop the requirement of gcc-4.1 and start using default gcc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Prompt handling
 
2
   
 
3
   Copyright (C) 1996 Maurizio Plaza
 
4
                 1996 Jakub Jelinek
 
5
                 2001 Ben Collins
 
6
   
 
7
   This program is free software; you can redistribute it and/or modify
 
8
   it under the terms of the GNU General Public License as published by
 
9
   the Free Software Foundation; either version 2 of the License, or
 
10
   (at your option) any later version.
 
11
   
 
12
   This program is distributed in the hope that it will be useful,
 
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
   GNU General Public License for more details.
 
16
 
 
17
   You should have received a copy of the GNU General Public License
 
18
   along with this program; if not, write to the Free Software
 
19
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
20
   USA.  */
 
21
 
 
22
#include <silo.h>
 
23
#include <stringops.h>
 
24
 
 
25
char cbuff[CMD_LENG];
 
26
char passwdbuff[CMD_LENG];
 
27
extern int useconf;
 
28
extern int tab_ambiguous;
 
29
 
 
30
void silo_cmdinit(void)
 
31
{
 
32
    cbuff[0] = 0;
 
33
    passwdbuff[0] = 0;
 
34
}
 
35
 
 
36
void silo_cmdedit(void (*tabfunc)(void), int password)
 
37
{
 
38
    int x, c;
 
39
    char *buff = password ? passwdbuff : cbuff;
 
40
 
 
41
    for (x = 0; x < CMD_LENG - 1; x++) {
 
42
        if (buff[x] == 0)
 
43
            break;
 
44
        else if (password)
 
45
            prom_puts ("*", 1);
 
46
    }
 
47
    if (!password)
 
48
        prom_puts (buff, x);
 
49
 
 
50
    for (;;) {
 
51
        c = prom_getchar ();
 
52
        switch (c) {
 
53
            case -1:
 
54
            case '\n':
 
55
            case '\r':
 
56
                goto break_both;
 
57
 
 
58
            case '\t':
 
59
                if (tabfunc) (*tabfunc)();
 
60
                /* reset x */
 
61
                x = strlen(buff);
 
62
                break;
 
63
 
 
64
            case '\b':
 
65
            case 0x7F:
 
66
                tab_ambiguous = 0;
 
67
                if (x > 0) {
 
68
                    x--;
 
69
                    cbuff[x] = 0;
 
70
                    prom_puts ("\b \b", 3);
 
71
                }
 
72
                break;
 
73
 
 
74
            default:
 
75
                if ((c & 0xE0) != 0) {
 
76
                    tab_ambiguous = 0;
 
77
                    if (x < CMD_LENG - 1) {
 
78
                        buff[x] = c;
 
79
                        buff[x + 1] = 0;
 
80
                        /* For password input, we mask it out */
 
81
                        prom_puts((password) ? "*" : buff + x, 1);
 
82
                        x++;
 
83
                    }
 
84
                    if (x == 1 && !password && useconf) {
 
85
                        if (cfg_get_flag (cbuff, "single-key"))
 
86
                            goto break_both;
 
87
                    }
 
88
                }
 
89
        }
 
90
    }
 
91
break_both:
 
92
    buff[x] = 0;
 
93
}