View | Details | Raw Unified | Return to bug 25663
Collapse All | Expand All

(-)a/com32/modules/Makefile (-1 / +1 lines)
Lines 22-28 MODULES = chain.c32 config.c32 ethersel.c32 dmitest.c32 cpuidtest.c32 \ Link Here
22
	    disk.c32 pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 \
22
	    disk.c32 pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 \
23
	    meminfo.c32 sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 \
23
	    meminfo.c32 sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 \
24
	    kbdmap.c32 cmd.c32 vpdtest.c32 host.c32 ls.c32 gpxecmd.c32 \
24
	    kbdmap.c32 cmd.c32 vpdtest.c32 host.c32 ls.c32 gpxecmd.c32 \
25
	    ifcpu.c32 cpuid.c32 cat.c32 pwd.c32 ifplop.c32
25
	    ifcpu.c32 cpuid.c32 cat.c32 pwd.c32 ifplop.c32 whichsys.c32
26
26
27
TESTFILES =
27
TESTFILES =
28
28
(-)a/com32/modules/whichsys.c (-2 / +128 lines)
Line 0 Link Here
0
- 
1
/* ----------------------------------------------------------------------- *
1
--
2
 *
3
 *   Copyright 2010 Gert Hulselmans - 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., 51 Franklin St, Fifth Floor,
8
 *   Boston MA 02110-1301, USA; either version 2 of the License, or
9
 *   (at your option) any later version; incorporated herein by reference.
10
 *
11
 * ----------------------------------------------------------------------- */
12
13
/*
14
 * whichsys.c
15
 *
16
 * Detemine which command to execute, based on the Syslinux bootloader variant
17
 * from which you run it.
18
 *
19
 * Usage:    whichsys.c32 [-iso- command] [-pxe- command] [-sys- command]
20
 * Examples: whichsys.c32 -iso- chain.c32 hd0 -sys- chain.c32 hd1 swap
21
 *           whichsys.c32 -iso- config iso.cfg -sys- sys.cfg -pxe- pxe.cfg
22
 *
23
 */
