Initial code release
[external/syslinux.git] / com32 / samples / advdump.c
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8  *   Boston MA 02111-1307, USA; either version 2 of the License, or
9  *   (at your option) any later version; incorporated herein by reference.
10  *
11  * ----------------------------------------------------------------------- */
12
13 /*
14  * advdump.c
15  *
16  * Dump the contents of the syslinux ADV
17  */
18
19 #include <stdio.h>
20 #include <console.h>
21 #include <syslinux/adv.h>
22 #include <string.h>
23
24 int main(void)
25 {
26     uint8_t *p, *ep;
27     size_t s = syslinux_adv_size();
28     char buf[256];
29
30     openconsole(&dev_stdcon_r, &dev_stdcon_w);
31
32     p = syslinux_adv_ptr();
33
34     printf("ADV size: %zd bytes at %p\n", s, p);
35
36     ep = p + s;                 /* Need at least opcode+len */
37     while (p < ep - 1 && *p) {
38         int t = *p++;
39         int l = *p++;
40
41         if (p + l > ep)
42             break;
43
44         memcpy(buf, p, l);
45         buf[l] = '\0';
46
47         printf("ADV %3d: \"%s\"\n", t, buf);
48
49         p += l;
50     }
51
52     return 0;
53 }