diff options
author | Pierre-Alexandre Meyer <pierre@mouraf.org> | 2009-08-04 20:23:16 -0700 |
---|---|---|
committer | Pierre-Alexandre Meyer <pierre@mouraf.org> | 2009-08-04 21:01:32 -0700 |
commit | 0b19aba1d072ab3a2d9f528d7f0042dc8bc9e0ca (patch) | |
tree | eb93c4db28c463d98cf520e3235e7357f870c0e8 /com32/cmenu | |
parent | a6b80d3e8a356a55b4365c5e402e502843bbff8c (diff) | |
parent | 8e01231be41fd889bcb71604dbda511688ed0f38 (diff) | |
download | syslinux.git-0b19aba1d072ab3a2d9f528d7f0042dc8bc9e0ca.tar.gz syslinux.git-0b19aba1d072ab3a2d9f528d7f0042dc8bc9e0ca.tar.xz syslinux.git-0b19aba1d072ab3a2d9f528d7f0042dc8bc9e0ca.zip |
Merge commit 'hpa/master' into for-erwan
Conflicts:
com32/cmenu/libmenu/com32io.h
com32/gplinclude/dmi/dmi.h
com32/gplinclude/dmi/dmi_base_board.h
com32/gplinclude/dmi/dmi_memory.h
com32/gplinclude/dmi/dmi_system.h
com32/gpllib/dmi/dmi.c
com32/gpllib/dmi/dmi_memory.c
com32/include/sys/pci.h
com32/lib/pci/scan.c
com32/modules/Makefile
Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Diffstat (limited to 'com32/cmenu')
-rw-r--r-- | com32/cmenu/.gitignore | 2 | ||||
-rw-r--r-- | com32/cmenu/Makefile | 8 | ||||
-rw-r--r-- | com32/cmenu/complex.c | 674 | ||||
-rw-r--r-- | com32/cmenu/display.c | 17 | ||||
-rw-r--r-- | com32/cmenu/libmenu/com32io.c | 130 | ||||
-rw-r--r-- | com32/cmenu/libmenu/com32io.h | 59 | ||||
-rw-r--r-- | com32/cmenu/libmenu/des.c | 1614 | ||||
-rw-r--r-- | com32/cmenu/libmenu/des.h | 2 | ||||
-rw-r--r-- | com32/cmenu/libmenu/help.c | 321 | ||||
-rw-r--r-- | com32/cmenu/libmenu/help.h | 8 | ||||
-rw-r--r-- | com32/cmenu/libmenu/menu.c | 2052 | ||||
-rw-r--r-- | com32/cmenu/libmenu/menu.h | 250 | ||||
-rw-r--r-- | com32/cmenu/libmenu/passwords.c | 199 | ||||
-rw-r--r-- | com32/cmenu/libmenu/passwords.h | 16 | ||||
-rw-r--r-- | com32/cmenu/libmenu/scancodes.h | 2 | ||||
-rw-r--r-- | com32/cmenu/libmenu/syslnx.c | 101 | ||||
-rw-r--r-- | com32/cmenu/libmenu/syslnx.h | 8 | ||||
-rw-r--r-- | com32/cmenu/libmenu/tui.c | 550 | ||||
-rw-r--r-- | com32/cmenu/libmenu/tui.h | 27 | ||||
-rw-r--r-- | com32/cmenu/simple.c | 97 |
20 files changed, 3153 insertions, 2984 deletions
diff --git a/com32/cmenu/.gitignore b/com32/cmenu/.gitignore new file mode 100644 index 00000000..4add14ba --- /dev/null +++ b/com32/cmenu/.gitignore @@ -0,0 +1,2 @@ +test.c +test2.c diff --git a/com32/cmenu/Makefile b/com32/cmenu/Makefile index db896e52..0ede58dc 100644 --- a/com32/cmenu/Makefile +++ b/com32/cmenu/Makefile @@ -41,11 +41,11 @@ MENUS = $(CMENUS) $(IMENUS) .PRECIOUS: %.o %.o: %.S - $(CC) $(SFLAGS) -c -o $@ $< + $(CC) $(MAKEDEPS) $(SFLAGS) -c -o $@ $< .PRECIOUS: %.o %.o: %.c %.h - $(CC) $(CFLAGS) -c -o $@ $< + $(CC) $(MAKEDEPS) $(CFLAGS) -c -o $@ $< .PRECIOUS: %.elf %.elf: %.o libmenu/libmenu.a $(LIBS) @@ -62,7 +62,7 @@ libmenu/libmenu.a: $(LIBMENU) $(RANLIB) $@ tidy dist: - rm -f *.o *.lo *.a *.lst *.elf + rm -f *.o *.lo *.a *.lst *.elf .*.d */.*.d libclean: rm -f libmenu/*.o libmenu/*.a @@ -79,3 +79,5 @@ spotless: clean libclean menuclean menus: $(MENUS) install: # Don't install samples + +-include .*.d */.*.d diff --git a/com32/cmenu/complex.c b/com32/cmenu/complex.c index 94627c4f..063125d6 100644 --- a/com32/cmenu/complex.c +++ b/com32/cmenu/complex.c @@ -28,37 +28,36 @@ char buffer[80]; // Different network options static char nonet[] = "<n>etwork [none]"; -static char dhcpnet[]="<n>etwork [dhcp]"; -static char statnet[]="<n>etwork [static]"; +static char dhcpnet[] = "<n>etwork [dhcp]"; +static char statnet[] = "<n>etwork [static]"; static char loginstr[] = "<L>ogin "; -static char logoutstr[]= "<L>ogout "; +static char logoutstr[] = "<L>ogout "; struct { - unsigned int baseurl : 1; // Do we need to specify by url - unsigned int mountcd : 1; // Should we mount the cd - unsigned int winrep : 1; // Want to repair windows? - unsigned int linrep : 1; // Want to repair linux? + unsigned int baseurl:1; // Do we need to specify by url + unsigned int mountcd:1; // Should we mount the cd + unsigned int winrep:1; // Want to repair windows? + unsigned int linrep:1; // Want to repair linux? } flags; // Some menu options -t_menuitem *baseurl,*mountcd,*network,*runprep,*winrep,*linrep; -t_menuitem * stat,*dhcp,*none,*prepopt,*secret; +t_menuitem *baseurl, *mountcd, *network, *runprep, *winrep, *linrep; +t_menuitem *stat, *dhcp, *none, *prepopt, *secret; // all the menus we are going to declare -unsigned char TESTING,RESCUE,MAIN,PREPMENU,NETMENU,LONGMENU,SECRETMENU; +unsigned char TESTING, RESCUE, MAIN, PREPMENU, NETMENU, LONGMENU, SECRETMENU; -char username[12]; // Name of user currently using the system +char username[12]; // Name of user currently using the system /* End globals */ TIMEOUTCODE ontimeout() { - beep(); - return CODE_WAIT; + beep(); + return CODE_WAIT; } - #define INFLINE 22 #define PWDLINE 3 #define PWDPROMPT 21 @@ -66,163 +65,162 @@ TIMEOUTCODE ontimeout() #define PWDATTR 0x74 #define EDITPROMPT 21 -void keys_handler(t_menusystem *ms, t_menuitem *mi,unsigned int scancode) +void keys_handler(t_menusystem * ms, t_menuitem * mi, unsigned int scancode) { - char nc; - - if ((scancode >> 8) == F1) { // If scancode of F1 - runhelpsystem(mi->helpid); - } - // If user hit TAB, and item is an "executable" item - // and user has privileges to edit it, edit it in place. - if (((scancode & 0xFF) == 0x09) && (mi->action == OPT_RUN) && - (isallowed(username,"editcmd") || isallowed(username,"root"))) { - nc = getnumcols(); - // User typed TAB and has permissions to edit command line - gotoxy(EDITPROMPT,1,ms->menupage); - csprint("Command line:",0x07); - editstring(mi->data,ACTIONLEN); - gotoxy(EDITPROMPT,1,ms->menupage); - cprint(' ',0x07,nc-1,ms->menupage); - } + char nc; + + if ((scancode >> 8) == F1) { // If scancode of F1 + runhelpsystem(mi->helpid); + } + // If user hit TAB, and item is an "executable" item + // and user has privileges to edit it, edit it in place. + if (((scancode & 0xFF) == 0x09) && (mi->action == OPT_RUN) && + (isallowed(username, "editcmd") || isallowed(username, "root"))) { + nc = getnumcols(); + // User typed TAB and has permissions to edit command line + gotoxy(EDITPROMPT, 1, ms->menupage); + csprint("Command line:", 0x07); + editstring(mi->data, ACTIONLEN); + gotoxy(EDITPROMPT, 1, ms->menupage); + cprint(' ', 0x07, nc - 1, ms->menupage); + } } -t_handler_return login_handler(t_menusystem *ms, t_menuitem *mi) +t_handler_return login_handler(t_menusystem * ms, t_menuitem * mi) { - (void)mi; // Unused - char pwd[40]; - char login[40]; - char nc; - t_handler_return rv; - - if (mi->item == loginstr) { /* User wants to login */ - nc = getnumcols(); - gotoxy(PWDPROMPT,1,ms->menupage); - csprint("Enter Username: ",0x07); - getstring(login, sizeof username); - gotoxy(PWDPROMPT,1,ms->menupage); - cprint(' ',0x07,nc,ms->menupage); - csprint("Enter Password: ",0x07); - getpwd(pwd, sizeof pwd); - gotoxy(PWDPROMPT,1,ms->menupage); - cprint(' ',0x07,nc,ms->menupage); - - if (authenticate_user(login,pwd)) + (void)mi; // Unused + char pwd[40]; + char login[40]; + char nc; + t_handler_return rv; + + if (mi->item == loginstr) { /* User wants to login */ + nc = getnumcols(); + gotoxy(PWDPROMPT, 1, ms->menupage); + csprint("Enter Username: ", 0x07); + getstring(login, sizeof username); + gotoxy(PWDPROMPT, 1, ms->menupage); + cprint(' ', 0x07, nc, ms->menupage); + csprint("Enter Password: ", 0x07); + getpwd(pwd, sizeof pwd); + gotoxy(PWDPROMPT, 1, ms->menupage); + cprint(' ', 0x07, nc, ms->menupage); + + if (authenticate_user(login, pwd)) { + strcpy(username, login); + mi->item = logoutstr; // Change item to read "Logout" + } else + strcpy(username, GUEST_USER); + } else // User needs to logout { - strcpy(username,login); - mi->item = logoutstr; // Change item to read "Logout" + strcpy(username, GUEST_USER); + mi->item = loginstr; + } + + if (strcmp(username, GUEST_USER) == 0) { + prepopt->action = OPT_INACTIVE; + secret->action = OPT_INVISIBLE; + } else { + prepopt->action = OPT_SUBMENU; + prepopt->itemdata.radiomenunum = PREPMENU; + secret->action = OPT_SUBMENU; + secret->itemdata.submenunum = SECRETMENU; } - else strcpy(username,GUEST_USER); - } - else // User needs to logout - { - strcpy(username,GUEST_USER); - mi->item = loginstr; - } - - if (strcmp(username,GUEST_USER)==0) - { - prepopt->action = OPT_INACTIVE; - secret->action = OPT_INVISIBLE; - } - else - { - prepopt->action = OPT_SUBMENU; - prepopt->itemdata.radiomenunum = PREPMENU; - secret->action = OPT_SUBMENU; - secret->itemdata.submenunum = SECRETMENU; - } - rv.valid = 0; - rv.refresh = 1; - return rv; + rv.valid = 0; + rv.refresh = 1; + return rv; } -void msys_handler(t_menusystem *ms, t_menuitem *mi) +void msys_handler(t_menusystem * ms, t_menuitem * mi) { char nc; void *v; - nc = getnumcols(); // Get number of columns + nc = getnumcols(); // Get number of columns - gotoxy(PWDLINE,PWDCOLUMN,ms->menupage); - csprint("User: ",PWDATTR); - cprint(ms->fillchar,ms->fillattr,sizeof username,ms->menupage); - gotoxy(PWDLINE,PWDCOLUMN +6,ms->menupage); - csprint(username,PWDATTR); + gotoxy(PWDLINE, PWDCOLUMN, ms->menupage); + csprint("User: ", PWDATTR); + cprint(ms->fillchar, ms->fillattr, sizeof username, ms->menupage); + gotoxy(PWDLINE, PWDCOLUMN + 6, ms->menupage); + csprint(username, PWDATTR); - if (mi->parindex != PREPMENU) // If we are not in the PREP MENU + if (mi->parindex != PREPMENU) // If we are not in the PREP MENU { - gotoxy(INFLINE,0,ms->menupage); - cprint(' ',0x07,nc,ms->menupage); - gotoxy(INFLINE+1,0,ms->menupage); - cprint(' ',0x07,nc,ms->menupage); - return; + gotoxy(INFLINE, 0, ms->menupage); + cprint(' ', 0x07, nc, ms->menupage); + gotoxy(INFLINE + 1, 0, ms->menupage); + cprint(' ', 0x07, nc, ms->menupage); + return; } - strcpy (infoline," "); - if (flags.baseurl) strcat(infoline,"baseurl=http://192.168.11.12/gui "); - if (flags.mountcd) strcat(infoline,"mountcd=yes "); + strcpy(infoline, " "); + if (flags.baseurl) + strcat(infoline, "baseurl=http://192.168.11.12/gui "); + if (flags.mountcd) + strcat(infoline, "mountcd=yes "); v = (void *)network->data; - if (v!=NULL) // Some network option specified - { - strcat(infoline,"network="); - strcat(infoline,(char *)(((t_menuitem *)v)->data)); - } - if (flags.winrep) strcat(infoline,"repair=win "); - if (flags.linrep) strcat(infoline,"repair=lin "); - - gotoxy(INFLINE,0,ms->menupage); - cprint(' ',0x07,nc,ms->menupage); - gotoxy(INFLINE+1,0,ms->menupage); - cprint(' ',0x07,nc,ms->menupage); - gotoxy(INFLINE,0,ms->menupage); - csprint("Kernel Arguments:",0x07); - gotoxy(INFLINE,17,ms->menupage); - csprint(infoline,0x07); + if (v != NULL) // Some network option specified + { + strcat(infoline, "network="); + strcat(infoline, (char *)(((t_menuitem *) v)->data)); + } + if (flags.winrep) + strcat(infoline, "repair=win "); + if (flags.linrep) + strcat(infoline, "repair=lin "); + + gotoxy(INFLINE, 0, ms->menupage); + cprint(' ', 0x07, nc, ms->menupage); + gotoxy(INFLINE + 1, 0, ms->menupage); + cprint(' ', 0x07, nc, ms->menupage); + gotoxy(INFLINE, 0, ms->menupage); + csprint("Kernel Arguments:", 0x07); + gotoxy(INFLINE, 17, ms->menupage); + csprint(infoline, 0x07); } -t_handler_return network_handler(t_menusystem *ms, t_menuitem *mi) +t_handler_return network_handler(t_menusystem * ms, t_menuitem * mi) { - // mi=network since this is handler only for that. - (void)ms; // Unused - - if (mi->data == (void *)none) mi->item = nonet; - if (mi->data == (void *)stat) mi->item = statnet; - if (mi->data == (void *)dhcp) mi->item = dhcpnet; - return ACTION_INVALID; // VALID or INVALID does not matter + // mi=network since this is handler only for that. + (void)ms; // Unused + + if (mi->data == (void *)none) + mi->item = nonet; + if (mi->data == (void *)stat) + mi->item = statnet; + if (mi->data == (void *)dhcp) + mi->item = dhcpnet; + return ACTION_INVALID; // VALID or INVALID does not matter } -t_handler_return checkbox_handler(t_menusystem *ms, t_menuitem *mi) +t_handler_return checkbox_handler(t_menusystem * ms, t_menuitem * mi) { - (void)ms; /* Unused */ - - if (mi->action != OPT_CHECKBOX) return ACTION_INVALID; - - if (strcmp(mi->data,"baseurl") == 0) flags.baseurl = (mi->itemdata.checked ? 1 : 0); - if (strcmp(mi->data,"winrepair") == 0) { - if (mi->itemdata.checked) - { - flags.winrep = 1; - linrep->action = OPT_INACTIVE; - } - else - { - flags.winrep = 0; - linrep->action = OPT_CHECKBOX; - } + (void)ms; /* Unused */ + + if (mi->action != OPT_CHECKBOX) + return ACTION_INVALID; + + if (strcmp(mi->data, "baseurl") == 0) + flags.baseurl = (mi->itemdata.checked ? 1 : 0); + if (strcmp(mi->data, "winrepair") == 0) { + if (mi->itemdata.checked) { + flags.winrep = 1; + linrep->action = OPT_INACTIVE; + } else { + flags.winrep = 0; + linrep->action = OPT_CHECKBOX; + } } - if (strcmp(mi->data,"linrepair") == 0) { - if (mi->itemdata.checked) - { - flags.linrep = 1; - winrep->action = OPT_INACTIVE; - } - else - { - flags.winrep = 0; - winrep->action = OPT_CHECKBOX; - } + if (strcmp(mi->data, "linrepair") == 0) { + if (mi->itemdata.checked) { + flags.linrep = 1; + winrep->action = OPT_INACTIVE; + } else { + flags.winrep = 0; + winrep->action = OPT_CHECKBOX; + } } - if (strcmp(mi->data,"mountcd") == 0) flags.mountcd = (mi->itemdata.checked ? 1 : 0); - return ACTION_VALID; + if (strcmp(mi->data, "mountcd") == 0) + flags.mountcd = (mi->itemdata.checked ? 1 : 0); + return ACTION_VALID; } /* @@ -234,190 +232,214 @@ t_handler_return checkbox_handler(t_menusystem *ms, t_menuitem *mi) */ int checkkeypress(int stepsize, int numsteps) { - int i; - clearkbdbuf(); - for (i=0; i < numsteps; i++) - { - if (checkkbdbuf()) return 1; - sleep(stepsize); + int i; + clearkbdbuf(); + for (i = 0; i < numsteps; i++) { + if (checkkbdbuf()) + return 1; + sleep(stepsize); } - return 0; + return 0; } int main() { - t_menuitem * curr; - char cmd[160]; - char ip[30]; - - // Set default username as guest - strcpy(username,GUEST_USER); - - // Switch video mode here - // setvideomode(0x18); // or whatever mode you want - - // Choose the default title and setup default values for all attributes.... - init_passwords("/isolinux/password"); - init_help("/isolinux/help"); - init_menusystem(NULL); - set_window_size(1,1,20,78); // Leave some space around - - // Choose the default values for all attributes and char's - // -1 means choose defaults (Actually the next 4 lines are not needed) - //set_normal_attr (-1,-1,-1,-1); - //set_status_info (-1,-1); // Display status on the last line - //set_title_info (-1,-1); - //set_misc_info(-1,-1,-1,-1); - - // Register the menusystem handler - reg_handler(HDLR_SCREEN,&msys_handler); - reg_handler(HDLR_KEYS,&keys_handler); - // Register the ontimeout handler, with a time out of 10 seconds - reg_ontimeout(ontimeout,1000,0); - - NETMENU = add_menu(" Init Network ",-1); - none = add_item("<N>one","Dont start network",OPT_RADIOITEM,"no ",0); - dhcp = add_item("<d>hcp","Use DHCP",OPT_RADIOITEM,"dhcp ",0); - stat = add_item("<s>tatic","Use static IP I will specify later",OPT_RADIOITEM,"static ",0); - - TESTING = add_menu(" Testing ",-1); - set_menu_pos(5,55); - add_item("<M>emory Test","Perform extensive memory testing",OPT_RUN, "memtest",0); - add_item("<I>nvisible","You dont see this",OPT_INVISIBLE,"junk",0); - add_item("<E>xit this menu","Go one level up",OPT_EXITMENU,"exit",0); - - RESCUE = add_menu(" Rescue Options ",-1); - add_item("<L>inux Rescue","linresc",OPT_RUN,"linresc",0); - add_item("<D>os Rescue","dosresc",OPT_RUN,"dosresc",0); - add_item("<W>indows Rescue","winresc",OPT_RUN,"winresc",0); - add_item("<E>xit this menu","Go one level up",OPT_EXITMENU,"exit",0); - - PREPMENU = add_menu(" Prep options ",-1); - baseurl = add_item("<b>aseurl by IP?","Specify gui baseurl by IP address",OPT_CHECKBOX,"baseurl",0); - mountcd = add_item("<m>ountcd?","Mount the cdrom drive?",OPT_CHECKBOX,"mountcd",0); - network = add_item(dhcpnet,"How to initialise network device?",OPT_RADIOMENU,NULL,NETMENU); - add_sep(); - winrep = add_item("Reinstall <w>indows","Re-install the windows side of a dual boot setup",OPT_CHECKBOX,"winrepair",0); - linrep = add_item("Reinstall <l>inux","Re-install the linux side of a dual boot setup",OPT_CHECKBOX,"linrepair",0); - add_sep(); - runprep = add_item("<R>un prep now","Execute prep with the above options",OPT_RUN,"prep",0); - add_item("<E>xit this menu","Go up one level",OPT_EXITMENU,"exitmenu",0); - baseurl->handler = &checkbox_handler; - mountcd->handler = &checkbox_handler; - winrep->handler = &checkbox_handler; - linrep->handler = &checkbox_handler; - network->handler = &network_handler; - flags.baseurl = 0; - flags.mountcd = 0; - flags.winrep = 0; - flags.linrep = 0; - - SECRETMENU = add_menu(" Secret Menu ",-1); - add_item("secret 1","Secret",OPT_RUN,"A",0); - add_item("secret 2","Secret",OPT_RUN,"A",0); - - LONGMENU = add_menu(" Long Menu ",40); // Override default here - add_item("<A>a","Aa",OPT_RUN,"A",0); - add_item("<B>b","Ab",OPT_RUN,"A",0); - add_item("<C>","A",OPT_RUN,"A",0); - add_item("<D>","A",OPT_RUN,"A",0); - add_item("<E>","A",OPT_RUN,"A",0); - add_item("<F>","A",OPT_RUN,"A",0); - add_item("<G>","A",OPT_RUN,"A",0); - add_item("<H>","A",OPT_RUN,"A",0); - add_item("<I>","A",OPT_RUN,"A",0); - add_item("<J>","A",OPT_RUN,"A",0); - add_item("<K>","A",OPT_RUN,"A",0); - add_item("<L>","A",OPT_RUN,"A",0); - add_item("<J>","A",OPT_RUN,"A",0); - add_item("<K>","A",OPT_RUN,"A",0); - add_item("<L>","A",OPT_RUN,"A",0); - add_item("<M>","A",OPT_RUN,"A",0); - add_item("<N>","A",OPT_RUN,"A",0); - add_item("<O>","A",OPT_RUN,"A",0); - add_item("<P>","A",OPT_RUN,"A",0); - add_item("<Q>","A",OPT_RUN,"A",0); - add_item("<R>","A",OPT_RUN,"A",0); - add_item("<S>","A",OPT_RUN,"A",0); - add_item("<T>","A",OPT_RUN,"A",0); - add_item("<U>","A",OPT_RUN,"A",0); - add_item("<V>","A",OPT_RUN,"A",0); - add_item("<W>","A",OPT_RUN,"A",0); - add_item("<X>","A",OPT_RUN,"A",0); - add_item("<Y>","A",OPT_RUN,"A",0); - add_item("<Z>","A",OPT_RUN,"A",0); - add_item("<1>","A",OPT_RUN,"A",0); - add_item("<2>","A",OPT_RUN,"A",0); - add_item("<3>","A",OPT_RUN,"A",0); - add_item("<4>","A",OPT_RUN,"A",0); - add_item("<5>","A",OPT_RUN,"A",0); - add_item("<6>","A",OPT_RUN,"A",0); - add_item("<7>","A",OPT_RUN,"A",0); - add_item("<8>","A",OPT_RUN,"A",0); - add_item("<9>","A",OPT_RUN,"A",0); - - MAIN = add_menu(" Main Menu ",8); - curr = add_item(loginstr,"Login as a privileged user",OPT_RUN,NULL,0); - set_item_options(-1,23); - curr->handler = &login_handler; - - add_item("<P>repare","prep",OPT_RUN,"prep",0); - set_item_options(-1,24); - prepopt = add_item("<P>rep options...","Options for prep image: Requires authenticated user",OPT_INACTIVE,NULL,PREPMENU); - set_item_options(-1,25); - - add_item("<R>escue options...","Troubleshoot a system",OPT_SUBMENU,NULL,RESCUE); - set_item_options(-1,26); - add_item("<T>esting...","Options to test hardware",OPT_SUBMENU,NULL,TESTING); - set_item_options(-1,27); - add_item("<L>ong Menu...","test menu system",OPT_SUBMENU,NULL,LONGMENU); - set_item_options(-1,28); - secret = add_item("<S>ecret Menu...","Secret menu",OPT_INVISIBLE,NULL,SECRETMENU); - set_item_options(-1,29); - add_item("<E>xit to prompt", "Exit the menu system", OPT_EXITMENU, "exit", 0); - set_item_options(-1,30); - csprint("Press any key within 5 seconds to show menu...",0x07); - if (!checkkeypress(100,50)) // Granularity of 100 milliseconds + t_menuitem *curr; + char cmd[160]; + char ip[30]; + + // Set default username as guest + strcpy(username, GUEST_USER); + + // Switch video mode here + // setvideomode(0x18); // or whatever mode you want + + // Choose the default title and setup default values for all attributes.... + init_passwords("/isolinux/password"); + init_help("/isolinux/help"); + init_menusystem(NULL); + set_window_size(1, 1, 20, 78); // Leave some space around + + // Choose the default values for all attributes and char's + // -1 means choose defaults (Actually the next 4 lines are not needed) + //set_normal_attr (-1,-1,-1,-1); + //set_status_info (-1,-1); // Display status on the last line + //set_title_info (-1,-1); + //set_misc_info(-1,-1,-1,-1); + + // Register the menusystem handler + reg_handler(HDLR_SCREEN, &msys_handler); + reg_handler(HDLR_KEYS, &keys_handler); + // Register the ontimeout handler, with a time out of 10 seconds + reg_ontimeout(ontimeout, 1000, 0); + + NETMENU = add_menu(" Init Network ", -1); + none = add_item("<N>one", "Dont start network", OPT_RADIOITEM, "no ", 0); + dhcp = add_item("<d>hcp", "Use DHCP", OPT_RADIOITEM, "dhcp ", 0); + stat = + add_item("<s>tatic", "Use static IP I will specify later", + OPT_RADIOITEM, "static ", 0); + + TESTING = add_menu(" Testing ", -1); + set_menu_pos(5, 55); + add_item("<M>emory Test", "Perform extensive memory testing", OPT_RUN, + "memtest", 0); + add_item("<I>nvisible", "You dont see this", OPT_INVISIBLE, "junk", 0); + add_item("<E>xit this menu", "Go one level up", OPT_EXITMENU, "exit", 0); + + RESCUE = add_menu(" Rescue Options ", -1); + add_item("<L>inux Rescue", "linresc", OPT_RUN, "linresc", 0); + add_item("<D>os Rescue", "dosresc", OPT_RUN, "dosresc", 0); + add_item("<W>indows Rescue", "winresc", OPT_RUN, "winresc", 0); + add_item("<E>xit this menu", "Go one level up", OPT_EXITMENU, "exit", 0); + + PREPMENU = add_menu(" Prep options ", -1); + baseurl = + add_item("<b>aseurl by IP?", "Specify gui baseurl by IP address", + OPT_CHECKBOX, "baseurl", 0); + mountcd = + add_item("<m>ountcd?", "Mount the cdrom drive?", OPT_CHECKBOX, + "mountcd", 0); + network = + add_item(dhcpnet, "How to initialise network device?", OPT_RADIOMENU, + NULL, NETMENU); + add_sep(); + winrep = + add_item("Reinstall <w>indows", + "Re-install the windows side of a dual boot setup", + OPT_CHECKBOX, "winrepair", 0); + linrep = + add_item("Reinstall <l>inux", + "Re-install the linux side of a dual boot setup", OPT_CHECKBOX, + "linrepair", 0); + add_sep(); + runprep = + add_item("<R>un prep now", "Execute prep with the above options", + OPT_RUN, "prep", 0); + add_item("<E>xit this menu", "Go up one level", OPT_EXITMENU, "exitmenu", + 0); + baseurl->handler = &checkbox_handler; + mountcd->handler = &checkbox_handler; + winrep->handler = &checkbox_handler; + linrep->handler = &checkbox_handler; + network->handler = &network_handler; + flags.baseurl = 0; + flags.mountcd = 0; + flags.winrep = 0; + flags.linrep = 0; + + SECRETMENU = add_menu(" Secret Menu ", -1); + add_item("secret 1", "Secret", OPT_RUN, "A", 0); + add_item("secret 2", "Secret", OPT_RUN, "A", 0); + + LONGMENU = add_menu(" Long Menu ", 40); // Override default here + add_item("<A>a", "Aa", OPT_RUN, "A", 0); + add_item("<B>b", "Ab", OPT_RUN, "A", 0); + add_item("<C>", "A", OPT_RUN, "A", 0); + add_item("<D>", "A", OPT_RUN, "A", 0); + add_item("<E>", "A", OPT_RUN, "A", 0); + add_item("<F>", "A", OPT_RUN, "A", 0); + add_item("<G>", "A", OPT_RUN, "A", 0); + add_item("<H>", "A", OPT_RUN, "A", 0); + add_item("<I>", "A", OPT_RUN, "A", 0); + add_item("<J>", "A", OPT_RUN, "A", 0); + add_item("<K>", "A", OPT_RUN, "A", 0); + add_item("<L>", "A", OPT_RUN, "A", 0); + add_item("<J>", "A", OPT_RUN, "A", 0); + add_item("<K>", "A", OPT_RUN, "A", 0); + add_item("<L>", "A", OPT_RUN, "A", 0); + add_item("<M>", "A", OPT_RUN, "A", 0); + add_item("<N>", "A", OPT_RUN, "A", 0); + add_item("<O>", "A", OPT_RUN, "A", 0); + add_item("<P>", "A", OPT_RUN, "A", 0); + add_item("<Q>", "A", OPT_RUN, "A", 0); + add_item("<R>", "A", OPT_RUN, "A", 0); + add_item("<S>", "A", OPT_RUN, "A", 0); + add_item("<T>", "A", OPT_RUN, "A", 0); + add_item("<U>", "A", OPT_RUN, "A", 0); + add_item("<V>", "A", OPT_RUN, "A", 0); + add_item("<W>", "A", OPT_RUN, "A", 0); + add_item("<X>", "A", OPT_RUN, "A", 0); + add_item("<Y>", "A", OPT_RUN, "A", 0); + add_item("<Z>", "A", OPT_RUN, "A", 0); + add_item("<1>", "A", OPT_RUN, "A", 0); + add_item("<2>", "A", OPT_RUN, "A", 0); + add_item("<3>", "A", OPT_RUN, "A", 0); + add_item("<4>", "A", OPT_RUN, "A", 0); + add_item("<5>", "A", OPT_RUN, "A", 0); + add_item("<6>", "A", OPT_RUN, "A", 0); + add_item("<7>", "A", OPT_RUN, "A", 0); + add_item("<8>", "A", OPT_RUN, "A", 0); + add_item("<9>", "A", OPT_RUN, "A", 0); + + MAIN = add_menu(" Main Menu ", 8); + curr = add_item(loginstr, "Login as a privileged user", OPT_RUN, NULL, 0); + set_item_options(-1, 23); + curr->handler = &login_handler; + + add_item("<P>repare", "prep", OPT_RUN, "prep", 0); + set_item_options(-1, 24); + prepopt = + add_item("<P>rep options...", + "Options for prep image: Requires authenticated user", + OPT_INACTIVE, NULL, PREPMENU); + set_item_options(-1, 25); + + add_item("<R>escue options...", "Troubleshoot a system", OPT_SUBMENU, NULL, + RESCUE); + set_item_options(-1, 26); + add_item("<T>esting...", "Options to test hardware", OPT_SUBMENU, NULL, + TESTING); + set_item_options(-1, 27); + add_item("<L>ong Menu...", "test menu system", OPT_SUBMENU, NULL, LONGMENU); + set_item_options(-1, 28); + secret = + add_item("<S>ecret Menu...", "Secret menu", OPT_INVISIBLE, NULL, + SECRETMENU); + set_item_options(-1, 29); + add_item("<E>xit to prompt", "Exit the menu system", OPT_EXITMENU, "exit", + 0); + set_item_options(-1, 30); + csprint("Press any key within 5 seconds to show menu...", 0x07); + if (!checkkeypress(100, 50)) // Granularity of 100 milliseconds { - csprint("Sorry! Time's up.\r\n",0x07); - return 1; + csprint("Sorry! Time's up.\r\n", 0x07); + return 1; + } else + clearkbdbuf(); // Just in case user pressed something important + curr = showmenus(MAIN); + if (curr) { + if (curr->action == OPT_RUN) { + strcpy(cmd, curr->data); + if (curr == runprep) { + strcat(cmd, infoline); + if (network->data == (void *)stat) // We want static + { + csprint("Enter IP address (last two octets only): ", 0x07); + strcpy(ip, "Junk"); + editstring(ip, sizeof ip); + strcat(cmd, "ipaddr=192.168."); + strcat(cmd, ip); + } + } + if (issyslinux()) + runsyslinuxcmd(cmd); + else + csprint(cmd, 0x07); + return 1; // Should not happen when run from SYSLINUX + } } - else clearkbdbuf(); // Just in case user pressed something important - curr = showmenus(MAIN); - if (curr) - { - if (curr->action == OPT_RUN) - { - strcpy(cmd,curr->data); - if (curr == runprep) - { - strcat(cmd,infoline); - if (network->data == (void *)stat) // We want static - { - csprint("Enter IP address (last two octets only): ",0x07); - strcpy(ip, "Junk"); - editstring(ip, sizeof ip); - strcat(cmd,"ipaddr=192.168."); - strcat(cmd,ip); - } - } - if (issyslinux()) - runsyslinuxcmd(cmd); - else csprint(cmd,0x07); - return 1; // Should not happen when run from SYSLINUX - } - } - // If user quits the menu system, control comes here - // If you want to execute some specific command uncomment the next two lines - - // if (syslinux) runcommand(YOUR_COMMAND_HERE); - // else csprint(YOUR_COMMAND_HERE,0x07); - - // Deallocate space used for these data structures - close_passwords(); - close_help(); - close_menusystem(); - - // Return to prompt - return 0; + // If user quits the menu system, control comes here + // If you want to execute some specific command uncomment the next two lines + + // if (syslinux) runcommand(YOUR_COMMAND_HERE); + // else csprint(YOUR_COMMAND_HERE,0x07); + + // Deallocate space used for these data structures + close_passwords(); + close_help(); + close_menusystem(); + + // Return to prompt + return 0; } diff --git a/com32/cmenu/display.c b/com32/cmenu/display.c index 5391d7fd..3acdf6aa 100644 --- a/com32/cmenu/display.c +++ b/com32/cmenu/display.c @@ -22,16 +22,15 @@ #include <com32.h> #include <stdio.h> - int main(int argc, char *argv[]) { - if (argc < 2) { - csprint("Usage: display.c32 <textfile>\n",0x07); - exit(1); - } + if (argc < 2) { + csprint("Usage: display.c32 <textfile>\n", 0x07); + exit(1); + } - init_help(NULL); // No base dir, so all filenames must be absolute - runhelp(argv[1]); - close_help(); - return 0; + init_help(NULL); // No base dir, so all filenames must be absolute + runhelp(argv[1]); + close_help(); + return 0; } diff --git a/com32/cmenu/libmenu/com32io.c b/com32/cmenu/libmenu/com32io.c index 31aec5df..d99eb87f 100644 --- a/com32/cmenu/libmenu/com32io.c +++ b/com32/cmenu/libmenu/com32io.c @@ -15,132 +15,134 @@ #include "com32io.h" #include "syslnx.h" -com32sys_t inreg,outreg; // Global register sets for use +com32sys_t inreg, outreg; // Global register sets for use /* Print character and attribute at cursor */ -void cprint(char chr,char attr,unsigned int times,char disppage) +void cprint(char chr, char attr, unsigned int times, char disppage) { REG_AH(inreg) = 0x09; REG_AL(inreg) = chr; REG_BH(inreg) = disppage; REG_BL(inreg) = attr; REG_CX(inreg) = times; - __intcall(0x10,&inreg,&outreg); + __intcall(0x10, &inreg, &outreg); } -void setdisppage(char num) // Set the display page to specified number +void setdisppage(char num) // Set the display page to specified number { REG_AH(inreg) = 0x05; REG_AL(inreg) = num; - __intcall(0x10,&inreg,&outreg); + __intcall(0x10, &inreg, &outreg); } -char getdisppage() // Get current display page +char getdisppage() // Get current display page { REG_AH(inreg) = 0x0f; - __intcall(0x10,&inreg,&outreg); + __intcall(0x10, &inreg, &outreg); return REG_BH(outreg); } -void getpos(char * row, char * col, char page) +void getpos(char *row, char *col, char page) { - REG_AH(inreg) = 0x03; - REG_BH(inreg) = page; - __intcall(0x10,&inreg,&outreg); - *row = REG_DH(outreg); - *col = REG_DL(outreg); + REG_AH(inreg) = 0x03; + REG_BH(inreg) = page; + __intcall(0x10, &inreg, &outreg); + *row = REG_DH(outreg); + *col = REG_DL(outreg); } -void gotoxy(char row,char col, char page) +void gotoxy(char row, char col, char page) { - REG_AH(inreg) = 0x02; - REG_BH(inreg) = page; - REG_DX(inreg) = (row << 8)+col; - __intcall(0x10,&inreg,&outreg); + REG_AH(inreg) = 0x02; + REG_BH(inreg) = page; + REG_DX(inreg) = (row << 8) + col; + __intcall(0x10, &inreg, &outreg); } unsigned char sleep(unsigned int msec) { - unsigned long micro = 1000*msec; + unsigned long micro = 1000 * msec; - REG_AH(inreg) = 0x86; - REG_CX(inreg) = (micro >> 16); - REG_DX(inreg) = (micro & 0xFFFF); - __intcall(0x15,&inreg,&outreg); - return REG_AH(outreg); + REG_AH(inreg) = 0x86; + REG_CX(inreg) = (micro >> 16); + REG_DX(inreg) = (micro & 0xFFFF); + __intcall(0x15, &inreg, &outreg); + return REG_AH(outreg); } void beep() { - REG_AH(inreg) = 0x0E; - REG_AL(inreg) = 0x07; - REG_BH(inreg) = 0; - __intcall(0x10,&inreg,&outreg); + REG_AH(inreg) = 0x0E; + REG_AL(inreg) = 0x07; + REG_BH(inreg) = 0; + __intcall(0x10, &inreg, &outreg); } -void scrollupwindow(char top, char left, char bot, char right, char attr,char numlines) +void scrollupwindow(char top, char left, char bot, char right, char attr, + char numlines) { - REG_AH(inreg) = 0x06; - REG_AL(inreg) = numlines; - REG_BH(inreg) = attr; // Attribute to write blanks lines - REG_DX(inreg) = (bot << 8) + right; // BOT RIGHT corner of window - REG_CX(inreg) = (top << 8) + left; // TOP LEFT of window - __intcall(0x10,&inreg,&outreg); + REG_AH(inreg) = 0x06; + REG_AL(inreg) = numlines; + REG_BH(inreg) = attr; // Attribute to write blanks lines + REG_DX(inreg) = (bot << 8) + right; // BOT RIGHT corner of window + REG_CX(inreg) = (top << 8) + left; // TOP LEFT of window + __intcall(0x10, &inreg, &outreg); } -char inputc(char * scancode) +char inputc(char *scancode) { - syslinux_idle(); /* So syslinux can perform periodic activity */ - REG_AH(inreg) = 0x10; - __intcall(0x16,&inreg,&outreg); - if (scancode) *scancode = REG_AH(outreg); - return REG_AL(outreg); + syslinux_idle(); /* So syslinux can perform periodic activity */ + REG_AH(inreg) = 0x10; + __intcall(0x16, &inreg, &outreg); + if (scancode) + *scancode = REG_AH(outreg); + return REG_AL(outreg); } void getcursorshape(char *start, char *end) { - char page = getdisppage(); - REG_AH(inreg) = 0x03; - REG_BH(inreg) = page; - __intcall(0x10,&inreg,&outreg); - *start = REG_CH(outreg); - *end = REG_CL(outreg); + char page = getdisppage(); + REG_AH(inreg) = 0x03; + REG_BH(inreg) = page; + __intcall(0x10, &inreg, &outreg); + *start = REG_CH(outreg); + *end = REG_CL(outreg); } void setcursorshape(char start, char end) { - REG_AH(inreg) = 0x01; - REG_CH(inreg) = start; - REG_CL(inreg) = end; - __intcall(0x10,&inreg,&outreg); + REG_AH(inreg) = 0x01; + REG_CH(inreg) = start; + REG_CL(inreg) = end; + __intcall(0x10, &inreg, &outreg); } char getchar(void) { - REG_AH(inreg) = 0x08; - __intcall(0x21,&inreg,&outreg); - return REG_AL(outreg); + REG_AH(inreg) = 0x08; + __intcall(0x21, &inreg, &outreg); + return REG_AL(outreg); } void setvideomode(char mode) { - REG_AH(inreg) = 0x00; - REG_AL(inreg) = mode; - __intcall(0x10,&inreg,&outreg); + REG_AH(inreg) = 0x00; + REG_AL(inreg) = mode; + __intcall(0x10, &inreg, &outreg); } unsigned char checkkbdbuf() { - REG_AH(inreg) = 0x11; - __intcall(0x16,&inreg,&outreg); - return !(outreg.eflags.l & EFLAGS_ZF); + REG_AH(inreg) = 0x11; + __intcall(0x16, &inreg, &outreg); + return !(outreg.eflags.l & EFLAGS_ZF); } // Get char displayed at current position unsigned char getcharat(char page) { - REG_AH(inreg) = 0x08; - REG_BH(inreg) = page; - __intcall(0x16,&inreg,&outreg); - return REG_AL(outreg); + REG_AH(inreg) = 0x08; + REG_BH(inreg) = page; + __intcall(0x16, &inreg, &outreg); + return REG_AL(outreg); } diff --git a/com32/cmenu/libmenu/com32io.h b/com32/cmenu/libmenu/com32io.h index c95c0cd8..cdaf0a84 100644 --- a/com32/cmenu/libmenu/com32io.h +++ b/com32/cmenu/libmenu/com32io.h @@ -28,45 +28,45 @@ void cswprint(const char *str, char attr, char left); static inline void csprint(const char *str, char attr) { - cswprint(str,attr,0); + cswprint(str, attr, 0); } -void cprint(char chr,char attr,unsigned int times, char disppage); // Print a char +void cprint(char chr, char attr, unsigned int times, char disppage); // Print a char -void setdisppage(char num); // Set the display page to specified number +void setdisppage(char num); // Set the display page to specified number -char getdisppage(); // Get current display page +char getdisppage(); // Get current display page -void gotoxy(char row,char col, char page); +void gotoxy(char row, char col, char page); -void getpos(char * row, char * col, char page); +void getpos(char *row, char *col, char page); -char inputc(char * scancode); // Return ASCII char by val, and scancode by reference +char inputc(char *scancode); // Return ASCII char by val, and scancode by reference static inline void putch(char x, char attr, char page) { - cprint(x,attr,1,page); + cprint(x, attr, 1, page); } -void setcursorshape(char start,char end); // Set cursor shape -void getcursorshape(char *start,char *end); // Get shape for current page +void setcursorshape(char start, char end); // Set cursor shape +void getcursorshape(char *start, char *end); // Get shape for current page // Get char displayed at current position in specified page unsigned char getcharat(char page); -static inline void cursoroff(void) /* Turns off cursor */ -{ - setcursorshape(32,33); +static inline void cursoroff(void) +{ /* Turns off cursor */ + setcursorshape(32, 33); } -static inline void cursoron(void) /* Turns on cursor */ -{ - setcursorshape(6,7); +static inline void cursoron(void) +{ /* Turns on cursor */ + setcursorshape(6, 7); } static inline unsigned char readbiosb(unsigned int ofs) { - return *((unsigned char *)MK_PTR(0,ofs)); + return *((unsigned char *)MK_PTR(0, ofs)); } static inline char getnumrows() @@ -76,7 +76,7 @@ static inline char getnumrows() static inline char getnumcols(void) { - return readbiosb(0x44a); // Actually numcols + return readbiosb(0x44a); // Actually numcols } static inline char getshiftflags(void) @@ -84,29 +84,30 @@ static inline char getshiftflags(void) return readbiosb(0x417); } -void scrollupwindow(char top, char left, char bot,char right,char attr,char numlines); //Scroll up given window +void scrollupwindow(char top, char left, char bot, char right, char attr, char numlines); //Scroll up given window -static inline void scrollup(void) //Scroll up display screen by one line +static inline void scrollup(void) //Scroll up display screen by one line { - scrollupwindow(0,0,getnumrows(),getnumcols(),0x07,1); + scrollupwindow(0, 0, getnumrows(), getnumcols(), 0x07, 1); } -void setvideomode(char mode); // Set the video mode. +void setvideomode(char mode); // Set the video mode. -static inline char getvideomode(void) // Get the current video mode +static inline char getvideomode(void) // Get the current video mode { - return readbiosb(0x449); + return readbiosb(0x449); } -unsigned char sleep(unsigned int msec); // Sleep for specified time +unsigned char sleep(unsigned int msec); // Sleep for specified time -void beep(); // A Bell +void beep(); // A Bell -unsigned char checkkbdbuf(); // Check to see if there is kbd buffer is non-empty? +unsigned char checkkbdbuf(); // Check to see if there is kbd buffer is non-empty? -static inline void clearkbdbuf() // Clear the kbd buffer (how many chars removed?) +static inline void clearkbdbuf() // Clear the kbd buffer (how many chars removed?) { - while (checkkbdbuf()) inputc(NULL); + while (checkkbdbuf()) + inputc(NULL); } #endif diff --git a/com32/cmenu/libmenu/des.c b/com32/cmenu/libmenu/des.c index 47ff78c4..a058df89 100644 --- a/com32/cmenu/libmenu/des.c +++ b/com32/cmenu/libmenu/des.c @@ -60,7 +60,6 @@ * alignment). */ - #define LOWSPACE #ifndef NULL @@ -72,10 +71,10 @@ typedef unsigned char my_u_char_t; /* Re-entrantify me -- all this junk needs to be in * struct crypt_data to make this really reentrant... */ -static my_u_char_t inv_key_perm[64]; -static my_u_char_t inv_comp_perm[56]; -static my_u_char_t u_sbox[8][64]; -static my_u_char_t un_pbox[32]; +static my_u_char_t inv_key_perm[64]; +static my_u_char_t inv_comp_perm[56]; +static my_u_char_t u_sbox[8][64]; +static my_u_char_t un_pbox[32]; static my_u_int32_t en_keysl[16], en_keysr[16]; static my_u_int32_t de_keysl[16], de_keysr[16]; @@ -97,1005 +96,970 @@ static my_u_int32_t common[8][256]; /* Static stuff that stays resident and doesn't change after * being initialized, and therefore doesn't need to be made * reentrant. */ -static my_u_char_t init_perm[64], final_perm[64]; -static my_u_char_t m_sbox[4][4096]; +static my_u_char_t init_perm[64], final_perm[64]; +static my_u_char_t m_sbox[4][4096]; #ifndef LOWSPACE static my_u_int32_t psbox[4][256]; #endif /* A pile of data */ -static const my_u_char_t ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - -static const my_u_char_t IP[64] = { - 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, - 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 +static const my_u_char_t ascii64[] = + "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + +static const my_u_char_t IP[64] = { + 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 }; -static const my_u_char_t key_perm[56] = { - 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, - 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 +static const my_u_char_t key_perm[56] = { + 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, + 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, + 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, + 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 }; -static const my_u_char_t key_shifts[16] = { - 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 +static const my_u_char_t key_shifts[16] = { + 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 }; -static const my_u_char_t comp_perm[48] = { - 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, - 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, - 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 +static const my_u_char_t comp_perm[48] = { + 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, + 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, + 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 }; /* * No E box is used, as it's replaced by some ANDs, shifts, and ORs. */ -static const my_u_char_t sbox[8][64] = { - { - 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, - 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, - 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, - 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 - }, - { - 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, - 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, - 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, - 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 - }, - { - 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, - 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, - 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, - 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 - }, - { - 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, - 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, - 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, - 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 - }, - { - 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, - 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, - 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, - 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 - }, - { - 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, - 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, - 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, - 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 - }, - { - 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, - 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, - 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, - 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 - }, - { - 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, - 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, - 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, - 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 - } +static const my_u_char_t sbox[8][64] = { + { + 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, + 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, + 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, + 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}, + { + 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, + 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, + 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, + 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}, + { + 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, + 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, + 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, + 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}, + { + 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, + 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, + 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, + 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}, + { + 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, + 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, + 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, + 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}, + { + 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, + 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, + 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, + 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}, + { + 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, + 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, + 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, + 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}, + { + 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, + 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, + 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, + 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11} }; -static const my_u_char_t pbox[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 +static const my_u_char_t pbox[32] = { + 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, + 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 }; -static const my_u_int32_t bits32[32] = -{ - 0x80000000, 0x40000000, 0x20000000, 0x10000000, - 0x08000000, 0x04000000, 0x02000000, 0x01000000, - 0x00800000, 0x00400000, 0x00200000, 0x00100000, - 0x00080000, 0x00040000, 0x00020000, 0x00010000, - 0x00008000, 0x00004000, 0x00002000, 0x00001000, - 0x00000800, 0x00000400, 0x00000200, 0x00000100, - 0x00000080, 0x00000040, 0x00000020, 0x00000010, - 0x00000008, 0x00000004, 0x00000002, 0x00000001 +static const my_u_int32_t bits32[32] = { + 0x80000000, 0x40000000, 0x20000000, 0x10000000, + 0x08000000, 0x04000000, 0x02000000, 0x01000000, + 0x00800000, 0x00400000, 0x00200000, 0x00100000, + 0x00080000, 0x00040000, 0x00020000, 0x00010000, + 0x00008000, 0x00004000, 0x00002000, 0x00001000, + 0x00000800, 0x00000400, 0x00000200, 0x00000100, + 0x00000080, 0x00000040, 0x00000020, 0x00000010, + 0x00000008, 0x00000004, 0x00000002, 0x00000001 }; -static const my_u_int32_t bits28[28] = -{ - 0x08000000, 0x04000000, 0x02000000, 0x01000000, - 0x00800000, 0x00400000, 0x00200000, 0x00100000, - 0x00080000, 0x00040000, 0x00020000, 0x00010000, - 0x00008000, 0x00004000, 0x00002000, 0x00001000, - 0x00000800, 0x00000400, 0x00000200, 0x00000100, - 0x00000080, 0x00000040, 0x00000020, 0x00000010, - 0x00000008, 0x00000004, 0x00000002, 0x00000001 +static const my_u_int32_t bits28[28] = { + 0x08000000, 0x04000000, 0x02000000, 0x01000000, + 0x00800000, 0x00400000, 0x00200000, 0x00100000, + 0x00080000, 0x00040000, 0x00020000, 0x00010000, + 0x00008000, 0x00004000, 0x00002000, 0x00001000, + 0x00000800, 0x00000400, 0x00000200, 0x00000100, + 0x00000080, 0x00000040, 0x00000020, 0x00000010, + 0x00000008, 0x00000004, 0x00000002, 0x00000001 }; -static const my_u_int32_t bits24[24] = -{ - 0x00800000, 0x00400000, 0x00200000, 0x00100000, - 0x00080000, 0x00040000, 0x00020000, 0x00010000, - 0x00008000, 0x00004000, 0x00002000, 0x00001000, - 0x00000800, 0x00000400, 0x00000200, 0x00000100, - 0x00000080, 0x00000040, 0x00000020, 0x00000010, - 0x00000008, 0x00000004, 0x00000002, 0x00000001 +static const my_u_int32_t bits24[24] = { + 0x00800000, 0x00400000, 0x00200000, 0x00100000, + 0x00080000, 0x00040000, 0x00020000, 0x00010000, + 0x00008000, 0x00004000, 0x00002000, 0x00001000, + 0x00000800, 0x00000400, 0x00000200, 0x00000100, + 0x00000080, 0x00000040, 0x00000020, 0x00000010, + 0x00000008, 0x00000004, 0x00000002, 0x00000001 }; -static const my_u_char_t bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; +static const my_u_char_t bits8[8] = + { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; // static const my_u_int32_t *bits28, *bits24; - -static int -ascii_to_bin(char ch) +static int ascii_to_bin(char ch) { - if (ch > 'z') - return(0); - if (ch >= 'a') - return(ch - 'a' + 38); - if (ch > 'Z') - return(0); - if (ch >= 'A') - return(ch - 'A' + 12); - if (ch > '9') - return(0); - if (ch >= '.') - return(ch - '.'); - return(0); + if (ch > 'z') + return (0); + if (ch >= 'a') + return (ch - 'a' + 38); + if (ch > 'Z') + return (0); + if (ch >= 'A') + return (ch - 'A' + 12); + if (ch > '9') + return (0); + if (ch >= '.') + return (ch - '.'); + return (0); } -static void -des_init(void) +static void des_init(void) { #ifdef LOWSPACE - int i, j, b; + int i, j, b; #else - int i, j, b, k, inbit, obit; - my_u_int32_t *p, *il, *ir, *fl, *fr; + int i, j, b, k, inbit, obit; + my_u_int32_t *p, *il, *ir, *fl, *fr; #endif - static int des_initialised = 0; - - if (des_initialised==1) - return; - - old_rawkey0 = old_rawkey1 = 0L; - saltbits = 0L; - old_salt = 0L; - // bits24 = (bits28 = bits32 + 4) + 4; - - /* - * Invert the S-boxes, reordering the input bits. - */ - for (i = 0; i < 8; i++) - for (j = 0; j < 64; j++) { - b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); - u_sbox[i][j] = sbox[i][b]; - } - - /* - * Convert the inverted S-boxes into 4 arrays of 8 bits. - * Each will handle 12 bits of the S-box input. - */ - for (b = 0; b < 4; b++) - for (i = 0; i < 64; i++) - for (j = 0; j < 64; j++) - m_sbox[b][(i << 6) | j] = - (my_u_char_t)((u_sbox[(b << 1)][i] << 4) | - u_sbox[(b << 1) + 1][j]); - - /* - * Set up the initial & final permutations into a useful form, and - * initialise the inverted key permutation. - */ - for (i = 0; i < 64; i++) { - init_perm[final_perm[i] = IP[i] - 1] = (my_u_char_t)i; - inv_key_perm[i] = 255; + static int des_initialised = 0; + + if (des_initialised == 1) + return; + + old_rawkey0 = old_rawkey1 = 0L; + saltbits = 0L; + old_salt = 0L; + // bits24 = (bits28 = bits32 + 4) + 4; + + /* + * Invert the S-boxes, reordering the input bits. + */ + for (i = 0; i < 8; i++) + for (j = 0; j < 64; j++) { + b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); + u_sbox[i][j] = sbox[i][b]; } - /* - * Invert the key permutation and initialise the inverted key - * compression permutation. - */ - for (i = 0; i < 56; i++) { - inv_key_perm[key_perm[i] - 1] = (my_u_char_t)i; - inv_comp_perm[i] = 255; - } + /* + * Convert the inverted S-boxes into 4 arrays of 8 bits. + * Each will handle 12 bits of the S-box input. + */ + for (b = 0; b < 4; b++) + for (i = 0; i < 64; i++) + for (j = 0; j < 64; j++) + m_sbox[b][(i << 6) | j] = + (my_u_char_t) ((u_sbox[(b << 1)][i] << 4) | + u_sbox[(b << 1) + 1][j]); + + /* + * Set up the initial & final permutations into a useful form, and + * initialise the inverted key permutation. + */ + for (i = 0; i < 64; i++) { + init_perm[final_perm[i] = IP[i] - 1] = (my_u_char_t) i; + inv_key_perm[i] = 255; + } - /* - * Invert the key compression permutation. - */ - for (i = 0; i < 48; i++) { - inv_comp_perm[comp_perm[i] - 1] = (my_u_char_t)i; - } + /* + * Invert the key permutation and initialise the inverted key + * compression permutation. + */ + for (i = 0; i < 56; i++) { + inv_key_perm[key_perm[i] - 1] = (my_u_char_t) i; + inv_comp_perm[i] = 255; + } - /* - * Set up the OR-mask arrays for the initial and final permutations, - * and for the key initial and compression permutations. - */ + /* + * Invert the key compression permutation. + */ + for (i = 0; i < 48; i++) { + inv_comp_perm[comp_perm[i] - 1] = (my_u_char_t) i; + } + + /* + * Set up the OR-mask arrays for the initial and final permutations, + * and for the key initial and compression permutations. + */ #ifndef LOWSPACE - for (k = 0; k < 8; k++) { - for (i = 0; i < 256; i++) { - *(il = &ip_maskl[k][i]) = 0L; - *(ir = &ip_maskr[k][i]) = 0L; - *(fl = &fp_maskl[k][i]) = 0L; - *(fr = &fp_maskr[k][i]) = 0L; - for (j = 0; j < 8; j++) { - inbit = 8 * k + j; - if (i & bits8[j]) { - if ((obit = init_perm[inbit]) < 32) - *il |= bits32[obit]; - else - *ir |= bits32[obit-32]; - if ((obit = final_perm[inbit]) < 32) - *fl |= bits32[obit]; - else - *fr |= bits32[obit - 32]; - } - } + for (k = 0; k < 8; k++) { + for (i = 0; i < 256; i++) { + *(il = &ip_maskl[k][i]) = 0L; + *(ir = &ip_maskr[k][i]) = 0L; + *(fl = &fp_maskl[k][i]) = 0L; + *(fr = &fp_maskr[k][i]) = 0L; + for (j = 0; j < 8; j++) { + inbit = 8 * k + j; + if (i & bits8[j]) { + if ((obit = init_perm[inbit]) < 32) + *il |= bits32[obit]; + else + *ir |= bits32[obit - 32]; + if ((obit = final_perm[inbit]) < 32) + *fl |= bits32[obit]; + else + *fr |= bits32[obit - 32]; + } + } + } + for (i = 0; i < 128; i++) { + *(il = &key_perm_maskl[k][i]) = 0L; + *(ir = &key_perm_maskr[k][i]) = 0L; + for (j = 0; j < 7; j++) { + inbit = 8 * k + j; + if (i & bits8[j + 1]) { + if ((obit = inv_key_perm[inbit]) == 255) + continue; + if (obit < 28) + *il |= bits28[obit]; + else + *ir |= bits28[obit - 28]; } - for (i = 0; i < 128; i++) { - *(il = &key_perm_maskl[k][i]) = 0L; - *(ir = &key_perm_maskr[k][i]) = 0L; - for (j = 0; j < 7; j++) { - inbit = 8 * k + j; - if (i & bits8[j + 1]) { - if ((obit = inv_key_perm[inbit]) == 255) - continue; - if (obit < 28) - *il |= bits28[obit]; - else - *ir |= bits28[obit - 28]; - } - } - *(il = &comp_maskl[k][i]) = 0L; - *(ir = &comp_maskr[k][i]) = 0L; - for (j = 0; j < 7; j++) { - inbit = 7 * k + j; - if (i & bits8[j + 1]) { - if ((obit=inv_comp_perm[inbit]) == 255) - continue; - if (obit < 24) - *il |= bits24[obit]; - else - *ir |= bits24[obit - 24]; - } - } + } + *(il = &comp_maskl[k][i]) = 0L; + *(ir = &comp_maskr[k][i]) = 0L; + for (j = 0; j < 7; j++) { + inbit = 7 * k + j; + if (i & bits8[j + 1]) { + if ((obit = inv_comp_perm[inbit]) == 255) + continue; + if (obit < 24) + *il |= bits24[obit]; + else + *ir |= bits24[obit - 24]; } + } } + } #endif - /* - * Invert the P-box permutation, and convert into OR-masks for - * handling the output of the S-box arrays setup above. - */ - for (i = 0; i < 32; i++) - un_pbox[pbox[i] - 1] = (my_u_char_t)i; + /* + * Invert the P-box permutation, and convert into OR-masks for + * handling the output of the S-box arrays setup above. + */ + for (i = 0; i < 32; i++) + un_pbox[pbox[i] - 1] = (my_u_char_t) i; #ifndef LOWSPACE - for (b = 0; b < 4; b++) - for (i = 0; i < 256; i++) { - *(p = &psbox[b][i]) = 0L; - for (j = 0; j < 8; j++) { - if (i & bits8[j]) - *p |= bits32[un_pbox[8 * b + j]]; - } - } + for (b = 0; b < 4; b++) + for (i = 0; i < 256; i++) { + *(p = &psbox[b][i]) = 0L; + for (j = 0; j < 8; j++) { + if (i & bits8[j]) + *p |= bits32[un_pbox[8 * b + j]]; + } + } #endif - des_initialised = 1; + des_initialised = 1; } - #ifdef LOWSPACE -static void -setup_ip_maskl(void) +static void setup_ip_maskl(void) { - int i, j, k, inbit, obit; - my_u_int32_t *il; - - for (k = 0; k < 8; k++) { - for (i = 0; i < 256; i++) { - *(il = &common[k][i]) = 0L; - for (j = 0; j < 8; j++) { - inbit = 8 * k + j; - if (i & bits8[j]) { - if ((obit = init_perm[inbit]) < 32) - *il |= bits32[obit]; + int i, j, k, inbit, obit; + my_u_int32_t *il; + + for (k = 0; k < 8; k++) { + for (i = 0; i < 256; i++) { + *(il = &common[k][i]) = 0L; + for (j = 0; j < 8; j++) { + inbit = 8 * k + j; + if (i & bits8[j]) { + if ((obit = init_perm[inbit]) < 32) + *il |= bits32[obit]; + } + } } - } } - } } -static void -setup_ip_maskr(void) +static void setup_ip_maskr(void) { - int i, j, k, inbit, obit; - my_u_int32_t *ir; - - for (k = 0; k < 8; k++) { - for (i = 0; i < 256; i++) { - *(ir = &common[k][i]) = 0L; - for (j = 0; j < 8; j++) { - inbit = 8 * k + j; - if (i & bits8[j]) { - if ((obit = init_perm[inbit]) >= 32) - *ir |= bits32[obit-32]; + int i, j, k, inbit, obit; + my_u_int32_t *ir; + + for (k = 0; k < 8; k++) { + for (i = 0; i < 256; i++) { + *(ir = &common[k][i]) = 0L; + for (j = 0; j < 8; j++) { + inbit = 8 * k + j; + if (i & bits8[j]) { + if ((obit = init_perm[inbit]) >= 32) + *ir |= bits32[obit - 32]; + } + } } - } } - } } -static void -setup_fp_maskl(void) +static void setup_fp_maskl(void) { - int i, j, k, inbit, obit; - my_u_int32_t *fl; - - for (k = 0; k < 8; k++) { - for (i = 0; i < 256; i++) { - *(fl = &common[k][i]) = 0L; - for (j = 0; j < 8; j++) { - inbit = 8 * k + j; - if (i & bits8[j]) { - if ((obit = final_perm[inbit]) < 32) - *fl |= bits32[obit]; + int i, j, k, inbit, obit; + my_u_int32_t *fl; + + for (k = 0; k < 8; k++) { + for (i = 0; i < 256; i++) { + *(fl = &common[k][i]) = 0L; + for (j = 0; j < 8; j++) { + inbit = 8 * k + j; + if (i & bits8[j]) { + if ((obit = final_perm[inbit]) < 32) + *fl |= bits32[obit]; + } + } } - } } - } } -static void -setup_fp_maskr(void) +static void setup_fp_maskr(void) { - int i, j, k, inbit, obit; - my_u_int32_t *fr; - - for (k = 0; k < 8; k++) { - for (i = 0; i < 256; i++) { - *(fr = &common[k][i]) = 0L; - for (j = 0; j < 8; j++) { - inbit = 8 * k + j; - if (i & bits8[j]) { - if ((obit = final_perm[inbit]) >= 32) - *fr |= bits32[obit - 32]; + int i, j, k, inbit, obit; + my_u_int32_t *fr; + + for (k = 0; k < 8; k++) { + for (i = 0; i < 256; i++) { + *(fr = &common[k][i]) = 0L; + for (j = 0; j < 8; j++) { + inbit = 8 * k + j; + if (i & bits8[j]) { + if ((obit = final_perm[inbit]) >= 32) + *fr |= bits32[obit - 32]; + } + } } - } } - } } -static void -setup_key_perm_maskl(void) +static void setup_key_perm_maskl(void) { - int i, j, k, inbit, obit; - my_u_int32_t *il; - - for (k = 0; k < 8; k++) { - for (i = 0; i < 128; i++) { - *(il = &common[k][i]) = 0L; - for (j = 0; j < 7; j++) { - inbit = 8 * k + j; - if (i & bits8[j + 1]) { - if ((obit = inv_key_perm[inbit]) == 255) - continue; - if (obit < 28) - *il |= bits28[obit]; + int i, j, k, inbit, obit; + my_u_int32_t *il; + + for (k = 0; k < 8; k++) { + for (i = 0; i < 128; i++) { + *(il = &common[k][i]) = 0L; + for (j = 0; j < 7; j++) { + inbit = 8 * k + j; + if (i & bits8[j + 1]) { + if ((obit = inv_key_perm[inbit]) == 255) + continue; + if (obit < 28) + *il |= bits28[obit]; + } + } } - } } - } } -static void -setup_key_perm_maskr(void) +static void setup_key_perm_maskr(void) { - int i, j, k, inbit, obit; - my_u_int32_t *ir; - - for (k = 0; k < 8; k++) { - for (i = 0; i < 128; i++) { - *(ir = &common[k][i]) = 0L; - for (j = 0; j < 7; j++) { - inbit = 8 * k + j; - if (i & bits8[j + 1]) { - if ((obit = inv_key_perm[inbit]) == 255) - continue; - if (obit >= 28) - *ir |= bits28[obit - 28]; + int i, j, k, inbit, obit; + my_u_int32_t *ir; + + for (k = 0; k < 8; k++) { + for (i = 0; i < 128; i++) { + *(ir = &common[k][i]) = 0L; + for (j = 0; j < 7; j++) { + inbit = 8 * k + j; + if (i & bits8[j + 1]) { + if ((obit = inv_key_perm[inbit]) == 255) + continue; + if (obit >= 28) + *ir |= bits28[obit - 28]; + } + } } - } } - } } -static void -setup_comp_maskl(void) +static void setup_comp_maskl(void) { - int i, j, k, inbit, obit; - my_u_int32_t *il; - - for (k = 0; k < 8; k++) { - for (i = 0; i < 128; i++) { - *(il = &common[k][i]) = 0L; - for (j = 0; j < 7; j++) { - inbit = 7 * k + j; - if (i & bits8[j + 1]) { - if ((obit=inv_comp_perm[inbit]) == 255) - continue; - if (obit < 24) - *il |= bits24[obit]; + int i, j, k, inbit, obit; + my_u_int32_t *il; + + for (k = 0; k < 8; k++) { + for (i = 0; i < 128; i++) { + *(il = &common[k][i]) = 0L; + for (j = 0; j < 7; j++) { + inbit = 7 * k + j; + if (i & bits8[j + 1]) { + if ((obit = inv_comp_perm[inbit]) == 255) + continue; + if (obit < 24) + *il |= bits24[obit]; + } + } } - } } - } } -static void -setup_comp_maskr(void) +static void setup_comp_maskr(void) { - int i, j, k, inbit, obit; - my_u_int32_t *ir; - - for (k = 0; k < 8; k++) { - for (i = 0; i < 128; i++) { - *(ir = &common[k][i]) = 0L; - for (j = 0; j < 7; j++) { - inbit = 7 * k + j; - if (i & bits8[j + 1]) { - if ((obit=inv_comp_perm[inbit]) == 255) - continue; - if (obit >= 24) - *ir |= bits24[obit - 24]; + int i, j, k, inbit, obit; + my_u_int32_t *ir; + + for (k = 0; k < 8; k++) { + for (i = 0; i < 128; i++) { + *(ir = &common[k][i]) = 0L; + for (j = 0; j < 7; j++) { + inbit = 7 * k + j; + if (i & bits8[j + 1]) { + if ((obit = inv_comp_perm[inbit]) == 255) + continue; + if (obit >= 24) + *ir |= bits24[obit - 24]; + } + } } - } } - } } -static void -setup_psbox(void) +static void setup_psbox(void) { - int i, j, b; - my_u_int32_t *p; - - for (b = 0; b < 4; b++) - for (i = 0; i < 256; i++) { - *(p = &common[b][i]) = 0L; - for (j = 0; j < 8; j++) { - if (i & bits8[j]) - *p |= bits32[un_pbox[8 * b + j]]; - } - } + int i, j, b; + my_u_int32_t *p; + + for (b = 0; b < 4; b++) + for (i = 0; i < 256; i++) { + *(p = &common[b][i]) = 0L; + for (j = 0; j < 8; j++) { + if (i & bits8[j]) + *p |= bits32[un_pbox[8 * b + j]]; + } + } } #endif -static void -setup_salt(my_u_int32_t salt) +static void setup_salt(my_u_int32_t salt) { - my_u_int32_t obit, saltbit; - int i; - - if (salt == old_salt) - return; - old_salt = salt; - - saltbits = 0L; - saltbit = 1; - obit = 0x800000; - for (i = 0; i < 24; i++) { - if (salt & saltbit) - saltbits |= obit; - saltbit <<= 1; - obit >>= 1; - } + my_u_int32_t obit, saltbit; + int i; + + if (salt == old_salt) + return; + old_salt = salt; + + saltbits = 0L; + saltbit = 1; + obit = 0x800000; + for (i = 0; i < 24; i++) { + if (salt & saltbit) + saltbits |= obit; + saltbit <<= 1; + obit >>= 1; + } } - static my_u_int32_t char_to_int(const char *key) { - my_u_int32_t byte0,byte1,byte2,byte3; - byte0 = (my_u_int32_t) (my_u_char_t) key[0]; - byte1 = (my_u_int32_t) (my_u_char_t) key[1]; - byte2 = (my_u_int32_t) (my_u_char_t) key[2]; - byte3 = (my_u_int32_t) (my_u_char_t) key[3]; + my_u_int32_t byte0, byte1, byte2, byte3; + byte0 = (my_u_int32_t) (my_u_char_t) key[0]; + byte1 = (my_u_int32_t) (my_u_char_t) key[1]; + byte2 = (my_u_int32_t) (my_u_char_t) key[2]; + byte3 = (my_u_int32_t) (my_u_char_t) key[3]; - return byte0 << 24 | byte1 << 16 | byte2 << 8 | byte3 ; + return byte0 << 24 | byte1 << 16 | byte2 << 8 | byte3; } - -static int -des_setkey(const char *key) +static int des_setkey(const char *key) { - my_u_int32_t k0, k1, rawkey0, rawkey1; - int shifts, round; + my_u_int32_t k0, k1, rawkey0, rawkey1; + int shifts, round; - des_init(); + des_init(); - /* rawkey0 = ntohl(*(const my_u_int32_t *) key); - * rawkey1 = ntohl(*(const my_u_int32_t *) (key + 4)); - */ + /* rawkey0 = ntohl(*(const my_u_int32_t *) key); + * rawkey1 = ntohl(*(const my_u_int32_t *) (key + 4)); + */ - rawkey0 = char_to_int(key); - rawkey1 = char_to_int(key+4); - - if ((rawkey0 | rawkey1) - && rawkey0 == old_rawkey0 - && rawkey1 == old_rawkey1) { - /* - * Already setup for this key. - * This optimisation fails on a zero key (which is weak and - * has bad parity anyway) in order to simplify the starting - * conditions. - */ - return(0); - } - old_rawkey0 = rawkey0; - old_rawkey1 = rawkey1; + rawkey0 = char_to_int(key); + rawkey1 = char_to_int(key + 4); + if ((rawkey0 | rawkey1) + && rawkey0 == old_rawkey0 && rawkey1 == old_rawkey1) { /* - * Do key permutation and split into two 28-bit subkeys. + * Already setup for this key. + * This optimisation fails on a zero key (which is weak and + * has bad parity anyway) in order to simplify the starting + * conditions. */ + return (0); + } + old_rawkey0 = rawkey0; + old_rawkey1 = rawkey1; + + /* + * Do key permutation and split into two 28-bit subkeys. + */ #ifdef LOWSPACE - setup_key_perm_maskl(); - k0 = common[0][rawkey0 >> 25] - | common[1][(rawkey0 >> 17) & 0x7f] - | common[2][(rawkey0 >> 9) & 0x7f] - | common[3][(rawkey0 >> 1) & 0x7f] - | common[4][rawkey1 >> 25] - | common[5][(rawkey1 >> 17) & 0x7f] - | common[6][(rawkey1 >> 9) & 0x7f] - | common[7][(rawkey1 >> 1) & 0x7f]; - setup_key_perm_maskr(); - k1 = common[0][rawkey0 >> 25] - | common[1][(rawkey0 >> 17) & 0x7f] - | common[2][(rawkey0 >> 9) & 0x7f] - | common[3][(rawkey0 >> 1) & 0x7f] - | common[4][rawkey1 >> 25] - | common[5][(rawkey1 >> 17) & 0x7f] - | common[6][(rawkey1 >> 9) & 0x7f] - | common[7][(rawkey1 >> 1) & 0x7f]; + setup_key_perm_maskl(); + k0 = common[0][rawkey0 >> 25] + | common[1][(rawkey0 >> 17) & 0x7f] + | common[2][(rawkey0 >> 9) & 0x7f] + | common[3][(rawkey0 >> 1) & 0x7f] + | common[4][rawkey1 >> 25] + | common[5][(rawkey1 >> 17) & 0x7f] + | common[6][(rawkey1 >> 9) & 0x7f] + | common[7][(rawkey1 >> 1) & 0x7f]; + setup_key_perm_maskr(); + k1 = common[0][rawkey0 >> 25] + | common[1][(rawkey0 >> 17) & 0x7f] + | common[2][(rawkey0 >> 9) & 0x7f] + | common[3][(rawkey0 >> 1) & 0x7f] + | common[4][rawkey1 >> 25] + | common[5][(rawkey1 >> 17) & 0x7f] + | common[6][(rawkey1 >> 9) & 0x7f] + | common[7][(rawkey1 >> 1) & 0x7f]; #else - k0 = key_perm_maskl[0][rawkey0 >> 25] - | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskl[4][rawkey1 >> 25] - | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; - k1 = key_perm_maskr[0][rawkey0 >> 25] - | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskr[4][rawkey1 >> 25] - | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; + k0 = key_perm_maskl[0][rawkey0 >> 25] + | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] + | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] + | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] + | key_perm_maskl[4][rawkey1 >> 25] + | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] + | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] + | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; + k1 = key_perm_maskr[0][rawkey0 >> 25] + | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] + | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] + | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] + | key_perm_maskr[4][rawkey1 >> 25] + | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] + | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] + | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; #endif - /* - * Rotate subkeys and do compression permutation. - */ - shifts = 0; - for (round = 0; round < 16; round++) { - my_u_int32_t t0, t1; + /* + * Rotate subkeys and do compression permutation. + */ + shifts = 0; + for (round = 0; round < 16; round++) { + my_u_int32_t t0, t1; - shifts += key_shifts[round]; + shifts += key_shifts[round]; - t0 = (k0 << shifts) | (k0 >> (28 - shifts)); - t1 = (k1 << shifts) | (k1 >> (28 - shifts)); + t0 = (k0 << shifts) | (k0 >> (28 - shifts)); + t1 = (k1 << shifts) | (k1 >> (28 - shifts)); #ifdef LOWSPACE - setup_comp_maskl(); - de_keysl[15 - round] = - en_keysl[round] = common[0][(t0 >> 21) & 0x7f] - | common[1][(t0 >> 14) & 0x7f] - | common[2][(t0 >> 7) & 0x7f] - | common[3][t0 & 0x7f] - | common[4][(t1 >> 21) & 0x7f] - | common[5][(t1 >> 14) & 0x7f] - | common[6][(t1 >> 7) & 0x7f] - | common[7][t1 & 0x7f]; - - setup_comp_maskr(); - de_keysr[15 - round] = - en_keysr[round] = common[0][(t0 >> 21) & 0x7f] - | common[1][(t0 >> 14) & 0x7f] - | common[2][(t0 >> 7) & 0x7f] - | common[3][t0 & 0x7f] - | common[4][(t1 >> 21) & 0x7f] - | common[5][(t1 >> 14) & 0x7f] - | common[6][(t1 >> 7) & 0x7f] - | common[7][t1 & 0x7f]; + setup_comp_maskl(); + de_keysl[15 - round] = en_keysl[round] = common[0][(t0 >> 21) & 0x7f] + | common[1][(t0 >> 14) & 0x7f] + | common[2][(t0 >> 7) & 0x7f] + | common[3][t0 & 0x7f] + | common[4][(t1 >> 21) & 0x7f] + | common[5][(t1 >> 14) & 0x7f] + | common[6][(t1 >> 7) & 0x7f] + | common[7][t1 & 0x7f]; + + setup_comp_maskr(); + de_keysr[15 - round] = en_keysr[round] = common[0][(t0 >> 21) & 0x7f] + | common[1][(t0 >> 14) & 0x7f] + | common[2][(t0 >> 7) & 0x7f] + | common[3][t0 & 0x7f] + | common[4][(t1 >> 21) & 0x7f] + | common[5][(t1 >> 14) & 0x7f] + | common[6][(t1 >> 7) & 0x7f] + | common[7][t1 & 0x7f]; #else - de_keysl[15 - round] = - en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] - | comp_maskl[1][(t0 >> 14) & 0x7f] - | comp_maskl[2][(t0 >> 7) & 0x7f] - | comp_maskl[3][t0 & 0x7f] - | comp_maskl[4][(t1 >> 21) & 0x7f] - | comp_maskl[5][(t1 >> 14) & 0x7f] - | comp_maskl[6][(t1 >> 7) & 0x7f] - | comp_maskl[7][t1 & 0x7f]; - - de_keysr[15 - round] = - en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] - | comp_maskr[1][(t0 >> 14) & 0x7f] - | comp_maskr[2][(t0 >> 7) & 0x7f] - | comp_maskr[3][t0 & 0x7f] - | comp_maskr[4][(t1 >> 21) & 0x7f] - | comp_maskr[5][(t1 >> 14) & 0x7f] - | comp_maskr[6][(t1 >> 7) & 0x7f] - | comp_maskr[7][t1 & 0x7f]; + de_keysl[15 - round] = + en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] + | comp_maskl[1][(t0 >> 14) & 0x7f] + | comp_maskl[2][(t0 >> 7) & 0x7f] + | comp_maskl[3][t0 & 0x7f] + | comp_maskl[4][(t1 >> 21) & 0x7f] + | comp_maskl[5][(t1 >> 14) & 0x7f] + | comp_maskl[6][(t1 >> 7) & 0x7f] + | comp_maskl[7][t1 & 0x7f]; + + de_keysr[15 - round] = + en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] + | comp_maskr[1][(t0 >> 14) & 0x7f] + | comp_maskr[2][(t0 >> 7) & 0x7f] + | comp_maskr[3][t0 & 0x7f] + | comp_maskr[4][(t1 >> 21) & 0x7f] + | comp_maskr[5][(t1 >> 14) & 0x7f] + | comp_maskr[6][(t1 >> 7) & 0x7f] + | comp_maskr[7][t1 & 0x7f]; #endif - } - return(0); + } + return (0); } - static int -do_des( my_u_int32_t l_in, my_u_int32_t r_in, my_u_int32_t *l_out, my_u_int32_t *r_out, int count) +do_des(my_u_int32_t l_in, my_u_int32_t r_in, my_u_int32_t * l_out, + my_u_int32_t * r_out, int count) { + /* + * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. + */ + my_u_int32_t l, r, *kl, *kr, *kl1, *kr1; + my_u_int32_t f, r48l, r48r; + int round; + + if (count == 0) { + return (1); + } else if (count > 0) { /* - * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. + * Encrypting */ - my_u_int32_t l, r, *kl, *kr, *kl1, *kr1; - my_u_int32_t f, r48l, r48r; - int round; - - if (count == 0) { - return(1); - } else if (count > 0) { - /* - * Encrypting - */ - kl1 = en_keysl; - kr1 = en_keysr; - } else { - /* - * Decrypting - */ - count = -count; - kl1 = de_keysl; - kr1 = de_keysr; - } - + kl1 = en_keysl; + kr1 = en_keysr; + } else { /* - * Do initial permutation (IP). + * Decrypting */ + count = -count; + kl1 = de_keysl; + kr1 = de_keysr; + } + + /* + * Do initial permutation (IP). + */ #ifdef LOWSPACE - setup_ip_maskl(); - l = common[0][l_in >> 24] - | common[1][(l_in >> 16) & 0xff] - | common[2][(l_in >> 8) & 0xff] - | common[3][l_in & 0xff] - | common[4][r_in >> 24] - | common[5][(r_in >> 16) & 0xff] - | common[6][(r_in >> 8) & 0xff] - | common[7][r_in & 0xff]; - setup_ip_maskr(); - r = common[0][l_in >> 24] - | common[1][(l_in >> 16) & 0xff] - | common[2][(l_in >> 8) & 0xff] - | common[3][l_in & 0xff] - | common[4][r_in >> 24] - | common[5][(r_in >> 16) & 0xff] - | common[6][(r_in >> 8) & 0xff] - | common[7][r_in & 0xff]; + setup_ip_maskl(); + l = common[0][l_in >> 24] + | common[1][(l_in >> 16) & 0xff] + | common[2][(l_in >> 8) & 0xff] + | common[3][l_in & 0xff] + | common[4][r_in >> 24] + | common[5][(r_in >> 16) & 0xff] + | common[6][(r_in >> 8) & 0xff] + | common[7][r_in & 0xff]; + setup_ip_maskr(); + r = common[0][l_in >> 24] + | common[1][(l_in >> 16) & 0xff] + | common[2][(l_in >> 8) & 0xff] + | common[3][l_in & 0xff] + | common[4][r_in >> 24] + | common[5][(r_in >> 16) & 0xff] + | common[6][(r_in >> 8) & 0xff] + | common[7][r_in & 0xff]; #else - l = ip_maskl[0][l_in >> 24] - | ip_maskl[1][(l_in >> 16) & 0xff] - | ip_maskl[2][(l_in >> 8) & 0xff] - | ip_maskl[3][l_in & 0xff] - | ip_maskl[4][r_in >> 24] - | ip_maskl[5][(r_in >> 16) & 0xff] - | ip_maskl[6][(r_in >> 8) & 0xff] - | ip_maskl[7][r_in & 0xff]; - r = ip_maskr[0][l_in >> 24] - | ip_maskr[1][(l_in >> 16) & 0xff] - | ip_maskr[2][(l_in >> 8) & 0xff] - | ip_maskr[3][l_in & 0xff] - | ip_maskr[4][r_in >> 24] - | ip_maskr[5][(r_in >> 16) & 0xff] - | ip_maskr[6][(r_in >> 8) & 0xff] - | ip_maskr[7][r_in & 0xff]; + l = ip_maskl[0][l_in >> 24] + | ip_maskl[1][(l_in >> 16) & 0xff] + | ip_maskl[2][(l_in >> 8) & 0xff] + | ip_maskl[3][l_in & 0xff] + | ip_maskl[4][r_in >> 24] + | ip_maskl[5][(r_in >> 16) & 0xff] + | ip_maskl[6][(r_in >> 8) & 0xff] + | ip_maskl[7][r_in & 0xff]; + r = ip_maskr[0][l_in >> 24] + | ip_maskr[1][(l_in >> 16) & 0xff] + | ip_maskr[2][(l_in >> 8) & 0xff] + | ip_maskr[3][l_in & 0xff] + | ip_maskr[4][r_in >> 24] + | ip_maskr[5][(r_in >> 16) & 0xff] + | ip_maskr[6][(r_in >> 8) & 0xff] + | ip_maskr[7][r_in & 0xff]; #endif - while (count--) { - /* - * Do each round. - */ - kl = kl1; - kr = kr1; - round = 16; - while (round--) { - /* - * Expand R to 48 bits (simulate the E-box). - */ - r48l = ((r & 0x00000001) << 23) - | ((r & 0xf8000000) >> 9) - | ((r & 0x1f800000) >> 11) - | ((r & 0x01f80000) >> 13) - | ((r & 0x001f8000) >> 15); - - r48r = ((r & 0x0001f800) << 7) - | ((r & 0x00001f80) << 5) - | ((r & 0x000001f8) << 3) - | ((r & 0x0000001f) << 1) - | ((r & 0x80000000) >> 31); - /* - * Do salting for crypt() and friends, and - * XOR with the permuted key. - */ - f = (r48l ^ r48r) & saltbits; - r48l ^= f ^ *kl++; - r48r ^= f ^ *kr++; - /* - * Do sbox lookups (which shrink it back to 32 bits) - * and do the pbox permutation at the same time. - */ + while (count--) { + /* + * Do each round. + */ + kl = kl1; + kr = kr1; + round = 16; + while (round--) { + /* + * Expand R to 48 bits (simulate the E-box). + */ + r48l = ((r & 0x00000001) << 23) + | ((r & 0xf8000000) >> 9) + | ((r & 0x1f800000) >> 11) + | ((r & 0x01f80000) >> 13) + | ((r & 0x001f8000) >> 15); + + r48r = ((r & 0x0001f800) << 7) + | ((r & 0x00001f80) << 5) + | ((r & 0x000001f8) << 3) + | ((r & 0x0000001f) << 1) + | ((r & 0x80000000) >> 31); + /* + * Do salting for crypt() and friends, and + * XOR with the permuted key. + */ + f = (r48l ^ r48r) & saltbits; + r48l ^= f ^ *kl++; + r48r ^= f ^ *kr++; + /* + * Do sbox lookups (which shrink it back to 32 bits) + * and do the pbox permutation at the same time. + */ #ifdef LOWSPACE - setup_psbox(); - f = common[0][m_sbox[0][r48l >> 12]] - | common[1][m_sbox[1][r48l & 0xfff]] - | common[2][m_sbox[2][r48r >> 12]] - | common[3][m_sbox[3][r48r & 0xfff]]; + setup_psbox(); + f = common[0][m_sbox[0][r48l >> 12]] + | common[1][m_sbox[1][r48l & 0xfff]] + | common[2][m_sbox[2][r48r >> 12]] + | common[3][m_sbox[3][r48r & 0xfff]]; #else - f = psbox[0][m_sbox[0][r48l >> 12]] - | psbox[1][m_sbox[1][r48l & 0xfff]] - | psbox[2][m_sbox[2][r48r >> 12]] - | psbox[3][m_sbox[3][r48r & 0xfff]]; + f = psbox[0][m_sbox[0][r48l >> 12]] + | psbox[1][m_sbox[1][r48l & 0xfff]] + | psbox[2][m_sbox[2][r48r >> 12]] + | psbox[3][m_sbox[3][r48r & 0xfff]]; #endif - /* - * Now that we've permuted things, complete f(). - */ - f ^= l; - l = r; - r = f; - } - r = l; - l = f; + /* + * Now that we've permuted things, complete f(). + */ + f ^= l; + l = r; + r = f; } - /* - * Do final permutation (inverse of IP). - */ + r = l; + l = f; + } + /* + * Do final permutation (inverse of IP). + */ #ifdef LOWSPACE - setup_fp_maskl(); - *l_out = common[0][l >> 24] - | common[1][(l >> 16) & 0xff] - | common[2][(l >> 8) & 0xff] - | common[3][l & 0xff] - | common[4][r >> 24] - | common[5][(r >> 16) & 0xff] - | common[6][(r >> 8) & 0xff] - | common[7][r & 0xff]; - setup_fp_maskr(); - *r_out = common[0][l >> 24] - | common[1][(l >> 16) & 0xff] - | common[2][(l >> 8) & 0xff] - | common[3][l & 0xff] - | common[4][r >> 24] - | common[5][(r >> 16) & 0xff] - | common[6][(r >> 8) & 0xff] - | common[7][r & 0xff]; + setup_fp_maskl(); + *l_out = common[0][l >> 24] + | common[1][(l >> 16) & 0xff] + | common[2][(l >> 8) & 0xff] + | common[3][l & 0xff] + | common[4][r >> 24] + | common[5][(r >> 16) & 0xff] + | common[6][(r >> 8) & 0xff] + | common[7][r & 0xff]; + setup_fp_maskr(); + *r_out = common[0][l >> 24] + | common[1][(l >> 16) & 0xff] + | common[2][(l >> 8) & 0xff] + | common[3][l & 0xff] + | common[4][r >> 24] + | common[5][(r >> 16) & 0xff] + | common[6][(r >> 8) & 0xff] + | common[7][r & 0xff]; #else - *l_out = fp_maskl[0][l >> 24] - | fp_maskl[1][(l >> 16) & 0xff] - | fp_maskl[2][(l >> 8) & 0xff] - | fp_maskl[3][l & 0xff] - | fp_maskl[4][r >> 24] - | fp_maskl[5][(r >> 16) & 0xff] - | fp_maskl[6][(r >> 8) & 0xff] - | fp_maskl[7][r & 0xff]; - *r_out = fp_maskr[0][l >> 24] - | fp_maskr[1][(l >> 16) & 0xff] - | fp_maskr[2][(l >> 8) & 0xff] - | fp_maskr[3][l & 0xff] - | fp_maskr[4][r >> 24] - | fp_maskr[5][(r >> 16) & 0xff] - | fp_maskr[6][(r >> 8) & 0xff] - | fp_maskr[7][r & 0xff]; + *l_out = fp_maskl[0][l >> 24] + | fp_maskl[1][(l >> 16) & 0xff] + | fp_maskl[2][(l >> 8) & 0xff] + | fp_maskl[3][l & 0xff] + | fp_maskl[4][r >> 24] + | fp_maskl[5][(r >> 16) & 0xff] + | fp_maskl[6][(r >> 8) & 0xff] + | fp_maskl[7][r & 0xff]; + *r_out = fp_maskr[0][l >> 24] + | fp_maskr[1][(l >> 16) & 0xff] + | fp_maskr[2][(l >> 8) & 0xff] + | fp_maskr[3][l & 0xff] + | fp_maskr[4][r >> 24] + | fp_maskr[5][(r >> 16) & 0xff] + | fp_maskr[6][(r >> 8) & 0xff] + | fp_maskr[7][r & 0xff]; #endif - return(0); + return (0); } - #if 0 -static int -des_cipher(const char *in, char *out, my_u_int32_t salt, int count) +static int des_cipher(const char *in, char *out, my_u_int32_t salt, int count) { - my_u_int32_t l_out, r_out, rawl, rawr; - int retval; - union { - my_u_int32_t *ui32; - const char *c; - } trans; + my_u_int32_t l_out, r_out, rawl, rawr; + int retval; + union { + my_u_int32_t *ui32; + const char *c; + } trans; - des_init(); + des_init(); - setup_salt(salt); + setup_salt(salt); - trans.c = in; - rawl = ntohl(*trans.ui32++); - rawr = ntohl(*trans.ui32); + trans.c = in; + rawl = ntohl(*trans.ui32++); + rawr = ntohl(*trans.ui32); - retval = do_des(rawl, rawr, &l_out, &r_out, count); + retval = do_des(rawl, rawr, &l_out, &r_out, count); - trans.c = out; - *trans.ui32++ = htonl(l_out); - *trans.ui32 = htonl(r_out); - return(retval); + trans.c = out; + *trans.ui32++ = htonl(l_out); + *trans.ui32 = htonl(r_out); + return (retval); } #endif - -void -setkey(const char *key) +void setkey(const char *key) { - int i, j; - my_u_int32_t packed_keys[2]; - my_u_char_t *p; + int i, j; + my_u_int32_t packed_keys[2]; + my_u_char_t *p; - p = (my_u_char_t *) packed_keys; + p = (my_u_char_t *) packed_keys; - for (i = 0; i < 8; i++) { - p[i] = 0; - for (j = 0; j < 8; j++) - if (*key++ & 1) - p[i] |= bits8[j]; - } - des_setkey(p); + for (i = 0; i < 8; i++) { + p[i] = 0; + for (j = 0; j < 8; j++) + if (*key++ & 1) + p[i] |= bits8[j]; + } + des_setkey(p); } - -void -encrypt(char *block, int flag) +void encrypt(char *block, int flag) { - my_u_int32_t io[2]; - my_u_char_t *p; - int i, j; - - des_init(); - - setup_salt(0L); - p = block; - for (i = 0; i < 2; i++) { - io[i] = 0L; - for (j = 0; j < 32; j++) - if (*p++ & 1) - io[i] |= bits32[j]; - } - do_des(io[0], io[1], io, io + 1, flag ? -1 : 1); - for (i = 0; i < 2; i++) - for (j = 0; j < 32; j++) - block[(i << 5) | j] = (io[i] & bits32[j]) ? 1 : 0; + my_u_int32_t io[2]; + my_u_char_t *p; + int i, j; + + des_init(); + + setup_salt(0L); + p = block; + for (i = 0; i < 2; i++) { + io[i] = 0L; + for (j = 0; j < 32; j++) + if (*p++ & 1) + io[i] |= bits32[j]; + } + do_des(io[0], io[1], io, io + 1, flag ? -1 : 1); + for (i = 0; i < 2; i++) + for (j = 0; j < 32; j++) + block[(i << 5) | j] = (io[i] & bits32[j]) ? 1 : 0; } char *crypt(const char *key, const char *setting) { - my_u_int32_t count, salt, l, r0, r1, keybuf[2]; - my_u_char_t *p, *q; - static char output[21]; - - des_init(); + my_u_int32_t count, salt, l, r0, r1, keybuf[2]; + my_u_char_t *p, *q; + static char output[21]; + + des_init(); + + /* + * Copy the key, shifting each character up by one bit + * and padding with zeros. + */ + q = (my_u_char_t *) keybuf; + while (q - (my_u_char_t *) keybuf - 8) { + *q++ = *key << 1; + if (*(q - 1)) + key++; + } + if (des_setkey((char *)keybuf)) + return (NULL); +#if 0 + if (*setting == _PASSWORD_EFMT1) { + int i; /* - * Copy the key, shifting each character up by one bit - * and padding with zeros. + * "new"-style: + * setting - underscore, 4 bytes of count, 4 bytes of salt + * key - unlimited characters */ - q = (my_u_char_t *)keybuf; - while (q - (my_u_char_t *)keybuf - 8) { - *q++ = *key << 1; - if (*(q - 1)) - key++; + for (i = 1, count = 0L; i < 5; i++) + count |= ascii_to_bin(setting[i]) << ((i - 1) * 6); + + for (i = 5, salt = 0L; i < 9; i++) + salt |= ascii_to_bin(setting[i]) << ((i - 5) * 6); + + while (*key) { + /* + * Encrypt the key with itself. + */ + if (des_cipher((char *)keybuf, (char *)keybuf, 0L, 1)) + return (NULL); + /* + * And XOR with the next 8 characters of the key. + */ + q = (my_u_char_t *) keybuf; + while (q - (my_u_char_t *) keybuf - 8 && *key) + *q++ ^= *key++ << 1; + + if (des_setkey((char *)keybuf)) + return (NULL); } - if (des_setkey((char *)keybuf)) - return(NULL); + strncpy(output, setting, 9); -#if 0 - if (*setting == _PASSWORD_EFMT1) { - int i; - /* - * "new"-style: - * setting - underscore, 4 bytes of count, 4 bytes of salt - * key - unlimited characters - */ - for (i = 1, count = 0L; i < 5; i++) - count |= ascii_to_bin(setting[i]) << ((i - 1) * 6); - - for (i = 5, salt = 0L; i < 9; i++) - salt |= ascii_to_bin(setting[i]) << ((i - 5) * 6); - - while (*key) { - /* - * Encrypt the key with itself. - */ - if (des_cipher((char *)keybuf, (char *)keybuf, 0L, 1)) - return(NULL); - /* - * And XOR with the next 8 characters of the key. - */ - q = (my_u_char_t *)keybuf; - while (q - (my_u_char_t *)keybuf - 8 && *key) - *q++ ^= *key++ << 1; - - if (des_setkey((char *)keybuf)) - return(NULL); - } - strncpy(output, setting, 9); - - /* - * Double check that we weren't given a short setting. - * If we were, the above code will probably have created - * wierd values for count and salt, but we don't really care. - * Just make sure the output string doesn't have an extra - * NUL in it. - */ - output[9] = '\0'; - p = (my_u_char_t *)output + strlen(output); - } else + /* + * Double check that we weren't given a short setting. + * If we were, the above code will probably have created + * wierd values for count and salt, but we don't really care. + * Just make sure the output string doesn't have an extra + * NUL in it. + */ + output[9] = '\0'; + p = (my_u_char_t *) output + strlen(output); + } else #endif - { - /* - * "old"-style: - * setting - 2 bytes of salt - * key - up to 8 characters - */ - count = 25; - - salt = (ascii_to_bin(setting[1]) << 6) - | ascii_to_bin(setting[0]); - - output[0] = setting[0]; - /* - * If the encrypted password that the salt was extracted from - * is only 1 character long, the salt will be corrupted. We - * need to ensure that the output string doesn't have an extra - * NUL in it! - */ - output[1] = setting[1] ? setting[1] : output[0]; - - p = (my_u_char_t *)output + 2; - } - setup_salt(salt); + { /* - * Do it. + * "old"-style: + * setting - 2 bytes of salt + * key - up to 8 characters */ - if (do_des(0L, 0L, &r0, &r1, (int)count)) - return(NULL); + count = 25; + + salt = (ascii_to_bin(setting[1]) << 6) + | ascii_to_bin(setting[0]); + + output[0] = setting[0]; /* - * Now encode the result... + * If the encrypted password that the salt was extracted from + * is only 1 character long, the salt will be corrupted. We + * need to ensure that the output string doesn't have an extra + * NUL in it! */ - l = (r0 >> 8); - *p++ = ascii64[(l >> 18) & 0x3f]; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - - l = (r0 << 16) | ((r1 >> 16) & 0xffff); - *p++ = ascii64[(l >> 18) & 0x3f]; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - - l = r1 << 2; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - *p = 0; - - return(output); + output[1] = setting[1] ? setting[1] : output[0]; + + p = (my_u_char_t *) output + 2; + } + setup_salt(salt); + /* + * Do it. + */ + if (do_des(0L, 0L, &r0, &r1, (int)count)) + return (NULL); + /* + * Now encode the result... + */ + l = (r0 >> 8); + *p++ = ascii64[(l >> 18) & 0x3f]; + *p++ = ascii64[(l >> 12) & 0x3f]; + *p++ = ascii64[(l >> 6) & 0x3f]; + *p++ = ascii64[l & 0x3f]; + + l = (r0 << 16) | ((r1 >> 16) & 0xffff); + *p++ = ascii64[(l >> 18) & 0x3f]; + *p++ = ascii64[(l >> 12) & 0x3f]; + *p++ = ascii64[(l >> 6) & 0x3f]; + *p++ = ascii64[l & 0x3f]; + + l = r1 << 2; + *p++ = ascii64[(l >> 12) & 0x3f]; + *p++ = ascii64[(l >> 6) & 0x3f]; + *p++ = ascii64[l & 0x3f]; + *p = 0; + + return (output); } diff --git a/com32/cmenu/libmenu/des.h b/com32/cmenu/libmenu/des.h index 67fc6b70..d820d423 100644 --- a/com32/cmenu/libmenu/des.h +++ b/com32/cmenu/libmenu/des.h @@ -3,6 +3,6 @@ #define _DES_H_ // des crypt -extern char *crypt (const char *key, const char *salt); +extern char *crypt(const char *key, const char *salt); #endif diff --git a/com32/cmenu/libmenu/help.c b/com32/cmenu/libmenu/help.c index 31944c79..a635bd21 100644 --- a/com32/cmenu/libmenu/help.c +++ b/com32/cmenu/libmenu/help.c @@ -14,185 +14,206 @@ #include <stdio.h> #include "string.h" #include "com32io.h" -#include <syslinux/loadfile.h> // to read entire file into memory +#include <syslinux/loadfile.h> // to read entire file into memory -char helpbasedir[HELPDIRLEN]; // name of help directory limited to HELPDIRLEN +char helpbasedir[HELPDIRLEN]; // name of help directory limited to HELPDIRLEN // Find the occurence of the count'th \n in buffer (or NULL) if not found -char * findline(char*buffer,int count) +char *findline(char *buffer, int count) { - int ctr; - char *p= buffer-1; - - if (count < 1) return buffer; - for (ctr=0; ctr < count; ctr++) { - p = strchr(p+1,'\n'); - if (p==NULL) return NULL; - } - return p; + int ctr; + char *p = buffer - 1; + + if (count < 1) + return buffer; + for (ctr = 0; ctr < count; ctr++) { + p = strchr(p + 1, '\n'); + if (p == NULL) + return NULL; + } + return p; } // return the number of lines in buffer -int countlines(char*buffer) +int countlines(char *buffer) { - int ans; - const char *p; - - p = buffer-1; - ans = 1; - while(p) {p = strchr(p+1,'\n'); ans++; } - return ans; + int ans; + const char *p; + + p = buffer - 1; + ans = 1; + while (p) { + p = strchr(p + 1, '\n'); + ans++; + } + return ans; } - // Print numlines of text starting from buf -void printtext(char*buf, int from) +void printtext(char *buf, int from) { - char *p,*f; - char right,bot,nlines; - - // clear window to print - right = getnumcols() - HELP_RIGHT_MARGIN; - bot = getnumrows() - HELP_BOTTOM_MARGIN; - nlines = bot-HELP_BODY_ROW+1; - scrollupwindow(HELP_BODY_ROW,HELP_LEFT_MARGIN,bot,right,0x07,nlines); - - f = findline(buf,from); - if (!f) return; // nothing to print - if (*f=='\n') f++; // start of from+1st line - p = findline(f,nlines); - if (p && (*p=='\n')) *p = '\0'; // change to NUL - gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE); - cswprint(f,0x07,HELP_LEFT_MARGIN); - if (p) *p = '\n'; // set it back + char *p, *f; + char right, bot, nlines; + + // clear window to print + right = getnumcols() - HELP_RIGHT_MARGIN; + bot = getnumrows() - HELP_BOTTOM_MARGIN; + nlines = bot - HELP_BODY_ROW + 1; + scrollupwindow(HELP_BODY_ROW, HELP_LEFT_MARGIN, bot, right, 0x07, nlines); + + f = findline(buf, from); + if (!f) + return; // nothing to print + if (*f == '\n') + f++; // start of from+1st line + p = findline(f, nlines); + if (p && (*p == '\n')) + *p = '\0'; // change to NUL + gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN, HELPPAGE); + cswprint(f, 0x07, HELP_LEFT_MARGIN); + if (p) + *p = '\n'; // set it back } void showhelp(const char *filename) { - char nc,nr,ph; - char *title,*text; - union { char *buffer; void *vbuf; } buf; // This is to avoild type-punning issues - - char line[512]; - size_t size; - char scan; - int rv,numlines,curr_line; - - nc = getnumcols(); - nr = getnumrows(); - ph = nr - HELP_BOTTOM_MARGIN - HELP_BODY_ROW - 1; - cls(); - drawbox(0,0,nr,nc-1,HELPPAGE,0x07,HELPBOX); - - drawhorizline(2,0,nc-1,HELPPAGE,0x07,HELPBOX,0); // dumb==0 - if (filename == NULL) { // print file contents - gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE); - cswprint("Filename not given",0x07,HELP_LEFT_MARGIN); - while (1) { - inputc(&scan); - if (scan == ESCAPE) break; - } - cls(); - return; - } - - rv = loadfile(filename,(void **)&buf.vbuf, &size); // load entire file into memory - if (rv < 0) { // Error reading file or no such file - sprintf(line, "Error reading file or file not found\n file=%s",filename); - gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE); - cswprint(line,0x07,HELP_LEFT_MARGIN); - while (1) { - inputc(&scan); - if (scan == ESCAPE) break; - } - cls(); - return; - } - - title = buf.buffer; - text = findline(title,1); // end of first line - *text++='\0'; // end the title string and increment text - - // Now we have a file just print it. - gotoxy(1,(nc-strlen(title))/2,HELPPAGE); - csprint(title,0x07); - numlines = countlines(text); - curr_line = 0; - scan = ESCAPE+1; // anything except ESCAPE - - while(scan != ESCAPE) { - printtext(text,curr_line); - gotoxy(HELP_BODY_ROW-1,nc-HELP_RIGHT_MARGIN,HELPPAGE); - if (curr_line > 0) - putch(HELP_MORE_ABOVE,0x07,HELPPAGE); - else putch(' ',0x07,HELPPAGE); - gotoxy(nr-HELP_BOTTOM_MARGIN+1,nc-HELP_RIGHT_MARGIN,HELPPAGE); - if (curr_line < numlines - ph) - putch(HELP_MORE_BELOW,0x07,HELPPAGE); - else putch(' ',0x07,HELPPAGE); - - inputc(&scan); // wait for user keypress - - switch(scan) { - case HOMEKEY: - curr_line = 0; - break; - case ENDKEY: - curr_line = numlines; - break; - case UPARROW: - curr_line--; - break; - case DNARROW: - curr_line++; - break; - case PAGEUP: - curr_line -= ph; - break; - case PAGEDN: - curr_line += ph; - break; - default: - break; - } - if (curr_line > numlines - ph) curr_line = numlines-ph; - if (curr_line < 0) curr_line = 0; - } - cls(); - return; + char nc, nr, ph; + char *title, *text; + union { + char *buffer; + void *vbuf; + } buf; // This is to avoild type-punning issues + + char line[512]; + size_t size; + char scan; + int rv, numlines, curr_line; + + nc = getnumcols(); + nr = getnumrows(); + ph = nr - HELP_BOTTOM_MARGIN - HELP_BODY_ROW - 1; + cls(); + drawbox(0, 0, nr, nc - 1, HELPPAGE, 0x07, HELPBOX); + + drawhorizline(2, 0, nc - 1, HELPPAGE, 0x07, HELPBOX, 0); // dumb==0 + if (filename == NULL) { // print file contents + gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN, HELPPAGE); + cswprint("Filename not given", 0x07, HELP_LEFT_MARGIN); + while (1) { + inputc(&scan); + if (scan == ESCAPE) + break; + } + cls(); + return; + } + + rv = loadfile(filename, (void **)&buf.vbuf, &size); // load entire file into memory + if (rv < 0) { // Error reading file or no such file + sprintf(line, "Error reading file or file not found\n file=%s", + filename); + gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN, HELPPAGE); + cswprint(line, 0x07, HELP_LEFT_MARGIN); + while (1) { + inputc(&scan); + if (scan == ESCAPE) + break; + } + cls(); + return; + } + + title = buf.buffer; + text = findline(title, 1); // end of first line + *text++ = '\0'; // end the title string and increment text + + // Now we have a file just print it. + gotoxy(1, (nc - strlen(title)) / 2, HELPPAGE); + csprint(title, 0x07); + numlines = countlines(text); + curr_line = 0; + scan = ESCAPE + 1; // anything except ESCAPE + + while (scan != ESCAPE) { + printtext(text, curr_line); + gotoxy(HELP_BODY_ROW - 1, nc - HELP_RIGHT_MARGIN, HELPPAGE); + if (curr_line > 0) + putch(HELP_MORE_ABOVE, 0x07, HELPPAGE); + else + putch(' ', 0x07, HELPPAGE); + gotoxy(nr - HELP_BOTTOM_MARGIN + 1, nc - HELP_RIGHT_MARGIN, HELPPAGE); + if (curr_line < numlines - ph) + putch(HELP_MORE_BELOW, 0x07, HELPPAGE); + else + putch(' ', 0x07, HELPPAGE); + + inputc(&scan); // wait for user keypress + + switch (scan) { + case HOMEKEY: + curr_line = 0; + break; + case ENDKEY: + curr_line = numlines; + break; + case UPARROW: + curr_line--; + break; + case DNARROW: + curr_line++; + break; + case PAGEUP: + curr_line -= ph; + break; + case PAGEDN: + curr_line += ph; + break; + default: + break; + } + if (curr_line > numlines - ph) + curr_line = numlines - ph; + if (curr_line < 0) + curr_line = 0; + } + cls(); + return; } void runhelp(const char *filename) { - char dp; - char fullname[HELPDIRLEN+16]; - - dp = getdisppage(); - if (dp != HELPPAGE) setdisppage(HELPPAGE); - cursoroff(); - if (helpbasedir[0] != 0) { - strcpy(fullname,helpbasedir); - strcat(fullname,"/"); - strcat(fullname,filename); - showhelp(fullname); - } - else showhelp (filename); // Assume filename is absolute - if (dp != HELPPAGE) setdisppage(dp); + char dp; + char fullname[HELPDIRLEN + 16]; + + dp = getdisppage(); + if (dp != HELPPAGE) + setdisppage(HELPPAGE); + cursoroff(); + if (helpbasedir[0] != 0) { + strcpy(fullname, helpbasedir); + strcat(fullname, "/"); + strcat(fullname, filename); + showhelp(fullname); + } else + showhelp(filename); // Assume filename is absolute + if (dp != HELPPAGE) + setdisppage(dp); } void runhelpsystem(unsigned int helpid) { - char filename[15]; + char filename[15]; - sprintf(filename,"hlp%5d.txt",helpid); - runhelp(filename); + sprintf(filename, "hlp%5d.txt", helpid); + runhelp(filename); } void init_help(const char *helpdir) { - if (helpdir != NULL) - strcpy(helpbasedir,helpdir); - else helpbasedir[0] = 0; + if (helpdir != NULL) + strcpy(helpbasedir, helpdir); + else + helpbasedir[0] = 0; } void close_help(void) diff --git a/com32/cmenu/libmenu/help.h b/com32/cmenu/libmenu/help.h index 06832d84..0fff524f 100644 --- a/com32/cmenu/libmenu/help.h +++ b/com32/cmenu/libmenu/help.h @@ -22,15 +22,15 @@ #define HELP_TITLE_HEIGHT 1 #define HELP_BODY_ROW (HELP_TITLE_HEIGHT+3) #define HELP_LEFT_MARGIN 2 -#define HELP_RIGHT_MARGIN 2 // Assume all lines dont cross this -#define HELP_BOTTOM_MARGIN 2 // Number of lines not use from bottom of screen +#define HELP_RIGHT_MARGIN 2 // Assume all lines dont cross this +#define HELP_BOTTOM_MARGIN 2 // Number of lines not use from bottom of screen #define HELPBOX BOX_SINSIN #define HELPDIRLEN 64 #define HELPPAGE 2 -#define HELP_MORE_ABOVE 24 // to print when more is available above -#define HELP_MORE_BELOW 25 // same as above but for below +#define HELP_MORE_ABOVE 24 // to print when more is available above +#define HELP_MORE_BELOW 25 // same as above but for below // Display one screen of help information void showhelp(const char *filename); diff --git a/com32/cmenu/libmenu/menu.c b/com32/cmenu/libmenu/menu.c index 56a7426c..cfe8f39f 100644 --- a/com32/cmenu/libmenu/menu.c +++ b/com32/cmenu/libmenu/menu.c @@ -15,8 +15,9 @@ #include <stdlib.h> // Local Variables -static pt_menusystem ms; // Pointer to the menusystem -char TITLESTR[] = "COMBOOT Menu System for SYSLINUX developed by Murali Krishnan Ganapathy"; +static pt_menusystem ms; // Pointer to the menusystem +char TITLESTR[] = + "COMBOOT Menu System for SYSLINUX developed by Murali Krishnan Ganapathy"; char TITLELONG[] = " TITLE too long "; char ITEMLONG[] = " ITEM too long "; char ACTIONLONG[] = " ACTION too long "; @@ -24,15 +25,14 @@ char STATUSLONG[] = " STATUS too long "; char EMPTYSTR[] = ""; /* Forward declarations */ -int calc_visible(pt_menu menu,int first); -int next_visible(pt_menu menu,int index); -int prev_visible(pt_menu menu,int index); -int next_visible_sep(pt_menu menu,int index); -int prev_visible_sep(pt_menu menu,int index); -int calc_first_early(pt_menu menu,int curr); -int calc_first_late(pt_menu menu,int curr); -int isvisible(pt_menu menu,int first, int curr); - +int calc_visible(pt_menu menu, int first); +int next_visible(pt_menu menu, int index); +int prev_visible(pt_menu menu, int index); +int next_visible_sep(pt_menu menu, int index); +int prev_visible_sep(pt_menu menu, int index); +int calc_first_early(pt_menu menu, int curr); +int calc_first_late(pt_menu menu, int curr); +int isvisible(pt_menu menu, int first, int curr); /* Basic Menu routines */ @@ -41,544 +41,575 @@ int isvisible(pt_menu menu,int first, int curr); // as this will not return unless a key has been pressed. char getch(char *scan) { - unsigned long i; - TIMEOUTCODE c; - t_timeout_handler th; + unsigned long i; + TIMEOUTCODE c; + t_timeout_handler th; - // Wait until keypress if no handler specified - if ((ms->ontimeout==NULL) && (ms->ontotaltimeout==NULL)) return inputc(scan); + // Wait until keypress if no handler specified + if ((ms->ontimeout == NULL) && (ms->ontotaltimeout == NULL)) + return inputc(scan); - th = ms->ontimeout; - while (1) // Forever do + th = ms->ontimeout; + while (1) // Forever do { - for (i=0; i < ms->tm_numsteps; i++) - { - if (checkkbdbuf()) return inputc(scan); - sleep(ms->tm_stepsize); - if ( (ms->tm_total_timeout == 0) || (ms->ontotaltimeout==NULL)) - continue; // Dont bother with calculations if no handler - ms->tm_sofar_timeout += ms->tm_stepsize; - if (ms->tm_sofar_timeout >= ms->tm_total_timeout) { - th = ms->ontotaltimeout; - ms->tm_sofar_timeout = 0; - break; // Get out of the for loop - } + for (i = 0; i < ms->tm_numsteps; i++) { + if (checkkbdbuf()) + return inputc(scan); + sleep(ms->tm_stepsize); + if ((ms->tm_total_timeout == 0) || (ms->ontotaltimeout == NULL)) + continue; // Dont bother with calculations if no handler + ms->tm_sofar_timeout += ms->tm_stepsize; + if (ms->tm_sofar_timeout >= ms->tm_total_timeout) { + th = ms->ontotaltimeout; + ms->tm_sofar_timeout = 0; + break; // Get out of the for loop + } } - if (!th) continue; // no handler dont call - c = th(); - switch(c) - { - case CODE_ENTER: // Pretend user hit enter - *scan = ENTERA; - return '\015'; // \015 octal = 13 - case CODE_ESCAPE: // Pretend user hit escape - *scan = ESCAPE; - return '\033'; // \033 octal = 27 + if (!th) + continue; // no handler dont call + c = th(); + switch (c) { + case CODE_ENTER: // Pretend user hit enter + *scan = ENTERA; + return '\015'; // \015 octal = 13 + case CODE_ESCAPE: // Pretend user hit escape + *scan = ESCAPE; + return '\033'; // \033 octal = 27 default: - break; + break; } } - return 0; + return 0; } /* Print a menu item */ /* attr[0] is non-hilite attr, attr[1] is highlight attr */ -void printmenuitem(const char *str,uchar* attr) +void printmenuitem(const char *str, uchar * attr) { uchar page = getdisppage(); - uchar row,col; - int hlite=NOHLITE; // Initially no highlighting + uchar row, col; + int hlite = NOHLITE; // Initially no highlighting - getpos(&row,&col,page); - while ( *str ) { - switch (*str) - { + getpos(&row, &col, page); + while (*str) { + switch (*str) { case '\b': - --col; - break; + --col; + break; case '\n': - ++row; - break; + ++row; + break; case '\r': - col=0; - break; - case BELL: // No Bell Char - break; - case ENABLEHLITE: // Switch on highlighting - hlite = HLITE; - break; - case DISABLEHLITE: // Turn off highlighting - hlite = NOHLITE; - break; + col = 0; + break; + case BELL: // No Bell Char + break; + case ENABLEHLITE: // Switch on highlighting + hlite = HLITE; + break; + case DISABLEHLITE: // Turn off highlighting + hlite = NOHLITE; + break; default: - putch(*str, attr[hlite], page); - ++col; + putch(*str, attr[hlite], page); + ++col; } - if (col > getnumcols()) - { - ++row; - col=0; + if (col > getnumcols()) { + ++row; + col = 0; } - if (row > getnumrows()) - { - scrollup(); - row= getnumrows(); + if (row > getnumrows()) { + scrollup(); + row = getnumrows(); } - gotoxy(row,col,page); - str++; + gotoxy(row, col, page); + str++; } } -int find_shortcut(pt_menu menu,uchar shortcut, int index) +int find_shortcut(pt_menu menu, uchar shortcut, int index) // Find the next index with specified shortcut key { - int ans; - pt_menuitem mi; - - // Garbage in garbage out - if ((index <0) || (index >= menu->numitems)) return index; - ans = index+1; - // Go till end of menu - while (ans < menu->numitems) - { - mi = menu->items[ans]; - if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP) - || (mi->shortcut != shortcut)) - ans ++; - else return ans; + int ans; + pt_menuitem mi; + + // Garbage in garbage out + if ((index < 0) || (index >= menu->numitems)) + return index; + ans = index + 1; + // Go till end of menu + while (ans < menu->numitems) { + mi = menu->items[ans]; + if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP) + || (mi->shortcut != shortcut)) + ans++; + else + return ans; } - // Start at the beginning and try again - ans = 0; - while (ans < index) - { - mi = menu->items[ans]; - if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP) - || (mi->shortcut != shortcut)) - ans ++; - else return ans; + // Start at the beginning and try again + ans = 0; + while (ans < index) { + mi = menu->items[ans]; + if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP) + || (mi->shortcut != shortcut)) + ans++; + else + return ans; } - return index; // Sorry not found + return index; // Sorry not found } // print the menu starting from FIRST // will print a maximum of menu->menuheight items void printmenu(pt_menu menu, int curr, uchar top, uchar left, uchar first) { - int x,row; // x = index, row = position from top - int numitems,menuwidth; - char fchar[5],lchar[5]; // The first and last char in for each entry - const char *str; // and inbetween the item or a seperator is printed - uchar *attr; // attribute attr - char sep[MENULEN];// and inbetween the item or a seperator is printed - pt_menuitem ci; - - numitems = calc_visible(menu,first); - if (numitems > menu->menuheight) numitems = menu->menuheight; - - menuwidth = menu->menuwidth+3; - clearwindow(top,left-2, top+numitems+1, left+menuwidth+1, - ms->menupage, ms->fillchar, ms->shadowattr); - drawbox(top-1,left-3,top+numitems,left+menuwidth, - ms->menupage,ms->normalattr[NOHLITE],ms->menubt); - memset(sep,ms->box_horiz,menuwidth); // String containing the seperator string - sep[menuwidth-1] = 0; - // Menu title - x = (menuwidth - strlen(menu->title) - 1) >> 1; - gotoxy(top-1,left+x,ms->menupage); - printmenuitem(menu->title,ms->normalattr); - row = -1; // 1 less than inital value of x - for (x=first; x < menu->numitems; x++) - { - ci = menu->items[x]; - if (ci->action == OPT_INVISIBLE) continue; - row++; - if (row >= numitems) break; // Already have enough number of items - // Setup the defaults now - lchar[0] = fchar[0] = ' '; - lchar[1] = fchar[1] = '\0'; // fchar and lchar are just spaces - str = ci->item; // Pointer to item string - attr = (x==curr ? ms->reverseattr : ms->normalattr); // Normal attributes - switch (ci->action) // set up attr,str,fchar,lchar for everything - { + int x, row; // x = index, row = position from top + int numitems, menuwidth; + char fchar[5], lchar[5]; // The first and last char in for each entry + const char *str; // and inbetween the item or a seperator is printed + uchar *attr; // attribute attr + char sep[MENULEN]; // and inbetween the item or a seperator is printed + pt_menuitem ci; + + numitems = calc_visible(menu, first); + if (numitems > menu->menuheight) + numitems = menu->menuheight; + + menuwidth = menu->menuwidth + 3; + clearwindow(top, left - 2, top + numitems + 1, left + menuwidth + 1, + ms->menupage, ms->fillchar, ms->shadowattr); + drawbox(top - 1, left - 3, top + numitems, left + menuwidth, + ms->menupage, ms->normalattr[NOHLITE], ms->menubt); + memset(sep, ms->box_horiz, menuwidth); // String containing the seperator string + sep[menuwidth - 1] = 0; + // Menu title + x = (menuwidth - strlen(menu->title) - 1) >> 1; + gotoxy(top - 1, left + x, ms->menupage); + printmenuitem(menu->title, ms->normalattr); + row = -1; // 1 less than inital value of x + for (x = first; x < menu->numitems; x++) { + ci = menu->items[x]; + if (ci->action == OPT_INVISIBLE) + continue; + row++; + if (row >= numitems) + break; // Already have enough number of items + // Setup the defaults now + lchar[0] = fchar[0] = ' '; + lchar[1] = fchar[1] = '\0'; // fchar and lchar are just spaces + str = ci->item; // Pointer to item string + attr = (x == curr ? ms->reverseattr : ms->normalattr); // Normal attributes + switch (ci->action) // set up attr,str,fchar,lchar for everything + { case OPT_INACTIVE: - attr = (x==curr? ms->revinactattr : ms->inactattr); - break; + attr = (x == curr ? ms->revinactattr : ms->inactattr); + break; case OPT_SUBMENU: - lchar[0] = SUBMENUCHAR; lchar[1] = 0; - break; + lchar[0] = SUBMENUCHAR; + lchar[1] = 0; + break; case OPT_RADIOMENU: - lchar[0] = RADIOMENUCHAR; lchar[1] = 0; - break; + lchar[0] = RADIOMENUCHAR; + lchar[1] = 0; + break; case OPT_CHECKBOX: - lchar[0] = (ci->itemdata.checked ? CHECKED : UNCHECKED); - lchar[1] = 0; - break; + lchar[0] = (ci->itemdata.checked ? CHECKED : UNCHECKED); + lchar[1] = 0; + break; case OPT_SEP: - fchar[0] = '\b'; fchar[1] = ms->box_ltrt; fchar[2] = ms->box_horiz; fchar[3] = ms->box_horiz; fchar[4] = 0; - lchar[0] = ms->box_horiz; lchar[1] = ms->box_rtlt; lchar[2] = 0; - str = sep; - break; + fchar[0] = '\b'; + fchar[1] = ms->box_ltrt; + fchar[2] = ms->box_horiz; + fchar[3] = ms->box_horiz; + fchar[4] = 0; + lchar[0] = ms->box_horiz; + lchar[1] = ms->box_rtlt; + lchar[2] = 0; + str = sep; + break; case OPT_EXITMENU: - fchar[0] = EXITMENUCHAR; fchar[1] = 0; - break; - default: // Just to keep the compiler happy - break; - } - gotoxy(top+row,left-2,ms->menupage); - cprint(ms->spacechar,attr[NOHLITE],menuwidth+2,ms->menupage); // Wipe area with spaces - gotoxy(top+row,left-2,ms->menupage); - csprint(fchar,attr[NOHLITE]); // Print first part - gotoxy(top+row,left,ms->menupage); - printmenuitem(str,attr); // Print main part - gotoxy(top+row,left+menuwidth-1,ms->menupage); // Last char if any - csprint(lchar,attr[NOHLITE]); // Print last part + fchar[0] = EXITMENUCHAR; + fchar[1] = 0; + break; + default: // Just to keep the compiler happy + break; + } + gotoxy(top + row, left - 2, ms->menupage); + cprint(ms->spacechar, attr[NOHLITE], menuwidth + 2, ms->menupage); // Wipe area with spaces + gotoxy(top + row, left - 2, ms->menupage); + csprint(fchar, attr[NOHLITE]); // Print first part + gotoxy(top + row, left, ms->menupage); + printmenuitem(str, attr); // Print main part + gotoxy(top + row, left + menuwidth - 1, ms->menupage); // Last char if any + csprint(lchar, attr[NOHLITE]); // Print last part + } + // Check if we need to MOREABOVE and MOREBELOW to be added + // reuse x + row = 0; + x = next_visible_sep(menu, 0); // First item + if (!isvisible(menu, first, x)) // There is more above + { + row = 1; + gotoxy(top, left + menuwidth, ms->menupage); + cprint(MOREABOVE, ms->normalattr[NOHLITE], 1, ms->menupage); + } + x = prev_visible_sep(menu, menu->numitems); // last item + if (!isvisible(menu, first, x)) // There is more above + { + row = 1; + gotoxy(top + numitems - 1, left + menuwidth, ms->menupage); + cprint(MOREBELOW, ms->normalattr[NOHLITE], 1, ms->menupage); } - // Check if we need to MOREABOVE and MOREBELOW to be added - // reuse x - row = 0; - x = next_visible_sep(menu,0); // First item - if (! isvisible(menu,first,x)) // There is more above - { - row = 1; - gotoxy(top,left+menuwidth,ms->menupage); - cprint(MOREABOVE,ms->normalattr[NOHLITE],1,ms->menupage); - } - x = prev_visible_sep(menu,menu->numitems); // last item - if (! isvisible(menu,first,x)) // There is more above - { - row = 1; - gotoxy(top+numitems-1,left+menuwidth,ms->menupage); - cprint(MOREBELOW,ms->normalattr[NOHLITE],1,ms->menupage); - } - // Add a scroll box - x = ((numitems-1)*curr)/(menu->numitems); - if ((x>0) && (row==1)) { - gotoxy(top+x,left+menuwidth,ms->menupage); - cprint(SCROLLBOX,ms->normalattr[NOHLITE],1,ms->menupage); - } - if (ms->handler) ms->handler(ms,menu->items[curr]); + // Add a scroll box + x = ((numitems - 1) * curr) / (menu->numitems); + if ((x > 0) && (row == 1)) { + gotoxy(top + x, left + menuwidth, ms->menupage); + cprint(SCROLLBOX, ms->normalattr[NOHLITE], 1, ms->menupage); + } + if (ms->handler) + ms->handler(ms, menu->items[curr]); } // Difference between this and regular menu, is that only // OPT_INVISIBLE, OPT_SEP are honoured void printradiomenu(pt_menu menu, int curr, uchar top, uchar left, int first) { - int x,row; // x = index, row = position from top - int numitems,menuwidth; - char fchar[5],lchar[5]; // The first and last char in for each entry - const char *str; // and inbetween the item or a seperator is printed - uchar *attr; // all in the attribute attr - char sep[MENULEN];// and inbetween the item or a seperator is printed - pt_menuitem ci; - - numitems = calc_visible(menu,first); - if (numitems > menu->menuheight) numitems = menu->menuheight; - - menuwidth = menu->menuwidth+3; - clearwindow(top,left-2, top+numitems+1, left+menuwidth+1, - ms->menupage, ms->fillchar, ms->shadowattr); - drawbox(top-1,left-3,top+numitems,left+menuwidth, - ms->menupage,ms->normalattr[NOHLITE],ms->menubt); - memset(sep,ms->box_horiz,menuwidth); // String containing the seperator string - sep[menuwidth-1] = 0; - // Menu title - x = (menuwidth - strlen(menu->title) - 1) >> 1; - gotoxy(top-1,left+x,ms->menupage); - printmenuitem(menu->title,ms->normalattr); - row = -1; // 1 less than inital value of x - for (x=first; x < menu->numitems; x++) - { - ci = menu->items[x]; - if (ci->action == OPT_INVISIBLE) continue; - row++; - if (row > numitems) break; - // Setup the defaults now - fchar[0] = RADIOUNSEL; fchar[1]='\0'; // Unselected ( ) - lchar[0] = '\0'; // Nothing special after - str = ci->item; // Pointer to item string - attr = ms->normalattr; // Always same attribute - fchar[0] = (x==curr ? RADIOSEL : RADIOUNSEL); - switch (ci->action) // set up attr,str,fchar,lchar for everything - { + int x, row; // x = index, row = position from top + int numitems, menuwidth; + char fchar[5], lchar[5]; // The first and last char in for each entry + const char *str; // and inbetween the item or a seperator is printed + uchar *attr; // all in the attribute attr + char sep[MENULEN]; // and inbetween the item or a seperator is printed + pt_menuitem ci; + + numitems = calc_visible(menu, first); + if (numitems > menu->menuheight) + numitems = menu->menuheight; + + menuwidth = menu->menuwidth + 3; + clearwindow(top, left - 2, top + numitems + 1, left + menuwidth + 1, + ms->menupage, ms->fillchar, ms->shadowattr); + drawbox(top - 1, left - 3, top + numitems, left + menuwidth, + ms->menupage, ms->normalattr[NOHLITE], ms->menubt); + memset(sep, ms->box_horiz, menuwidth); // String containing the seperator string + sep[menuwidth - 1] = 0; + // Menu title + x = (menuwidth - strlen(menu->title) - 1) >> 1; + gotoxy(top - 1, left + x, ms->menupage); + printmenuitem(menu->title, ms->normalattr); + row = -1; // 1 less than inital value of x + for (x = first; x < menu->numitems; x++) { + ci = menu->items[x]; + if (ci->action == OPT_INVISIBLE) + continue; + row++; + if (row > numitems) + break; + // Setup the defaults now + fchar[0] = RADIOUNSEL; + fchar[1] = '\0'; // Unselected ( ) + lchar[0] = '\0'; // Nothing special after + str = ci->item; // Pointer to item string + attr = ms->normalattr; // Always same attribute + fchar[0] = (x == curr ? RADIOSEL : RADIOUNSEL); + switch (ci->action) // set up attr,str,fchar,lchar for everything + { case OPT_INACTIVE: - attr = ms->inactattr; - break; + attr = ms->inactattr; + break; case OPT_SEP: - fchar[0] = '\b'; fchar[1] = ms->box_ltrt; fchar[2] = ms->box_horiz; fchar[3] = ms->box_horiz; fchar[4] = 0; - lchar[0] = ms->box_horiz; lchar[1] = ms->box_rtlt; lchar[3] = 0; - str = sep; - break; - default: // To keep the compiler happy - break; - } - gotoxy(top+row,left-2,ms->menupage); - cprint(ms->spacechar,attr[NOHLITE],menuwidth+2,ms->menupage); // Wipe area with spaces - gotoxy(top+row,left-2,ms->menupage); - csprint(fchar,attr[NOHLITE]); // Print first part - gotoxy(top+row,left,ms->menupage); - printmenuitem(str,attr); // Print main part - gotoxy(top+row,left+menuwidth-1,ms->menupage); // Last char if any - csprint(lchar,attr[NOHLITE]); // Print last part + fchar[0] = '\b'; + fchar[1] = ms->box_ltrt; + fchar[2] = ms->box_horiz; + fchar[3] = ms->box_horiz; + fchar[4] = 0; + lchar[0] = ms->box_horiz; + lchar[1] = ms->box_rtlt; + lchar[3] = 0; + str = sep; + break; + default: // To keep the compiler happy + break; + } + gotoxy(top + row, left - 2, ms->menupage); + cprint(ms->spacechar, attr[NOHLITE], menuwidth + 2, ms->menupage); // Wipe area with spaces + gotoxy(top + row, left - 2, ms->menupage); + csprint(fchar, attr[NOHLITE]); // Print first part + gotoxy(top + row, left, ms->menupage); + printmenuitem(str, attr); // Print main part + gotoxy(top + row, left + menuwidth - 1, ms->menupage); // Last char if any + csprint(lchar, attr[NOHLITE]); // Print last part } - // Check if we need to MOREABOVE and MOREBELOW to be added - // reuse x - row = 0; - x = next_visible_sep(menu,0); // First item - if (! isvisible(menu,first,x)) // There is more above - { - row = 1; - gotoxy(top,left+menuwidth,ms->menupage); - cprint(MOREABOVE,ms->normalattr[NOHLITE],1,ms->menupage); - } - x = prev_visible_sep(menu,menu->numitems); // last item - if (! isvisible(menu,first,x)) // There is more above - { - row = 1; - gotoxy(top+numitems-1,left+menuwidth,ms->menupage); - cprint(MOREBELOW,ms->normalattr[NOHLITE],1,ms->menupage); - } - // Add a scroll box - x = ((numitems-1)*curr)/(menu->numitems); - if ((x > 0) && (row == 1)) - { - gotoxy(top+x,left+menuwidth,ms->menupage); - cprint(SCROLLBOX,ms->normalattr[NOHLITE],1,ms->menupage); - } - if (ms->handler) ms->handler(ms,menu->items[curr]); + // Check if we need to MOREABOVE and MOREBELOW to be added + // reuse x + row = 0; + x = next_visible_sep(menu, 0); // First item + if (!isvisible(menu, first, x)) // There is more above + { + row = 1; + gotoxy(top, left + menuwidth, ms->menupage); + cprint(MOREABOVE, ms->normalattr[NOHLITE], 1, ms->menupage); + } + x = prev_visible_sep(menu, menu->numitems); // last item + if (!isvisible(menu, first, x)) // There is more above + { + row = 1; + gotoxy(top + numitems - 1, left + menuwidth, ms->menupage); + cprint(MOREBELOW, ms->normalattr[NOHLITE], 1, ms->menupage); + } + // Add a scroll box + x = ((numitems - 1) * curr) / (menu->numitems); + if ((x > 0) && (row == 1)) { + gotoxy(top + x, left + menuwidth, ms->menupage); + cprint(SCROLLBOX, ms->normalattr[NOHLITE], 1, ms->menupage); + } + if (ms->handler) + ms->handler(ms, menu->items[curr]); } -void cleanupmenu(pt_menu menu, uchar top,uchar left,int numitems) +void cleanupmenu(pt_menu menu, uchar top, uchar left, int numitems) { - if (numitems > menu->menuheight) numitems = menu->menuheight; - clearwindow(top,left-2, top+numitems+1, left+menu->menuwidth+4, - ms->menupage, ms->fillchar, ms->fillattr); // Clear the shadow - clearwindow(top-1, left-3, top+numitems, left+menu->menuwidth+3, - ms->menupage, ms->fillchar, ms->fillattr); // main window + if (numitems > menu->menuheight) + numitems = menu->menuheight; + clearwindow(top, left - 2, top + numitems + 1, left + menu->menuwidth + 4, ms->menupage, ms->fillchar, ms->fillattr); // Clear the shadow + clearwindow(top - 1, left - 3, top + numitems, left + menu->menuwidth + 3, ms->menupage, ms->fillchar, ms->fillattr); // main window } /* Handle a radio menu */ pt_menuitem getradiooption(pt_menu menu, uchar top, uchar left, uchar startopt) // Return item chosen or NULL if ESC was hit. { - int curr,i,first,tmp; - uchar asc,scan; - uchar numitems; - pt_menuitem ci; // Current item - - numitems = calc_visible(menu,0); - // Setup status line - gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage); - cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,ms->menupage); - - // Initialise current menu item - curr = next_visible(menu,startopt); - - gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage); - cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,1); - gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage); - printmenuitem(menu->items[curr]->status,ms->statusattr); - first = calc_first_early(menu,curr); - while (1) // Forever + int curr, i, first, tmp; + uchar asc, scan; + uchar numitems; + pt_menuitem ci; // Current item + + numitems = calc_visible(menu, 0); + // Setup status line + gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); + cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, ms->menupage); + + // Initialise current menu item + curr = next_visible(menu, startopt); + + gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); + cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, 1); + gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); + printmenuitem(menu->items[curr]->status, ms->statusattr); + first = calc_first_early(menu, curr); + while (1) // Forever { - printradiomenu(menu,curr,top,left,first); - ci = menu->items[curr]; + printradiomenu(menu, curr, top, left, first); + ci = menu->items[curr]; - asc = getch(&scan); - switch (scan) - { + asc = getch(&scan); + switch (scan) { case HOMEKEY: - curr = next_visible(menu,0); - first = calc_first_early(menu,curr); - break; + curr = next_visible(menu, 0); + first = calc_first_early(menu, curr); + break; case ENDKEY: - curr = prev_visible(menu,numitems-1); - first = calc_first_late(menu,curr); - break; + curr = prev_visible(menu, numitems - 1); + first = calc_first_late(menu, curr); + break; case PAGEDN: - for (i=0; i < 5; i++) curr = next_visible(menu,curr+1); - first = calc_first_late(menu,curr); - break; + for (i = 0; i < 5; i++) + curr = next_visible(menu, curr + 1); + first = calc_first_late(menu, curr); + break; case PAGEUP: - for (i=0; i < 5; i++) curr = prev_visible(menu,curr-1); - first = calc_first_early(menu,curr); - break; + for (i = 0; i < 5; i++) + curr = prev_visible(menu, curr - 1); + first = calc_first_early(menu, curr); + break; case UPARROW: - curr = prev_visible(menu,curr-1); - if (curr < first) first = calc_first_early(menu,curr); - break; + curr = prev_visible(menu, curr - 1); + if (curr < first) + first = calc_first_early(menu, curr); + break; case DNARROW: - curr = next_visible(menu,curr+1); - if (! isvisible(menu,first,curr)) - first = calc_first_late(menu,curr); - break; + curr = next_visible(menu, curr + 1); + if (!isvisible(menu, first, curr)) + first = calc_first_late(menu, curr); + break; case LTARROW: case ESCAPE: - return NULL; - break; + return NULL; + break; case RTARROW: case ENTERA: case ENTERB: - if (ci->action == OPT_INACTIVE) break; - if (ci->action == OPT_SEP) break; - return ci; - break; + if (ci->action == OPT_INACTIVE) + break; + if (ci->action == OPT_SEP) + break; + return ci; + break; default: - // Check if this is a shortcut key - if (((asc >= 'A') && (asc <= 'Z')) || - ((asc >= 'a') && (asc <= 'z')) || - ((asc >= '0') && (asc <= '9'))) - { - tmp = find_shortcut(menu,asc,curr); - if ((tmp > curr) && (! isvisible(menu,first,tmp))) - first = calc_first_late(menu,tmp); - if (tmp < curr) - first = calc_first_early(menu,tmp); - curr = tmp; - } - else { - if (ms->keys_handler) // Call extra keys handler - ms->keys_handler(ms,menu->items[curr],(scan << 8) | asc); - } - break; - } - // Update status line - gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage); - cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,ms->menupage); - printmenuitem(menu->items[curr]->status,ms->statusattr); + // Check if this is a shortcut key + if (((asc >= 'A') && (asc <= 'Z')) || + ((asc >= 'a') && (asc <= 'z')) || + ((asc >= '0') && (asc <= '9'))) { + tmp = find_shortcut(menu, asc, curr); + if ((tmp > curr) && (!isvisible(menu, first, tmp))) + first = calc_first_late(menu, tmp); + if (tmp < curr) + first = calc_first_early(menu, tmp); + curr = tmp; + } else { + if (ms->keys_handler) // Call extra keys handler + ms->keys_handler(ms, menu->items[curr], (scan << 8) | asc); + } + break; + } + // Update status line + gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); + cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, + ms->menupage); + printmenuitem(menu->items[curr]->status, ms->statusattr); } - return NULL; // Should never come here + return NULL; // Should never come here } /* Handle one menu */ pt_menuitem getmenuoption(pt_menu menu, uchar top, uchar left, uchar startopt) // Return item chosen or NULL if ESC was hit. { - int curr,i,first,tmp; - uchar asc,scan; - uchar numitems; - pt_menuitem ci; // Current item - t_handler_return hr; // Return value of handler - - numitems = calc_visible(menu,0); - // Setup status line - gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage); - cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,ms->menupage); - - // Initialise current menu item - curr = next_visible(menu,startopt); - - gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage); - cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,1); - gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage); - printmenuitem(menu->items[curr]->status,ms->statusattr); - first = calc_first_early(menu,curr); - while (1) // Forever + int curr, i, first, tmp; + uchar asc, scan; + uchar numitems; + pt_menuitem ci; // Current item + t_handler_return hr; // Return value of handler + + numitems = calc_visible(menu, 0); + // Setup status line + gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); + cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, ms->menupage); + + // Initialise current menu item + curr = next_visible(menu, startopt); + + gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); + cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, 1); + gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); + printmenuitem(menu->items[curr]->status, ms->statusattr); + first = calc_first_early(menu, curr); + while (1) // Forever { - printmenu(menu,curr,top,left,first); - ci = menu->items[curr]; - asc = getch(&scan); - switch (scan) - { + printmenu(menu, curr, top, left, first); + ci = menu->items[curr]; + asc = getch(&scan); + switch (scan) { case HOMEKEY: - curr = next_visible(menu,0); - first = calc_first_early(menu,curr); - break; + curr = next_visible(menu, 0); + first = calc_first_early(menu, curr); + break; case ENDKEY: - curr = prev_visible(menu,numitems-1); - first = calc_first_late(menu,curr); - break; + curr = prev_visible(menu, numitems - 1); + first = calc_first_late(menu, curr); + break; case PAGEDN: - for (i=0; i < 5; i++) curr = next_visible(menu,curr+1); - first = calc_first_late(menu,curr); - break; + for (i = 0; i < 5; i++) + curr = next_visible(menu, curr + 1); + first = calc_first_late(menu, curr); + break; case PAGEUP: - for (i=0; i < 5; i++) curr = prev_visible(menu,curr-1); - first = calc_first_early(menu,curr); - break; + for (i = 0; i < 5; i++) + curr = prev_visible(menu, curr - 1); + first = calc_first_early(menu, curr); + break; case UPARROW: - curr = prev_visible(menu,curr-1); - if (curr < first) first = calc_first_early(menu,curr); - break; + curr = prev_visible(menu, curr - 1); + if (curr < first) + first = calc_first_early(menu, curr); + break; case DNARROW: - curr = next_visible(menu,curr+1); - if (! isvisible(menu,first,curr)) - first = calc_first_late(menu,curr); - break; + curr = next_visible(menu, curr + 1); + if (!isvisible(menu, first, curr)) + first = calc_first_late(menu, curr); + break; case LTARROW: case ESCAPE: - return NULL; - break; + return NULL; + break; case RTARROW: case ENTERA: case ENTERB: - if (ci->action == OPT_INACTIVE) break; - if (ci->action == OPT_CHECKBOX) break; - if (ci->action == OPT_SEP) break; - if (ci->action == OPT_EXITMENU) return NULL; // As if we hit Esc - // If we are going into a radio menu, dont call handler, return ci - if (ci->action == OPT_RADIOMENU) return ci; - if (ci->handler != NULL) // Do we have a handler - { - hr = ci->handler(ms,ci); - if (hr.refresh) // Do we need to refresh - { - // Cleanup menu using old number of items - cleanupmenu(menu,top,left,numitems); - // Recalculate the number of items - numitems = calc_visible(menu,0); - // Reprint the menu - printmenu(menu,curr,top,left,first); - } - if (hr.valid) return ci; - } - else return ci; - break; + if (ci->action == OPT_INACTIVE) + break; + if (ci->action == OPT_CHECKBOX) + break; + if (ci->action == OPT_SEP) + break; + if (ci->action == OPT_EXITMENU) + return NULL; // As if we hit Esc + // If we are going into a radio menu, dont call handler, return ci + if (ci->action == OPT_RADIOMENU) + return ci; + if (ci->handler != NULL) // Do we have a handler + { + hr = ci->handler(ms, ci); + if (hr.refresh) // Do we need to refresh + { + // Cleanup menu using old number of items + cleanupmenu(menu, top, left, numitems); + // Recalculate the number of items + numitems = calc_visible(menu, 0); + // Reprint the menu + printmenu(menu, curr, top, left, first); + } + if (hr.valid) + return ci; + } else + return ci; + break; case SPACEKEY: - if (ci->action != OPT_CHECKBOX) break; - ci->itemdata.checked = !ci->itemdata.checked; - if (ci->handler != NULL) // Do we have a handler - { - hr = ci->handler(ms,ci); - if (hr.refresh) // Do we need to refresh - { - // Cleanup menu using old number of items - cleanupmenu(menu,top,left,numitems); - // Recalculate the number of items - numitems = calc_visible(menu,0); - // Reprint the menu - printmenu(menu,curr,top,left,first); - } - } - break; + if (ci->action != OPT_CHECKBOX) + break; + ci->itemdata.checked = !ci->itemdata.checked; + if (ci->handler != NULL) // Do we have a handler + { + hr = ci->handler(ms, ci); + if (hr.refresh) // Do we need to refresh + { + // Cleanup menu using old number of items + cleanupmenu(menu, top, left, numitems); + // Recalculate the number of items + numitems = calc_visible(menu, 0); + // Reprint the menu + printmenu(menu, curr, top, left, first); + } + } + break; default: - // Check if this is a shortcut key - if (((asc >= 'A') && (asc <= 'Z')) || - ((asc >= 'a') && (asc <= 'z')) || - ((asc >= '0') && (asc <= '9'))) - { - tmp = find_shortcut(menu,asc,curr); - if ((tmp > curr) && (! isvisible(menu,first,tmp))) - first = calc_first_late(menu,tmp); - if (tmp < curr) - first = calc_first_early(menu,tmp); - curr = tmp; - } - else { - if (ms->keys_handler) // Call extra keys handler - ms->keys_handler(ms,menu->items[curr],(scan << 8) | asc); - } - break; - } - // Update status line - gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage); - cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,ms->menupage); - printmenuitem(menu->items[curr]->status,ms->statusattr); + // Check if this is a shortcut key + if (((asc >= 'A') && (asc <= 'Z')) || + ((asc >= 'a') && (asc <= 'z')) || + ((asc >= '0') && (asc <= '9'))) { + tmp = find_shortcut(menu, asc, curr); + if ((tmp > curr) && (!isvisible(menu, first, tmp))) + first = calc_first_late(menu, tmp); + if (tmp < curr) + first = calc_first_early(menu, tmp); + curr = tmp; + } else { + if (ms->keys_handler) // Call extra keys handler + ms->keys_handler(ms, menu->items[curr], (scan << 8) | asc); + } + break; + } + // Update status line + gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); + cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, + ms->menupage); + printmenuitem(menu->items[curr]->status, ms->statusattr); } - return NULL; // Should never come here + return NULL; // Should never come here } /* Handle the entire system of menu's. */ -pt_menuitem runmenusystem(uchar top, uchar left, pt_menu cmenu, uchar startopt, uchar menutype) +pt_menuitem runmenusystem(uchar top, uchar left, pt_menu cmenu, uchar startopt, + uchar menutype) /* * cmenu * Which menu should be currently displayed @@ -593,90 +624,91 @@ pt_menuitem runmenusystem(uchar top, uchar left, pt_menu cmenu, uchar startopt, * Returns a pointer to the final item chosen, or NULL if nothing chosen. */ { - pt_menuitem opt,choice; - uchar startat,mt; - uchar row,col; - - if (cmenu == NULL) return NULL; - startover: - // Set the menu height - cmenu->menuheight = ms->maxrow - top-3; - if (cmenu->menuheight > ms->maxmenuheight) - cmenu->menuheight = ms->maxmenuheight; - if (menutype == NORMALMENU) - opt = getmenuoption(cmenu,top,left,startopt); - else // menutype == RADIOMENU - opt = getradiooption(cmenu,top,left,startopt); - - if (opt == NULL) - { - // User hit Esc - cleanupmenu(cmenu,top,left,calc_visible(cmenu,0)); - return NULL; + pt_menuitem opt, choice; + uchar startat, mt; + uchar row, col; + + if (cmenu == NULL) + return NULL; +startover: + // Set the menu height + cmenu->menuheight = ms->maxrow - top - 3; + if (cmenu->menuheight > ms->maxmenuheight) + cmenu->menuheight = ms->maxmenuheight; + if (menutype == NORMALMENU) + opt = getmenuoption(cmenu, top, left, startopt); + else // menutype == RADIOMENU + opt = getradiooption(cmenu, top, left, startopt); + + if (opt == NULL) { + // User hit Esc + cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0)); + return NULL; } - // Are we done with the menu system? - if ((opt->action != OPT_SUBMENU) && (opt->action != OPT_RADIOMENU)) - { - cleanupmenu(cmenu,top,left,calc_visible(cmenu,0)); - return opt; // parent cleanup other menus + // Are we done with the menu system? + if ((opt->action != OPT_SUBMENU) && (opt->action != OPT_RADIOMENU)) { + cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0)); + return opt; // parent cleanup other menus } - // Either radiomenu or submenu - // Do we have a valid menu number? The next hack uses the fact that - // itemdata.submenunum = itemdata.radiomenunum (since enum data type) - if (opt->itemdata.submenunum >= ms->nummenus) // This is Bad.... + // Either radiomenu or submenu + // Do we have a valid menu number? The next hack uses the fact that + // itemdata.submenunum = itemdata.radiomenunum (since enum data type) + if (opt->itemdata.submenunum >= ms->nummenus) // This is Bad.... { - gotoxy(12,12,ms->menupage); // Middle of screen - csprint("ERROR: Invalid submenu requested.",0x07); - cleanupmenu(cmenu,top,left,calc_visible(cmenu,0)); - return NULL; // Pretend user hit esc + gotoxy(12, 12, ms->menupage); // Middle of screen + csprint("ERROR: Invalid submenu requested.", 0x07); + cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0)); + return NULL; // Pretend user hit esc } - // Call recursively for submenu - // Position the submenu below the current item, - // covering half the current window (horizontally) - row = ms->menus[(unsigned int)opt->itemdata.submenunum]->row; - col = ms->menus[(unsigned int)opt->itemdata.submenunum]->col; - if (row == 0xFF) row = top+opt->index+2; - if (col == 0xFF) col = left+3+(cmenu->menuwidth >> 1); - mt = (opt->action == OPT_SUBMENU ? NORMALMENU : RADIOMENU ); - startat = 0; - if ((opt->action == OPT_RADIOMENU) && (opt->data != NULL)) - startat = ((t_menuitem *)opt->data)->index; - - choice = runmenusystem(row, col, - ms->menus[(unsigned int)opt->itemdata.submenunum], - startat, mt ); - if (opt->action == OPT_RADIOMENU) - { - if (choice != NULL) opt->data = (void *)choice; // store choice in data field - if (opt->handler != NULL) opt->handler(ms,opt); - choice = NULL; // Pretend user hit esc + // Call recursively for submenu + // Position the submenu below the current item, + // covering half the current window (horizontally) + row = ms->menus[(unsigned int)opt->itemdata.submenunum]->row; + col = ms->menus[(unsigned int)opt->itemdata.submenunum]->col; + if (row == 0xFF) + row = top + opt->index + 2; + if (col == 0xFF) + col = left + 3 + (cmenu->menuwidth >> 1); + mt = (opt->action == OPT_SUBMENU ? NORMALMENU : RADIOMENU); + startat = 0; + if ((opt->action == OPT_RADIOMENU) && (opt->data != NULL)) + startat = ((t_menuitem *) opt->data)->index; + + choice = runmenusystem(row, col, + ms->menus[(unsigned int)opt->itemdata.submenunum], + startat, mt); + if (opt->action == OPT_RADIOMENU) { + if (choice != NULL) + opt->data = (void *)choice; // store choice in data field + if (opt->handler != NULL) + opt->handler(ms, opt); + choice = NULL; // Pretend user hit esc } - if (choice==NULL) // User hit Esc in submenu + if (choice == NULL) // User hit Esc in submenu { - // Startover - startopt = opt->index; - goto startover; - } - else - { - cleanupmenu(cmenu,top,left,calc_visible(cmenu,0)); - return choice; + // Startover + startopt = opt->index; + goto startover; + } else { + cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0)); + return choice; } } // Finds the indexof the menu with given name uchar find_menu_num(const char *name) { - int i; - pt_menu m; - - if (name == NULL) return (uchar)(-1); - for (i=0; i < ms->nummenus; i++) - { - m = ms->menus[i]; - if ((m->name) && (strcmp(m->name,name)==0)) return i; - } - return (uchar)(-1); + int i; + pt_menu m; + + if (name == NULL) + return (uchar) (-1); + for (i = 0; i < ms->nummenus; i++) { + m = ms->menus[i]; + if ((m->name) && (strcmp(m->name, name) == 0)) + return i; + } + return (uchar) (-1); } // Run through all items and if they are submenus @@ -684,563 +716,620 @@ uchar find_menu_num(const char *name) // replace submenunum with the menu with name "action" void fix_submenus() { - int i,j; - pt_menu m; - pt_menuitem mi; - - i = 0; - for (i=0; i < ms->nummenus; i++) - { - m = ms->menus[i]; - for (j=0; j < m->numitems; j++) - { - mi = m->items[j]; - // if item is a submenu and has non-empty non-trivial data string - if (mi->data && strlen(mi->data) > 0 && - ((mi->action == OPT_SUBMENU) || (mi->action == OPT_RADIOMENU)) ) { - mi->itemdata.submenunum = find_menu_num (mi->data); - } - } - } + int i, j; + pt_menu m; + pt_menuitem mi; + + i = 0; + for (i = 0; i < ms->nummenus; i++) { + m = ms->menus[i]; + for (j = 0; j < m->numitems; j++) { + mi = m->items[j]; + // if item is a submenu and has non-empty non-trivial data string + if (mi->data && strlen(mi->data) > 0 && + ((mi->action == OPT_SUBMENU) + || (mi->action == OPT_RADIOMENU))) { + mi->itemdata.submenunum = find_menu_num(mi->data); + } + } + } } /* User Callable functions */ pt_menuitem showmenus(uchar startmenu) { - pt_menuitem rv; - uchar oldpage,tpos; - - fix_submenus(); // Fix submenu numbers incase nick names were used - - // Setup screen for menusystem - oldpage = getdisppage(); - setdisppage(ms->menupage); - cls(); - clearwindow(ms->minrow, ms->mincol, ms->maxrow, ms->maxcol, - ms->menupage, ms->fillchar, ms->fillattr); - tpos = (ms->numcols - strlen(ms->title) - 1) >> 1; // center it on line - gotoxy(ms->minrow,ms->mincol,ms->menupage); - cprint(ms->tfillchar,ms->titleattr,ms->numcols,ms->menupage); - gotoxy(ms->minrow,ms->mincol+tpos,ms->menupage); - csprint(ms->title,ms->titleattr); - - cursoroff(); // Doesn't seem to work? - - - // Go, main menu cannot be a radio menu - rv = runmenusystem(ms->minrow+MENUROW, ms->mincol+MENUCOL, - ms->menus[(unsigned int)startmenu], 0, NORMALMENU); - - // Hide the garbage we left on the screen - cursoron(); - if (oldpage == ms->menupage) cls(); else setdisppage(oldpage); - - // Return user choice - return rv; + pt_menuitem rv; + uchar oldpage, tpos; + + fix_submenus(); // Fix submenu numbers incase nick names were used + + // Setup screen for menusystem + oldpage = getdisppage(); + setdisppage(ms->menupage); + cls(); + clearwindow(ms->minrow, ms->mincol, ms->maxrow, ms->maxcol, + ms->menupage, ms->fillchar, ms->fillattr); + tpos = (ms->numcols - strlen(ms->title) - 1) >> 1; // center it on line + gotoxy(ms->minrow, ms->mincol, ms->menupage); + cprint(ms->tfillchar, ms->titleattr, ms->numcols, ms->menupage); + gotoxy(ms->minrow, ms->mincol + tpos, ms->menupage); + csprint(ms->title, ms->titleattr); + + cursoroff(); // Doesn't seem to work? + + // Go, main menu cannot be a radio menu + rv = runmenusystem(ms->minrow + MENUROW, ms->mincol + MENUCOL, + ms->menus[(unsigned int)startmenu], 0, NORMALMENU); + + // Hide the garbage we left on the screen + cursoron(); + if (oldpage == ms->menupage) + cls(); + else + setdisppage(oldpage); + + // Return user choice + return rv; } pt_menusystem init_menusystem(const char *title) { - int i; - - ms = NULL; - ms = (pt_menusystem) malloc(sizeof(t_menusystem)); - if (ms == NULL) return NULL; - ms->nummenus = 0; - // Initialise all menu pointers - for (i=0; i < MAXMENUS; i++) ms->menus[i] = NULL; - - ms->title = (char *)malloc(TITLELEN+1); - if (title == NULL) - strcpy(ms->title,TITLESTR); // Copy string - else strcpy(ms->title,title); - - // Timeout settings - ms->tm_stepsize = TIMEOUTSTEPSIZE; - ms->tm_numsteps = TIMEOUTNUMSTEPS; - - ms->normalattr[NOHLITE] = NORMALATTR; - ms->normalattr[HLITE] = NORMALHLITE; - - ms->reverseattr[NOHLITE] = REVERSEATTR; - ms->reverseattr[HLITE] = REVERSEHLITE; - - ms->inactattr[NOHLITE] = INACTATTR; - ms->inactattr[HLITE] = INACTHLITE; - - ms->revinactattr[NOHLITE] = REVINACTATTR; - ms->revinactattr[HLITE] = REVINACTHLITE; - - ms->statusattr[NOHLITE] = STATUSATTR; - ms->statusattr[HLITE] = STATUSHLITE; - - ms->statline = STATLINE; - ms->tfillchar= TFILLCHAR; - ms->titleattr= TITLEATTR; - - ms->fillchar = FILLCHAR; - ms->fillattr = FILLATTR; - ms->spacechar= SPACECHAR; - ms->shadowattr = SHADOWATTR; - - ms->menupage = MENUPAGE; // Usually no need to change this at all - - // Initialise all handlers - ms->handler = NULL; - ms->keys_handler = NULL; - ms->ontimeout=NULL; // No timeout handler - ms->tm_total_timeout = 0; - ms->tm_sofar_timeout = 0; - ms->ontotaltimeout = NULL; - - // Setup ACTION_{,IN}VALID - ACTION_VALID.valid=1; - ACTION_VALID.refresh=0; - ACTION_INVALID.valid = 0; - ACTION_INVALID.refresh = 0; - - // Figure out the size of the screen we are in now. - // By default we use the whole screen for our menu - ms->minrow = ms->mincol = 0; - ms->numcols = getnumcols(); - ms->numrows = getnumrows(); - ms->maxcol = ms->numcols - 1; - ms->maxrow = ms->numrows - 1; - - // How many entries per menu can we display at a time - ms->maxmenuheight = ms->maxrow - ms->minrow - 3; - if (ms->maxmenuheight > MAXMENUHEIGHT) - ms->maxmenuheight= MAXMENUHEIGHT; - - // Set up the look of the box - set_box_type(MENUBOXTYPE); - return ms; + int i; + + ms = NULL; + ms = (pt_menusystem) malloc(sizeof(t_menusystem)); + if (ms == NULL) + return NULL; + ms->nummenus = 0; + // Initialise all menu pointers + for (i = 0; i < MAXMENUS; i++) + ms->menus[i] = NULL; + + ms->title = (char *)malloc(TITLELEN + 1); + if (title == NULL) + strcpy(ms->title, TITLESTR); // Copy string + else + strcpy(ms->title, title); + + // Timeout settings + ms->tm_stepsize = TIMEOUTSTEPSIZE; + ms->tm_numsteps = TIMEOUTNUMSTEPS; + + ms->normalattr[NOHLITE] = NORMALATTR; + ms->normalattr[HLITE] = NORMALHLITE; + + ms->reverseattr[NOHLITE] = REVERSEATTR; + ms->reverseattr[HLITE] = REVERSEHLITE; + + ms->inactattr[NOHLITE] = INACTATTR; + ms->inactattr[HLITE] = INACTHLITE; + + ms->revinactattr[NOHLITE] = REVINACTATTR; + ms->revinactattr[HLITE] = REVINACTHLITE; + + ms->statusattr[NOHLITE] = STATUSATTR; + ms->statusattr[HLITE] = STATUSHLITE; + + ms->statline = STATLINE; + ms->tfillchar = TFILLCHAR; + ms->titleattr = TITLEATTR; + + ms->fillchar = FILLCHAR; + ms->fillattr = FILLATTR; + ms->spacechar = SPACECHAR; + ms->shadowattr = SHADOWATTR; + + ms->menupage = MENUPAGE; // Usually no need to change this at all + + // Initialise all handlers + ms->handler = NULL; + ms->keys_handler = NULL; + ms->ontimeout = NULL; // No timeout handler + ms->tm_total_timeout = 0; + ms->tm_sofar_timeout = 0; + ms->ontotaltimeout = NULL; + + // Setup ACTION_{,IN}VALID + ACTION_VALID.valid = 1; + ACTION_VALID.refresh = 0; + ACTION_INVALID.valid = 0; + ACTION_INVALID.refresh = 0; + + // Figure out the size of the screen we are in now. + // By default we use the whole screen for our menu + ms->minrow = ms->mincol = 0; + ms->numcols = getnumcols(); + ms->numrows = getnumrows(); + ms->maxcol = ms->numcols - 1; + ms->maxrow = ms->numrows - 1; + + // How many entries per menu can we display at a time + ms->maxmenuheight = ms->maxrow - ms->minrow - 3; + if (ms->maxmenuheight > MAXMENUHEIGHT) + ms->maxmenuheight = MAXMENUHEIGHT; + + // Set up the look of the box + set_box_type(MENUBOXTYPE); + return ms; } -void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected) +void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal, + uchar inactiveselected) { - if (normal != 0xFF) ms->normalattr[0] = normal; - if (selected != 0xFF) ms->reverseattr[0] = selected; - if (inactivenormal != 0xFF) ms->inactattr[0] = inactivenormal; - if (inactiveselected != 0xFF) ms->revinactattr[0] = inactiveselected; + if (normal != 0xFF) + ms->normalattr[0] = normal; + if (selected != 0xFF) + ms->reverseattr[0] = selected; + if (inactivenormal != 0xFF) + ms->inactattr[0] = inactivenormal; + if (inactiveselected != 0xFF) + ms->revinactattr[0] = inactiveselected; } -void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected) +void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal, + uchar inactiveselected) { - if (normal != 0xFF) ms->normalattr[1] = normal; - if (selected != 0xFF) ms->reverseattr[1] = selected; - if (inactivenormal != 0xFF) ms->inactattr[1] = inactivenormal; - if (inactiveselected != 0xFF) ms->revinactattr[1] = inactiveselected; + if (normal != 0xFF) + ms->normalattr[1] = normal; + if (selected != 0xFF) + ms->reverseattr[1] = selected; + if (inactivenormal != 0xFF) + ms->inactattr[1] = inactivenormal; + if (inactiveselected != 0xFF) + ms->revinactattr[1] = inactiveselected; } void set_status_info(uchar statusattr, uchar statushlite, uchar statline) { - if (statusattr != 0xFF) ms->statusattr[NOHLITE] = statusattr; - if (statushlite!= 0xFF) ms->statusattr[HLITE] = statushlite; - // statline is relative to minrow - if (statline >= ms->numrows) statline = ms->numrows - 1; - ms->statline = statline; // relative to ms->minrow, 0 based + if (statusattr != 0xFF) + ms->statusattr[NOHLITE] = statusattr; + if (statushlite != 0xFF) + ms->statusattr[HLITE] = statushlite; + // statline is relative to minrow + if (statline >= ms->numrows) + statline = ms->numrows - 1; + ms->statline = statline; // relative to ms->minrow, 0 based } void set_title_info(uchar tfillchar, uchar titleattr) { - if (tfillchar != 0xFF) ms->tfillchar = tfillchar; - if (titleattr != 0xFF) ms->titleattr = titleattr; + if (tfillchar != 0xFF) + ms->tfillchar = tfillchar; + if (titleattr != 0xFF) + ms->titleattr = titleattr; } -void set_misc_info(uchar fillchar, uchar fillattr,uchar spacechar, uchar shadowattr) +void set_misc_info(uchar fillchar, uchar fillattr, uchar spacechar, + uchar shadowattr) { - if (fillchar != 0xFF) ms->fillchar = fillchar; - if (fillattr != 0xFF) ms->fillattr = fillattr; - if (spacechar != 0xFF) ms->spacechar = spacechar; - if (shadowattr!= 0xFF) ms->shadowattr= shadowattr; + if (fillchar != 0xFF) + ms->fillchar = fillchar; + if (fillattr != 0xFF) + ms->fillattr = fillattr; + if (spacechar != 0xFF) + ms->spacechar = spacechar; + if (shadowattr != 0xFF) + ms->shadowattr = shadowattr; } void set_box_type(boxtype bt) { - uchar *bxc; - ms->menubt = bt; - bxc = getboxchars(bt); - ms->box_horiz = bxc[BOX_HORIZ]; // The char used to draw top line - ms->box_ltrt = bxc[BOX_LTRT]; - ms->box_rtlt = bxc[BOX_RTLT]; + uchar *bxc; + ms->menubt = bt; + bxc = getboxchars(bt); + ms->box_horiz = bxc[BOX_HORIZ]; // The char used to draw top line + ms->box_ltrt = bxc[BOX_LTRT]; + ms->box_rtlt = bxc[BOX_RTLT]; } void set_menu_options(uchar maxmenuheight) { - if (maxmenuheight != 0xFF) ms->maxmenuheight = maxmenuheight; + if (maxmenuheight != 0xFF) + ms->maxmenuheight = maxmenuheight; } // Set the window which menusystem should use void set_window_size(uchar top, uchar left, uchar bot, uchar right) { - uchar nr,nc; - if ((top > bot) || (left > right)) return; // Sorry no change will happen here - nr = getnumrows(); - nc = getnumcols(); - if (bot >= nr) bot = nr-1; - if (right >= nc) right = nc-1; - ms->minrow = top; - ms->mincol = left; - ms->maxrow = bot; - ms->maxcol = right; - ms->numcols = right - left + 1; - ms->numrows = bot - top + 1; - if (ms->statline >= ms->numrows) ms->statline = ms->numrows - 1; // Clip statline if need be + uchar nr, nc; + if ((top > bot) || (left > right)) + return; // Sorry no change will happen here + nr = getnumrows(); + nc = getnumcols(); + if (bot >= nr) + bot = nr - 1; + if (right >= nc) + right = nc - 1; + ms->minrow = top; + ms->mincol = left; + ms->maxrow = bot; + ms->maxcol = right; + ms->numcols = right - left + 1; + ms->numrows = bot - top + 1; + if (ms->statline >= ms->numrows) + ms->statline = ms->numrows - 1; // Clip statline if need be } -void reg_handler( t_handler htype, void * handler) +void reg_handler(t_handler htype, void *handler) { - // If bad value set to default screen handler - switch(htype) { + // If bad value set to default screen handler + switch (htype) { case HDLR_KEYS: - ms->keys_handler = (t_keys_handler) handler; - break; + ms->keys_handler = (t_keys_handler) handler; + break; default: - ms->handler = (t_menusystem_handler) handler; - break; - } + ms->handler = (t_menusystem_handler) handler; + break; + } } void unreg_handler(t_handler htype) { - switch(htype) { + switch (htype) { case HDLR_KEYS: - ms->keys_handler = NULL; - break; + ms->keys_handler = NULL; + break; default: - ms->handler = NULL; - break; - } + ms->handler = NULL; + break; + } } -void reg_ontimeout(t_timeout_handler handler, unsigned int numsteps, unsigned int stepsize) +void reg_ontimeout(t_timeout_handler handler, unsigned int numsteps, + unsigned int stepsize) { - ms->ontimeout = handler; - if (numsteps != 0) ms->tm_numsteps = numsteps; - if (stepsize != 0) ms->tm_stepsize = stepsize; + ms->ontimeout = handler; + if (numsteps != 0) + ms->tm_numsteps = numsteps; + if (stepsize != 0) + ms->tm_stepsize = stepsize; } void unreg_ontimeout() { - ms->ontimeout = NULL; + ms->ontimeout = NULL; } -void reg_ontotaltimeout (t_timeout_handler handler, unsigned long numcentiseconds) +void reg_ontotaltimeout(t_timeout_handler handler, + unsigned long numcentiseconds) { - if (numcentiseconds != 0) { - ms->ontotaltimeout = handler; - ms->tm_total_timeout = numcentiseconds*10; // to convert to milliseconds - ms->tm_sofar_timeout = 0; - } + if (numcentiseconds != 0) { + ms->ontotaltimeout = handler; + ms->tm_total_timeout = numcentiseconds * 10; // to convert to milliseconds + ms->tm_sofar_timeout = 0; + } } void unreg_ontotaltimeout() { - ms->ontotaltimeout = NULL; + ms->ontotaltimeout = NULL; } - int next_visible(pt_menu menu, int index) { - int ans; - if (index < 0) ans = 0 ; - else if (index >= menu->numitems) ans = menu->numitems-1; - else ans = index; - while ((ans < menu->numitems-1) && - ((menu->items[ans]->action == OPT_INVISIBLE) || - (menu->items[ans]->action == OPT_SEP))) - ans++; - return ans; + int ans; + if (index < 0) + ans = 0; + else if (index >= menu->numitems) + ans = menu->numitems - 1; + else + ans = index; + while ((ans < menu->numitems - 1) && + ((menu->items[ans]->action == OPT_INVISIBLE) || + (menu->items[ans]->action == OPT_SEP))) + ans++; + return ans; } -int prev_visible(pt_menu menu, int index) // Return index of prev visible +int prev_visible(pt_menu menu, int index) // Return index of prev visible { - int ans; - if (index < 0) ans = 0; - else if (index >= menu->numitems) ans = menu->numitems-1; - else ans = index; - while ((ans > 0) && - ((menu->items[ans]->action == OPT_INVISIBLE) || - (menu->items[ans]->action == OPT_SEP))) - ans--; - return ans; + int ans; + if (index < 0) + ans = 0; + else if (index >= menu->numitems) + ans = menu->numitems - 1; + else + ans = index; + while ((ans > 0) && + ((menu->items[ans]->action == OPT_INVISIBLE) || + (menu->items[ans]->action == OPT_SEP))) + ans--; + return ans; } int next_visible_sep(pt_menu menu, int index) { - int ans; - if (index < 0) ans = 0 ; - else if (index >= menu->numitems) ans = menu->numitems-1; - else ans = index; - while ((ans < menu->numitems-1) && - (menu->items[ans]->action == OPT_INVISIBLE)) - ans++; - return ans; + int ans; + if (index < 0) + ans = 0; + else if (index >= menu->numitems) + ans = menu->numitems - 1; + else + ans = index; + while ((ans < menu->numitems - 1) && + (menu->items[ans]->action == OPT_INVISIBLE)) + ans++; + return ans; } -int prev_visible_sep(pt_menu menu, int index) // Return index of prev visible +int prev_visible_sep(pt_menu menu, int index) // Return index of prev visible { - int ans; - if (index < 0) ans = 0; - else if (index >= menu->numitems) ans = menu->numitems-1; - else ans = index; - while ((ans > 0) && - (menu->items[ans]->action == OPT_INVISIBLE)) - ans--; - return ans; + int ans; + if (index < 0) + ans = 0; + else if (index >= menu->numitems) + ans = menu->numitems - 1; + else + ans = index; + while ((ans > 0) && (menu->items[ans]->action == OPT_INVISIBLE)) + ans--; + return ans; } -int calc_visible(pt_menu menu,int first) +int calc_visible(pt_menu menu, int first) { - int ans,i; - - if (menu == NULL) return 0; - ans = 0; - for (i=first; i < menu->numitems; i++) - if (menu->items[i]->action != OPT_INVISIBLE) ans++; - return ans; + int ans, i; + + if (menu == NULL) + return 0; + ans = 0; + for (i = first; i < menu->numitems; i++) + if (menu->items[i]->action != OPT_INVISIBLE) + ans++; + return ans; } // is curr visible if first entry is first? -int isvisible(pt_menu menu,int first, int curr) +int isvisible(pt_menu menu, int first, int curr) { - if (curr < first) return 0; - return (calc_visible(menu,first)-calc_visible(menu,curr) < menu->menuheight); + if (curr < first) + return 0; + return (calc_visible(menu, first) - calc_visible(menu, curr) < + menu->menuheight); } // Calculate the first entry to be displayed // so that curr is visible and make curr as late as possible -int calc_first_late(pt_menu menu,int curr) +int calc_first_late(pt_menu menu, int curr) { - int ans,i,nv; - - nv = calc_visible(menu,0); - if (nv <= menu->menuheight) return 0; - // Start with curr and go back menu->menuheight times - ans = curr+1; - for (i=0; i < menu->menuheight; i++) - ans = prev_visible_sep(menu,ans-1); - return ans; + int ans, i, nv; + + nv = calc_visible(menu, 0); + if (nv <= menu->menuheight) + return 0; + // Start with curr and go back menu->menuheight times + ans = curr + 1; + for (i = 0; i < menu->menuheight; i++) + ans = prev_visible_sep(menu, ans - 1); + return ans; } // Calculate the first entry to be displayed // so that curr is visible and make curr as early as possible -int calc_first_early(pt_menu menu,int curr) +int calc_first_early(pt_menu menu, int curr) { - int ans,i,nv; - - nv = calc_visible(menu,0); - if (nv <= menu->menuheight) return 0; - // Start with curr and go back till >= menu->menuheight - // items are visible - nv = calc_visible(menu,curr); // Already nv of them are visible - ans = curr; - for (i=0; i < menu->menuheight - nv; i++) - ans = prev_visible_sep(menu,ans-1); - return ans; + int ans, i, nv; + + nv = calc_visible(menu, 0); + if (nv <= menu->menuheight) + return 0; + // Start with curr and go back till >= menu->menuheight + // items are visible + nv = calc_visible(menu, curr); // Already nv of them are visible + ans = curr; + for (i = 0; i < menu->menuheight - nv; i++) + ans = prev_visible_sep(menu, ans - 1); + return ans; } // Create a new menu and return its position uchar add_menu(const char *title, int maxmenusize) { - int num,i; - pt_menu m; - - num = ms->nummenus; - if (num >= MAXMENUS) return -1; - m = NULL; - m = (pt_menu) malloc(sizeof(t_menu)); - if (m == NULL) return -1; - ms->menus[num] = m; - m->numitems = 0; - m->name = NULL; - m->row = 0xFF; - m->col = 0xFF; - if (maxmenusize < 1) - m->maxmenusize = MAXMENUSIZE; - else m->maxmenusize = maxmenusize; - m->items = (pt_menuitem *) malloc(sizeof(pt_menuitem)*(m->maxmenusize)); - for (i=0; i < m->maxmenusize; i++) m->items[i] = NULL; - - m->title = (char *)malloc(MENULEN+1); - if (title) - { - if (strlen(title) > MENULEN - 2) - strcpy(m->title,TITLELONG); - else strcpy(m->title,title); - } - else strcpy(m->title,EMPTYSTR); - m ->menuwidth = strlen(m->title); - ms->nummenus ++; - return ms->nummenus - 1; + int num, i; + pt_menu m; + + num = ms->nummenus; + if (num >= MAXMENUS) + return -1; + m = NULL; + m = (pt_menu) malloc(sizeof(t_menu)); + if (m == NULL) + return -1; + ms->menus[num] = m; + m->numitems = 0; + m->name = NULL; + m->row = 0xFF; + m->col = 0xFF; + if (maxmenusize < 1) + m->maxmenusize = MAXMENUSIZE; + else + m->maxmenusize = maxmenusize; + m->items = (pt_menuitem *) malloc(sizeof(pt_menuitem) * (m->maxmenusize)); + for (i = 0; i < m->maxmenusize; i++) + m->items[i] = NULL; + + m->title = (char *)malloc(MENULEN + 1); + if (title) { + if (strlen(title) > MENULEN - 2) + strcpy(m->title, TITLELONG); + else + strcpy(m->title, title); + } else + strcpy(m->title, EMPTYSTR); + m->menuwidth = strlen(m->title); + ms->nummenus++; + return ms->nummenus - 1; } -void set_menu_name(const char *name) // Set the "name" of this menu +void set_menu_name(const char *name) // Set the "name" of this menu { - pt_menu m; + pt_menu m; - m = ms->menus[ms->nummenus-1]; - if (m->name) // Free up previous name - { - free(m->name); - m -> name = NULL; - } - - if (name) + m = ms->menus[ms->nummenus - 1]; + if (m->name) // Free up previous name { - m->name = (char *)malloc(strlen(name)+1); - strcpy(m->name,name); + free(m->name); + m->name = NULL; + } + + if (name) { + m->name = (char *)malloc(strlen(name) + 1); + strcpy(m->name, name); } } // Create a new named menu and return its position -uchar add_named_menu(const char * name, const char *title, int maxmenusize) +uchar add_named_menu(const char *name, const char *title, int maxmenusize) { - add_menu(title,maxmenusize); - set_menu_name(name); - return ms->nummenus - 1; + add_menu(title, maxmenusize); + set_menu_name(name); + return ms->nummenus - 1; } -void set_menu_pos(uchar row,uchar col) // Set the position of this menu. +void set_menu_pos(uchar row, uchar col) // Set the position of this menu. { - pt_menu m; + pt_menu m; - m = ms->menus[ms->nummenus-1]; - m->row = row; - m->col = col; + m = ms->menus[ms->nummenus - 1]; + m->row = row; + m->col = col; } -pt_menuitem add_sep() // Add a separator to current menu +pt_menuitem add_sep() // Add a separator to current menu { - pt_menuitem mi; - pt_menu m; - - m = (ms->menus[ms->nummenus-1]); - mi = NULL; - mi = (pt_menuitem) malloc(sizeof(t_menuitem)); - if (mi == NULL) return NULL; - m->items[(unsigned int)m->numitems] = mi; - mi->handler = NULL; // No handler - mi->item = mi->status = mi->data = NULL; - mi->action = OPT_SEP; - mi->index = m->numitems++; - mi->parindex = ms->nummenus-1; - mi->shortcut = 0; - mi->helpid=0; - return mi; + pt_menuitem mi; + pt_menu m; + + m = (ms->menus[ms->nummenus - 1]); + mi = NULL; + mi = (pt_menuitem) malloc(sizeof(t_menuitem)); + if (mi == NULL) + return NULL; + m->items[(unsigned int)m->numitems] = mi; + mi->handler = NULL; // No handler + mi->item = mi->status = mi->data = NULL; + mi->action = OPT_SEP; + mi->index = m->numitems++; + mi->parindex = ms->nummenus - 1; + mi->shortcut = 0; + mi->helpid = 0; + return mi; } // Add item to the "current" menu pt_menuitem add_item(const char *item, const char *status, t_action action, const char *data, uchar itemdata) { - pt_menuitem mi; - pt_menu m; - const char *str; - uchar inhlite=0; // Are we inside hlite area - - m = (ms->menus[ms->nummenus-1]); - mi = NULL; - mi = (pt_menuitem) malloc(sizeof(t_menuitem)); - if (mi == NULL) return NULL; - m->items[(unsigned int) m->numitems] = mi; - mi->handler = NULL; // No handler - - // Allocate space to store stuff - mi->item = (char *)malloc(MENULEN+1); - mi->status = (char *)malloc(STATLEN+1); - mi->data = (char *)malloc(ACTIONLEN+1); - - if (item) { - if (strlen(item) > MENULEN) { - strcpy(mi->item,ITEMLONG); - } else { - strcpy(mi->item,item); - } - if (strlen(mi->item) > m->menuwidth) m->menuwidth = strlen(mi->item); - } else strcpy(mi->item,EMPTYSTR); - - if (status) { - if (strlen(status) > STATLEN) { - strcpy(mi->status,STATUSLONG); - } else { - strcpy(mi->status,status); - } - } else strcpy(mi->status,EMPTYSTR); - - mi->action=action; - str = mi->item; - mi->shortcut = 0; - mi->helpid = 0xFFFF; - inhlite = 0; // We have not yet seen an ENABLEHLITE char - // Find the first char in [A-Za-z0-9] after ENABLEHLITE and not arg to control char - while (*str) - { - if (*str == ENABLEHLITE) - { - inhlite=1; + pt_menuitem mi; + pt_menu m; + const char *str; + uchar inhlite = 0; // Are we inside hlite area + + m = (ms->menus[ms->nummenus - 1]); + mi = NULL; + mi = (pt_menuitem) malloc(sizeof(t_menuitem)); + if (mi == NULL) + return NULL; + m->items[(unsigned int)m->numitems] = mi; + mi->handler = NULL; // No handler + + // Allocate space to store stuff + mi->item = (char *)malloc(MENULEN + 1); + mi->status = (char *)malloc(STATLEN + 1); + mi->data = (char *)malloc(ACTIONLEN + 1); + + if (item) { + if (strlen(item) > MENULEN) { + strcpy(mi->item, ITEMLONG); + } else { + strcpy(mi->item, item); } - if (*str == DISABLEHLITE) - { - inhlite = 0; + if (strlen(mi->item) > m->menuwidth) + m->menuwidth = strlen(mi->item); + } else + strcpy(mi->item, EMPTYSTR); + + if (status) { + if (strlen(status) > STATLEN) { + strcpy(mi->status, STATUSLONG); + } else { + strcpy(mi->status, status); } - if ( (inhlite == 1) && - (((*str >= 'A') && (*str <= 'Z')) || - ((*str >= 'a') && (*str <= 'z')) || - ((*str >= '0') && (*str <= '9')))) - { - mi->shortcut=*str; - break; + } else + strcpy(mi->status, EMPTYSTR); + + mi->action = action; + str = mi->item; + mi->shortcut = 0; + mi->helpid = 0xFFFF; + inhlite = 0; // We have not yet seen an ENABLEHLITE char + // Find the first char in [A-Za-z0-9] after ENABLEHLITE and not arg to control char + while (*str) { + if (*str == ENABLEHLITE) { + inhlite = 1; } - ++str; - } - if ((mi->shortcut >= 'A') && (mi->shortcut <= 'Z')) // Make lower case - mi->shortcut = mi->shortcut -'A'+'a'; - - if (data) { - if (strlen(data) > ACTIONLEN) { - strcpy(mi->data,ACTIONLONG); - } else { - strcpy(mi->data,data); + if (*str == DISABLEHLITE) { + inhlite = 0; + } + if ((inhlite == 1) && + (((*str >= 'A') && (*str <= 'Z')) || + ((*str >= 'a') && (*str <= 'z')) || + ((*str >= '0') && (*str <= '9')))) { + mi->shortcut = *str; + break; + } + ++str; } - } else strcpy(mi->data,EMPTYSTR); + if ((mi->shortcut >= 'A') && (mi->shortcut <= 'Z')) // Make lower case + mi->shortcut = mi->shortcut - 'A' + 'a'; + + if (data) { + if (strlen(data) > ACTIONLEN) { + strcpy(mi->data, ACTIONLONG); + } else { + strcpy(mi->data, data); + } + } else + strcpy(mi->data, EMPTYSTR); - switch (action) - { + switch (action) { case OPT_SUBMENU: - mi->itemdata.submenunum = itemdata; - break; + mi->itemdata.submenunum = itemdata; + break; case OPT_CHECKBOX: - mi->itemdata.checked = itemdata; - break; + mi->itemdata.checked = itemdata; + break; case OPT_RADIOMENU: - mi->itemdata.radiomenunum = itemdata; - if (mi->data) free(mi->data); - mi->data = NULL; // No selection made - break; - default: // to keep the compiler happy - break; + mi->itemdata.radiomenunum = itemdata; + if (mi->data) + free(mi->data); + mi->data = NULL; // No selection made + break; + default: // to keep the compiler happy + break; } - mi->index = m->numitems++; - mi->parindex = ms->nummenus-1; - return mi; + mi->index = m->numitems++; + mi->parindex = ms->nummenus - 1; + return mi; } // Set the shortcut key for the current item -void set_item_options(uchar shortcut,int helpid) +void set_item_options(uchar shortcut, int helpid) { - pt_menuitem mi; - pt_menu m; - - m = (ms->menus[ms->nummenus-1]); - if (m->numitems <= 0) return; - mi = m->items[(unsigned int) m->numitems-1]; - - if (shortcut != 0xFF) mi->shortcut = shortcut; - if (helpid != 0xFFFF) mi->helpid = helpid; + pt_menuitem mi; + pt_menu m; + + m = (ms->menus[ms->nummenus - 1]); + if (m->numitems <= 0) + return; + mi = m->items[(unsigned int)m->numitems - 1]; + + if (shortcut != 0xFF) + mi->shortcut = shortcut; + if (helpid != 0xFFFF) + mi->helpid = helpid; } // Free internal datasutructures @@ -1251,50 +1340,49 @@ void close_menusystem(void) // append_line_helper(pt_menu menu,char *line) void append_line_helper(int menunum, char *line) { - pt_menu menu; - pt_menuitem mi,ri; - char *app; - int ctr; - char dp; - - - dp = getdisppage(); - menu = ms->menus[menunum]; - for (ctr = 0; ctr < (int) menu->numitems; ctr++) - { - mi = menu->items[ctr]; - app = NULL; //What to append - switch (mi->action) { - case OPT_CHECKBOX: - if (mi->itemdata.checked) app = mi->data; - break; - case OPT_RADIOMENU: - if (mi->data) { // Some selection has been made - ri = (pt_menuitem) (mi->data); - app = ri->data; - } - break; - case OPT_SUBMENU: - append_line_helper(mi->itemdata.submenunum,line); - break; - default: - break; - } - if (app) { - strcat(line," "); - strcat(line,app); - } - } + pt_menu menu; + pt_menuitem mi, ri; + char *app; + int ctr; + char dp; + + dp = getdisppage(); + menu = ms->menus[menunum]; + for (ctr = 0; ctr < (int)menu->numitems; ctr++) { + mi = menu->items[ctr]; + app = NULL; //What to append + switch (mi->action) { + case OPT_CHECKBOX: + if (mi->itemdata.checked) + app = mi->data; + break; + case OPT_RADIOMENU: + if (mi->data) { // Some selection has been made + ri = (pt_menuitem) (mi->data); + app = ri->data; + } + break; + case OPT_SUBMENU: + append_line_helper(mi->itemdata.submenunum, line); + break; + default: + break; + } + if (app) { + strcat(line, " "); + strcat(line, app); + } + } } - // Generate string based on state of checkboxes and radioitem in given menu // Assume line points to large enough buffer -void gen_append_line(const char *menu_name,char *line) +void gen_append_line(const char *menu_name, char *line) { - int menunum; + int menunum; - menunum = find_menu_num(menu_name); - if (menunum < 0) return; // No such menu - append_line_helper(menunum,line); + menunum = find_menu_num(menu_name); + if (menunum < 0) + return; // No such menu + append_line_helper(menunum, line); } diff --git a/com32/cmenu/libmenu/menu.h b/com32/cmenu/libmenu/menu.h index 9b009db1..68adf278 100644 --- a/com32/cmenu/libmenu/menu.h +++ b/com32/cmenu/libmenu/menu.h @@ -48,16 +48,16 @@ // Attributes #define NORMALATTR 0x17 -#define NORMALHLITE 0x1F // Normal Highlight attribute +#define NORMALHLITE 0x1F // Normal Highlight attribute #define REVERSEATTR 0x70 -#define REVERSEHLITE 0x78 // Reverse Hightlight attribute +#define REVERSEHLITE 0x78 // Reverse Hightlight attribute #define INACTATTR 0x18 -#define INACTHLITE 0x10 // Inactive Highlight attribute +#define INACTHLITE 0x10 // Inactive Highlight attribute #define REVINACTATTR 0x78 -#define REVINACTHLITE 0x70 // Reverse Inactive Highlight attr +#define REVINACTHLITE 0x70 // Reverse Inactive Highlight attr #define STATUSATTR 0x74 -#define STATUSHLITE 0x7B // Status highlight +#define STATUSHLITE 0x7B // Status highlight #define FILLCHAR 177 #define FILLATTR 0x01 @@ -67,45 +67,45 @@ #define TFILLCHAR ' ' #define TITLEATTR 0x70 -#define ENABLEHLITE '<' // Char which turns on highlight -#define DISABLEHLITE '>' // Char which turns off highlight -#define NOHLITE 0 // The offset into attrib array for non-hilite -#define HLITE 1 // The offset for Hlite attrib +#define ENABLEHLITE '<' // Char which turns on highlight +#define DISABLEHLITE '>' // Char which turns off highlight +#define NOHLITE 0 // The offset into attrib array for non-hilite +#define HLITE 1 // The offset for Hlite attrib -#define MOREABOVE 24 // char to print when more menu items available above -#define MOREBELOW 25 // more items available below -#define SCROLLBOX 176 // Filled char to display +#define MOREABOVE 24 // char to print when more menu items available above +#define MOREBELOW 25 // more items available below +#define SCROLLBOX 176 // Filled char to display // Attributes of the menu system -#define MAXMENUS 150 // Maximum number of menu's allowed -#define MAXMENUSIZE 60 // Default value for max num of entries in each menu -#define MAXMENUHEIGHT 20 // Maximum number of entries displayed -#define MENUBOXTYPE BOX_SINSIN // Default box type Look at tui.h for other values +#define MAXMENUS 150 // Maximum number of menu's allowed +#define MAXMENUSIZE 60 // Default value for max num of entries in each menu +#define MAXMENUHEIGHT 20 // Maximum number of entries displayed +#define MENUBOXTYPE BOX_SINSIN // Default box type Look at tui.h for other values // Upper bounds on lengths // We copy the given string, so user can reuse the space used to store incoming arguments. -#define MENULEN 78 // Each menu entry is atmost MENULEN chars -#define STATLEN 78 // Maximum length of status string -#define TITLELEN 78 // Maximum length of title string -#define ACTIONLEN 255 // Maximum length of an action string +#define MENULEN 78 // Each menu entry is atmost MENULEN chars +#define STATLEN 78 // Maximum length of status string +#define TITLELEN 78 // Maximum length of title string +#define ACTIONLEN 255 // Maximum length of an action string // Layout of menu -#define MENUROW 3 // Row where menu is displayed (relative to window) -#define MENUCOL 4 // Col where menu is displayed (relative to window) -#define MENUPAGE 1 // show in display page 1 -#define STATLINE 24 // Line number where status line starts (relative to window) +#define MENUROW 3 // Row where menu is displayed (relative to window) +#define MENUCOL 4 // Col where menu is displayed (relative to window) +#define MENUPAGE 1 // show in display page 1 +#define STATLINE 24 // Line number where status line starts (relative to window) // Used for printing debugging messages -#define DEBUGLINE 23 // debugging info goes here +#define DEBUGLINE 23 // debugging info goes here // Other Chars -#define SUBMENUCHAR 175 // This is >> symbol -#define RADIOMENUCHAR '>' // > symbol for radio menu? -#define EXITMENUCHAR 174 // This is << symbol -#define CHECKED 251 // Check mark -#define UNCHECKED 250 // Light bullet -#define RADIOSEL '.' // Current Radio Selection -#define RADIOUNSEL ' ' // Radio option not selected +#define SUBMENUCHAR 175 // This is >> symbol +#define RADIOMENUCHAR '>' // > symbol for radio menu? +#define EXITMENUCHAR 174 // This is << symbol +#define CHECKED 251 // Check mark +#define UNCHECKED 250 // Light bullet +#define RADIOSEL '.' // Current Radio Selection +#define RADIOUNSEL ' ' // Radio option not selected typedef unsigned char uchar; @@ -113,14 +113,15 @@ typedef unsigned char uchar; #define NORMALMENU 1 #define RADIOMENU 2 -typedef enum {OPT_INACTIVE, OPT_SUBMENU, OPT_RUN, OPT_EXITMENU, OPT_CHECKBOX, - OPT_RADIOMENU, OPT_SEP, OPT_INVISIBLE, - OPT_RADIOITEM} t_action; +typedef enum { OPT_INACTIVE, OPT_SUBMENU, OPT_RUN, OPT_EXITMENU, OPT_CHECKBOX, + OPT_RADIOMENU, OPT_SEP, OPT_INVISIBLE, + OPT_RADIOITEM +} t_action; typedef union { - uchar submenunum; // For submenu's - uchar checked; // For check boxes - uchar radiomenunum; // Item mapping to a radio menu + uchar submenunum; // For submenu's + uchar checked; // For check boxes + uchar radiomenunum; // Item mapping to a radio menu } t_itemdata; struct s_menuitem; @@ -128,127 +129,133 @@ struct s_menu; struct s_menusystem; typedef struct { - unsigned int valid :1; // Is action valid? - unsigned int refresh:1; // Should we recompute menu stuff? - unsigned int reserved:6; // For future expansion + unsigned int valid:1; // Is action valid? + unsigned int refresh:1; // Should we recompute menu stuff? + unsigned int reserved:6; // For future expansion } t_handler_return; -t_handler_return ACTION_VALID,ACTION_INVALID; // Specific values +t_handler_return ACTION_VALID, ACTION_INVALID; // Specific values -typedef t_handler_return (*t_item_handler)(struct s_menusystem *, struct s_menuitem *); -typedef void (*t_menusystem_handler)(struct s_menusystem *, struct s_menuitem *); -typedef void (*t_keys_handler)(struct s_menusystem *, struct s_menuitem *, - unsigned int scancode); +typedef t_handler_return(*t_item_handler) (struct s_menusystem *, + struct s_menuitem *); +typedef void (*t_menusystem_handler) (struct s_menusystem *, + struct s_menuitem *); +typedef void (*t_keys_handler) (struct s_menusystem *, struct s_menuitem *, + unsigned int scancode); // Last parameter = HIGH BYTE = scan code , LOW BYTE = ASCII CODE -typedef enum {HDLR_SCREEN, HDLR_KEYS } t_handler; +typedef enum { HDLR_SCREEN, HDLR_KEYS } t_handler; // Types of handlers for menu system // TIMEOUT is the list of possible values which can be returned by the handler // instructing the menusystem what to do. The default is CODE_WAIT -typedef enum {CODE_WAIT, CODE_ENTER, CODE_ESCAPE } TIMEOUTCODE; -typedef TIMEOUTCODE (*t_timeout_handler)(void); +typedef enum { CODE_WAIT, CODE_ENTER, CODE_ESCAPE } TIMEOUTCODE; +typedef TIMEOUTCODE(*t_timeout_handler) (void); typedef struct s_menuitem { - char *item; - char *status; - char *data; // string containing kernel to run.. but... - // for radio menu's this is a pointer to the item selected or NULL (initially) - // for submenu's this string could be name of menu - void * extra_data; // Any other data user can point to - unsigned int helpid; // Used for Context sensitive help - t_item_handler handler; // Pointer to function of type menufn - t_action action; - t_itemdata itemdata; // Data depends on action value - uchar shortcut; // one of [A-Za-z0-9] shortcut for this menu item - uchar index; // Index within the menu array - uchar parindex; // Index of the menu in which this item appears. + char *item; + char *status; + char *data; // string containing kernel to run.. but... + // for radio menu's this is a pointer to the item selected or NULL (initially) + // for submenu's this string could be name of menu + void *extra_data; // Any other data user can point to + unsigned int helpid; // Used for Context sensitive help + t_item_handler handler; // Pointer to function of type menufn + t_action action; + t_itemdata itemdata; // Data depends on action value + uchar shortcut; // one of [A-Za-z0-9] shortcut for this menu item + uchar index; // Index within the menu array + uchar parindex; // Index of the menu in which this item appears. } t_menuitem; -typedef t_menuitem *pt_menuitem; // Pointer to type menuitem +typedef t_menuitem *pt_menuitem; // Pointer to type menuitem typedef struct s_menu { - pt_menuitem *items; // pointer to array of pointer to menuitems - char *title; // Title string for menu - char *name; // menu can be referred to by this string - int maxmenusize; // the size of array allocated - uchar numitems; // how many items do we actually have - uchar menuwidth; - uchar row,col; // Position where this menu should be displayed - uchar menuheight; // Maximum number of items to be displayed + pt_menuitem *items; // pointer to array of pointer to menuitems + char *title; // Title string for menu + char *name; // menu can be referred to by this string + int maxmenusize; // the size of array allocated + uchar numitems; // how many items do we actually have + uchar menuwidth; + uchar row, col; // Position where this menu should be displayed + uchar menuheight; // Maximum number of items to be displayed } t_menu; -typedef t_menu *pt_menu; // Pointer to type menu +typedef t_menu *pt_menu; // Pointer to type menu typedef struct s_menusystem { - pt_menu menus[MAXMENUS]; - char *title; - t_menusystem_handler handler; // Menu system handler - t_keys_handler keys_handler; // Handler for unknown keys - t_timeout_handler ontimeout; // Timeout handler - unsigned long tm_numsteps; - // Time to wait for key press=numsteps * stepsize milliseconds - unsigned int tm_stepsize; // Timeout step size (in milliseconds) - // Total timeout max time spent idle before we call handler - unsigned long tm_total_timeout; // (in milli seconds) - unsigned long tm_sofar_timeout; // All accumulated timeout - // total timeout handler - t_timeout_handler ontotaltimeout; // Total timeout handler - - int maxmenuheight; - uchar nummenus; - uchar normalattr[2]; // [0] is non-hlite attr, [1] is hlite attr - uchar reverseattr[2]; - uchar inactattr[2]; - uchar revinactattr[2]; - uchar statusattr[2]; - uchar fillchar; - uchar fillattr; - uchar spacechar; - uchar tfillchar; - uchar titleattr; - uchar shadowattr; - uchar statline; - uchar menupage; - uchar maxrow,minrow,numrows; // Number of rows in the window - uchar maxcol,mincol,numcols; // Number of columns in the window - - // Menu box look - boxtype menubt; // What type of boxes should be drawn - char box_horiz,box_ltrt,box_rtlt; // Some chars of the box, for redrawing portions of the box + pt_menu menus[MAXMENUS]; + char *title; + t_menusystem_handler handler; // Menu system handler + t_keys_handler keys_handler; // Handler for unknown keys + t_timeout_handler ontimeout; // Timeout handler + unsigned long tm_numsteps; + // Time to wait for key press=numsteps * stepsize milliseconds + unsigned int tm_stepsize; // Timeout step size (in milliseconds) + // Total timeout max time spent idle before we call handler + unsigned long tm_total_timeout; // (in milli seconds) + unsigned long tm_sofar_timeout; // All accumulated timeout + // total timeout handler + t_timeout_handler ontotaltimeout; // Total timeout handler + + int maxmenuheight; + uchar nummenus; + uchar normalattr[2]; // [0] is non-hlite attr, [1] is hlite attr + uchar reverseattr[2]; + uchar inactattr[2]; + uchar revinactattr[2]; + uchar statusattr[2]; + uchar fillchar; + uchar fillattr; + uchar spacechar; + uchar tfillchar; + uchar titleattr; + uchar shadowattr; + uchar statline; + uchar menupage; + uchar maxrow, minrow, numrows; // Number of rows in the window + uchar maxcol, mincol, numcols; // Number of columns in the window + + // Menu box look + boxtype menubt; // What type of boxes should be drawn + char box_horiz, box_ltrt, box_rtlt; // Some chars of the box, for redrawing portions of the box } t_menusystem; -typedef t_menusystem *pt_menusystem; // Pointer to type menusystem +typedef t_menusystem *pt_menusystem; // Pointer to type menusystem pt_menuitem showmenus(uchar startmenu); pt_menusystem init_menusystem(const char *title); -void close_menusystem(); // Deallocate memory used +void close_menusystem(); // Deallocate memory used -void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected); +void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal, + uchar inactiveselected); -void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected); +void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal, + uchar inactiveselected); void set_status_info(uchar statusattr, uchar statushlite, uchar statline); void set_title_info(uchar tfillchar, uchar titleattr); -void set_misc_info(uchar fillchar, uchar fillattr,uchar spacechar, uchar shadowattr); +void set_misc_info(uchar fillchar, uchar fillattr, uchar spacechar, + uchar shadowattr); void set_box_type(boxtype bt); -void set_window_size(uchar top, uchar left, uchar bot, uchar right); // Set the window which menusystem should use +void set_window_size(uchar top, uchar left, uchar bot, uchar right); // Set the window which menusystem should use void set_menu_options(uchar maxmenuheight); // maximum height of a menu -void reg_handler(t_handler htype, void * handler); // Register handler +void reg_handler(t_handler htype, void *handler); // Register handler -void unreg_handler( t_handler htype); +void unreg_handler(t_handler htype); -void reg_ontimeout(t_timeout_handler, unsigned int numsteps, unsigned int stepsize); +void reg_ontimeout(t_timeout_handler, unsigned int numsteps, + unsigned int stepsize); // Set timeout handler, set 0 for default values. // So stepsize=0 means numsteps is measured in centiseconds. void unreg_ontimeout(); @@ -266,18 +273,19 @@ uchar add_menu(const char *title, int maxmenusize); // Create a named menu and return its position uchar add_named_menu(const char *name, const char *title, int maxmenusize); -void set_menu_pos(uchar row,uchar col); // Set the position of this menu. +void set_menu_pos(uchar row, uchar col); // Set the position of this menu. // Add item to the "current" menu -pt_menuitem add_item(const char *item, const char *status, t_action action, const char *data, uchar itemdata); +pt_menuitem add_item(const char *item, const char *status, t_action action, + const char *data, uchar itemdata); // Set shortcut key and help id -void set_item_options(uchar shortcut,int helpid); +void set_item_options(uchar shortcut, int helpid); // Set the shortcut key for the current item static inline void set_shortcut(uchar shortcut) { - set_item_options(shortcut,0xFFFF); + set_item_options(shortcut, 0xFFFF); } // Add a separator to the "current" menu @@ -286,6 +294,6 @@ pt_menuitem add_sep(); // Generate string based on state of checkboxes and radioitem in given menu // and append string to existing contents of "line" // line must have enough space allocated -void gen_append_line(const char *menu_name,char *line); +void gen_append_line(const char *menu_name, char *line); #endif diff --git a/com32/cmenu/libmenu/passwords.c b/com32/cmenu/libmenu/passwords.c index 40b5c49f..06f4cfb3 100644 --- a/com32/cmenu/libmenu/passwords.c +++ b/com32/cmenu/libmenu/passwords.c @@ -19,122 +19,141 @@ #define MAX_LINE 512 // Max line length in a pwdfile -p_pwdentry userdb[MAX_USERS]; // Array of pointers -int numusers; // Actual number of users +p_pwdentry userdb[MAX_USERS]; // Array of pointers +int numusers; // Actual number of users // returns true or false, i.e. 1 or 0 -char authenticate_user(const char * username, const char* pwd) +char authenticate_user(const char *username, const char *pwd) { - char salt[12]; - int i; + char salt[12]; + int i; - for (i=0; i< numusers; i++) { - if (userdb[i] == NULL) continue; - if (strcmp(username,userdb[i]->username)==0) { - strcpy(salt, userdb[i]->pwdhash); - salt[2] = '\0'; - if (strcmp(userdb[i]->pwdhash,crypt(pwd,salt))==0) return 1; + for (i = 0; i < numusers; i++) { + if (userdb[i] == NULL) + continue; + if (strcmp(username, userdb[i]->username) == 0) { + strcpy(salt, userdb[i]->pwdhash); + salt[2] = '\0'; + if (strcmp(userdb[i]->pwdhash, crypt(pwd, salt)) == 0) + return 1; + } } - } - return 0; + return 0; } // Does user USERNAME have permission PERM char isallowed(const char *username, const char *perm) { - int i; - char *dperm; - char *tmp; + int i; + char *dperm; + char *tmp; - // If no users, then everybody is allowed to do everything - if (numusers == 0) return 1; - if (strcmp(username,GUEST_USER) == 0) return 0; - dperm = (char *) malloc(strlen(perm)+3); - strcpy(dperm+1,perm); - dperm[0] = ':'; - dperm[strlen(perm)+1]=':'; - dperm[strlen(perm)+2]=0; - // Now dperm = ":perm:" - for (i=0; i < numusers; i++) { - if (strcmp(userdb[i]->username,username)==0) // Found the user - { - if (userdb[i]->perms == NULL) return 0; // No permission - tmp = strstr(userdb[i]->perms,dperm); // Search for permission - free (dperm); // Release memory - if (tmp == NULL) return 0; else return 1; - } - } - // User not found return 0 - free (dperm); - return 0; + // If no users, then everybody is allowed to do everything + if (numusers == 0) + return 1; + if (strcmp(username, GUEST_USER) == 0) + return 0; + dperm = (char *)malloc(strlen(perm) + 3); + strcpy(dperm + 1, perm); + dperm[0] = ':'; + dperm[strlen(perm) + 1] = ':'; + dperm[strlen(perm) + 2] = 0; + // Now dperm = ":perm:" + for (i = 0; i < numusers; i++) { + if (strcmp(userdb[i]->username, username) == 0) // Found the user + { + if (userdb[i]->perms == NULL) + return 0; // No permission + tmp = strstr(userdb[i]->perms, dperm); // Search for permission + free(dperm); // Release memory + if (tmp == NULL) + return 0; + else + return 1; + } + } + // User not found return 0 + free(dperm); + return 0; } // Initialise the list of of user passwords permissions from file void init_passwords(const char *filename) { - int i; - char line[MAX_LINE], *p,*user,*pwdhash,*perms; - FILE *f; + int i; + char line[MAX_LINE], *p, *user, *pwdhash, *perms; + FILE *f; - for (i=0; i < MAX_USERS; i++) userdb[i] = NULL; - numusers = 0; + for (i = 0; i < MAX_USERS; i++) + userdb[i] = NULL; + numusers = 0; - if ( !filename ) return; // No filename specified + if (!filename) + return; // No filename specified - f = fopen(filename,"r"); - if ( !f ) return; // File does not exist + f = fopen(filename, "r"); + if (!f) + return; // File does not exist - // Process each line - while ( fgets(line, sizeof line, f) ) { - // Replace EOLN with \0 - p = strchr(line, '\r'); - if ( p ) *p = '\0'; - p = strchr(line, '\n'); - if ( p ) *p = '\0'; + // Process each line + while (fgets(line, sizeof line, f)) { + // Replace EOLN with \0 + p = strchr(line, '\r'); + if (p) + *p = '\0'; + p = strchr(line, '\n'); + if (p) + *p = '\0'; - // If comment line or empty ignore line - p = line; - while (*p==' ') p++; // skip initial spaces - if ( (*p == '#') || (*p == '\0')) continue; // Skip comment lines + // If comment line or empty ignore line + p = line; + while (*p == ' ') + p++; // skip initial spaces + if ((*p == '#') || (*p == '\0')) + continue; // Skip comment lines - user = p; // This is where username starts - p = strchr(user,':'); - if (p == NULL) continue; // Malformed line skip - *p = '\0'; - pwdhash = p+1; - if (*pwdhash == 0) continue; // Malformed line (no password specified) - p = strchr(pwdhash,':'); - if (p == NULL) { // No perms specified - perms = NULL; - } else { - *p = '\0'; - perms = p+1; - if (*perms == 0) perms = NULL; - } - // At this point we have user,pwdhash and perms setup - userdb[numusers] = (p_pwdentry)malloc(sizeof(pwdentry)); - strcpy(userdb[numusers]->username,user); - strcpy(userdb[numusers]->pwdhash,pwdhash); - if (perms == NULL) - userdb[numusers]->perms = NULL; - else { - userdb[numusers]->perms = (char *)malloc(strlen(perms)+3); - (userdb[numusers]->perms)[0] = ':'; - strcpy(userdb[numusers]->perms + 1,perms); - (userdb[numusers]->perms)[strlen(perms)+1] = ':'; - (userdb[numusers]->perms)[strlen(perms)+2] = 0; - // Now perms field points to ":perms:" + user = p; // This is where username starts + p = strchr(user, ':'); + if (p == NULL) + continue; // Malformed line skip + *p = '\0'; + pwdhash = p + 1; + if (*pwdhash == 0) + continue; // Malformed line (no password specified) + p = strchr(pwdhash, ':'); + if (p == NULL) { // No perms specified + perms = NULL; + } else { + *p = '\0'; + perms = p + 1; + if (*perms == 0) + perms = NULL; + } + // At this point we have user,pwdhash and perms setup + userdb[numusers] = (p_pwdentry) malloc(sizeof(pwdentry)); + strcpy(userdb[numusers]->username, user); + strcpy(userdb[numusers]->pwdhash, pwdhash); + if (perms == NULL) + userdb[numusers]->perms = NULL; + else { + userdb[numusers]->perms = (char *)malloc(strlen(perms) + 3); + (userdb[numusers]->perms)[0] = ':'; + strcpy(userdb[numusers]->perms + 1, perms); + (userdb[numusers]->perms)[strlen(perms) + 1] = ':'; + (userdb[numusers]->perms)[strlen(perms) + 2] = 0; + // Now perms field points to ":perms:" + } + numusers++; } - numusers++; - } - fclose(f); + fclose(f); } void close_passwords() { - int i; + int i; - for (i=0; i < numusers; i++) - if (userdb[i] != NULL) free(userdb[i]); - numusers = 0; + for (i = 0; i < numusers; i++) + if (userdb[i] != NULL) + free(userdb[i]); + numusers = 0; } diff --git a/com32/cmenu/libmenu/passwords.h b/com32/cmenu/libmenu/passwords.h index 00e5702d..9ac06b19 100644 --- a/com32/cmenu/libmenu/passwords.h +++ b/com32/cmenu/libmenu/passwords.h @@ -1,23 +1,23 @@ #ifndef _PASSWORDS_H_ #define _PASSWORDS_H_ -char authenticate_user(const char * username, const char* pwd); +char authenticate_user(const char *username, const char *pwd); -char isallowed(const char *username, const char * perm); +char isallowed(const char *username, const char *perm); // Initialise the list of of user passwords permissions from file void init_passwords(const char *filename); // Free all space used for internal data structures void close_passwords(); -#define MAX_USERS 128 // Maximum number of users -#define USERNAME_LENGTH 12 // Max length of user name -#define PWDHASH_LENGTH 40 // Max lenght of pwd hash +#define MAX_USERS 128 // Maximum number of users +#define USERNAME_LENGTH 12 // Max length of user name +#define PWDHASH_LENGTH 40 // Max lenght of pwd hash typedef struct { - char username[USERNAME_LENGTH+1]; - char pwdhash[PWDHASH_LENGTH+1]; - char *perms; // pointer to string containing ":" delimited permissions + char username[USERNAME_LENGTH + 1]; + char pwdhash[PWDHASH_LENGTH + 1]; + char *perms; // pointer to string containing ":" delimited permissions } pwdentry; typedef pwdentry *p_pwdentry; diff --git a/com32/cmenu/libmenu/scancodes.h b/com32/cmenu/libmenu/scancodes.h index d3f625a6..b70f6c67 100644 --- a/com32/cmenu/libmenu/scancodes.h +++ b/com32/cmenu/libmenu/scancodes.h @@ -28,7 +28,7 @@ #define PAGEDN 81 #define INSERT 82 #define DELETE 83 -#define SPACEKEY 57 // Scan code for SPACE +#define SPACEKEY 57 // Scan code for SPACE #define CTRLLT 0x73 #define CTRLRT 0x74 diff --git a/com32/cmenu/libmenu/syslnx.c b/com32/cmenu/libmenu/syslnx.c index d2b0aef4..5cc19333 100644 --- a/com32/cmenu/libmenu/syslnx.c +++ b/com32/cmenu/libmenu/syslnx.c @@ -14,75 +14,80 @@ #include <com32.h> #include "syslnx.h" -com32sys_t inreg,outreg; // Global registers for this module +com32sys_t inreg, outreg; // Global registers for this module char issyslinux(void) { - REG_EAX(inreg) = 0x00003000; - REG_EBX(inreg) = REG_ECX(inreg) = REG_EDX(inreg) = 0xFFFFFFFF; - __intcall(0x21,&inreg,&outreg); - return (REG_EAX(outreg) == 0x59530000) && - (REG_EBX(outreg) == 0x4c530000) && - (REG_ECX(outreg) == 0x4e490000) && - (REG_EDX(outreg) == 0x58550000); + REG_EAX(inreg) = 0x00003000; + REG_EBX(inreg) = REG_ECX(inreg) = REG_EDX(inreg) = 0xFFFFFFFF; + __intcall(0x21, &inreg, &outreg); + return (REG_EAX(outreg) == 0x59530000) && + (REG_EBX(outreg) == 0x4c530000) && + (REG_ECX(outreg) == 0x4e490000) && (REG_EDX(outreg) == 0x58550000); } void runsyslinuxcmd(const char *cmd) { - strcpy(__com32.cs_bounce, cmd); - REG_AX(inreg) = 0x0003; // Run command - REG_BX(inreg) = OFFS(__com32.cs_bounce); - REG_ES(inreg) = SEG(__com32.cs_bounce); - __intcall(0x22, &inreg, &outreg); + strcpy(__com32.cs_bounce, cmd); + REG_AX(inreg) = 0x0003; // Run command + REG_BX(inreg) = OFFS(__com32.cs_bounce); + REG_ES(inreg) = SEG(__com32.cs_bounce); + __intcall(0x22, &inreg, &outreg); } void gototxtmode(void) { - REG_AX(inreg) = 0x0005; - __intcall(0x22,&inreg,&outreg); + REG_AX(inreg) = 0x0005; + __intcall(0x22, &inreg, &outreg); } void syslinux_idle(void) { - REG_AX(inreg) = 0x0013; - __intcall(0x22,&inreg,&outreg); + REG_AX(inreg) = 0x0013; + __intcall(0x22, &inreg, &outreg); } -unsigned int getversion(char *deriv,unsigned int *numfun) +unsigned int getversion(char *deriv, unsigned int *numfun) { - REG_AX(inreg) = 0x0001; - __intcall(0x22,&inreg,&outreg); - if (deriv) *deriv= REG_DL(outreg); - if (numfun) *numfun = REG_AX(outreg); - return REG_CX(outreg); + REG_AX(inreg) = 0x0001; + __intcall(0x22, &inreg, &outreg); + if (deriv) + *deriv = REG_DL(outreg); + if (numfun) + *numfun = REG_AX(outreg); + return REG_CX(outreg); } -void runsyslinuximage(const char*cmd, long ipappend) +void runsyslinuximage(const char *cmd, long ipappend) { - unsigned int numfun = 0; - char *ptr,*cmdline; + unsigned int numfun = 0; + char *ptr, *cmdline; - getversion(NULL,&numfun); - // Function 16h not supported Fall back to runcommand - if (numfun < 0x16) runsyslinuxcmd(cmd); - // Try the Run Kernel Image function - // Split command line into - strcpy(__com32.cs_bounce,cmd); - ptr = __com32.cs_bounce; - // serach for first space or end of string - while ( (*ptr) && (*ptr != ' ')) ptr++; - if (!*ptr) cmdline = ptr; // no command line - else { - *ptr++='\0'; // terminate kernal name - cmdline = ptr+1; - while (*cmdline != ' ') cmdline++; // find first non-space - } - // Now call the interrupt - REG_BX(inreg) = OFFS(cmdline); - REG_ES(inreg) = SEG(cmdline); - REG_SI(inreg) = OFFS(__com32.cs_bounce); - REG_DS(inreg) = SEG(__com32.cs_bounce); - REG_EDX(inreg) = 0; + getversion(NULL, &numfun); + // Function 16h not supported Fall back to runcommand + if (numfun < 0x16) + runsyslinuxcmd(cmd); + // Try the Run Kernel Image function + // Split command line into + strcpy(__com32.cs_bounce, cmd); + ptr = __com32.cs_bounce; + // serach for first space or end of string + while ((*ptr) && (*ptr != ' ')) + ptr++; + if (!*ptr) + cmdline = ptr; // no command line + else { + *ptr++ = '\0'; // terminate kernal name + cmdline = ptr + 1; + while (*cmdline != ' ') + cmdline++; // find first non-space + } + // Now call the interrupt + REG_BX(inreg) = OFFS(cmdline); + REG_ES(inreg) = SEG(cmdline); + REG_SI(inreg) = OFFS(__com32.cs_bounce); + REG_DS(inreg) = SEG(__com32.cs_bounce); + REG_EDX(inreg) = 0; - __intcall(0x22,&inreg,&outreg); // If successful does not return + __intcall(0x22, &inreg, &outreg); // If successful does not return } diff --git a/com32/cmenu/libmenu/syslnx.h b/com32/cmenu/libmenu/syslnx.h index 755b9690..29649e5d 100644 --- a/com32/cmenu/libmenu/syslnx.h +++ b/com32/cmenu/libmenu/syslnx.h @@ -51,14 +51,14 @@ char issyslinux(void); /* Check if syslinux is running */ -void runsyslinuxcmd(const char *cmd); /* Run specified command */ +void runsyslinuxcmd(const char *cmd); /* Run specified command */ -void gototxtmode(void); /* Change mode to text mode */ +void gototxtmode(void); /* Change mode to text mode */ -void syslinux_idle(void); /* Call syslinux idle loop */ +void syslinux_idle(void); /* Call syslinux idle loop */ /* Run command line with ipappend, returns if kernel image not found If syslinux version too old, then defaults to runsyslinuxcmd */ -void runsyslinuximage(const char*cmd, long ipappend); +void runsyslinuximage(const char *cmd, long ipappend); #endif diff --git a/com32/cmenu/libmenu/tui.c b/com32/cmenu/libmenu/tui.c index cb8c1936..81e40793 100644 --- a/com32/cmenu/libmenu/tui.c +++ b/com32/cmenu/libmenu/tui.c @@ -15,7 +15,7 @@ #include <com32.h> #include <stdlib.h> -com32sys_t inreg,outreg; // Global register sets for use +com32sys_t inreg, outreg; // Global register sets for use char bkspstr[] = " \b$"; char eolstr[] = "\n$"; @@ -27,234 +27,267 @@ char eolstr[] = "\n$"; // If showoldvalue <> 0 then caller responsibility to ensure that // str is NULL terminated. void getuserinput(char *stra, unsigned int size, unsigned int password, - unsigned int showoldvalue) + unsigned int showoldvalue) { - unsigned char c,scan; - char *p,*q; // p = current char of string, q = tmp - char *last; // The current last char of string - char *str; // pointer to string which is going to be allocated + unsigned char c, scan; + char *p, *q; // p = current char of string, q = tmp + char *last; // The current last char of string + char *str; // pointer to string which is going to be allocated char page; - char row,col; - char start,end; // Cursor shape - char fudge; // How many chars should be removed from output - char insmode; // Are we in insert or overwrite + char row, col; + char start, end; // Cursor shape + char fudge; // How many chars should be removed from output + char insmode; // Are we in insert or overwrite page = getdisppage(); - getpos(&row,&col,page); // Get current position - getcursorshape(&start,&end); + getpos(&row, &col, page); // Get current position + getcursorshape(&start, &end); insmode = 1; - str = (char *)malloc(size+1); // Allocate memory to store user input - memset(str,0,size+1); // Zero it out - if (password != 0) showoldvalue = 0; // Password's never displayed + str = (char *)malloc(size + 1); // Allocate memory to store user input + memset(str, 0, size + 1); // Zero it out + if (password != 0) + showoldvalue = 0; // Password's never displayed - if (showoldvalue != 0) strcpy(str,stra); // If show old value copy current value + if (showoldvalue != 0) + strcpy(str, stra); // If show old value copy current value last = str; - while (*last) {last++;} // Find the terminating null byte - p = str+ strlen(str); + while (*last) { + last++; + } // Find the terminating null byte + p = str + strlen(str); if (insmode == 0) - setcursorshape(1,7); // Block cursor - else setcursorshape(6,7); // Normal cursor + setcursorshape(1, 7); // Block cursor + else + setcursorshape(6, 7); // Normal cursor // Invariants: p is the current char // col is the corresponding column on the screen - if (password == 0) // Not a password, print initial value + if (password == 0) // Not a password, print initial value { - gotoxy(row,col,page); - csprint(str,GETSTRATTR); + gotoxy(row, col, page); + csprint(str, GETSTRATTR); } - while (1) { // Do forever - c = inputc(&scan); - if (c == '\r') break; // User hit Enter getout of loop - if (scan == ESCAPE) // User hit escape getout and nullify string - { *str = 0; - break; - } - fudge = 0; - // if scan code is regognized do something - // else if char code is recognized do something - // else ignore - switch(scan) { - case HOMEKEY: - p = str; - break; - case ENDKEY: - p = last; - break; - case LTARROW: - if (p > str) p--; - break; - case CTRLLT: - if (p==str) break; - if (*p == ' ') - while ((p > str) && (*p == ' ')) p--; - else { - if (*(p-1) == ' ') { - p--; - while ((p > str) && (*p == ' ')) p--; - } - } - while ((p > str) && ((*p == ' ') || (*(p-1) != ' '))) p--; - break; - case RTARROW: - if (p < last) p++; - break; - case CTRLRT: - if (*p==0) break; // At end of string - if (*p != ' ') - while ((*p!=0) && (*p != ' ')) p++; - while ((*p!=0) && ((*p == ' ') && (*(p+1) != ' '))) p++; - if (*p==' ') p++; - break; - case DELETE: - q = p; - while (*(q+1)) {*q = *(q+1); q++; } - if (last > str) last--; - fudge = 1; - break; - case INSERT: - insmode = 1-insmode; // Switch mode - if (insmode == 0) - setcursorshape(1,7); // Block cursor - else setcursorshape(6,7); // Normal cursor - break; + while (1) { // Do forever + c = inputc(&scan); + if (c == '\r') + break; // User hit Enter getout of loop + if (scan == ESCAPE) // User hit escape getout and nullify string + { + *str = 0; + break; + } + fudge = 0; + // if scan code is regognized do something + // else if char code is recognized do something + // else ignore + switch (scan) { + case HOMEKEY: + p = str; + break; + case ENDKEY: + p = last; + break; + case LTARROW: + if (p > str) + p--; + break; + case CTRLLT: + if (p == str) + break; + if (*p == ' ') + while ((p > str) && (*p == ' ')) + p--; + else { + if (*(p - 1) == ' ') { + p--; + while ((p > str) && (*p == ' ')) + p--; + } + } + while ((p > str) && ((*p == ' ') || (*(p - 1) != ' '))) + p--; + break; + case RTARROW: + if (p < last) + p++; + break; + case CTRLRT: + if (*p == 0) + break; // At end of string + if (*p != ' ') + while ((*p != 0) && (*p != ' ')) + p++; + while ((*p != 0) && ((*p == ' ') && (*(p + 1) != ' '))) + p++; + if (*p == ' ') + p++; + break; + case DELETE: + q = p; + while (*(q + 1)) { + *q = *(q + 1); + q++; + } + if (last > str) + last--; + fudge = 1; + break; + case INSERT: + insmode = 1 - insmode; // Switch mode + if (insmode == 0) + setcursorshape(1, 7); // Block cursor + else + setcursorshape(6, 7); // Normal cursor + break; - default: // Unrecognized scan code, look at the ascii value - switch (c) { - case '\b': // Move over by one - q=p; - while ( q <= last ) { *(q-1)=*q; q++;} - if (last > str) last--; - if (p > str) p--; - fudge = 1; - break; - case '\x15': /* Ctrl-U: kill input */ - fudge = last-str; - while ( p > str ) *p--=0; - p = str; *p=0; last = str; - break; - default: // Handle insert and overwrite mode - if ((c >= ' ') && (c < 128) && - ((unsigned int)(p-str) < size-1) ) { - if (insmode == 0) { // Overwrite mode - if (p==last) last++; - *last = 0; - *p++ = c; - } else { // Insert mode - if (p==last) { // last char - last++; - *last=0; - *p++=c; - } else { // Non-last char - q=last++; - while (q >= p) { *q=*(q-1); q--;} - *p++=c; - } - } - } - else beep(); - } - break; + default: // Unrecognized scan code, look at the ascii value + switch (c) { + case '\b': // Move over by one + q = p; + while (q <= last) { + *(q - 1) = *q; + q++; + } + if (last > str) + last--; + if (p > str) + p--; + fudge = 1; + break; + case '\x15': /* Ctrl-U: kill input */ + fudge = last - str; + while (p > str) + *p-- = 0; + p = str; + *p = 0; + last = str; + break; + default: // Handle insert and overwrite mode + if ((c >= ' ') && (c < 128) && + ((unsigned int)(p - str) < size - 1)) { + if (insmode == 0) { // Overwrite mode + if (p == last) + last++; + *last = 0; + *p++ = c; + } else { // Insert mode + if (p == last) { // last char + last++; + *last = 0; + *p++ = c; + } else { // Non-last char + q = last++; + while (q >= p) { + *q = *(q - 1); + q--; + } + *p++ = c; + } + } + } else + beep(); + } + break; + } + // Now the string has been modified, print it + if (password == 0) { + gotoxy(row, col, page); + csprint(str, GETSTRATTR); + if (fudge > 0) + cprint(' ', GETSTRATTR, fudge, page); + gotoxy(row, col + (p - str), page); } - // Now the string has been modified, print it - if (password == 0) { - gotoxy(row,col,page); - csprint(str,GETSTRATTR); - if (fudge > 0) cprint(' ',GETSTRATTR,fudge,page); - gotoxy(row,col+(p-str),page); - } - } + } *p = '\0'; - if (password == 0) csprint("\r\n",GETSTRATTR); - setcursorshape(start,end); // Block cursor + if (password == 0) + csprint("\r\n", GETSTRATTR); + setcursorshape(start, end); // Block cursor // If user hit ESCAPE so return without any changes - if (scan != ESCAPE) strcpy(stra,str); + if (scan != ESCAPE) + strcpy(stra, str); free(str); } /* Print a C string (NUL-terminated) */ -void cswprint(const char *str,char attr,char left) +void cswprint(const char *str, char attr, char left) { char page = getdisppage(); - char newattr=0,cha,chb; - char row,col; - char nr,nc; + char newattr = 0, cha, chb; + char row, col; + char nr, nc; nr = getnumrows(); nc = getnumcols(); - getpos(&row,&col,page); - while ( *str ) { - switch (*str) - { + getpos(&row, &col, page); + while (*str) { + switch (*str) { case '\b': - --col; - break; + --col; + break; case '\n': - ++row; - col = left; - break; + ++row; + col = left; + break; case '\r': - //col=left; - break; - case BELL: // Bell Char - beep(); - break; - case CHRELATTR: // change attribute (relatively) - case CHABSATTR: // change attribute (absolute) - cha = *(str+1); - chb = *(str+2); - if ((((cha >= '0') && (cha <= '9')) || - ((cha >= 'A') && (cha <= 'F'))) && - (((chb >= '0') && (chb <= '9')) || - ((chb >= 'A') && (chb <= 'F')))) // Next two chars are legal + //col=left; + break; + case BELL: // Bell Char + beep(); + break; + case CHRELATTR: // change attribute (relatively) + case CHABSATTR: // change attribute (absolute) + cha = *(str + 1); + chb = *(str + 2); + if ((((cha >= '0') && (cha <= '9')) || ((cha >= 'A') && (cha <= 'F'))) && (((chb >= '0') && (chb <= '9')) || ((chb >= 'A') && (chb <= 'F')))) // Next two chars are legal { - if ((cha >= 'A') && (cha <= 'F')) - cha = cha - 'A'+10; - else cha = cha - '0'; - if ((chb >= 'A') && (chb <= 'F')) - chb = chb - 'A'+10; - else chb = chb - '0'; - newattr = (cha << 4) + chb; - attr = (*str == CHABSATTR ? newattr : attr ^ newattr); - str += 2; // Will be incremented again later + if ((cha >= 'A') && (cha <= 'F')) + cha = cha - 'A' + 10; + else + cha = cha - '0'; + if ((chb >= 'A') && (chb <= 'F')) + chb = chb - 'A' + 10; + else + chb = chb - '0'; + newattr = (cha << 4) + chb; + attr = (*str == CHABSATTR ? newattr : attr ^ newattr); + str += 2; // Will be incremented again later } - break; + break; default: - putch(*str, attr, page); - ++col; + putch(*str, attr, page); + ++col; } - if (col >= nc) - { - ++row; - col=left; + if (col >= nc) { + ++row; + col = left; } - if (row > nr) - { - scrollup(); - row= nr; + if (row > nr) { + scrollup(); + row = nr; } - gotoxy(row,col,page); - str++; + gotoxy(row, col, page); + str++; } } -void clearwindow(char top, char left, char bot, char right, char page, char fillchar, char fillattr) +void clearwindow(char top, char left, char bot, char right, char page, + char fillchar, char fillattr) { char x; - for (x=top; x < bot+1; x++) - { - gotoxy(x,left,page); - cprint(fillchar,fillattr,right-left+1,page); + for (x = top; x < bot + 1; x++) { + gotoxy(x, left, page); + cprint(fillchar, fillattr, right - left + 1, page); } } void cls(void) { - unsigned char dp = getdisppage(); - gotoxy(0,0,dp); - cprint(' ',GETSTRATTR,(1+getnumrows())*getnumcols(),dp); + unsigned char dp = getdisppage(); + gotoxy(0, 0, dp); + cprint(' ', GETSTRATTR, (1 + getnumrows()) * getnumcols(), dp); } //////////////////////////////Box Stuff @@ -262,96 +295,97 @@ void cls(void) // This order of numbers must match // the values of BOX_TOPLEFT,... in the header file -unsigned char SINSIN_CHARS[] = {218,192,191,217, //Corners - 196,179, // Horiz and Vertical - 195,180,194,193,197}; // Connectors & Middle +unsigned char SINSIN_CHARS[] = { 218, 192, 191, 217, //Corners + 196, 179, // Horiz and Vertical + 195, 180, 194, 193, 197 +}; // Connectors & Middle -unsigned char DBLDBL_CHARS[] = {201,200,187,188, // Corners - 205,186, // Horiz and Vertical - 199,182,203,202,206}; // Connectors & Middle +unsigned char DBLDBL_CHARS[] = { 201, 200, 187, 188, // Corners + 205, 186, // Horiz and Vertical + 199, 182, 203, 202, 206 +}; // Connectors & Middle -unsigned char SINDBL_CHARS[] = {214,211,183,189, // Corners - 196,186, // Horiz & Vert - 199,182,210,208,215}; // Connectors & Middle +unsigned char SINDBL_CHARS[] = { 214, 211, 183, 189, // Corners + 196, 186, // Horiz & Vert + 199, 182, 210, 208, 215 +}; // Connectors & Middle -unsigned char DBLSIN_CHARS[] = {213,212,184,190, // Corners - 205,179, // Horiz & Vert - 198,181,209,207,216}; // Connectors & Middle +unsigned char DBLSIN_CHARS[] = { 213, 212, 184, 190, // Corners + 205, 179, // Horiz & Vert + 198, 181, 209, 207, 216 +}; // Connectors & Middle -unsigned char * getboxchars(boxtype bt) +unsigned char *getboxchars(boxtype bt) { - switch (bt) - { - case BOX_SINSIN: - return SINSIN_CHARS; - break; - case BOX_DBLDBL: - return DBLDBL_CHARS; - break; - case BOX_SINDBL: - return SINDBL_CHARS; - break; - case BOX_DBLSIN: - return DBLSIN_CHARS; - break; - default: - return SINSIN_CHARS; - break; - } - return SINSIN_CHARS; + switch (bt) { + case BOX_SINSIN: + return SINSIN_CHARS; + break; + case BOX_DBLDBL: + return DBLDBL_CHARS; + break; + case BOX_SINDBL: + return SINDBL_CHARS; + break; + case BOX_DBLSIN: + return DBLSIN_CHARS; + break; + default: + return SINSIN_CHARS; + break; + } + return SINSIN_CHARS; } // Draw box and lines -void drawbox(char top,char left,char bot, char right, - char page, char attr,boxtype bt) +void drawbox(char top, char left, char bot, char right, + char page, char attr, boxtype bt) { - unsigned char *box_chars; // pointer to array of box chars - unsigned char x; + unsigned char *box_chars; // pointer to array of box chars + unsigned char x; - box_chars = getboxchars(bt); - // Top border - gotoxy(top,left,page); - cprint(box_chars[BOX_TOPLEFT],attr,1,page); - gotoxy(top,left+1,page); - cprint(box_chars[BOX_TOP],attr,right-left,page); - gotoxy(top,right,page); - cprint(box_chars[BOX_TOPRIGHT],attr,1,page); - // Bottom border - gotoxy(bot,left,page); - cprint(box_chars[BOX_BOTLEFT],attr,1,page); - gotoxy(bot,left+1,page); - cprint(box_chars[BOX_BOT],attr,right-left,page); - gotoxy(bot,right,page); - cprint(box_chars[BOX_BOTRIGHT],attr,1,page); - // Left & right borders - for (x=top+1; x < bot; x++) - { - gotoxy(x,left,page); - cprint(box_chars[BOX_LEFT],attr,1,page); - gotoxy(x,right,page); - cprint(box_chars[BOX_RIGHT],attr,1,page); + box_chars = getboxchars(bt); + // Top border + gotoxy(top, left, page); + cprint(box_chars[BOX_TOPLEFT], attr, 1, page); + gotoxy(top, left + 1, page); + cprint(box_chars[BOX_TOP], attr, right - left, page); + gotoxy(top, right, page); + cprint(box_chars[BOX_TOPRIGHT], attr, 1, page); + // Bottom border + gotoxy(bot, left, page); + cprint(box_chars[BOX_BOTLEFT], attr, 1, page); + gotoxy(bot, left + 1, page); + cprint(box_chars[BOX_BOT], attr, right - left, page); + gotoxy(bot, right, page); + cprint(box_chars[BOX_BOTRIGHT], attr, 1, page); + // Left & right borders + for (x = top + 1; x < bot; x++) { + gotoxy(x, left, page); + cprint(box_chars[BOX_LEFT], attr, 1, page); + gotoxy(x, right, page); + cprint(box_chars[BOX_RIGHT], attr, 1, page); } } void drawhorizline(char top, char left, char right, char page, char attr, - boxtype bt, char dumb) + boxtype bt, char dumb) { - unsigned char start,end; - unsigned char *box_chars = getboxchars(bt); - if (dumb==0) { - start = left+1; - end = right-1; - } else { - start = left; - end = right; - } - gotoxy(top,start,page); - cprint(box_chars[BOX_HORIZ],attr,end-start+1,page); - if (dumb == 0) - { - gotoxy(top,left,page); - cprint(box_chars[BOX_LTRT],attr,1,page); - gotoxy(top,right,page); - cprint(box_chars[BOX_RTLT],attr,1,page); - } + unsigned char start, end; + unsigned char *box_chars = getboxchars(bt); + if (dumb == 0) { + start = left + 1; + end = right - 1; + } else { + start = left; + end = right; + } + gotoxy(top, start, page); + cprint(box_chars[BOX_HORIZ], attr, end - start + 1, page); + if (dumb == 0) { + gotoxy(top, left, page); + cprint(box_chars[BOX_LTRT], attr, 1, page); + gotoxy(top, right, page); + cprint(box_chars[BOX_RTLT], attr, 1, page); + } } diff --git a/com32/cmenu/libmenu/tui.h b/com32/cmenu/libmenu/tui.h index 92f93863..4df15327 100644 --- a/com32/cmenu/libmenu/tui.h +++ b/com32/cmenu/libmenu/tui.h @@ -18,7 +18,6 @@ #include "com32io.h" #include "scancodes.h" - #ifndef NULL #define NULL ((void *)0) #endif @@ -31,27 +30,27 @@ void clearwindow(char top, char left, char bot, char right, char page, char fillchar, char fillattr); -void cls(void); /* Clears the entire current screen page */ +void cls(void); /* Clears the entire current screen page */ // Generic user input, // password = 0 iff chars echoed on screen // showoldvalue <> 0 iff current displayed for editing void getuserinput(char *str, unsigned int size, - unsigned int password, unsigned int showoldvalue); + unsigned int password, unsigned int showoldvalue); static inline void getstring(char *str, unsigned int size) { - getuserinput(str,size,0,0); + getuserinput(str, size, 0, 0); } static inline void editstring(char *str, unsigned int size) { - getuserinput(str,size,0,1); + getuserinput(str, size, 0, 1); } -static inline void getpwd(char * str, unsigned int size) +static inline void getpwd(char *str, unsigned int size) { - getuserinput(str,size,1,0); + getuserinput(str, size, 1, 0); } // Box drawing Chars offsets into array @@ -59,30 +58,30 @@ static inline void getpwd(char * str, unsigned int size) #define BOX_BOTLEFT 0x1 #define BOX_TOPRIGHT 0x2 #define BOX_BOTRIGHT 0x3 -#define BOX_TOP 0x4 // TOP = BOT = HORIZ +#define BOX_TOP 0x4 // TOP = BOT = HORIZ #define BOX_BOT 0x4 #define BOX_HORIZ 0x4 #define BOX_LEFT 0x5 #define BOX_RIGHT 0x5 -#define BOX_VERT 0x5 // LEFT=RIGHT=VERT +#define BOX_VERT 0x5 // LEFT=RIGHT=VERT #define BOX_LTRT 0x6 #define BOX_RTLT 0x7 #define BOX_TOPBOT 0x8 #define BOX_BOTTOP 0x9 #define BOX_MIDDLE 0xA -typedef enum {BOX_SINSIN,BOX_DBLDBL, BOX_SINDBL, BOX_DBLSIN} boxtype; +typedef enum { BOX_SINSIN, BOX_DBLDBL, BOX_SINDBL, BOX_DBLSIN } boxtype; -unsigned char * getboxchars(boxtype bt); +unsigned char *getboxchars(boxtype bt); -void drawbox(char top,char left,char bot, char right, - char page, char attr,boxtype bt); +void drawbox(char top, char left, char bot, char right, + char page, char attr, boxtype bt); // Draw a horizontal line // dumb == 1, means just draw the line // dumb == 0 means check the first and last positions and depending on what is // currently on the screen make it a LTRT and/or RTLT appropriately. void drawhorizline(char top, char left, char right, char page, char attr, - boxtype bt, char dumb); + boxtype bt, char dumb); #endif diff --git a/com32/cmenu/simple.c b/com32/cmenu/simple.c index 92e8ab12..4f602a9a 100644 --- a/com32/cmenu/simple.c +++ b/com32/cmenu/simple.c @@ -20,60 +20,63 @@ int main(void) { - t_menuitem * curr; + t_menuitem *curr; - // Change the video mode here - // setvideomode(0) + // Change the video mode here + // setvideomode(0) - // Choose the default title and setup default values for all attributes.... - init_menusystem(NULL); - set_window_size(1,1,23,78); // Leave one row/col border all around + // Choose the default title and setup default values for all attributes.... + init_menusystem(NULL); + set_window_size(1, 1, 23, 78); // Leave one row/col border all around - // Choose the default values for all attributes and char's - // -1 means choose defaults (Actually the next 4 lines are not needed) - //set_normal_attr (-1,-1,-1,-1); - //set_status_info (-1,-1); - //set_title_info (-1,-1); - //set_misc_info(-1,-1,-1,-1); + // Choose the default values for all attributes and char's + // -1 means choose defaults (Actually the next 4 lines are not needed) + //set_normal_attr (-1,-1,-1,-1); + //set_status_info (-1,-1); + //set_title_info (-1,-1); + //set_misc_info(-1,-1,-1,-1); - // menuindex = add_named_menu("name"," Menu Title ",-1); - // add_item("Item string","Status String",TYPE,"any string",NUM) - // TYPE = OPT_RUN | OPT_EXITMENU | OPT_SUBMENU | OPT_CHECKBOX | OPT_INACTIVE - // "any string" useful for storing kernel names - // In case of OPT_SUBMENU, "any string" can be set to "name" of menu to be linked - // in which case value NUM is ignored - // NUM = index of submenu if OPT_SUBMENU, - // 0/1 default checked state if OPT_CHECKBOX - // unused otherwise. + // menuindex = add_named_menu("name"," Menu Title ",-1); + // add_item("Item string","Status String",TYPE,"any string",NUM) + // TYPE = OPT_RUN | OPT_EXITMENU | OPT_SUBMENU | OPT_CHECKBOX | OPT_INACTIVE + // "any string" useful for storing kernel names + // In case of OPT_SUBMENU, "any string" can be set to "name" of menu to be linked + // in which case value NUM is ignored + // NUM = index of submenu if OPT_SUBMENU, + // 0/1 default checked state if OPT_CHECKBOX + // unused otherwise. - add_named_menu("testing"," Testing ",-1); - add_item("Self Loop","Go to testing",OPT_SUBMENU,"testing",0); - add_item("Memory Test","Perform extensive memory testing",OPT_RUN, "memtest",0); - add_item("Exit this menu","Go one level up",OPT_EXITMENU,"exit",0); + add_named_menu("testing", " Testing ", -1); + add_item("Self Loop", "Go to testing", OPT_SUBMENU, "testing", 0); + add_item("Memory Test", "Perform extensive memory testing", OPT_RUN, + "memtest", 0); + add_item("Exit this menu", "Go one level up", OPT_EXITMENU, "exit", 0); - add_named_menu("rescue"," Rescue Options ",-1); - add_item("Linux Rescue","linresc",OPT_RUN,"linresc",0); - add_item("Dos Rescue","dosresc",OPT_RUN,"dosresc",0); - add_item("Windows Rescue","winresc",OPT_RUN,"winresc",0); - add_item("Exit this menu","Go one level up",OPT_EXITMENU,"exit",0); + add_named_menu("rescue", " Rescue Options ", -1); + add_item("Linux Rescue", "linresc", OPT_RUN, "linresc", 0); + add_item("Dos Rescue", "dosresc", OPT_RUN, "dosresc", 0); + add_item("Windows Rescue", "winresc", OPT_RUN, "winresc", 0); + add_item("Exit this menu", "Go one level up", OPT_EXITMENU, "exit", 0); - add_named_menu("main"," Main Menu ",-1); - add_item("Prepare","prep",OPT_RUN,"prep",0); - add_item("Rescue options...","Troubleshoot a system",OPT_SUBMENU,"rescue",0); - add_item("Testing...","Options to test hardware",OPT_SUBMENU,"testing",0); - add_item("Exit to prompt", "Exit the menu system", OPT_EXITMENU, "exit", 0); + add_named_menu("main", " Main Menu ", -1); + add_item("Prepare", "prep", OPT_RUN, "prep", 0); + add_item("Rescue options...", "Troubleshoot a system", OPT_SUBMENU, + "rescue", 0); + add_item("Testing...", "Options to test hardware", OPT_SUBMENU, "testing", + 0); + add_item("Exit to prompt", "Exit the menu system", OPT_EXITMENU, "exit", 0); - curr = showmenus(find_menu_num("main")); // Initial menu is the one called "main" + curr = showmenus(find_menu_num("main")); // Initial menu is the one called "main" - if (curr) - { - if (curr->action == OPT_RUN) - { - if (issyslinux()) runsyslinuxcmd(curr->data); - else csprint(curr->data,0x07); - return 1; - } - csprint("Error in programming!",0x07); - } - return 0; + if (curr) { + if (curr->action == OPT_RUN) { + if (issyslinux()) + runsyslinuxcmd(curr->data); + else + csprint(curr->data, 0x07); + return 1; + } + csprint("Error in programming!", 0x07); + } + return 0; } |