home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
useful
/
dist
/
disk
/
cdrom
/
amicdrom
/
devsupp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-11
|
14KB
|
513 lines
/* devsupp.c:
*
* Support routines for the device handler.
* - debugging
* - Mountlist "Startup" field parsing
*
* ----------------------------------------------------------------------
* This code is (C) Copyright 1993,1994 by Frank Munkert.
* All rights reserved.
* This software may be freely distributed and redistributed for
* non-commercial purposes, provided this notice is included.
* ----------------------------------------------------------------------
* History:
*
* 09-Apr-94 fmu Larger buffer for startup strings.
* 02-Jan-94 fmu New options XPOS and YPOS.
* 11-Dec-93 fmu Memory type can now be chosen by the user:
* new options CHIP, DMA and ANY.
* 11-Dec-93 fmu The assembly code stubs for the debugging process
* are no longer necessary; the debugger code is now
* called with CreateNewProcTags().
* 21-Nov-93 fmu New option SCANINTERVAL.
* 14-Nov-93 fmu Added Handle_Control_Packet for 'cdcontrol' program.
* 10-Nov-93 fmu New options SHOWVERSION and HFSFIRST.
* 23-Oct-93 fmu MacHFS options added.
* 15-Oct-93 fmu Adapted to new VOLUME structure.
*/
/*
* Extract information from Mountlist "Startup" field.
*/
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#ifdef _DCC
#define abs
#endif
#include <exec/types.h>
#include <dos/dostags.h>
#include <clib/dos_protos.h>
#include "device.h"
#include "devsupp.h"
#include "intui.h"
#include "params.h"
#include "cdcontrol.h"
static char *TheVersion = "$VER: " VERSION;
unsigned long g_memory_type;
int
Get_Startup (LONG p_startup)
{
enum {
ARG_DEVICE,
ARG_UNIT,
ARG_CHIP,
ARG_FAST,
ARG_DMA,
ARG_ANY,
ARG_LOWERCASE,
ARG_ROCKRIDGE,
ARG_TRACKDISK,
ARG_MACTOISO,
ARG_CONVERTSPACES,
ARG_SHOWVERSION,
ARG_HFSFIRST,
ARG_STDBUFFERS,
ARG_FILEBUFFERS,
ARG_DATAEXT,
ARG_RESOURCEEXT,
ARG_SCANINTERVAL,
ARG_PLAYCDDA,
ARG_XPOS,
ARG_YPOS,
ARGCOUNT
};
STRPTR Args[ARGCOUNT],Index;
UBYTE LocalBuffer[250];
struct RDArgs *ArgsPtr;
int result = FALSE,len,i;
int cnt;
/* Clear the argument vector. */
memset (Args, 0, sizeof(Args));
/* valid startup entry? */
if (!p_startup) {
Display_Error ("Filesystem startup entry invalid");
return FALSE;
}
/* Get the contents of the startup field. */
len = ((STRPTR)(BADDR(p_startup)))[0];
if (len > sizeof (LocalBuffer) - 1)
len = sizeof (LocalBuffer) - 1;
memcpy (LocalBuffer, ((STRPTR)(BADDR(p_startup))) + 1, len);
/* Provide null-termination. */
LocalBuffer[len] = 0;
/* Remove leading quotes. */
for (i = 0 ; i < len ; i++) {
if (LocalBuffer[i] != ' ') {
if (LocalBuffer[i] == '\"')
LocalBuffer[i] = ' ';
break;
}
}
/* Remove trailing quotes. */
for (i = len - 1 ; i >= 0 ; i--) {
if (LocalBuffer[i] != ' '){
if (LocalBuffer[i] == '\"')
LocalBuffer[i] = ' ';
break;
}
}
/* Replace "-" by spaces, except "--" which is replaced by "-". */
Index = LocalBuffer;
for (i = 0 ; i < len ; i++) {
if (LocalBuffer[i] == '-') {
if (i+1 < len && LocalBuffer[i+1] == '-') {
*Index++ = '-';
i++;
} else
*Index++ = ' ';
} else
*Index++ = LocalBuffer[i];
}
/* Provide null-termination. */
*Index = 0;
/* Don't forget the newline, or ReadArgs won't work. */
strcat ((char *) LocalBuffer, "\n");
if (ArgsPtr = (struct RDArgs *) AllocDosObjectTags (DOS_RDARGS,TAG_DONE)) {
/* Don't prompt for input! */
ArgsPtr -> RDA_Flags |= RDAF_NOPROMPT;
/* Set up for local parsing. */
ArgsPtr->RDA_Source.CS_Buffer = LocalBuffer;
ArgsPtr->RDA_Source.CS_Length = strlen ((char *) LocalBuffer);
ArgsPtr->RDA_Source.CS_CurChr = 0;
/* Read the arguments. */
if (ReadArgs ((UBYTE *)
"D=DEVICE,U=UNIT/N,C=CHIP/S,F=FAST/S,DMA/S,ANY/S,"
"L=LOWERCASE/S,"
"R=ROCKRIDGE/S,T=TRACKDISK/S,"
"MI=MACTOISO/S,CS=CONVERTSPACES/S,"
"SV=SHOWVERSION/S,HF=HFSFIRST/S,"
"SB=STDBUFFERS/K/N,FB=FILEBUFFERS/K/N,"
"DE=DATAEXT/K,RE=RESOURCEEXT/K,"
"SI=SCANINTERVAL/K/N,PC=PLAYCDDA/K,"
"X=XPOS/K/N,Y=YPOS/K/N",
(LONG *) Args, ArgsPtr)) {
result = TRUE;
if (Args[ARG_DEVICE]) {
len = strlen((char *) (Args[ARG_DEVICE]));
if (len >= sizeof (g_device)) {
Display_Error ("Device name entry too long");
result = FALSE;
} else
strcpy (g_device, (char *) (Args[ARG_DEVICE]));
} else
Display_Error("Device name entry missing");
g_unit = *(long *) (Args[ARG_UNIT]);
g_memory_type = MEMF_CHIP;
cnt = 0;
if (Args[ARG_FAST] != NULL) {
g_memory_type = MEMF_FAST;
cnt++;
}
if (Args[ARG_CHIP] != NULL) {
g_memory_type = MEMF_CHIP;
cnt++;
}
if (Args[ARG_DMA] != NULL) {
g_memory_type = MEMF_24BITDMA;
cnt++;
}
if (Args[ARG_ANY] != NULL) {
g_memory_type = MEMF_ANY;
cnt++;
}
if (cnt > 1) {
Display_Error ("Only ONE memory option may be used!");
result = FALSE;
}
g_map_to_lowercase = (Args[ARG_LOWERCASE] != NULL);
g_use_rock_ridge = (Args[ARG_ROCKRIDGE] != NULL);
g_trackdisk = (Args[ARG_TRACKDISK] != NULL);
g_show_version_numbers = (Args[ARG_SHOWVERSION] != NULL);
g_hfs_first = (Args[ARG_HFSFIRST] != NULL);
if (Args[ARG_STDBUFFERS]) {
g_std_buffers = *(long *) (Args[ARG_STDBUFFERS]);
if (g_std_buffers <= 0) {
Display_Error ("Illegal number of standard buffers: %ld", g_std_buffers);
result = FALSE;
}
} else
g_std_buffers = 5;
if (Args[ARG_FILEBUFFERS]) {
g_file_buffers = *(long *) (Args[ARG_FILEBUFFERS]);
if (g_file_buffers <= 0) {
Display_Error ("Illegal number of file buffers: %ld", g_std_buffers);
result = FALSE;
}
} else
g_file_buffers = 5;
if (Args[ARG_DATAEXT])
strcpy (g_data_fork_extension, (char *) Args[ARG_DATAEXT]);
if (Args[ARG_RESOURCEEXT])
strcpy (g_resource_fork_extension, (char *) Args[ARG_RESOURCEEXT]);
g_convert_hfs_filenames = (Args[ARG_MACTOISO] != NULL);
g_convert_hfs_spaces = (Args[ARG_CONVERTSPACES] != NULL);
if (Args[ARG_SCANINTERVAL]) {
g_scan_interval = *(long *) (Args[ARG_SCANINTERVAL]);
if (g_scan_interval < 0)
g_scan_interval = 0;
} else
g_scan_interval = 3;
if (Args[ARG_PLAYCDDA]) {
len = strlen((char *) (Args[ARG_PLAYCDDA]));
if (len >= sizeof (g_play_cdda_command)) {
Display_Error ("PLAYCDDA command name too long");
result = FALSE;
} else
strcpy (g_play_cdda_command, (char *) (Args[ARG_PLAYCDDA]));
} else
g_play_cdda_command[0] = 0;
if (Args[ARG_XPOS])
g_xpos = *(long *) (Args[ARG_XPOS]);
if (Args[ARG_YPOS])
g_ypos = *(long *) (Args[ARG_YPOS]);
FreeArgs(ArgsPtr);
} else {
Fault(IoErr (), (UBYTE *) "", LocalBuffer, sizeof (LocalBuffer));
Display_Error ("Error while parsing \"Startup\" field in Mountlist:\n%s",
LocalBuffer + 2);
}
FreeDosObject (DOS_RDARGS, ArgsPtr);
} else
Display_Error ("Out of memory");
if (result) {
if (!(g_cd = Open_CDROM (g_device, g_unit, g_trackdisk, g_memory_type,
g_std_buffers, g_file_buffers))) {
switch (g_cdrom_errno) {
case CDROMERR_NO_MEMORY:
Display_Error ("Out of memory: cannot allocate buffers\n"
"(Try CHIP, FAST, DMA or ANY option.)");
break;
case CDROMERR_MSGPORT:
Display_Error ("Cannot open the message port.");
break;
case CDROMERR_IOREQ:
Display_Error ("Cannot open the I/O request structure.");
break;
case CDROMERR_DEVICE:
Display_Error ("Cannot open \"%s\" unit %ld", g_device, (int) g_unit);
break;
case CDROMERR_BLOCKSIZE:
Display_Error ("Cannot access CDROM drive: illegal blocksize.");
break;
default:
break;
}
result = FALSE