aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--com32/cmenu/complex.c674
-rw-r--r--com32/cmenu/display.c17
-rw-r--r--com32/cmenu/libmenu/com32io.c130
-rw-r--r--com32/cmenu/libmenu/com32io.h61
-rw-r--r--com32/cmenu/libmenu/des.c1614
-rw-r--r--com32/cmenu/libmenu/des.h2
-rw-r--r--com32/cmenu/libmenu/help.c321
-rw-r--r--com32/cmenu/libmenu/help.h8
-rw-r--r--com32/cmenu/libmenu/menu.c2052
-rw-r--r--com32/cmenu/libmenu/menu.h250
-rw-r--r--com32/cmenu/libmenu/passwords.c199
-rw-r--r--com32/cmenu/libmenu/passwords.h16
-rw-r--r--com32/cmenu/libmenu/scancodes.h2
-rw-r--r--com32/cmenu/libmenu/syslnx.c101
-rw-r--r--com32/cmenu/libmenu/syslnx.h8
-rw-r--r--com32/cmenu/libmenu/tui.c550
-rw-r--r--com32/cmenu/libmenu/tui.h27
-rw-r--r--com32/cmenu/simple.c97
-rw-r--r--com32/gdbstub/gdbstub.c814
-rw-r--r--com32/gdbstub/main.c56
-rw-r--r--com32/gdbstub/serial.c165
-rw-r--r--com32/gdbstub/serial.h6
-rw-r--r--com32/gplinclude/cpuid.h224
-rw-r--r--com32/gplinclude/dmi/dmi.h65
-rw-r--r--com32/gplinclude/dmi/dmi_base_board.h30
-rw-r--r--com32/gplinclude/dmi/dmi_battery.h32
-rw-r--r--com32/gplinclude/dmi/dmi_bios.h112
-rw-r--r--com32/gplinclude/dmi/dmi_chassis.h28
-rw-r--r--com32/gplinclude/dmi/dmi_ipmi.h18
-rw-r--r--com32/gplinclude/dmi/dmi_memory.h36
-rw-r--r--com32/gplinclude/dmi/dmi_processor.h123
-rw-r--r--com32/gplinclude/dmi/dmi_system.h18
-rw-r--r--com32/gplinclude/vpd/vpd.h22
-rw-r--r--com32/gpllib/cpuid.c448
-rw-r--r--com32/gpllib/dmi/dmi.c1073
-rw-r--r--com32/gpllib/dmi/dmi_base_board.c12
-rw-r--r--com32/gpllib/dmi/dmi_battery.c54
-rw-r--r--com32/gpllib/dmi/dmi_bios.c84
-rw-r--r--com32/gpllib/dmi/dmi_chassis.c118
-rw-r--r--com32/gpllib/dmi/dmi_ipmi.c37
-rw-r--r--com32/gpllib/dmi/dmi_memory.c211
-rw-r--r--com32/gpllib/dmi/dmi_processor.c750
-rw-r--r--com32/gpllib/vpd/vpd.c112
-rw-r--r--com32/include/alloca.h2
-rw-r--r--com32/include/bitsize/stddef.h2
-rw-r--r--com32/include/bitsize/stdint.h28
-rw-r--r--com32/include/colortbl.h18
-rw-r--r--com32/include/com32.h85
-rw-r--r--com32/include/console.h4
-rw-r--r--com32/include/cpufeature.h124
-rw-r--r--com32/include/ctype.h50
-rw-r--r--com32/include/dev.h4
-rw-r--r--com32/include/dirent.h18
-rw-r--r--com32/include/elf.h2
-rw-r--r--com32/include/endian.h2
-rw-r--r--com32/include/inttypes.h2
-rw-r--r--com32/include/klibc/archsetjmp.h12
-rw-r--r--com32/include/klibc/diverr.h2
-rw-r--r--com32/include/klibc/endian.h2
-rw-r--r--com32/include/netinet/in.h23
-rw-r--r--com32/include/png.h2906
-rw-r--r--com32/include/pngconf.h121
-rw-r--r--com32/include/stdbool.h2
-rw-r--r--com32/include/stdint.h56
-rw-r--r--com32/include/stdio.h23
-rw-r--r--com32/include/stdlib.h41
-rw-r--r--com32/include/sys/cpu.h114
-rw-r--r--com32/include/sys/elf32.h104
-rw-r--r--com32/include/sys/elf64.h104
-rw-r--r--com32/include/sys/elfcommon.h2
-rw-r--r--com32/include/sys/io.h24
-rw-r--r--com32/include/sys/pci.h103
-rw-r--r--com32/include/sys/stat.h4
-rw-r--r--com32/include/sys/times.h2
-rw-r--r--com32/include/sys/types.h6
-rw-r--r--com32/include/syslinux/adv.h4
-rw-r--r--com32/include/syslinux/align.h5
-rw-r--r--com32/include/syslinux/bootpm.h24
-rw-r--r--com32/include/syslinux/bootrm.h37
-rw-r--r--com32/include/syslinux/config.h198
-rw-r--r--com32/include/syslinux/features.h16
-rw-r--r--com32/include/syslinux/keyboard.h11
-rw-r--r--com32/include/syslinux/linux.h13
-rw-r--r--com32/include/syslinux/memscan.h2
-rw-r--r--com32/include/syslinux/movebits.h43
-rw-r--r--com32/include/syslinux/pxe.h475
-rw-r--r--com32/include/zconf.h55
-rw-r--r--com32/lib/abort.c2
-rw-r--r--com32/lib/asprintf.c28
-rw-r--r--com32/lib/atexit.c4
-rw-r--r--com32/lib/atexit.h6
-rw-r--r--com32/lib/atox.c4
-rw-r--r--com32/lib/calloc.c2
-rw-r--r--com32/lib/chdir.c4
-rw-r--r--com32/lib/closedir.c28
-rw-r--r--com32/lib/creat.c2
-rw-r--r--com32/lib/ctypes.c514
-rw-r--r--com32/lib/exit.c4
-rw-r--r--com32/lib/fclose.c4
-rw-r--r--com32/lib/fdopendir.c4
-rw-r--r--com32/lib/fgetc.c6
-rw-r--r--com32/lib/fgets.c32
-rw-r--r--com32/lib/fopen.c54
-rw-r--r--com32/lib/fopendev.c56
-rw-r--r--com32/lib/fprintf.c14
-rw-r--r--com32/lib/fputc.c6
-rw-r--r--com32/lib/fputs.c4
-rw-r--r--com32/lib/fread.c38
-rw-r--r--com32/lib/fread2.c4
-rw-r--r--com32/lib/free.c135
-rw-r--r--com32/lib/fwrite.c38
-rw-r--r--com32/lib/fwrite2.c4
-rw-r--r--com32/lib/getcwd.c26
-rw-r--r--com32/lib/getopt.c88
-rw-r--r--com32/lib/libgcc/__divdi3.c30
-rw-r--r--com32/lib/libgcc/__moddi3.c30
-rw-r--r--com32/lib/libgcc/__udivdi3.c4
-rw-r--r--com32/lib/libgcc/__udivmoddi4.c42
-rw-r--r--com32/lib/libgcc/__umoddi3.c8
-rw-r--r--com32/lib/lrand48.c25
-rw-r--r--com32/lib/malloc.c191
-rw-r--r--com32/lib/malloc.h10
-rw-r--r--com32/lib/math/strtod.c199
-rw-r--r--com32/lib/memccpy.c18
-rw-r--r--com32/lib/memchr.c12
-rw-r--r--com32/lib/memcmp.c16
-rw-r--r--com32/lib/memmem.c44
-rw-r--r--com32/lib/memswap.c19
-rw-r--r--com32/lib/onexit.c32
-rw-r--r--com32/lib/opendir.c37
-rw-r--r--com32/lib/pci/cfgtype.c120
-rw-r--r--com32/lib/pci/readbios.c14
-rw-r--r--com32/lib/pci/readx.c93
-rw-r--r--com32/lib/pci/scan.c921
-rw-r--r--com32/lib/pci/writebios.c14
-rw-r--r--com32/lib/pci/writex.c79
-rw-r--r--com32/lib/perror.c2
-rw-r--r--com32/lib/printf.c12
-rw-r--r--com32/lib/putchar.c4
-rw-r--r--com32/lib/puts.c6
-rw-r--r--com32/lib/qsort.c45
-rw-r--r--com32/lib/readdir.c72
-rw-r--r--com32/lib/realloc.c144
-rw-r--r--com32/lib/seed48.c8
-rw-r--r--com32/lib/snprintf.c12
-rw-r--r--com32/lib/sprintf.c12
-rw-r--r--com32/lib/srand48.c7
-rw-r--r--com32/lib/sscanf.c12
-rw-r--r--com32/lib/stpcpy.c20
-rw-r--r--com32/lib/stpncpy.c20
-rw-r--r--com32/lib/strcasecmp.c22
-rw-r--r--com32/lib/strcat.c4
-rw-r--r--com32/lib/strchr.c12
-rw-r--r--com32/lib/strcmp.c18
-rw-r--r--com32/lib/strcpy.c14
-rw-r--r--com32/lib/strdup.c10
-rw-r--r--com32/lib/strerror.c20
-rw-r--r--com32/lib/strlcat.c30
-rw-r--r--com32/lib/strlcpy.c22
-rw-r--r--com32/lib/strlen.c8
-rw-r--r--com32/lib/strncasecmp.c22
-rw-r--r--com32/lib/strncat.c4
-rw-r--r--com32/lib/strncmp.c18
-rw-r--r--com32/lib/strncpy.c18
-rw-r--r--com32/lib/strndup.c12
-rw-r--r--com32/lib/strnlen.c8
-rw-r--r--com32/lib/strntoimax.c2
-rw-r--r--com32/lib/strntoumax.c100
-rw-r--r--com32/lib/strpcpy.c14
-rw-r--r--com32/lib/strrchr.c14
-rw-r--r--com32/lib/strsep.c18
-rw-r--r--com32/lib/strspn.c56
-rw-r--r--com32/lib/strstr.c2
-rw-r--r--com32/lib/strtok.c8
-rw-r--r--com32/lib/strtox.c4
-rw-r--r--com32/lib/sys/ansi.c716
-rw-r--r--com32/lib/sys/ansi.h68
-rw-r--r--com32/lib/sys/ansicon_write.c253
-rw-r--r--com32/lib/sys/ansiserial_write.c19
-rw-r--r--com32/lib/sys/argv.c88
-rw-r--r--com32/lib/sys/cfarcall.c5
-rw-r--r--com32/lib/sys/close.c38
-rw-r--r--com32/lib/sys/colortable.c4
-rw-r--r--com32/lib/sys/err_read.c18
-rw-r--r--com32/lib/sys/err_write.c18
-rw-r--r--com32/lib/sys/farcall.c4
-rw-r--r--com32/lib/sys/file.h68
-rw-r--r--com32/lib/sys/fileclose.c16
-rw-r--r--com32/lib/sys/fileread.c76
-rw-r--r--com32/lib/sys/fstat.c36
-rw-r--r--com32/lib/sys/ftell.c8
-rw-r--r--com32/lib/sys/intcall.c4
-rw-r--r--com32/lib/sys/isatty.c14
-rw-r--r--com32/lib/sys/line_input.c84
-rw-r--r--com32/lib/sys/null_read.c16
-rw-r--r--com32/lib/sys/null_write.c16
-rw-r--r--com32/lib/sys/open.c64
-rw-r--r--com32/lib/sys/openconsole.c20
-rw-r--r--com32/lib/sys/opendev.c88
-rw-r--r--com32/lib/sys/rawcon_read.c52
-rw-r--r--com32/lib/sys/rawcon_write.c37
-rw-r--r--com32/lib/sys/read.c12
-rw-r--r--com32/lib/sys/screensize.c24
-rw-r--r--com32/lib/sys/serial_write.c40
-rw-r--r--com32/lib/sys/stdcon_read.c49
-rw-r--r--com32/lib/sys/stdcon_write.c45
-rw-r--r--com32/lib/sys/times.c8
-rw-r--r--com32/lib/sys/vesa/background.c534
-rw-r--r--com32/lib/sys/vesa/debug.h20
-rw-r--r--com32/lib/sys/vesa/drawtxt.c410
-rw-r--r--com32/lib/sys/vesa/fill.h47
-rw-r--r--com32/lib/sys/vesa/fmtpixel.c79
-rw-r--r--com32/lib/sys/vesa/initvesa.c443
-rw-r--r--com32/lib/sys/vesa/screencpy.c132
-rw-r--r--com32/lib/sys/vesa/vesa.h101
-rw-r--r--com32/lib/sys/vesa/video.h20
-rw-r--r--com32/lib/sys/vesacon_write.c121
-rw-r--r--com32/lib/sys/vesaserial_write.c21
-rw-r--r--com32/lib/sys/write.c12
-rw-r--r--com32/lib/sys/x86_init_fpu.c42
-rw-r--r--com32/lib/sys/xserial_write.c116
-rw-r--r--com32/lib/sys/zfile.c172
-rw-r--r--com32/lib/sys/zfopen.c54
-rw-r--r--com32/lib/syslinux/addlist.c20
-rw-r--r--com32/lib/syslinux/adv.c10
-rw-r--r--com32/lib/syslinux/advwrite.c8
-rw-r--r--com32/lib/syslinux/cleanup.c8
-rw-r--r--com32/lib/syslinux/config.c8
-rw-r--r--com32/lib/syslinux/dsinfo.c12
-rw-r--r--com32/lib/syslinux/dump_mmap.c17
-rw-r--r--com32/lib/syslinux/dump_movelist.c15
-rw-r--r--com32/lib/syslinux/features.c12
-rw-r--r--com32/lib/syslinux/floadfile.c114
-rw-r--r--com32/lib/syslinux/freelist.c12
-rw-r--r--com32/lib/syslinux/getadv.c42
-rw-r--r--com32/lib/syslinux/idle.c24
-rw-r--r--com32/lib/syslinux/initramfs.c48
-rw-r--r--com32/lib/syslinux/initramfs_archive.c10
-rw-r--r--com32/lib/syslinux/initramfs_file.c164
-rw-r--r--com32/lib/syslinux/initramfs_loadfile.c12
-rw-r--r--com32/lib/syslinux/ipappend.c24
-rw-r--r--com32/lib/syslinux/keyboard.c16
-rw-r--r--com32/lib/syslinux/load_linux.c729
-rw-r--r--com32/lib/syslinux/loadfile.c24
-rw-r--r--com32/lib/syslinux/localboot.c8
-rw-r--r--com32/lib/syslinux/memmap.c24
-rw-r--r--com32/lib/syslinux/memscan.c188
-rw-r--r--com32/lib/syslinux/movebits.c1021
-rw-r--r--com32/lib/syslinux/pxe_get_cached.c54
-rw-r--r--com32/lib/syslinux/pxe_get_nic.c24
-rw-r--r--com32/lib/syslinux/reboot.c10
-rw-r--r--com32/lib/syslinux/run_command.c16
-rw-r--r--com32/lib/syslinux/run_default.c10
-rw-r--r--com32/lib/syslinux/runimage.c36
-rw-r--r--com32/lib/syslinux/serial.c14
-rw-r--r--com32/lib/syslinux/setadv.c116
-rw-r--r--com32/lib/syslinux/shuffle.c317
-rw-r--r--com32/lib/syslinux/shuffle_pm.c61
-rw-r--r--com32/lib/syslinux/shuffle_rm.c172
-rw-r--r--com32/lib/syslinux/version.c16
-rw-r--r--com32/lib/syslinux/zloadfile.c18
-rw-r--r--com32/lib/syslinux/zonelist.c302
-rw-r--r--com32/lib/vasprintf.c20
-rw-r--r--com32/lib/vfprintf.c18
-rw-r--r--com32/lib/vprintf.c2
-rw-r--r--com32/lib/vsnprintf.c785
-rw-r--r--com32/lib/vsprintf.c2
-rw-r--r--com32/lib/vsscanf.c615
-rw-r--r--com32/lib/zalloc.c10
-rw-r--r--com32/libutil/ansiline.c39
-rw-r--r--com32/libutil/ansiraw.c43
-rw-r--r--com32/libutil/base64.c131
-rw-r--r--com32/libutil/crypt-md5.c247
-rw-r--r--com32/libutil/get_key.c225
-rw-r--r--com32/libutil/include/base64.h4
-rw-r--r--com32/libutil/include/md5.h8
-rw-r--r--com32/libutil/include/sha1.h8
-rw-r--r--com32/libutil/include/xcrypt.h4
-rw-r--r--com32/libutil/md5.c279
-rw-r--r--com32/libutil/sha1hash.c288
-rw-r--r--com32/libutil/sha256crypt.c1029
-rw-r--r--com32/libutil/sha512crypt.c1177
-rw-r--r--com32/libutil/unbase64.c59
-rw-r--r--com32/mboot/apm.c89
-rw-r--r--com32/mboot/map.c467
-rw-r--r--com32/mboot/mb_header.h52
-rw-r--r--com32/mboot/mb_info.h188
-rw-r--r--com32/mboot/mboot.c335
-rw-r--r--com32/mboot/mboot.h6
-rw-r--r--com32/mboot/mem.c273
-rw-r--r--com32/mboot/solaris.c19
-rw-r--r--com32/menu/background.c10
-rw-r--r--com32/menu/colors.c227
-rw-r--r--com32/menu/drain.c26
-rw-r--r--com32/menu/execute.c78
-rw-r--r--com32/menu/menu.c10
-rw-r--r--com32/menu/menu.h178
-rw-r--r--com32/menu/menumain.c1846
-rw-r--r--com32/menu/passwd.c100
-rw-r--r--com32/menu/printmsg.c140
-rw-r--r--com32/menu/readconfig.c1646
-rw-r--r--com32/menu/refstr.c92
-rw-r--r--com32/menu/refstr.h8
-rw-r--r--com32/menu/vesamenu.c16
-rw-r--r--com32/modules/chain.c1137
-rw-r--r--com32/modules/cmd.c4
-rw-r--r--com32/modules/config.c16
-rw-r--r--com32/modules/cpuidtest.c130
-rw-r--r--com32/modules/dmi_utils.c65
-rw-r--r--com32/modules/dmitest.c277
-rw-r--r--com32/modules/elf.c367
-rw-r--r--com32/modules/ethersel.c252
-rw-r--r--com32/modules/ifcpu64.c111
-rw-r--r--com32/modules/kbdmap.c58
-rw-r--r--com32/modules/linux.c274
-rw-r--r--com32/modules/meminfo.c157
-rw-r--r--com32/modules/pcitest.c146
-rw-r--r--com32/modules/pmload.c248
-rw-r--r--com32/modules/reboot.c15
-rw-r--r--com32/modules/sanboot.c142
-rw-r--r--com32/modules/sdi.c248
-rw-r--r--com32/modules/vesainfo.c93
-rw-r--r--com32/modules/vpdtest.c46
-rw-r--r--com32/rosh/rosh.c1090
-rw-r--r--com32/rosh/rosh.h86
-rw-r--r--com32/samples/advdump.c36
-rw-r--r--com32/samples/cat.c34
-rw-r--r--com32/samples/entrydump.c48
-rw-r--r--com32/samples/fancyhello.c22
-rw-r--r--com32/samples/hello.c12
-rw-r--r--com32/samples/keytest.c64
-rw-r--r--com32/samples/localboot.c4
-rw-r--r--com32/samples/resolv.c52
-rw-r--r--com32/samples/serialinfo.c19
-rw-r--r--dos/__divdi3.c30
-rw-r--r--dos/__udivmoddi4.c42
-rw-r--r--dos/argv.c80
-rw-r--r--dos/atou.c8
-rw-r--r--dos/conio.c22
-rw-r--r--dos/free.c93
-rw-r--r--dos/malloc.c153
-rw-r--r--dos/malloc.h10
-rw-r--r--dos/mystuff.h5
-rw-r--r--dos/perror.c2
-rw-r--r--dos/printf.c481
-rw-r--r--dos/skipatou.c8
-rw-r--r--dos/stdint.h56
-rw-r--r--dos/stdio.h2
-rw-r--r--dos/stdlib.h2
-rw-r--r--dos/string.h8
-rw-r--r--dos/syslinux.c985
-rw-r--r--dummy.c2
-rw-r--r--extlinux/ext2_fs.h341
-rw-r--r--extlinux/main.c1360
-rw-r--r--libfat/cache.c58
-rw-r--r--libfat/fat.h132
-rw-r--r--libfat/fatchain.c190
-rw-r--r--libfat/libfat.h16
-rw-r--r--libfat/libfatint.h36
-rw-r--r--libfat/open.c176
-rw-r--r--libfat/searchdir.c67
-rw-r--r--libfat/ulint.h84
-rw-r--r--libinstaller/setadv.c180
-rw-r--r--libinstaller/syslinux.h26
-rw-r--r--libinstaller/syslxint.h164
-rw-r--r--libinstaller/syslxmod.c347
-rw-r--r--linux/syslinux.c757
-rw-r--r--mbr/adjust.h16
-rw-r--r--memdisk/conio.c532
-rw-r--r--memdisk/e820.h6
-rw-r--r--memdisk/e820func.c120
-rw-r--r--memdisk/e820test.c86
-rw-r--r--memdisk/inflate.c1399
-rw-r--r--memdisk/memdisk.h51
-rw-r--r--memdisk/msetup.c201
-rw-r--r--memdisk/setup.c1752
-rw-r--r--memdisk/unzip.c411
-rw-r--r--memdump/__divdi3.c30
-rw-r--r--memdump/__udivmoddi4.c42
-rw-r--r--memdump/argv.c82
-rw-r--r--memdump/conio.c22
-rw-r--r--memdump/io.h24
-rw-r--r--memdump/main.c156
-rw-r--r--memdump/malloc.h10
-rw-r--r--memdump/mystuff.h5
-rw-r--r--memdump/printf.c481
-rw-r--r--memdump/serial.c106
-rw-r--r--memdump/skipatou.c8
-rw-r--r--memdump/stdint.h56
-rw-r--r--memdump/stdio.h2
-rw-r--r--memdump/stdlib.h2
-rw-r--r--memdump/string.h8
-rw-r--r--memdump/strtoul.c90
-rw-r--r--memdump/ymsend.c270
-rw-r--r--memdump/ymsend.h14
-rw-r--r--mtools/syslinux.c529
-rw-r--r--sample/atou.c13
-rw-r--r--sample/c32echo.c29
-rw-r--r--sample/conio.c37
-rw-r--r--sample/fd.c64
-rw-r--r--sample/filetest.c129
-rw-r--r--sample/hello.c23
-rw-r--r--sample/hello2.c32
-rw-r--r--sample/mdiskchk.c202
-rw-r--r--sample/printf.c486
-rw-r--r--sample/skipatou.c13
-rw-r--r--utils/gethostip.c176
-rw-r--r--win32/hello.c4
-rw-r--r--win32/syslinux.c815
409 files changed, 29346 insertions, 28788 deletions
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 78ce72fa..ba955e99 100644
--- a/com32/cmenu/libmenu/com32io.h
+++ b/com32/cmenu/libmenu/com32io.h
@@ -28,55 +28,55 @@ 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()
{
- return readbiosb(0x484); // Actually numrows - 1
+ return readbiosb(0x484); // Actually numrows - 1
}
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;
}
diff --git a/com32/gdbstub/gdbstub.c b/com32/gdbstub/gdbstub.c
index f235a349..bd19addc 100644
--- a/com32/gdbstub/gdbstub.c
+++ b/com32/gdbstub/gdbstub.c
@@ -30,203 +30,215 @@
typedef uint32_t gdbreg_t;
enum {
- POSIX_EINVAL = 0x1c, /* used to report bad arguments to GDB */
- SIZEOF_PAYLOAD = 256, /* buffer size of GDB payload data */
- DR7_CLEAR = 0x00000400, /* disable hardware breakpoints */
- DR6_CLEAR = 0xffff0ff0, /* clear breakpoint status */
+ POSIX_EINVAL = 0x1c, /* used to report bad arguments to GDB */
+ SIZEOF_PAYLOAD = 256, /* buffer size of GDB payload data */
+ DR7_CLEAR = 0x00000400, /* disable hardware breakpoints */
+ DR6_CLEAR = 0xffff0ff0, /* clear breakpoint status */
};
/* The register snapshot, this must be in sync with interrupt handler and the
* GDB protocol. */
enum {
- GDBMACH_EAX,
- GDBMACH_ECX,
- GDBMACH_EDX,
- GDBMACH_EBX,
- GDBMACH_ESP,
- GDBMACH_EBP,
- GDBMACH_ESI,
- GDBMACH_EDI,
- GDBMACH_EIP,
- GDBMACH_EFLAGS,
- GDBMACH_CS,
- GDBMACH_SS,
- GDBMACH_DS,
- GDBMACH_ES,
- GDBMACH_FS,
- GDBMACH_GS,
- GDBMACH_NREGS,
- GDBMACH_SIZEOF_REGS = GDBMACH_NREGS * sizeof ( gdbreg_t )
+ GDBMACH_EAX,
+ GDBMACH_ECX,
+ GDBMACH_EDX,
+ GDBMACH_EBX,
+ GDBMACH_ESP,
+ GDBMACH_EBP,
+ GDBMACH_ESI,
+ GDBMACH_EDI,
+ GDBMACH_EIP,
+ GDBMACH_EFLAGS,
+ GDBMACH_CS,
+ GDBMACH_SS,
+ GDBMACH_DS,
+ GDBMACH_ES,
+ GDBMACH_FS,
+ GDBMACH_GS,
+ GDBMACH_NREGS,
+ GDBMACH_SIZEOF_REGS = GDBMACH_NREGS * sizeof(gdbreg_t)
};
/* Breakpoint types */
enum {
- GDBMACH_BPMEM,
- GDBMACH_BPHW,
- GDBMACH_WATCH,
- GDBMACH_RWATCH,
- GDBMACH_AWATCH,
+ GDBMACH_BPMEM,
+ GDBMACH_BPHW,
+ GDBMACH_WATCH,
+ GDBMACH_RWATCH,
+ GDBMACH_AWATCH,
};
struct gdbstub {
- int exit_handler; /* leave interrupt handler */
+ int exit_handler; /* leave interrupt handler */
- int signo;
- gdbreg_t *regs;
+ int signo;
+ gdbreg_t *regs;
- void ( * parse ) ( struct gdbstub *stub, char ch );
- uint8_t cksum1;
+ void (*parse) (struct gdbstub * stub, char ch);
+ uint8_t cksum1;
- /* Buffer for payload data when parsing a packet. Once the
- * packet has been received, this buffer is used to hold
- * the reply payload. */
- char buf [ SIZEOF_PAYLOAD + 4 ]; /* $...PAYLOAD...#XX */
- char *payload; /* start of payload */
- int len; /* length of payload */
+ /* Buffer for payload data when parsing a packet. Once the
+ * packet has been received, this buffer is used to hold
+ * the reply payload. */
+ char buf[SIZEOF_PAYLOAD + 4]; /* $...PAYLOAD...#XX */
+ char *payload; /* start of payload */
+ int len; /* length of payload */
};
/** Hardware breakpoint, fields stored in x86 bit pattern form */
struct hwbp {
- int type; /* type (1=write watchpoint, 3=access watchpoint) */
- unsigned long addr; /* linear address */
- size_t len; /* length (0=1-byte, 1=2-byte, 3=4-byte) */
- int enabled;
+ int type; /* type (1=write watchpoint, 3=access watchpoint) */
+ unsigned long addr; /* linear address */
+ size_t len; /* length (0=1-byte, 1=2-byte, 3=4-byte) */
+ int enabled;
};
-static struct hwbp hwbps [ 4 ];
+static struct hwbp hwbps[4];
static gdbreg_t dr7 = DR7_CLEAR;
-static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) {
- regs [ GDBMACH_EIP ] = pc;
+static inline void gdbmach_set_pc(gdbreg_t * regs, gdbreg_t pc)
+{
+ regs[GDBMACH_EIP] = pc;
}
-static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) {
- regs [ GDBMACH_EFLAGS ] &= ~( 1 << 8 ); /* Trace Flag (TF) */
- regs [ GDBMACH_EFLAGS ] |= ( step << 8 );
+static inline void gdbmach_set_single_step(gdbreg_t * regs, int step)
+{
+ regs[GDBMACH_EFLAGS] &= ~(1 << 8); /* Trace Flag (TF) */
+ regs[GDBMACH_EFLAGS] |= (step << 8);
}
-static inline void gdbmach_breakpoint ( void ) {
- __asm__ __volatile__ ( "int $3\n" );
+static inline void gdbmach_breakpoint(void)
+{
+ __asm__ __volatile__("int $3\n");
}
-static struct hwbp *gdbmach_find_hwbp ( int type, unsigned long addr, size_t len ) {
- struct hwbp *available = NULL;
- unsigned int i;
- for ( i = 0; i < sizeof hwbps / sizeof hwbps [ 0 ]; i++ ) {
- if ( hwbps [ i ].type == type && hwbps [ i ].addr == addr && hwbps [ i ].len == len ) {
- return &hwbps [ i ];
- }
- if ( !hwbps [ i ].enabled ) {
- available = &hwbps [ i ];
- }
+static struct hwbp *gdbmach_find_hwbp(int type, unsigned long addr, size_t len)
+{
+ struct hwbp *available = NULL;
+ unsigned int i;
+ for (i = 0; i < sizeof hwbps / sizeof hwbps[0]; i++) {
+ if (hwbps[i].type == type && hwbps[i].addr == addr
+ && hwbps[i].len == len) {
+ return &hwbps[i];
}
- return available;
-}
-
-static void gdbmach_commit_hwbp ( struct hwbp *bp ) {
- int regnum = bp - hwbps;
-
- /* Set breakpoint address */
- switch ( regnum ) {
- case 0:
- __asm__ __volatile__ ( "movl %0, %%dr0\n" : : "r" ( bp->addr ) );
- break;
- case 1:
- __asm__ __volatile__ ( "movl %0, %%dr1\n" : : "r" ( bp->addr ) );
- break;
- case 2:
- __asm__ __volatile__ ( "movl %0, %%dr2\n" : : "r" ( bp->addr ) );
- break;
- case 3:
- __asm__ __volatile__ ( "movl %0, %%dr3\n" : : "r" ( bp->addr ) );
- break;
+ if (!hwbps[i].enabled) {
+ available = &hwbps[i];
}
+ }
+ return available;
+}
+
+static void gdbmach_commit_hwbp(struct hwbp *bp)
+{
+ int regnum = bp - hwbps;
+
+ /* Set breakpoint address */
+ switch (regnum) {
+ case 0:
+__asm__ __volatile__("movl %0, %%dr0\n": :"r"(bp->addr));
+ break;
+ case 1:
+__asm__ __volatile__("movl %0, %%dr1\n": :"r"(bp->addr));
+ break;
+ case 2:
+__asm__ __volatile__("movl %0, %%dr2\n": :"r"(bp->addr));
+ break;
+ case 3:
+__asm__ __volatile__("movl %0, %%dr3\n": :"r"(bp->addr));
+ break;
+ }
- /* Set type */
- dr7 &= ~( 0x3 << ( 16 + 4 * regnum ) );
- dr7 |= bp->type << ( 16 + 4 * regnum );
-
- /* Set length */
- dr7 &= ~( 0x3 << ( 18 + 4 * regnum ) );
- dr7 |= bp->len << ( 18 + 4 * regnum );
-
- /* Set/clear local enable bit */
- dr7 &= ~( 0x3 << 2 * regnum );
- dr7 |= bp->enabled << 2 * regnum;
-}
-
-int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, int enable ) {
- struct hwbp *bp;
-
- /* Check and convert breakpoint type to x86 type */
- switch ( type ) {
- case GDBMACH_WATCH:
- type = 0x1;
- break;
- case GDBMACH_AWATCH:
- type = 0x3;
- break;
- default:
- return 0; /* unsupported breakpoint type */
- }
+ /* Set type */
+ dr7 &= ~(0x3 << (16 + 4 * regnum));
+ dr7 |= bp->type << (16 + 4 * regnum);
+
+ /* Set length */
+ dr7 &= ~(0x3 << (18 + 4 * regnum));
+ dr7 |= bp->len << (18 + 4 * regnum);
+
+ /* Set/clear local enable bit */
+ dr7 &= ~(0x3 << 2 * regnum);
+ dr7 |= bp->enabled << 2 * regnum;
+}
+
+int gdbmach_set_breakpoint(int type, unsigned long addr, size_t len, int enable)
+{
+ struct hwbp *bp;
+
+ /* Check and convert breakpoint type to x86 type */
+ switch (type) {
+ case GDBMACH_WATCH:
+ type = 0x1;
+ break;
+ case GDBMACH_AWATCH:
+ type = 0x3;
+ break;
+ default:
+ return 0; /* unsupported breakpoint type */
+ }
- /* Only lengths 1, 2, and 4 are supported */
- if ( len != 2 && len != 4 ) {
- len = 1;
- }
- len--; /* convert to x86 breakpoint length bit pattern */
+ /* Only lengths 1, 2, and 4 are supported */
+ if (len != 2 && len != 4) {
+ len = 1;
+ }
+ len--; /* convert to x86 breakpoint length bit pattern */
- /* Set up the breakpoint */
- bp = gdbmach_find_hwbp ( type, addr, len );
- if ( !bp ) {
- return 0; /* ran out of hardware breakpoints */
- }
- bp->type = type;
- bp->addr = addr;
- bp->len = len;
- bp->enabled = enable;
- gdbmach_commit_hwbp ( bp );
- return 1;
+ /* Set up the breakpoint */
+ bp = gdbmach_find_hwbp(type, addr, len);
+ if (!bp) {
+ return 0; /* ran out of hardware breakpoints */
+ }
+ bp->type = type;
+ bp->addr = addr;
+ bp->len = len;
+ bp->enabled = enable;
+ gdbmach_commit_hwbp(bp);
+ return 1;
}
-static void gdbmach_disable_hwbps ( void ) {
- /* Store and clear hardware breakpoints */
- __asm__ __volatile__ ( "movl %0, %%dr7\n" : : "r" ( DR7_CLEAR ) );
+static void gdbmach_disable_hwbps(void)
+{
+ /* Store and clear hardware breakpoints */
+ __asm__ __volatile__("movl %0, %%dr7\n"::"r"(DR7_CLEAR));
}
-static void gdbmach_enable_hwbps ( void ) {
- /* Clear breakpoint status register */
- __asm__ __volatile__ ( "movl %0, %%dr6\n" : : "r" ( DR6_CLEAR ) );
+static void gdbmach_enable_hwbps(void)
+{
+ /* Clear breakpoint status register */
+ __asm__ __volatile__("movl %0, %%dr6\n"::"r"(DR6_CLEAR));
- /* Restore hardware breakpoints */
- __asm__ __volatile__ ( "movl %0, %%dr7\n" : : "r" ( dr7 ) );
+ /* Restore hardware breakpoints */
+ __asm__ __volatile__("movl %0, %%dr7\n"::"r"(dr7));
}
/* Packet parser states */
-static void gdbstub_state_new ( struct gdbstub *stub, char ch );
-static void gdbstub_state_data ( struct gdbstub *stub, char ch );
-static void gdbstub_state_cksum1 ( struct gdbstub *stub, char ch );
-static void gdbstub_state_cksum2 ( struct gdbstub *stub, char ch );
-static void gdbstub_state_wait_ack ( struct gdbstub *stub, char ch );
-
-static void serial_write ( void *buf, size_t len ) {
+static void gdbstub_state_new(struct gdbstub *stub, char ch);
+static void gdbstub_state_data(struct gdbstub *stub, char ch);
+static void gdbstub_state_cksum1(struct gdbstub *stub, char ch);
+static void gdbstub_state_cksum2(struct gdbstub *stub, char ch);
+static void gdbstub_state_wait_ack(struct gdbstub *stub, char ch);
+
+static void serial_write(void *buf, size_t len)
+{
char *p = buf;
- while ( len-- > 0 )
- serial_putc ( *p++ );
+ while (len-- > 0)
+ serial_putc(*p++);
}
-static uint8_t gdbstub_from_hex_digit ( char ch ) {
- if ( ch >= '0' && ch <= '9' )
- return ch - '0';
- else if ( ch >= 'A' && ch <= 'F' )
- return ch - 'A' + 0xa;
+static uint8_t gdbstub_from_hex_digit(char ch)
+{
+ if (ch >= '0' && ch <= '9')
+ return ch - '0';
+ else if (ch >= 'A' && ch <= 'F')
+ return ch - 'A' + 0xa;
else
- return ( ch - 'a' + 0xa ) & 0xf;
+ return (ch - 'a' + 0xa) & 0xf;
}
-static uint8_t gdbstub_to_hex_digit ( uint8_t b ) {
- b &= 0xf;
- return ( b < 0xa ? '0' : 'a' - 0xa ) + b;
+static uint8_t gdbstub_to_hex_digit(uint8_t b)
+{
+ b &= 0xf;
+ return (b < 0xa ? '0' : 'a' - 0xa) + b;
}
/*
@@ -234,296 +246,324 @@ static uint8_t gdbstub_to_hex_digit ( uint8_t b ) {
* 2- or 4-byte aligned operations and handle them specially.
*/
-static void gdbstub_from_hex_buf ( char *dst, char *src, int lenbytes ) {
- if ( lenbytes == 2 && ( ( unsigned long ) dst & 0x1 ) == 0 ) {
- uint16_t i = gdbstub_from_hex_digit ( src [ 2 ] ) << 12 |
- gdbstub_from_hex_digit ( src [ 3 ] ) << 8 |
- gdbstub_from_hex_digit ( src [ 0 ] ) << 4 |
- gdbstub_from_hex_digit ( src [ 1 ] );
- * ( uint16_t * ) dst = i;
- } else if ( lenbytes == 4 && ( ( unsigned long ) dst & 0x3 ) == 0 ) {
- uint32_t i = gdbstub_from_hex_digit ( src [ 6 ] ) << 28 |
- gdbstub_from_hex_digit ( src [ 7 ] ) << 24 |
- gdbstub_from_hex_digit ( src [ 4 ] ) << 20 |
- gdbstub_from_hex_digit ( src [ 5 ] ) << 16 |
- gdbstub_from_hex_digit ( src [ 2 ] ) << 12 |
- gdbstub_from_hex_digit ( src [ 3 ] ) << 8 |
- gdbstub_from_hex_digit ( src [ 0 ] ) << 4 |
- gdbstub_from_hex_digit ( src [ 1 ] );
- * ( uint32_t * ) dst = i;
- } else {
- while ( lenbytes-- > 0 ) {
- *dst++ = gdbstub_from_hex_digit ( src [ 0 ] ) << 4 |
- gdbstub_from_hex_digit ( src [ 1 ] );
- src += 2;
- }
+static void gdbstub_from_hex_buf(char *dst, char *src, int lenbytes)
+{
+ if (lenbytes == 2 && ((unsigned long)dst & 0x1) == 0) {
+ uint16_t i = gdbstub_from_hex_digit(src[2]) << 12 |
+ gdbstub_from_hex_digit(src[3]) << 8 |
+ gdbstub_from_hex_digit(src[0]) << 4 |
+ gdbstub_from_hex_digit(src[1]);
+ *(uint16_t *) dst = i;
+ } else if (lenbytes == 4 && ((unsigned long)dst & 0x3) == 0) {
+ uint32_t i = gdbstub_from_hex_digit(src[6]) << 28 |
+ gdbstub_from_hex_digit(src[7]) << 24 |
+ gdbstub_from_hex_digit(src[4]) << 20 |
+ gdbstub_from_hex_digit(src[5]) << 16 |
+ gdbstub_from_hex_digit(src[2]) << 12 |
+ gdbstub_from_hex_digit(src[3]) << 8 |
+ gdbstub_from_hex_digit(src[0]) << 4 |
+ gdbstub_from_hex_digit(src[1]);
+ *(uint32_t *) dst = i;
+ } else {
+ while (lenbytes-- > 0) {
+ *dst++ = gdbstub_from_hex_digit(src[0]) << 4 |
+ gdbstub_from_hex_digit(src[1]);
+ src += 2;
}
+ }
}
-static void gdbstub_to_hex_buf ( char *dst, char *src, int lenbytes ) {
- if ( lenbytes == 2 && ( ( unsigned long ) src & 0x1 ) == 0 ) {
- uint16_t i = * ( uint16_t * ) src;
- dst [ 0 ] = gdbstub_to_hex_digit ( i >> 4 );
- dst [ 1 ] = gdbstub_to_hex_digit ( i );
- dst [ 2 ] = gdbstub_to_hex_digit ( i >> 12 );
- dst [ 3 ] = gdbstub_to_hex_digit ( i >> 8 );
- } else if ( lenbytes == 4 && ( ( unsigned long ) src & 0x3 ) == 0 ) {
- uint32_t i = * ( uint32_t * ) src;
- dst [ 0 ] = gdbstub_to_hex_digit ( i >> 4 );
- dst [ 1 ] = gdbstub_to_hex_digit ( i );
- dst [ 2 ] = gdbstub_to_hex_digit ( i >> 12 );
- dst [ 3 ] = gdbstub_to_hex_digit ( i >> 8 );
- dst [ 4 ] = gdbstub_to_hex_digit ( i >> 20 );
- dst [ 5 ] = gdbstub_to_hex_digit ( i >> 16);
- dst [ 6 ] = gdbstub_to_hex_digit ( i >> 28 );
- dst [ 7 ] = gdbstub_to_hex_digit ( i >> 24 );
- } else {
- while ( lenbytes-- > 0 ) {
- *dst++ = gdbstub_to_hex_digit ( *src >> 4 );
- *dst++ = gdbstub_to_hex_digit ( *src );
- src++;
- }
+static void gdbstub_to_hex_buf(char *dst, char *src, int lenbytes)
+{
+ if (lenbytes == 2 && ((unsigned long)src & 0x1) == 0) {
+ uint16_t i = *(uint16_t *) src;
+ dst[0] = gdbstub_to_hex_digit(i >> 4);
+ dst[1] = gdbstub_to_hex_digit(i);
+ dst[2] = gdbstub_to_hex_digit(i >> 12);
+ dst[3] = gdbstub_to_hex_digit(i >> 8);
+ } else if (lenbytes == 4 && ((unsigned long)src & 0x3) == 0) {
+ uint32_t i = *(uint32_t *) src;
+ dst[0] = gdbstub_to_hex_digit(i >> 4);
+ dst[1] = gdbstub_to_hex_digit(i);
+ dst[2] = gdbstub_to_hex_digit(i >> 12);
+ dst[3] = gdbstub_to_hex_digit(i >> 8);
+ dst[4] = gdbstub_to_hex_digit(i >> 20);
+ dst[5] = gdbstub_to_hex_digit(i >> 16);
+ dst[6] = gdbstub_to_hex_digit(i >> 28);
+ dst[7] = gdbstub_to_hex_digit(i >> 24);
+ } else {
+ while (lenbytes-- > 0) {
+ *dst++ = gdbstub_to_hex_digit(*src >> 4);
+ *dst++ = gdbstub_to_hex_digit(*src);
+ src++;
}
+ }
}
-static uint8_t gdbstub_cksum ( char *data, int len ) {
- uint8_t cksum = 0;
- while ( len-- > 0 ) {
- cksum += ( uint8_t ) *data++;
- }
- return cksum;
+static uint8_t gdbstub_cksum(char *data, int len)
+{
+ uint8_t cksum = 0;
+ while (len-- > 0) {
+ cksum += (uint8_t) * data++;
+ }
+ return cksum;
}
-static void gdbstub_tx_packet ( struct gdbstub *stub ) {
- uint8_t cksum = gdbstub_cksum ( stub->payload, stub->len );
- stub->buf [ 0 ] = '$';
- stub->buf [ stub->len + 1 ] = '#';
- stub->buf [ stub->len + 2 ] = gdbstub_to_hex_digit ( cksum >> 4 );
- stub->buf [ stub->len + 3 ] = gdbstub_to_hex_digit ( cksum );
- serial_write ( stub->buf, stub->len + 4 );
- stub->parse = gdbstub_state_wait_ack;
+static void gdbstub_tx_packet(struct gdbstub *stub)
+{
+ uint8_t cksum = gdbstub_cksum(stub->payload, stub->len);
+ stub->buf[0] = '$';
+ stub->buf[stub->len + 1] = '#';
+ stub->buf[stub->len + 2] = gdbstub_to_hex_digit(cksum >> 4);
+ stub->buf[stub->len + 3] = gdbstub_to_hex_digit(cksum);
+ serial_write(stub->buf, stub->len + 4);
+ stub->parse = gdbstub_state_wait_ack;
}
/* GDB commands */
-static void gdbstub_send_ok ( struct gdbstub *stub ) {
- stub->payload [ 0 ] = 'O';
- stub->payload [ 1 ] = 'K';
- stub->len = 2;
- gdbstub_tx_packet ( stub );
+static void gdbstub_send_ok(struct gdbstub *stub)
+{
+ stub->payload[0] = 'O';
+ stub->payload[1] = 'K';
+ stub->len = 2;
+ gdbstub_tx_packet(stub);
}
-static void gdbstub_send_num_packet ( struct gdbstub *stub, char reply, int num ) {
- stub->payload [ 0 ] = reply;
- stub->payload [ 1 ] = gdbstub_to_hex_digit ( ( char ) num >> 4 );
- stub->payload [ 2 ] = gdbstub_to_hex_digit ( ( char ) num );
- stub->len = 3;
- gdbstub_tx_packet ( stub );
+static void gdbstub_send_num_packet(struct gdbstub *stub, char reply, int num)
+{
+ stub->payload[0] = reply;
+ stub->payload[1] = gdbstub_to_hex_digit((char)num >> 4);
+ stub->payload[2] = gdbstub_to_hex_digit((char)num);
+ stub->len = 3;
+ gdbstub_tx_packet(stub);
}
/* Format is arg1,arg2,...,argn:data where argn are hex integers and data is not an argument */
-static int gdbstub_get_packet_args ( struct gdbstub *stub, unsigned long *args, int nargs, int *stop_idx ) {
- int i;
- char ch = 0;
- int argc = 0;
- unsigned long val = 0;
- for ( i = 1; i < stub->len && argc < nargs; i++ ) {
- ch = stub->payload [ i ];
- if ( ch == ':' ) {
- break;
- } else if ( ch == ',' ) {
- args [ argc++ ] = val;
- val = 0;
- } else {
- val = ( val << 4 ) | gdbstub_from_hex_digit ( ch );
- }
- }
- if ( stop_idx ) {
- *stop_idx = i;
- }
- if ( argc < nargs ) {
- args [ argc++ ] = val;
+static int gdbstub_get_packet_args(struct gdbstub *stub, unsigned long *args,
+ int nargs, int *stop_idx)
+{
+ int i;
+ char ch = 0;
+ int argc = 0;
+ unsigned long val = 0;
+ for (i = 1; i < stub->len && argc < nargs; i++) {
+ ch = stub->payload[i];
+ if (ch == ':') {
+ break;
+ } else if (ch == ',') {
+ args[argc++] = val;
+ val = 0;
+ } else {
+ val = (val << 4) | gdbstub_from_hex_digit(ch);
}
- return ( ( i == stub->len || ch == ':' ) && argc == nargs );
-}
-
-static void gdbstub_send_errno ( struct gdbstub *stub, int errno ) {
- gdbstub_send_num_packet ( stub, 'E', errno );
-}
-
-static void gdbstub_report_signal ( struct gdbstub *stub ) {
- gdbstub_send_num_packet ( stub, 'S', stub->signo );
+ }
+ if (stop_idx) {
+ *stop_idx = i;
+ }
+ if (argc < nargs) {
+ args[argc++] = val;
+ }
+ return ((i == stub->len || ch == ':') && argc == nargs);
}
-static void gdbstub_read_regs ( struct gdbstub *stub ) {
- gdbstub_to_hex_buf ( stub->payload, ( char * ) stub->regs, GDBMACH_SIZEOF_REGS );
- stub->len = GDBMACH_SIZEOF_REGS * 2;
- gdbstub_tx_packet ( stub );
+static void gdbstub_send_errno(struct gdbstub *stub, int errno)
+{
+ gdbstub_send_num_packet(stub, 'E', errno);
}
-static void gdbstub_write_regs ( struct gdbstub *stub ) {
- if ( stub->len != 1 + GDBMACH_SIZEOF_REGS * 2 ) {
- gdbstub_send_errno ( stub, POSIX_EINVAL );
- return;
- }
- gdbstub_from_hex_buf ( ( char * ) stub->regs, &stub->payload [ 1 ], GDBMACH_SIZEOF_REGS );
- gdbstub_send_ok ( stub );
+static void gdbstub_report_signal(struct gdbstub *stub)
+{
+ gdbstub_send_num_packet(stub, 'S', stub->signo);
}
-static void gdbstub_read_mem ( struct gdbstub *stub ) {
- unsigned long args [ 2 ];
- if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], NULL ) ) {
- gdbstub_send_errno ( stub, POSIX_EINVAL );
- return;
- }
- args [ 1 ] = ( args [ 1 ] < SIZEOF_PAYLOAD / 2 ) ? args [ 1 ] : SIZEOF_PAYLOAD / 2;
- gdbstub_to_hex_buf ( stub->payload, ( char * ) args [ 0 ], args [ 1 ] );
- stub->len = args [ 1 ] * 2;
- gdbstub_tx_packet ( stub );
-}
-
-static void gdbstub_write_mem ( struct gdbstub *stub ) {
- unsigned long args [ 2 ];
- int colon;
- if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], &colon ) ||
- colon >= stub->len || stub->payload [ colon ] != ':' ||
- ( stub->len - colon - 1 ) % 2 != 0 ) {
- gdbstub_send_errno ( stub, POSIX_EINVAL );
- return;
- }
- gdbstub_from_hex_buf ( ( char * ) args [ 0 ], &stub->payload [ colon + 1 ], ( stub->len - colon - 1 ) / 2 );
- gdbstub_send_ok ( stub );
+static void gdbstub_read_regs(struct gdbstub *stub)
+{
+ gdbstub_to_hex_buf(stub->payload, (char *)stub->regs, GDBMACH_SIZEOF_REGS);
+ stub->len = GDBMACH_SIZEOF_REGS * 2;
+ gdbstub_tx_packet(stub);
}
-static void gdbstub_continue ( struct gdbstub *stub, int single_step ) {
- gdbreg_t pc;
- if ( stub->len > 1 && gdbstub_get_packet_args ( stub, (unsigned long *)&pc, 1, NULL ) ) {
- gdbmach_set_pc ( stub->regs, pc );
- }
- gdbmach_set_single_step ( stub->regs, single_step );
- stub->exit_handler = 1;
- /* Reply will be sent when we hit the next breakpoint or interrupt */
+static void gdbstub_write_regs(struct gdbstub *stub)
+{
+ if (stub->len != 1 + GDBMACH_SIZEOF_REGS * 2) {
+ gdbstub_send_errno(stub, POSIX_EINVAL);
+ return;
+ }
+ gdbstub_from_hex_buf((char *)stub->regs, &stub->payload[1],
+ GDBMACH_SIZEOF_REGS);
+ gdbstub_send_ok(stub);
+}
+
+static void gdbstub_read_mem(struct gdbstub *stub)
+{
+ unsigned long args[2];
+ if (!gdbstub_get_packet_args
+ (stub, args, sizeof args / sizeof args[0], NULL)) {
+ gdbstub_send_errno(stub, POSIX_EINVAL);
+ return;
+ }
+ args[1] = (args[1] < SIZEOF_PAYLOAD / 2) ? args[1] : SIZEOF_PAYLOAD / 2;
+ gdbstub_to_hex_buf(stub->payload, (char *)args[0], args[1]);
+ stub->len = args[1] * 2;
+ gdbstub_tx_packet(stub);
+}
+
+static void gdbstub_write_mem(struct gdbstub *stub)
+{
+ unsigned long args[2];
+ int colon;
+ if (!gdbstub_get_packet_args
+ (stub, args, sizeof args / sizeof args[0], &colon) || colon >= stub->len
+ || stub->payload[colon] != ':' || (stub->len - colon - 1) % 2 != 0) {
+ gdbstub_send_errno(stub, POSIX_EINVAL);
+ return;
+ }
+ gdbstub_from_hex_buf((char *)args[0], &stub->payload[colon + 1],
+ (stub->len - colon - 1) / 2);
+ gdbstub_send_ok(stub);
}
-static void gdbstub_breakpoint ( struct gdbstub *stub ) {
- unsigned long args [ 3 ];
- int enable = stub->payload [ 0 ] == 'Z' ? 1 : 0;
- if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], NULL ) ) {
- gdbstub_send_errno ( stub, POSIX_EINVAL );
- return;
- }
- if ( gdbmach_set_breakpoint ( args [ 0 ], args [ 1 ], args [ 2 ], enable ) ) {
- gdbstub_send_ok ( stub );
- } else {
- /* Not supported */
- stub->len = 0;
- gdbstub_tx_packet ( stub );
- }
+static void gdbstub_continue(struct gdbstub *stub, int single_step)
+{
+ gdbreg_t pc;
+ if (stub->len > 1
+ && gdbstub_get_packet_args(stub, (unsigned long *)&pc, 1, NULL)) {
+ gdbmach_set_pc(stub->regs, pc);
+ }
+ gdbmach_set_single_step(stub->regs, single_step);
+ stub->exit_handler = 1;
+ /* Reply will be sent when we hit the next breakpoint or interrupt */
+}
+
+static void gdbstub_breakpoint(struct gdbstub *stub)
+{
+ unsigned long args[3];
+ int enable = stub->payload[0] == 'Z' ? 1 : 0;
+ if (!gdbstub_get_packet_args
+ (stub, args, sizeof args / sizeof args[0], NULL)) {
+ gdbstub_send_errno(stub, POSIX_EINVAL);
+ return;
+ }
+ if (gdbmach_set_breakpoint(args[0], args[1], args[2], enable)) {
+ gdbstub_send_ok(stub);
+ } else {
+ /* Not supported */
+ stub->len = 0;
+ gdbstub_tx_packet(stub);
+ }
}
-static void gdbstub_rx_packet ( struct gdbstub *stub ) {
- switch ( stub->payload [ 0 ] ) {
- case '?':
- gdbstub_report_signal ( stub );
- break;
- case 'g':
- gdbstub_read_regs ( stub );
- break;
- case 'G':
- gdbstub_write_regs ( stub );
- break;
- case 'm':
- gdbstub_read_mem ( stub );
- break;
- case 'M':
- gdbstub_write_mem ( stub );
- break;
- case 'c': /* Continue */
- case 'k': /* Kill */
- case 's': /* Step */
- case 'D': /* Detach */
- gdbstub_continue ( stub, stub->payload [ 0 ] == 's' );
- if ( stub->payload [ 0 ] == 'D' ) {
- gdbstub_send_ok ( stub );
- }
- break;
- case 'Z': /* Insert breakpoint */
- case 'z': /* Remove breakpoint */
- gdbstub_breakpoint ( stub );
- break;
- default:
- stub->len = 0;
- gdbstub_tx_packet ( stub );
- break;
+static void gdbstub_rx_packet(struct gdbstub *stub)
+{
+ switch (stub->payload[0]) {
+ case '?':
+ gdbstub_report_signal(stub);
+ break;
+ case 'g':
+ gdbstub_read_regs(stub);
+ break;
+ case 'G':
+ gdbstub_write_regs(stub);
+ break;
+ case 'm':
+ gdbstub_read_mem(stub);
+ break;
+ case 'M':
+ gdbstub_write_mem(stub);
+ break;
+ case 'c': /* Continue */
+ case 'k': /* Kill */
+ case 's': /* Step */
+ case 'D': /* Detach */
+ gdbstub_continue(stub, stub->payload[0] == 's');
+ if (stub->payload[0] == 'D') {
+ gdbstub_send_ok(stub);
}
+ break;
+ case 'Z': /* Insert breakpoint */
+ case 'z': /* Remove breakpoint */
+ gdbstub_breakpoint(stub);
+ break;
+ default:
+ stub->len = 0;
+ gdbstub_tx_packet(stub);
+ break;
+ }
}
/* GDB packet parser */
-static void gdbstub_state_new ( struct gdbstub *stub, char ch ) {
- if ( ch == '$' ) {
- stub->len = 0;
- stub->parse = gdbstub_state_data;
- }
+static void gdbstub_state_new(struct gdbstub *stub, char ch)
+{
+ if (ch == '$') {
+ stub->len = 0;
+ stub->parse = gdbstub_state_data;
+ }
}
-static void gdbstub_state_data ( struct gdbstub *stub, char ch ) {
- if ( ch == '#' ) {
- stub->parse = gdbstub_state_cksum1;
- } else if ( ch == '$' ) {
- stub->len = 0; /* retry new packet */
- } else {
- /* If the length exceeds our buffer, let the checksum fail */
- if ( stub->len < SIZEOF_PAYLOAD ) {
- stub->payload [ stub->len++ ] = ch;
- }
+static void gdbstub_state_data(struct gdbstub *stub, char ch)
+{
+ if (ch == '#') {
+ stub->parse = gdbstub_state_cksum1;
+ } else if (ch == '$') {
+ stub->len = 0; /* retry new packet */
+ } else {
+ /* If the length exceeds our buffer, let the checksum fail */
+ if (stub->len < SIZEOF_PAYLOAD) {
+ stub->payload[stub->len++] = ch;
}
+ }
}
-static void gdbstub_state_cksum1 ( struct gdbstub *stub, char ch ) {
- stub->cksum1 = gdbstub_from_hex_digit ( ch ) << 4;
- stub->parse = gdbstub_state_cksum2;
+static void gdbstub_state_cksum1(struct gdbstub *stub, char ch)
+{
+ stub->cksum1 = gdbstub_from_hex_digit(ch) << 4;
+ stub->parse = gdbstub_state_cksum2;
}
-static void gdbstub_state_cksum2 ( struct gdbstub *stub, char ch ) {
- uint8_t their_cksum;
- uint8_t our_cksum;
+static void gdbstub_state_cksum2(struct gdbstub *stub, char ch)
+{
+ uint8_t their_cksum;
+ uint8_t our_cksum;
- stub->parse = gdbstub_state_new;
- their_cksum = stub->cksum1 + gdbstub_from_hex_digit ( ch );
- our_cksum = gdbstub_cksum ( stub->payload, stub->len );
-
- if ( their_cksum == our_cksum ) {
- serial_write ( "+", 1 );
- if ( stub->len > 0 ) {
- gdbstub_rx_packet ( stub );
- }
- } else {
- serial_write ( "-", 1 );
+ stub->parse = gdbstub_state_new;
+ their_cksum = stub->cksum1 + gdbstub_from_hex_digit(ch);
+ our_cksum = gdbstub_cksum(stub->payload, stub->len);
+
+ if (their_cksum == our_cksum) {
+ serial_write("+", 1);
+ if (stub->len > 0) {
+ gdbstub_rx_packet(stub);
}
+ } else {
+ serial_write("-", 1);
+ }
}
-static void gdbstub_state_wait_ack ( struct gdbstub *stub, char ch ) {
- if ( ch == '+' ) {
- stub->parse = gdbstub_state_new;
- } else {
- /* This retransmit is very aggressive but necessary to keep
- * in sync with GDB. */
- gdbstub_tx_packet ( stub );
+static void gdbstub_state_wait_ack(struct gdbstub *stub, char ch)
+{
+ if (ch == '+') {
+ stub->parse = gdbstub_state_new;
+ } else {
+ /* This retransmit is very aggressive but necessary to keep
+ * in sync with GDB. */
+ gdbstub_tx_packet(stub);
}
}
-void gdbstub_handler ( int signo, gdbreg_t *regs ) {
+void gdbstub_handler(int signo, gdbreg_t * regs)
+{
struct gdbstub stub;
gdbmach_disable_hwbps();
stub.parse = gdbstub_state_new;
- stub.payload = &stub.buf [ 1 ];
- stub.signo = signo;
- stub.regs = regs;
- stub.exit_handler = 0;
- gdbstub_report_signal ( &stub );
- while ( !stub.exit_handler )
- stub.parse ( &stub, serial_getc() );
+ stub.payload = &stub.buf[1];
+ stub.signo = signo;
+ stub.regs = regs;
+ stub.exit_handler = 0;
+ gdbstub_report_signal(&stub);
+ while (!stub.exit_handler)
+ stub.parse(&stub, serial_getc());
gdbmach_enable_hwbps();
}
diff --git a/com32/gdbstub/main.c b/com32/gdbstub/main.c
index 8bb1dc5e..2ff9f28a 100644
--- a/com32/gdbstub/main.c
+++ b/com32/gdbstub/main.c
@@ -28,14 +28,14 @@ static inline void error(const char *msg)
static inline uint32_t reloc_ptr(struct reloc_info *ri, void *ptr)
{
- return ri->reloc_base + (uint32_t)((char*)ptr - _start);
+ return ri->reloc_base + (uint32_t) ((char *)ptr - _start);
}
static void hijack_interrupt(int intn, uint32_t handler)
{
struct {
- uint32_t lo;
- uint32_t hi;
+ uint32_t lo;
+ uint32_t hi;
} *idt = COM32_IDT;
idt[intn].lo = (idt[intn].lo & 0xffff0000) | (handler & 0x0000ffff);
@@ -47,16 +47,13 @@ static void shift_cmdline(struct com32_sys_args *com32)
char *p;
/* Skip leading whitespace */
- for (p = com32->cs_cmdline; *p != '\0' && *p == ' '; p++)
- ;
+ for (p = com32->cs_cmdline; *p != '\0' && *p == ' '; p++) ;
/* Skip first word */
- for (; *p != '\0' && *p != ' '; p++)
- ;
+ for (; *p != '\0' && *p != ' '; p++) ;
/* Skip whitespace after first word */
- for (; *p != '\0' && *p == ' '; p++)
- ;
+ for (; *p != '\0' && *p == ' '; p++) ;
com32->cs_cmdline = p;
}
@@ -76,41 +73,38 @@ static __noreturn reloc_entry(struct reloc_info *ri)
/* Copy stack frame onto module stack */
module_esp = (ri->reloc_base - stack_frame_size) & ~15;
- memcpy((void*)module_esp, (void*)ri->old_esp, stack_frame_size);
+ memcpy((void *)module_esp, (void *)ri->old_esp, stack_frame_size);
/* Fix up command line */
- com32 = (struct com32_sys_args*)(module_esp + 4);
+ com32 = (struct com32_sys_args *)(module_esp + 4);
shift_cmdline(com32);
/* Set up CPU state to run module and enter GDB */
- asm volatile (
- "movl %0, %%esp\n\t"
- "pushf\n\t"
- "pushl %%cs\n\t"
- "pushl %1\n\t"
- "jmp *%2\n\t"
- : : "r"(module_esp),
- "c"(COM32_LOAD_ADDR),
- "r"(reloc_ptr(ri, int_handler))
- );
- for(;;); /* shut the compiler up */
+ asm volatile ("movl %0, %%esp\n\t"
+ "pushf\n\t"
+ "pushl %%cs\n\t"
+ "pushl %1\n\t"
+ "jmp *%2\n\t"::"r" (module_esp),
+ "c"(COM32_LOAD_ADDR), "r"(reloc_ptr(ri, int_handler))
+ );
+ for (;;) ; /* shut the compiler up */
}
static inline __noreturn reloc(void *ptr, size_t len)
{
extern uint32_t __entry_esp;
size_t total_size = _end - _start;
- __noreturn (*entry_fn)(struct reloc_info*);
+ __noreturn(*entry_fn) (struct reloc_info *);
struct reloc_info ri;
uint32_t esp;
char *dest;
/* Calculate relocation address, preserve current stack */
- asm volatile ("movl %%esp, %0\n\t" : "=m"(esp));
- dest = (char*)((esp - STACK_SIZE - total_size) & ~3);
+ asm volatile ("movl %%esp, %0\n\t":"=m" (esp));
+ dest = (char *)((esp - STACK_SIZE - total_size) & ~3);
/* Calculate entry point in relocated code */
- entry_fn = (void*)(dest + ((char*)reloc_entry - _start));
+ entry_fn = (void *)(dest + ((char *)reloc_entry - _start));
/* Copy all sections to relocation address */
printf("Relocating %d bytes from %p to %p\n", total_size, _start, dest);
@@ -120,7 +114,7 @@ static inline __noreturn reloc(void *ptr, size_t len)
ri.data = ptr;
ri.len = len;
ri.old_esp = __entry_esp;
- ri.reloc_base = (uint32_t)dest;
+ ri.reloc_base = (uint32_t) dest;
entry_fn(&ri);
}
@@ -132,13 +126,13 @@ int main(int argc, char *argv[])
openconsole(&dev_null_r, &dev_stdcon_w);
if (argc < 2) {
- error("Usage: gdbstub.c32 com32_file arguments...\n");
- return 1;
+ error("Usage: gdbstub.c32 com32_file arguments...\n");
+ return 1;
}
if (loadfile(argv[1], &data, &data_len)) {
- error("Unable to load file\n");
- return 1;
+ error("Unable to load file\n");
+ return 1;
}
serial_init();
diff --git a/com32/gdbstub/serial.c b/com32/gdbstub/serial.c
index 2b9fc2ef..8c69b028 100644
--- a/com32/gdbstub/serial.c
+++ b/com32/gdbstub/serial.c
@@ -87,104 +87,107 @@
* void serial_putc(int ch);
* Write character `ch' to port UART_BASE.
*/
-void serial_putc ( int ch ) {
- int status;
- for (;;) {
- status = uart_readb(UART_BASE + UART_LSR);
- if (status & UART_LSR_THRE) {
- /* TX buffer emtpy */
- uart_writeb(ch, UART_BASE + UART_TBR);
- break;
- }
+void serial_putc(int ch)
+{
+ int status;
+ for (;;) {
+ status = uart_readb(UART_BASE + UART_LSR);
+ if (status & UART_LSR_THRE) {
+ /* TX buffer emtpy */
+ uart_writeb(ch, UART_BASE + UART_TBR);
+ break;
}
+ }
}
/*
* int serial_getc(void);
* Read a character from port UART_BASE.
*/
-int serial_getc ( void ) {
- int status;
- int ch;
- do {
- status = uart_readb(UART_BASE + UART_LSR);
- } while((status & 1) == 0);
- ch = uart_readb(UART_BASE + UART_RBR); /* fetch (first) character */
- ch &= 0x7f; /* remove any parity bits we get */
- if (ch == 0x7f) { /* Make DEL... look like BS */
- ch = 0x08;
- }
- return ch;
+int serial_getc(void)
+{
+ int status;
+ int ch;
+ do {
+ status = uart_readb(UART_BASE + UART_LSR);
+ } while ((status & 1) == 0);
+ ch = uart_readb(UART_BASE + UART_RBR); /* fetch (first) character */
+ ch &= 0x7f; /* remove any parity bits we get */
+ if (ch == 0x7f) { /* Make DEL... look like BS */
+ ch = 0x08;
+ }
+ return ch;
}
/*
* int serial_init(void);
* Initialize port UART_BASE to speed COMSPEED, line settings 8N1.
*/
-void serial_init ( void ) {
- int status;
- int divisor, lcs;
-
- divisor = COMBRD;
- lcs = UART_LCS;
+void serial_init(void)
+{
+ int status;
+ int divisor, lcs;
+ divisor = COMBRD;
+ lcs = UART_LCS;
#ifdef COMPRESERVE
- lcs = uart_readb(UART_BASE + UART_LCR) & 0x7f;
- uart_writeb(0x80 | lcs, UART_BASE + UART_LCR);
- divisor = (uart_readb(UART_BASE + UART_DLM) << 8) | uart_readb(UART_BASE + UART_DLL);
- uart_writeb(lcs, UART_BASE + UART_LCR);
+ lcs = uart_readb(UART_BASE + UART_LCR) & 0x7f;
+ uart_writeb(0x80 | lcs, UART_BASE + UART_LCR);
+ divisor =
+ (uart_readb(UART_BASE + UART_DLM) << 8) | uart_readb(UART_BASE +
+ UART_DLL);
+ uart_writeb(lcs, UART_BASE + UART_LCR);
#endif
- /* Set Baud Rate Divisor to COMSPEED, and test to see if the
- * serial port appears to be present.
+ /* Set Baud Rate Divisor to COMSPEED, and test to see if the
+ * serial port appears to be present.
+ */
+ uart_writeb(0x80 | lcs, UART_BASE + UART_LCR);
+ uart_writeb(0xaa, UART_BASE + UART_DLL);
+ if (uart_readb(UART_BASE + UART_DLL) != 0xaa) {
+ goto out;
+ }
+ uart_writeb(0x55, UART_BASE + UART_DLL);
+ if (uart_readb(UART_BASE + UART_DLL) != 0x55) {
+ goto out;
+ }
+ uart_writeb(divisor & 0xff, UART_BASE + UART_DLL);
+ if (uart_readb(UART_BASE + UART_DLL) != (divisor & 0xff)) {
+ goto out;
+ }
+ uart_writeb(0xaa, UART_BASE + UART_DLM);
+ if (uart_readb(UART_BASE + UART_DLM) != 0xaa) {
+ goto out;
+ }
+ uart_writeb(0x55, UART_BASE + UART_DLM);
+ if (uart_readb(UART_BASE + UART_DLM) != 0x55) {
+ goto out;
+ }
+ uart_writeb((divisor >> 8) & 0xff, UART_BASE + UART_DLM);
+ if (uart_readb(UART_BASE + UART_DLM) != ((divisor >> 8) & 0xff)) {
+ goto out;
+ }
+ uart_writeb(lcs, UART_BASE + UART_LCR);
+
+ /* disable interrupts */
+ uart_writeb(0x0, UART_BASE + UART_IER);
+
+ /* disable fifo's */
+ uart_writeb(0x00, UART_BASE + UART_FCR);
+
+ /* Set clear to send, so flow control works... */
+ uart_writeb((1 << 1), UART_BASE + UART_MCR);
+
+ /* Flush the input buffer. */
+ do {
+ /* rx buffer reg
+ * throw away (unconditionally the first time)
*/
- uart_writeb(0x80 | lcs, UART_BASE + UART_LCR);
- uart_writeb(0xaa, UART_BASE + UART_DLL);
- if (uart_readb(UART_BASE + UART_DLL) != 0xaa) {
- goto out;
- }
- uart_writeb(0x55, UART_BASE + UART_DLL);
- if (uart_readb(UART_BASE + UART_DLL) != 0x55) {
- goto out;
- }
- uart_writeb(divisor & 0xff, UART_BASE + UART_DLL);
- if (uart_readb(UART_BASE + UART_DLL) != (divisor & 0xff)) {
- goto out;
- }
- uart_writeb(0xaa, UART_BASE + UART_DLM);
- if (uart_readb(UART_BASE + UART_DLM) != 0xaa) {
- goto out;
- }
- uart_writeb(0x55, UART_BASE + UART_DLM);
- if (uart_readb(UART_BASE + UART_DLM) != 0x55) {
- goto out;
- }
- uart_writeb((divisor >> 8) & 0xff, UART_BASE + UART_DLM);
- if (uart_readb(UART_BASE + UART_DLM) != ((divisor >> 8) & 0xff)) {
- goto out;
- }
- uart_writeb(lcs, UART_BASE + UART_LCR);
-
- /* disable interrupts */
- uart_writeb(0x0, UART_BASE + UART_IER);
-
- /* disable fifo's */
- uart_writeb(0x00, UART_BASE + UART_FCR);
-
- /* Set clear to send, so flow control works... */
- uart_writeb((1<<1), UART_BASE + UART_MCR);
-
-
- /* Flush the input buffer. */
- do {
- /* rx buffer reg
- * throw away (unconditionally the first time)
- */
- (void) uart_readb(UART_BASE + UART_RBR);
- /* line status reg */
- status = uart_readb(UART_BASE + UART_LSR);
- } while(status & UART_LSR_DR);
- out:
- return;
+ (void)uart_readb(UART_BASE + UART_RBR);
+ /* line status reg */
+ status = uart_readb(UART_BASE + UART_LSR);
+ } while (status & UART_LSR_DR);
+out:
+ return;
}
diff --git a/com32/gdbstub/serial.h b/com32/gdbstub/serial.h
index c78a5757..bb27a62f 100644
--- a/com32/gdbstub/serial.h
+++ b/com32/gdbstub/serial.h
@@ -7,8 +7,8 @@
*
*/
-extern void serial_putc ( int ch );
-extern int serial_getc ( void );
-extern void serial_init ( void );
+extern void serial_putc(int ch);
+extern int serial_getc(void);
+extern void serial_init(void);
#endif /* _GPXE_SERIAL_H */
diff --git a/com32/gplinclude/cpuid.h b/com32/gplinclude/cpuid.h
index ca1c3142..95d66e99 100644
--- a/com32/gplinclude/cpuid.h
+++ b/com32/gplinclude/cpuid.h
@@ -28,53 +28,53 @@
#define CPU_VENDOR_SIZE 48
typedef struct {
- bool fpu; /* Onboard FPU */
- bool vme; /* Virtual Mode Extensions */
- bool de; /* Debugging Extensions */
- bool pse; /* Page Size Extensions */
- bool tsc; /* Time Stamp Counter */
- bool msr; /* Model-Specific Registers, RDMSR, WRMSR */
- bool pae; /* Physical Address Extensions */
- bool mce; /* Machine Check Architecture */
- bool cx8; /* CMPXCHG8 instruction */
- bool apic;/* Onboard APIC */
- bool sep; /* SYSENTER/SYSEXIT */
- bool mtrr;/* Memory Type Range Registers */
- bool pge; /* Page Global Enable */
- bool mca; /* Machine Check Architecture */
- bool cmov;/* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */
- bool pat; /* Page Attribute Table */
- bool pse_36; /* 36-bit PSEs */
- bool psn; /* Processor serial number */
- bool clflsh; /* Supports the CLFLUSH instruction */
- bool dts; /* Debug Trace Store */
- bool acpi;/* ACPI via MSR */
- bool mmx; /* Multimedia Extensions */
- bool fxsr;/* FXSAVE and FXRSTOR instructions (fast save and restore */
- /* of FPU context), and CR4.OSFXSR available */
- bool sse; /* Streaming SIMD Extensions */
- bool sse2;/* Streaming SIMD Extensions 2*/
- bool ss; /* CPU self snoop */
- bool htt; /* Hyper-Threading */
- bool acc; /* Automatic clock control */
- bool syscall; /* SYSCALL/SYSRET */
- bool mp; /* MP Capable. */
- bool nx; /* Execute Disable */
- bool mmxext; /* AMD MMX extensions */
- bool lm; /* Long Mode (x86-64) */
- bool nowext;/* AMD 3DNow! extensions */
- bool now; /* 3DNow! */
- bool smp; /* A smp configuration has been found*/
+ bool fpu; /* Onboard FPU */
+ bool vme; /* Virtual Mode Extensions */
+ bool de; /* Debugging Extensions */
+ bool pse; /* Page Size Extensions */
+ bool tsc; /* Time Stamp Counter */
+ bool msr; /* Model-Specific Registers, RDMSR, WRMSR */
+ bool pae; /* Physical Address Extensions */
+ bool mce; /* Machine Check Architecture */
+ bool cx8; /* CMPXCHG8 instruction */
+ bool apic; /* Onboard APIC */
+ bool sep; /* SYSENTER/SYSEXIT */
+ bool mtrr; /* Memory Type Range Registers */
+ bool pge; /* Page Global Enable */
+ bool mca; /* Machine Check Architecture */
+ bool cmov; /* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */
+ bool pat; /* Page Attribute Table */
+ bool pse_36; /* 36-bit PSEs */
+ bool psn; /* Processor serial number */
+ bool clflsh; /* Supports the CLFLUSH instruction */
+ bool dts; /* Debug Trace Store */
+ bool acpi; /* ACPI via MSR */
+ bool mmx; /* Multimedia Extensions */
+ bool fxsr; /* FXSAVE and FXRSTOR instructions (fast save and restore */
+ /* of FPU context), and CR4.OSFXSR available */
+ bool sse; /* Streaming SIMD Extensions */
+ bool sse2; /* Streaming SIMD Extensions 2 */
+ bool ss; /* CPU self snoop */
+ bool htt; /* Hyper-Threading */
+ bool acc; /* Automatic clock control */
+ bool syscall; /* SYSCALL/SYSRET */
+ bool mp; /* MP Capable. */
+ bool nx; /* Execute Disable */
+ bool mmxext; /* AMD MMX extensions */
+ bool lm; /* Long Mode (x86-64) */
+ bool nowext; /* AMD 3DNow! extensions */
+ bool now; /* 3DNow! */
+ bool smp; /* A smp configuration has been found */
} s_cpu_flags;
typedef struct {
- char vendor[CPU_VENDOR_SIZE];
- uint8_t vendor_id;
- uint8_t family;
- char model[CPU_MODEL_SIZE];
- uint8_t model_id;
- uint8_t stepping;
- s_cpu_flags flags;
+ char vendor[CPU_VENDOR_SIZE];
+ uint8_t vendor_id;
+ uint8_t family;
+ char model[CPU_MODEL_SIZE];
+ uint8_t model_id;
+ uint8_t stepping;
+ s_cpu_flags flags;
} s_cpu;
/**********************************************************************************/
@@ -86,23 +86,23 @@ typedef struct {
/*
* EFLAGS bits
*/
-#define X86_EFLAGS_CF 0x00000001 /* Carry Flag */
-#define X86_EFLAGS_PF 0x00000004 /* Parity Flag */
-#define X86_EFLAGS_AF 0x00000010 /* Auxillary carry Flag */
-#define X86_EFLAGS_ZF 0x00000040 /* Zero Flag */
-#define X86_EFLAGS_SF 0x00000080 /* Sign Flag */
-#define X86_EFLAGS_TF 0x00000100 /* Trap Flag */
-#define X86_EFLAGS_IF 0x00000200 /* Interrupt Flag */
-#define X86_EFLAGS_DF 0x00000400 /* Direction Flag */
-#define X86_EFLAGS_OF 0x00000800 /* Overflow Flag */
-#define X86_EFLAGS_IOPL 0x00003000 /* IOPL mask */
-#define X86_EFLAGS_NT 0x00004000 /* Nested Task */
-#define X86_EFLAGS_RF 0x00010000 /* Resume Flag */
-#define X86_EFLAGS_VM 0x00020000 /* Virtual Mode */
-#define X86_EFLAGS_AC 0x00040000 /* Alignment Check */
-#define X86_EFLAGS_VIF 0x00080000 /* Virtual Interrupt Flag */
-#define X86_EFLAGS_VIP 0x00100000 /* Virtual Interrupt Pending */
-#define X86_EFLAGS_ID 0x00200000 /* CPUID detection flag */
+#define X86_EFLAGS_CF 0x00000001 /* Carry Flag */
+#define X86_EFLAGS_PF 0x00000004 /* Parity Flag */
+#define X86_EFLAGS_AF 0x00000010 /* Auxillary carry Flag */
+#define X86_EFLAGS_ZF 0x00000040 /* Zero Flag */
+#define X86_EFLAGS_SF 0x00000080 /* Sign Flag */
+#define X86_EFLAGS_TF 0x00000100 /* Trap Flag */
+#define X86_EFLAGS_IF 0x00000200 /* Interrupt Flag */
+#define X86_EFLAGS_DF 0x00000400 /* Direction Flag */
+#define X86_EFLAGS_OF 0x00000800 /* Overflow Flag */
+#define X86_EFLAGS_IOPL 0x00003000 /* IOPL mask */
+#define X86_EFLAGS_NT 0x00004000 /* Nested Task */
+#define X86_EFLAGS_RF 0x00010000 /* Resume Flag */
+#define X86_EFLAGS_VM 0x00020000 /* Virtual Mode */
+#define X86_EFLAGS_AC 0x00040000 /* Alignment Check */
+#define X86_EFLAGS_VIF 0x00080000 /* Virtual Interrupt Flag */
+#define X86_EFLAGS_VIP 0x00100000 /* Virtual Interrupt Pending */
+#define X86_EFLAGS_ID 0x00200000 /* CPUID detection flag */
#define X86_VENDOR_INTEL 0
#define X86_VENDOR_CYRIX 1
@@ -116,9 +116,9 @@ typedef struct {
#define X86_VENDOR_NUM 9
#define X86_VENDOR_UNKNOWN 0xff
-static inline __purefunc bool test_bit(int nr, const uint32_t *addr)
+static inline __purefunc bool test_bit(int nr, const uint32_t * addr)
{
- return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0;
+ return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0;
}
#define cpu_has(c, bit) test_bit(bit, (c)->x86_capability)
@@ -130,55 +130,55 @@ static inline __purefunc bool test_bit(int nr, const uint32_t *addr)
*/
struct cpuinfo_x86 {
- uint8_t x86; /* CPU family */
- uint8_t x86_vendor; /* CPU vendor */
- uint8_t x86_model;
- uint8_t x86_mask;
- char wp_works_ok; /* It doesn't on 386's */
- char hlt_works_ok; /* Problems on some 486Dx4's and old 386's */
- char hard_math;
- char rfu;
- int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */
- uint32_t x86_capability[NCAPINTS];
- char x86_vendor_id[16];
- char x86_model_id[64];
- int x86_cache_size; /* in KB, if available */
- int x86_cache_alignment; /* in bytes */
- char fdiv_bug;
- char f00f_bug;
- char coma_bug;
- char pad0;
- int x86_power;
- unsigned long loops_per_jiffy;
+ uint8_t x86; /* CPU family */
+ uint8_t x86_vendor; /* CPU vendor */
+ uint8_t x86_model;
+ uint8_t x86_mask;
+ char wp_works_ok; /* It doesn't on 386's */
+ char hlt_works_ok; /* Problems on some 486Dx4's and old 386's */
+ char hard_math;
+ char rfu;
+ int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */
+ uint32_t x86_capability[NCAPINTS];
+ char x86_vendor_id[16];
+ char x86_model_id[64];
+ int x86_cache_size; /* in KB, if available */
+ int x86_cache_alignment; /* in bytes */
+ char fdiv_bug;
+ char f00f_bug;
+ char coma_bug;
+ char pad0;
+ int x86_power;
+ unsigned long loops_per_jiffy;
#ifdef CONFIG_SMP
- cpumask_t llc_shared_map; /* cpus sharing the last level cache */
+ cpumask_t llc_shared_map; /* cpus sharing the last level cache */
#endif
- unsigned char x86_max_cores; /* cpuid returned max cores value */
- unsigned char booted_cores; /* number of cores as seen by OS */
- unsigned char apicid;
- unsigned char x86_clflush_size;
+ unsigned char x86_max_cores; /* cpuid returned max cores value */
+ unsigned char booted_cores; /* number of cores as seen by OS */
+ unsigned char apicid;
+ unsigned char x86_clflush_size;
-} __attribute__((__packed__));
+} __attribute__ ((__packed__));
#endif
struct cpu_model_info {
- int vendor;
- int family;
- char *model_names[16];
+ int vendor;
+ int family;
+ char *model_names[16];
};
/* attempt to consolidate cpu attributes */
struct cpu_dev {
- char * c_vendor;
+ char *c_vendor;
- /* some have two possibilities for cpuid string */
- char * c_ident[2];
+ /* some have two possibilities for cpuid string */
+ char *c_ident[2];
- struct cpu_model_info c_models[4];
+ struct cpu_model_info c_models[4];
- void (*c_init)(struct cpuinfo_x86 * c);
- void (*c_identify)(struct cpuinfo_x86 * c);
- unsigned int (*c_size_cache)(struct cpuinfo_x86 * c, unsigned int size);
+ void (*c_init) (struct cpuinfo_x86 * c);
+ void (*c_identify) (struct cpuinfo_x86 * c);
+ unsigned int (*c_size_cache) (struct cpuinfo_x86 * c, unsigned int size);
};
/*
@@ -193,20 +193,18 @@ struct cpu_dev {
#define SMP_MAGIC_IDENT (('_'<<24)|('P'<<16)|('M'<<8)|'_')
-struct intel_mp_floating
-{
- char mpf_signature[4]; /* "_MP_" */
- uint32_t mpf_physptr; /* Configuration table address */
- uint8_t mpf_length; /* Our length (paragraphs) */
- uint8_t mpf_specification; /* Specification version */
- uint8_t mpf_checksum; /* Checksum (makes sum 0) */
- uint8_t mpf_feature1; /* Standard or configuration ? */
- uint8_t mpf_feature2; /* Bit7 set for IMCR|PIC */
- uint8_t mpf_feature3; /* Unused (0) */
- uint8_t mpf_feature4; /* Unused (0) */
- uint8_t mpf_feature5; /* Unused (0) */
+struct intel_mp_floating {
+ char mpf_signature[4]; /* "_MP_" */
+ uint32_t mpf_physptr; /* Configuration table address */
+ uint8_t mpf_length; /* Our length (paragraphs) */
+ uint8_t mpf_specification; /* Specification version */
+ uint8_t mpf_checksum; /* Checksum (makes sum 0) */
+ uint8_t mpf_feature1; /* Standard or configuration ? */
+ uint8_t mpf_feature2; /* Bit7 set for IMCR|PIC */
+ uint8_t mpf_feature3; /* Unused (0) */
+ uint8_t mpf_feature4; /* Unused (0) */
+ uint8_t mpf_feature5; /* Unused (0) */
};
-
extern void get_cpu_vendor(struct cpuinfo_x86 *c);
-extern void detect_cpu(s_cpu *cpu);
+extern void detect_cpu(s_cpu * cpu);
diff --git a/com32/gplinclude/dmi/dmi.h b/com32/gplinclude/dmi/dmi.h
index 89782a97..71372f3e 100644
--- a/com32/gplinclude/dmi/dmi.h
+++ b/com32/gplinclude/dmi/dmi.h
@@ -24,7 +24,7 @@ extern const char *bad_index;
#define DWORD(x) (uint32_t)(*(const uint32_t *)(x))
#define QWORD(x) (*(const uint64_t *)(x))
-enum {DMI_TABLE_PRESENT = 100, ENODMITABLE};
+enum { DMI_TABLE_PRESENT = 100, ENODMITABLE };
#include "dmi_bios.h"
#include "dmi_system.h"
@@ -39,47 +39,44 @@ extern char display_line;
#define moreprintf(...) do { display_line++; if (display_line == 24) { char tempbuf[10]; display_line=0; printf("Press enter to continue"); fgets(tempbuf, sizeof tempbuf, stdin);} printf ( __VA_ARGS__); } while (0);
typedef struct {
-uint16_t num;
-uint16_t len;
-uint16_t ver;
-uint32_t base;
-uint16_t major_version;
-uint16_t minor_version;
+ uint16_t num;
+ uint16_t len;
+ uint16_t ver;
+ uint32_t base;
+ uint16_t major_version;
+ uint16_t minor_version;
} dmi_table;
-
-
-struct dmi_header
-{
- uint8_t type;
- uint8_t length;
- uint16_t handle;
- uint8_t *data;
+struct dmi_header {
+ uint8_t type;
+ uint8_t length;
+ uint16_t handle;
+ uint8_t *data;
};
typedef struct {
- s_bios bios;
- s_system system;
- s_base_board base_board;
- s_chassis chassis;
- s_processor processor;
- s_battery battery;
- s_memory memory[MAX_DMI_MEMORY_ITEMS];
- s_ipmi ipmi;
- int memory_count;
- dmi_table dmitable;
+ s_bios bios;
+ s_system system;
+ s_base_board base_board;
+ s_chassis chassis;
+ s_processor processor;
+ s_battery battery;
+ s_memory memory[MAX_DMI_MEMORY_ITEMS];
+ s_ipmi ipmi;
+ int memory_count;
+ dmi_table dmitable;
} s_dmi;
-void to_dmi_header(struct dmi_header *h, uint8_t *data);
-void dmi_bios_runtime_size(uint32_t code, s_dmi *dmi);
+void to_dmi_header(struct dmi_header *h, uint8_t * data);
+void dmi_bios_runtime_size(uint32_t code, s_dmi * dmi);
const char *dmi_string(struct dmi_header *dm, uint8_t s);
-int dmi_checksum(uint8_t *buf);
-void parse_dmitable(s_dmi *dmi);
-void dmi_decode(struct dmi_header *h, uint16_t ver, s_dmi *dmi);
-int dmi_iterate(s_dmi *dmi);
+int dmi_checksum(uint8_t * buf);
+void parse_dmitable(s_dmi * dmi);
+void dmi_decode(struct dmi_header *h, uint16_t ver, s_dmi * dmi);
+int dmi_iterate(s_dmi * dmi);
/* dmi_utils.c */
-void display_bios_characteristics(s_dmi *dmi);
-void display_base_board_features(s_dmi *dmi);
-void display_processor_flags(s_dmi *dmi);
+void display_bios_characteristics(s_dmi * dmi);
+void display_base_board_features(s_dmi * dmi);
+void display_processor_flags(s_dmi * dmi);
#endif
diff --git a/com32/gplinclude/dmi/dmi_base_board.h b/com32/gplinclude/dmi/dmi_base_board.h
index 5b92b848..9fe35440 100644
--- a/com32/gplinclude/dmi/dmi_base_board.h
+++ b/com32/gplinclude/dmi/dmi_base_board.h
@@ -30,24 +30,24 @@ extern const char *base_board_features_strings[];
/* this struct have BASE_BOARD_NB_ELEMENTS */
/* each bool is associated to the relevant message above */
typedef struct {
-bool hosting;
-bool board_needs_daughter;
-bool removable;
-bool replaceable;
-bool hot_swappable;
-} __attribute__((__packed__)) s_base_board_features;
+ bool hosting;
+ bool board_needs_daughter;
+ bool removable;
+ bool replaceable;
+ bool hot_swappable;
+} __attribute__ ((__packed__)) s_base_board_features;
typedef struct {
-char manufacturer[BASE_BOARD_MANUFACTURER_SIZE];
-char product_name[BASE_BOARD_PRODUCT_NAME_SIZE];
-char version[BASE_BOARD_VERSION_SIZE];
-char serial[BASE_BOARD_SERIAL_SIZE];
-char asset_tag[BASE_BOARD_ASSET_TAG_SIZE];
-char location[BASE_BOARD_LOCATION_SIZE];
-char type[BASE_BOARD_TYPE_SIZE];
-s_base_board_features features;
+ char manufacturer[BASE_BOARD_MANUFACTURER_SIZE];
+ char product_name[BASE_BOARD_PRODUCT_NAME_SIZE];
+ char version[BASE_BOARD_VERSION_SIZE];
+ char serial[BASE_BOARD_SERIAL_SIZE];
+ char asset_tag[BASE_BOARD_ASSET_TAG_SIZE];
+ char location[BASE_BOARD_LOCATION_SIZE];
+ char type[BASE_BOARD_TYPE_SIZE];
+ s_base_board_features features;
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_base_board;
#endif
diff --git a/com32/gplinclude/dmi/dmi_battery.h b/com32/gplinclude/dmi/dmi_battery.h
index 72c19693..fae7acb5 100644
--- a/com32/gplinclude/dmi/dmi_battery.h
+++ b/com32/gplinclude/dmi/dmi_battery.h
@@ -32,26 +32,26 @@
#define BATTERY_OEM_INFO_SIZE 255
typedef struct {
-char location[BATTERY_LOCATION_SIZE];
-char manufacturer[BATTERY_MANUFACTURER_SIZE];
-char manufacture_date[BATTERY_MANUFACTURE_DATE_SIZE];
-char serial[BATTERY_SERIAL_SIZE];
-char name[BATTERY_DEVICE_NAME_SIZE];
-char chemistry[BATTERY_CHEMISTRY_SIZE];
-char design_capacity[BATTERY_CAPACITY_SIZE];
-char design_voltage[BATTERY_DESIGN_VOLTAGE_SIZE];
-char sbds[BATTERY_SBDS_SIZE];
-char sbds_serial[BATTERY_SBDS_SERIAL_SIZE];
-char maximum_error[BATTERY_MAXIMUM_ERROR_SIZE];
-char sbds_manufacture_date[BATTERY_SBDS_MANUFACTURE_DATE_SIZE];
-char sbds_chemistry[BATTERY_SBDS_CHEMISTRY_SIZE];
-char oem_info[BATTERY_OEM_INFO_SIZE];
+ char location[BATTERY_LOCATION_SIZE];
+ char manufacturer[BATTERY_MANUFACTURER_SIZE];
+ char manufacture_date[BATTERY_MANUFACTURE_DATE_SIZE];
+ char serial[BATTERY_SERIAL_SIZE];
+ char name[BATTERY_DEVICE_NAME_SIZE];
+ char chemistry[BATTERY_CHEMISTRY_SIZE];
+ char design_capacity[BATTERY_CAPACITY_SIZE];
+ char design_voltage[BATTERY_DESIGN_VOLTAGE_SIZE];
+ char sbds[BATTERY_SBDS_SIZE];
+ char sbds_serial[BATTERY_SBDS_SERIAL_SIZE];
+ char maximum_error[BATTERY_MAXIMUM_ERROR_SIZE];
+ char sbds_manufacture_date[BATTERY_SBDS_MANUFACTURE_DATE_SIZE];
+ char sbds_chemistry[BATTERY_SBDS_CHEMISTRY_SIZE];
+ char oem_info[BATTERY_OEM_INFO_SIZE];
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_battery;
const char *dmi_battery_chemistry(uint8_t code);
-void dmi_battery_capacity(uint16_t code, uint8_t multiplier,char *capacity);
+void dmi_battery_capacity(uint16_t code, uint8_t multiplier, char *capacity);
void dmi_battery_voltage(uint16_t code, char *voltage);
void dmi_battery_maximum_error(uint8_t code, char *error);
#endif
diff --git a/com32/gplinclude/dmi/dmi_bios.h b/com32/gplinclude/dmi/dmi_bios.h
index 546bbefc..53201acb 100644
--- a/com32/gplinclude/dmi/dmi_bios.h
+++ b/com32/gplinclude/dmi/dmi_bios.h
@@ -31,77 +31,77 @@ extern const char *bios_charac_strings[];
/* this struct has BIOS_CHAR_NB_ELEMENTS */
/* each bool is associated with the relevant message above */
typedef struct {
-bool bios_characteristics_not_supported;
-bool isa;
-bool mca;
-bool eisa;
-bool pci;
-bool pc_card;
-bool pnp;
-bool apm;
-bool bios_upgreadable;
-bool bios_shadowing;
-bool vlb;
-bool escd;
-bool boot_from_cd;
-bool selectable_boot;
-bool bios_rom_socketed;
-bool edd;
-bool japanese_floppy_nec_9800_1_2MB;
-bool japanese_floppy_toshiba_1_2MB;
-bool floppy_5_25_360KB;
-bool floppy_5_25_1_2MB;
-bool floppy_3_5_720KB;
-bool floppy_3_5_2_88MB;
-bool print_screen;
-bool keyboard_8042_support;
-bool serial_support;
-bool printer_support;
-bool cga_mono_support;
-bool nec_pc_98;
-} __attribute__((__packed__)) s_characteristics;
+ bool bios_characteristics_not_supported;
+ bool isa;
+ bool mca;
+ bool eisa;
+ bool pci;
+ bool pc_card;
+ bool pnp;
+ bool apm;
+ bool bios_upgreadable;
+ bool bios_shadowing;
+ bool vlb;
+ bool escd;
+ bool boot_from_cd;
+ bool selectable_boot;
+ bool bios_rom_socketed;
+ bool edd;
+ bool japanese_floppy_nec_9800_1_2MB;
+ bool japanese_floppy_toshiba_1_2MB;
+ bool floppy_5_25_360KB;
+ bool floppy_5_25_1_2MB;
+ bool floppy_3_5_720KB;
+ bool floppy_3_5_2_88MB;
+ bool print_screen;
+ bool keyboard_8042_support;
+ bool serial_support;
+ bool printer_support;
+ bool cga_mono_support;
+ bool nec_pc_98;
+} __attribute__ ((__packed__)) s_characteristics;
extern const char *bios_charac_x1_strings[];
/* this struct has BIOS_CHAR_X1_NB_ELEMENTS */
/* each bool is associated with the relevant message above */
typedef struct {
-bool acpi;
-bool usb_legacy;
-bool agp;
-bool i2o_boot;
-bool ls_120_boot;
-bool zip_drive_boot;
-bool ieee_1394_boot;
-bool smart_battery;
-} __attribute__((__packed__)) s_characteristics_x1;
+ bool acpi;
+ bool usb_legacy;
+ bool agp;
+ bool i2o_boot;
+ bool ls_120_boot;
+ bool zip_drive_boot;
+ bool ieee_1394_boot;
+ bool smart_battery;
+} __attribute__ ((__packed__)) s_characteristics_x1;
extern const char *bios_charac_x2_strings[];
/* this struct has BIOS_CHAR_X2_NB_ELEMENTS */
/* each bool is associated with the relevant message above */
typedef struct {
-bool bios_boot_specification;
-bool bios_network_boot_by_keypress;
-bool target_content_distribution;
-} __attribute__((__packed__)) s_characteristics_x2;
+ bool bios_boot_specification;
+ bool bios_network_boot_by_keypress;
+ bool target_content_distribution;
+} __attribute__ ((__packed__)) s_characteristics_x2;
typedef struct {
-char vendor[BIOS_VENDOR_SIZE];
-char version[BIOS_VERSION_SIZE];
-char release_date[BIOS_RELEASE_SIZE];
-uint16_t address;
-uint16_t runtime_size;
-char runtime_size_unit[BIOS_RUNTIME_SIZE_UNIT_SIZE];
-uint16_t rom_size;
-char rom_size_unit[BIOS_ROM_UNIT_SIZE];
-s_characteristics characteristics;
-s_characteristics_x1 characteristics_x1;
-s_characteristics_x2 characteristics_x2;
-char bios_revision [BIOS_BIOS_REVISION_SIZE];
-char firmware_revision [BIOS_FIRMWARE_REVISION_SIZE];
+ char vendor[BIOS_VENDOR_SIZE];
+ char version[BIOS_VERSION_SIZE];
+ char release_date[BIOS_RELEASE_SIZE];
+ uint16_t address;
+ uint16_t runtime_size;
+ char runtime_size_unit[BIOS_RUNTIME_SIZE_UNIT_SIZE];
+ uint16_t rom_size;
+ char rom_size_unit[BIOS_ROM_UNIT_SIZE];
+ s_characteristics characteristics;
+ s_characteristics_x1 characteristics_x1;
+ s_characteristics_x2 characteristics_x2;
+ char bios_revision[BIOS_BIOS_REVISION_SIZE];
+ char firmware_revision[BIOS_FIRMWARE_REVISION_SIZE];
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_bios;
#endif
diff --git a/com32/gplinclude/dmi/dmi_chassis.h b/com32/gplinclude/dmi/dmi_chassis.h
index 96711ed4..88433ea1 100644
--- a/com32/gplinclude/dmi/dmi_chassis.h
+++ b/com32/gplinclude/dmi/dmi_chassis.h
@@ -26,21 +26,21 @@
#define CHASSIS_OEM_INFORMATION_SIZE 32
typedef struct {
-char manufacturer[CHASSIS_MANUFACTURER_SIZE];
-char type[CHASSIS_TYPE_SIZE];
-char lock[CHASSIS_LOCK_SIZE];
-char version[CHASSIS_VERSION_SIZE];
-char serial[CHASSIS_SERIAL_SIZE];
-char asset_tag[CHASSIS_ASSET_TAG_SIZE];
-char boot_up_state[CHASSIS_BOOT_UP_STATE_SIZE];
-char power_supply_state[CHASSIS_POWER_SUPPLY_STATE_SIZE];
-char thermal_state[CHASSIS_THERMAL_STATE_SIZE];
-char security_status[CHASSIS_SECURITY_STATUS_SIZE];
-char oem_information[CHASSIS_OEM_INFORMATION_SIZE];
-uint16_t height;
-uint16_t nb_power_cords;
+ char manufacturer[CHASSIS_MANUFACTURER_SIZE];
+ char type[CHASSIS_TYPE_SIZE];
+ char lock[CHASSIS_LOCK_SIZE];
+ char version[CHASSIS_VERSION_SIZE];
+ char serial[CHASSIS_SERIAL_SIZE];
+ char asset_tag[CHASSIS_ASSET_TAG_SIZE];
+ char boot_up_state[CHASSIS_BOOT_UP_STATE_SIZE];
+ char power_supply_state[CHASSIS_POWER_SUPPLY_STATE_SIZE];
+ char thermal_state[CHASSIS_THERMAL_STATE_SIZE];
+ char security_status[CHASSIS_SECURITY_STATUS_SIZE];
+ char oem_information[CHASSIS_OEM_INFORMATION_SIZE];
+ uint16_t height;
+ uint16_t nb_power_cords;
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_chassis;
const char *dmi_chassis_type(uint8_t code);
diff --git a/com32/gplinclude/dmi/dmi_ipmi.h b/com32/gplinclude/dmi/dmi_ipmi.h
index 7dcb71b9..9110ae4f 100644
--- a/com32/gplinclude/dmi/dmi_ipmi.h
+++ b/com32/gplinclude/dmi/dmi_ipmi.h
@@ -17,17 +17,17 @@
#define IPMI_MEMORY_MODEL_SIZE 16
typedef struct {
-char interface_type[IPMI_INTERFACE_TYPE_SIZE];
-uint8_t major_specification_version;
-uint8_t minor_specification_version;
-uint8_t I2C_slave_address;
-uint16_t nv_address;
-uint64_t base_address;
+ char interface_type[IPMI_INTERFACE_TYPE_SIZE];
+ uint8_t major_specification_version;
+ uint8_t minor_specification_version;
+ uint8_t I2C_slave_address;
+ uint16_t nv_address;
+ uint64_t base_address;
-uint8_t irq;
-bool filled;
+ uint8_t irq;
+ bool filled;
} s_ipmi;
-void dmi_ipmi_base_address(uint8_t type, const uint8_t *p, s_ipmi *ipmi);
+void dmi_ipmi_base_address(uint8_t type, const uint8_t * p, s_ipmi * ipmi);
const char *dmi_ipmi_interface_type(uint8_t code);
#endif
diff --git a/com32/gplinclude/dmi/dmi_memory.h b/com32/gplinclude/dmi/dmi_memory.h
index 2b744b5c..ed4eb6f4 100644
--- a/com32/gplinclude/dmi/dmi_memory.h
+++ b/com32/gplinclude/dmi/dmi_memory.h
@@ -30,32 +30,32 @@
#define MEMORY_PART_NUMBER_SIZE 16
typedef struct {
-char manufacturer[MEMORY_MANUFACTURER_SIZE];
-char error[MEMORY_ERROR_SIZE];
-char total_width[MEMORY_TOTAL_WIDTH_SIZE];
-char data_width[MEMORY_DATA_WIDTH_SIZE];
-char size[MEMORY_SIZE_SIZE];
-char form_factor[MEMORY_FORM_FACTOR_SIZE];
-char device_set[MEMORY_DEVICE_SET_SIZE];
-char device_locator[MEMORY_DEVICE_LOCATOR_SIZE];
-char bank_locator[MEMORY_BANK_LOCATOR_SIZE];
-char type[MEMORY_TYPE_SIZE];
-char type_detail[MEMORY_TYPE_DETAIL_SIZE];
-char speed[MEMORY_SPEED_SIZE];
-char serial[MEMORY_SERIAL_SIZE];
-char asset_tag[MEMORY_ASSET_TAG_SIZE];
-char part_number[MEMORY_PART_NUMBER_SIZE];
+ char manufacturer[MEMORY_MANUFACTURER_SIZE];
+ char error[MEMORY_ERROR_SIZE];
+ char total_width[MEMORY_TOTAL_WIDTH_SIZE];
+ char data_width[MEMORY_DATA_WIDTH_SIZE];
+ char size[MEMORY_SIZE_SIZE];
+ char form_factor[MEMORY_FORM_FACTOR_SIZE];
+ char device_set[MEMORY_DEVICE_SET_SIZE];
+ char device_locator[MEMORY_DEVICE_LOCATOR_SIZE];
+ char bank_locator[MEMORY_BANK_LOCATOR_SIZE];
+ char type[MEMORY_TYPE_SIZE];
+ char type_detail[MEMORY_TYPE_DETAIL_SIZE];
+ char speed[MEMORY_SPEED_SIZE];
+ char serial[MEMORY_SERIAL_SIZE];
+ char asset_tag[MEMORY_ASSET_TAG_SIZE];
+ char part_number[MEMORY_PART_NUMBER_SIZE];
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_memory;
-void dmi_memory_array_error_handle(uint16_t code,char *array);
+void dmi_memory_array_error_handle(uint16_t code, char *array);
void dmi_memory_device_width(uint16_t code, char *width);
void dmi_memory_device_size(uint16_t code, char *size);
const char *dmi_memory_device_form_factor(uint8_t code);
void dmi_memory_device_set(uint8_t code, char *set);
const char *dmi_memory_device_type(uint8_t code);
-void dmi_memory_device_type_detail(uint16_t code,char *type_detail);
+void dmi_memory_device_type_detail(uint16_t code, char *type_detail);
void dmi_memory_device_speed(uint16_t code, char *speed);
#endif
diff --git a/com32/gplinclude/dmi/dmi_processor.h b/com32/gplinclude/dmi/dmi_processor.h
index 79ee43d4..de2f4e4f 100644
--- a/com32/gplinclude/dmi/dmi_processor.h
+++ b/com32/gplinclude/dmi/dmi_processor.h
@@ -36,76 +36,77 @@ extern const char *cpu_flags_strings[PROCESSOR_FLAGS_ELEMENTS];
/* this struct have PROCESSOR_FLAGS_ELEMENTS */
/* each bool is associated to the relevant message above */
typedef struct {
-bool fpu;
-bool vme;
-bool de;
-bool pse;
-bool tsc;
-bool msr;
-bool pae;
-bool mce;
-bool cx8;
-bool apic;
-bool null_10;
-bool sep;
-bool mtrr;
-bool pge;
-bool mca;
-bool cmov;
-bool pat;
-bool pse_36;
-bool psn;
-bool clfsh;
-bool null_20;
-bool ds;
-bool acpi;
-bool mmx;
-bool fxsr;
-bool sse;
-bool sse2;
-bool ss;
-bool htt;
-bool tm;
-bool null_30;
-bool pbe;
-} __attribute__((__packed__)) s_dmi_cpu_flags;
+ bool fpu;
+ bool vme;
+ bool de;
+ bool pse;
+ bool tsc;
+ bool msr;
+ bool pae;
+ bool mce;
+ bool cx8;
+ bool apic;
+ bool null_10;
+ bool sep;
+ bool mtrr;
+ bool pge;
+ bool mca;
+ bool cmov;
+ bool pat;
+ bool pse_36;
+ bool psn;
+ bool clfsh;
+ bool null_20;
+ bool ds;
+ bool acpi;
+ bool mmx;
+ bool fxsr;
+ bool sse;
+ bool sse2;
+ bool ss;
+ bool htt;
+ bool tm;
+ bool null_30;
+ bool pbe;
+} __attribute__ ((__packed__)) s_dmi_cpu_flags;
typedef struct {
-uint8_t type;
-uint8_t family;
-uint8_t model;
-uint8_t stepping;
-uint8_t minor_stepping;
-} __attribute__((__packed__)) s_signature;
+ uint8_t type;
+ uint8_t family;
+ uint8_t model;
+ uint8_t stepping;
+ uint8_t minor_stepping;
+} __attribute__ ((__packed__)) s_signature;
typedef struct {
-char socket_designation[PROCESSOR_SOCKET_DESIGNATION_SIZE];
-char type[PROCESSOR_TYPE_SIZE];
-char family[PROCESSOR_FAMILY_SIZE];
-char manufacturer[PROCESSOR_MANUFACTURER_SIZE];
-char version[PROCESSOR_VERSION_SIZE];
-float voltage;
-uint16_t external_clock;
-uint16_t max_speed;
-uint16_t current_speed;
-char status[PROCESSOR_STATUS_SIZE];
-char upgrade[PROCESSOR_UPGRADE_SIZE];
-char cache1[PROCESSOR_CACHE_SIZE];
-char cache2[PROCESSOR_CACHE_SIZE];
-char cache3[PROCESSOR_CACHE_SIZE];
-char serial[PROCESSOR_SERIAL_SIZE];
-char asset_tag[PROCESSOR_ASSET_TAG_SIZE];
-char part_number[PROCESSOR_PART_NUMBER_SIZE];
-char id[PROCESSOR_ID_SIZE];
-s_dmi_cpu_flags cpu_flags;
-s_signature signature;
+ char socket_designation[PROCESSOR_SOCKET_DESIGNATION_SIZE];
+ char type[PROCESSOR_TYPE_SIZE];
+ char family[PROCESSOR_FAMILY_SIZE];
+ char manufacturer[PROCESSOR_MANUFACTURER_SIZE];
+ char version[PROCESSOR_VERSION_SIZE];
+ float voltage;
+ uint16_t external_clock;
+ uint16_t max_speed;
+ uint16_t current_speed;
+ char status[PROCESSOR_STATUS_SIZE];
+ char upgrade[PROCESSOR_UPGRADE_SIZE];
+ char cache1[PROCESSOR_CACHE_SIZE];
+ char cache2[PROCESSOR_CACHE_SIZE];
+ char cache3[PROCESSOR_CACHE_SIZE];
+ char serial[PROCESSOR_SERIAL_SIZE];
+ char asset_tag[PROCESSOR_ASSET_TAG_SIZE];
+ char part_number[PROCESSOR_PART_NUMBER_SIZE];
+ char id[PROCESSOR_ID_SIZE];
+ s_dmi_cpu_flags cpu_flags;
+ s_signature signature;
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_processor;
const char *dmi_processor_type(uint8_t code);
const char *dmi_processor_family(uint8_t code, char *manufacturer);
const char *dmi_processor_status(uint8_t code);
const char *dmi_processor_upgrade(uint8_t code);
-void dmi_processor_cache(uint16_t code, const char *level, uint16_t ver, char *cache);
+void dmi_processor_cache(uint16_t code, const char *level, uint16_t ver,
+ char *cache);
#endif
diff --git a/com32/gplinclude/dmi/dmi_system.h b/com32/gplinclude/dmi/dmi_system.h
index 5a461d5f..9c313ebb 100644
--- a/com32/gplinclude/dmi/dmi_system.h
+++ b/com32/gplinclude/dmi/dmi_system.h
@@ -23,16 +23,16 @@
#define SYSTEM_FAMILY_SIZE 32
typedef struct {
-char manufacturer[SYSTEM_MANUFACTURER_SIZE];
-char product_name[SYSTEM_PRODUCT_NAME_SIZE];
-char version[SYSTEM_VERSION_SIZE];
-char serial[SYSTEM_SERIAL_SIZE];
-char uuid[SYSTEM_UUID_SIZE];
-char wakeup_type[SYSTEM_WAKEUP_TYPE_SIZE];
-char sku_number[SYSTEM_SKU_NUMBER_SIZE];
-char family[SYSTEM_FAMILY_SIZE];
+ char manufacturer[SYSTEM_MANUFACTURER_SIZE];
+ char product_name[SYSTEM_PRODUCT_NAME_SIZE];
+ char version[SYSTEM_VERSION_SIZE];
+ char serial[SYSTEM_SERIAL_SIZE];
+ char uuid[SYSTEM_UUID_SIZE];
+ char wakeup_type[SYSTEM_WAKEUP_TYPE_SIZE];
+ char sku_number[SYSTEM_SKU_NUMBER_SIZE];
+ char family[SYSTEM_FAMILY_SIZE];
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_system;
#endif
diff --git a/com32/gplinclude/vpd/vpd.h b/com32/gplinclude/vpd/vpd.h
index 4bb1afc9..f1dcec68 100644
--- a/com32/gplinclude/vpd/vpd.h
+++ b/com32/gplinclude/vpd/vpd.h
@@ -15,19 +15,19 @@
#include <inttypes.h>
#include <stdbool.h>
-enum {VPD_TABLE_PRESENT = 100, ENOVPDTABLE};
+enum { VPD_TABLE_PRESENT = 100, ENOVPDTABLE };
typedef struct {
- char bios_build_id[10];
- char box_serial_number[8];
- char motherboard_serial_number[12];
- char machine_type_model[8];
- char bios_release_date[9];
- char default_flash_filename[13];
- char bios_version[255];
- char base_address[6];
- bool filled;
+ char bios_build_id[10];
+ char box_serial_number[8];
+ char motherboard_serial_number[12];
+ char machine_type_model[8];
+ char bios_release_date[9];
+ char default_flash_filename[13];
+ char bios_version[255];
+ char base_address[6];
+ bool filled;
} s_vpd;
-int vpd_decode(s_vpd *vpd);
+int vpd_decode(s_vpd * vpd);
#endif
diff --git a/com32/gpllib/cpuid.c b/com32/gpllib/cpuid.c
index ed3224d4..6d464c7e 100644
--- a/com32/gpllib/cpuid.c
+++ b/com32/gpllib/cpuid.c
@@ -20,7 +20,7 @@
#include <string.h>
#include "cpuid.h"
-struct cpu_dev * cpu_devs[X86_VENDOR_NUM] = {};
+struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = { };
/*
* CPUID functions returning a single datum
@@ -29,153 +29,153 @@ struct cpu_dev * cpu_devs[X86_VENDOR_NUM] = {};
/* Probe for the CPUID instruction */
static int have_cpuid_p(void)
{
- return cpu_has_eflag(X86_EFLAGS_ID);
+ return cpu_has_eflag(X86_EFLAGS_ID);
}
static struct cpu_dev amd_cpu_dev = {
- .c_vendor = "AMD",
- .c_ident = { "AuthenticAMD" }
+ .c_vendor = "AMD",
+ .c_ident = {"AuthenticAMD"}
};
static struct cpu_dev intel_cpu_dev = {
- .c_vendor = "Intel",
- .c_ident = { "GenuineIntel" }
+ .c_vendor = "Intel",
+ .c_ident = {"GenuineIntel"}
};
static struct cpu_dev cyrix_cpu_dev = {
- .c_vendor = "Cyrix",
- .c_ident = { "CyrixInstead" }
+ .c_vendor = "Cyrix",
+ .c_ident = {"CyrixInstead"}
};
static struct cpu_dev umc_cpu_dev = {
- .c_vendor = "UMC",
- .c_ident = { "UMC UMC UMC" }
+ .c_vendor = "UMC",
+ .c_ident = {"UMC UMC UMC"}
};
static struct cpu_dev nexgen_cpu_dev = {
- .c_vendor = "Nexgen",
- .c_ident = { "NexGenDriven" }
+ .c_vendor = "Nexgen",
+ .c_ident = {"NexGenDriven"}
};
static struct cpu_dev centaur_cpu_dev = {
- .c_vendor = "Centaur",
- .c_ident = { "CentaurHauls" }
+ .c_vendor = "Centaur",
+ .c_ident = {"CentaurHauls"}
};
static struct cpu_dev rise_cpu_dev = {
- .c_vendor = "Rise",
- .c_ident = { "RiseRiseRise" }
+ .c_vendor = "Rise",
+ .c_ident = {"RiseRiseRise"}
};
static struct cpu_dev transmeta_cpu_dev = {
- .c_vendor = "Transmeta",
- .c_ident = { "GenuineTMx86", "TransmetaCPU" }
+ .c_vendor = "Transmeta",
+ .c_ident = {"GenuineTMx86", "TransmetaCPU"}
};
void init_cpu_devs(void)
{
- cpu_devs[X86_VENDOR_INTEL] = &intel_cpu_dev;
- cpu_devs[X86_VENDOR_CYRIX] = &cyrix_cpu_dev;
- cpu_devs[X86_VENDOR_AMD] = &amd_cpu_dev;
- cpu_devs[X86_VENDOR_UMC] = &umc_cpu_dev;
- cpu_devs[X86_VENDOR_NEXGEN] = &nexgen_cpu_dev;
- cpu_devs[X86_VENDOR_CENTAUR] = &centaur_cpu_dev;
- cpu_devs[X86_VENDOR_RISE] = &rise_cpu_dev;
- cpu_devs[X86_VENDOR_TRANSMETA] = &transmeta_cpu_dev;
+ cpu_devs[X86_VENDOR_INTEL] = &intel_cpu_dev;
+ cpu_devs[X86_VENDOR_CYRIX] = &cyrix_cpu_dev;
+ cpu_devs[X86_VENDOR_AMD] = &amd_cpu_dev;
+ cpu_devs[X86_VENDOR_UMC] = &umc_cpu_dev;
+ cpu_devs[X86_VENDOR_NEXGEN] = &nexgen_cpu_dev;
+ cpu_devs[X86_VENDOR_CENTAUR] = &centaur_cpu_dev;
+ cpu_devs[X86_VENDOR_RISE] = &rise_cpu_dev;
+ cpu_devs[X86_VENDOR_TRANSMETA] = &transmeta_cpu_dev;
}
void get_cpu_vendor(struct cpuinfo_x86 *c)
{
- char *v = c->x86_vendor_id;
- int i;
- init_cpu_devs();
- for (i = 0; i < X86_VENDOR_NUM; i++) {
- if (cpu_devs[i]) {
- if (!strcmp(v,cpu_devs[i]->c_ident[0]) ||
- (cpu_devs[i]->c_ident[1] &&
- !strcmp(v,cpu_devs[i]->c_ident[1]))) {
- c->x86_vendor = i;
- return;
- }
- }
- }
-
- c->x86_vendor = X86_VENDOR_UNKNOWN;
+ char *v = c->x86_vendor_id;
+ int i;
+ init_cpu_devs();
+ for (i = 0; i < X86_VENDOR_NUM; i++) {
+ if (cpu_devs[i]) {
+ if (!strcmp(v, cpu_devs[i]->c_ident[0]) ||
+ (cpu_devs[i]->c_ident[1] &&
+ !strcmp(v, cpu_devs[i]->c_ident[1]))) {
+ c->x86_vendor = i;
+ return;
+ }
+ }
+ }
+
+ c->x86_vendor = X86_VENDOR_UNKNOWN;
}
int get_model_name(struct cpuinfo_x86 *c)
{
- unsigned int *v;
- char *p, *q;
-
- if (cpuid_eax(0x80000000) < 0x80000004)
- return 0;
-
- v = (unsigned int *) c->x86_model_id;
- cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
- cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
- cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
- c->x86_model_id[48] = 0;
-
- /* Intel chips right-justify this string for some dumb reason;
- undo that brain damage */
- p = q = &c->x86_model_id[0];
- while ( *p == ' ' )
- p++;
- if ( p != q ) {
- while ( *p )
- *q++ = *p++;
- while ( q <= &c->x86_model_id[48] )
- *q++ = '\0'; /* Zero-pad the rest */
- }
-
- return 1;
+ unsigned int *v;
+ char *p, *q;
+
+ if (cpuid_eax(0x80000000) < 0x80000004)
+ return 0;
+
+ v = (unsigned int *)c->x86_model_id;
+ cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
+ cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
+ cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
+ c->x86_model_id[48] = 0;
+
+ /* Intel chips right-justify this string for some dumb reason;
+ undo that brain damage */
+ p = q = &c->x86_model_id[0];
+ while (*p == ' ')
+ p++;
+ if (p != q) {
+ while (*p)
+ *q++ = *p++;
+ while (q <= &c->x86_model_id[48])
+ *q++ = '\0'; /* Zero-pad the rest */
+ }
+
+ return 1;
}
void generic_identify(struct cpuinfo_x86 *c)
{
- uint32_t tfms, xlvl;
- unsigned int ebx;
-
- /* Get vendor name */
- cpuid(0x00000000,
- (uint32_t *)&c->cpuid_level,
- (uint32_t *)&c->x86_vendor_id[0],
- (uint32_t *)&c->x86_vendor_id[8],
- (uint32_t *)&c->x86_vendor_id[4]);
-
- get_cpu_vendor(c);
- /* Intel-defined flags: level 0x00000001 */
- if ( c->cpuid_level >= 0x00000001 ) {
- uint32_t capability, excap;
- cpuid(0x00000001, &tfms, &ebx, &excap, &capability);
- c->x86_capability[0] = capability;
- c->x86_capability[4] = excap;
- c->x86 = (tfms >> 8) & 15;
- c->x86_model = (tfms >> 4) & 15;
- if (c->x86 == 0xf)
- c->x86 += (tfms >> 20) & 0xff;
- if (c->x86 >= 0x6)
- c->x86_model += ((tfms >> 16) & 0xF) << 4;
- c->x86_mask = tfms & 15;
- if (cpu_has(c, X86_FEATURE_CLFLSH))
- c->x86_clflush_size = ((ebx >> 8) & 0xff) * 8;
- } else {
- /* Have CPUID level 0 only - unheard of */
- c->x86 = 4;
+ uint32_t tfms, xlvl;
+ unsigned int ebx;
+
+ /* Get vendor name */
+ cpuid(0x00000000,
+ (uint32_t *) & c->cpuid_level,
+ (uint32_t *) & c->x86_vendor_id[0],
+ (uint32_t *) & c->x86_vendor_id[8],
+ (uint32_t *) & c->x86_vendor_id[4]);
+
+ get_cpu_vendor(c);
+ /* Intel-defined flags: level 0x00000001 */
+ if (c->cpuid_level >= 0x00000001) {
+ uint32_t capability, excap;
+ cpuid(0x00000001, &tfms, &ebx, &excap, &capability);
+ c->x86_capability[0] = capability;
+ c->x86_capability[4] = excap;
+ c->x86 = (tfms >> 8) & 15;
+ c->x86_model = (tfms >> 4) & 15;
+ if (c->x86 == 0xf)
+ c->x86 += (tfms >> 20) & 0xff;
+ if (c->x86 >= 0x6)
+ c->x86_model += ((tfms >> 16) & 0xF) << 4;
+ c->x86_mask = tfms & 15;
+ if (cpu_has(c, X86_FEATURE_CLFLSH))
+ c->x86_clflush_size = ((ebx >> 8) & 0xff) * 8;
+ } else {
+ /* Have CPUID level 0 only - unheard of */
+ c->x86 = 4;
+ }
+
+ /* AMD-defined flags: level 0x80000001 */
+ xlvl = cpuid_eax(0x80000000);
+ if ((xlvl & 0xffff0000) == 0x80000000) {
+ if (xlvl >= 0x80000001) {
+ c->x86_capability[1] = cpuid_edx(0x80000001);
+ c->x86_capability[6] = cpuid_ecx(0x80000001);
}
-
- /* AMD-defined flags: level 0x80000001 */
- xlvl = cpuid_eax(0x80000000);
- if ( (xlvl & 0xffff0000) == 0x80000000 ) {
- if ( xlvl >= 0x80000001 ) {
- c->x86_capability[1] = cpuid_edx(0x80000001);
- c->x86_capability[6] = cpuid_ecx(0x80000001);
- }
- if ( xlvl >= 0x80000004 )
- get_model_name(c); /* Default name */
- }
+ if (xlvl >= 0x80000004)
+ get_model_name(c); /* Default name */
+ }
}
/*
@@ -184,145 +184,147 @@ void generic_identify(struct cpuinfo_x86 *c)
static int mpf_checksum(unsigned char *mp, int len)
{
- int sum = 0;
+ int sum = 0;
- while (len--)
- sum += *mp++;
+ while (len--)
+ sum += *mp++;
- return sum & 0xFF;
+ return sum & 0xFF;
}
-static int smp_scan_config (unsigned long base, unsigned long length)
+static int smp_scan_config(unsigned long base, unsigned long length)
{
- unsigned long *bp = (unsigned long *)base;
- struct intel_mp_floating *mpf;
+ unsigned long *bp = (unsigned long *)base;
+ struct intel_mp_floating *mpf;
// printf("Scan SMP from %p for %ld bytes.\n", bp,length);
- if (sizeof(*mpf) != 16) {
- printf("Error: MPF size\n");
- return 0;
+ if (sizeof(*mpf) != 16) {
+ printf("Error: MPF size\n");
+ return 0;
+ }
+
+ while (length > 0) {
+ mpf = (struct intel_mp_floating *)bp;
+ if ((*bp == SMP_MAGIC_IDENT) &&
+ (mpf->mpf_length == 1) &&
+ !mpf_checksum((unsigned char *)bp, 16) &&
+ ((mpf->mpf_specification == 1)
+ || (mpf->mpf_specification == 4))) {
+ return 1;
}
-
- while (length > 0) {
- mpf = (struct intel_mp_floating *)bp;
- if ((*bp == SMP_MAGIC_IDENT) &&
- (mpf->mpf_length == 1) &&
- !mpf_checksum((unsigned char *)bp, 16) &&
- ((mpf->mpf_specification == 1)
- || (mpf->mpf_specification == 4)) ) {
- return 1;
- }
- bp += 4;
- length -= 16;
- }
- return 0;
+ bp += 4;
+ length -= 16;
+ }
+ return 0;
}
-int find_smp_config (void)
+int find_smp_config(void)
{
// unsigned int address;
- /*
- * FIXME: Linux assumes you have 640K of base ram..
- * this continues the error...
- *
- * 1) Scan the bottom 1K for a signature
- * 2) Scan the top 1K of base RAM
- * 3) Scan the 64K of bios
- */
- if (smp_scan_config(0x0,0x400) ||
- smp_scan_config(639*0x400,0x400) ||
- smp_scan_config(0xF0000,0x10000))
- return 1;
- /*
- * If it is an SMP machine we should know now, unless the
- * configuration is in an EISA/MCA bus machine with an
- * extended bios data area.
- *
- * there is a real-mode segmented pointer pointing to the
- * 4K EBDA area at 0x40E, calculate and scan it here.
- *
- * NOTE! There are Linux loaders that will corrupt the EBDA
- * area, and as such this kind of SMP config may be less
- * trustworthy, simply because the SMP table may have been
- * stomped on during early boot. These loaders are buggy and
- * should be fixed.
- *
- * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
- */
+ /*
+ * FIXME: Linux assumes you have 640K of base ram..
+ * this continues the error...
+ *
+ * 1) Scan the bottom 1K for a signature
+ * 2) Scan the top 1K of base RAM
+ * 3) Scan the 64K of bios
+ */
+ if (smp_scan_config(0x0, 0x400) ||
+ smp_scan_config(639 * 0x400, 0x400) ||
+ smp_scan_config(0xF0000, 0x10000))
+ return 1;
+ /*
+ * If it is an SMP machine we should know now, unless the
+ * configuration is in an EISA/MCA bus machine with an
+ * extended bios data area.
+ *
+ * there is a real-mode segmented pointer pointing to the
+ * 4K EBDA area at 0x40E, calculate and scan it here.
+ *
+ * NOTE! There are Linux loaders that will corrupt the EBDA
+ * area, and as such this kind of SMP config may be less
+ * trustworthy, simply because the SMP table may have been
+ * stomped on during early boot. These loaders are buggy and
+ * should be fixed.
+ *
+ * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
+ */
// address = get_bios_ebda();
// if (address)
// smp_scan_config(address, 0x400);
- return 0;
+ return 0;
}
-
-void set_cpu_flags(struct cpuinfo_x86 *c, s_cpu *cpu) {
-cpu->flags.fpu=cpu_has(c, X86_FEATURE_FPU);
-cpu->flags.vme=cpu_has(c, X86_FEATURE_VME);
-cpu->flags.de=cpu_has(c, X86_FEATURE_DE);
-cpu->flags.pse=cpu_has(c, X86_FEATURE_PSE);
-cpu->flags.tsc=cpu_has(c, X86_FEATURE_TSC);
-cpu->flags.msr=cpu_has(c, X86_FEATURE_MSR);
-cpu->flags.pae=cpu_has(c, X86_FEATURE_PAE);
-cpu->flags.mce=cpu_has(c, X86_FEATURE_MCE);
-cpu->flags.cx8=cpu_has(c, X86_FEATURE_CX8);
-cpu->flags.apic=cpu_has(c, X86_FEATURE_APIC);
-cpu->flags.sep=cpu_has(c, X86_FEATURE_SEP);
-cpu->flags.mtrr=cpu_has(c, X86_FEATURE_MTRR);
-cpu->flags.pge=cpu_has(c, X86_FEATURE_PGE);
-cpu->flags.mca=cpu_has(c, X86_FEATURE_MCA);
-cpu->flags.cmov=cpu_has(c, X86_FEATURE_CMOV);
-cpu->flags.pat=cpu_has(c, X86_FEATURE_PAT);
-cpu->flags.pse_36=cpu_has(c, X86_FEATURE_PSE36);
-cpu->flags.psn=cpu_has(c, X86_FEATURE_PN);
-cpu->flags.clflsh=cpu_has(c, X86_FEATURE_CLFLSH);
-cpu->flags.dts=cpu_has(c, X86_FEATURE_DTES);
-cpu->flags.acpi=cpu_has(c, X86_FEATURE_ACPI);
-cpu->flags.mmx=cpu_has(c, X86_FEATURE_MMX);
-cpu->flags.fxsr=cpu_has(c, X86_FEATURE_FXSR);
-cpu->flags.sse=cpu_has(c, X86_FEATURE_XMM);
-cpu->flags.sse2=cpu_has(c, X86_FEATURE_XMM2);
-cpu->flags.ss=cpu_has(c, X86_FEATURE_SELFSNOOP);
-cpu->flags.htt=cpu_has(c, X86_FEATURE_HT);
-cpu->flags.acc=cpu_has(c, X86_FEATURE_ACC);
-cpu->flags.syscall=cpu_has(c, X86_FEATURE_SYSCALL);
-cpu->flags.mp=cpu_has(c, X86_FEATURE_MP);
-cpu->flags.nx=cpu_has(c, X86_FEATURE_NX);
-cpu->flags.mmxext=cpu_has(c, X86_FEATURE_MMXEXT);
-cpu->flags.lm=cpu_has(c, X86_FEATURE_LM);
-cpu->flags.nowext=cpu_has(c, X86_FEATURE_3DNOWEXT);
-cpu->flags.now=cpu_has(c, X86_FEATURE_3DNOW);
-cpu->flags.smp = find_smp_config();
+void set_cpu_flags(struct cpuinfo_x86 *c, s_cpu * cpu)
+{
+ cpu->flags.fpu = cpu_has(c, X86_FEATURE_FPU);
+ cpu->flags.vme = cpu_has(c, X86_FEATURE_VME);
+ cpu->flags.de = cpu_has(c, X86_FEATURE_DE);
+ cpu->flags.pse = cpu_has(c, X86_FEATURE_PSE);
+ cpu->flags.tsc = cpu_has(c, X86_FEATURE_TSC);
+ cpu->flags.msr = cpu_has(c, X86_FEATURE_MSR);
+ cpu->flags.pae = cpu_has(c, X86_FEATURE_PAE);
+ cpu->flags.mce = cpu_has(c, X86_FEATURE_MCE);
+ cpu->flags.cx8 = cpu_has(c, X86_FEATURE_CX8);
+ cpu->flags.apic = cpu_has(c, X86_FEATURE_APIC);
+ cpu->flags.sep = cpu_has(c, X86_FEATURE_SEP);
+ cpu->flags.mtrr = cpu_has(c, X86_FEATURE_MTRR);
+ cpu->flags.pge = cpu_has(c, X86_FEATURE_PGE);
+ cpu->flags.mca = cpu_has(c, X86_FEATURE_MCA);
+ cpu->flags.cmov = cpu_has(c, X86_FEATURE_CMOV);
+ cpu->flags.pat = cpu_has(c, X86_FEATURE_PAT);
+ cpu->flags.pse_36 = cpu_has(c, X86_FEATURE_PSE36);
+ cpu->flags.psn = cpu_has(c, X86_FEATURE_PN);
+ cpu->flags.clflsh = cpu_has(c, X86_FEATURE_CLFLSH);
+ cpu->flags.dts = cpu_has(c, X86_FEATURE_DTES);
+ cpu->flags.acpi = cpu_has(c, X86_FEATURE_ACPI);
+ cpu->flags.mmx = cpu_has(c, X86_FEATURE_MMX);
+ cpu->flags.fxsr = cpu_has(c, X86_FEATURE_FXSR);
+ cpu->flags.sse = cpu_has(c, X86_FEATURE_XMM);
+ cpu->flags.sse2 = cpu_has(c, X86_FEATURE_XMM2);
+ cpu->flags.ss = cpu_has(c, X86_FEATURE_SELFSNOOP);
+ cpu->flags.htt = cpu_has(c, X86_FEATURE_HT);
+ cpu->flags.acc = cpu_has(c, X86_FEATURE_ACC);
+ cpu->flags.syscall = cpu_has(c, X86_FEATURE_SYSCALL);
+ cpu->flags.mp = cpu_has(c, X86_FEATURE_MP);
+ cpu->flags.nx = cpu_has(c, X86_FEATURE_NX);
+ cpu->flags.mmxext = cpu_has(c, X86_FEATURE_MMXEXT);
+ cpu->flags.lm = cpu_has(c, X86_FEATURE_LM);
+ cpu->flags.nowext = cpu_has(c, X86_FEATURE_3DNOWEXT);
+ cpu->flags.now = cpu_has(c, X86_FEATURE_3DNOW);
+ cpu->flags.smp = find_smp_config();
}
-void set_generic_info(struct cpuinfo_x86 *c,s_cpu *cpu) {
- cpu->family=c->x86;
- cpu->vendor_id=c->x86_vendor;
- cpu->model_id=c->x86_model;
- cpu->stepping=c->x86_mask;
- strncpy(cpu->vendor,cpu_devs[c->x86_vendor]->c_vendor,sizeof(cpu->vendor));
- strncpy(cpu->model,c->x86_model_id,sizeof(cpu->model));
+void set_generic_info(struct cpuinfo_x86 *c, s_cpu * cpu)
+{
+ cpu->family = c->x86;
+ cpu->vendor_id = c->x86_vendor;
+ cpu->model_id = c->x86_model;
+ cpu->stepping = c->x86_mask;
+ strncpy(cpu->vendor, cpu_devs[c->x86_vendor]->c_vendor,
+ sizeof(cpu->vendor));
+ strncpy(cpu->model, c->x86_model_id, sizeof(cpu->model));
}
-void detect_cpu(s_cpu *cpu)
+void detect_cpu(s_cpu * cpu)
{
- struct cpuinfo_x86 c;
- c.x86_clflush_size = 32;
- c.x86_cache_size = -1;
- c.x86_vendor = X86_VENDOR_UNKNOWN;
- c.cpuid_level = -1; /* CPUID not detected */
- c.x86_model = c.x86_mask = 0; /* So far unknown... */
- c.x86_max_cores = 1;
- memset(&c.x86_capability, 0, sizeof(c.x86_capability));
- memset(&c.x86_vendor_id,0,sizeof(c.x86_vendor_id));
- memset(&c.x86_model_id,0,sizeof(c.x86_model_id));
-
- if (!have_cpuid_p())
- return;
-
- generic_identify(&c);
- set_generic_info(&c,cpu);
- set_cpu_flags(&c,cpu);
+ struct cpuinfo_x86 c;
+ c.x86_clflush_size = 32;
+ c.x86_cache_size = -1;
+ c.x86_vendor = X86_VENDOR_UNKNOWN;
+ c.cpuid_level = -1; /* CPUID not detected */
+ c.x86_model = c.x86_mask = 0; /* So far unknown... */
+ c.x86_max_cores = 1;
+ memset(&c.x86_capability, 0, sizeof(c.x86_capability));
+ memset(&c.x86_vendor_id, 0, sizeof(c.x86_vendor_id));
+ memset(&c.x86_model_id, 0, sizeof(c.x86_model_id));
+
+ if (!have_cpuid_p())
+ return;
+
+ generic_identify(&c);
+ set_generic_info(&c, cpu);
+ set_cpu_flags(&c, cpu);
}
diff --git a/com32/gpllib/dmi/dmi.c b/com32/gpllib/dmi/dmi.c
index 23caa334..70ddd455 100644
--- a/com32/gpllib/dmi/dmi.c
+++ b/com32/gpllib/dmi/dmi.c
@@ -33,586 +33,605 @@
const char *out_of_spec = "<OUT OF SPEC>";
const char *bad_index = "<BAD INDEX>";
-void dmi_bios_runtime_size(uint32_t code, s_dmi *dmi)
+void dmi_bios_runtime_size(uint32_t code, s_dmi * dmi)
{
- if(code&0x000003FF) {
- dmi->bios.runtime_size=code;
- strcpy(dmi->bios.runtime_size_unit,"bytes");
- } else {
- dmi->bios.runtime_size=code >>10;
- strcpy(dmi->bios.runtime_size_unit,"KB");
-
- }
+ if (code & 0x000003FF) {
+ dmi->bios.runtime_size = code;
+ strcpy(dmi->bios.runtime_size_unit, "bytes");
+ } else {
+ dmi->bios.runtime_size = code >> 10;
+ strcpy(dmi->bios.runtime_size_unit, "KB");
+
+ }
}
-void dmi_bios_characteristics(uint64_t code, s_dmi *dmi)
+void dmi_bios_characteristics(uint64_t code, s_dmi * dmi)
{
- int i;
- /*
- * This isn't very clear what this bit is supposed to mean
- */
- //if(code.l&(1<<3))
- if(code&&(1<<3))
- {
- ((bool *)(& dmi->bios.characteristics))[0]=true;
- return;
- }
-
- for(i=4; i<=31; i++)
- //if(code.l&(1<<i))
- if(code&(1<<i))
- ((bool *)(& dmi->bios.characteristics))[i-3]=true;
+ int i;
+ /*
+ * This isn't very clear what this bit is supposed to mean
+ */
+ //if(code.l&(1<<3))
+ if (code && (1 << 3)) {
+ ((bool *) (&dmi->bios.characteristics))[0] = true;
+ return;
+ }
+
+ for (i = 4; i <= 31; i++)
+ //if(code.l&(1<<i))
+ if (code & (1 << i))
+ ((bool *) (&dmi->bios.characteristics))[i - 3] = true;
}
-void dmi_bios_characteristics_x1(uint8_t code, s_dmi *dmi)
+void dmi_bios_characteristics_x1(uint8_t code, s_dmi * dmi)
{
- int i;
+ int i;
- for(i=0; i<=7; i++)
- if(code&(1<<i))
- ((bool *)(& dmi->bios.characteristics_x1))[i]=true;
+ for (i = 0; i <= 7; i++)
+ if (code & (1 << i))
+ ((bool *) (&dmi->bios.characteristics_x1))[i] = true;
}
-void dmi_bios_characteristics_x2(uint8_t code, s_dmi *dmi)
+void dmi_bios_characteristics_x2(uint8_t code, s_dmi * dmi)
{
- int i;
+ int i;
- for(i=0; i<=2; i++)
- if(code&(1<<i))
- ((bool *)(& dmi->bios.characteristics_x2))[i]=true;
+ for (i = 0; i <= 2; i++)
+ if (code & (1 << i))
+ ((bool *) (&dmi->bios.characteristics_x2))[i] = true;
}
-
-void dmi_system_uuid(uint8_t *p, s_dmi *dmi)
+void dmi_system_uuid(uint8_t * p, s_dmi * dmi)
{
- int only0xFF=1, only0x00=1;
- int i;
-
- for(i=0; i<16 && (only0x00 || only0xFF); i++)
- {
- if(p[i]!=0x00) only0x00=0;
- if(p[i]!=0xFF) only0xFF=0;
- }
-
- if(only0xFF)
- {
- sprintf(dmi->system.uuid,"Not Present");
- return;
- }
- if(only0x00)
- {
- sprintf(dmi->system.uuid,"Not Settable");
- return;
- }
-
- sprintf(dmi->system.uuid,"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
- p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
- p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
+ int only0xFF = 1, only0x00 = 1;
+ int i;
+
+ for (i = 0; i < 16 && (only0x00 || only0xFF); i++) {
+ if (p[i] != 0x00)
+ only0x00 = 0;
+ if (p[i] != 0xFF)
+ only0xFF = 0;
+ }
+
+ if (only0xFF) {
+ sprintf(dmi->system.uuid, "Not Present");
+ return;
+ }
+ if (only0x00) {
+ sprintf(dmi->system.uuid, "Not Settable");
+ return;
+ }
+
+ sprintf(dmi->system.uuid,
+ "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
+ p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10],
+ p[11], p[12], p[13], p[14], p[15]);
}
-void dmi_system_wake_up_type(uint8_t code, s_dmi *dmi)
+void dmi_system_wake_up_type(uint8_t code, s_dmi * dmi)
{
- /* 3.3.2.1 */
- static const char *type[]={
- "Reserved", /* 0x00 */
- "Other",
- "Unknown",
- "APM Timer",
- "Modem Ring",
- "LAN Remote",
- "Power Switch",
- "PCI PME#",
- "AC Power Restored" /* 0x08 */
- };
-
- if(code<=0x08) {
- strcpy(dmi->system.wakeup_type,type[code]);
- } else {
- strcpy(dmi->system.wakeup_type,out_of_spec);
- }
-return;
+ /* 3.3.2.1 */
+ static const char *type[] = {
+ "Reserved", /* 0x00 */
+ "Other",
+ "Unknown",
+ "APM Timer",
+ "Modem Ring",
+ "LAN Remote",
+ "Power Switch",
+ "PCI PME#",
+ "AC Power Restored" /* 0x08 */
+ };
+
+ if (code <= 0x08) {
+ strcpy(dmi->system.wakeup_type, type[code]);
+ } else {
+ strcpy(dmi->system.wakeup_type, out_of_spec);
+ }
+ return;
}
-static void dmi_base_board_features(uint8_t code, s_dmi *dmi)
+static void dmi_base_board_features(uint8_t code, s_dmi * dmi)
{
- if((code&0x1F)!=0)
- {
- int i;
-
- for(i=0; i<=4; i++)
- if(code&(1<<i))
- ((bool *)(& dmi->base_board.features))[i]=true;
- }
+ if ((code & 0x1F) != 0) {
+ int i;
+
+ for (i = 0; i <= 4; i++)
+ if (code & (1 << i))
+ ((bool *) (&dmi->base_board.features))[i] = true;
+ }
}
-static void dmi_processor_voltage(uint8_t code, s_dmi *dmi)
+static void dmi_processor_voltage(uint8_t code, s_dmi * dmi)
{
- /* 3.3.5.4 */
- static const float voltage[]={
- 5.0,
- 3.3,
- 2.9
- };
- int i;
-
- if(code&0x80)
- dmi->processor.voltage=((float)(code&0x7f)/10);
- else
- {
- for(i=0; i<=2; i++)
- if(code&(1<<i))
- dmi->processor.voltage=voltage[i];
- }
+ /* 3.3.5.4 */
+ static const float voltage[] = {
+ 5.0,
+ 3.3,
+ 2.9
+ };
+ int i;
+
+ if (code & 0x80)
+ dmi->processor.voltage = ((float)(code & 0x7f) / 10);
+ else {
+ for (i = 0; i <= 2; i++)
+ if (code & (1 << i))
+ dmi->processor.voltage = voltage[i];
+ }
}
-static void dmi_processor_id(uint8_t type, uint8_t *p, const char *version, s_dmi *dmi)
+static void dmi_processor_id(uint8_t type, uint8_t * p, const char *version,
+ s_dmi * dmi)
{
- /*
- * Extra flags are now returned in the ECX register when one calls
- * the CPUID instruction. Their meaning is explained in table 6, but
- * DMI doesn't support this yet.
- */
- uint32_t eax, edx;
- int sig=0;
-
- /*
- * This might help learn about new processors supporting the
- * CPUID instruction or another form of identification.
- */
- sprintf(dmi->processor.id,"ID: %02X %02X %02X %02X %02X %02X %02X %02X\n",
- p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
-
- if(type==0x05) /* 80386 */
- {
- uint16_t dx=WORD(p);
- /*
- * 80386 have a different signature.
- */
- dmi->processor.signature.type=(dx >>12);
- dmi->processor.signature.family=((dx>>8)&0xF);
- dmi->processor.signature.stepping=(dx>>4)&0xF;
- dmi->processor.signature.minor_stepping=(dx&0xF);
- return;
- }
- if(type==0x06) /* 80486 */
- {
- uint16_t dx=WORD(p);
- /*
- * Not all 80486 CPU support the CPUID instruction, we have to find
- * wether the one we have here does or not. Note that this trick
- * works only because we know that 80486 must be little-endian.
- */
- if((dx&0x0F00)==0x0400
- && ((dx&0x00F0)==0x0040 || (dx&0x00F0)>=0x0070)
- && ((dx&0x000F)>=0x0003))
- sig=1;
- else
- {
- dmi->processor.signature.type=((dx >>12)&0x3);
- dmi->processor.signature.family=((dx>>8)&0xF);
- dmi->processor.signature.model=((dx>>4)&0xF);
- dmi->processor.signature.stepping=(dx&0xF);
- return;
- }
- }
- else if((type>=0x0B && type<=0x13) /* Intel, Cyrix */
- || (type>=0xB0 && type<=0xB3) /* Intel */
- || type==0xB5 /* Intel */
- || type==0xB9) /* Intel */
- sig=1;
- else if((type>=0x18 && type<=0x1D) /* AMD */
- || type==0x1F /* AMD */
- || (type>=0xB6 && type<=0xB7) /* AMD */
- || (type>=0x83 && type<=0x85)) /* AMD */
- sig=2;
- else if(type==0x01 || type==0x02)
- {
- /*
- * Some X86-class CPU have family "Other" or "Unknown". In this case,
- * we use the version string to determine if they are known to
- * support the CPUID instruction.
- */
- if(strncmp(version, "Pentium III MMX", 15)==0)
- sig=1;
- else if(strncmp(version, "AMD Athlon(TM)", 14)==0
- || strncmp(version, "AMD Opteron(tm)", 15)==0)
- sig=2;
- else
- return;
- }
- else /* not X86-class */
- return;
-
- eax=DWORD(p);
- edx=DWORD(p+4);
- switch(sig)
- {
- case 1: /* Intel */
- dmi->processor.signature.type=((eax >>12)&0x3);
- dmi->processor.signature.family=(((eax>>16)&0xFF0)+((eax>>8)&0x00F));
- dmi->processor.signature.model=(((eax>>12)&0xF0)+((eax>>4)&0x0F));
- dmi->processor.signature.stepping=(eax&0xF);
- break;
- case 2: /* AMD */
- dmi->processor.signature.family=(((eax>>8)&0xF)==0xF?(eax>>20)&0xFF:(eax>>8)&0xF);
- dmi->processor.signature.model =(((eax>>4)&0xF)==0xF?(eax>>16)&0xF :(eax>>4)&0xF);
- dmi->processor.signature.stepping=(eax&0xF);
- break;
- }
-
- edx=DWORD(p+4);
- if((edx&0x3FF7FDFF)!=0)
- {
- int i;
- for(i=0; i<=31; i++)
- if(cpu_flags_strings[i]!=NULL && edx&(1<<i))
- ((bool *)(& dmi->processor.cpu_flags))[i]=true;
- //printf("%s\t%s\n", prefix, flags[i]);
- }
+ /*
+ * Extra flags are now returned in the ECX register when one calls
+ * the CPUID instruction. Their meaning is explained in table 6, but
+ * DMI doesn't support this yet.
+ */
+ uint32_t eax, edx;
+ int sig = 0;
+
+ /*
+ * This might help learn about new processors supporting the
+ * CPUID instruction or another form of identification.
+ */
+ sprintf(dmi->processor.id, "ID: %02X %02X %02X %02X %02X %02X %02X %02X\n",
+ p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
+
+ if (type == 0x05) { /* 80386 */
+ uint16_t dx = WORD(p);
+ /*
+ * 80386 have a different signature.
+ */
+ dmi->processor.signature.type = (dx >> 12);
+ dmi->processor.signature.family = ((dx >> 8) & 0xF);
+ dmi->processor.signature.stepping = (dx >> 4) & 0xF;
+ dmi->processor.signature.minor_stepping = (dx & 0xF);
+ return;
+ }
+ if (type == 0x06) { /* 80486 */
+ uint16_t dx = WORD(p);
+ /*
+ * Not all 80486 CPU support the CPUID instruction, we have to find
+ * wether the one we have here does or not. Note that this trick
+ * works only because we know that 80486 must be little-endian.
+ */
+ if ((dx & 0x0F00) == 0x0400
+ && ((dx & 0x00F0) == 0x0040 || (dx & 0x00F0) >= 0x0070)
+ && ((dx & 0x000F) >= 0x0003))
+ sig = 1;
+ else {
+ dmi->processor.signature.type = ((dx >> 12) & 0x3);
+ dmi->processor.signature.family = ((dx >> 8) & 0xF);
+ dmi->processor.signature.model = ((dx >> 4) & 0xF);
+ dmi->processor.signature.stepping = (dx & 0xF);
+ return;
+ }
+ } else if ((type >= 0x0B && type <= 0x13) /* Intel, Cyrix */
+ ||(type >= 0xB0 && type <= 0xB3) /* Intel */
+ ||type == 0xB5 /* Intel */
+ || type == 0xB9) /* Intel */
+ sig = 1;
+ else if ((type >= 0x18 && type <= 0x1D) /* AMD */
+ ||type == 0x1F /* AMD */
+ || (type >= 0xB6 && type <= 0xB7) /* AMD */
+ ||(type >= 0x83 && type <= 0x85)) /* AMD */
+ sig = 2;
+ else if (type == 0x01 || type == 0x02) {
+ /*
+ * Some X86-class CPU have family "Other" or "Unknown". In this case,
+ * we use the version string to determine if they are known to
+ * support the CPUID instruction.
+ */
+ if (strncmp(version, "Pentium III MMX", 15) == 0)
+ sig = 1;
+ else if (strncmp(version, "AMD Athlon(TM)", 14) == 0
+ || strncmp(version, "AMD Opteron(tm)", 15) == 0)
+ sig = 2;
+ else
+ return;
+ } else /* not X86-class */
+ return;
+
+ eax = DWORD(p);
+ edx = DWORD(p + 4);
+ switch (sig) {
+ case 1: /* Intel */
+ dmi->processor.signature.type = ((eax >> 12) & 0x3);
+ dmi->processor.signature.family =
+ (((eax >> 16) & 0xFF0) + ((eax >> 8) & 0x00F));
+ dmi->processor.signature.model =
+ (((eax >> 12) & 0xF0) + ((eax >> 4) & 0x0F));
+ dmi->processor.signature.stepping = (eax & 0xF);
+ break;
+ case 2: /* AMD */
+ dmi->processor.signature.family =
+ (((eax >> 8) & 0xF) == 0xF ? (eax >> 20) & 0xFF : (eax >> 8) & 0xF);
+ dmi->processor.signature.model =
+ (((eax >> 4) & 0xF) == 0xF ? (eax >> 16) & 0xF : (eax >> 4) & 0xF);
+ dmi->processor.signature.stepping = (eax & 0xF);
+ break;
+ }
+
+ edx = DWORD(p + 4);
+ if ((edx & 0x3FF7FDFF) != 0) {
+ int i;
+ for (i = 0; i <= 31; i++)
+ if (cpu_flags_strings[i] != NULL && edx & (1 << i))
+ ((bool *) (&dmi->processor.cpu_flags))[i] = true;
+ //printf("%s\t%s\n", prefix, flags[i]);
+ }
}
-
-void to_dmi_header(struct dmi_header *h, uint8_t *data)
+void to_dmi_header(struct dmi_header *h, uint8_t * data)
{
- h->type=data[0];
- h->length=data[1];
- h->handle=WORD(data+2);
- h->data=data;
+ h->type = data[0];
+ h->length = data[1];
+ h->handle = WORD(data + 2);
+ h->data = data;
}
const char *dmi_string(struct dmi_header *dm, uint8_t s)
{
- char *bp=(char *)dm->data;
- size_t i, len;
-
- if(s==0)
- return "Not Specified";
-
- bp+=dm->length;
- while(s>1 && *bp)
- {
- bp+=strlen(bp);
- bp++;
- s--;
- }
-
- if(!*bp)
- return bad_index;
-
- /* ASCII filtering */
- len=strlen(bp);
- for(i=0; i<len; i++)
- if(bp[i]<32 || bp[i]==127)
- bp[i]='.';
-
- return bp;
+ char *bp = (char *)dm->data;
+ size_t i, len;
+
+ if (s == 0)
+ return "Not Specified";
+
+ bp += dm->length;
+ while (s > 1 && *bp) {
+ bp += strlen(bp);
+ bp++;
+ s--;
+ }
+
+ if (!*bp)
+ return bad_index;
+
+ /* ASCII filtering */
+ len = strlen(bp);
+ for (i = 0; i < len; i++)
+ if (bp[i] < 32 || bp[i] == 127)
+ bp[i] = '.';
+
+ return bp;
}
-int dmi_checksum(uint8_t *buf)
+int dmi_checksum(uint8_t * buf)
{
- uint8_t sum=0;
- int a;
+ uint8_t sum = 0;
+ int a;
- for(a=0; a<15; a++)
- sum+=buf[a];
- return (sum==0);
+ for (a = 0; a < 15; a++)
+ sum += buf[a];
+ return (sum == 0);
}
-int dmi_iterate(s_dmi *dmi) {
- uint8_t buf[16];
- char *p,*q;
-
- /* Cleaning structures */
- memset(&dmi->base_board,0,sizeof (s_base_board));
- memset(&dmi->battery,0,sizeof (s_battery));
- memset(&dmi->bios,0,sizeof (s_bios));
- memset(&dmi->chassis,0,sizeof (s_chassis));
- for (int i=0;i<MAX_DMI_MEMORY_ITEMS;i++)
- memset(&dmi->memory[i],0,sizeof (s_memory));
- memset(&dmi->processor,0,sizeof (s_processor));
- memset(&dmi->system,0,sizeof (s_system));
-
- /* Until we found this elements in the dmitable, we consider them as not filled */
- dmi->base_board.filled=false;
- dmi->battery.filled=false;
- dmi->bios.filled=false;
- dmi->chassis.filled=false;
- for (int i=0;i<MAX_DMI_MEMORY_ITEMS;i++)
- dmi->memory[i].filled=false;
- dmi->processor.filled=false;
- dmi->system.filled=false;
-
- p=(char *)0xF0000; /* The start address to look at the dmi table */
- for (q = p; q < p + 0x10000; q += 16) {
- memcpy(buf, q, 15);
- if(memcmp(buf, "_DMI_", 5)==0 && dmi_checksum(buf)) {
- dmi->dmitable.num = buf[13]<<8|buf[12];
- dmi->dmitable.len = buf[7]<<8|buf[6];
- dmi->dmitable.base = buf[11]<<24|buf[10]<<16|buf[9]<<8|buf[8];
- dmi->dmitable.ver = (buf[0x06]<<8)+buf[0x07];
-
- /*
- * DMI version 0.0 means that the real version is taken from
- * the SMBIOS version, which we don't know at this point.
- */
- if(buf[14]!=0) {
- dmi->dmitable.major_version=buf[14]>>4;
- dmi->dmitable.minor_version=buf[14]&0x0F;
- }
- else {
- dmi->dmitable.major_version=0;
- dmi->dmitable.minor_version=0;
-
- }
+int dmi_iterate(s_dmi * dmi)
+{
+ uint8_t buf[16];
+ char *p, *q;
+
+ /* Cleaning structures */
+ memset(&dmi->base_board, 0, sizeof(s_base_board));
+ memset(&dmi->battery, 0, sizeof(s_battery));
+ memset(&dmi->bios, 0, sizeof(s_bios));
+ memset(&dmi->chassis, 0, sizeof(s_chassis));
+ for (int i = 0; i < MAX_DMI_MEMORY_ITEMS; i++)
+ memset(&dmi->memory[i], 0, sizeof(s_memory));
+ memset(&dmi->processor, 0, sizeof(s_processor));
+ memset(&dmi->system, 0, sizeof(s_system));
+
+ /* Until we found this elements in the dmitable, we consider them as not filled */
+ dmi->base_board.filled = false;
+ dmi->battery.filled = false;
+ dmi->bios.filled = false;
+ dmi->chassis.filled = false;
+ for (int i = 0; i < MAX_DMI_MEMORY_ITEMS; i++)
+ dmi->memory[i].filled = false;
+ dmi->processor.filled = false;
+ dmi->system.filled = false;
+
+ p = (char *)0xF0000; /* The start address to look at the dmi table */
+ for (q = p; q < p + 0x10000; q += 16) {
+ memcpy(buf, q, 15);
+ if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf)) {
+ dmi->dmitable.num = buf[13] << 8 | buf[12];
+ dmi->dmitable.len = buf[7] << 8 | buf[6];
+ dmi->dmitable.base =
+ buf[11] << 24 | buf[10] << 16 | buf[9] << 8 | buf[8];
+ dmi->dmitable.ver = (buf[0x06] << 8) + buf[0x07];
+
+ /*
+ * DMI version 0.0 means that the real version is taken from
+ * the SMBIOS version, which we don't know at this point.
+ */
+ if (buf[14] != 0) {
+ dmi->dmitable.major_version = buf[14] >> 4;
+ dmi->dmitable.minor_version = buf[14] & 0x0F;
+ } else {
+ dmi->dmitable.major_version = 0;
+ dmi->dmitable.minor_version = 0;
+
+ }
/* printf("DMI present (version %d.%d)\n", dmitable.major_version,dmitable.minor_version);
printf("%d structures occupying %d bytes.\n",dmitable.num, dmitable.len);
printf("DMI table at 0x%08X.\n",dmitable.base);*/
- return DMI_TABLE_PRESENT;
- }
- }
- dmi->dmitable.base=0;
- dmi->dmitable.num=0;
- dmi->dmitable.ver=0;
- dmi->dmitable.len=0;
- return -ENODMITABLE;
+ return DMI_TABLE_PRESENT;
+ }
+ }
+ dmi->dmitable.base = 0;
+ dmi->dmitable.num = 0;
+ dmi->dmitable.ver = 0;
+ dmi->dmitable.len = 0;
+ return -ENODMITABLE;
}
-void dmi_decode(struct dmi_header *h, uint16_t ver, s_dmi *dmi)
+void dmi_decode(struct dmi_header *h, uint16_t ver, s_dmi * dmi)
{
- uint8_t *data=h->data;
-
- /*
- * Note: DMI types 37, 38 and 39 are untested
- */
- switch(h->type)
- {
- case 0: /* 3.3.1 BIOS Information */
+ uint8_t *data = h->data;
+
+ /*
+ * Note: DMI types 37, 38 and 39 are untested
+ */
+ switch (h->type) {
+ case 0: /* 3.3.1 BIOS Information */
// printf("BIOS Information\n");
- if(h->length<0x12) break;
- dmi->bios.filled=true;
- strcpy(dmi->bios.vendor,dmi_string(h,data[0x04]));
- strcpy(dmi->bios.version,dmi_string(h,data[0x05]));
- strcpy(dmi->bios.release_date,dmi_string(h,data[0x08]));
- dmi->bios.address=WORD(data+0x06);
- dmi_bios_runtime_size((0x10000-WORD(data+0x06))<<4,dmi);
- dmi->bios.rom_size=(data[0x09]+1)<<6;
- strcpy(dmi->bios.rom_size_unit,"kB");
- dmi_bios_characteristics(QWORD(data+0x0A),dmi);
-
- if(h->length<0x13) break;
- dmi_bios_characteristics_x1(data[0x12], dmi);
- if(h->length<0x14) break;
- dmi_bios_characteristics_x2(data[0x13], dmi);
- if(h->length<0x18) break;
- if(data[0x14]!=0xFF && data[0x15]!=0xFF)
- sprintf(dmi->bios.bios_revision,"%u.%u",
- data[0x14], data[0x15]);
- if(data[0x16]!=0xFF && data[0x17]!=0xFF)
- sprintf(dmi->bios.firmware_revision,"%u.%u",
- data[0x16], data[0x17]);
- break;
- case 1: /* 3.3.2 System Information */
+ if (h->length < 0x12)
+ break;
+ dmi->bios.filled = true;
+ strcpy(dmi->bios.vendor, dmi_string(h, data[0x04]));
+ strcpy(dmi->bios.version, dmi_string(h, data[0x05]));
+ strcpy(dmi->bios.release_date, dmi_string(h, data[0x08]));
+ dmi->bios.address = WORD(data + 0x06);
+ dmi_bios_runtime_size((0x10000 - WORD(data + 0x06)) << 4, dmi);
+ dmi->bios.rom_size = (data[0x09] + 1) << 6;
+ strcpy(dmi->bios.rom_size_unit, "kB");
+ dmi_bios_characteristics(QWORD(data + 0x0A), dmi);
+
+ if (h->length < 0x13)
+ break;
+ dmi_bios_characteristics_x1(data[0x12], dmi);
+ if (h->length < 0x14)
+ break;
+ dmi_bios_characteristics_x2(data[0x13], dmi);
+ if (h->length < 0x18)
+ break;
+ if (data[0x14] != 0xFF && data[0x15] != 0xFF)
+ sprintf(dmi->bios.bios_revision, "%u.%u", data[0x14], data[0x15]);
+ if (data[0x16] != 0xFF && data[0x17] != 0xFF)
+ sprintf(dmi->bios.firmware_revision, "%u.%u",
+ data[0x16], data[0x17]);
+ break;
+ case 1: /* 3.3.2 System Information */
// printf("System Information\n");
- if(h->length<0x08) break;
- dmi->system.filled=true;
- strcpy(dmi->system.manufacturer,dmi_string(h,data[0x04]));
- strcpy(dmi->system.product_name,dmi_string(h,data[0x05]));
- strcpy(dmi->system.version,dmi_string(h,data[0x06]));
- strcpy(dmi->system.serial,dmi_string(h,data[0x07]));
- if(h->length<0x19) break;
- dmi_system_uuid(data+0x08,dmi);
- dmi_system_wake_up_type(data[0x18],dmi);
- if(h->length<0x1B) break;
- strcpy(dmi->system.sku_number,dmi_string(h,data[0x19]));
- strcpy(dmi->system.family,dmi_string(h,data[0x1A]));
- break;
-
- case 2: /* 3.3.3 Base Board Information */
+ if (h->length < 0x08)
+ break;
+ dmi->system.filled = true;
+ strcpy(dmi->system.manufacturer, dmi_string(h, data[0x04]));
+ strcpy(dmi->system.product_name, dmi_string(h, data[0x05]));
+ strcpy(dmi->system.version, dmi_string(h, data[0x06]));
+ strcpy(dmi->system.serial, dmi_string(h, data[0x07]));
+ if (h->length < 0x19)
+ break;
+ dmi_system_uuid(data + 0x08, dmi);
+ dmi_system_wake_up_type(data[0x18], dmi);
+ if (h->length < 0x1B)
+ break;
+ strcpy(dmi->system.sku_number, dmi_string(h, data[0x19]));
+ strcpy(dmi->system.family, dmi_string(h, data[0x1A]));
+ break;
+
+ case 2: /* 3.3.3 Base Board Information */
// printf("Base Board Information\n");
- if(h->length<0x08) break;
- dmi->base_board.filled=true;
- strcpy(dmi->base_board.manufacturer,dmi_string(h,data[0x04]));
- strcpy(dmi->base_board.product_name,dmi_string(h,data[0x05]));
- strcpy(dmi->base_board.version,dmi_string(h,data[0x06]));
- strcpy(dmi->base_board.serial,dmi_string(h,data[0x07]));
- if(h->length<0x0F) break;
- strcpy(dmi->base_board.asset_tag,dmi_string(h,data[0x08]));
- dmi_base_board_features(data[0x09], dmi);
- strcpy(dmi->base_board.location,dmi_string(h,data[0x0A]));
- strcpy(dmi->base_board.type,dmi_string(h,data[0x0D]));
- if(h->length<0x0F+data[0x0E]*sizeof(uint16_t)) break;
- break;
- case 3: /* 3.3.4 Chassis Information */
+ if (h->length < 0x08)
+ break;
+ dmi->base_board.filled = true;
+ strcpy(dmi->base_board.manufacturer, dmi_string(h, data[0x04]));
+ strcpy(dmi->base_board.product_name, dmi_string(h, data[0x05]));
+ strcpy(dmi->base_board.version, dmi_string(h, data[0x06]));
+ strcpy(dmi->base_board.serial, dmi_string(h, data[0x07]));
+ if (h->length < 0x0F)
+ break;
+ strcpy(dmi->base_board.asset_tag, dmi_string(h, data[0x08]));
+ dmi_base_board_features(data[0x09], dmi);
+ strcpy(dmi->base_board.location, dmi_string(h, data[0x0A]));
+ strcpy(dmi->base_board.type, dmi_string(h, data[0x0D]));
+ if (h->length < 0x0F + data[0x0E] * sizeof(uint16_t))
+ break;
+ break;
+ case 3: /* 3.3.4 Chassis Information */
// printf("Chassis Information\n");
- if(h->length<0x09) break;
- dmi->chassis.filled=true;
- strcpy(dmi->chassis.manufacturer,dmi_string(h,data[0x04]));
- strcpy(dmi->chassis.type,dmi_chassis_type(data[0x05]&0x7F));
- strcpy(dmi->chassis.lock,dmi_chassis_lock(data[0x05]>>7));
- strcpy(dmi->chassis.version,dmi_string(h,data[0x06]));
- strcpy(dmi->chassis.serial,dmi_string(h,data[0x07]));
- strcpy(dmi->chassis.asset_tag,dmi_string(h,data[0x08]));
- if(h->length<0x0D) break;
- strcpy(dmi->chassis.boot_up_state,dmi_chassis_state(data[0x09]));
- strcpy(dmi->chassis.power_supply_state,dmi_chassis_state(data[0x0A]));
- strcpy(dmi->chassis.thermal_state,dmi_chassis_state(data[0x0B]));
- strcpy(dmi->chassis.security_status,dmi_chassis_security_status(data[0x0C]));
- if(h->length<0x11) break;
- sprintf(dmi->chassis.oem_information,"0x%08X\n",DWORD(data+0x0D));
- if(h->length<0x15) break;
- dmi->chassis.height=data[0x11];
- dmi->chassis.nb_power_cords=data[0x12];
- break;
-
- case 4: /* 3.3.5 Processor Information */
+ if (h->length < 0x09)
+ break;
+ dmi->chassis.filled = true;
+ strcpy(dmi->chassis.manufacturer, dmi_string(h, data[0x04]));
+ strcpy(dmi->chassis.type, dmi_chassis_type(data[0x05] & 0x7F));
+ strcpy(dmi->chassis.lock, dmi_chassis_lock(data[0x05] >> 7));
+ strcpy(dmi->chassis.version, dmi_string(h, data[0x06]));
+ strcpy(dmi->chassis.serial, dmi_string(h, data[0x07]));
+ strcpy(dmi->chassis.asset_tag, dmi_string(h, data[0x08]));
+ if (h->length < 0x0D)
+ break;
+ strcpy(dmi->chassis.boot_up_state, dmi_chassis_state(data[0x09]));
+ strcpy(dmi->chassis.power_supply_state, dmi_chassis_state(data[0x0A]));
+ strcpy(dmi->chassis.thermal_state, dmi_chassis_state(data[0x0B]));
+ strcpy(dmi->chassis.security_status,
+ dmi_chassis_security_status(data[0x0C]));
+ if (h->length < 0x11)
+ break;
+ sprintf(dmi->chassis.oem_information, "0x%08X\n", DWORD(data + 0x0D));
+ if (h->length < 0x15)
+ break;
+ dmi->chassis.height = data[0x11];
+ dmi->chassis.nb_power_cords = data[0x12];
+ break;
+
+ case 4: /* 3.3.5 Processor Information */
// printf("Processor Information\n");
- if(h->length<0x1A) break;
- dmi->processor.filled=true;
- strcpy(dmi->processor.socket_designation,dmi_string(h, data[0x04]));
- strcpy(dmi->processor.type,dmi_processor_type(data[0x05]));
- strcpy(dmi->processor.manufacturer,dmi_string(h, data[0x07]));
- strcpy(dmi->processor.family,dmi_processor_family(data[0x06],dmi->processor.manufacturer));
- dmi_processor_id(data[0x06], data+8, dmi_string(h, data[0x10]), dmi);
- strcpy(dmi->processor.version,dmi_string(h, data[0x10]));
- dmi_processor_voltage(data[0x11],dmi);
- dmi->processor.external_clock=WORD(data+0x12);
- dmi->processor.max_speed=WORD(data+0x14);
- dmi->processor.current_speed=WORD(data+0x16);
- if(data[0x18]&(1<<6))
- strcpy(dmi->processor.status,dmi_processor_status(data[0x18]&0x07));
- else
- sprintf(dmi->processor.status,"Unpopulated");
- sprintf(dmi->processor.upgrade,dmi_processor_upgrade(data[0x19]));
- if(h->length<0x20) break;
- dmi_processor_cache(WORD(data+0x1A), "L1", ver,dmi->processor.cache1);
- dmi_processor_cache(WORD(data+0x1C), "L2", ver,dmi->processor.cache2);
- dmi_processor_cache(WORD(data+0x1E), "L3", ver,dmi->processor.cache3);
- if(h->length<0x23) break;
- strcpy(dmi->processor.serial,dmi_string(h, data[0x20]));
- strcpy(dmi->processor.asset_tag,dmi_string(h, data[0x21]));
- strcpy(dmi->processor.part_number,dmi_string(h, data[0x22]));
- break;
- case 17: /* 3.3.18 Memory Device */
- if (h->length < 0x15) break;
- dmi->memory_count++;
- s_memory *mem = &dmi->memory[dmi->memory_count-1];
- dmi->memory[dmi->memory_count-1].filled=true;
- dmi_memory_array_error_handle(WORD(data + 0x06),mem->error);
- dmi_memory_device_width(WORD(data + 0x08),mem->total_width);
- dmi_memory_device_width(WORD(data + 0x0A),mem->data_width);
- dmi_memory_device_size(WORD(data + 0x0C),mem->size);
- strcpy(mem->form_factor,dmi_memory_device_form_factor(data[0x0E]));
- dmi_memory_device_set(data[0x0F],mem->device_set);
- strcpy(mem->device_locator,dmi_string(h, data[0x10]));
- strcpy(mem->bank_locator,dmi_string(h, data[0x11]));
- strcpy(mem->type,dmi_memory_device_type(data[0x12]));
- dmi_memory_device_type_detail(WORD(data + 0x13),mem->type_detail);
- if (h->length < 0x17) break;
- dmi_memory_device_speed(WORD(data + 0x15),mem->speed);
- if (h->length < 0x1B) break;
- strcpy(mem->manufacturer, dmi_string(h, data[0x17]));
- strcpy(mem->serial,dmi_string(h, data[0x18]));
- strcpy(mem->asset_tag,dmi_string(h, data[0x19]));
- strcpy(mem->part_number,dmi_string(h, data[0x1A]));
- break;
- case 22: /* 3.3.23 Portable Battery */
- if (h->length < 0x10) break;
- dmi->battery.filled=true;
- strcpy(dmi->battery.location,dmi_string(h, data[0x04]));
- strcpy(dmi->battery.manufacturer,dmi_string(h, data[0x05]));
-
- if (data[0x06] || h->length < 0x1A)
- strcpy(dmi->battery.manufacture_date, dmi_string(h, data[0x06]));
-
- if (data[0x07] || h->length < 0x1A)
- strcpy(dmi->battery.serial, dmi_string(h, data[0x07]));
-
- strcpy(dmi->battery.name,dmi_string(h, data[0x08]));
-
- if (data[0x09] != 0x02 || h->length < 0x1A)
- strcpy(dmi->battery.chemistry,dmi_battery_chemistry(data[0x09]));
-
- if (h->length < 0x1A)
- dmi_battery_capacity(WORD(data + 0x0A), 1,dmi->battery.design_capacity);
- else
- dmi_battery_capacity(WORD(data + 0x0A), data[0x15],dmi->battery.design_capacity);
- dmi_battery_voltage(WORD(data + 0x0C),dmi->battery.design_voltage);
- strcpy(dmi->battery.sbds,dmi_string(h, data[0x0E]));
- dmi_battery_maximum_error(data[0x0F],dmi->battery.maximum_error);
- if (h->length < 0x1A) break;
- if (data[0x07] == 0)
- sprintf(dmi->battery.sbds_serial,"%04X", WORD(data + 0x10));
-
- if (data[0x06] == 0)
- sprintf(dmi->battery.sbds_manufacture_date,"%u-%02u-%02u",
- 1980 + (WORD(data + 0x12) >> 9),
- (WORD(data + 0x12) >> 5) & 0x0F,
- WORD(data + 0x12) & 0x1F);
- if (data[0x09] == 0x02)
- strcpy(dmi->battery.sbds_chemistry, dmi_string(h, data[0x14]));
-
- // sprintf(dmi->battery.oem_info,"0x%08X",DWORD(h, data+0x16));
- break;
- case 38: /* 3.3.39 IPMI Device Information */
- if (h->length < 0x10) break;
- dmi->ipmi.filled=true;
- snprintf(dmi->ipmi.interface_type,sizeof(dmi->ipmi.interface_type),
- "%s", dmi_ipmi_interface_type(data[0x04]));
- dmi->ipmi.major_specification_version=data[0x05] >> 4;
- dmi->ipmi.minor_specification_version=data[0x05] & 0x0F;
- dmi->ipmi.I2C_slave_address=data[0x06] >> 1;
- if (data[0x07] != 0xFF)
- dmi->ipmi.nv_address=data[0x07];
- else
- dmi->ipmi.nv_address=0; /* Not Present */
- dmi_ipmi_base_address(data[0x04], data + 0x08,
- &dmi->ipmi);
- if (h->length < 0x12) break;
- if (data[0x11] != 0x00)
- {
- dmi->ipmi.irq=data[0x11];
- }
- break;
- }
+ if (h->length < 0x1A)
+ break;
+ dmi->processor.filled = true;
+ strcpy(dmi->processor.socket_designation, dmi_string(h, data[0x04]));
+ strcpy(dmi->processor.type, dmi_processor_type(data[0x05]));
+ strcpy(dmi->processor.manufacturer, dmi_string(h, data[0x07]));
+ strcpy(dmi->processor.family,
+ dmi_processor_family(data[0x06], dmi->processor.manufacturer));
+ dmi_processor_id(data[0x06], data + 8, dmi_string(h, data[0x10]), dmi);
+ strcpy(dmi->processor.version, dmi_string(h, data[0x10]));
+ dmi_processor_voltage(data[0x11], dmi);
+ dmi->processor.external_clock = WORD(data + 0x12);
+ dmi->processor.max_speed = WORD(data + 0x14);
+ dmi->processor.current_speed = WORD(data + 0x16);
+ if (data[0x18] & (1 << 6))
+ strcpy(dmi->processor.status,
+ dmi_processor_status(data[0x18] & 0x07));
+ else
+ sprintf(dmi->processor.status, "Unpopulated");
+ sprintf(dmi->processor.upgrade, dmi_processor_upgrade(data[0x19]));
+ if (h->length < 0x20)
+ break;
+ dmi_processor_cache(WORD(data + 0x1A), "L1", ver,
+ dmi->processor.cache1);
+ dmi_processor_cache(WORD(data + 0x1C), "L2", ver,
+ dmi->processor.cache2);
+ dmi_processor_cache(WORD(data + 0x1E), "L3", ver,
+ dmi->processor.cache3);
+ if (h->length < 0x23)
+ break;
+ strcpy(dmi->processor.serial, dmi_string(h, data[0x20]));
+ strcpy(dmi->processor.asset_tag, dmi_string(h, data[0x21]));
+ strcpy(dmi->processor.part_number, dmi_string(h, data[0x22]));
+ break;
+ case 17: /* 3.3.18 Memory Device */
+ if (h->length < 0x15)
+ break;
+ dmi->memory_count++;
+ s_memory *mem = &dmi->memory[dmi->memory_count - 1];
+ dmi->memory[dmi->memory_count - 1].filled = true;
+ dmi_memory_array_error_handle(WORD(data + 0x06), mem->error);
+ dmi_memory_device_width(WORD(data + 0x08), mem->total_width);
+ dmi_memory_device_width(WORD(data + 0x0A), mem->data_width);
+ dmi_memory_device_size(WORD(data + 0x0C), mem->size);
+ strcpy(mem->form_factor, dmi_memory_device_form_factor(data[0x0E]));
+ dmi_memory_device_set(data[0x0F], mem->device_set);
+ strcpy(mem->device_locator, dmi_string(h, data[0x10]));
+ strcpy(mem->bank_locator, dmi_string(h, data[0x11]));
+ strcpy(mem->type, dmi_memory_device_type(data[0x12]));
+ dmi_memory_device_type_detail(WORD(data + 0x13), mem->type_detail);
+ if (h->length < 0x17)
+ break;
+ dmi_memory_device_speed(WORD(data + 0x15), mem->speed);
+ if (h->length < 0x1B)
+ break;
+ strcpy(mem->manufacturer, dmi_string(h, data[0x17]));
+ strcpy(mem->serial, dmi_string(h, data[0x18]));
+ strcpy(mem->asset_tag, dmi_string(h, data[0x19]));
+ strcpy(mem->part_number, dmi_string(h, data[0x1A]));
+ break;
+ case 22: /* 3.3.23 Portable Battery */
+ if (h->length < 0x10)
+ break;
+ dmi->battery.filled = true;
+ strcpy(dmi->battery.location, dmi_string(h, data[0x04]));
+ strcpy(dmi->battery.manufacturer, dmi_string(h, data[0x05]));
+
+ if (data[0x06] || h->length < 0x1A)
+ strcpy(dmi->battery.manufacture_date, dmi_string(h, data[0x06]));
+
+ if (data[0x07] || h->length < 0x1A)
+ strcpy(dmi->battery.serial, dmi_string(h, data[0x07]));
+
+ strcpy(dmi->battery.name, dmi_string(h, data[0x08]));
+
+ if (data[0x09] != 0x02 || h->length < 0x1A)
+ strcpy(dmi->battery.chemistry, dmi_battery_chemistry(data[0x09]));
+
+ if (h->length < 0x1A)
+ dmi_battery_capacity(WORD(data + 0x0A), 1,
+ dmi->battery.design_capacity);
+ else
+ dmi_battery_capacity(WORD(data + 0x0A), data[0x15],
+ dmi->battery.design_capacity);
+ dmi_battery_voltage(WORD(data + 0x0C), dmi->battery.design_voltage);
+ strcpy(dmi->battery.sbds, dmi_string(h, data[0x0E]));
+ dmi_battery_maximum_error(data[0x0F], dmi->battery.maximum_error);
+ if (h->length < 0x1A)
+ break;
+ if (data[0x07] == 0)
+ sprintf(dmi->battery.sbds_serial, "%04X", WORD(data + 0x10));
+
+ if (data[0x06] == 0)
+ sprintf(dmi->battery.sbds_manufacture_date, "%u-%02u-%02u",
+ 1980 + (WORD(data + 0x12) >> 9),
+ (WORD(data + 0x12) >> 5) & 0x0F, WORD(data + 0x12) & 0x1F);
+ if (data[0x09] == 0x02)
+ strcpy(dmi->battery.sbds_chemistry, dmi_string(h, data[0x14]));
+
+ // sprintf(dmi->battery.oem_info,"0x%08X",DWORD(h, data+0x16));
+ break;
+ case 38: /* 3.3.39 IPMI Device Information */
+ if (h->length < 0x10)
+ break;
+ dmi->ipmi.filled = true;
+ snprintf(dmi->ipmi.interface_type, sizeof(dmi->ipmi.interface_type),
+ "%s", dmi_ipmi_interface_type(data[0x04]));
+ dmi->ipmi.major_specification_version = data[0x05] >> 4;
+ dmi->ipmi.minor_specification_version = data[0x05] & 0x0F;
+ dmi->ipmi.I2C_slave_address = data[0x06] >> 1;
+ if (data[0x07] != 0xFF)
+ dmi->ipmi.nv_address = data[0x07];
+ else
+ dmi->ipmi.nv_address = 0; /* Not Present */
+ dmi_ipmi_base_address(data[0x04], data + 0x08, &dmi->ipmi);
+ if (h->length < 0x12)
+ break;
+ if (data[0x11] != 0x00) {
+ dmi->ipmi.irq = data[0x11];
+ }
+ break;
+ }
}
-void parse_dmitable(s_dmi *dmi) {
- int i=0;
- uint8_t *data = NULL;
- uint8_t buf[dmi->dmitable.len];
-
- memcpy(buf,(int *)dmi->dmitable.base,sizeof(uint8_t) * dmi->dmitable.len);
- data=buf;
- dmi->memory_count=0;
- while(i<dmi->dmitable.num && data+4<=buf+dmi->dmitable.len) /* 4 is the length of an SMBIOS structure header */ {
- uint8_t *next;
- struct dmi_header h;
- to_dmi_header(&h, data);
-
- /*
- * If a short entry is found (less than 4 bytes), not only it
- * is invalid, but we cannot reliably locate the next entry.
- * Better stop at this point, and let the user know his/her
- * table is broken.
- */
- if(h.length<4)
- {
- printf("Invalid entry length (%u). DMI table is broken! Stop.\n\n", (unsigned int)h.length);
- break;
- }
-
+void parse_dmitable(s_dmi * dmi)
+{
+ int i = 0;
+ uint8_t *data = NULL;
+ uint8_t buf[dmi->dmitable.len];
+
+ memcpy(buf, (int *)dmi->dmitable.base, sizeof(uint8_t) * dmi->dmitable.len);
+ data = buf;
+ dmi->memory_count = 0;
+ while (i < dmi->dmitable.num && data + 4 <= buf + dmi->dmitable.len) { /* 4 is the length of an SMBIOS structure header */
+ uint8_t *next;
+ struct dmi_header h;
+ to_dmi_header(&h, data);
+
+ /*
+ * If a short entry is found (less than 4 bytes), not only it
+ * is invalid, but we cannot reliably locate the next entry.
+ * Better stop at this point, and let the user know his/her
+ * table is broken.
+ */
+ if (h.length < 4) {
+ printf("Invalid entry length (%u). DMI table is broken! Stop.\n\n",
+ (unsigned int)h.length);
+ break;
+ }
// printf("Handle 0x%04X, DMI type %d, %d bytes\n", h.handle, h.type, h.length);
- /* loo for the next handle */
- next=data+h.length;
- while(next-buf+1<dmi->dmitable.len && (next[0]!=0 || next[1]!=0))
- next++;
- next+=2;
- if(next-buf<=dmi->dmitable.len)
- {
- dmi_decode(&h, dmi->dmitable.ver,dmi);
- }
- data=next;
- i++;
- }
+ /* loo for the next handle */
+ next = data + h.length;
+ while (next - buf + 1 < dmi->dmitable.len
+ && (next[0] != 0 || next[1] != 0))
+ next++;
+ next += 2;
+ if (next - buf <= dmi->dmitable.len) {
+ dmi_decode(&h, dmi->dmitable.ver, dmi);
+ }
+ data = next;
+ i++;
+ }
}
diff --git a/com32/gpllib/dmi/dmi_base_board.c b/com32/gpllib/dmi/dmi_base_board.c
index 2f19fda4..07253218 100644
--- a/com32/gpllib/dmi/dmi_base_board.c
+++ b/com32/gpllib/dmi/dmi_base_board.c
@@ -28,10 +28,10 @@
#include <dmi/dmi.h>
#include <stdio.h>
-const char *base_board_features_strings[]={
- "Board is a hosting board", /* 0 */
- "Board requires at least one daughter board",
- "Board is removable",
- "Board is replaceable",
- "Board is hot swappable" /* 4 */
+const char *base_board_features_strings[] = {
+ "Board is a hosting board", /* 0 */
+ "Board requires at least one daughter board",
+ "Board is removable",
+ "Board is replaceable",
+ "Board is hot swappable" /* 4 */
};
diff --git a/com32/gpllib/dmi/dmi_battery.c b/com32/gpllib/dmi/dmi_battery.c
index 02b5e6df..b0eab9bb 100644
--- a/com32/gpllib/dmi/dmi_battery.c
+++ b/com32/gpllib/dmi/dmi_battery.c
@@ -30,43 +30,43 @@
#include <stdio.h>
const char *dmi_battery_chemistry(uint8_t code)
{
- /* 3.3.23.1 */
- static const char *chemistry[] = {
- "Other", /* 0x01 */
- "Unknown",
- "Lead Acid",
- "Nickel Cadmium",
- "Nickel Metal Hydride",
- "Lithium Ion",
- "Zinc Air",
- "Lithium Polymer" /* 0x08 */
- };
+ /* 3.3.23.1 */
+ static const char *chemistry[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "Lead Acid",
+ "Nickel Cadmium",
+ "Nickel Metal Hydride",
+ "Lithium Ion",
+ "Zinc Air",
+ "Lithium Polymer" /* 0x08 */
+ };
- if (code >= 0x01 && code <= 0x08)
- return chemistry[code - 0x01];
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x08)
+ return chemistry[code - 0x01];
+ return out_of_spec;
}
-void dmi_battery_capacity(uint16_t code, uint8_t multiplier,char *capacity)
+void dmi_battery_capacity(uint16_t code, uint8_t multiplier, char *capacity)
{
- if (code == 0)
- sprintf(capacity,"%s","Unknown");
- else
- sprintf(capacity,"%u mWh", code * multiplier);
+ if (code == 0)
+ sprintf(capacity, "%s", "Unknown");
+ else
+ sprintf(capacity, "%u mWh", code * multiplier);
}
void dmi_battery_voltage(uint16_t code, char *voltage)
{
- if (code == 0)
- sprintf(voltage,"%s","Unknown");
- else
- sprintf(voltage,"%u mV", code);
+ if (code == 0)
+ sprintf(voltage, "%s", "Unknown");
+ else
+ sprintf(voltage, "%u mV", code);
}
void dmi_battery_maximum_error(uint8_t code, char *error)
{
- if (code == 0xFF)
- sprintf(error,"%s","Unknown");
- else
- sprintf(error,"%u%%", code);
+ if (code == 0xFF)
+ sprintf(error, "%s", "Unknown");
+ else
+ sprintf(error, "%u%%", code);
}
diff --git a/com32/gpllib/dmi/dmi_bios.c b/com32/gpllib/dmi/dmi_bios.c
index 1fea7524..4a74800e 100644
--- a/com32/gpllib/dmi/dmi_bios.c
+++ b/com32/gpllib/dmi/dmi_bios.c
@@ -29,51 +29,51 @@
#include <dmi/dmi.h>
#include <stdio.h>
-const char *bios_charac_strings[]={
- "BIOS characteristics not supported", /* 3 */
- "ISA is supported",
- "MCA is supported",
- "EISA is supported",
- "PCI is supported",
- "PC Card (PCMCIA) is supported",
- "PNP is supported",
- "APM is supported",
- "BIOS is upgradeable",
- "BIOS shadowing is allowed",
- "VLB is supported",
- "ESCD support is available",
- "Boot from CD is supported",
- "Selectable boot is supported",
- "BIOS ROM is socketed",
- "Boot from PC Card (PCMCIA) is supported",
- "EDD is supported",
- "Japanese floppy for NEC 9800 1.2 MB is supported (int 13h)",
- "Japanese floppy for Toshiba 1.2 MB is supported (int 13h)",
- "5.25\"/360 KB floppy services are supported (int 13h)",
- "5.25\"/1.2 MB floppy services are supported (int 13h)",
- "3.5\"/720 KB floppy services are supported (int 13h)",
- "3.5\"/2.88 MB floppy services are supported (int 13h)",
- "Print screen service is supported (int 5h)",
- "8042 keyboard services are supported (int 9h)",
- "Serial services are supported (int 14h)",
- "Printer services are supported (int 17h)",
- "CGA/mono video services are supported (int 10h)",
- "NEC PC-98" /* 31 */
+const char *bios_charac_strings[] = {
+ "BIOS characteristics not supported", /* 3 */
+ "ISA is supported",
+ "MCA is supported",
+ "EISA is supported",
+ "PCI is supported",
+ "PC Card (PCMCIA) is supported",
+ "PNP is supported",
+ "APM is supported",
+ "BIOS is upgradeable",
+ "BIOS shadowing is allowed",
+ "VLB is supported",
+ "ESCD support is available",
+ "Boot from CD is supported",
+ "Selectable boot is supported",
+ "BIOS ROM is socketed",
+ "Boot from PC Card (PCMCIA) is supported",
+ "EDD is supported",
+ "Japanese floppy for NEC 9800 1.2 MB is supported (int 13h)",
+ "Japanese floppy for Toshiba 1.2 MB is supported (int 13h)",
+ "5.25\"/360 KB floppy services are supported (int 13h)",
+ "5.25\"/1.2 MB floppy services are supported (int 13h)",
+ "3.5\"/720 KB floppy services are supported (int 13h)",
+ "3.5\"/2.88 MB floppy services are supported (int 13h)",
+ "Print screen service is supported (int 5h)",
+ "8042 keyboard services are supported (int 9h)",
+ "Serial services are supported (int 14h)",
+ "Printer services are supported (int 17h)",
+ "CGA/mono video services are supported (int 10h)",
+ "NEC PC-98" /* 31 */
};
-const char *bios_charac_x1_strings[]={
- "ACPI is supported", /* 0 */
- "USB legacy is supported",
- "AGP is supported",
- "I2O boot is supported",
- "LS-120 boot is supported",
- "ATAPI Zip drive boot is supported",
- "IEEE 1394 boot is supported",
- "Smart battery is supported" /* 7 */
+const char *bios_charac_x1_strings[] = {
+ "ACPI is supported", /* 0 */
+ "USB legacy is supported",
+ "AGP is supported",
+ "I2O boot is supported",
+ "LS-120 boot is supported",
+ "ATAPI Zip drive boot is supported",
+ "IEEE 1394 boot is supported",
+ "Smart battery is supported" /* 7 */
};
-const char *bios_charac_x2_strings[]={
- "BIOS boot specification is supported", /* 0 */
+const char *bios_charac_x2_strings[] = {
+ "BIOS boot specification is supported", /* 0 */
"Function key-initiated network boot is supported",
- "Targeted content distribution is supported" /* 2 */
+ "Targeted content distribution is supported" /* 2 */
};
diff --git a/com32/gpllib/dmi/dmi_chassis.c b/com32/gpllib/dmi/dmi_chassis.c
index 6150016f..84dbe909 100644
--- a/com32/gpllib/dmi/dmi_chassis.c
+++ b/com32/gpllib/dmi/dmi_chassis.c
@@ -31,79 +31,79 @@
const char *dmi_chassis_type(uint8_t code)
{
- /* 3.3.4.1 */
- static const char *type[]={
- "Other", /* 0x01 */
- "Unknown",
- "Desktop",
- "Low Profile Desktop",
- "Pizza Box",
- "Mini Tower",
- "Tower",
- "Portable",
- "Laptop",
- "Notebook",
- "Hand Held",
- "Docking Station",
- "All In One",
- "Sub Notebook",
- "Space-saving",
- "Lunch Box",
- "Main Server Chassis", /* master.mif says System */
- "Expansion Chassis",
- "Sub Chassis",
- "Bus Expansion Chassis",
- "Peripheral Chassis",
- "RAID Chassis",
- "Rack Mount Chassis",
- "Sealed-case PC",
- "Multi-system" /* 0x19 */
- };
+ /* 3.3.4.1 */
+ static const char *type[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "Desktop",
+ "Low Profile Desktop",
+ "Pizza Box",
+ "Mini Tower",
+ "Tower",
+ "Portable",
+ "Laptop",
+ "Notebook",
+ "Hand Held",
+ "Docking Station",
+ "All In One",
+ "Sub Notebook",
+ "Space-saving",
+ "Lunch Box",
+ "Main Server Chassis", /* master.mif says System */
+ "Expansion Chassis",
+ "Sub Chassis",
+ "Bus Expansion Chassis",
+ "Peripheral Chassis",
+ "RAID Chassis",
+ "Rack Mount Chassis",
+ "Sealed-case PC",
+ "Multi-system" /* 0x19 */
+ };
- if(code>=0x01 && code<=0x19)
- return type[code-0x01];
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x19)
+ return type[code - 0x01];
+ return out_of_spec;
}
const char *dmi_chassis_lock(uint8_t code)
{
- static const char *lock[]={
- "Not Present", /* 0x00 */
- "Present" /* 0x01 */
- };
+ static const char *lock[] = {
+ "Not Present", /* 0x00 */
+ "Present" /* 0x01 */
+ };
- return lock[code];
+ return lock[code];
}
const char *dmi_chassis_state(uint8_t code)
{
- /* 3.3.4.2 */
- static const char *state[]={
- "Other", /* 0x01 */
- "Unknown",
- "Safe", /* master.mif says OK */
- "Warning",
- "Critical",
- "Non-recoverable" /* 0x06 */
- };
+ /* 3.3.4.2 */
+ static const char *state[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "Safe", /* master.mif says OK */
+ "Warning",
+ "Critical",
+ "Non-recoverable" /* 0x06 */
+ };
- if(code>=0x01 && code<=0x06)
- return(state[code-0x01]);
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x06)
+ return (state[code - 0x01]);
+ return out_of_spec;
}
const char *dmi_chassis_security_status(uint8_t code)
{
- /* 3.3.4.3 */
- static const char *status[]={
- "Other", /* 0x01 */
- "Unknown",
- "None",
- "External Interface Locked Out",
- "External Interface Enabled" /* 0x05 */
- };
+ /* 3.3.4.3 */
+ static const char *status[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "None",
+ "External Interface Locked Out",
+ "External Interface Enabled" /* 0x05 */
+ };
- if(code>=0x01 && code<=0x05)
- return(status[code-0x01]);
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x05)
+ return (status[code - 0x01]);
+ return out_of_spec;
}
diff --git a/com32/gpllib/dmi/dmi_ipmi.c b/com32/gpllib/dmi/dmi_ipmi.c
index 8081375c..68a472ed 100644
--- a/com32/gpllib/dmi/dmi_ipmi.c
+++ b/com32/gpllib/dmi/dmi_ipmi.c
@@ -31,28 +31,25 @@
const char *dmi_ipmi_interface_type(uint8_t code)
{
- /* 3.3.39.1 and IPMI 2.0, appendix C1, table C1-2 */
- static const char *type[] = {
- "Unknown", /* 0x00 */
- "KCS (Keyboard Control Style)",
- "SMIC (Server Management Interface Chip)",
- "BT (Block Transfer)",
- "SSIF (SMBus System Interface)" /* 0x04 */
- };
+ /* 3.3.39.1 and IPMI 2.0, appendix C1, table C1-2 */
+ static const char *type[] = {
+ "Unknown", /* 0x00 */
+ "KCS (Keyboard Control Style)",
+ "SMIC (Server Management Interface Chip)",
+ "BT (Block Transfer)",
+ "SSIF (SMBus System Interface)" /* 0x04 */
+ };
- if (code <= 0x04)
- return type[code];
- return out_of_spec;
+ if (code <= 0x04)
+ return type[code];
+ return out_of_spec;
}
-void dmi_ipmi_base_address(uint8_t type, const uint8_t *p, s_ipmi *ipmi)
+void dmi_ipmi_base_address(uint8_t type, const uint8_t * p, s_ipmi * ipmi)
{
- if (type == 0x04) /* SSIF */
- {
- ipmi->base_address= (*p) >> 1;
- }
- else
- {
- ipmi->base_address = QWORD(p);
- }
+ if (type == 0x04) { /* SSIF */
+ ipmi->base_address = (*p) >> 1;
+ } else {
+ ipmi->base_address = QWORD(p);
+ }
}
diff --git a/com32/gpllib/dmi/dmi_memory.c b/com32/gpllib/dmi/dmi_memory.c
index 9067009a..b04dabbe 100644
--- a/com32/gpllib/dmi/dmi_memory.c
+++ b/com32/gpllib/dmi/dmi_memory.c
@@ -29,143 +29,142 @@
#include <dmi/dmi.h>
#include <stdio.h>
-void dmi_memory_array_error_handle(uint16_t code,char *array)
+void dmi_memory_array_error_handle(uint16_t code, char *array)
{
- if (code == 0xFFFE)
- sprintf(array,"%s","Not Provided");
- else if (code == 0xFFFF)
- sprintf(array,"%s","No Error");
- else
- sprintf(array,"0x%04X", code);
+ if (code == 0xFFFE)
+ sprintf(array, "%s", "Not Provided");
+ else if (code == 0xFFFF)
+ sprintf(array, "%s", "No Error");
+ else
+ sprintf(array, "0x%04X", code);
}
void dmi_memory_device_width(uint16_t code, char *width)
{
- /*
- * 3.3.18 Memory Device (Type 17)
- * If no memory module is present, width may be 0
- */
- if (code == 0xFFFF || code == 0)
- sprintf(width,"%s","Unknown");
- else
- sprintf(width,"%u bits", code);
+ /*
+ * 3.3.18 Memory Device (Type 17)
+ * If no memory module is present, width may be 0
+ */
+ if (code == 0xFFFF || code == 0)
+ sprintf(width, "%s", "Unknown");
+ else
+ sprintf(width, "%u bits", code);
}
void dmi_memory_device_size(uint16_t code, char *size)
{
- if (code == 0)
- sprintf(size,"%s","Free");
- else if (code == 0xFFFF)
- sprintf(size,"%s","Unknown");
- else {
- if (code & 0x8000)
- sprintf(size, "%u kB", code & 0x7FFF);
- else
- sprintf(size,"%u MB", code);
- }
+ if (code == 0)
+ sprintf(size, "%s", "Free");
+ else if (code == 0xFFFF)
+ sprintf(size, "%s", "Unknown");
+ else {
+ if (code & 0x8000)
+ sprintf(size, "%u kB", code & 0x7FFF);
+ else
+ sprintf(size, "%u MB", code);
+ }
}
const char *dmi_memory_device_form_factor(uint8_t code)
{
- /* 3.3.18.1 */
- static const char *form_factor[] = {
- "Other", /* 0x01 */
- "Unknown",
- "SIMM",
- "SIP",
- "Chip",
- "DIP",
- "ZIP",
- "Proprietary Card",
- "DIMM",
- "TSOP",
- "Row Of Chips",
- "RIMM",
- "SODIMM",
- "SRIMM",
- "FB-DIMM" /* 0x0F */
- };
+ /* 3.3.18.1 */
+ static const char *form_factor[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "SIMM",
+ "SIP",
+ "Chip",
+ "DIP",
+ "ZIP",
+ "Proprietary Card",
+ "DIMM",
+ "TSOP",
+ "Row Of Chips",
+ "RIMM",
+ "SODIMM",
+ "SRIMM",
+ "FB-DIMM" /* 0x0F */
+ };
- if (code >= 0x01 && code <= 0x0F)
- return form_factor[code - 0x01];
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x0F)
+ return form_factor[code - 0x01];
+ return out_of_spec;
}
void dmi_memory_device_set(uint8_t code, char *set)
{
- if (code == 0)
- sprintf(set,"%s","None");
- else if (code == 0xFF)
- sprintf(set,"%s","Unknown");
- else
- sprintf(set,"%u", code);
+ if (code == 0)
+ sprintf(set, "%s", "None");
+ else if (code == 0xFF)
+ sprintf(set, "%s", "Unknown");
+ else
+ sprintf(set, "%u", code);
}
const char *dmi_memory_device_type(uint8_t code)
{
- /* 3.3.18.2 */
- static const char *type[] = {
- "Other", /* 0x01 */
- "Unknown",
- "DRAM",
- "EDRAM",
- "VRAM",
- "SRAM",
- "RAM",
- "ROM",
- "Flash",
- "EEPROM",
- "FEPROM",
- "EPROM",
- "CDRAM",
- "3DRAM",
- "SDRAM",
- "SGRAM",
- "RDRAM",
- "DDR",
- "DDR2",
- "DDR2 FB-DIMM" /* 0x14 */
- };
+ /* 3.3.18.2 */
+ static const char *type[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "DRAM",
+ "EDRAM",
+ "VRAM",
+ "SRAM",
+ "RAM",
+ "ROM",
+ "Flash",
+ "EEPROM",
+ "FEPROM",
+ "EPROM",
+ "CDRAM",
+ "3DRAM",
+ "SDRAM",
+ "SGRAM",
+ "RDRAM",
+ "DDR",
+ "DDR2",
+ "DDR2 FB-DIMM" /* 0x14 */
+ };
- if (code >= 0x01 && code <= 0x14)
- return type[code - 0x01];
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x14)
+ return type[code - 0x01];
+ return out_of_spec;
}
-void dmi_memory_device_type_detail(uint16_t code,char *type_detail)
+void dmi_memory_device_type_detail(uint16_t code, char *type_detail)
{
- /* 3.3.18.3 */
- static const char *detail[] = {
- "Other", /* 1 */
- "Unknown",
- "Fast-paged",
- "Static Column",
- "Pseudo-static",
- "RAMBus",
- "Synchronous",
- "CMOS",
- "EDO",
- "Window DRAM",
- "Cache DRAM",
- "Non-Volatile" /* 12 */
- };
+ /* 3.3.18.3 */
+ static const char *detail[] = {
+ "Other", /* 1 */
+ "Unknown",
+ "Fast-paged",
+ "Static Column",
+ "Pseudo-static",
+ "RAMBus",
+ "Synchronous",
+ "CMOS",
+ "EDO",
+ "Window DRAM",
+ "Cache DRAM",
+ "Non-Volatile" /* 12 */
+ };
- if ((code & 0x1FFE) == 0)
- sprintf(type_detail,"%s","None");
- else
- {
- int i;
+ if ((code & 0x1FFE) == 0)
+ sprintf(type_detail, "%s", "None");
+ else {
+ int i;
- for (i = 1; i <= 12; i++)
- if (code & (1 << i))
- sprintf(type_detail,"%s", detail[i - 1]);
+ for (i = 1; i <= 12; i++)
+ if (code & (1 << i))
+ sprintf(type_detail, "%s", detail[i - 1]);
}
}
void dmi_memory_device_speed(uint16_t code, char *speed)
{
- if (code == 0)
- sprintf(speed,"%s","Unknown");
- else
- sprintf(speed,"%u MHz", code);
+ if (code == 0)
+ sprintf(speed, "%s", "Unknown");
+ else
+ sprintf(speed, "%u MHz", code);
}
diff --git a/com32/gpllib/dmi/dmi_processor.c b/com32/gpllib/dmi/dmi_processor.c
index 321f6e65..8f3dda63 100644
--- a/com32/gpllib/dmi/dmi_processor.c
+++ b/com32/gpllib/dmi/dmi_processor.c
@@ -31,402 +31,400 @@
const char *dmi_processor_type(uint8_t code)
{
- /* 3.3.5.1 */
- static const char *type[]={
- "Other", /* 0x01 */
- "Unknown",
- "Central Processor",
- "Math Processor",
- "DSP Processor",
- "Video Processor" /* 0x06 */
- };
+ /* 3.3.5.1 */
+ static const char *type[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "Central Processor",
+ "Math Processor",
+ "DSP Processor",
+ "Video Processor" /* 0x06 */
+ };
- if(code>=0x01 && code<=0x06)
- return type[code-0x01];
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x06)
+ return type[code - 0x01];
+ return out_of_spec;
}
const char *dmi_processor_family(uint8_t code, char *manufacturer)
{
- /* 3.3.5.2 */
- static const char *family[]={
- NULL, /* 0x00 */
- "Other",
- "Unknown",
- "8086",
- "80286",
- "80386",
- "80486",
- "8087",
- "80287",
- "80387",
- "80487",
- "Pentium",
- "Pentium Pro",
- "Pentium II",
- "Pentium MMX",
- "Celeron",
- "Pentium II Xeon",
- "Pentium III",
- "M1",
- "M2",
- "Celeron M", /* 0x14 */
- "Pentium 4 HT",
- NULL,
- NULL, /* 0x17 */
- "Duron",
- "K5",
- "K6",
- "K6-2",
- "K6-3",
- "Athlon",
- "AMD2900",
- "K6-2+",
- "Power PC",
- "Power PC 601",
- "Power PC 603",
- "Power PC 603+",
- "Power PC 604",
- "Power PC 620",
- "Power PC x704",
- "Power PC 750",
- "Core 2 Duo", /* 0x28 */
- "Core 2 Duo Mobile",
- "Core Solo Mobile",
- "Atom",
- NULL,
- NULL,
- NULL,
- NULL,/* 0x2F */
- "Alpha",
- "Alpha 21064",
- "Alpha 21066",
- "Alpha 21164",
- "Alpha 21164PC",
- "Alpha 21164a",
- "Alpha 21264",
- "Alpha 21364",
- NULL, /* 0x38 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0x3F */
- "MIPS",
- "MIPS R4000",
- "MIPS R4200",
- "MIPS R4400",
- "MIPS R4600",
- "MIPS R10000",
- NULL, /* 0x46 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0x4F */
- "SPARC",
- "SuperSPARC",
- "MicroSPARC II",
- "MicroSPARC IIep",
- "UltraSPARC",
- "UltraSPARC II",
- "UltraSPARC IIi",
- "UltraSPARC III",
- "UltraSPARC IIIi",
- NULL, /* 0x59 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0x5F */
- "68040",
- "68xxx",
- "68000",
- "68010",
- "68020",
- "68030",
- NULL, /* 0x66 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0x6F */
- "Hobbit",
- NULL, /* 0x71 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0x77 */
- "Crusoe TM5000",
- "Crusoe TM3000",
- "Efficeon TM8000",
- NULL, /* 0x7B */
- NULL,
- NULL,
- NULL,
- NULL, /* 0x7F */
- "Weitek",
- NULL, /* 0x81 */
- "Itanium",
- "Athlon 64",
- "Opteron",
- "Sempron",
- "Turion 64", /* 0x86 */
- "Dual-Core Opteron",
- "Atlhon 64 X2",
- "Turion 64 X2",
- "Quad-Core Opteron",
- "Third-Generation Opteron",
- "Phenom FX",
- "Phenom X4",
- "Phenom X2",
- "Athlon X2",/* 0x8F */
- "PA-RISC",
- "PA-RISC 8500",
- "PA-RISC 8000",
- "PA-RISC 7300LC",
- "PA-RISC 7200",
- "PA-RISC 7100LC",
- "PA-RISC 7100",
- NULL, /* 0x97 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0x9F */
- "V30",
- "Quad-Core Xeon 3200", /* 0xA1 */
- "Dual-Core Xeon 3000",
- "Quad-Core Xeon 5300",
- "Dual-Core Xeon 5100",
- "Dual-Core Xeon 5000",
- "Dual-Core Xeon LV",
- "Dual-Core Xeon ULV",
- "Dual-Core Xeon 7100",
- "Quad-Core Xeon 5400",
- "Quad-Core Xeon", /* 0xAA */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0xAF */
- "Pentium III Xeon",
- "Pentium III Speedstep",
- "Pentium 4",
- "Xeon",
- "AS400",
- "Xeon MP",
- "Athlon XP",
- "Athlon MP",
- "Itanium 2",
- "Pentium M",
- "Celeron D", /* 0xBA */
- "Pentium D",
- "Pentium EE",
- "Core Solo", /* 0xBD */
- NULL,
- "Core 2 Duo",
- "Core 2 Solo",
- "Core 2 Extreme",
- "Core 2 Quad",
- "Core 2 Extreme Mobile",
- "Core 2 Duo Mobile",
- "Core 2 Solo Mobile",
- NULL,
- NULL, /* 0xC7 */
- "IBM390",
- "G4",
- "G5",
- "ESA/390 G6", /* 0xCB */
- "z/Architectur",
- NULL,
- NULL,
- NULL,
- NULL, /*0xD0*/
- NULL,
- "C7-M",
- "C7-D",
- "C7",
- "Eden",
- NULL,/*0xD6*/
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /*0xE0*/
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- "Embedded Opteron Quad-Core",/* 0xE6*/
- "Phenom Triple-Core" ,
- "Turion Ultra Dual-Core Mobile",
- "Turion Dual-Core Mobile",
- "Athlon Dual-Core",
- "Sempron SI",/*0xEB*/
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0xF9 */
- "i860",
- "i960",
- NULL, /* 0xFC */
- NULL,
- NULL,
- NULL /* 0xFF */
- /* master.mif has values beyond that, but they can't be used for DMI */
- };
- /* Special case for ambiguous value 0xBE */
- if (code == 0xBE)
- {
- /* Best bet based on manufacturer string */
- if (strstr(manufacturer, "Intel") != NULL
- || strncasecmp(manufacturer, "Intel", 5) == 0)
- return "Core 2";
- if (strstr(manufacturer, "AMD") != NULL
- || strncasecmp(manufacturer, "AMD", 3) == 0)
- return "K7";
- return "Core 2 or K7";
- }
+ /* 3.3.5.2 */
+ static const char *family[] = {
+ NULL, /* 0x00 */
+ "Other",
+ "Unknown",
+ "8086",
+ "80286",
+ "80386",
+ "80486",
+ "8087",
+ "80287",
+ "80387",
+ "80487",
+ "Pentium",
+ "Pentium Pro",
+ "Pentium II",
+ "Pentium MMX",
+ "Celeron",
+ "Pentium II Xeon",
+ "Pentium III",
+ "M1",
+ "M2",
+ "Celeron M", /* 0x14 */
+ "Pentium 4 HT",
+ NULL,
+ NULL, /* 0x17 */
+ "Duron",
+ "K5",
+ "K6",
+ "K6-2",
+ "K6-3",
+ "Athlon",
+ "AMD2900",
+ "K6-2+",
+ "Power PC",
+ "Power PC 601",
+ "Power PC 603",
+ "Power PC 603+",
+ "Power PC 604",
+ "Power PC 620",
+ "Power PC x704",
+ "Power PC 750",
+ "Core 2 Duo", /* 0x28 */
+ "Core 2 Duo Mobile",
+ "Core Solo Mobile",
+ "Atom",
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x2F */
+ "Alpha",
+ "Alpha 21064",
+ "Alpha 21066",
+ "Alpha 21164",
+ "Alpha 21164PC",
+ "Alpha 21164a",
+ "Alpha 21264",
+ "Alpha 21364",
+ NULL, /* 0x38 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x3F */
+ "MIPS",
+ "MIPS R4000",
+ "MIPS R4200",
+ "MIPS R4400",
+ "MIPS R4600",
+ "MIPS R10000",
+ NULL, /* 0x46 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x4F */
+ "SPARC",
+ "SuperSPARC",
+ "MicroSPARC II",
+ "MicroSPARC IIep",
+ "UltraSPARC",
+ "UltraSPARC II",
+ "UltraSPARC IIi",
+ "UltraSPARC III",
+ "UltraSPARC IIIi",
+ NULL, /* 0x59 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x5F */
+ "68040",
+ "68xxx",
+ "68000",
+ "68010",
+ "68020",
+ "68030",
+ NULL, /* 0x66 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x6F */
+ "Hobbit",
+ NULL, /* 0x71 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x77 */
+ "Crusoe TM5000",
+ "Crusoe TM3000",
+ "Efficeon TM8000",
+ NULL, /* 0x7B */
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x7F */
+ "Weitek",
+ NULL, /* 0x81 */
+ "Itanium",
+ "Athlon 64",
+ "Opteron",
+ "Sempron",
+ "Turion 64", /* 0x86 */
+ "Dual-Core Opteron",
+ "Atlhon 64 X2",
+ "Turion 64 X2",
+ "Quad-Core Opteron",
+ "Third-Generation Opteron",
+ "Phenom FX",
+ "Phenom X4",
+ "Phenom X2",
+ "Athlon X2", /* 0x8F */
+ "PA-RISC",
+ "PA-RISC 8500",
+ "PA-RISC 8000",
+ "PA-RISC 7300LC",
+ "PA-RISC 7200",
+ "PA-RISC 7100LC",
+ "PA-RISC 7100",
+ NULL, /* 0x97 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x9F */
+ "V30",
+ "Quad-Core Xeon 3200", /* 0xA1 */
+ "Dual-Core Xeon 3000",
+ "Quad-Core Xeon 5300",
+ "Dual-Core Xeon 5100",
+ "Dual-Core Xeon 5000",
+ "Dual-Core Xeon LV",
+ "Dual-Core Xeon ULV",
+ "Dual-Core Xeon 7100",
+ "Quad-Core Xeon 5400",
+ "Quad-Core Xeon", /* 0xAA */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0xAF */
+ "Pentium III Xeon",
+ "Pentium III Speedstep",
+ "Pentium 4",
+ "Xeon",
+ "AS400",
+ "Xeon MP",
+ "Athlon XP",
+ "Athlon MP",
+ "Itanium 2",
+ "Pentium M",
+ "Celeron D", /* 0xBA */
+ "Pentium D",
+ "Pentium EE",
+ "Core Solo", /* 0xBD */
+ NULL,
+ "Core 2 Duo",
+ "Core 2 Solo",
+ "Core 2 Extreme",
+ "Core 2 Quad",
+ "Core 2 Extreme Mobile",
+ "Core 2 Duo Mobile",
+ "Core 2 Solo Mobile",
+ NULL,
+ NULL, /* 0xC7 */
+ "IBM390",
+ "G4",
+ "G5",
+ "ESA/390 G6", /* 0xCB */
+ "z/Architectur",
+ NULL,
+ NULL,
+ NULL,
+ NULL, /*0xD0 */
+ NULL,
+ "C7-M",
+ "C7-D",
+ "C7",
+ "Eden",
+ NULL, /*0xD6 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /*0xE0 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ "Embedded Opteron Quad-Core", /* 0xE6 */
+ "Phenom Triple-Core",
+ "Turion Ultra Dual-Core Mobile",
+ "Turion Dual-Core Mobile",
+ "Athlon Dual-Core",
+ "Sempron SI", /*0xEB */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0xF9 */
+ "i860",
+ "i960",
+ NULL, /* 0xFC */
+ NULL,
+ NULL,
+ NULL /* 0xFF */
+ /* master.mif has values beyond that, but they can't be used for DMI */
+ };
+ /* Special case for ambiguous value 0xBE */
+ if (code == 0xBE) {
+ /* Best bet based on manufacturer string */
+ if (strstr(manufacturer, "Intel") != NULL
+ || strncasecmp(manufacturer, "Intel", 5) == 0)
+ return "Core 2";
+ if (strstr(manufacturer, "AMD") != NULL
+ || strncasecmp(manufacturer, "AMD", 3) == 0)
+ return "K7";
+ return "Core 2 or K7";
+ }
- if(family[code]!=NULL) {
- return family[code];
- }
- return out_of_spec;
+ if (family[code] != NULL) {
+ return family[code];
+ }
+ return out_of_spec;
}
const char *dmi_processor_status(uint8_t code)
{
- static const char *status[]={
- "Unknown", /* 0x00 */
- "Enabled",
- "Disabled By User",
- "Disabled By BIOS",
- "Idle", /* 0x04 */
- "<OUT OF SPEC>",
- "<OUT OF SPEC>",
- "Other" /* 0x07 */
- };
+ static const char *status[] = {
+ "Unknown", /* 0x00 */
+ "Enabled",
+ "Disabled By User",
+ "Disabled By BIOS",
+ "Idle", /* 0x04 */
+ "<OUT OF SPEC>",
+ "<OUT OF SPEC>",
+ "Other" /* 0x07 */
+ };
- if(code<=0x04)
- return status[code];
- if(code==0x07)
- return status[0x05];
- return out_of_spec;
+ if (code <= 0x04)
+ return status[code];
+ if (code == 0x07)
+ return status[0x05];
+ return out_of_spec;
}
const char *dmi_processor_upgrade(uint8_t code)
{
- /* 3.3.5.5 */
- static const char *upgrade[]={
- "Other", /* 0x01 */
- "Unknown",
- "Daughter Board",
- "ZIF Socket",
- "Replaceable Piggy Back",
- "None",
- "LIF Socket",
- "Slot 1",
- "Slot 2",
- "370-pin Socket",
- "Slot A",
- "Slot M",
- "Socket 423",
- "Socket A (Socket 462)",
- "Socket 478",
- "Socket 754",
- "Socket 940",
- "Socket 939" /* 0x12 */
- "Socket mPGA604",
- "Socket LGA771",
- "Socket LGA775",
- "Socket S1",
- "Socket AM2",
- "Socket F (1207)"
- };
+ /* 3.3.5.5 */
+ static const char *upgrade[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "Daughter Board",
+ "ZIF Socket",
+ "Replaceable Piggy Back",
+ "None",
+ "LIF Socket",
+ "Slot 1",
+ "Slot 2",
+ "370-pin Socket",
+ "Slot A",
+ "Slot M",
+ "Socket 423",
+ "Socket A (Socket 462)",
+ "Socket 478",
+ "Socket 754",
+ "Socket 940",
+ "Socket 939" /* 0x12 */
+ "Socket mPGA604",
+ "Socket LGA771",
+ "Socket LGA775",
+ "Socket S1",
+ "Socket AM2",
+ "Socket F (1207)"
+ };
- if(code>=0x01 && code<=0x11)
- return upgrade[code-0x01];
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x11)
+ return upgrade[code - 0x01];
+ return out_of_spec;
}
-void dmi_processor_cache(uint16_t code, const char *level, uint16_t ver, char *cache)
+void dmi_processor_cache(uint16_t code, const char *level, uint16_t ver,
+ char *cache)
{
- if(code==0xFFFF)
- {
- if(ver>=0x0203)
- sprintf(cache,"Not Provided");
- else
- sprintf(cache,"No %s Cache", level);
- }
- else
- sprintf(cache,"0x%04X", code);
+ if (code == 0xFFFF) {
+ if (ver >= 0x0203)
+ sprintf(cache, "Not Provided");
+ else
+ sprintf(cache, "No %s Cache", level);
+ } else
+ sprintf(cache, "0x%04X", code);
}
/* Intel AP-485 revision 28, table 5 */
-const char *cpu_flags_strings[PROCESSOR_FLAGS_ELEMENTS]={
- "FPU (Floating-point unit on-chip)", /* 0 */
- "VME (Virtual mode extension)",
- "DE (Debugging extension)",
- "PSE (Page size extension)",
- "TSC (Time stamp counter)",
- "MSR (Model specific registers)",
- "PAE (Physical address extension)",
- "MCE (Machine check exception)",
- "CX8 (CMPXCHG8 instruction supported)",
- "APIC (On-chip APIC hardware supported)",
- NULL, /* 10 */
- "SEP (Fast system call)",
- "MTRR (Memory type range registers)",
- "PGE (Page global enable)",
- "MCA (Machine check architecture)",
- "CMOV (Conditional move instruction supported)",
- "PAT (Page attribute table)",
- "PSE-36 (36-bit page size extension)",
- "PSN (Processor serial number present and enabled)",
- "CLFSH (CLFLUSH instruction supported)",
- NULL, /* 20 */
- "DS (Debug store)",
- "ACPI (ACPI supported)",
- "MMX (MMX technology supported)",
- "FXSR (Fast floating-point save and restore)",
- "SSE (Streaming SIMD extensions)",
- "SSE2 (Streaming SIMD extensions 2)",
- "SS (Self-snoop)",
- "HTT (Hyper-threading technology)",
- "TM (Thermal monitor supported)",
- "IA64 (IA64 capabilities)", /* 30 */
- "PBE (Pending break enabled)" /* 31 */
+const char *cpu_flags_strings[PROCESSOR_FLAGS_ELEMENTS] = {
+ "FPU (Floating-point unit on-chip)", /* 0 */
+ "VME (Virtual mode extension)",
+ "DE (Debugging extension)",
+ "PSE (Page size extension)",
+ "TSC (Time stamp counter)",
+ "MSR (Model specific registers)",
+ "PAE (Physical address extension)",
+ "MCE (Machine check exception)",
+ "CX8 (CMPXCHG8 instruction supported)",
+ "APIC (On-chip APIC hardware supported)",
+ NULL, /* 10 */
+ "SEP (Fast system call)",
+ "MTRR (Memory type range registers)",
+ "PGE (Page global enable)",
+ "MCA (Machine check architecture)",
+ "CMOV (Conditional move instruction supported)",
+ "PAT (Page attribute table)",
+ "PSE-36 (36-bit page size extension)",
+ "PSN (Processor serial number present and enabled)",
+ "CLFSH (CLFLUSH instruction supported)",
+ NULL, /* 20 */
+ "DS (Debug store)",
+ "ACPI (ACPI supported)",
+ "MMX (MMX technology supported)",
+ "FXSR (Fast floating-point save and restore)",
+ "SSE (Streaming SIMD extensions)",
+ "SSE2 (Streaming SIMD extensions 2)",
+ "SS (Self-snoop)",
+ "HTT (Hyper-threading technology)",
+ "TM (Thermal monitor supported)",
+ "IA64 (IA64 capabilities)", /* 30 */
+ "PBE (Pending break enabled)" /* 31 */
};
diff --git a/com32/gpllib/vpd/vpd.c b/com32/gpllib/vpd/vpd.c
index ff04b8bf..fd468e4c 100644
--- a/com32/gpllib/vpd/vpd.c
+++ b/com32/gpllib/vpd/vpd.c
@@ -32,72 +32,72 @@
int vpd_checksum(char *buf, int len)
{
- uint8_t sum=0;
- int a;
+ uint8_t sum = 0;
+ int a;
- for(a=0; a<len; a++)
- sum+=buf[a];
- return (sum==0);
+ for (a = 0; a < len; a++)
+ sum += buf[a];
+ return (sum == 0);
}
-int vpd_decode(s_vpd *vpd) {
- uint8_t buf[16];
- char *p,*q;
+int vpd_decode(s_vpd * vpd)
+{
+ uint8_t buf[16];
+ char *p, *q;
- /* Cleaning structures */
- memset(&vpd->base_address,0,sizeof (vpd->base_address));
- memset(&vpd->bios_build_id,0,sizeof (vpd->bios_build_id));
- memset(&vpd->box_serial_number,0,sizeof (vpd->box_serial_number));
- memset(&vpd->motherboard_serial_number,0,sizeof (vpd->motherboard_serial_number));
- memset(&vpd->machine_type_model,0,sizeof (vpd->machine_type_model));
- memset(&vpd->bios_release_date,0,sizeof (vpd->bios_release_date));
- memset(&vpd->default_flash_filename,0,sizeof (vpd->default_flash_filename));
- memset(&vpd->bios_version,0,sizeof (vpd->bios_version));
+ /* Cleaning structures */
+ memset(&vpd->base_address, 0, sizeof(vpd->base_address));
+ memset(&vpd->bios_build_id, 0, sizeof(vpd->bios_build_id));
+ memset(&vpd->box_serial_number, 0, sizeof(vpd->box_serial_number));
+ memset(&vpd->motherboard_serial_number, 0,
+ sizeof(vpd->motherboard_serial_number));
+ memset(&vpd->machine_type_model, 0, sizeof(vpd->machine_type_model));
+ memset(&vpd->bios_release_date, 0, sizeof(vpd->bios_release_date));
+ memset(&vpd->default_flash_filename, 0,
+ sizeof(vpd->default_flash_filename));
+ memset(&vpd->bios_version, 0, sizeof(vpd->bios_version));
- /* Until we found elements in the vpdtable, we consider them as not filled */
- vpd->filled=false;
+ /* Until we found elements in the vpdtable, we consider them as not filled */
+ vpd->filled = false;
- p=(char *)0xF0000; /* The start address to look at the dmi table */
- for (q = p; q < p + 0x10000; q +=4) {
- memcpy(buf, q, 5);
- if(memcmp(buf, "\252\125VPD", 5)==0) {
- snprintf(&vpd->base_address,5,"%X",q);
- if (q[5] < 0x30)
- return -ENOVPDTABLE;
+ p = (char *)0xF0000; /* The start address to look at the dmi table */
+ for (q = p; q < p + 0x10000; q += 4) {
+ memcpy(buf, q, 5);
+ if (memcmp(buf, "\252\125VPD", 5) == 0) {
+ snprintf(&vpd->base_address, 5, "%X", q);
+ if (q[5] < 0x30)
+ return -ENOVPDTABLE;
- vpd->filled=true;
- /* XSeries have longer records, exact length seems to vary. */
- if (!(q[5] >= 0x45 && vpd_checksum(q, q[5]))
- /* Some Netvista seem to work with this. */
- && !(vpd_checksum(q, 0x30))
- /* The Thinkpad/Thinkcentre checksum does *not* include the first 13 bytes. */
- && !(vpd_checksum(q + 0x0D, 0x30 - 0x0D)))
- {
- /* A few systems have a bad checksum (xSeries 325, 330, 335
- and 345 with early BIOS) but the record is otherwise
- valid. */
- printf("VPD: Bad checksum!\n");
- }
+ vpd->filled = true;
+ /* XSeries have longer records, exact length seems to vary. */
+ if (!(q[5] >= 0x45 && vpd_checksum(q, q[5]))
+ /* Some Netvista seem to work with this. */
+ && !(vpd_checksum(q, 0x30))
+ /* The Thinkpad/Thinkcentre checksum does *not* include the first 13 bytes. */
+ && !(vpd_checksum(q + 0x0D, 0x30 - 0x0D))) {
+ /* A few systems have a bad checksum (xSeries 325, 330, 335
+ and 345 with early BIOS) but the record is otherwise
+ valid. */
+ printf("VPD: Bad checksum!\n");
+ }
- strncpy(vpd->bios_build_id,q+0x0D, 9);
- strncpy(vpd->box_serial_number,q+0x16, 7);
- strncpy(vpd->motherboard_serial_number,q+0x1D, 11);
- strncpy(vpd->machine_type_model,q+0x28, 7);
+ strncpy(vpd->bios_build_id, q + 0x0D, 9);
+ strncpy(vpd->box_serial_number, q + 0x16, 7);
+ strncpy(vpd->motherboard_serial_number, q + 0x1D, 11);
+ strncpy(vpd->machine_type_model, q + 0x28, 7);
- if (q[5] < 0x44)
- return VPD_TABLE_PRESENT;
+ if (q[5] < 0x44)
+ return VPD_TABLE_PRESENT;
- strncpy(vpd->bios_release_date,q+0x30, 8);
- strncpy(vpd->default_flash_filename,q+0x38, 12);
+ strncpy(vpd->bios_release_date, q + 0x30, 8);
+ strncpy(vpd->default_flash_filename, q + 0x38, 12);
- if (q[5] >= 0x46 && q[0x44] != 0x00) {
- strncpy(vpd->bios_version,q+0x44, 255);
- }
+ if (q[5] >= 0x46 && q[0x44] != 0x00) {
+ strncpy(vpd->bios_version, q + 0x44, 255);
+ }
- return VPD_TABLE_PRESENT;
- }
- }
- return -ENOVPDTABLE;
+ return VPD_TABLE_PRESENT;
+ }
+ }
+ return -ENOVPDTABLE;
}
-
-
diff --git a/com32/include/alloca.h b/com32/include/alloca.h
index 91ef4c0d..8c4067f9 100644
--- a/com32/include/alloca.h
+++ b/com32/include/alloca.h
@@ -9,4 +9,4 @@
#define alloca(size) __builtin_alloca(size)
-#endif /* _ALLOCA_H */
+#endif /* _ALLOCA_H */
diff --git a/com32/include/bitsize/stddef.h b/com32/include/bitsize/stddef.h
index c486041f..caa5e726 100644
--- a/com32/include/bitsize/stddef.h
+++ b/com32/include/bitsize/stddef.h
@@ -13,6 +13,6 @@ typedef unsigned int size_t;
#endif
#define _PTRDIFF_T
-typedef signed int ptrdiff_t;
+typedef signed int ptrdiff_t;
#endif /* _BITSIZE_STDDEF_H */
diff --git a/com32/include/bitsize/stdint.h b/com32/include/bitsize/stdint.h
index bdfe1328..8cbfc5dd 100644
--- a/com32/include/bitsize/stdint.h
+++ b/com32/include/bitsize/stdint.h
@@ -5,24 +5,24 @@
#ifndef _BITSIZE_STDINT_H
#define _BITSIZE_STDINT_H
-typedef signed char int8_t;
-typedef short int int16_t;
-typedef int int32_t;
-typedef long long int int64_t;
+typedef signed char int8_t;
+typedef short int int16_t;
+typedef int int32_t;
+typedef long long int int64_t;
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long long int uint64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short int uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long int uint64_t;
-typedef int int_fast16_t;
-typedef int int_fast32_t;
+typedef int int_fast16_t;
+typedef int int_fast32_t;
-typedef unsigned int uint_fast16_t;
-typedef unsigned int uint_fast32_t;
+typedef unsigned int uint_fast16_t;
+typedef unsigned int uint_fast32_t;
-typedef int intptr_t;
-typedef unsigned int uintptr_t;
+typedef int intptr_t;
+typedef unsigned int uintptr_t;
#define __INT64_C(c) c ## LL
#define __UINT64_C(c) c ## ULL
diff --git a/com32/include/colortbl.h b/com32/include/colortbl.h
index fb5196cc..e9f0a127 100644
--- a/com32/include/colortbl.h
+++ b/com32/include/colortbl.h
@@ -33,18 +33,18 @@
/* Note: vesacon relies on the encoding of these numbers */
enum color_table_shadow {
- SHADOW_NONE = 0,
- SHADOW_ALL = 1,
- SHADOW_NORMAL = 2,
- SHADOW_REVERSE = 3,
+ SHADOW_NONE = 0,
+ SHADOW_ALL = 1,
+ SHADOW_NORMAL = 2,
+ SHADOW_REVERSE = 3,
};
struct color_table {
- const char *name; /* Attribute name (used for customization) */
- const char *ansi; /* ANSI attribute */
- unsigned int argb_fg; /* ARGB for foreground */
- unsigned int argb_bg; /* ARGB for background */
- enum color_table_shadow shadow; /* Shadow mode */
+ const char *name; /* Attribute name (used for customization) */
+ const char *ansi; /* ANSI attribute */
+ unsigned int argb_fg; /* ARGB for foreground */
+ unsigned int argb_bg; /* ARGB for background */
+ enum color_table_shadow shadow; /* Shadow mode */
};
extern struct color_table *console_color_table;
diff --git a/com32/include/com32.h b/com32/include/com32.h
index da2edfb1..c003f7ca 100644
--- a/com32/include/com32.h
+++ b/com32/include/com32.h
@@ -48,27 +48,27 @@
* __farcall(seg, offs, source_regs, return_regs)
*/
typedef union {
- uint32_t l;
- uint16_t w[2];
- uint8_t b[4];
+ uint32_t l;
+ uint16_t w[2];
+ uint8_t b[4];
} reg32_t;
typedef struct {
- uint16_t gs; /* Offset 0 */
- uint16_t fs; /* Offset 2 */
- uint16_t es; /* Offset 4 */
- uint16_t ds; /* Offset 6 */
-
- reg32_t edi; /* Offset 8 */
- reg32_t esi; /* Offset 12 */
- reg32_t ebp; /* Offset 16 */
- reg32_t _unused_esp; /* Offset 20 */
- reg32_t ebx; /* Offset 24 */
- reg32_t edx; /* Offset 28 */
- reg32_t ecx; /* Offset 32 */
- reg32_t eax; /* Offset 36 */
-
- reg32_t eflags; /* Offset 40 */
+ uint16_t gs; /* Offset 0 */
+ uint16_t fs; /* Offset 2 */
+ uint16_t es; /* Offset 4 */
+ uint16_t ds; /* Offset 6 */
+
+ reg32_t edi; /* Offset 8 */
+ reg32_t esi; /* Offset 12 */
+ reg32_t ebp; /* Offset 16 */
+ reg32_t _unused_esp; /* Offset 20 */
+ reg32_t ebx; /* Offset 24 */
+ reg32_t edx; /* Offset 28 */
+ reg32_t ecx; /* Offset 32 */
+ reg32_t eax; /* Offset 36 */
+
+ reg32_t eflags; /* Offset 40 */
} com32sys_t;
/* EFLAGS definitions */
@@ -91,22 +91,22 @@ typedef struct {
#define EFLAGS_ID 0x00200000
extern struct com32_sys_args {
- uint32_t cs_sysargs;
- char *cs_cmdline;
- void __cdecl (*cs_intcall)(uint8_t, const com32sys_t *, com32sys_t *);
- void *cs_bounce;
- uint32_t cs_bounce_size;
- void __cdecl (*cs_farcall)(uint32_t, const com32sys_t *, com32sys_t *);
- int __cdecl (*cs_cfarcall)(uint32_t, const void *, uint32_t);
- uint32_t cs_memsize;
+ uint32_t cs_sysargs;
+ char *cs_cmdline;
+ void __cdecl(*cs_intcall) (uint8_t, const com32sys_t *, com32sys_t *);
+ void *cs_bounce;
+ uint32_t cs_bounce_size;
+ void __cdecl(*cs_farcall) (uint32_t, const com32sys_t *, com32sys_t *);
+ int __cdecl(*cs_cfarcall) (uint32_t, const void *, uint32_t);
+ uint32_t cs_memsize;
} __com32;
/*
* System call wrapper functions
*/
-void __intcall(uint8_t __i, const com32sys_t *__sr, com32sys_t *__dr);
+void __intcall(uint8_t __i, const com32sys_t * __sr, com32sys_t * __dr);
void __farcall(uint16_t __cs, uint16_t __ip,
- const com32sys_t *__sr, com32sys_t *__dr);
+ const com32sys_t * __sr, com32sys_t * __dr);
int __cfarcall(uint16_t __cs, uint16_t __ip,
const void *__stack, uint32_t __stack_size);
extern const com32sys_t __com32_zero_regs;
@@ -123,53 +123,52 @@ extern const com32sys_t __com32_zero_regs;
*/
static inline uint16_t SEG(const volatile void *__p)
{
- return (uint16_t)(((uintptr_t)__p) >> 4);
+ return (uint16_t) (((uintptr_t) __p) >> 4);
}
static inline uint16_t OFFS(const volatile void *__p)
{
- /* The double cast here is to shut up gcc */
- return (uint16_t)(uintptr_t)__p & 0x000F;
+ /* The double cast here is to shut up gcc */
+ return (uint16_t) (uintptr_t) __p & 0x000F;
}
static inline uint16_t OFFS_WRT(const volatile void *__p, uint16_t seg)
{
- return (uint16_t)((uintptr_t)__p - ((uintptr_t)seg << 4));
+ return (uint16_t) ((uintptr_t) __p - ((uintptr_t) seg << 4));
}
static inline int OFFS_VALID(const volatile void *__p, uint16_t seg)
{
- uintptr_t __segstart = (uintptr_t)seg << 4;
- uintptr_t __ptr = (uintptr_t)__p;
+ uintptr_t __segstart = (uintptr_t) seg << 4;
+ uintptr_t __ptr = (uintptr_t) __p;
- return (__ptr >= __segstart) && (__ptr <= __segstart+0xffff);
+ return (__ptr >= __segstart) && (__ptr <= __segstart + 0xffff);
}
static inline void *MK_PTR(uint16_t __seg, uint16_t __offs)
{
- return (void *)((__seg << 4) + __offs);
+ return (void *)((__seg << 4) + __offs);
}
/* Some tools to handle 16:16 far pointers in memory */
struct __far_ptr {
- uint32_t __ptr;
-} __attribute__((packed));
+ uint32_t __ptr;
+} __attribute__ ((packed));
typedef struct __far_ptr far_ptr_t;
-
static inline void *GET_PTR(far_ptr_t __fptr)
{
- return MK_PTR(__fptr.__ptr >> 16, __fptr.__ptr);
+ return MK_PTR(__fptr.__ptr >> 16, __fptr.__ptr);
}
static inline far_ptr_t FAR_PTR(void *__ptr)
{
- far_ptr_t __fptr;
+ far_ptr_t __fptr;
- __fptr.__ptr = (SEG(__ptr) << 16) + OFFS(__ptr);
- return __fptr;
+ __fptr.__ptr = (SEG(__ptr) << 16) + OFFS(__ptr);
+ return __fptr;
}
#endif /* _COM32_H */
diff --git a/com32/include/console.h b/com32/include/console.h
index 973aeddb..74e68f1a 100644
--- a/com32/include/console.h
+++ b/com32/include/console.h
@@ -40,10 +40,10 @@
__extern int openconsole(const struct input_dev *, const struct output_dev *);
/* Standard line-oriented console */
-extern const struct input_dev dev_stdcon_r;
+extern const struct input_dev dev_stdcon_r;
extern const struct output_dev dev_stdcon_w;
/* Raw character-oriented console */
-extern const struct input_dev dev_rawcon_r;
+extern const struct input_dev dev_rawcon_r;
extern const struct output_dev dev_rawcon_w;
/* These are output-only consoles; combine with one of the input methods */
diff --git a/com32/include/cpufeature.h b/com32/include/cpufeature.h
index df1d1a15..2fd47579 100644
--- a/com32/include/cpufeature.h
+++ b/com32/include/cpufeature.h
@@ -10,83 +10,83 @@
#define NCAPINTS 7 /* N 32-bit words worth of info */
/* Intel-defined CPU features, CPUID level 0x00000001 (edx), word 0 */
-#define X86_FEATURE_FPU (0*32+ 0) /* Onboard FPU */
-#define X86_FEATURE_VME (0*32+ 1) /* Virtual Mode Extensions */
-#define X86_FEATURE_DE (0*32+ 2) /* Debugging Extensions */
-#define X86_FEATURE_PSE (0*32+ 3) /* Page Size Extensions */
-#define X86_FEATURE_TSC (0*32+ 4) /* Time Stamp Counter */
-#define X86_FEATURE_MSR (0*32+ 5) /* Model-Specific Registers, RDMSR, WRMSR */
-#define X86_FEATURE_PAE (0*32+ 6) /* Physical Address Extensions */
-#define X86_FEATURE_MCE (0*32+ 7) /* Machine Check Architecture */
-#define X86_FEATURE_CX8 (0*32+ 8) /* CMPXCHG8 instruction */
-#define X86_FEATURE_APIC (0*32+ 9) /* Onboard APIC */
-#define X86_FEATURE_SEP (0*32+11) /* SYSENTER/SYSEXIT */
-#define X86_FEATURE_MTRR (0*32+12) /* Memory Type Range Registers */
-#define X86_FEATURE_PGE (0*32+13) /* Page Global Enable */
-#define X86_FEATURE_MCA (0*32+14) /* Machine Check Architecture */
-#define X86_FEATURE_CMOV (0*32+15) /* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */
-#define X86_FEATURE_PAT (0*32+16) /* Page Attribute Table */
-#define X86_FEATURE_PSE36 (0*32+17) /* 36-bit PSEs */
-#define X86_FEATURE_PN (0*32+18) /* Processor serial number */
-#define X86_FEATURE_CLFLSH (0*32+19) /* Supports the CLFLUSH instruction */
-#define X86_FEATURE_DTES (0*32+21) /* Debug Trace Store */
-#define X86_FEATURE_ACPI (0*32+22) /* ACPI via MSR */
-#define X86_FEATURE_MMX (0*32+23) /* Multimedia Extensions */
-#define X86_FEATURE_FXSR (0*32+24) /* FXSAVE and FXRSTOR instructions (fast save and restore */
- /* of FPU context), and CR4.OSFXSR available */
-#define X86_FEATURE_XMM (0*32+25) /* Streaming SIMD Extensions */
-#define X86_FEATURE_XMM2 (0*32+26) /* Streaming SIMD Extensions-2 */
-#define X86_FEATURE_SELFSNOOP (0*32+27) /* CPU self snoop */
-#define X86_FEATURE_HT (0*32+28) /* Hyper-Threading */
-#define X86_FEATURE_ACC (0*32+29) /* Automatic clock control */
-#define X86_FEATURE_IA64 (0*32+30) /* IA-64 processor */
+#define X86_FEATURE_FPU (0*32+ 0) /* Onboard FPU */
+#define X86_FEATURE_VME (0*32+ 1) /* Virtual Mode Extensions */
+#define X86_FEATURE_DE (0*32+ 2) /* Debugging Extensions */
+#define X86_FEATURE_PSE (0*32+ 3) /* Page Size Extensions */
+#define X86_FEATURE_TSC (0*32+ 4) /* Time Stamp Counter */
+#define X86_FEATURE_MSR (0*32+ 5) /* Model-Specific Registers, RDMSR, WRMSR */
+#define X86_FEATURE_PAE (0*32+ 6) /* Physical Address Extensions */
+#define X86_FEATURE_MCE (0*32+ 7) /* Machine Check Architecture */
+#define X86_FEATURE_CX8 (0*32+ 8) /* CMPXCHG8 instruction */
+#define X86_FEATURE_APIC (0*32+ 9) /* Onboard APIC */
+#define X86_FEATURE_SEP (0*32+11) /* SYSENTER/SYSEXIT */
+#define X86_FEATURE_MTRR (0*32+12) /* Memory Type Range Registers */
+#define X86_FEATURE_PGE (0*32+13) /* Page Global Enable */
+#define X86_FEATURE_MCA (0*32+14) /* Machine Check Architecture */
+#define X86_FEATURE_CMOV (0*32+15) /* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */
+#define X86_FEATURE_PAT (0*32+16) /* Page Attribute Table */
+#define X86_FEATURE_PSE36 (0*32+17) /* 36-bit PSEs */
+#define X86_FEATURE_PN (0*32+18) /* Processor serial number */
+#define X86_FEATURE_CLFLSH (0*32+19) /* Supports the CLFLUSH instruction */
+#define X86_FEATURE_DTES (0*32+21) /* Debug Trace Store */
+#define X86_FEATURE_ACPI (0*32+22) /* ACPI via MSR */
+#define X86_FEATURE_MMX (0*32+23) /* Multimedia Extensions */
+#define X86_FEATURE_FXSR (0*32+24) /* FXSAVE and FXRSTOR instructions (fast save and restore */
+ /* of FPU context), and CR4.OSFXSR available */
+#define X86_FEATURE_XMM (0*32+25) /* Streaming SIMD Extensions */
+#define X86_FEATURE_XMM2 (0*32+26) /* Streaming SIMD Extensions-2 */
+#define X86_FEATURE_SELFSNOOP (0*32+27) /* CPU self snoop */
+#define X86_FEATURE_HT (0*32+28) /* Hyper-Threading */
+#define X86_FEATURE_ACC (0*32+29) /* Automatic clock control */
+#define X86_FEATURE_IA64 (0*32+30) /* IA-64 processor */
/* AMD-defined CPU features, CPUID level 0x80000001, word 1 */
/* Don't duplicate feature flags which are redundant with Intel! */
-#define X86_FEATURE_SYSCALL (1*32+11) /* SYSCALL/SYSRET */
-#define X86_FEATURE_MP (1*32+19) /* MP Capable. */
-#define X86_FEATURE_NX (1*32+20) /* Execute Disable */
-#define X86_FEATURE_MMXEXT (1*32+22) /* AMD MMX extensions */
-#define X86_FEATURE_LM (1*32+29) /* Long Mode (x86-64) */
-#define X86_FEATURE_3DNOWEXT (1*32+30) /* AMD 3DNow! extensions */
-#define X86_FEATURE_3DNOW (1*32+31) /* 3DNow! */
+#define X86_FEATURE_SYSCALL (1*32+11) /* SYSCALL/SYSRET */
+#define X86_FEATURE_MP (1*32+19) /* MP Capable. */
+#define X86_FEATURE_NX (1*32+20) /* Execute Disable */
+#define X86_FEATURE_MMXEXT (1*32+22) /* AMD MMX extensions */
+#define X86_FEATURE_LM (1*32+29) /* Long Mode (x86-64) */
+#define X86_FEATURE_3DNOWEXT (1*32+30) /* AMD 3DNow! extensions */
+#define X86_FEATURE_3DNOW (1*32+31) /* 3DNow! */
/* Transmeta-defined CPU features, CPUID level 0x80860001, word 2 */
-#define X86_FEATURE_RECOVERY (2*32+ 0) /* CPU in recovery mode */
-#define X86_FEATURE_LONGRUN (2*32+ 1) /* Longrun power control */
-#define X86_FEATURE_LRTI (2*32+ 3) /* LongRun table interface */
+#define X86_FEATURE_RECOVERY (2*32+ 0) /* CPU in recovery mode */
+#define X86_FEATURE_LONGRUN (2*32+ 1) /* Longrun power control */
+#define X86_FEATURE_LRTI (2*32+ 3) /* LongRun table interface */
/* Other features, Linux-defined mapping, word 3 */
/* This range is used for feature bits which conflict or are synthesized */
-#define X86_FEATURE_CXMMX (3*32+ 0) /* Cyrix MMX extensions */
-#define X86_FEATURE_K6_MTRR (3*32+ 1) /* AMD K6 nonstandard MTRRs */
-#define X86_FEATURE_CYRIX_ARR (3*32+ 2) /* Cyrix ARRs (= MTRRs) */
-#define X86_FEATURE_CENTAUR_MCR (3*32+ 3) /* Centaur MCRs (= MTRRs) */
+#define X86_FEATURE_CXMMX (3*32+ 0) /* Cyrix MMX extensions */
+#define X86_FEATURE_K6_MTRR (3*32+ 1) /* AMD K6 nonstandard MTRRs */
+#define X86_FEATURE_CYRIX_ARR (3*32+ 2) /* Cyrix ARRs (= MTRRs) */
+#define X86_FEATURE_CENTAUR_MCR (3*32+ 3) /* Centaur MCRs (= MTRRs) */
/* cpu types for specific tunings: */
-#define X86_FEATURE_K8 (3*32+ 4) /* Opteron, Athlon64 */
-#define X86_FEATURE_K7 (3*32+ 5) /* Athlon */
-#define X86_FEATURE_P3 (3*32+ 6) /* P3 */
-#define X86_FEATURE_P4 (3*32+ 7) /* P4 */
+#define X86_FEATURE_K8 (3*32+ 4) /* Opteron, Athlon64 */
+#define X86_FEATURE_K7 (3*32+ 5) /* Athlon */
+#define X86_FEATURE_P3 (3*32+ 6) /* P3 */
+#define X86_FEATURE_P4 (3*32+ 7) /* P4 */
/* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
-#define X86_FEATURE_XMM3 (4*32+ 0) /* Streaming SIMD Extensions-3 */
-#define X86_FEATURE_MWAIT (4*32+ 3) /* Monitor/Mwait support */
-#define X86_FEATURE_DSCPL (4*32+ 4) /* CPL Qualified Debug Store */
-#define X86_FEATURE_EST (4*32+ 7) /* Enhanced SpeedStep */
-#define X86_FEATURE_TM2 (4*32+ 8) /* Thermal Monitor 2 */
-#define X86_FEATURE_CID (4*32+10) /* Context ID */
-#define X86_FEATURE_CX16 (4*32+13) /* CMPXCHG16B */
-#define X86_FEATURE_XTPR (4*32+14) /* Send Task Priority Messages */
+#define X86_FEATURE_XMM3 (4*32+ 0) /* Streaming SIMD Extensions-3 */
+#define X86_FEATURE_MWAIT (4*32+ 3) /* Monitor/Mwait support */
+#define X86_FEATURE_DSCPL (4*32+ 4) /* CPL Qualified Debug Store */
+#define X86_FEATURE_EST (4*32+ 7) /* Enhanced SpeedStep */
+#define X86_FEATURE_TM2 (4*32+ 8) /* Thermal Monitor 2 */
+#define X86_FEATURE_CID (4*32+10) /* Context ID */
+#define X86_FEATURE_CX16 (4*32+13) /* CMPXCHG16B */
+#define X86_FEATURE_XTPR (4*32+14) /* Send Task Priority Messages */
/* VIA/Cyrix/Centaur-defined CPU features, CPUID level 0xC0000001, word 5 */
-#define X86_FEATURE_XSTORE (5*32+ 2) /* on-CPU RNG present (xstore insn) */
-#define X86_FEATURE_XSTORE_EN (5*32+ 3) /* on-CPU RNG enabled */
-#define X86_FEATURE_XCRYPT (5*32+ 6) /* on-CPU crypto (xcrypt insn) */
-#define X86_FEATURE_XCRYPT_EN (5*32+ 7) /* on-CPU crypto enabled */
+#define X86_FEATURE_XSTORE (5*32+ 2) /* on-CPU RNG present (xstore insn) */
+#define X86_FEATURE_XSTORE_EN (5*32+ 3) /* on-CPU RNG enabled */
+#define X86_FEATURE_XCRYPT (5*32+ 6) /* on-CPU crypto (xcrypt insn) */
+#define X86_FEATURE_XCRYPT_EN (5*32+ 7) /* on-CPU crypto enabled */
/* More extended AMD flags: CPUID level 0x80000001, ecx, word 6 */
-#define X86_FEATURE_LAHF_LM (6*32+ 0) /* LAHF/SAHF in long mode */
-#define X86_FEATURE_CMP_LEGACY (6*32+ 1) /* If yes HyperThreading not valid */
+#define X86_FEATURE_LAHF_LM (6*32+ 0) /* LAHF/SAHF in long mode */
+#define X86_FEATURE_CMP_LEGACY (6*32+ 1) /* If yes HyperThreading not valid */
#endif /* __ASM_I386_CPUFEATURE_H */
diff --git a/com32/include/ctype.h b/com32/include/ctype.h
index 89b6e6dd..28fae9fd 100644
--- a/com32/include/ctype.h
+++ b/com32/include/ctype.h
@@ -22,84 +22,82 @@
* blank = '\t' || ' ' (per POSIX requirement)
*/
enum {
- __ctype_upper = (1 << 0),
- __ctype_lower = (1 << 1),
- __ctype_digit = (1 << 2),
- __ctype_xdigit = (1 << 3),
- __ctype_space = (1 << 4),
- __ctype_print = (1 << 5),
- __ctype_punct = (1 << 6),
- __ctype_cntrl = (1 << 7),
+ __ctype_upper = (1 << 0),
+ __ctype_lower = (1 << 1),
+ __ctype_digit = (1 << 2),
+ __ctype_xdigit = (1 << 3),
+ __ctype_space = (1 << 4),
+ __ctype_print = (1 << 5),
+ __ctype_punct = (1 << 6),
+ __ctype_cntrl = (1 << 7),
};
extern const unsigned char __ctypes[];
__ctype_inline int isalnum(int __c)
{
- return __ctypes[__c+1] &
- (__ctype_upper|__ctype_lower|__ctype_digit);
+ return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower | __ctype_digit);
}
__ctype_inline int isalpha(int __c)
{
- return __ctypes[__c+1] &
- (__ctype_upper|__ctype_lower);
+ return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower);
}
__ctype_inline int isascii(int __c)
{
- return !(__c & ~0x7f);
+ return !(__c & ~0x7f);
}
__ctype_inline int isblank(int __c)
{
- return (__c == '\t') || (__c == ' ');
+ return (__c == '\t') || (__c == ' ');
}
__ctype_inline int iscntrl(int __c)
{
- return __ctypes[__c+1] & __ctype_cntrl;
+ return __ctypes[__c + 1] & __ctype_cntrl;
}
__ctype_inline int isdigit(int __c)
{
- return ((unsigned)__c - '0') <= 9;
+ return ((unsigned)__c - '0') <= 9;
}
__ctype_inline int isgraph(int __c)
{
- return __ctypes[__c+1] &
- (__ctype_upper|__ctype_lower|__ctype_digit|__ctype_punct);
+ return __ctypes[__c + 1] &
+ (__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct);
}
__ctype_inline int islower(int __c)
{
- return __ctypes[__c+1] & __ctype_lower;
+ return __ctypes[__c + 1] & __ctype_lower;
}
__ctype_inline int isprint(int __c)
{
- return __ctypes[__c+1] & __ctype_print;
+ return __ctypes[__c + 1] & __ctype_print;
}
__ctype_inline int ispunct(int __c)
{
- return __ctypes[__c+1] & __ctype_punct;
+ return __ctypes[__c + 1] & __ctype_punct;
}
__ctype_inline int isspace(int __c)
{
- return __ctypes[__c+1] & __ctype_space;
+ return __ctypes[__c + 1] & __ctype_space;
}
__ctype_inline int isupper(int __c)
{
- return __ctypes[__c+1] & __ctype_upper;
+ return __ctypes[__c + 1] & __ctype_upper;
}
__ctype_inline int isxdigit(int __c)
{
- return __ctypes[__c+1] & __ctype_xdigit;
+ return __ctypes[__c + 1] & __ctype_xdigit;
}
/* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */
@@ -108,12 +106,12 @@ __ctype_inline int isxdigit(int __c)
__ctype_inline int toupper(int __c)
{
- return islower(__c) ? _toupper(__c) : __c;
+ return islower(__c) ? _toupper(__c) : __c;
}
__ctype_inline int tolower(int __c)
{
- return isupper(__c) ? _tolower(__c) : __c;
+ return isupper(__c) ? _tolower(__c) : __c;
}
#endif /* _CTYPE_H */
diff --git a/com32/include/dev.h b/com32/include/dev.h
index 54198e88..7809fb56 100644
--- a/com32/include/dev.h
+++ b/com32/include/dev.h
@@ -45,11 +45,11 @@ __extern int opendev(const struct input_dev *, const struct output_dev *, int);
/* Common generic devices */
/* Null device */
-extern const struct input_dev dev_null_r;
+extern const struct input_dev dev_null_r;
extern const struct output_dev dev_null_w;
/* Error device */
-extern const struct input_dev dev_error_r;
+extern const struct input_dev dev_error_r;
extern const struct output_dev dev_error_w;
#endif /* _DEV_H */
diff --git a/com32/include/dirent.h b/com32/include/dirent.h
index 956b911d..d99b21fb 100644
--- a/com32/include/dirent.h
+++ b/com32/include/dirent.h
@@ -15,17 +15,17 @@
#endif
struct dirent {
- long d_ino; /* Inode/File number */
- off_t d_size; /* Size of file */
- mode_t d_mode; /* Type of file */
- char d_name[NAME_MAX + 1];
+ long d_ino; /* Inode/File number */
+ off_t d_size; /* Size of file */
+ mode_t d_mode; /* Type of file */
+ char d_name[NAME_MAX + 1];
};
typedef struct {
- short dd_stat; /* status return from last lookup */
- uint16_t dd_fd;
- size_t dd_sect;
- char dd_name[NAME_MAX + 1]; /* directory */
+ short dd_stat; /* status return from last lookup */
+ uint16_t dd_fd;
+ size_t dd_sect;
+ char dd_name[NAME_MAX + 1]; /* directory */
} DIR;
__extern DIR *opendir(const char *);
@@ -33,4 +33,4 @@ __extern struct dirent *readdir(DIR *);
__extern int closedir(DIR *);
__extern DIR *fdopendir(int);
-#endif /* Not _DIRENT_H */
+#endif /* Not _DIRENT_H */
diff --git a/com32/include/elf.h b/com32/include/elf.h
index c543a812..970753db 100644
--- a/com32/include/elf.h
+++ b/com32/include/elf.h
@@ -8,4 +8,4 @@
#include <sys/elf32.h>
#include <sys/elf64.h>
-#endif /* _ELF_H */
+#endif /* _ELF_H */
diff --git a/com32/include/endian.h b/com32/include/endian.h
index a6cd6d9b..e65b1b94 100644
--- a/com32/include/endian.h
+++ b/com32/include/endian.h
@@ -12,4 +12,4 @@
#define PDP_ENDIAN __PDP_ENDIAN
#define BYTE_ORDER __BYTE_ORDER
-#endif /* _ENDIAN_H */
+#endif /* _ENDIAN_H */
diff --git a/com32/include/inttypes.h b/com32/include/inttypes.h
index e00fa631..b8631265 100644
--- a/com32/include/inttypes.h
+++ b/com32/include/inttypes.h
@@ -11,7 +11,7 @@
static __inline__ intmax_t imaxabs(intmax_t __n)
{
- return (__n < (intmax_t)0) ? -__n : __n;
+ return (__n < (intmax_t) 0) ? -__n : __n;
}
__extern intmax_t strtoimax(const char *, char **, int);
diff --git a/com32/include/klibc/archsetjmp.h b/com32/include/klibc/archsetjmp.h
index db04314b..a0def6a1 100644
--- a/com32/include/klibc/archsetjmp.h
+++ b/com32/include/klibc/archsetjmp.h
@@ -6,12 +6,12 @@
#define _KLIBC_ARCHSETJMP_H
struct __jmp_buf {
- unsigned int __ebx;
- unsigned int __esp;
- unsigned int __ebp;
- unsigned int __esi;
- unsigned int __edi;
- unsigned int __eip;
+ unsigned int __ebx;
+ unsigned int __esp;
+ unsigned int __ebp;
+ unsigned int __esi;
+ unsigned int __edi;
+ unsigned int __eip;
};
typedef struct __jmp_buf jmp_buf[1];
diff --git a/com32/include/klibc/diverr.h b/com32/include/klibc/diverr.h
index a4bbeddf..106f0624 100644
--- a/com32/include/klibc/diverr.h
+++ b/com32/include/klibc/diverr.h
@@ -1,4 +1,4 @@
static inline void __divide_error(void)
{
- asm volatile("int $0"); /* Divide by zero */
+ asm volatile ("int $0"); /* Divide by zero */
}
diff --git a/com32/include/klibc/endian.h b/com32/include/klibc/endian.h
index 7537a47e..94664212 100644
--- a/com32/include/klibc/endian.h
+++ b/com32/include/klibc/endian.h
@@ -35,4 +35,4 @@
# error "Unknown byte order!"
#endif
-#endif /* _KLIBC_ENDIAN_H */
+#endif /* _KLIBC_ENDIAN_H */
diff --git a/com32/include/netinet/in.h b/com32/include/netinet/in.h
index e8cacf6c..582632c9 100644
--- a/com32/include/netinet/in.h
+++ b/com32/include/netinet/in.h
@@ -7,7 +7,7 @@
static inline uint16_t __htons(uint16_t v)
{
- return ((v) << 8) | ((v) >> 8);
+ return ((v) << 8) | ((v) >> 8);
}
#define htons(x) __htons(x)
@@ -15,15 +15,14 @@ static inline uint16_t __htons(uint16_t v)
static inline uint32_t __htonl(uint32_t v)
{
- if ( __builtin_constant_p(v) ) {
- return (((v) & 0x000000ff) << 24) |
- (((v) & 0x0000ff00) << 8) |
- (((v) & 0x00ff0000) >> 8) |
- (((v) & 0xff000000) >> 24);
- } else {
- asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0" : "+q" (v));
- return v;
- }
+ if (__builtin_constant_p(v)) {
+ return (((v) & 0x000000ff) << 24) |
+ (((v) & 0x0000ff00) << 8) |
+ (((v) & 0x00ff0000) >> 8) | (((v) & 0xff000000) >> 24);
+ } else {
+asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0":"+q"(v));
+ return v;
+ }
}
#define htonl(x) __htonl(x)
@@ -31,7 +30,7 @@ static inline uint32_t __htonl(uint32_t v)
static inline uint64_t __htonq(uint64_t v)
{
- return ((uint64_t) __htonl(v) << 32) | __htonl(v >> 32);
+ return ((uint64_t) __htonl(v) << 32) | __htonl(v >> 32);
}
#define htonq(x) __htonq(x)
@@ -41,7 +40,7 @@ typedef uint32_t in_addr_t;
typedef uint16_t in_port_t;
struct in_addr {
- in_addr_t s_addr;
+ in_addr_t s_addr;
};
#endif /* _NETINET_IN_H */
diff --git a/com32/include/png.h b/com32/include/png.h
index 800b912e..d9e73c9c 100644
--- a/com32/include/png.h
+++ b/com32/include/png.h
@@ -338,12 +338,12 @@
#define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
/* Release-Specific Flags */
-#define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
- PNG_LIBPNG_BUILD_STABLE only */
-#define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
- PNG_LIBPNG_BUILD_SPECIAL */
-#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
- PNG_LIBPNG_BUILD_PRIVATE */
+#define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
+ PNG_LIBPNG_BUILD_STABLE only */
+#define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
+ PNG_LIBPNG_BUILD_SPECIAL */
+#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
+ PNG_LIBPNG_BUILD_PRIVATE */
#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
@@ -352,7 +352,7 @@
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
* version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */
-#define PNG_LIBPNG_VER 10208 /* 1.2.8 */
+#define PNG_LIBPNG_VER 10208 /* 1.2.8 */
#ifndef PNG_VERSION_INFO_ONLY
/* include the compression library's header */
@@ -392,7 +392,7 @@
/* Inhibit C++ name-mangling for libpng functions but not for system calls. */
#ifdef __cplusplus
extern "C" {
-#endif /* __cplusplus */
+#endif /* __cplusplus */
/* This file is arranged in several sections. The first section contains
* structure and type definitions. The second section contains the external
@@ -440,8 +440,8 @@ extern "C" {
* the version above.
*/
#ifdef PNG_USE_GLOBAL_ARRAYS
-PNG_EXPORT_VAR (const char) png_libpng_ver[18];
- /* need room for 99.99.99beta99z */
+ PNG_EXPORT_VAR(const char) png_libpng_ver[18];
+ /* need room for 99.99.99beta99z */
#else
#define png_libpng_ver png_get_header_ver(NULL)
#endif
@@ -449,86 +449,81 @@ PNG_EXPORT_VAR (const char) png_libpng_ver[18];
#ifdef PNG_USE_GLOBAL_ARRAYS
/* This was removed in version 1.0.5c */
/* Structures to facilitate easy interlacing. See png.c for more details */
-PNG_EXPORT_VAR (const int FARDATA) png_pass_start[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_inc[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_ystart[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_yinc[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_mask[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_dsp_mask[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_start[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_inc[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_ystart[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_yinc[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_mask[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_dsp_mask[7];
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
-PNG_EXPORT_VAR (const int FARDATA) png_pass_width[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_width[7];
#endif
/* This isn't currently used. If you need it, see png.c for more details.
PNG_EXPORT_VAR (const int FARDATA) png_pass_height[7];
*/
#endif
-#endif /* PNG_NO_EXTERN */
+#endif /* PNG_NO_EXTERN */
/* Three color definitions. The order of the red, green, and blue, (and the
* exact size) is not important, although the size of the fields need to
* be png_byte or png_uint_16 (as defined below).
*/
-typedef struct png_color_struct
-{
- png_byte red;
- png_byte green;
- png_byte blue;
-} png_color;
-typedef png_color FAR * png_colorp;
-typedef png_color FAR * FAR * png_colorpp;
-
-typedef struct png_color_16_struct
-{
- png_byte index; /* used for palette files */
- png_uint_16 red; /* for use in red green blue files */
- png_uint_16 green;
- png_uint_16 blue;
- png_uint_16 gray; /* for use in grayscale files */
-} png_color_16;
-typedef png_color_16 FAR * png_color_16p;
-typedef png_color_16 FAR * FAR * png_color_16pp;
-
-typedef struct png_color_8_struct
-{
- png_byte red; /* for use in red green blue files */
- png_byte green;
- png_byte blue;
- png_byte gray; /* for use in grayscale files */
- png_byte alpha; /* for alpha channel files */
-} png_color_8;
-typedef png_color_8 FAR * png_color_8p;
-typedef png_color_8 FAR * FAR * png_color_8pp;
+ typedef struct png_color_struct {
+ png_byte red;
+ png_byte green;
+ png_byte blue;
+ } png_color;
+ typedef png_color FAR *png_colorp;
+ typedef png_color FAR *FAR * png_colorpp;
+
+ typedef struct png_color_16_struct {
+ png_byte index; /* used for palette files */
+ png_uint_16 red; /* for use in red green blue files */
+ png_uint_16 green;
+ png_uint_16 blue;
+ png_uint_16 gray; /* for use in grayscale files */
+ } png_color_16;
+ typedef png_color_16 FAR *png_color_16p;
+ typedef png_color_16 FAR *FAR * png_color_16pp;
+
+ typedef struct png_color_8_struct {
+ png_byte red; /* for use in red green blue files */
+ png_byte green;
+ png_byte blue;
+ png_byte gray; /* for use in grayscale files */
+ png_byte alpha; /* for alpha channel files */
+ } png_color_8;
+ typedef png_color_8 FAR *png_color_8p;
+ typedef png_color_8 FAR *FAR * png_color_8pp;
/*
* The following two structures are used for the in-core representation
* of sPLT chunks.
*/
-typedef struct png_sPLT_entry_struct
-{
- png_uint_16 red;
- png_uint_16 green;
- png_uint_16 blue;
- png_uint_16 alpha;
- png_uint_16 frequency;
-} png_sPLT_entry;
-typedef png_sPLT_entry FAR * png_sPLT_entryp;
-typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
+ typedef struct png_sPLT_entry_struct {
+ png_uint_16 red;
+ png_uint_16 green;
+ png_uint_16 blue;
+ png_uint_16 alpha;
+ png_uint_16 frequency;
+ } png_sPLT_entry;
+ typedef png_sPLT_entry FAR *png_sPLT_entryp;
+ typedef png_sPLT_entry FAR *FAR * png_sPLT_entrypp;
/* When the depth of the sPLT palette is 8 bits, the color and alpha samples
* occupy the LSB of their respective members, and the MSB of each member
* is zero-filled. The frequency member always occupies the full 16 bits.
*/
-typedef struct png_sPLT_struct
-{
- png_charp name; /* palette name */
- png_byte depth; /* depth of palette samples */
- png_sPLT_entryp entries; /* palette entries */
- png_int_32 nentries; /* number of palette entries */
-} png_sPLT_t;
-typedef png_sPLT_t FAR * png_sPLT_tp;
-typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
+ typedef struct png_sPLT_struct {
+ png_charp name; /* palette name */
+ png_byte depth; /* depth of palette samples */
+ png_sPLT_entryp entries; /* palette entries */
+ png_int_32 nentries; /* number of palette entries */
+ } png_sPLT_t;
+ typedef png_sPLT_t FAR *png_sPLT_tp;
+ typedef png_sPLT_t FAR *FAR * png_sPLT_tpp;
#ifdef PNG_TEXT_SUPPORTED
/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file,
@@ -539,27 +534,26 @@ typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
* regular zero-terminated C strings (possibly empty), never NULL pointers,
* so they can be safely used in printf() and other string-handling functions.
*/
-typedef struct png_text_struct
-{
- int compression; /* compression value:
- -1: tEXt, none
- 0: zTXt, deflate
- 1: iTXt, none
- 2: iTXt, deflate */
- png_charp key; /* keyword, 1-79 character description of "text" */
- png_charp text; /* comment, may be an empty string (ie "")
- or a NULL pointer */
- png_size_t text_length; /* length of the text string */
+ typedef struct png_text_struct {
+ int compression; /* compression value:
+ -1: tEXt, none
+ 0: zTXt, deflate
+ 1: iTXt, none
+ 2: iTXt, deflate */
+ png_charp key; /* keyword, 1-79 character description of "text" */
+ png_charp text; /* comment, may be an empty string (ie "")
+ or a NULL pointer */
+ png_size_t text_length; /* length of the text string */
#ifdef PNG_iTXt_SUPPORTED
- png_size_t itxt_length; /* length of the itxt string */
- png_charp lang; /* language code, 0-79 characters
- or a NULL pointer */
- png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
- chars or a NULL pointer */
+ png_size_t itxt_length; /* length of the itxt string */
+ png_charp lang; /* language code, 0-79 characters
+ or a NULL pointer */
+ png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
+ chars or a NULL pointer */
#endif
-} png_text;
-typedef png_text FAR * png_textp;
-typedef png_text FAR * FAR * png_textpp;
+ } png_text;
+ typedef png_text FAR *png_textp;
+ typedef png_text FAR *FAR * png_textpp;
#endif
/* Supported compression types for text in PNG files (tEXt, and zTXt).
@@ -570,7 +564,7 @@ typedef png_text FAR * FAR * png_textpp;
#define PNG_TEXT_COMPRESSION_zTXt 0
#define PNG_ITXT_COMPRESSION_NONE 1
#define PNG_ITXT_COMPRESSION_zTXt 2
-#define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
+#define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
/* png_time is a way to hold the time in an machine independent way.
* Two conversions are provided, both from time_t and struct tm. There
@@ -578,17 +572,16 @@ typedef png_text FAR * FAR * png_textpp;
* as I know. If you know of a portable way, send it to me. As a side
* note - PNG has always been Year 2000 compliant!
*/
-typedef struct png_time_struct
-{
- png_uint_16 year; /* full year, as in, 1995 */
- png_byte month; /* month of year, 1 - 12 */
- png_byte day; /* day of month, 1 - 31 */
- png_byte hour; /* hour of day, 0 - 23 */
- png_byte minute; /* minute of hour, 0 - 59 */
- png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
-} png_time;
-typedef png_time FAR * png_timep;
-typedef png_time FAR * FAR * png_timepp;
+ typedef struct png_time_struct {
+ png_uint_16 year; /* full year, as in, 1995 */
+ png_byte month; /* month of year, 1 - 12 */
+ png_byte day; /* day of month, 1 - 31 */
+ png_byte hour; /* hour of day, 0 - 23 */
+ png_byte minute; /* minute of hour, 0 - 59 */
+ png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
+ } png_time;
+ typedef png_time FAR *png_timep;
+ typedef png_time FAR *FAR * png_timepp;
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
/* png_unknown_chunk is a structure to hold queued chunks for which there is
@@ -596,18 +589,16 @@ typedef png_time FAR * FAR * png_timepp;
* up private chunks for output even though the library doesn't actually
* know about their semantics.
*/
-typedef struct png_unknown_chunk_t
-{
- png_byte name[5];
- png_byte *data;
- png_size_t size;
-
- /* libpng-using applications should NOT directly modify this byte. */
- png_byte location; /* mode of operation at read time */
-}
-png_unknown_chunk;
-typedef png_unknown_chunk FAR * png_unknown_chunkp;
-typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
+ typedef struct png_unknown_chunk_t {
+ png_byte name[5];
+ png_byte *data;
+ png_size_t size;
+
+ /* libpng-using applications should NOT directly modify this byte. */
+ png_byte location; /* mode of operation at read time */
+ } png_unknown_chunk;
+ typedef png_unknown_chunk FAR *png_unknown_chunkp;
+ typedef png_unknown_chunk FAR *FAR * png_unknown_chunkpp;
#endif
/* png_info is a structure that holds the information in a PNG file so
@@ -649,246 +640,245 @@ typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
* itxt_ptr structure argument, and the png_set_rows and png_set_unknowns
* functions do not make their own copies.
*/
-typedef struct png_info_struct
-{
- /* the following are necessary for every PNG file */
- png_uint_32 width; /* width of image in pixels (from IHDR) */
- png_uint_32 height; /* height of image in pixels (from IHDR) */
- png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
- png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
- png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
- png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
- png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
- png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
- png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
- /* The following three should have been named *_method not *_type */
- png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
- png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
- png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
-
- /* The following is informational only on read, and not used on writes. */
- png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
- png_byte pixel_depth; /* number of bits per pixel */
- png_byte spare_byte; /* to align the data, and for future use */
- png_byte signature[8]; /* magic bytes read by libpng from start of file */
-
- /* The rest of the data is optional. If you are reading, check the
- * valid field to see if the information in these are valid. If you
- * are writing, set the valid field to those chunks you want written,
- * and initialize the appropriate fields below.
- */
+ typedef struct png_info_struct {
+ /* the following are necessary for every PNG file */
+ png_uint_32 width; /* width of image in pixels (from IHDR) */
+ png_uint_32 height; /* height of image in pixels (from IHDR) */
+ png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
+ png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
+ png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
+ png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
+ png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
+ png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
+ png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
+ /* The following three should have been named *_method not *_type */
+ png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
+ png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
+ png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
+
+ /* The following is informational only on read, and not used on writes. */
+ png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
+ png_byte pixel_depth; /* number of bits per pixel */
+ png_byte spare_byte; /* to align the data, and for future use */
+ png_byte signature[8]; /* magic bytes read by libpng from start of file */
+
+ /* The rest of the data is optional. If you are reading, check the
+ * valid field to see if the information in these are valid. If you
+ * are writing, set the valid field to those chunks you want written,
+ * and initialize the appropriate fields below.
+ */
#if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
- /* The gAMA chunk describes the gamma characteristics of the system
- * on which the image was created, normally in the range [1.0, 2.5].
- * Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
- */
- float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
+ /* The gAMA chunk describes the gamma characteristics of the system
+ * on which the image was created, normally in the range [1.0, 2.5].
+ * Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
+ */
+ float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
#endif
#if defined(PNG_sRGB_SUPPORTED)
- /* GR-P, 0.96a */
- /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
- png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
+ /* GR-P, 0.96a */
+ /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
+ png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
#endif
#if defined(PNG_TEXT_SUPPORTED)
- /* The tEXt, and zTXt chunks contain human-readable textual data in
- * uncompressed, compressed, and optionally compressed forms, respectively.
- * The data in "text" is an array of pointers to uncompressed,
- * null-terminated C strings. Each chunk has a keyword that describes the
- * textual data contained in that chunk. Keywords are not required to be
- * unique, and the text string may be empty. Any number of text chunks may
- * be in an image.
- */
- int num_text; /* number of comments read/to write */
- int max_text; /* current size of text array */
- png_textp text; /* array of comments read/to write */
-#endif /* PNG_TEXT_SUPPORTED */
+ /* The tEXt, and zTXt chunks contain human-readable textual data in
+ * uncompressed, compressed, and optionally compressed forms, respectively.
+ * The data in "text" is an array of pointers to uncompressed,
+ * null-terminated C strings. Each chunk has a keyword that describes the
+ * textual data contained in that chunk. Keywords are not required to be
+ * unique, and the text string may be empty. Any number of text chunks may
+ * be in an image.
+ */
+ int num_text; /* number of comments read/to write */
+ int max_text; /* current size of text array */
+ png_textp text; /* array of comments read/to write */
+#endif /* PNG_TEXT_SUPPORTED */
#if defined(PNG_tIME_SUPPORTED)
- /* The tIME chunk holds the last time the displayed image data was
- * modified. See the png_time struct for the contents of this struct.
- */
- png_time mod_time;
+ /* The tIME chunk holds the last time the displayed image data was
+ * modified. See the png_time struct for the contents of this struct.
+ */
+ png_time mod_time;
#endif
#if defined(PNG_sBIT_SUPPORTED)
- /* The sBIT chunk specifies the number of significant high-order bits
- * in the pixel data. Values are in the range [1, bit_depth], and are
- * only specified for the channels in the pixel data. The contents of
- * the low-order bits is not specified. Data is valid if
- * (valid & PNG_INFO_sBIT) is non-zero.
- */
- png_color_8 sig_bit; /* significant bits in color channels */
+ /* The sBIT chunk specifies the number of significant high-order bits
+ * in the pixel data. Values are in the range [1, bit_depth], and are
+ * only specified for the channels in the pixel data. The contents of
+ * the low-order bits is not specified. Data is valid if
+ * (valid & PNG_INFO_sBIT) is non-zero.
+ */
+ png_color_8 sig_bit; /* significant bits in color channels */
#endif
#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
defined(PNG_READ_BACKGROUND_SUPPORTED)
- /* The tRNS chunk supplies transparency data for paletted images and
- * other image types that don't need a full alpha channel. There are
- * "num_trans" transparency values for a paletted image, stored in the
- * same order as the palette colors, starting from index 0. Values
- * for the data are in the range [0, 255], ranging from fully transparent
- * to fully opaque, respectively. For non-paletted images, there is a
- * single color specified that should be treated as fully transparent.
- * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
- */
- png_bytep trans; /* transparent values for paletted image */
- png_color_16 trans_values; /* transparent color for non-palette image */
+ /* The tRNS chunk supplies transparency data for paletted images and
+ * other image types that don't need a full alpha channel. There are
+ * "num_trans" transparency values for a paletted image, stored in the
+ * same order as the palette colors, starting from index 0. Values
+ * for the data are in the range [0, 255], ranging from fully transparent
+ * to fully opaque, respectively. For non-paletted images, there is a
+ * single color specified that should be treated as fully transparent.
+ * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
+ */
+ png_bytep trans; /* transparent values for paletted image */
+ png_color_16 trans_values; /* transparent color for non-palette image */
#endif
#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
- /* The bKGD chunk gives the suggested image background color if the
- * display program does not have its own background color and the image
- * is needs to composited onto a background before display. The colors
- * in "background" are normally in the same color space/depth as the
- * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
- */
- png_color_16 background;
+ /* The bKGD chunk gives the suggested image background color if the
+ * display program does not have its own background color and the image
+ * is needs to composited onto a background before display. The colors
+ * in "background" are normally in the same color space/depth as the
+ * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
+ */
+ png_color_16 background;
#endif
#if defined(PNG_oFFs_SUPPORTED)
- /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
- * and downwards from the top-left corner of the display, page, or other
- * application-specific co-ordinate space. See the PNG_OFFSET_ defines
- * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero.
- */
- png_int_32 x_offset; /* x offset on page */
- png_int_32 y_offset; /* y offset on page */
- png_byte offset_unit_type; /* offset units type */
+ /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
+ * and downwards from the top-left corner of the display, page, or other
+ * application-specific co-ordinate space. See the PNG_OFFSET_ defines
+ * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero.
+ */
+ png_int_32 x_offset; /* x offset on page */
+ png_int_32 y_offset; /* y offset on page */
+ png_byte offset_unit_type; /* offset units type */
#endif
#if defined(PNG_pHYs_SUPPORTED)
- /* The pHYs chunk gives the physical pixel density of the image for
- * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
- * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
- */
- png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
- png_uint_32 y_pixels_per_unit; /* vertical pixel density */
- png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
+ /* The pHYs chunk gives the physical pixel density of the image for
+ * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
+ * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
+ */
+ png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
+ png_uint_32 y_pixels_per_unit; /* vertical pixel density */
+ png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
#endif
#if defined(PNG_hIST_SUPPORTED)
- /* The hIST chunk contains the relative frequency or importance of the
- * various palette entries, so that a viewer can intelligently select a
- * reduced-color palette, if required. Data is an array of "num_palette"
- * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
- * is non-zero.
- */
- png_uint_16p hist;
+ /* The hIST chunk contains the relative frequency or importance of the
+ * various palette entries, so that a viewer can intelligently select a
+ * reduced-color palette, if required. Data is an array of "num_palette"
+ * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
+ * is non-zero.
+ */
+ png_uint_16p hist;
#endif
#ifdef PNG_cHRM_SUPPORTED
- /* The cHRM chunk describes the CIE color characteristics of the monitor
- * on which the PNG was created. This data allows the viewer to do gamut
- * mapping of the input image to ensure that the viewer sees the same
- * colors in the image as the creator. Values are in the range
- * [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero.
- */
+ /* The cHRM chunk describes the CIE color characteristics of the monitor
+ * on which the PNG was created. This data allows the viewer to do gamut
+ * mapping of the input image to ensure that the viewer sees the same
+ * colors in the image as the creator. Values are in the range
+ * [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero.
+ */
#ifdef PNG_FLOATING_POINT_SUPPORTED
- float x_white;
- float y_white;
- float x_red;
- float y_red;
- float x_green;
- float y_green;
- float x_blue;
- float y_blue;
+ float x_white;
+ float y_white;
+ float x_red;
+ float y_red;
+ float x_green;
+ float y_green;
+ float x_blue;
+ float y_blue;
#endif
#endif
#if defined(PNG_pCAL_SUPPORTED)
- /* The pCAL chunk describes a transformation between the stored pixel
- * values and original physical data values used to create the image.
- * The integer range [0, 2^bit_depth - 1] maps to the floating-point
- * range given by [pcal_X0, pcal_X1], and are further transformed by a
- * (possibly non-linear) transformation function given by "pcal_type"
- * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_
- * defines below, and the PNG-Group's PNG extensions document for a
- * complete description of the transformations and how they should be
- * implemented, and for a description of the ASCII parameter strings.
- * Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
- */
- png_charp pcal_purpose; /* pCAL chunk description string */
- png_int_32 pcal_X0; /* minimum value */
- png_int_32 pcal_X1; /* maximum value */
- png_charp pcal_units; /* Latin-1 string giving physical units */
- png_charpp pcal_params; /* ASCII strings containing parameter values */
- png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
- png_byte pcal_nparams; /* number of parameters given in pcal_params */
+ /* The pCAL chunk describes a transformation between the stored pixel
+ * values and original physical data values used to create the image.
+ * The integer range [0, 2^bit_depth - 1] maps to the floating-point
+ * range given by [pcal_X0, pcal_X1], and are further transformed by a
+ * (possibly non-linear) transformation function given by "pcal_type"
+ * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_
+ * defines below, and the PNG-Group's PNG extensions document for a
+ * complete description of the transformations and how they should be
+ * implemented, and for a description of the ASCII parameter strings.
+ * Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
+ */
+ png_charp pcal_purpose; /* pCAL chunk description string */
+ png_int_32 pcal_X0; /* minimum value */
+ png_int_32 pcal_X1; /* maximum value */
+ png_charp pcal_units; /* Latin-1 string giving physical units */
+ png_charpp pcal_params; /* ASCII strings containing parameter values */
+ png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
+ png_byte pcal_nparams; /* number of parameters given in pcal_params */
#endif
/* New members added in libpng-1.0.6 */
#ifdef PNG_FREE_ME_SUPPORTED
- png_uint_32 free_me; /* flags items libpng is responsible for freeing */
+ png_uint_32 free_me; /* flags items libpng is responsible for freeing */
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
- /* storage for unknown chunks that the library doesn't recognize. */
- png_unknown_chunkp unknown_chunks;
- png_size_t unknown_chunks_num;
+ /* storage for unknown chunks that the library doesn't recognize. */
+ png_unknown_chunkp unknown_chunks;
+ png_size_t unknown_chunks_num;
#endif
#if defined(PNG_iCCP_SUPPORTED)
- /* iCCP chunk data. */
- png_charp iccp_name; /* profile name */
- png_charp iccp_profile; /* International Color Consortium profile data */
- /* Note to maintainer: should be png_bytep */
- png_uint_32 iccp_proflen; /* ICC profile data length */
- png_byte iccp_compression; /* Always zero */
+ /* iCCP chunk data. */
+ png_charp iccp_name; /* profile name */
+ png_charp iccp_profile; /* International Color Consortium profile data */
+ /* Note to maintainer: should be png_bytep */
+ png_uint_32 iccp_proflen; /* ICC profile data length */
+ png_byte iccp_compression; /* Always zero */
#endif
#if defined(PNG_sPLT_SUPPORTED)
- /* data on sPLT chunks (there may be more than one). */
- png_sPLT_tp splt_palettes;
- png_uint_32 splt_palettes_num;
+ /* data on sPLT chunks (there may be more than one). */
+ png_sPLT_tp splt_palettes;
+ png_uint_32 splt_palettes_num;
#endif
#if defined(PNG_sCAL_SUPPORTED)
- /* The sCAL chunk describes the actual physical dimensions of the
- * subject matter of the graphic. The chunk contains a unit specification
- * a byte value, and two ASCII strings representing floating-point
- * values. The values are width and height corresponsing to one pixel
- * in the image. This external representation is converted to double
- * here. Data values are valid if (valid & PNG_INFO_sCAL) is non-zero.
- */
- png_byte scal_unit; /* unit of physical scale */
+ /* The sCAL chunk describes the actual physical dimensions of the
+ * subject matter of the graphic. The chunk contains a unit specification
+ * a byte value, and two ASCII strings representing floating-point
+ * values. The values are width and height corresponsing to one pixel
+ * in the image. This external representation is converted to double
+ * here. Data values are valid if (valid & PNG_INFO_sCAL) is non-zero.
+ */
+ png_byte scal_unit; /* unit of physical scale */
#ifdef PNG_FLOATING_POINT_SUPPORTED
- double scal_pixel_width; /* width of one pixel */
- double scal_pixel_height; /* height of one pixel */
+ double scal_pixel_width; /* width of one pixel */
+ double scal_pixel_height; /* height of one pixel */
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
- png_charp scal_s_width; /* string containing height */
- png_charp scal_s_height; /* string containing width */
+ png_charp scal_s_width; /* string containing height */
+ png_charp scal_s_height; /* string containing width */
#endif
#endif
#if defined(PNG_INFO_IMAGE_SUPPORTED)
- /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) non-zero */
- /* Data valid if (valid & PNG_INFO_IDAT) non-zero */
- png_bytepp row_pointers; /* the image bits */
+ /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) non-zero */
+ /* Data valid if (valid & PNG_INFO_IDAT) non-zero */
+ png_bytepp row_pointers; /* the image bits */
#endif
#if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
- png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
+ png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
#endif
#if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
- png_fixed_point int_x_white;
- png_fixed_point int_y_white;
- png_fixed_point int_x_red;
- png_fixed_point int_y_red;
- png_fixed_point int_x_green;
- png_fixed_point int_y_green;
- png_fixed_point int_x_blue;
- png_fixed_point int_y_blue;
+ png_fixed_point int_x_white;
+ png_fixed_point int_y_white;
+ png_fixed_point int_x_red;
+ png_fixed_point int_y_red;
+ png_fixed_point int_x_green;
+ png_fixed_point int_y_green;
+ png_fixed_point int_x_blue;
+ png_fixed_point int_y_blue;
#endif
-} png_info;
+ } png_info;
-typedef png_info FAR * png_infop;
-typedef png_info FAR * FAR * png_infopp;
+ typedef png_info FAR *png_infop;
+ typedef png_info FAR *FAR * png_infopp;
/* Maximum positive integer used in PNG is (2^31)-1 */
#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
@@ -914,48 +904,48 @@ typedef png_info FAR * FAR * png_infopp;
#define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
/* This is for compression type. PNG 1.0-1.2 only define the single type. */
-#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
+#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
/* This is for filter type. PNG 1.0-1.2 only define the single type. */
-#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
-#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
+#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
+#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
/* These are for the interlacing type. These values should NOT be changed. */
-#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
-#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
-#define PNG_INTERLACE_LAST 2 /* Not a valid value */
+#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
+#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
+#define PNG_INTERLACE_LAST 2 /* Not a valid value */
/* These are for the oFFs chunk. These values should NOT be changed. */
-#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
-#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
-#define PNG_OFFSET_LAST 2 /* Not a valid value */
+#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
+#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
+#define PNG_OFFSET_LAST 2 /* Not a valid value */
/* These are for the pCAL chunk. These values should NOT be changed. */
-#define PNG_EQUATION_LINEAR 0 /* Linear transformation */
-#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
-#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
-#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
-#define PNG_EQUATION_LAST 4 /* Not a valid value */
+#define PNG_EQUATION_LINEAR 0 /* Linear transformation */
+#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
+#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
+#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
+#define PNG_EQUATION_LAST 4 /* Not a valid value */
/* These are for the sCAL chunk. These values should NOT be changed. */
-#define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
-#define PNG_SCALE_METER 1 /* meters per pixel */
-#define PNG_SCALE_RADIAN 2 /* radians per pixel */
-#define PNG_SCALE_LAST 3 /* Not a valid value */
+#define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
+#define PNG_SCALE_METER 1 /* meters per pixel */
+#define PNG_SCALE_RADIAN 2 /* radians per pixel */
+#define PNG_SCALE_LAST 3 /* Not a valid value */
/* These are for the pHYs chunk. These values should NOT be changed. */
-#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
-#define PNG_RESOLUTION_METER 1 /* pixels/meter */
-#define PNG_RESOLUTION_LAST 2 /* Not a valid value */
+#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
+#define PNG_RESOLUTION_METER 1 /* pixels/meter */
+#define PNG_RESOLUTION_LAST 2 /* Not a valid value */
/* These are for the sRGB chunk. These values should NOT be changed. */
#define PNG_sRGB_INTENT_PERCEPTUAL 0
#define PNG_sRGB_INTENT_RELATIVE 1
#define PNG_sRGB_INTENT_SATURATION 2
#define PNG_sRGB_INTENT_ABSOLUTE 3
-#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
+#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
/* This is for text chunks */
#define PNG_KEYWORD_MAX_LENGTH 79
@@ -979,28 +969,27 @@ typedef png_info FAR * FAR * png_infopp;
#define PNG_INFO_oFFs 0x0100
#define PNG_INFO_tIME 0x0200
#define PNG_INFO_pCAL 0x0400
-#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
-#define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
-#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
-#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
-#define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
+#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
+#define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
+#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
+#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
+#define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
/* This is used for the transformation routines, as some of them
* change these values for the row. It also should enable using
* the routines for other purposes.
*/
-typedef struct png_row_info_struct
-{
- png_uint_32 width; /* width of row */
- png_uint_32 rowbytes; /* number of bytes in row */
- png_byte color_type; /* color type of row */
- png_byte bit_depth; /* bit depth of row */
- png_byte channels; /* number of channels (1, 2, 3, or 4) */
- png_byte pixel_depth; /* bits per pixel (depth * channels) */
-} png_row_info;
-
-typedef png_row_info FAR * png_row_infop;
-typedef png_row_info FAR * FAR * png_row_infopp;
+ typedef struct png_row_info_struct {
+ png_uint_32 width; /* width of row */
+ png_uint_32 rowbytes; /* number of bytes in row */
+ png_byte color_type; /* color type of row */
+ png_byte bit_depth; /* bit depth of row */
+ png_byte channels; /* number of channels (1, 2, 3, or 4) */
+ png_byte pixel_depth; /* bits per pixel (depth * channels) */
+ } png_row_info;
+
+ typedef png_row_info FAR *png_row_infop;
+ typedef png_row_info FAR *FAR * png_row_infopp;
/* These are the function types for the I/O functions and for the functions
* that allow the user to override the default I/O functions with his or her
@@ -1008,60 +997,67 @@ typedef png_row_info FAR * FAR * png_row_infopp;
* and error functions, while the png_rw_ptr type should match that of the
* user read/write data functions.
*/
-typedef struct png_struct_def png_struct;
-typedef png_struct FAR * png_structp;
-
-typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
-typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
-typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
-typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
- int));
-typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
- int));
+ typedef struct png_struct_def png_struct;
+ typedef png_struct FAR *png_structp;
+
+ typedef void (PNGAPI *
+ png_error_ptr) PNGARG((png_structp, png_const_charp));
+ typedef void (PNGAPI *
+ png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
+ typedef void (PNGAPI * png_flush_ptr) PNGARG((png_structp));
+ typedef void (PNGAPI *
+ png_read_status_ptr) PNGARG((png_structp, png_uint_32, int));
+ typedef void (PNGAPI *
+ png_write_status_ptr) PNGARG((png_structp, png_uint_32, int));
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
-typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
-typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
-typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
- png_uint_32, int));
+ typedef void (PNGAPI *
+ png_progressive_info_ptr) PNGARG((png_structp, png_infop));
+ typedef void (PNGAPI *
+ png_progressive_end_ptr) PNGARG((png_structp, png_infop));
+ typedef void (PNGAPI *
+ png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
+ png_uint_32, int));
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_LEGACY_SUPPORTED)
-typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
- png_row_infop, png_bytep));
+ typedef void (PNGAPI * png_user_transform_ptr) PNGARG((png_structp,
+ png_row_infop,
+ png_bytep));
#endif
#if defined(PNG_USER_CHUNKS_SUPPORTED)
-typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
+ typedef int (PNGAPI *
+ png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
-typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
+ typedef void (PNGAPI * png_unknown_chunk_ptr) PNGARG((png_structp));
#endif
/* Transform masks for the high-level interface */
-#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
-#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
-#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
-#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
-#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
-#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
-#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
-#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
-#define PNG_TRANSFORM_BGR 0x0080 /* read and write */
-#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
-#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
-#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
-#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
+#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
+#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
+#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
+#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
+#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
+#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
+#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
+#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
+#define PNG_TRANSFORM_BGR 0x0080 /* read and write */
+#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
+#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
+#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
+#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
/* Flags for MNG supported features */
#define PNG_FLAG_MNG_EMPTY_PLTE 0x01
#define PNG_FLAG_MNG_FILTER_64 0x04
#define PNG_ALL_MNG_FEATURES 0x05
-typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
-typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
+ typedef png_voidp(*png_malloc_ptr) PNGARG((png_structp, png_size_t));
+ typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
/* The structure that holds the information to read and write PNG files.
* The only people who need to care about what is inside of this are the
@@ -1070,223 +1066,222 @@ typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
* the jmp_buf.
*/
-struct png_struct_def
-{
+ struct png_struct_def {
#ifdef PNG_SETJMP_SUPPORTED
- jmp_buf jmpbuf; /* used in png_error */
+ jmp_buf jmpbuf; /* used in png_error */
#endif
- png_error_ptr error_fn; /* function for printing errors and aborting */
- png_error_ptr warning_fn; /* function for printing warnings */
- png_voidp error_ptr; /* user supplied struct for error functions */
- png_rw_ptr write_data_fn; /* function for writing output data */
- png_rw_ptr read_data_fn; /* function for reading input data */
- png_voidp io_ptr; /* ptr to application struct for I/O functions */
+ png_error_ptr error_fn; /* function for printing errors and aborting */
+ png_error_ptr warning_fn; /* function for printing warnings */
+ png_voidp error_ptr; /* user supplied struct for error functions */
+ png_rw_ptr write_data_fn; /* function for writing output data */
+ png_rw_ptr read_data_fn; /* function for reading input data */
+ png_voidp io_ptr; /* ptr to application struct for I/O functions */
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
- png_user_transform_ptr read_user_transform_fn; /* user read transform */
+ png_user_transform_ptr read_user_transform_fn; /* user read transform */
#endif
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
- png_user_transform_ptr write_user_transform_fn; /* user write transform */
+ png_user_transform_ptr write_user_transform_fn; /* user write transform */
#endif
/* These were added in libpng-1.0.2 */
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
- png_voidp user_transform_ptr; /* user supplied struct for user transform */
- png_byte user_transform_depth; /* bit depth of user transformed pixels */
- png_byte user_transform_channels; /* channels in user transformed pixels */
-#endif
-#endif
-
- png_uint_32 mode; /* tells us where we are in the PNG file */
- png_uint_32 flags; /* flags indicating various things to libpng */
- png_uint_32 transformations; /* which transformations to perform */
-
- z_stream zstream; /* pointer to decompression structure (below) */
- png_bytep zbuf; /* buffer for zlib */
- png_size_t zbuf_size; /* size of zbuf */
- int zlib_level; /* holds zlib compression level */
- int zlib_method; /* holds zlib compression method */
- int zlib_window_bits; /* holds zlib compression window bits */
- int zlib_mem_level; /* holds zlib compression memory level */
- int zlib_strategy; /* holds zlib compression strategy */
-
- png_uint_32 width; /* width of image in pixels */
- png_uint_32 height; /* height of image in pixels */
- png_uint_32 num_rows; /* number of rows in current pass */
- png_uint_32 usr_width; /* width of row at start of write */
- png_uint_32 rowbytes; /* size of row in bytes */
- png_uint_32 irowbytes; /* size of current interlaced row in bytes */
- png_uint_32 iwidth; /* width of current interlaced row in pixels */
- png_uint_32 row_number; /* current row in interlace pass */
- png_bytep prev_row; /* buffer to save previous (unfiltered) row */
- png_bytep row_buf; /* buffer to save current (unfiltered) row */
- png_bytep sub_row; /* buffer to save "sub" row when filtering */
- png_bytep up_row; /* buffer to save "up" row when filtering */
- png_bytep avg_row; /* buffer to save "avg" row when filtering */
- png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
- png_row_info row_info; /* used for transformation routines */
-
- png_uint_32 idat_size; /* current IDAT size for read */
- png_uint_32 crc; /* current chunk CRC value */
- png_colorp palette; /* palette from the input file */
- png_uint_16 num_palette; /* number of color entries in palette */
- png_uint_16 num_trans; /* number of transparency values */
- png_byte chunk_name[5]; /* null-terminated name of current chunk */
- png_byte compression; /* file compression type (always 0) */
- png_byte filter; /* file filter type (always 0) */
- png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
- png_byte pass; /* current interlace pass (0 - 6) */
- png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
- png_byte color_type; /* color type of file */
- png_byte bit_depth; /* bit depth of file */
- png_byte usr_bit_depth; /* bit depth of users row */
- png_byte pixel_depth; /* number of bits per pixel */
- png_byte channels; /* number of channels in file */
- png_byte usr_channels; /* channels at start of write */
- png_byte sig_bytes; /* magic bytes read/written from start of file */
+ png_voidp user_transform_ptr; /* user supplied struct for user transform */
+ png_byte user_transform_depth; /* bit depth of user transformed pixels */
+ png_byte user_transform_channels; /* channels in user transformed pixels */
+#endif
+#endif
+
+ png_uint_32 mode; /* tells us where we are in the PNG file */
+ png_uint_32 flags; /* flags indicating various things to libpng */
+ png_uint_32 transformations; /* which transformations to perform */
+
+ z_stream zstream; /* pointer to decompression structure (below) */
+ png_bytep zbuf; /* buffer for zlib */
+ png_size_t zbuf_size; /* size of zbuf */
+ int zlib_level; /* holds zlib compression level */
+ int zlib_method; /* holds zlib compression method */
+ int zlib_window_bits; /* holds zlib compression window bits */
+ int zlib_mem_level; /* holds zlib compression memory level */
+ int zlib_strategy; /* holds zlib compression strategy */
+
+ png_uint_32 width; /* width of image in pixels */
+ png_uint_32 height; /* height of image in pixels */
+ png_uint_32 num_rows; /* number of rows in current pass */
+ png_uint_32 usr_width; /* width of row at start of write */
+ png_uint_32 rowbytes; /* size of row in bytes */
+ png_uint_32 irowbytes; /* size of current interlaced row in bytes */
+ png_uint_32 iwidth; /* width of current interlaced row in pixels */
+ png_uint_32 row_number; /* current row in interlace pass */
+ png_bytep prev_row; /* buffer to save previous (unfiltered) row */
+ png_bytep row_buf; /* buffer to save current (unfiltered) row */
+ png_bytep sub_row; /* buffer to save "sub" row when filtering */
+ png_bytep up_row; /* buffer to save "up" row when filtering */
+ png_bytep avg_row; /* buffer to save "avg" row when filtering */
+ png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
+ png_row_info row_info; /* used for transformation routines */
+
+ png_uint_32 idat_size; /* current IDAT size for read */
+ png_uint_32 crc; /* current chunk CRC value */
+ png_colorp palette; /* palette from the input file */
+ png_uint_16 num_palette; /* number of color entries in palette */
+ png_uint_16 num_trans; /* number of transparency values */
+ png_byte chunk_name[5]; /* null-terminated name of current chunk */
+ png_byte compression; /* file compression type (always 0) */
+ png_byte filter; /* file filter type (always 0) */
+ png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
+ png_byte pass; /* current interlace pass (0 - 6) */
+ png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
+ png_byte color_type; /* color type of file */
+ png_byte bit_depth; /* bit depth of file */
+ png_byte usr_bit_depth; /* bit depth of users row */
+ png_byte pixel_depth; /* number of bits per pixel */
+ png_byte channels; /* number of channels in file */
+ png_byte usr_channels; /* channels at start of write */
+ png_byte sig_bytes; /* magic bytes read/written from start of file */
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
#ifdef PNG_LEGACY_SUPPORTED
- png_byte filler; /* filler byte for pixel expansion */
+ png_byte filler; /* filler byte for pixel expansion */
#else
- png_uint_16 filler; /* filler bytes for pixel expansion */
+ png_uint_16 filler; /* filler bytes for pixel expansion */
#endif
#endif
#if defined(PNG_bKGD_SUPPORTED)
- png_byte background_gamma_type;
+ png_byte background_gamma_type;
# ifdef PNG_FLOATING_POINT_SUPPORTED
- float background_gamma;
+ float background_gamma;
# endif
- png_color_16 background; /* background color in screen gamma space */
+ png_color_16 background; /* background color in screen gamma space */
#if defined(PNG_READ_GAMMA_SUPPORTED)
- png_color_16 background_1; /* background normalized to gamma 1.0 */
+ png_color_16 background_1; /* background normalized to gamma 1.0 */
#endif
-#endif /* PNG_bKGD_SUPPORTED */
+#endif /* PNG_bKGD_SUPPORTED */
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
- png_flush_ptr output_flush_fn;/* Function for flushing output */
- png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
- png_uint_32 flush_rows; /* number of rows written since last flush */
+ png_flush_ptr output_flush_fn; /* Function for flushing output */
+ png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
+ png_uint_32 flush_rows; /* number of rows written since last flush */
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
- int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
+ int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
#ifdef PNG_FLOATING_POINT_SUPPORTED
- float gamma; /* file gamma value */
- float screen_gamma; /* screen gamma value (display_exponent) */
+ float gamma; /* file gamma value */
+ float screen_gamma; /* screen gamma value (display_exponent) */
#endif
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
- png_bytep gamma_table; /* gamma table for 8-bit depth files */
- png_bytep gamma_from_1; /* converts from 1.0 to screen */
- png_bytep gamma_to_1; /* converts from file to 1.0 */
- png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
- png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
- png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
+ png_bytep gamma_table; /* gamma table for 8-bit depth files */
+ png_bytep gamma_from_1; /* converts from 1.0 to screen */
+ png_bytep gamma_to_1; /* converts from file to 1.0 */
+ png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
+ png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
+ png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
- png_color_8 sig_bit; /* significant bits in each available channel */
+ png_color_8 sig_bit; /* significant bits in each available channel */
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
- png_color_8 shift; /* shift for significant bit tranformation */
+ png_color_8 shift; /* shift for significant bit tranformation */
#endif
#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
|| defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
- png_bytep trans; /* transparency values for paletted files */
- png_color_16 trans_values; /* transparency values for non-paletted files */
+ png_bytep trans; /* transparency values for paletted files */
+ png_color_16 trans_values; /* transparency values for non-paletted files */
#endif
- png_read_status_ptr read_row_fn; /* called after each row is decoded */
- png_write_status_ptr write_row_fn; /* called after each row is encoded */
+ png_read_status_ptr read_row_fn; /* called after each row is decoded */
+ png_write_status_ptr write_row_fn; /* called after each row is encoded */
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
- png_progressive_info_ptr info_fn; /* called after header data fully read */
- png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
- png_progressive_end_ptr end_fn; /* called after image is complete */
- png_bytep save_buffer_ptr; /* current location in save_buffer */
- png_bytep save_buffer; /* buffer for previously read data */
- png_bytep current_buffer_ptr; /* current location in current_buffer */
- png_bytep current_buffer; /* buffer for recently used data */
- png_uint_32 push_length; /* size of current input chunk */
- png_uint_32 skip_length; /* bytes to skip in input data */
- png_size_t save_buffer_size; /* amount of data now in save_buffer */
- png_size_t save_buffer_max; /* total size of save_buffer */
- png_size_t buffer_size; /* total amount of available input data */
- png_size_t current_buffer_size; /* amount of data now in current_buffer */
- int process_mode; /* what push library is currently doing */
- int cur_palette; /* current push library palette index */
+ png_progressive_info_ptr info_fn; /* called after header data fully read */
+ png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
+ png_progressive_end_ptr end_fn; /* called after image is complete */
+ png_bytep save_buffer_ptr; /* current location in save_buffer */
+ png_bytep save_buffer; /* buffer for previously read data */
+ png_bytep current_buffer_ptr; /* current location in current_buffer */
+ png_bytep current_buffer; /* buffer for recently used data */
+ png_uint_32 push_length; /* size of current input chunk */
+ png_uint_32 skip_length; /* bytes to skip in input data */
+ png_size_t save_buffer_size; /* amount of data now in save_buffer */
+ png_size_t save_buffer_max; /* total size of save_buffer */
+ png_size_t buffer_size; /* total amount of available input data */
+ png_size_t current_buffer_size; /* amount of data now in current_buffer */
+ int process_mode; /* what push library is currently doing */
+ int cur_palette; /* current push library palette index */
# if defined(PNG_TEXT_SUPPORTED)
- png_size_t current_text_size; /* current size of text input data */
- png_size_t current_text_left; /* how much text left to read in input */
- png_charp current_text; /* current text chunk buffer */
- png_charp current_text_ptr; /* current location in current_text */
-# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */
+ png_size_t current_text_size; /* current size of text input data */
+ png_size_t current_text_left; /* how much text left to read in input */
+ png_charp current_text; /* current text chunk buffer */
+ png_charp current_text_ptr; /* current location in current_text */
+# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */
-#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* for the Borland special 64K segment handler */
- png_bytepp offset_table_ptr;
- png_bytep offset_table;
- png_uint_16 offset_table_number;
- png_uint_16 offset_table_count;
- png_uint_16 offset_table_count_free;
+ png_bytepp offset_table_ptr;
+ png_bytep offset_table;
+ png_uint_16 offset_table_number;
+ png_uint_16 offset_table_count;
+ png_uint_16 offset_table_count_free;
#endif
#if defined(PNG_READ_DITHER_SUPPORTED)
- png_bytep palette_lookup; /* lookup table for dithering */
- png_bytep dither_index; /* index translation for palette files */
+ png_bytep palette_lookup; /* lookup table for dithering */
+ png_bytep dither_index; /* index translation for palette files */
#endif
#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
- png_uint_16p hist; /* histogram */
+ png_uint_16p hist; /* histogram */
#endif
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
- png_byte heuristic_method; /* heuristic for row filter selection */
- png_byte num_prev_filters; /* number of weights for previous rows */
- png_bytep prev_filters; /* filter type(s) of previous row(s) */
- png_uint_16p filter_weights; /* weight(s) for previous line(s) */
- png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
- png_uint_16p filter_costs; /* relative filter calculation cost */
- png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
+ png_byte heuristic_method; /* heuristic for row filter selection */
+ png_byte num_prev_filters; /* number of weights for previous rows */
+ png_bytep prev_filters; /* filter type(s) of previous row(s) */
+ png_uint_16p filter_weights; /* weight(s) for previous line(s) */
+ png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
+ png_uint_16p filter_costs; /* relative filter calculation cost */
+ png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
- png_charp time_buffer; /* String to hold RFC 1123 time text */
+ png_charp time_buffer; /* String to hold RFC 1123 time text */
#endif
/* New members added in libpng-1.0.6 */
#ifdef PNG_FREE_ME_SUPPORTED
- png_uint_32 free_me; /* flags items libpng is responsible for freeing */
+ png_uint_32 free_me; /* flags items libpng is responsible for freeing */
#endif
#if defined(PNG_USER_CHUNKS_SUPPORTED)
- png_voidp user_chunk_ptr;
- png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
+ png_voidp user_chunk_ptr;
+ png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
- int num_chunk_list;
- png_bytep chunk_list;
+ int num_chunk_list;
+ png_bytep chunk_list;
#endif
/* New members added in libpng-1.0.3 */
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
- png_byte rgb_to_gray_status;
- /* These were changed from png_byte in libpng-1.0.6 */
- png_uint_16 rgb_to_gray_red_coeff;
- png_uint_16 rgb_to_gray_green_coeff;
- png_uint_16 rgb_to_gray_blue_coeff;
+ png_byte rgb_to_gray_status;
+ /* These were changed from png_byte in libpng-1.0.6 */
+ png_uint_16 rgb_to_gray_red_coeff;
+ png_uint_16 rgb_to_gray_green_coeff;
+ png_uint_16 rgb_to_gray_blue_coeff;
#endif
/* New member added in libpng-1.0.4 (renamed in 1.0.9) */
@@ -1295,70 +1290,69 @@ struct png_struct_def
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
/* changed from png_byte to png_uint_32 at version 1.2.0 */
#ifdef PNG_1_0_X
- png_byte mng_features_permitted;
+ png_byte mng_features_permitted;
#else
- png_uint_32 mng_features_permitted;
-#endif /* PNG_1_0_X */
+ png_uint_32 mng_features_permitted;
+#endif /* PNG_1_0_X */
#endif
/* New member added in libpng-1.0.7 */
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
- png_fixed_point int_gamma;
+ png_fixed_point int_gamma;
#endif
/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
#if defined(PNG_MNG_FEATURES_SUPPORTED)
- png_byte filter_type;
+ png_byte filter_type;
#endif
#if defined(PNG_1_0_X) || (defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD))
/* New member added in libpng-1.0.10, ifdef'ed out in 1.2.0 */
- png_uint_32 row_buf_size;
+ png_uint_32 row_buf_size;
#endif
/* New members added in libpng-1.2.0 */
#if !defined(PNG_1_0_X) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
- png_byte mmx_bitdepth_threshold;
- png_uint_32 mmx_rowbytes_threshold;
- png_uint_32 asm_flags;
+ png_byte mmx_bitdepth_threshold;
+ png_uint_32 mmx_rowbytes_threshold;
+ png_uint_32 asm_flags;
#endif
/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
#ifdef PNG_USER_MEM_SUPPORTED
- png_voidp mem_ptr; /* user supplied struct for mem functions */
- png_malloc_ptr malloc_fn; /* function for allocating memory */
- png_free_ptr free_fn; /* function for freeing memory */
+ png_voidp mem_ptr; /* user supplied struct for mem functions */
+ png_malloc_ptr malloc_fn; /* function for allocating memory */
+ png_free_ptr free_fn; /* function for freeing memory */
#endif
/* New member added in libpng-1.0.13 and 1.2.0 */
- png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
+ png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
#if defined(PNG_READ_DITHER_SUPPORTED)
/* The following three members were added at version 1.0.14 and 1.2.4 */
- png_bytep dither_sort; /* working sort array */
- png_bytep index_to_palette; /* where the original index currently is */
- /* in the palette */
- png_bytep palette_to_index; /* which original index points to this */
- /* palette color */
+ png_bytep dither_sort; /* working sort array */
+ png_bytep index_to_palette; /* where the original index currently is */
+ /* in the palette */
+ png_bytep palette_to_index; /* which original index points to this */
+ /* palette color */
#endif
/* New members added in libpng-1.0.16 and 1.2.6 */
- png_byte compression_type;
+ png_byte compression_type;
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
- png_uint_32 user_width_max;
- png_uint_32 user_height_max;
+ png_uint_32 user_width_max;
+ png_uint_32 user_height_max;
#endif
-};
-
+ };
/* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number.
*/
-typedef png_structp version_1_2_8;
+ typedef png_structp version_1_2_8;
-typedef png_struct FAR * FAR * png_structpp;
+ typedef png_struct FAR *FAR * png_structpp;
/* Here are the function definitions most commonly used. This is not
* the place to find out how to use libpng. See libpng.txt for the
@@ -1367,218 +1361,244 @@ typedef png_struct FAR * FAR * png_structpp;
*/
/* Returns the version number of the library */
-extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
+ extern PNG_EXPORT(png_uint_32, png_access_version_number) PNGARG((void));
/* Tell lib we have already handled the first <num_bytes> magic bytes.
* Handling more than 8 bytes from the beginning of the file is an error.
*/
-extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
- int num_bytes));
+ extern PNG_EXPORT(void, png_set_sig_bytes) PNGARG((png_structp png_ptr,
+ int num_bytes));
/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a
* PNG file. Returns zero if the supplied bytes match the 8-byte PNG
* signature, and non-zero otherwise. Having num_to_check == 0 or
* start > 7 will always fail (ie return non-zero).
*/
-extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
- png_size_t num_to_check));
+ extern PNG_EXPORT(int, png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
+ png_size_t num_to_check));
/* Simple signature checking function. This is the same as calling
* png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
*/
-extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
+ extern PNG_EXPORT(int, png_check_sig) PNGARG((png_bytep sig, int num));
/* Allocate and initialize png_ptr struct for reading, and any other memory. */
-extern PNG_EXPORT(png_structp,png_create_read_struct)
- PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
- png_error_ptr error_fn, png_error_ptr warn_fn));
+ extern PNG_EXPORT(png_structp, png_create_read_struct)
+ PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
+ png_error_ptr error_fn, png_error_ptr warn_fn));
/* Allocate and initialize png_ptr struct for writing, and any other memory */
-extern PNG_EXPORT(png_structp,png_create_write_struct)
- PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
- png_error_ptr error_fn, png_error_ptr warn_fn));
+ extern PNG_EXPORT(png_structp, png_create_write_struct)
+ PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
+ png_error_ptr error_fn, png_error_ptr warn_fn));
#ifdef PNG_WRITE_SUPPORTED
-extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
- PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_uint_32, png_get_compression_buffer_size)
+ PNGARG((png_structp png_ptr));
#endif
#ifdef PNG_WRITE_SUPPORTED
-extern PNG_EXPORT(void,png_set_compression_buffer_size)
- PNGARG((png_structp png_ptr, png_uint_32 size));
+ extern PNG_EXPORT(void, png_set_compression_buffer_size)
+ PNGARG((png_structp png_ptr, png_uint_32 size));
#endif
/* Reset the compression stream */
-extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(int, png_reset_zstream) PNGARG((png_structp png_ptr));
/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */
#ifdef PNG_USER_MEM_SUPPORTED
-extern PNG_EXPORT(png_structp,png_create_read_struct_2)
- PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
- png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
- png_malloc_ptr malloc_fn, png_free_ptr free_fn));
-extern PNG_EXPORT(png_structp,png_create_write_struct_2)
- PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
- png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
- png_malloc_ptr malloc_fn, png_free_ptr free_fn));
+ extern PNG_EXPORT(png_structp, png_create_read_struct_2)
+ PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
+ png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
+ png_malloc_ptr malloc_fn, png_free_ptr free_fn));
+ extern PNG_EXPORT(png_structp, png_create_write_struct_2)
+ PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
+ png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
+ png_malloc_ptr malloc_fn, png_free_ptr free_fn));
#endif
/* Write a PNG chunk - size, type, (optional) data, CRC. */
-extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
- png_bytep chunk_name, png_bytep data, png_size_t length));
+ extern PNG_EXPORT(void, png_write_chunk) PNGARG((png_structp png_ptr,
+ png_bytep chunk_name,
+ png_bytep data,
+ png_size_t length));
/* Write the start of a PNG chunk - length and chunk name. */
-extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
- png_bytep chunk_name, png_uint_32 length));
+ extern PNG_EXPORT(void, png_write_chunk_start) PNGARG((png_structp png_ptr,
+ png_bytep chunk_name,
+ png_uint_32 length));
/* Write the data of a PNG chunk started with png_write_chunk_start(). */
-extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
- png_bytep data, png_size_t length));
+ extern PNG_EXPORT(void, png_write_chunk_data) PNGARG((png_structp png_ptr,
+ png_bytep data,
+ png_size_t length));
/* Finish a chunk started with png_write_chunk_start() (includes CRC). */
-extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_write_chunk_end) PNGARG((png_structp png_ptr));
/* Allocate and initialize the info structure */
-extern PNG_EXPORT(png_infop,png_create_info_struct)
- PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_infop, png_create_info_struct)
+ PNGARG((png_structp png_ptr));
/* Initialize the info structure (old interface - DEPRECATED) */
-extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
+ extern PNG_EXPORT(void, png_info_init) PNGARG((png_infop info_ptr));
#undef png_info_init
#define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
png_sizeof(png_info));
-extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
- png_size_t png_info_struct_size));
+ extern PNG_EXPORT(void, png_info_init_3) PNGARG((png_infopp info_ptr,
+ png_size_t
+ png_info_struct_size));
/* Writes all the PNG information before the image. */
-extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
- png_infop info_ptr));
-extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
- png_infop info_ptr));
+ extern PNG_EXPORT(void,
+ png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+ extern PNG_EXPORT(void,
+ png_write_info) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
/* read the information before the actual image data. */
-extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
- png_infop info_ptr));
+ extern PNG_EXPORT(void, png_read_info) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
-extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
- PNGARG((png_structp png_ptr, png_timep ptime));
+ extern PNG_EXPORT(png_charp, png_convert_to_rfc1123)
+ PNGARG((png_structp png_ptr, png_timep ptime));
#endif
#if !defined(_WIN32_WCE)
/* "time.h" functions are not supported on WindowsCE */
#if defined(PNG_WRITE_tIME_SUPPORTED)
/* convert from a struct tm to png_time */
-extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
- struct tm FAR * ttime));
+ extern PNG_EXPORT(void, png_convert_from_struct_tm) PNGARG((png_timep ptime,
+ struct tm FAR *
+ ttime));
/* convert from time_t to png_time. Uses gmtime() */
-extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
- time_t ttime));
-#endif /* PNG_WRITE_tIME_SUPPORTED */
-#endif /* _WIN32_WCE */
+ extern PNG_EXPORT(void, png_convert_from_time_t) PNGARG((png_timep ptime,
+ time_t ttime));
+#endif /* PNG_WRITE_tIME_SUPPORTED */
+#endif /* _WIN32_WCE */
#if defined(PNG_READ_EXPAND_SUPPORTED)
/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */
-extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
-extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
-extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
-extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_expand) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void,
+ png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void,
+ png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void,
+ png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
/* Use blue, green, red order for pixels. */
-extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_bgr) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
/* Expand the grayscale to 24-bit RGB if necessary. */
-extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
/* Reduce RGB to grayscale. */
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
- int error_action, double red, double green ));
+ extern PNG_EXPORT(void, png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
+ int error_action,
+ double red,
+ double green));
#endif
-extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
- int error_action, png_fixed_point red, png_fixed_point green ));
-extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
- png_ptr));
+ extern PNG_EXPORT(void,
+ png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
+ int error_action,
+ png_fixed_point red,
+ png_fixed_point
+ green));
+ extern PNG_EXPORT(png_byte,
+ png_get_rgb_to_gray_status) PNGARG((png_structp png_ptr));
#endif
-extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
- png_colorp palette));
+ extern PNG_EXPORT(void, png_build_grayscale_palette) PNGARG((int bit_depth,
+ png_colorp
+ palette));
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
-extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_strip_alpha) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
-extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_swap_alpha) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
-extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_invert_alpha) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
/* Add a filler byte to 8-bit Gray or 24-bit RGB images. */
-extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
- png_uint_32 filler, int flags));
+ extern PNG_EXPORT(void, png_set_filler) PNGARG((png_structp png_ptr,
+ png_uint_32 filler,
+ int flags));
/* The values of the PNG_FILLER_ defines should NOT be changed */
#define PNG_FILLER_BEFORE 0
#define PNG_FILLER_AFTER 1
/* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */
#if !defined(PNG_1_0_X)
-extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
- png_uint_32 filler, int flags));
+ extern PNG_EXPORT(void, png_set_add_alpha) PNGARG((png_structp png_ptr,
+ png_uint_32 filler,
+ int flags));
#endif
-#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
+#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
/* Swap bytes in 16-bit depth files. */
-extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_swap) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */
-extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_packing) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
/* Swap packing order of pixels in bytes. */
-extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_packswap) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
/* Converts files to legal bit depths. */
-extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
- png_color_8p true_bits));
+ extern PNG_EXPORT(void, png_set_shift) PNGARG((png_structp png_ptr,
+ png_color_8p true_bits));
#endif
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
defined(PNG_WRITE_INTERLACING_SUPPORTED)
/* Have the code handle the interlacing. Returns the number of passes. */
-extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(int,
+ png_set_interlace_handling) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
/* Invert monochrome files */
-extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_invert_mono) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
/* Handle alpha and tRNS by replacing with a background color. */
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
- png_color_16p background_color, int background_gamma_code,
- int need_expand, double background_gamma));
+ extern PNG_EXPORT(void, png_set_background) PNGARG((png_structp png_ptr,
+ png_color_16p
+ background_color,
+ int
+ background_gamma_code,
+ int need_expand,
+ double
+ background_gamma));
#endif
#define PNG_BACKGROUND_GAMMA_UNKNOWN 0
#define PNG_BACKGROUND_GAMMA_SCREEN 1
@@ -1588,21 +1608,25 @@ extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
#if defined(PNG_READ_16_TO_8_SUPPORTED)
/* strip the second byte of information from a 16-bit depth file. */
-extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_strip_16) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_DITHER_SUPPORTED)
/* Turn on dithering, and reduce the palette to the number of colors available. */
-extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
- png_colorp palette, int num_palette, int maximum_colors,
- png_uint_16p histogram, int full_dither));
+ extern PNG_EXPORT(void, png_set_dither) PNGARG((png_structp png_ptr,
+ png_colorp palette,
+ int num_palette,
+ int maximum_colors,
+ png_uint_16p histogram,
+ int full_dither));
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
/* Handle gamma correction. Screen_gamma=(display_exponent) */
#ifdef PNG_FLOATING_POINT_SUP