More fixes to the extlinux installer; change back to writable types
[profile/ivi/syslinux.git] / parsecmd.inc
1 ;; $Id$
2 ;; -----------------------------------------------------------------------
3 ;;   
4 ;;   Copyright 1994-2002 H. Peter Anvin - All Rights Reserved
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, Inc., 53 Temple Place Ste 330,
9 ;;   Boston MA 02111-1307, USA; either version 2 of the License, or
10 ;;   (at your option) any later version; incorporated herein by reference.
11 ;;
12 ;; -----------------------------------------------------------------------
13
14 ;;
15 ;; parsecmd.inc
16 ;;
17 ;; Command line parser code
18 ;;
19
20                 section .text
21
22 ; -------------------------------------------------------------------------
23 ;  getcommand:  Get a keyword from the current "getc" file and match it
24 ;               against a list of keywords (keywd_table).  Each entry in
25 ;               that table should have the following form:
26 ;               <32 bit hash value> <16 bit handler offset>
27 ;
28 ;               The handler is called, and upon return this function
29 ;               returns with CF = 0.  On EOF, this function returns
30 ;               with CF = 1.
31 ; -------------------------------------------------------------------------
32
33 getcommand:
34 .find:
35                 call skipspace          ; Skip leading whitespace
36                 jz .eof                 ; End of file
37                 jc .find                ; End of line: try again
38                 cmp al,'0'              ; Skip comment line
39                 jb .skipline
40
41                 or al,20h               ; Convert to lower case
42                 movzx ebx,al            ; Hash for a one-char keyword
43 .read_loop:
44                 push ebx
45                 call getc
46                 pop ebx
47                 jc .eof
48                 cmp al,' '              ; Whitespace
49                 jbe .done
50                 or al,20h
51                 rol ebx,5
52                 xor bl,al
53                 jmp short .read_loop
54 .done:          call ungetc
55                 call skipspace
56                 jz .eof
57                 jc .noparm
58                 call ungetc             ; Return nonwhitespace char to buf
59                 mov si,keywd_table
60                 mov cx,keywd_count
61 .table_search:
62                 lodsd
63                 cmp ebx,eax
64                 je .found_keywd
65                 lodsd                   ; Skip entrypoint/argument
66                 loop .table_search
67
68                 ; Otherwise unrecognized keyword
69                 mov si,err_badcfg
70                 jmp short .error
71
72                 ; No parameter
73 .noparm:
74                 mov si,err_noparm
75 .error:
76                 call cwritestr
77                 jmp short .find
78
79 .found_keywd:   lodsw                   ; Load argument into ax
80                 call [si]
81                 clc
82                 ret
83
84 .eof:           stc
85                 ret
86
87 .skipline:      cmp al,10               ; Search for LF
88                 je .find
89                 call getc
90                 jc .eof
91                 jmp short .skipline
92
93                 section .bss
94                 alignb 4
95 vk_size         equ (vk_end + 3) & ~3
96 VKernelBuf:     resb vk_size            ; "Current" vkernel
97 AppendBuf       resb max_cmd_len+1      ; append=
98 Ontimeout       resb max_cmd_len+1      ; ontimeout
99 Onerror         resb max_cmd_len+1      ; onerror
100 KbdMap          resb 256                ; Keyboard map
101 FKeyName        resb 10*FILENAME_MAX    ; File names for F-key help
102 KernelCNameLen  resw 1                  ; Length of unmangled kernel name
103 InitRDCNameLen  resw 1                  ; Length of unmangled initrd name
104 %if IS_SYSLINUX
105 KernelName      resb FILENAME_MAX+1     ; Mangled name for kernel
106 KernelCName     resb FILENAME_MAX+2     ; Unmangled kernel name
107 InitRDCName     resb FILENAME_MAX+2     ; Unmangled initrd name
108 %else
109 KernelName      resb FILENAME_MAX       ; Mangled name for kernel
110 KernelCName     resb FILENAME_MAX       ; Unmangled kernel name
111 InitRDCName     resb FILENAME_MAX       ; Unmangled initrd name
112 %endif
113 MNameBuf        resb FILENAME_MAX
114 InitRD          resb FILENAME_MAX