24
25
#include <stdio.h>
26
#include <alloca.h>
27
#include <console.h>
28
#include <string.h>
29
#include <syslinux/boot.h>
30
#include "syslinux/config.h"
31
32
33
static struct syslinux_parameter {
34
    char **arg[1];
35
    bool option;
36
} isolinux, pxelinux, syslinux;
37
38
/* XXX: this really should be librarized */
39
static void boot_args(char **args)
40
{
41
    int len = 0, a = 0;
42
    char **pp;
43
    const char *p;
44
    char c, *q, *str;
45
46
    for (pp = args; *pp; pp++)
47
	len += strlen(*pp) + 1;
48
49
    q = str = alloca(len);
50
    for (pp = args; *pp; pp++) {
51
	p = *pp;
52
	while ((c = *p++))
53
	    *q++ = c;
54
	*q++ = ' ';
55
	a = 1;
56
    }
57
    q -= a;
58
    *q = '\0';
59
60
    if (!str[0])
61
	syslinux_run_default();
62
    else
63
	syslinux_run_command(str);
64
}
65
66
static void usage(void)
67
{
68
    static const char usage[] = "\
69
Usage:    whichsys.c32 [-iso- command] [-pxe- command] [-sys- command]\n\
70
Examples: whichsys.c32 -iso- chain.c32 hd0 -sys- chain.c32 hd1 swap\n\
71
          whichsys.c32 -iso- config iso.cfg -sys- sys.cfg -pxe- pxe.cfg\n";
72
    fprintf(stderr, usage);
73
}
74
75
int main(int argc, char *argv[])
76
{
77
    const union syslinux_derivative_info *sdi;
78
79
    int arg = 0;
80
81
    openconsole(&dev_null_r, &dev_stdcon_w);
82
83
    /* If no argument got passed, let's show the usage */
84
    if (argc == 1) {
85
	    usage();
86
	    return 0;
87
    }
88
89
    arg++;
90
91
    while (arg < argc) {
92
	if (!strcmp(argv[arg], "-iso-")) {
93
	    argv[arg] = NULL;
94
	    isolinux.arg[0] = &argv[arg + 1];
95
	    isolinux.option = true;
96
	}
97
	if (!strcmp(argv[arg], "-pxe-")) {
98
	    argv[arg] = NULL;
99
	    pxelinux.arg[0] = &argv[arg + 1];
100
	    pxelinux.option = true;
101
	}
102
	if (!strcmp(argv[arg], "-sys-")) {
103
	    argv[arg] = NULL;
104
	    syslinux.arg[0] = &argv[arg + 1];
105
	    syslinux.option = true;
106
	}
107
	arg++;
108
    }
109
110
    sdi = syslinux_derivative_info();
111
112
    switch (sdi->c.filesystem) {
113
	case SYSLINUX_FS_ISOLINUX:
114
	    isolinux.option ? boot_args(isolinux.arg[0]) : fprintf(stderr, "No command specified for ISOLINUX.\n\n"); usage();
115
	    break;
116
	case SYSLINUX_FS_PXELINUX:
117
	    pxelinux.option ? boot_args(pxelinux.arg[0]) : fprintf(stderr, "No command specified for PXELINUX.\n\n"); usage();
118
	    break;
119
	case SYSLINUX_FS_SYSLINUX:
120
	    syslinux.option ? boot_args(syslinux.arg[0]) : fprintf(stderr, "No command specified for SYSLINUX.\n\n"); usage();
121
	    break;
122
	case SYSLINUX_FS_UNKNOWN:
123
	default:
124
	    fprintf(stderr, "Unknown Syslinux filesystem\n\n");
125
    }
126
127
    return -1;
128
}
2
com32/modules/whichsys.c |    4 ++--
129
com32/modules/whichsys.c |    4 ++--
3
1 files changed, 2 insertions(+), 2 deletions(-)
130
1 files changed, 2 insertions(+), 2 deletions(-)
(-)a/com32/modules/whichsys.c (-3 / +2 lines)
Lines 18-24 Link Here
18
 *
18
 *
19
 * Usage:    whichsys.c32 [-iso- command] [-pxe- command] [-sys- command]
19
 * Usage:    whichsys.c32 [-iso- command] [-pxe- command] [-sys- command]
20
 * Examples: whichsys.c32 -iso- chain.c32 hd0 -sys- chain.c32 hd1 swap
20
 * Examples: whichsys.c32 -iso- chain.c32 hd0 -sys- chain.c32 hd1 swap
21
 *           whichsys.c32 -iso- config iso.cfg -sys- sys.cfg -pxe- pxe.cfg
21
 *           whichsys.c32 -iso- config iso.cfg -pxe- config pxe.cfg
22
 *
22
 *
23
 */
23
 */
24
24
Lines 68-74 static void usage(void) Link Here
68
    static const char usage[] = "\
68
    static const char usage[] = "\
69
Usage:    whichsys.c32 [-iso- command] [-pxe- command] [-sys- command]\n\
69
Usage:    whichsys.c32 [-iso- command] [-pxe- command] [-sys- command]\n\
70
Examples: whichsys.c32 -iso- chain.c32 hd0 -sys- chain.c32 hd1 swap\n\
70
Examples: whichsys.c32 -iso- chain.c32 hd0 -sys- chain.c32 hd1 swap\n\
71
          whichsys.c32 -iso- config iso.cfg -sys- sys.cfg -pxe- pxe.cfg\n";
71
          whichsys.c32 -iso- config iso.cfg -pxe- config pxe.cfg\n";
72
    fprintf(stderr, usage);
72
    fprintf(stderr, usage);
73
}
73
}
74
74
75
- 

Return to bug 25663