Add externs to avoid multiple definitions, and then add missing definitions.
[rrq/maintain_lilo.git] / src / identify.c
1 /* identify.c  -  Translate label names to kernel paths
2  * 
3  * Copyright 1992-1998 Werner Almesberger
4  * Copyright 1999-2004 John Coffman
5  * Copyright 2009-2011 Joachim Wiedorn
6  * All rights reserved.
7  * 
8  * Licensed under the terms contained in the file 'COPYING'
9  * in the source directory.
10  */
11
12 #define _GNU_SOURCE
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <stdio.h>
16 #include <string.h>
17
18 #include "lilo.h"
19 #include "common.h"
20 #include "cfg.h"
21
22 char *identify;
23 static char *opt;
24 static char *first, *dflt;
25 static int idefault;
26
27
28 static void do_identify(char *var,char type)
29 {
30     char *label,*path,*alias,*initrd,*keytab,*appstr,*dtem,*addappstr;
31     char *rootstr;
32     int root,image, ramdisk, kt, append;
33
34 #if 1
35     image = !!strchr(opt,'i');
36     ramdisk = !!strchr(opt,'r');
37     kt = !!strchr(opt,'k');
38     append = !!strchr(opt,'a');
39     root = !!strchr(opt,'R');
40     if (opt && !image && !ramdisk && !kt && !append
41         && !idefault && !root) exit(1);
42 /*    if (!opt) image = 1; */
43 #else
44     image = ramdisk = 1;
45     printf("do_identify:  opt=\"%s\"\n", opt);
46 #endif
47     
48     label = strrchr(path = cfg_get_strg(cf_identify,var),'/');
49     if (label) label++;
50     if (cfg_get_strg(cf_all,"label")) label = cfg_get_strg(cf_all,"label");
51     else if (!label) label = path;
52
53     if (!first) first = stralloc(label);
54     
55     alias = cfg_get_strg(cf_all,"alias");
56     dtem = cfg_get_strg(cf_options,"default");
57
58     if (verbose>=2) printf("identify: dtem=%s  label=%s\n", dtem, label);
59 #ifdef LCF_IGNORECASE
60     if (dtem && (!strcasecmp(label,dtem) || (alias && !strcasecmp(alias,dtem)))) {
61 #else
62     if (dtem && (!strcmp(label,dtem) || (alias && !strcmp(alias,dtem)))) {
63 #endif
64         if (verbose>=2) printf("setting  dflt\n");
65         dflt = dtem;
66     }
67
68     initrd = cfg_get_strg(cf_kernel,"initrd");
69     if (!initrd) initrd = cfg_get_strg(cf_options,"initrd");
70     keytab = cfg_get_strg(cf_options,"keytable");
71     if (!keytab) keytab="us.ktl";
72     appstr = cfg_get_strg(cf_kernel,"append");
73     if (!appstr) appstr = cfg_get_strg(cf_options,"append");
74     addappstr = cfg_get_strg(cf_kernel,"addappend");
75     rootstr = cfg_get_strg(cf_kernel,"root");
76     if (!rootstr) rootstr = cfg_get_strg(cf_options,"root");
77
78 #ifdef LCF_IGNORECASE
79     if (!strcasecmp(label,identify) || (alias && !strcasecmp(alias,identify))) {
80 #else
81     if (!strcmp(label,identify) || (alias && !strcmp(alias,identify))) {
82 #endif
83         if (image) printf("%s\n",path);
84         if (ramdisk) printf("%s\n",initrd?initrd:"No initial ramdisk specified");
85         if (kt) printf("%s\n",keytab);
86         if (append) {
87             if (!appstr && !addappstr)
88                 printf("No append= was specified\n");
89             else if ((appstr && !addappstr) || (!appstr && addappstr))
90                 printf("%s\n", appstr?appstr:addappstr);
91             else printf("%s %s\n", appstr, addappstr);
92         }
93         if (root) printf("%s\n",rootstr?rootstr:"No root specified");
94         if (idefault) printf("%s\n", dflt ? dflt : first);
95         exit(0);
96     }
97 }
98
99
100 void id_image(void)
101 {
102     cfg_init(cf_image);
103     (void) cfg_parse(cf_image);
104     do_identify("image",'i');
105     cfg_init(cf_identify);
106 }
107
108
109 void id_other(void)
110 {
111     cfg_init(cf_other);
112     cfg_init(cf_kernel);
113     curr_drv_map = curr_prt_map = 0;
114     (void) cfg_parse(cf_other);
115     cfg_init(cf_identify);
116 }
117
118
119 void identify_image(char *label,char *options)
120 {
121     identify = label;
122     opt = options;
123     if (verbose>=2) printf("identify_image: id='%s' opt='%s'\n", label, options);
124     idefault = !!strchr(opt,'D');
125     if (idefault) identify = "";
126     cfg_init(cf_identify);
127     if (cfg_parse(cf_identify)) cfg_error("Syntax error");
128     if (idefault && first) {
129         printf("%s\n", dflt ? dflt : first);
130         exit(0);
131     }
132     die("No image found for \"%s\"",label);
133 }