示例#1
0
int main(void) {
  ARP2_SysCallBase = OpenResource(ARP2_SYSCALL_NAME);

  if (ARP2_SysCallBase != NULL) {
    LONG fd = arp2sys_open("/etc/passwd", O_RDONLY, 0);
    PrintFault(IoErr(), "arp2sys_open");
    Printf("Opened file %ld\n", fd);

    if (fd != -1) {
      char buf[512];

      LONG count = arp2sys_read(fd, buf, sizeof (buf) - 1);
      buf[511] = 0;

      PrintFault(IoErr(), "arp2sys_read");
      Printf("Read %ld bytes.\n", count);
      PutStr(buf);
      PutStr("\n");
    }

    arp2sys_close(fd);
    PrintFault(IoErr(), "arp2sys_close");
    Printf("Closed file %ld\n", fd);
  }

  return 0;
}
示例#2
0
LONG setup(char *name, STRPTR args) {
BOOL retval = RETURN_FAIL;
IPTR myargs[]={0,0,0,0};
struct RDArgs *rdargs;
struct RDArgs rda = {{args, strlen(args), 0}, 0, 0, 0, NULL, 0};

	rda.RDA_Source.CS_Buffer[rda.RDA_Source.CS_Length]='\n';
	rdargs = ReadArgs(setuptemplate,myargs, &rda);
	if (rdargs)
	{
		printf
		(
			"setup\n\tdevice=%s unit=%ld\n",
			(STRPTR)myargs[0], *(LONG *)myargs[1]
		);
		if (myargs[2])
		{
			printf("\ttable in partition=%s\n", (STRPTR)myargs[2]);
		}
		else
			printf("\ttable in whole HD\n");
		if (myargs[3])
		{
			printf("\tscipt is %s\n", (STRPTR)myargs[3]);
		}
		else
			printf("\tinteractive\n");
		FreeArgs(rdargs);
	}
	else
		PrintFault(IoErr(), name);
	return retval;
}
示例#3
0
int main()
{
    struct Process *child;
    
    struct TagItem tags[] =
    {
	{ NP_Entry,         (IPTR) entry              },
    	{ NP_Cli,           (IPTR) TRUE               },
        { NP_Name,          (IPTR) "test"             },
        { NP_NotifyOnDeath, (IPTR) TRUE               },
        { TAG_DONE,         0                         }
    };
    
    child = CreateNewProc(tags);
    
    if(child)
    {
	ULONG childid = GetETask((struct Task*) child)->et_UniqueID;
	Printf("Waiting for child with id %d\n", childid);
	ChildWait(childid);
	Printf("Child exited, freeing child\n");
	ChildFree(childid);
    }
    else
	PrintFault(IoErr(), "Couldn't create child process");
    return 0;
}
示例#4
0
void TxCom(char *com, char *a1, char *a2, char *a3, 
	              char *a4, char *a5, char *a6)
{
  int i;
  ubyte txBuf[MAXMSGSIZE];
  int header = 0x82; /* Long message by default */
  int data1  = 0x01;
  int data2  = 0x02;
  int data3  = 0x03;
  int data4  = 0x04;
  word res;

  if (a1[0]) sscanf(a1, "%x", &header);
  if (a2[0]) sscanf(a2, "%x", &data1);
  if (a3[0]) sscanf(a3, "%x", &data2);
  if (a4[0]) sscanf(a4, "%x", &data3);
  if (a5[0]) sscanf(a5, "%x", &data4);

  txBuf[0] = header & 0xFF;
  txBuf[1] = data1 & 0xFF;
  txBuf[2] = data2 & 0xFF;
  txBuf[3] = data3 & 0xFF;
  txBuf[4] = data4 & 0xFF;

  for (i = 5; i < MAXMSGSIZE; ++i) txBuf[i] = i; /* put known values in buf */

  PrintMessage(txBuf);
  res = ML_Transmit(txBuf);
  if (res < 0) PrintFault("ML_Transmit", res);
}
示例#5
0
/*** Functions **************************************************************/
int main(void)
{
    int            rc              = RETURN_OK;
    struct RDArgs *rdargs          = NULL;
    IPTR           args[ARG_COUNT] = { 0 };

    if ((rdargs = ReadArgs("FILE/M/A,VERBOSE/S", args, NULL)) != NULL)
    {
        CONST_STRPTR *files = (CONST_STRPTR *) args[ARG_FILE], file;

        while ((file = *files++) != NULL)
        {
            if (identify(file, args[ARG_VERBOSE]) != RETURN_OK)
            {
                rc = RETURN_WARN;
            }
        }
        
        FreeArgs(rdargs);
    }
    else
    {
        PrintFault(IoErr(), ERROR_HEADER);
        rc = RETURN_FAIL;
    }

    return rc;
}
示例#6
0
int main(void)
{
    IPTR           args[NOOFARGS] = { (IPTR)NULL, (IPTR)0 };
    struct RDArgs *rda;

    int    result;
    int    error = RETURN_OK;
    ULONG  buffers = 0;

    rda = ReadArgs(ARG_TEMPLATE, args, NULL);

    if (rda != NULL)
    {
	STRPTR  drive = (STRPTR)args[ARG_DRIVE];
	ULONG  *bufsptr = (ULONG *)args[ARG_BUFFERS];

	if (bufsptr != NULL)
	{
	    buffers = *bufsptr;
	}

	result = AddBuffers(drive, buffers);

	if (result == -1)
	{
	    Printf("%s has %ld buffers\n", drive, IoErr());
	}
	else if (result > 0)
	{
	    Printf("%s has %ld buffers\n", drive, (LONG)result);
	}
	else
	{
	    PrintFault(IoErr(), "AddBuffers");
	    error = RETURN_FAIL;
	}
	
	FreeArgs(rda);
    }
    else
    {
	PrintFault(IoErr(), "AddBuffers");
	error = RETURN_FAIL;
    }
    
    return error;
}
示例#7
0
int identify(CONST_STRPTR filename, BOOL verbose)
{
    int  rc   = RETURN_OK;
    BPTR lock = Lock(filename, ACCESS_READ);
    
    if (lock != NULL)
    {
        struct DataType *dt = ObtainDataType(DTST_FILE, lock, TAG_DONE);
        if (dt != NULL)
        {
            struct DataTypeHeader *dth = dt->dtn_Header;
            
            if (!verbose)
            {
                Printf
                (
                    "%s:\t%s/%s\n", 
                    filename, gid2string(dth->dth_GroupID), dth->dth_Name
                );
            }
            else
            {   
                ULONG gid = AROS_LONG2BE(dth->dth_GroupID),
                      id  = AROS_LONG2BE(dth->dth_ID);
                
                Printf
                (
                    "File:        %s\n"
                    "Type:        %s/%s\t(GID: %.4s, ID: %.4s)\n"
                    "DT Basename: %s\n\n",
                    filename, gid2string(dth->dth_GroupID), dth->dth_Name,
                    (CONST_STRPTR) &gid, (CONST_STRPTR) &id,
                    dth->dth_BaseName
                );
            }
        }
        else
        {
            FPrintf(Error(), ERROR_HEADER": Could not obtain datatype for file.\n");
            rc = RETURN_FAIL;
        }

        UnLock(lock);
    }
    else
    {
        PrintFault(IoErr(), ERROR_HEADER);
        rc = RETURN_FAIL;
    }

    return rc;
}
示例#8
0
void RemHandlerCom(char *com, char *a1, char *a2, char *a3, 
		              char *a4, char *a5, char *a6)
{
  int  addr;
  word res;
  
  if (a1[0] == 0)
    { printf("must give handler address\n"); return; }
    
  sscanf(a1, "%x", &addr);
  
  res = ML_DetachHandler((ML_MsgHandler *)addr);
  if (res < 0)
    PrintFault("ML_RemHandler", res);
}
示例#9
0
void WaitRxCom(char *com, char *a1, char *a2, char *a3, 
	                  char *a4, char *a5, char *a6)
{
  word handle = lastRxHandle;
  word res;
  word timeout = -1;

  if (a1[0]) sscanf(a1, "%d", &timeout);

  printf("waiting on handle 0x%lx, timeout %ld\n", handle, timeout);

  res = ML_WaitForRx(handle, timeout);
  if (res < 0)
    PrintFault("ML_WaitForRx", res);
  else
    PrintMessage(buffer);
}
示例#10
0
void SetUpRxCom(char *com, char *a1, char *a2, char *a3, 
		           char *a4, char *a5, char *a6)
{
  int  type = 0x84;
  word res;

  if (a1[0]) sscanf(a1, "%x", &type);

  printf("setting up rx for msg type 0x%x\n", type);
  res = ML_SetUpRx(buffer, type);
  if (res < 0)
    PrintFault("ML_SetUpRx", res);
  else
  {
    lastRxHandle = res;
    printf("handle 0x%lx\n", res);
  }
}
示例#11
0
int main()
{
    struct Process *child;
    
    struct TagItem tags[] =
    {
	{ NP_Entry,         (IPTR) entry              },
    	{ NP_Cli,           (IPTR) TRUE               },
        { NP_Name,          (IPTR) "test"             },
        { NP_NotifyOnDeath, (IPTR) TRUE               },
        { TAG_DONE,         0                         }
    };
    
    child = CreateNewProc(tags);
    
    if(child)
    {
	ULONG childstatus;
	ULONG childid = GetETask((struct Task*) child)->et_UniqueID;
	Printf("Checking status value for non-existing child id\n");
	childstatus = ChildStatus(-1);
	assert(childstatus == CHILD_NOTFOUND);
	Printf("Result: CHILD_NOTFOUND\n");
	Printf("Checking status value for running child id\n");
	childstatus = ChildStatus(childid);
	assert(childstatus == CHILD_ACTIVE);
	Printf("Result: CHILD_ACTIVE\n");
	ChildWait(childid);
	Printf("Checking status value for died child id\n");
	childstatus = ChildStatus(childid);
	assert(childstatus == CHILD_EXITED);
	Printf("Result: CHILD_EXITED\n");
	ChildFree(childid);
	Printf("Checking status value for freed child id\n");
	childstatus = ChildStatus(childid);
	assert(childstatus == CHILD_NOTFOUND);
	Printf("Result: CHILD_NOTFOUND\n");
    }
    else
	PrintFault(IoErr(), "Couldn't create child process");
    return 0;
}
示例#12
0
文件: amiwild.c 项目: yeonsh/Amoeba
/*
 * matchwild - pushes filenames which match the given pattern.
 * it also returns a count of the matches found.
*/
int matchwild(char *pattern)
{
    static char *special = "#?*%([|";	/* )] */
    struct AnchorPath *APath;
    int          matches = 0;
    LONG         error;

    /* Check if correct OS */
    if (isOldDOS())
	return;

    /* Check if pattern is special */
    if (!(strpbrk(pattern, special)))
	return;

    APath = AllocMem(sizeof(struct AnchorPath) + BLKSIZE, MEMF_CLEAR);

    if (!(APath))
	return;

    APath->ap_Strlen = BLKSIZE;
    APath->ap_BreakBits = SIGBREAKF_CTRL_C;

    if ((error = MatchFirst((UBYTE *) pattern, APath)) == 0)
    {
	do
	{
	    ++matches;
	    push(strdup((char *) APath->ap_Buf));
	}
	while ((error = MatchNext(APath)) == 0);
    }
    MatchEnd(APath);

    if (error != ERROR_NO_MORE_ENTRIES)
    {
	PrintFault(error, NULL);
    }
    FreeMem(APath, sizeof(struct AnchorPath) + BLKSIZE);

    return matches;
}
示例#13
0
文件: 7zUtils.c 项目: diegocr/7zUI
void PrintError(char * msg)
{
	PrintFault(IoErr(), "IoErr");
	
	if( G->CliUsage )
	{
		Printf("\n +++ Error: %s\n", (long) msg );
	}
	else
	{
		STATIC UBYTE okm[] = "Ok";
		static struct IntuiText body = { 0,0,0, 15,5, NULL, NULL, NULL };
		static struct IntuiText   ok = { 0,0,0,  6,3, NULL, okm, NULL };
		
		if(((struct Process *)FindTask(NULL))->pr_WindowPtr != (APTR)-1L)
		{
			body.IText = (UBYTE *)msg;
			AutoRequest(NULL,&body,NULL,&ok,0,0,640,72);
		}
	}
}
示例#14
0
void TxManyCom(char *com, char *a1, char *a2, char *a3, 
	                  char *a4, char *a5, char *a6)
{
  int i;
  int times = 100;	/* Number of times to send message */
  ubyte txBuf[MAXMSGSIZE];
  int header = 0x82; /* Long message by default */
  int data1  = 0x01;
  int data2  = 0x02;
  int data3  = 0x03;
  int data4  = 0x04;
  word res;

  if (a1[0]) sscanf(a1, "%d", &times);
  if (a2[0]) sscanf(a2, "%x", &header);
  if (a3[0]) sscanf(a3, "%x", &data1);
  if (a4[0]) sscanf(a4, "%x", &data2);
  if (a5[0]) sscanf(a5, "%x", &data3);
  if (a6[0]) sscanf(a6, "%x", &data4);

  txBuf[0] = header & 0xFF;
  txBuf[1] = data1 & 0xFF;
  txBuf[2] = data2 & 0xFF;
  txBuf[3] = data3 & 0xFF;
  txBuf[4] = data4 & 0xFF;

  for (i = 5; i < MAXMSGSIZE; ++i) txBuf[i] = i; /* put known values in buf */

  printf("sending %d times: ", times);
  PrintMessage(txBuf);

  for (i = 0; i < times; ++i)
  {
    txBuf[5] = i & 0xFF; /* Increment the byte after the last settable one */
    res = ML_Transmit(txBuf);
    if (res < 0) 
      { PrintFault("ML_Transmit", res); break; }
  }
}
示例#15
0
/****** SmartReadArgs/SmartReadArgs ******************************************
 * NAME
 *   SmartReadArgs -- Workbench/CLI transparent ReadArgs().
 * SYNOPSIS
 *   error = SmartReadArgs(wb_startup, smart_args);
 *
 *   LONG SmartReadArgs(struct WBStartup *, struct SmartArgs *);
 * FUNCTION
 *   This function is a CLI/Workbench transparent interface to ReadArgs().
 *
 *   In case of a Workbench start, it analyzes the WBStartup message and
 *   possible tooltypes. These are converted to a text string that can be
 *   passed to ReadArgs() like before.
 *
 *   Tooltypes that are not part of the template are ignored. This includes
 *   tooltypes being disabled with "(...)", NewIcons image data on systems
 *   without NewIcons installed and all this лл Icon by some idiot ╗╗ crap.
 *
 *   If the application was stared from CLI, it simply calls ReadArgs()
 *   without the conversion step.
 *
 *   If all went well you get a return value of zero. This means the passed
 *   arguments fit the template and are ready to use. Otherwise you get a
 *   IoErr()-like return code.
 * INPUTS
 *    wb_startup - Workbench startup message. Refer to your compiler manual
 *        to learn how to obtain it. If this is NULL, the program was
 *        started from CLI.
 *    smart_args - structure which holds all information used by
 *        SmartReadArgs(). You have to setup the following fields before the
 *        call:
 *
 *        sa_Template - The template passed to ReadArgs()
 *        sa_Parameter - ReadArgs() LONG WORD array to hold the arguments
 *        sa_FileParameter - number of Argument in the template to use
 *            for the files passed via WBStartup->sm_ArgList or -1, that
 *            means you don't want any files
 *        sa_Window - Window description string to open when the program
 *            is started from the workbench. NULL means no window. If the
 *            icon has a WINDOW tooltype, this value is ignored.
 *        sa_RDArgs - RDArgs structure to use for ReadArgs() call. This
 *            can be used to provide extended help.
 *        sa_Buffer - Pointer to a buffer to use for the Workbench startup
 *            or NULL, that means SmartReadArgs() allocates a buffer for you
 *        sa_BufferSize - Size of the optional buffer. If it is smaller than
 *            SA_MINIMUM_BUFFER_SIZE it will be adjusted.
 *
 *        All other fields should be set to NULL.
 * RESULTS
 *   Zero for success. You can check the sa_Flags field for the
 *   SAF_WORKBENCH flag to learn how the program was started.
 *
 *   Otherwise an IoErr()-like error code is returned. This can be passed
 *   directly to PrintFault() or similar.
 * NOTES
 *   Always call SmartFreeArgs(), even if SmartReadArgs() failed! See example
 *   below.
 *
 *   This function requires "dos.library", "icon.library" and
 *   "utility.library" to be opened by the application. Normally this
 *   already has been done by the compiler startup code.
 *
 *   There is a not widely known feature of ReadArgs(): with templates like
 *   "FROM/M/A,TO/A", you can select the files from workbench performing the
 *   following steps:
 *
 *   - Select the program
 *   - Select the FROM files
 *   - Select and double click the TO file
 *
 *   This is available because ReadArgs() grabs the last string from a
 *   multi-argument FROM and uses it as the TO parameter, if none is passed
 *   explicitely.
 * BUGS
 *   There are some known problems when used with GCC, mostly related to the
 *   fact that I never bothered creating a useable developer environment
 *   around it (and I'm not sure if this is even possible >:) ...):
 *
 *   - Debugging output shows up in the console instead of SER:. Does
 *     debug.lib exist for gcc? (Wasn't there this strange hunk2gcc
 *     converter?)
 *   - "Read from 0" Enforcer hit in SmartReadArgs(). Couldn't figure out
 *     the exact location yet because of the asynchronous debugging output
 *     mentioned above.
 *
 *   For someone with a reasonable experience with GCC, it should be easy to
 *   fix this.
 *
 *   The SAS/c implementation does not have these problems.
 * SEE ALSO
 *   SmartFreeArgs(), dos.library/ReadArgs(), icon.library/GetDiskObjectNew()
 * EXAMPLE
 *   The main archiev comes with a "test.c" and a couple of icons to start
 *   the corresponding executable "test". Take a look at the source code and
 *   play with it.
 *
 *   See below for a smaller code segment that expects the "dos.library",
 *   "icon.library" and "utility.library" to be open already.
 * SOURCE
 */
