scroll mode for very long start menus
[reactos.git] / freeldr / freeldr / reactos / arcname.c
1 /*
2 * FreeLoader - arcname.c
3 *
4 * Copyright (C) 2001 Brian Palmer <brianp@sginet.com>
5 * Copyright (C) 2001 Eric Kohl
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include <freeldr.h>
23 #include <rtl.h>
24
25
26 BOOL DissectArcPath(char *ArcPath, char *BootPath, U32* BootDrive, U32* BootPartition)
27 {
28 char *p;
29
30 if (strnicmp(ArcPath, "multi(0)disk(0)", 15) != 0)
31 return FALSE;
32
33 p = ArcPath + 15;
34 if (strnicmp(p, "fdisk(", 6) == 0)
35 {
36 /*
37 * floppy disk path:
38 * multi(0)disk(0)fdisk(x)\path
39 */
40 p = p + 6;
41 *BootDrive = atoi(p);
42 p = strchr(p, ')');
43 if (p == NULL)
44 return FALSE;
45 p++;
46 *BootPartition = 0;
47 }
48 else if (strnicmp(p, "rdisk(", 6) == 0)
49 {
50 /*
51 * hard disk path:
52 * multi(0)disk(0)rdisk(x)partition(y)\path
53 */
54 p = p + 6;
55 *BootDrive = atoi(p) + 0x80;
56 p = strchr(p, ')');
57 if ((p == NULL) || (strnicmp(p, ")partition(", 11) != 0))
58 return FALSE;
59 p = p + 11;
60 *BootPartition = atoi(p);
61 p = strchr(p, ')');
62 if ((p == NULL) || (*BootPartition == 0))
63 return FALSE;
64 p++;
65 }
66 else
67 {
68 return FALSE;
69 }
70
71 strcpy(BootPath, p);
72
73 return TRUE;
74 }
75
76 void ConstructArcPath(PUCHAR ArcPath, PUCHAR SystemFolder, U32 Disk, U32 Partition)
77 {
78 char tmp[50];
79
80 strcpy(ArcPath, "multi(0)disk(0)");
81
82 if (Disk < 0x80)
83 {
84 /*
85 * floppy disk path:
86 * multi(0)disk(0)fdisk(x)\path
87 */
88 sprintf(tmp, "fdisk(%d)", (int) Disk);
89 strcat(ArcPath, tmp);
90 }
91 else
92 {
93 /*
94 * hard disk path:
95 * multi(0)disk(0)rdisk(x)partition(y)\path
96 */
97 sprintf(tmp, "rdisk(%d)partition(%d)", (int) (Disk - 0x80), (int) Partition);
98 strcat(ArcPath, tmp);
99 }
100
101 if (SystemFolder[0] == '\\' || SystemFolder[0] == '/')
102 {
103 strcat(ArcPath, SystemFolder);
104 }
105 else
106 {
107 strcat(ArcPath, "\\");
108 strcat(ArcPath, SystemFolder);
109 }
110 }
111
112 U32 ConvertArcNameToBiosDriveNumber(PUCHAR ArcPath)
113 {
114 char * p;
115 U32 DriveNumber = 0;
116
117 if (strnicmp(ArcPath, "multi(0)disk(0)", 15) != 0)
118 return 0;
119
120 p = ArcPath + 15;
121 if (strnicmp(p, "fdisk(", 6) == 0)
122 {
123 /*
124 * floppy disk path:
125 * multi(0)disk(0)fdisk(x)\path
126 */
127 p = p + 6;
128 DriveNumber = atoi(p);
129 }
130 else if (strnicmp(p, "rdisk(", 6) == 0)
131 {
132 /*
133 * hard disk path:
134 * multi(0)disk(0)rdisk(x)partition(y)\path
135 */
136 p = p + 6;
137 DriveNumber = atoi(p) + 0x80;
138 }
139
140 return DriveNumber;
141 }