Subversion Repositories HelenOS

Rev

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

Rev 3386 Rev 4263
Line 53... Line 53...
53
/* #include <fcntl.h> */
53
/* #include <fcntl.h> */
54
/* #include <pwd.h> */
54
/* #include <pwd.h> */
55
#include <stdio.h>
55
#include <stdio.h>
56
/* #include <stdlib.h> */
56
/* #include <stdlib.h> */
57
#include <string.h>
57
#include <string.h>
-
 
58
#include <kbd/kbd.h>
-
 
59
#include <kbd/keycode.h>
-
 
60
#include <stdlib.h>
58
/* #include <time.h> */
61
/* #include <time.h> */
59
/* #include <term.h> */
62
/* #include <term.h> */
60
/* #include <unistd.h> */
63
/* #include <unistd.h> */
61
/* #include <sys/param.h> */
64
/* #include <sys/param.h> */
62
/* #include <sys/stat.h> */
65
/* #include <sys/stat.h> */
Line 120... Line 123...
120
}
123
}
121
 
124
 
122
void insertscore(int score, int level)
125
void insertscore(int score, int level)
123
{
126
{
124
    int i,j;
127
    int i,j;
125
    int key;
128
    size_t off;
126
 
129
    kbd_event_t ev;
127
   
130
   
128
    clear_screen();
131
    clear_screen();
129
    moveto(10 , 10);
132
    moveto(10 , 10);
130
    puts("Insert your name: ");
133
    puts("Insert your name: ");
131
    strncpy(scores[NUMSPOTS - 1].hs_name, "Player", MAXLOGNAME);
134
    strncpy(scores[NUMSPOTS - 1].hs_name, "Player", MAXLOGNAME);
132
    i = 6;
135
    i = 6; off = 6;
133
 
136
 
134
    moveto(10 , 28);
137
    moveto(10 , 28);
135
    printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................");
138
    printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................");
-
 
139
 
-
 
140
    while (1) {
136
    key = getchar();   
141
        fflush(stdout);
-
 
142
        if (kbd_get_event(&ev) != EOK)
-
 
143
            exit(1);
-
 
144
 
137
    while(key != '\n') {
145
        if (ev.type == KE_RELEASE)
-
 
146
            continue;
-
 
147
 
-
 
148
        if (ev.key == KC_ENTER || ev.key == KC_NENTER)
-
 
149
            break;
-
 
150
 
138
        if (key == '\b') {
151
        if (ev.key == KC_BACKSPACE) {
139
            if (i > 0)
152
            if (i > 0) {
-
 
153
                wchar_t uc;
-
 
154
 
-
 
155
                --i;
-
 
156
                while (off > 0) {
-
 
157
                    --off;
-
 
158
                    size_t otmp = off;
-
 
159
                    uc = str_decode(scores[NUMSPOTS - 1].hs_name,
-
 
160
                        &otmp, STR_BOUNDS(MAXLOGNAME) + 1);
-
 
161
                    if (uc != U_SPECIAL)
-
 
162
                        break;
-
 
163
                }
-
 
164
 
140
                scores[NUMSPOTS - 1].hs_name[--i] = '\0';  
165
                scores[NUMSPOTS - 1].hs_name[off] = '\0';
-
 
166
            }
141
        } else {
167
        } else if (ev.c != '\0') {
142
            if (i < (MAXLOGNAME - 1))
168
            if (i < (MAXLOGNAME - 1)) {
143
                scores[NUMSPOTS - 1].hs_name[i++] = key;   
169
                if (chr_encode(ev.c, scores[NUMSPOTS - 1].hs_name,
-
 
170
                    &off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) {
-
 
171
                    ++i;
-
 
172
                }
144
                scores[NUMSPOTS - 1].hs_name[i] = '\0';
173
                scores[NUMSPOTS - 1].hs_name[off] = '\0';
-
 
174
            }
145
        }
175
        }
146
       
176
       
147
        moveto(10 , 28);
177
        moveto(10 , 28);
148
        printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................");
178
        printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................");
149
   
-
 
150
        key = getchar();   
-
 
151
    }
179
    }
152
   
180
   
153
    scores[NUMSPOTS - 1].hs_score = score; 
181
    scores[NUMSPOTS - 1].hs_score = score; 
154
    scores[NUMSPOTS - 1].hs_level = level;
182
    scores[NUMSPOTS - 1].hs_level = level;
155
   
183