int main(int argc, STRPTR argv[])
{
   struct SmartArgs smart_args =
   {NULL};
   LONG argument[2];
   LONG error;

   /* Obtain WBStartup; depends on your compiler environment */
   struct WBStartup *wb_startup = NULL;
#ifdef __GNUC__
   wb_startup = _WBenchMsg;
#else
   if (argc == 0)
   {
      wb_startup = (struct WBStartup *) argv;
   }
#endif

   smart_args.sa_Template = "FILES/M/A,VERBOSE";
   smart_args.sa_Parameter = argument;
   smart_args.sa_FileParameter = 0;
   smart_args.sa_Window = "CON:////My WB-Window/AUTO/CLOSE/WAIT";

   error = SmartReadArgs(wb_startup, &smart_args);
   if (error == 0)
   {
      /* do something */
   }
   else
   {
      PrintFault(error, "MyProgram");
   }

   SmartFreeArgs(&smart_args);

   return ((error == 0) ? RETURN_OK : RETURN_FAIL);
}
示例#16
0
void RegHandlerCom(char *com, char *a1, char *a2, char *a3, 
		              char *a4, char *a5, char *a6)
{
  ML_MsgHandler *handler;
  int		type = 0x80;
  word		res;

  if (a1[0]) sscanf(a1, "%x", &type);
  
  handler = (ML_MsgHandler *)Malloc(sizeof(ML_MsgHandler));
  if (handler == 0)
    { printf("Malloc failed\n"); return; }
    
  printf("setting up handler (at 0x%x) for message type 0x%02x\n",
  	 (int)handler, type);
  	 
  handler->msgType = type & 0xFF;
  handler->func    = HandlerFunc; /* Shared by all handlers		*/
  handler->arg     = &handlerArg; /* Shared (unsafely!) by all handlers */
  
  res = ML_RegisterHandler(handler);
  if (res < 0)
    PrintFault("ML_RegisterHandler", res);
}
示例#17
0
void main(int argc, char *argv[])
{
  BYTE *p1=buffer1,*p2=buffer2,*tmp;
  ULONG signals;

  if(AHImp=CreateMsgPort()) {
    if(AHIio=(struct AHIRequest *)CreateIORequest(AHImp,sizeof(struct AHIRequest))) {
      AHIio->ahir_Version = 4;
      AHIDevice=OpenDevice(AHINAME,0,(struct IORequest *)AHIio,NULL);
    }
  }

  if(AHIDevice) {
    Printf("Unable to open %s/0 version 4\n",AHINAME);
    cleanup(RETURN_FAIL);
  }

// Initialize the first read
  AHIio->ahir_Std.io_Command=CMD_READ;
  AHIio->ahir_Std.io_Data=&buffer1;
  AHIio->ahir_Std.io_Length=BUFFERSIZE;
  AHIio->ahir_Std.io_Offset=0;
  AHIio->ahir_Frequency=FREQUENCY;
  AHIio->ahir_Type=TYPE;
  if(!DoIO((struct IORequest *) AHIio)) {

// The first buffer is now filled
    SetIoErr(NULL);

    for(;;) {
      ULONG length;
      
      length=AHIio->ahir_Std.io_Actual;

// Initialize the second read (note that io_Offset is not cleared!)
      AHIio->ahir_Std.io_Data=p2;
      AHIio->ahir_Std.io_Length=BUFFERSIZE;
      AHIio->ahir_Frequency=FREQUENCY;
      AHIio->ahir_Type=TYPE;
      SendIO((struct IORequest *) AHIio);

// While the second read is in progress, save the first buffer to stdout
      if(Write(Output(),p1,length) != length) {
        break;
      }

      signals=Wait(SIGBREAKF_CTRL_C | (1L << AHImp->mp_SigBit));

      if(signals & SIGBREAKF_CTRL_C) {
        SetIoErr(ERROR_BREAK);
        break;
      }

// Remove the reply 
      if(WaitIO((struct IORequest *) AHIio)) {
        SetIoErr(ERROR_READ_PROTECTED);
        break;
      }

// Swap buffer pointers and repeat
      tmp=p1;
      p1=p2;
      p2=tmp;
    }

// Abort any pending iorequests
    AbortIO((struct IORequest *) AHIio);
    WaitIO((struct IORequest *) AHIio);
  }

  if(IoErr())
  {
    PrintFault(IoErr(), argv[0] ); // Oh, common! It's not MY fault that this
                                   // routine prints to stdout instead of stderr!
    cleanup(RETURN_ERROR);
  }

  cleanup(RETURN_OK);
}
示例#18
0
int main (int argc, char ** argv)
{
    struct MainLevel demo =
    {
	(BYTE)0x88,       0xFF,
	(WORD)0x8844,     0xFF77,
	(LONG)0x88442211, 0xFF773311,
	1.5, 1.75,
	"Hallo",
	{ (BYTE)0x88, (LONG)0x88442211 },
	/* ... */
    };
    BYTE b = (BYTE)0x88;
    WORD w = (WORD)0x8844;
    LONG l = (LONG)0x88442211;
    FLOAT f = 1.5;
    DOUBLE d = 1.75;
    STRPTR s = "Hallo";
    struct Level1 l1 =
    {
	(BYTE)0x88, (LONG)0x88442211
    };
    BPTR fh;
    struct MainLevel * readback;

    demo.ml_BytePtr = &b;
    demo.ml_WordPtr = &w;
    demo.ml_LongPtr = &l;
    demo.ml_FloatPtr = &f;
    demo.ml_DoublePtr = &d;
    demo.ml_StringPtr = &s;
    demo.ml_Level1Ptr = &l1;

    fh = Open ("writestruct.dat", MODE_NEWFILE);

    if (!fh)
    {
	PrintFault (IoErr(), "Can't open file\n");
	return 10;
    }

    /*
	This writes the following data stream:

	    0000 88			    ml_Byte
	    0001 ff			    ml_Ubyte
	    0002 88 44			    ml_Word
	    0004 ff 77			    ml_UWord
	    0006 88 44 22 11		    ml_Long
	    000a ff 77 33 11		    ml_ULong
	    000e 3f c0 00 00		    ml_Float
	    0012 3f fc 00 00 00 00 00 00    ml_Double
	    001a 01:48 61 6c 6c 6f 00	    ml_String
	    0021 88			    ml_Level1.l1_Byte
	    0022 88 44 22 11		    ml_Level1.l1_Long
	    0026 01:88			    ml_BytePtr
	    0028 01:88 44		    ml_WordPtr
	    002b 01:88 44 22 11 	    ml_LongPtr
	    0030 01:3f c0 00 00 	    ml_FloatPtr
	    0035 01:3f fc 00 00 00 00 00 00 ml_DoublePtr
	    003e 01:01:48 61 6c 6c 6f 00    ml_StringPtr - Note two 01 !
	    0046 01:88 88 44 22 11	    ml_Level1Ptr
    */

    if (!WriteStruct (&dsh, &demo, fh, MainDesc))
    {
	PrintFault (IoErr(), "Failed to write to file\n");
    }

    if (!Close (fh))
    {
	PrintFault (IoErr(), "Failed to close file\n");
    }

    /* Read the structure back */
    fh = Open ("writestruct.dat", MODE_OLDFILE);

    if (!fh)
    {
	PrintFault (IoErr(), "Can't open file for reading\n");
	return 10;
    }

    if (!ReadStruct (&dsh, (APTR *)&readback, fh, MainDesc))
    {
	PrintFault (IoErr(), "Failed to read from file\n");
    }
    else
    {
	UBYTE * ptr;
	int t;

	ptr = (UBYTE *)readback;
	t = 0;

	kprintf ("readback = %p\n", readback);

	kprintf ("%02X (88) %02X (FF)\n"
	    , (UBYTE)readback->ml_Byte
	    , readback->ml_UByte
	);
	kprintf ("%04X (8844) %04X (FF77)\n"
	    , (UWORD)readback->ml_Word
	    , readback->ml_UWord
	);
	kprintf ("%08lX (88442211) %08lX (FF773311)\n"
	    , readback->ml_Long
	    , readback->ml_ULong
	);
	kprintf ("%08lX (3FC00000) %08lX:%08lX (3FFC0000:00000000)\n"
	    , *(ULONG *)&readback->ml_Float
	    , ((ULONG *)&readback->ml_Double)[1]
	    , ((ULONG *)&readback->ml_Double)[0]
	);
	kprintf ("%s (Hallo)\n"
	    , readback->ml_String
	);
	kprintf ("{ %02X %08X } ({ 88 88442211 })\n"
	    , (UBYTE)readback->ml_Level1.l1_Byte
	    , readback->ml_Level1.l1_Long
	);
	kprintf ("%02X (88)\n"
	    , (UBYTE)*readback->ml_BytePtr
	);
	kprintf ("%04X (8844)\n"
	    , (UWORD)*readback->ml_WordPtr
	);
	kprintf ("%08lX (88442211)\n"
	    , *readback->ml_LongPtr
	);
	kprintf ("%08lX (3FC00000) %08lX:%08lX (3FFC0000:00000000)\n"
	    , *(ULONG *)readback->ml_FloatPtr
	    , ((ULONG *)readback->ml_DoublePtr)[1]
	    , ((ULONG *)readback->ml_DoublePtr)[0]
	);
	kprintf ("%s (Hallo)\n"
	    , *readback->ml_StringPtr
	);
	kprintf ("{ %02X %08X } ({ 88 88442211 })\n"
	    , (UBYTE)readback->ml_Level1Ptr->l1_Byte
	    , readback->ml_Level1Ptr->l1_Long
	);

	FreeStruct (readback, MainDesc);
    }

    if (!Close (fh))
    {
	PrintFault (IoErr(), "Failed to close file after reading\n");
    }

    return 0;
} /* main */
示例#19
0
int main (void)
{
  IPTR args[ARG_NUM] = { (IPTR) NULL, (IPTR) NULL, (IPTR) NULL, FALSE, FALSE};
  struct RDArgs *rda;
  ULONG error = 0;

  locale = OpenLocale(NULL);
  if (!locale)
  {
    PutStr("Could not open locale!\n");
    return -1;
  }

  rda = ReadArgs(TEMPLATE, args, NULL);
  if (rda)
  {
    BPTR lock_in;
    lock_in = Lock((STRPTR)args[ARG_FROM], ACCESS_READ);

    if (lock_in)
    {
       BPTR file_out = Open((STRPTR)args[ARG_TO], MODE_NEWFILE);

       if (NULL != file_out)
       {
          struct FileInfoBlock fib;
          UBYTE * data = NULL;
          BOOL success = Examine(lock_in, &fib);

          /*
          ** Read  the input file into memory
          */
          if (fib.fib_Size && DOSTRUE == success)
            data = AllocVec(fib.fib_Size, MEMF_ANY);

          if (data)
          {
            ULONG read = Read(lock_in, data, fib.fib_Size);

            if (-1 != read)
            {
              struct sorted_data * sd;
              sd = sort(data, 
                        fib.fib_Size, 
                        (STRPTR)args[ARG_COLSTART],
                        (BOOL)args[ARG_CASE],
                        (BOOL)args[ARG_NUMERIC]);

              error = write_data(sd, file_out);
            }
            FreeVec(data);
          }/*  if (data) */

          Close(file_out);  
       } /* if (file_out) */
       UnLock(lock_in);
    } /* if (lock_in) */
    FreeArgs(rda);
  }
  else
    error=RETURN_FAIL;
    
  if (error)
    PrintFault(IoErr(), "Sort");
  
  return error; 
}
示例#20
0
int
main( void )
{
  struct RDArgs *rdargs;
  int            rc = RETURN_OK;

  rdargs = ReadArgs( TEMPLATE , (LONG *) &args, NULL );

  if( rdargs != NULL )
  {
    /* Refresh database */

    if( args.refresh && !args.remove )
    {
      OpenAHI();
      
      if( !AHI_LoadModeFile( "DEVS:AudioModes" ) && !args.quiet )
      {
        PrintFault( IoErr(), "DEVS:AudioModes" );
        rc = RETURN_ERROR;
      }
    }

    /* Load mode files */

    if( args.files != NULL && !args.remove )
    {
      int i = 0;

      OpenAHI();

      while( args.files[i] )
      {
        if( !AHI_LoadModeFile( args.files[i] ) && !args.quiet )
        {
          PrintFault( IoErr(), args.files[i] );
          rc = RETURN_ERROR;
        }
        i++;
      }
    }

    /* Remove database */

    if( args.remove )
    {
      if( args.files || args.refresh )
      {
        PutStr( "The REMOVE switch cannot be used together with FILES or REFRESH.\n" );
        rc = RETURN_FAIL;
      }
      else
      {
        ULONG id;

        OpenAHI();

        for( id = AHI_NextAudioID( AHI_INVALID_ID );
             id != AHI_INVALID_ID;
             id = AHI_NextAudioID( AHI_INVALID_ID ) )
        {
          AHI_RemoveAudioMode( id );
        }
      }
    }

    /* Make display mode doublescan (allowing > 28 kHz sample rates) */

    if( args.dblscan )
    {
      ULONG          id;
      ULONG          bestid = INVALID_ID;
      int            minper = MAXINT;
      struct Screen *screen = NULL;

      static const struct ColorSpec colorspecs[] =
      {
        { 0, 0, 0, 0 },
        { 1, 0, 0, 0 },
        {-1, 0, 0, 0 }
      };
      
      union {
        struct MonitorInfo mon;
        struct DisplayInfo dis;
      } buffer;

      for( id = NextDisplayInfo( INVALID_ID );
           id != (ULONG) INVALID_ID;
           id = NextDisplayInfo( id ) )
      {
        int period;

        if( GetDisplayInfoData( NULL, 
                                (UBYTE*) &buffer.dis, sizeof(buffer.dis),
                                DTAG_DISP, id ) )
        {
          if( !(buffer.dis.PropertyFlags & (DIPF_IS_ECS | DIPF_IS_AA ) ) )
          {
            continue;
          }
        }

        if( GetDisplayInfoData( NULL,
                                (UBYTE*) &buffer.mon, sizeof(buffer.mon),
                                DTAG_MNTR, id ) )
        {
          period = buffer.mon.TotalColorClocks * buffer.mon.TotalRows
                   / ( 2 * ( buffer.mon.TotalRows - buffer.mon.MinRow + 1 ) );

          if( period < minper )
          {
            minper = period;
            bestid = id;
          }
        }

      }

      if( bestid != (ULONG) INVALID_ID && minper < 100 )
      {
        screen = OpenScreenTags( NULL,
                                 SA_DisplayID,  bestid,
                                 SA_Colors,    (ULONG) &colorspecs,
                                 TAG_DONE );
      }
      else if( ( GfxBase->ChipRevBits0 & (GFXF_HR_DENISE | GFXF_AA_LISA ) ) != 0 )
      {
        /* No suitable screen mode found, let's bang the hardware...
           Using code from Sebastiano Vigna <*****@*****.**>. */

        extern struct Custom custom;

        custom.bplcon0  = 0x8211;
        custom.ddfstrt  = 0x0018;
        custom.ddfstop  = 0x0058;
        custom.hbstrt   = 0x0009;
        custom.hsstop   = 0x0017;
        custom.hbstop   = 0x0021;
        custom.htotal   = 0x0071;
        custom.vbstrt   = 0x0000;
        custom.vsstrt   = 0x0003;
        custom.vsstop   = 0x0005;
        custom.vbstop   = 0x001D;
        custom.vtotal   = 0x020E;
        custom.beamcon0 = 0x0B88;
        custom.bplcon1  = 0x0000;
        custom.bplcon2  = 0x027F;
        custom.bplcon3  = 0x00A3;
        custom.bplcon4  = 0x0011;
      }

      if( screen != NULL )
      {
        CloseScreen( screen );
      }
    }

    FreeArgs( rdargs );
  }

  cleanup( rc );
}
示例#21
0
/*
 * Read in file and generate executable tree
 */
