grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / filesys / CDVDFS / src / cdcontrol.c
blobfdb055dd50ad5d78fcb6ce0586b9afdbaeb8b99f
1 /* cdcontrol.c:
3 * Control program for the CDVDFS handler.
5 * ----------------------------------------------------------------------
6 * This code is (C) Copyright 1993,1994 by Frank Munkert.
7 * (C) Copyright 2007 by Pavel Fedin.
8 * All rights reserved.
9 * This software may be freely distributed and redistributed for
10 * non-commercial purposes, provided this notice is included.
13 #include <stdlib.h>
14 #include <stdio.h>
16 #include <proto/dos.h>
17 #include <proto/exec.h>
18 #include <proto/utility.h>
20 #include <dos/dosextens.h>
21 #include <exec/memory.h>
23 #ifdef LATTICE
24 extern struct Library *DOSBase;
25 #endif
27 #include "cdcontrol.h"
29 #ifdef __AROS__
30 struct UtilityBase *UtilityBase = NULL;
31 #else
32 struct Library *UtilityBase = NULL;
33 #endif
35 struct MsgPort *g_device_proc;
37 enum partype {
38 PAR_NONE,
39 PAR_ANY,
40 PAR_ON_OFF
43 void Cleanup (void)
45 if (UtilityBase)
46 CloseLibrary ((APTR)UtilityBase);
49 void Send_Packet (int p_cmd, void *p_1, void *p_2)
51 struct MsgPort *replyport = CreateMsgPort();
52 struct StandardPacket *packet = AllocMem (sizeof (struct StandardPacket),
53 MEMF_CLEAR | MEMF_PUBLIC);
54 long res1, res2;
56 if (!packet || !replyport) {
57 fprintf (stderr, "ERROR: cannot send packet\n");
58 if (packet)
59 FreeMem (packet, sizeof (struct StandardPacket));
60 if (replyport)
61 DeleteMsgPort(replyport);
62 exit (1);
65 packet->sp_Msg.mn_Node.ln_Name = (char *) &(packet->sp_Pkt);
66 packet->sp_Pkt.dp_Link = &(packet->sp_Msg);
68 packet->sp_Pkt.dp_Port = replyport;
69 packet->sp_Pkt.dp_Type = ACTION_USER;
70 packet->sp_Pkt.dp_Arg1 = p_cmd;
71 packet->sp_Pkt.dp_Arg2 = (IPTR) p_1;
72 packet->sp_Pkt.dp_Arg3 = (IPTR) p_2;
74 PutMsg (g_device_proc, (struct Message *) packet);
75 WaitPort (replyport);
76 GetMsg (replyport);
78 res1 = packet->sp_Pkt.dp_Res1;
79 res2 = packet->sp_Pkt.dp_Res2;
80 if (res1 == 0)
81 PrintFault (res2, (UBYTE *) "ERROR");
83 FreeMem (packet, sizeof (struct StandardPacket));
84 DeleteMsgPort (replyport);
87 void Cmd_Lowercase (void *p_1, void *p_2)
89 Send_Packet (CDCMD_LOWERCASE, p_1, p_2);
92 void Cmd_Mactoiso (void *p_1, void *p_2)
94 Send_Packet (CDCMD_MACTOISO, p_1, p_2);
97 void Cmd_Convertspaces (void *p_1, void *p_2)
99 Send_Packet (CDCMD_CONVERTSPACES, p_1, p_2);
102 void Cmd_Showversion (void *p_1, void *p_2)
104 Send_Packet (CDCMD_SHOWVERSION, p_1, p_2);
107 void Cmd_Hfsfirst (void *p_1, void *p_2)
109 Send_Packet (CDCMD_HFSFIRST, p_1, p_2);
112 void Cmd_Dataext (void *p_1, void *p_2)
114 Send_Packet (CDCMD_DATAEXT, p_1, p_2);
117 void Cmd_Resourceext (void *p_1, void *p_2)
119 Send_Packet (CDCMD_RESOURCEEXT, p_1, p_2);
122 void Cmd_Unicodetable (void *p_1, void *p_2)
124 if (!Stricmp(p_1, "none"))
125 p_1 = NULL;
126 Send_Packet (CDCMD_UNICODETABLE, p_1, p_2);
129 struct par {
130 char *name;
131 char *abbrev;
132 enum partype par1;
133 enum partype par2;
134 void (*func)(void *, void *);
135 } g_par[] = {
136 {"lowercase", "l", PAR_ON_OFF, PAR_NONE, Cmd_Lowercase},
137 {"mactoiso", "mi", PAR_ON_OFF, PAR_NONE, Cmd_Mactoiso},
138 {"convertspaces", "cs", PAR_ON_OFF, PAR_NONE, Cmd_Convertspaces},
139 {"showversion", "sv", PAR_ON_OFF, PAR_NONE, Cmd_Showversion},
140 {"hfsfirst", "hf", PAR_ON_OFF, PAR_NONE, Cmd_Hfsfirst},
141 {"dataext", "de", PAR_ANY, PAR_NONE, Cmd_Dataext},
142 {"resourceext", "re", PAR_ANY, PAR_NONE, Cmd_Resourceext},
143 {"unicodetable", "ut", PAR_ANY, PAR_NONE, Cmd_Unicodetable}
146 void Usage (void)
148 printf (
149 "Usage: cdcontrol device command\n"
150 " Commands & parameters Abbrev. Meaning\n"
151 " --------------------- ------- -------\n"
152 " lowercase [on/off] l Convert ISO filenames to lowercase\n"
153 " mactoiso [on/off] mi Convert Mac to Amiga characters\n"
154 " convertspaces [on/off] cs Convert HFS spaces into underscores\n"
155 " showversion [on/off] sv Show version number of ISO filenames\n"
156 " hfsfirst [on/off] hf Look for a HFS partition first\n"
157 " dataext <extension> de Set extension for HFS data forks\n"
158 " resourceext <extension> re Set extension for HFS resource forks\n"
159 " unicodetable <name> ut Load Joliet character conversion table\n"
160 " (\"none\" means default built-in Latin-1 table)\n"
161 "Examples:\n"
162 " cdcontrol cd0: showversion on\n"
163 " cdcontrol cd0: sv on\n"
164 " cdcontrol cd0: ut L:FileSystem_Trans/windows-1251.txt\n"
165 " cdcontrol cd0: ut none\n"
168 exit (1);
171 int main (int argc, char *argv[])
173 int i;
174 struct DevProc *dvp;
176 atexit (Cleanup);
178 if (argc != 4)
179 Usage ();
181 if (!(UtilityBase = (APTR)OpenLibrary ("utility.library", 37))) {
182 fprintf (stderr, "cannot open utility.library\n");
183 exit (1);
186 dvp = GetDeviceProc(argv[1], NULL);
187 if (!dvp) {
188 fprintf (stderr, "ERROR: cannot find device \"%s\"\n", argv[1]);
189 exit (1);
191 #ifdef __AROS__
192 g_device_proc = dvp->dvp_DevNode->dol_Task;
193 #else
194 g_device_proc = dvp->dvp_Port;
195 #endif
196 FreeDeviceProc(dvp);
197 #ifdef __AROS__
198 if (!g_device_proc) {
199 fprintf(stderr, "ERROR: \"%s\" is not a CDVDFS device\n", argv[1]);
200 exit(1);
202 #endif
203 for (i=0; i < (sizeof (g_par) / sizeof (struct par)); i++) {
204 if (Stricmp ((UBYTE *) argv[2], (UBYTE *) g_par[i].name) == 0 ||
205 Stricmp ((UBYTE *) argv[2], (UBYTE *) g_par[i].abbrev) == 0) {
206 void *a = argv[3];
207 void *b = NULL;
209 if (g_par[i].par1 == PAR_ON_OFF) {
210 if (Stricmp ((UBYTE *) argv[3], (UBYTE *) "on") == 0)
211 a = (void *) 1;
212 else if (Stricmp ((UBYTE *) argv[3], (UBYTE *) "off") == 0)
213 a = (void *) 0;
214 else {
215 fprintf (stderr, "ERROR: \"on\" or \"off\" expected\n");
216 exit (1);
219 g_par[i].func (a, b);
220 exit (0);
223 Usage ();
224 return 0;