void parse_file(ScriptArg *first)
{
ScriptArg *current;
int count, i, j, ready;
char **mclip;

    ready = FALSE;
    current = first;
    do
    {
	count = Read(inputfile, &buffer[0], 1);
	if (count == 0)
	{
	    PrintFault(IoErr(), INSTALLER_NAME);
	    show_parseerror("End of File", line);
	    cleanup();
	    exit(-1);
	}
	if (!isspace(buffer[0]))
	{
	    switch (buffer[0])
	    {
		case SEMICOLON: /* A comment, ok - Go on with next line */
		    do
		    {
			count = Read(inputfile, &buffer[0], 1);
		    } while (buffer[0] != LINEFEED && count != 0);
		    line++;
		    break;

		case LBRACK: /* Open bracket: recurse into next level */
		    current->cmd = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
		    if (current->cmd == NULL)
		    {
			end_alloc();
		    }
		    /* Set initial values */
		    current->cmd->parent = current;
		    current->cmd->arg = NULL;
		    current->cmd->cmd = NULL;
		    current->cmd->next = NULL;
		    current->cmd->intval = 0;
		    current->cmd->ignore = 0;
		    parse_file(current->cmd);
		    current->next = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
		    if (current->next == NULL)
		    {
			end_alloc();
		    }
		    current->next->parent = current->parent;
		    /* Set initial values */
		    current = current->next;
		    current->arg = NULL;
		    current->cmd = NULL;
		    current->next = NULL;
		    current->intval = 0;
		    current->ignore = 0;
		    break;

		case RBRACK: /* All args collected return to lower level */
		    /* We have allocated one ScriptArg too much */
		    current = current->parent->cmd;
		    if (current->next != NULL)
		    {
			while (current->next->next != NULL)
			{
			    current = current->next;
			}
			FreeVec(current->next);
			current->next = NULL;
		    }
		    else
		    {
			/* This is an empty bracket */
			show_parseerror("There is an empty bracket.", line);
			cleanup();
			exit(-1);
		    }
		    ready = TRUE;
		    break;

		default: /* This is the real string */
		    i = 0;
		    if (buffer[0] == DQUOTE || buffer[0] == SQUOTE)
		    {
		    int masquerade = FALSE;
			do
			{
			    if (masquerade == TRUE)
			    {
				switch (buffer[i])
				{
				    case 'n': /* NEWLINE */
					buffer[i-1] = 0x0a;
						  break;
				    case 'r': /* RETURN */
					buffer[i-1] = 0x0d;
					break;
				    case 't': /* TAB */
					buffer[i-1] = 0x09;
					break;
				    case SQUOTE: /* SQUOTE */
					buffer[i-1] = SQUOTE;
					break;
				    case DQUOTE: /* DQUOTE */
					 buffer[i-1] = DQUOTE;
					 break;
				    case BACKSLASH: /* BACKSLASH */
					 buffer[i-1] = BACKSLASH;
					 break;
#warning TODO: convert missing '\\' masqueraded symbols
				    case 'h': /* H.TAB */
				    case 'v': /* V.TAB */
				    case 'b': /* BACKSPACE */
				    case 'f': /* FORMFEED */
				    case 'x': /* HEX number */
				    case 'o': /* \\ooo OCTAL number ('o' is just to remember) */
				    default:
					i++;
					break;
				}
				masquerade = FALSE;
			    }
			    else
			    {
				if (buffer[i] == BACKSLASH)
				    masquerade = TRUE;
				i++;
			    }
			    if (i == MAXARGSIZE)
			    {
				show_parseerror("Argument length overflow!" ,line);
				cleanup();
				exit(-1);
			    }
			    count = Read(inputfile, &buffer[i], 1);
			} while (masquerade || (buffer[i] != buffer[0] && count != 0));
			current->arg = AllocVec(sizeof(char)*(i+2), MEMF_PUBLIC);
			if (current->arg == NULL)
			{
			    end_alloc();
			}
			buffer[i+1] = 0;
			strncpy (current->arg, buffer, i+2);
		    }
		    else
		    {
			do
			{
			    i++;
			    count = Read(inputfile, &buffer[i], 1);
			} while (!isspace(buffer[i]) && buffer[i]!=LBRACK && buffer[i]!=RBRACK && buffer[i]!=SEMICOLON && count != 0 && i < MAXARGSIZE);
			if (buffer[i] == LINEFEED)
			{
			    line++;
			}
			if (i == MAXARGSIZE)
			{
			    show_parseerror("Argument length overflow!", line);
			    cleanup();
			    exit(-1);
			}
			if (buffer[i] == SEMICOLON)
			{
			    do
			    {
				count = Read(inputfile, &buffer[i], 1);
			    } while (buffer[i] != LINEFEED && count != 0);
			    line++;
			}
			if (buffer[i] == LBRACK || buffer[i] == RBRACK)
			{
			    Seek(inputfile, -1 , OFFSET_CURRENT);
			}
			buffer[i] = 0;
			switch (buffer[0])
			{
			    case DOLLAR: /* HEX number */
				current->intval = strtol(&buffer[1], NULL, 16);
					    break;
			    case PERCENT: /* binary number */
				current->intval = strtol(&buffer[1], NULL, 2);
				break;
			    default: /* number or variable */
				if (isdigit(buffer[0]) || ((buffer[0] == PLUS || buffer[0] == MINUS) && isdigit(buffer[1])))
				{
				    current->intval = atol(buffer);
				}
				else
				{
				    current->arg = AllocVec(sizeof(char)*(i+1), MEMF_PUBLIC);
				    if (current->arg == NULL)
				    {
					end_alloc();
				    }
				    strncpy(current->arg, buffer, i+1);
				}
				if (current == current->parent->cmd && strcasecmp(buffer, "procedure") == 0)
				{
				ScriptArg *proc, *uproc;
				int finish;
				    /* Save procedure in ProcedureList */
				    proc = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
				    if (proc == NULL)
				    {
					end_alloc();
				    }
				    uproc = proc;
				    proc->parent = NULL;
				    proc->next = NULL;
				    proc->arg = NULL;
				    proc->intval = 0;
				    proc->ignore = 0;
				    proc->cmd = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
				    if (proc->cmd == NULL)
				    {
					end_alloc();
				    }
				    proc->cmd->parent = proc;
				    proc->cmd->next = NULL;
				    proc->cmd->arg = NULL;
				    proc->cmd->intval = 0;
				    proc->cmd->ignore = 0;
				    proc = proc->cmd;
				    proc->cmd = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
				    if (proc->cmd == NULL)
				    {
					end_alloc();
				    }
				    proc->cmd->parent = proc;
				    proc->cmd->next = NULL;
				    proc->cmd->arg = NULL;
				    proc->cmd->intval = 0;
				    proc->cmd->ignore = 0;
				    proc->cmd->cmd = NULL;
				    /* parse procedure name and args */
				    mclip = NULL;
				    j = 0;
				    finish = FALSE;
				    do
				    {
					/* goto next argument */
					do
					{
					    count = Read(inputfile, &buffer[0], 1);
					    if (buffer[0] == LINEFEED)
					    {
						line++;
					    }
					    if (buffer[0] == RBRACK)
					    {
						if (j > 0)
						{
						    show_parseerror("Procedure has no body!", line);
						}
						else
						{
						    show_parseerror("Procedure has no name!", line);
						}
						cleanup();
						exit(-1);
					    }
					    if (buffer[0] == SQUOTE ||  buffer[0] == DQUOTE)
					    {
						show_parseerror("Procedure has a quoted argument!", line);
						cleanup();
						exit(-1);
					    }
					    if (buffer[0] == SEMICOLON && count != 0)
					    {
						do
						{
						    count = Read(inputfile, &buffer[0], 1);
						} while (buffer[0] != LINEFEED && count != 0);
						line++;
					    }
					} while (isspace(buffer[0]) && count != 0);

					if (buffer[0] != LBRACK)
					{
					    i = 0;
					    /* read in string */
					    do
					    {
						i++;
						count = Read(inputfile, &buffer[i], 1);
					    } while (!isspace(buffer[i]) && buffer[i]!=LBRACK && buffer[i]!=RBRACK && buffer[i]!=SEMICOLON && count != 0 && i < MAXARGSIZE);
					    if (i == MAXARGSIZE)
					    {
						show_parseerror("Argument length overflow!", line);
						cleanup();
						exit(-1);
					    }
					    if (buffer[i] == LINEFEED)
					    {
						line++;
					    }
					    if (buffer[i] == LBRACK || buffer[i] == RBRACK || buffer[i] == SEMICOLON)
					    {
						Seek(inputfile, -1 , OFFSET_CURRENT);
					    }
					    buffer[i] = 0;
					    j++;
					    mclip = ReAllocVec(mclip, sizeof(char *) * j, MEMF_PUBLIC);
					    if (mclip == NULL)
					    {
						end_alloc();
					    }
					    mclip[j-1] = StrDup(buffer);
					    if (mclip[j-1] == NULL)
					    {
						end_alloc();
					    }
					}
					else
					{
					    /* Exit if procedure has no name or name is string/digit or bracket follows */
					    if (j == 0)
					    {
						show_parseerror("Argument to procedure is a command!\n", line);
						cleanup();
						exit(-1);
					    }
					    /* Next string is body-command */
					    finish = TRUE;
					}
				    } while (!finish);
				    /* Procedure body */
				    parse_file(proc->cmd);
				    finish = FALSE;
				    do
				    {
					do
					{
					    count = Read(inputfile, &buffer[0], 1);
					    if (buffer[0] == LINEFEED)
					    {
						line++;
					    }
					} while (isspace(buffer[0]) && count != 0);
					if (buffer[0] == SEMICOLON)
					{
					    do
					    {
						count = Read(inputfile, &buffer[0], 1);
					    } while (buffer[0] != LINEFEED && count != 0);
					    line++;
					}
					else if (buffer[0] == LBRACK)
					{
					    proc->next = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
					    if (proc->next == NULL)
					    {
						end_alloc();
					    }
					    proc->next->parent = proc->parent;
					    proc->next->next = NULL;
					    proc->next->arg = NULL;
					    proc->next->intval = 0;
					    proc->next->ignore = 0;
					    proc = proc->next;
					    proc->cmd = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
					    if (proc->cmd == NULL)
					    {
						end_alloc();
					    }
					    proc->cmd->parent = proc;
					    proc->cmd->next = NULL;
					    proc->cmd->arg = NULL;
					    proc->cmd->intval = 0;
					    proc->cmd->ignore = 0;
					    proc->cmd->cmd = NULL;
					    parse_file(proc->cmd);
					}
					else if (buffer[0] == RBRACK)
					{
					    finish = TRUE;
					}
					else
					{
					    show_parseerror("Procedure has rubbish in its body!", line);
					    cleanup();
					    exit(-1);
					}
				    } while (!finish);
				    current->next = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
				    if (current->next == NULL)
				    {
					end_alloc();
				    }
				    current->next->parent = current->parent;
				    current = current->next;
				    current->arg = mclip[0];
				    current->cmd = NULL;
				    current->next = NULL;
				    current->intval = set_procedure(mclip, j, uproc);
				    current->ignore = 0;
#ifdef DEBUG
	printf("\n\n");
	printcode(uproc, 0);
#endif /* DEBUG */
				    buffer[0] = 0;
				    ready = TRUE;
				}
				if (current->arg == current->parent->cmd->arg && strcasecmp(buffer, "welcome") == 0)
				{
				    preferences.welcome = TRUE;
				}
				break;
			}
		    }
		    current->next = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
		    if (current->next == NULL)
		    {
			end_alloc();
		    }
		    current->next->parent = current->parent;
		    current = current->next;
		    /* Set initial values */
		    current->arg = NULL;
		    current->cmd = NULL;
		    current->next = NULL;
		    current->intval = 0;
		    current->ignore = 0;
		    break;
	    }
	}
	else
	{
	    if (buffer[0] == LINEFEED)
	    {
		line++;
	    }
	}
	if (count == 0)
	{
	    PrintFault(IoErr(), INSTALLER_NAME);
	    show_parseerror("End of File", line);
	    cleanup();
	    exit(-1);
	}
    } while (!ready);
}
示例#22
0
int main(int argc, char **argv)
{
    ULONG ret = RETURN_FAIL;

    OOP_AttrBase HiddGCAttrBase;
    OOP_AttrBase HiddGfxAttrBase;
    OOP_AttrBase HiddBitMapAttrBase;

    OOP_Object   *gfxHidd;
    OOP_Object   *bitMap;
    OOP_Object   *gc;

    STRPTR hiddName = "graphics.hidd";
    ULONG  width    = 320;
    ULONG  height   = 200;
    ULONG  depth    = 8;
    ULONG  format   = vHidd_BitMap_Format_Planar;

    WORD x;
    char wait;

    struct Args
    {
        STRPTR hiddName;
        IPTR   *width;
        IPTR   *height;
        IPTR   *depth;
        IPTR   *chunky;
        ULONG  displayable;
    };

    struct Args args = {hiddName, &width, &height, &depth, 0, 0};
    struct RDArgs *rda;


    if(ght_OpenLibs(LibsArray))
    {
        rda = ReadArgs("HIDD/K,WIDTH/N/K,HEIGHT/N/K,DEPTH/N/K,CHUNKY/S,DISPLAYABLE=DP/S", (IPTR *)&args, NULL);
        if (rda != NULL)
        {
            if(args.chunky      != 0) format           = vHidd_BitMap_Format_Chunky;
            if(args.displayable != 0) args.displayable = (ULONG) TRUE;

            HIDDGraphicsBase = OpenLibrary(args.hiddName, 0);
            if(HIDDGraphicsBase)
            {
                ret = RETURN_ERROR;

                HiddGfxAttrBase    = OOP_ObtainAttrBase(IID_Hidd_Gfx);
                HiddBitMapAttrBase = OOP_ObtainAttrBase(IID_Hidd_BitMap);
                HiddGCAttrBase     = OOP_ObtainAttrBase(IID_Hidd_GC);
        
                if(HiddGfxAttrBase && HiddBitMapAttrBase && HiddGCAttrBase)
                {
                    gfxHidd = OOP_NewObject(NULL, args.hiddName, NULL);
                    if(gfxHidd)
                    {
                        struct TagItem bm_tags[] =
                        {
                            {aHidd_BitMap_Width,       (IPTR) *args.width},
                            {aHidd_BitMap_Height,      (IPTR) *args.height},
                            {aHidd_BitMap_Depth,       (IPTR) *args.depth},
                            {aHidd_BitMap_Format,      (IPTR) format},
                            {aHidd_BitMap_Displayable, (IPTR) args.displayable},
                            {TAG_DONE, 0UL}
                        };
    
                        bitMap = HIDD_Gfx_NewBitMap(gfxHidd, bm_tags);
                        if(bitMap)
                        {
                            struct TagItem gc_tags[] =
                            {
                                {aHidd_GC_BitMap,     (IPTR) bitMap},
                                {TAG_DONE, 0UL}
                            };
        
                            gc = HIDD_Gfx_NewGC(gfxHidd, gc_tags);
                            if(gc)
                            {
                                OOP_SetAttrsTags(gc, aHidd_GC_Foreground, 15, TAG_END);

                                for(x = 10; x < 30; x++)
                                {
                                    OOP_SetAttrsTags(gc, aHidd_GC_ColorMask, ~0, TAG_END);
                                    HIDD_BM_DrawPixel(gc, x, 10);

                                    OOP_SetAttrsTags(gc, aHidd_GC_ColorMask, ~0 - 7, TAG_END);
                                    HIDD_BM_DrawPixel(gc, x, 12);

                                    OOP_SetAttrsTags(gc, aHidd_GC_ColorMask, 0, TAG_END);
                                    HIDD_BM_DrawPixel(gc, x, 14);
                                }

                                printf("Press enter to continue");
                                scanf("%c", &wait);

                                HIDD_Gfx_DisposeGC(gfxHidd, gc);
        
                                ret = RETURN_OK;
                            }
        
                            HIDD_Gfx_DisposeBitMap(gfxHidd, bitMap);
                        }
    
                        if(gfxHidd) OOP_DisposeObject(gfxHidd);
                    }
                }  /* if(HiddGfxAttrBase && HiddBitMapAttrBase && HiddGCAttrBase) */
    
                if(HiddGfxAttrBase)    OOP_ReleaseAttrBase(IID_Hidd_Gfx);
                if(HiddBitMapAttrBase) OOP_ReleaseAttrBase(IID_Hidd_BitMap);
                if(HiddGCAttrBase)     OOP_ReleaseAttrBase(IID_Hidd_GC);

                CloseLibrary(HIDDGraphicsBase);
            } /* if(HIDDGraphicsBase) */
            FreeArgs(rda);
        }
        else
        {
           PrintFault(IoErr(), "");
        }  /* if (rda != NULL) */
    } /* if OpenLibs() */

    ght_CloseLibs(LibsArray);

    return(ret);
}
示例#23
0
int main(void)
{
    IPTR           args[NOOFARGS] = { (IPTR)FALSE,
                                      (IPTR)FALSE,
                                      (IPTR)FALSE,
                                      (IPTR)FALSE,
                                      (IPTR)FALSE
                                    };
    struct RDArgs *rda;
    LONG           error = 0;
    BOOL bPrintErr = TRUE;
    rda = ReadArgs(ARG_TEMPLATE, args, NULL);

    if (rda != NULL)
    {
        UWORD typeCount = 0;
        BOOL  aChip  = (BOOL)args[ARG_CHIP];
        BOOL  aFast  = (BOOL)args[ARG_FAST];
        BOOL  aTotal = (BOOL)args[ARG_TOTAL];
        BOOL  aFlush = (BOOL)args[ARG_FLUSH];
        aHuman = (BOOL)args[ARG_HUMAN];

        if (aChip)
        {
            typeCount++;
        }
        if (aFast)
        {
            typeCount++;
        }
        if (aTotal)
        {
            typeCount++;
        }

        ULONG chip[4], fast[4], total[4];

        if (typeCount > 1)
        {
            FPuts(Output(), "Only one of CHIP, FAST or TOTAL allowed\n");
            bPrintErr = FALSE;
            FreeArgs(rda);

            return RETURN_FAIL;
        }
        else
        {
            if (aFlush)
            {
                APTR Mem;

                Mem = AllocMem(0x7ffffff0, MEMF_PUBLIC);
                if (Mem)
                    FreeMem(Mem, 0x7ffffff0);
            }

            if(aChip)
            {

                chip[0] = AvailMem(MEMF_CHIP);

                if (printm(NULL, chip, 1) < 0)
                {
                    error = RETURN_ERROR;
                }
            }
            else if(aFast)
            {
                fast[0] = AvailMem(MEMF_FAST);

                if (printm(NULL, fast, 1) < 0)
                {
                    error = RETURN_ERROR;
                }
            }
            else if (aTotal)
            {
                total[0] = AvailMem(MEMF_ANY);

                if (printm(NULL, total, 1) < 0)
                {
                    error = RETURN_ERROR;
                }
            }
            else
            {
                Forbid();

                chip[0] = AvailMem(MEMF_CHIP);
                chip[2] = AvailMem(MEMF_CHIP | MEMF_TOTAL);
                chip[3] = AvailMem(MEMF_CHIP | MEMF_LARGEST);
                chip[1] = chip[2] - chip[0];
                fast[0] = AvailMem(MEMF_FAST);
                fast[2] = AvailMem(MEMF_FAST | MEMF_TOTAL);
                fast[3] = AvailMem(MEMF_FAST | MEMF_LARGEST);
                fast[1] = fast[2] - fast[0];
                total[0] = AvailMem(MEMF_ANY);
                total[2] = AvailMem(MEMF_ANY | MEMF_TOTAL);
                total[3] = AvailMem(MEMF_ANY | MEMF_LARGEST);
                total[1] = total[2] - total[0];

                Permit();

                if (PutStr("Type   Available    In-Use   Maximum   Largest\n") < 0 ||
                        printm("chip", chip, 4) < 0 ||
                        printm("fast", fast, 4) < 0 ||
                        printm("total", total, 4) < 0)
                {
                    error = RETURN_ERROR;
                }
            }
        }

        FreeArgs(rda);
    }
    else
    {
        error = RETURN_FAIL;
    }

    if(error != RETURN_OK && bPrintErr)
    {
        PrintFault(IoErr(), "Avail");
    }

    return error;
}
示例#24
0
int main(int argc, char *argv[])
{
  BYTE *p1=buffer1,*p2=buffer2;
  void *tmp;
  ULONG signals,length;
  struct AHIRequest *link = NULL;
  LONG priority = 0;
  BYTE pri;

  if(argc == 2)
  {
    StrToLong(argv[1], &priority);
  }
  pri = priority;
  Printf("Sound priority: %ld\n", pri);

  if((AHImp=CreateMsgPort()) != NULL) {
    if((AHIio=(struct AHIRequest *)CreateIORequest(AHImp,sizeof(struct AHIRequest))) != NULL) {
      AHIio->ahir_Version = 4;
      AHIDevice=OpenDevice(AHINAME,0,(struct IORequest *)AHIio,0);
    }
  }

  if(AHIDevice) {
    Printf("Unable to open %s/0 version 4\n",AHINAME);
    cleanup(RETURN_FAIL);
  }

// Make a copy of the request (for double buffering)
  AHIiocopy = AllocMem(sizeof(struct AHIRequest), MEMF_ANY);
  if(! AHIiocopy) {
    cleanup(RETURN_FAIL);
  }
  CopyMem(AHIio, AHIiocopy, sizeof(struct AHIRequest));
  AHIios[0]=AHIio;
  AHIios[1]=AHIiocopy;

  SetIoErr(0);

  for(;;) {

// Fill buffer
    length = Read(Input(),p1,BUFFERSIZE);

// Play buffer
    AHIios[0]->ahir_Std.io_Message.mn_Node.ln_Pri = pri;
    AHIios[0]->ahir_Std.io_Command  = CMD_WRITE;
    AHIios[0]->ahir_Std.io_Data     = p1;
    AHIios[0]->ahir_Std.io_Length   = length;
    AHIios[0]->ahir_Std.io_Offset   = 0;
    AHIios[0]->ahir_Frequency       = FREQUENCY;
    AHIios[0]->ahir_Type            = TYPE;
    AHIios[0]->ahir_Volume          = 0x10000;          // Full volume
    AHIios[0]->ahir_Position        = 0x8000;           // Centered
    AHIios[0]->ahir_Link            = link;
    SendIO((struct IORequest *) AHIios[0]);

    if(link) {

// Wait until the last buffer is finished (== the new buffer is started)
      signals=Wait(SIGBREAKF_CTRL_C | (1L << AHImp->mp_SigBit));

// Check for Ctrl-C and abort if pressed
      if(signals & SIGBREAKF_CTRL_C) {
        SetIoErr(ERROR_BREAK);
        break;
      }

// Remove the reply and abort on error
      if(WaitIO((struct IORequest *) link)) {
        SetIoErr(ERROR_WRITE_PROTECTED);
        break;
      }
    }

// Check for end-of-sound, and wait until it is finished before aborting
    if(length != BUFFERSIZE) {
      WaitIO((struct IORequest *) AHIios[0]);
      break;
    }

    link = AHIios[0];

// Swap buffer and request pointers, and restart
    tmp    = p1;
    p1     = p2;
    p2     = tmp;

    tmp    = AHIios[0];
    AHIios[0] = AHIios[1];
    AHIios[1] = tmp;
  }
  

// Abort any pending iorequests
  AbortIO((struct IORequest *) AHIios[0]);
  WaitIO((struct IORequest *) AHIios[0]);

  if(link) { // Only if the second request was started
    AbortIO((struct IORequest *) AHIios[1]);
    WaitIO((struct IORequest *) AHIios[1]);
  }

  if(IoErr()) {
    PrintFault(IoErr(), argv[0] );
    cleanup(RETURN_ERROR);
  }

  cleanup(RETURN_OK);
  return RETURN_OK; // Make compiler happy
}
示例#25
0
文件: 7zMain.c 项目: diegocr/7zUI
int main( VOID )
{
	LONG arg[5] = {0};
	struct RDArgs *args = NULL;
	int rc = 10;
	
	if((G = (struct GlobalData*)AllocMem(sizeof(struct GlobalData),MEMF_PUBLIC|MEMF_CLEAR)))
	{
		/* Initialize 'GlobalData' */
		
		G->WbStartup = ((_WBenchMsg != NULL) ? TRUE : FALSE);
		
		if((IntuitionBase = OpenLibrary("intuition.library", 0)))
		{
			if((DOSBase = OpenLibrary("dos.library", 0)))
			{
				args = ReadArgs( TEMPLATE, (long*)arg, NULL);
				if(!args)
				{
					if((rc = _7zUI ( )) != 0 )
					{
						/* failed creating MUI App */
						
						if( G->WbStartup )
							DisplayBeep(NULL);
						
						PrintFault(IoErr(),0L);
					}
				}
				else
				{
					int mode = 1;
					BPTR WhereToExtract = 0, 
						OldCurrentdir = 0;
					
					G->CliUsage = TRUE;
					
					if( TOFOLDER )
					{
						MakeDir( TOFOLDER );
						
						mode=SwitchCurrentdir(TOFOLDER,
							&WhereToExtract, 
							&OldCurrentdir );
					}
					
					if( mode )
					{
						mode = LIST_ARG ? 1 : TEST_ARG ? 2:3;
						
						rc = _7zArchive( ARCHIVE_ARG, mode );
						
						if( TOFOLDER )
						  SwitchCurrentdir(NULL,
							&WhereToExtract,
							&OldCurrentdir);
					}
					
					FreeArgs( args );
				}
				
				CloseLibrary( DOSBase );
			}
			
			CloseLibrary( IntuitionBase );
		}
		
		FreeMem( G, sizeof(struct GlobalData));
	}
	
	return rc;
}
示例#26
0
int main(void)
{
    struct DateTime curr;
    char day[LEN_DATSTRING];
    char time[LEN_DATSTRING];
    char date[LEN_DATSTRING];
    struct DateStamp stamp;

    curr.dat_Format  = FORMAT_DOS;
    curr.dat_Flags   = 0;
    curr.dat_StrDay  = day;
    curr.dat_StrDate = date;
    curr.dat_StrTime = time;  

    DateStamp(&curr.dat_Stamp);
    DateToStr(&curr);
    Printf("Current time: %s, %s, %s\n", day, date, time);
    
    BPTR fh = Open("__TEST__", MODE_NEWFILE);
    
    if (fh != BNULL)
    {
        struct FileInfoBlock *fib = AllocDosObject(DOS_FIB, NULL);
        
        if (fib != NULL)
        {
            if (ExamineFH(fh, fib))
            { 
        	curr.dat_Stamp = fib->fib_Date;
        	DateToStr(&curr);
                Printf("File modification time: %s, %s, %s\n", day, date, time);
            }
            else
        	PrintFault(IoErr(), "Examine failed");

            Printf("Waiting 5 seconds\n");
            Delay(5*50);
            
            DateStamp(&stamp);
            
            Printf("Calling SetFileDate\n");
            if(SetFileDate("__TEST__", &stamp))
            {
                if (ExamineFH(fh, fib))
                { 
                    curr.dat_Stamp = fib->fib_Date;
                    DateToStr(&curr);
                    Printf("New file modification time: %s, %s, %s\n", day, date, time);
                }
                else
                    PrintFault(IoErr(), "Examine failed");        	
            }
            else
        	PrintFault(IoErr(), "SetFileDate");
            
            FreeDosObject(DOS_FIB, fib);
        }
        else 
            PrintFault(IoErr(), "Couldn't alloc FileInfoBlock");
            
        Close(fh);
        DeleteFile("__TEST__");
    }
    else
	PrintFault(IoErr(), "Couldn't create file");
    
    return 0;
}
示例#27
0
int main(int argc, char **argv)
{
    ULONG ret = RETURN_FAIL;

    OOP_AttrBase HiddGfxAttrBase     = 0;
    OOP_AttrBase HiddGCAttrBase      = 0;
    OOP_AttrBase HiddBitMapAttrBase  = 0;

    OOP_Object   *gfxHidd;
    OOP_Object   *bitMap;
    OOP_Object   *gc;

    STRPTR hiddName = "graphics.hidd";
    ULONG  fg       = 1;
    ULONG  bg       = 2;

    /* ReadArgs() declarations                */
    /* each entry must have a size of 4 bytes */
    struct Args
    {
        STRPTR hiddName;
        IPTR   *fg;
        IPTR   *bg;
    };

    struct Args args = {hiddName, &fg, &bg};
    struct RDArgs *rda;


    if(ght_OpenLibs(LibsArray))
    {
        rda = ReadArgs("HIDD/K,FG/N/K,BG/N/K", (IPTR *)&args, NULL);
        if (rda != NULL)
        {
            HIDDGraphicsBase = OpenLibrary(args.hiddName, 0);
            if(HIDDGraphicsBase)
            {
                ret = RETURN_ERROR;

                HiddGfxAttrBase    = OOP_ObtainAttrBase(IID_Hidd_Gfx);
                HiddBitMapAttrBase = OOP_ObtainAttrBase(IID_Hidd_BitMap);
                HiddGCAttrBase     = OOP_ObtainAttrBase(IID_Hidd_GC);
                if(HiddGfxAttrBase && HiddBitMapAttrBase && HiddGCAttrBase)
                {
                    gfxHidd = OOP_NewObject(NULL, args.hiddName, NULL);
                    if(gfxHidd)
                    {
                        bitMap = HIDD_Gfx_NewBitMap(gfxHidd, NULL);
                        if(bitMap)
                        {
                            struct TagItem gc_tags[] =
                            {
                                {aHidd_GC_BitMap,     (IPTR) bitMap},
                                {aHidd_GC_Foreground, (IPTR) *args.fg},
                                {aHidd_GC_Background, (IPTR) *args.bg},
                                {TAG_DONE, 0UL}
                            };

                            gc = HIDD_Gfx_NewGC(gfxHidd, gc_tags);
                            if(gc)
                            {
                                printf("GC created:\n");
                                printf("  fg    : %li\n", ght_GetAttr(gc, aHidd_GC_Foreground));
                                printf("  bg    : %li\n", ght_GetAttr(gc, aHidd_GC_Background));
                                printf("  drMode: %li\n", ght_GetAttr(gc, aHidd_GC_DrawMode));
                                printf("  bitMap: %li\n", ght_GetAttr(gc, aHidd_GC_BitMap));
        
                                HIDD_Gfx_DisposeGC(gfxHidd, gc);
        
                                ret = RETURN_OK;
                            }
        
                            HIDD_Gfx_DisposeBitMap(gfxHidd, bitMap);
                        }

                        if(gfxHidd) OOP_DisposeObject(gfxHidd);
                    } /* if(gfxHidd) */
                }  /* if(HiddGfxAttrBase && HiddBitMapAttrBase && HiddGCAttrBase) */

                if(HiddGCAttrBase)     OOP_ReleaseAttrBase(IID_Hidd_GC);
                if(HiddBitMapAttrBase) OOP_ReleaseAttrBase(IID_Hidd_BitMap);
                if(HiddGfxAttrBase)    OOP_ReleaseAttrBase(IID_Hidd_Gfx);

                CloseLibrary(HIDDGraphicsBase);
            } /* if(HIDDGraphicsBase) */

            FreeArgs(rda);
        }
        else
        {
           PrintFault(IoErr(), "");
        }  /* if (rda != NULL) */

    } /* if OpenLibs() */

    ght_CloseLibs(LibsArray);

    return(ret);
}
示例#28
0
int main ( int argc, char *argv[] )
{
    struct RDArgs *rda = NULL;
    ULONG sigs;
    globalEvents = -1;
    globalCurrentTool = LUNA_TOOL_BRUSH;

    // Init brush
    brushTool.antialias = TRUE; // TODO: load from config set toolbox cycle!
    brushTool.width = 1;
    brushTool.height = 1;
    brushTool.feather = TRUE; // TODO: load from config and set toolbox cycle!

    // Set the colors
    prevColor = 0;
    currColor = 0;
    globalColor = 0;

    BOOL keyIsDown = FALSE;
    keyboardEnabled = TRUE;
    // Starts up the application

#ifdef __amigaos4__
   MUIMasterBase = OpenLibrary("muimaster.library", 0);
    if (!MUIMasterBase) {
        printf("Error opening muimaster library\n");
        exit(0);
    };

    IMUIMaster = (struct MUIMasterIFace *) GetInterface(MUIMasterBase, "main", 1, NULL);

    if (!MUIMasterBase && !IMUIMaster) {
        printf("Error opening muimaster library\n");
        exit(0);
    };

   CyberGfxBase = OpenLibrary("cybergraphics.library", 0);
    if (!CyberGfxBase) {
        printf("Error opening cybergraphics library\n");
        exit(0);
    };

    ICyberGfx = (struct CyberGfxIFace *) GetInterface(CyberGfxBase, "main", 1, NULL);

    if (!CyberGfxBase && !ICyberGfx) {
        printf("Error opening muimaster library\n");
        exit(0);
    };
#endif


    struct MsgPort *port;
    Forbid();
    port = FindPort("LUNAPAINT");
    Permit();
    if ( port == NULL)
    {
        Locale_Initialize();
        Init_Application ( );
    } else { // Double Start
        // TODO: open projects when clicking on icons from there
        goto quit;
    }
    if (argc)
    {
        IPTR args[ ARG_CNT ] = {0};

        rda = ReadArgs ( ARG_TEMPLATE, args, NULL );
        if ( ! rda )
        {
            PrintFault( IoErr ( ), argv[0] );
            goto exit;
        }

        if ( args[ARG_FILE] )
        {
            STRPTR *file = (STRPTR *)args[ARG_FILE];
            while ( *file )
            {
                LoadProject ( *file, FALSE );
                file++;
            }
        }
    }

    // Main loop
    while ( getSignals ( &sigs ) )
    {
        // Check for signals from GUI
        if ( checkSignalBreak ( &sigs ) )
            break;

        if ( keyboardEnabled )
        {
            // Execute keyboard events on key press
            if ( evalRawKey >= IECODE_ASCII_FIRST && evalRawKey < IECODE_ASCII_LAST )
            {
                if ( !keyIsDown )
                {
                    keyIsDown = TRUE;
                    checkKeyboardShortcuts ( evalRawKey );
                }
            }
        }
        // We always register keyup strokes
        if ( evalRawKey & IECODE_UP_PREFIX )
            keyIsDown = FALSE;

        // Execute pending events
        if ( globalActiveWindow && globalActiveCanvas )
            doEvents ( );

        // Reset events
        globalEvents = -1;

        // Mouse clicks
        if ( mouseClickCount > 0 ) mouseClickCount--;

        // Delayed canvas redraw
        if ( redrawTimes == 1 )
        {
            if ( globalActiveWindow )
                DoMethod ( globalActiveWindow->area, MUIM_Draw );
            redrawTimes--;
        }
        if ( redrawTimes > 0 ) redrawTimes--;
    }

    // Exists the application and cleans up reserved resources
exit:
    Exit_Application ( );
    Locale_Deinitialize();

#ifdef __amigaos4__

    if(MUIMasterBase &&  IMUIMaster)  DropInterface((struct Interface *)IMUIMaster);
    if (MUIMasterBase)      CloseLibrary(MUIMasterBase);

    if(CyberGfxBase && ICyberGfx)  DropInterface((struct Interface *)ICyberGfx);
    if(CyberGfxBase)      CloseLibrary(CyberGfxBase);

#endif

    if (rda) FreeArgs(rda);
quit:
    return 0;
}
示例#29
0
int main(void)
{
    struct AnchorPath aPath;
    struct RDArgs  *rda;
    IPTR            args[5] = { NULL, NULL, NULL, NULL, FALSE };
    struct DateTime dt;
    LONG            error = 0;
    BPTR            oldCurDir;
    LONG            retval = RETURN_OK;
    BOOL            timeError = FALSE; /* Error in time/date specification? */

    rda = ReadArgs("FILE/A,WEEKDAY,DATE,TIME,ALL/S", args, NULL);

    if(rda == NULL)
    {
	PrintFault(IoErr(), "SetDate");
	return RETURN_FAIL;
    }

    /* Use the current time as default (if no DATE, TIME or WEEKDAY is
       defined) */
    DateStamp(&dt.dat_Stamp);

    dt.dat_Flags   = DTF_FUTURE;
    dt.dat_Format  = FORMAT_DOS;
    dt.dat_StrDate = (TEXT *)args[ARG_DATE];
    dt.dat_StrTime = (TEXT *)args[ARG_TIME];

    /* Change the defaults according to the user's specifications */
    if(StrToDate(&dt))
    {
	dt.dat_StrDate = (TEXT *)args[ARG_WEEKDAY];

	if(!StrToDate(&dt))
	    timeError = TRUE;
    }
    else
	timeError = TRUE;
   
    if(timeError)
    {
	PutStr("SetDate: Illegal DATE or TIME string\n");
	return RETURN_FAIL;
    }


    aPath.ap_Flags = (BOOL)args[ARG_ALL] ? APF_DOWILD : 0;
    aPath.ap_BreakBits = SIGBREAKF_CTRL_C;
    aPath.ap_Strlen = 0;

    /* Save the current dir */
    oldCurDir = CurrentDir(NULL);
    CurrentDir(oldCurDir);

    error = MatchFirst((STRPTR)args[ARG_FILE], &aPath);

    while(error == 0)
    {
	CurrentDir(aPath.ap_Current->an_Lock);

	// VPrintf("%s", (IPTR *)&aPath.ap_Info.fib_FileName);
	
	SetFileDate(aPath.ap_Info.fib_FileName, &dt.dat_Stamp);

	error = MatchNext(&aPath);
    }
    
    MatchEnd(&aPath);

    /* Restore the current dir */
    CurrentDir(oldCurDir);
    
    FreeArgs(rda);

    if(error != ERROR_NO_MORE_ENTRIES)
    {
	if(error == ERROR_BREAK)
	    retval = RETURN_WARN;
	else
	    retval = RETURN_FAIL;

	PrintFault(IoErr(), "SetDate");
    }

    return retval;
}	
示例#30
0
int
main( void )
{
  struct RDArgs *rdargs;
  int            rc = RETURN_OK;

  GfxBase       = (struct GfxBase *) OpenLibrary( GRAPHICSNAME, 37 );
  IntuitionBase = (struct IntuitionBase *) OpenLibrary( "intuition.library", 37 );
  
  if( GfxBase == NULL )
  {
    Printf( "Unable to open %s version %ld\n", (ULONG) GRAPHICSNAME, 37 );
    cleanup();
    return RETURN_FAIL;
  }

  if( IntuitionBase == NULL )
  {
    Printf( "Unable to open %s version %ld\n", (ULONG) "intuition.library", 37 );
    cleanup();
    return RETURN_FAIL;
  }

  rdargs = ReadArgs( TEMPLATE , (LONG *) &args, NULL );

  if( rdargs != NULL )
  {
    /* Refresh database */

    if( args.refresh && !args.remove )
    {
      ULONG id;

      OpenAHI();

      /* First, empty the database */
      
      for( id = AHI_NextAudioID( AHI_INVALID_ID );
           id != (ULONG) AHI_INVALID_ID;
           id = AHI_NextAudioID( AHI_INVALID_ID ) )
      {
        AHI_RemoveAudioMode( id );
      }

      /* Now add all modes */

      if( !AHI_LoadModeFile( "DEVS:AudioModes" ) )
      {
        if( IS_MORPHOS )
        {
          ULONG res;

          /* Be quiet here. - Piru */
          APTR *windowptr = &((struct Process *) FindTask(NULL))->pr_WindowPtr;
          APTR oldwindowptr = *windowptr;
          *windowptr = (APTR) -1;
          res = AHI_LoadModeFile( "MOSSYS:DEVS/AudioModes" );
          *windowptr = oldwindowptr;

          if( !res )
          {
            if( !args.quiet )
            {
              PrintFault( IoErr(), "AudioModes" );
            }

            rc = RETURN_ERROR;
          }
        }
        else
        {
          if ( !args.quiet )
          {
            PrintFault( IoErr(), "DEVS:AudioModes" );
          }

          rc = RETURN_ERROR;
        }
      }
    }

    /* Load mode files */

    if( args.files != NULL && !args.remove )
    {
      int i = 0;

      OpenAHI();

      while( args.files[i] )
      {
        if( !AHI_LoadModeFile( args.files[i] ) && !args.quiet )
        {
          PrintFault( IoErr(), args.files[i] );
          rc = RETURN_ERROR;
        }
        i++;
      }
    }

    /* Remove database */

    if( args.remove )
    {
      if( args.files || args.refresh )
      {
        PutStr( "The REMOVE switch cannot be used together with FILES or REFRESH.\n" );
        rc = RETURN_FAIL;
      }
      else
      {
        ULONG id;

        OpenAHI();

        for( id = AHI_NextAudioID( AHI_INVALID_ID );
             id != (ULONG) AHI_INVALID_ID;
             id = AHI_NextAudioID( AHI_INVALID_ID ) )
        {
          AHI_RemoveAudioMode( id );
        }
      }
    }

    /* Make display mode doublescan (allowing > 28 kHz sample rates) */

    if( args.dblscan )
    {
      ULONG          id;
      ULONG          bestid = INVALID_ID;
      int            minper = INT_MAX;
      struct Screen *screen = NULL;

      static const struct ColorSpec colorspecs[] =
      {
        { 0, 0, 0, 0 },
        { 1, 0, 0, 0 },
        {-1, 0, 0, 0 }
      };
      
      union {
        struct MonitorInfo mon;
        struct DisplayInfo dis;
      } buffer;

      for( id = NextDisplayInfo( INVALID_ID );
           id != (ULONG) INVALID_ID;
           id = NextDisplayInfo( id ) )
      {
        int period;

        if( GetDisplayInfoData( NULL, 
                                (UBYTE*) &buffer.dis, sizeof(buffer.dis),
                                DTAG_DISP, id ) )
        {
          if( !(buffer.dis.PropertyFlags & (DIPF_IS_ECS | DIPF_IS_AA ) ) )
          {
            continue;
          }
        }

        if( GetDisplayInfoData( NULL,
                                (UBYTE*) &buffer.mon, sizeof(buffer.mon),
                                DTAG_MNTR, id ) )
        {
          period = buffer.mon.TotalColorClocks * buffer.mon.TotalRows
                   / ( 2 * ( buffer.mon.TotalRows - buffer.mon.MinRow + 1 ) );

          if( period < minper )
          {
            minper = period;
            bestid = id;
          }
        }

      }

      if( bestid != (ULONG) INVALID_ID && minper < 100 )
      {
        screen = OpenScreenTags( NULL,
                                 SA_DisplayID,  bestid,
                                 SA_Colors,    (ULONG) &colorspecs,
                                 TAG_DONE );
      }
      else if( ( GfxBase->ChipRevBits0 & (GFXF_HR_DENISE | GFXF_AA_LISA ) ) != 0 )
      {
        /* No suitable screen mode found, let's bang the hardware...
           Using code from Sebastiano Vigna <*****@*****.**>. */

        struct Custom *custom = (struct Custom *) 0xdff000;

        custom->bplcon0  = 0x8211;
        custom->ddfstrt  = 0x0018;
        custom->ddfstop  = 0x0058;
        custom->hbstrt   = 0x0009;
        custom->hsstop   = 0x0017;
        custom->hbstop   = 0x0021;
        custom->htotal   = 0x0071;
        custom->vbstrt   = 0x0000;
        custom->vsstrt   = 0x0003;
        custom->vsstop   = 0x0005;
        custom->vbstop   = 0x001D;
        custom->vtotal   = 0x020E;
        custom->beamcon0 = 0x0B88;
        custom->bplcon1  = 0x0000;
        custom->bplcon2  = 0x027F;
        custom->bplcon3  = 0x00A3;
        custom->bplcon4  = 0x0011;
      }

      if( screen != NULL )
      {
        CloseScreen( screen );
      }
    }

    FreeArgs( rdargs );
  }

  cleanup();
  return rc;
}