Esempio n. 1
0
int main(void) {
	char cmd[MAX_CMD];
	ShellCmds *c;

	bzero(CWD, MAX_CMD);
	strcpy(CWD, "/");

	if (InitFS(512*1024)) {
		puts("Failed to initialize the RAM file system\n");
		return(-1);
	}

	puts("Welcome to the cgcfs shell!");
	puts("Type help for a list of available commands.");
	printf("% ");
	bzero(cmd, MAX_CMD);
	while (readUntil(cmd, MAX_CMD-1, '\n') != -1) {
		ParseArgs(cmd);

		// parse failure
		if (ARGC == 0) {
			FreeArgs();
			bzero(cmd, MAX_CMD);
			printf("% ");
			continue;
		}

		// find the command being requested
		if (ARGV[0] != NULL) {
			c = cmds;
			while (c->command != NULL) {
				if (!strcmp(c->command, ARGV[0])) {
					// run the command
					c->handler();

					break;
				}
				c++;
			}
		}
		if (c == NULL) {
			puts("Invalid command");
		}
		if (c->command == NULL) {
			puts("Invalid command");
		}

		FreeArgs();
		bzero(cmd, MAX_CMD);
		printf("% ");
	}

	if (DestroyFS()) {
		puts("Failed to destroy the RAM file system\n");
		return(-1); 
	}

	return(0);

}
Esempio n. 2
0
Int2 Main (void)

{
    Char buf[256] = { '\0' };  /* Used below for name and version. */
    Int2 status = 0;    /* return value of function. */

    StringCpy(buf, "bl2seq ");
    StringNCat(buf, BlastGetVersionNumber(), sizeof(buf)-StringLen(buf)-1);
    if (! GetArgs (buf, NUMARG, myargs)) {
        return (1);
    }

    UseLocalAsnloadDataAndErrMsg ();

    if (! SeqEntryLoad())
                return 1;

    ErrSetMessageLevel(SEV_WARNING);

    if (myargs[ARG_FORCE_OLD].intvalue != 0)
        status = Main_old();
    else
        status = Main_new();

    FreeArgs(NUMARG, myargs);

    return status;
}
Esempio n. 3
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;
}
Esempio n. 4
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;
}
Esempio n. 5
0
JNIEXPORT jobjectArray JNICALL Java_mit_moira_MoiraConnectInternal_mr_1query
    (JNIEnv *env, jclass Class, jstring jcommand, jobjectArray jargs) {
    ListBlock *listblock = NewListBlock();
    jobjectArray retval;
    int status;
    const char *command;
    char icommand[1024];
    char **args = ConvertJavaArgs(env, jargs);
    if (args == NULL) return (NULL); /* It probably thru an exception */
    command = (*env)->GetStringUTFChars(env, jcommand, 0);
    strncpy(icommand, command, sizeof(icommand));

    status = mr_query(icommand, (*env)->GetArrayLength(env, jargs), args, 
			 StashResults, listblock);
    FreeArgs(args);			/* Don't need them anymore */
    if (status != MR_SUCCESS) {
	FreeListBlock(listblock);
	throwMoiraException(env, status);
	return (0);
    }
    /*    if (listblock->count == 0) { / * No such list or empty list * /
	FreeListBlock(listblock);
	throwMoiraExceptionMess(env, "No Such List or Empty List");
	return(0);
    } */

    if (listblock->count == 0) return (0);

    retval = ListBlockToJavaArray(env, listblock);
    FreeListBlock(listblock);
    return (retval);

}
Esempio n. 6
0
void NewFreeArgs(struct NewRDArgs *rdargs)
{
  ENTER();

  D(DBF_STARTUP, "FreeArgs(rdargs->FreeArgs)");
  FreeArgs(rdargs->FreeArgs);

  if(rdargs->RDArgs != NULL)
  {
    free((void *)rdargs->RDArgs->RDA_Source.CS_Buffer);

    D(DBF_STARTUP, "FreeDosObject(DOS_RDARGS, rdargs->RDArgs)");
    FreeDosObject(DOS_RDARGS, rdargs->RDArgs);
  }

  if(rdargs->Args != NULL)
  {
    ULONG i;

    for(i=0; i < rdargs->MaxArgs; i++)
    {
      if(rdargs->Args[i] != NULL)
        FreeVecPooled(rdargs->Pool, rdargs->Args[i]);
    }
    FreeVecPooled(rdargs->Pool, rdargs->Args);
    rdargs->Args = NULL;
  }

  if(rdargs->ToolWindow != NULL)
  {
    FreeVecPooled(rdargs->Pool, rdargs->ToolWindow);
    rdargs->ToolWindow = NULL;
  }

  if(rdargs->WinFH != 0)
  {
    D(DBF_STARTUP, "SelectOutput( .. ) .. Close( ... )");
    SelectOutput(rdargs->OldOutput);
    SelectInput(rdargs->OldInput);
    Close(rdargs->WinFH);
    rdargs->WinFH = 0;
  }

  if(rdargs->Pool != NULL)
  {
    #if defined(__amigaos4__)
    FreeSysObject(ASOT_MEMPOOL, rdargs->Pool);
    #else
    DeletePool(rdargs->Pool);
    #endif
    rdargs->Pool = NULL;
  }

  D(DBF_STARTUP, "memory freed");

  LEAVE();
}
Esempio n. 7
0
int lib_dos_f_FreeArgs_2(emumsg_syscall_t *msg)
{
	/* Make real syscall */
	FreeArgs(
		(struct RDArgs *)msg->arg[0]._aptr
	);

	return HOOK_DONE;
}
Esempio n. 8
0
/* Free all resources allocated in ParseTemplate */
VOID FreeTemplate(APTR m)
{
	ULONG *mem = (ULONG*)m;
	if(mem)
	{
		if(mem[2]) FreeArgs((struct RDArgs*)mem[2]);
		if(mem[1]) FreeVec((APTR)mem[1]);
		if(mem[0]) FreeDosObject(DOS_RDARGS,(APTR)mem[0]);
	}
	FreeVec(mem);
}
Esempio n. 9
0
void fail(char *str)
{
    if(ArgsHook)
    {
        FreeArgs(ArgsHook);
        ArgsHook = NULL;
    }
    if(str)
    {
        PutStr(str);
        exit(20);
    }
    exit(0);
}
Esempio n. 10
0
VOID
FreeExit( LONG rc )
{
    if( Menus )
    {
        if( WindowPtr )
        {
            ClearMenuStrip( WindowPtr );
        }

        FreeMenus( Menus );
    }

    CloseGUI();

    if( Screen )
    {
        FreeScreenDrawInfo( Screen, DrawInfo );
        UnlockPubScreen (NULL, Screen );
    }

    if( GadToolsBase )
    {
        FreeVisualInfo( VisualInfo );
    }

    if( FileReq )
    {
        rtFreeRequest( FileReq );
    }

    if( DiskObject )
    {
        FreeDiskObject( DiskObject );
    }

    FreeArgs( RDArgs );
    FreeLocale();

    CloseLib( GadToolsBase );
    CloseLib( IconBase );
    CloseLib( IntuitionBase );
    CloseLib( ReqToolsBase );
    CloseLib( UtilityBase );

    CloseLibrary( ( struct Library * ) GfxBase );
    __exit( rc );
}
Esempio n. 11
0
static void cleanup(char *msg, ULONG retcode)
{
    if (msg && !args[ARG_QUIET]) 
    {
    	fprintf(stderr, "CopyToPAR: %s\n", msg);
    }
    
    if (fh) Close(fh);
    if (myargs) FreeArgs(myargs);
    
    if (ParOpen) CloseDevice((struct IORequest *)ParIO);
    if (ParIO) DeleteIORequest((struct IORequest *)ParIO);
    if (ParMP) DeleteMsgPort(ParMP);
    
    exit(retcode);
}
Esempio n. 12
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;
}
Esempio n. 13
0
static void Cleanup(char *msg)
{
    WORD rc;
    
    if (msg)
    {
    	Printf("damagelist: %s\n",msg);
	rc = RETURN_WARN;
    } else {
    	rc = RETURN_OK;
    }
    
    if (MyArgs) FreeArgs(MyArgs);
   
    if (rc != RETURN_OK)
        longjmp(exit_buf, rc);
}
Esempio n. 14
0
static void Cleanup(char *msg)
{
    if (msg)
    {
	printf("clippingtest: %s\n",msg);
    }

    if (win) CloseWindow(win);

    if (myargs) FreeArgs(myargs);

    if (LayersBase) CloseLibrary(LayersBase);
    if (GfxBase) CloseLibrary((struct Library *)GfxBase);
    if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);

    exit(0);
}
Esempio n. 15
0
static void Cleanup(char *msg)
{
    WORD rc;
    
    if (msg)
    {
    	printf("crlist: %s\n",msg);
	rc = RETURN_WARN;
    } else {
    	rc = RETURN_OK;
    }
    
    if (MyArgs) FreeArgs(MyArgs);
    
    if (GfxBase) CloseLibrary((struct Library *)GfxBase);
    if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
    
    exit(rc);
}
Esempio n. 16
0
/****** SmartReadArgs/SmartFreeArgs ******************************************
 * NAME
 *   SmartFreeArgs -- Free all resources allocated by SmartReadArgs().
 * SYNOPSIS
 *   SmartFreeArgs(smart_args);
 *
 *   void SmartFreeArgs(struct SmartArgs *);
 * FUNCTION
 *   Free all resources allocated by a previous call to SmartReadArgs().
 * INPUTS
 *   smart_args - Same pointer as passed to SmartReadArgs() before
 * NOTES
 *   Always call SmartFreeArgs(), even if SmartReadArgs() failed! Take a look
 *   at the example for SmartReadArgs().
 * SEE ALSO
 *   SmartReadArgs()
 ****************************************************************************/
void SmartFreeArgs(struct SmartArgs *args)
{
   /* FreeArgs() can handle a NULL pointer */
   FreeArgs(args->sa_FreeArgs);

   if (args->sa_Flags & SAF_ALLOCRDARGS)
      if (args->sa_RDArgs)
         FreeDosObject(DOS_RDARGS, args->sa_RDArgs);

   if (args->sa_Flags & SAF_ALLOCBUFFER)
      FreeMem(args->sa_Buffer, args->sa_BufferSize);

   if (args->sa_WindowFH)
   {
      SelectOutput(args->sa_OldOutput);
      SelectInput(args->sa_OldInput);
      Close(args->sa_WindowFH);
   }

   if (args->sa_Flags & SAF_ALLOCWINDOW && args->sa_Window)
      FreeVec(args->sa_Window);

}
Esempio n. 17
0
// Free font data
void font_free(font_data *data)
{
	if (data)
	{
		// Close stuff
		font_close(data);

		// Free font
		if (data->font) CloseFont(data->font);

		// Free port
		DeleteMsgPort(data->appport);

		// Close locale stuff
		if (data->locale.li_Locale)
		{
			CloseLocale(data->locale.li_Locale);
			CloseCatalog(data->locale.li_Catalog);
		}

		// Free args
		FreeArgs(data->args);

		// Free labels
		FreeVec(data->size_labels);

		// Free data
		FreeVec(data);
	}

	// Close library
#ifdef __amigaos4__
	DropInterface((struct Interface *)IDOpus);
#endif
	CloseLibrary(DOpusBase);
}
Esempio n. 18
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 );
}
Esempio n. 19
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);
}
Esempio n. 20
0
static DispatchReturn NaClSrpcReceiveAndDispatch(NaClSrpcChannel* channel,
                                                 NaClSrpcRpc* rpc_stack_top) {
  NaClSrpcRpc rpc;
  NaClSrpcArg* args[NACL_SRPC_MAX_ARGS + 1];
  NaClSrpcArg* rets[NACL_SRPC_MAX_ARGS + 1];
  NaClSrpcMethod method;
  ssize_t bytes_read;
  RpcCheckingClosure* closure = NULL;
  /* DISPATCH_EOF is the closest we have to an error return. */
  DispatchReturn dispatch_return = DISPATCH_EOF;

  closure = (RpcCheckingClosure*) malloc(sizeof *closure);
  if (NULL == closure) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "NaClSrpcReceiveAndDispatch(channel=%p):"
                "closure malloc failed\n",
                (void*) channel);
    dispatch_return = DISPATCH_EOF;
    goto done;
  }
  if (!NaClSrpcRpcCtor(&rpc, channel) ||
      !RpcCheckingClosureCtor(closure, &rpc)) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "NaClSrpcReceiveAndDispatch(channel=%p): constructor failed\n",
                (void*) channel);
    goto done;
  }
  rpc.rets = rets;
  /* Read a message from the channel. */
  bytes_read = SrpcPeekMessage(channel->message_channel, &rpc);
  if (bytes_read < 0) {
    goto done;
  }
  if (rpc.is_request) {
    /* This is a new request. */
    if (NULL == channel->server) {
      if (NULL == rpc_stack_top) {
        /* There is no service to dispatch requests. Abort. */
        dispatch_return = DISPATCH_EOF;
        goto done;
      } else {
        /* Inform the pending invoke that a failure happened. */
        NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                    "NaClSrpcReceiveAndDispatch(channel=%p):"
                    "out of order request\n",
                    (void*) channel);
        rpc_stack_top->result = NACL_SRPC_RESULT_INTERNAL;
        dispatch_return = DISPATCH_BREAK;
        goto done;
      }
    }
    /* Fall through to request handling below. */
  } else {
    /* This is a response to a pending request. */
    if (NULL == rpc_stack_top) {
      NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                  "NaClSrpcReceiveAndDispatch(channel=%p):"
                  "response, no pending request\n",
                  (void*) channel);
      /* There is no pending request. Abort. */
      dispatch_return = DISPATCH_BREAK;
      goto done;
    } else {
      if (rpc.request_id == rpc_stack_top->request_id) {
        /* Copy the serialized portion of the Rpc and process as a response. */
        memcpy(rpc_stack_top, &rpc, kRpcSize);
        dispatch_return = DISPATCH_RESPONSE;
        goto done;
      } else {
        /* Received an out-of-order response.  Abort. */
        NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                    "NaClSrpcReceiveAndDispatch(channel=%p):"
                    " response for wrong request\n",
                    (void*) channel);
        dispatch_return = DISPATCH_BREAK;
        goto done;
      }
    }
  }
  bytes_read = RecvRequest(channel->message_channel, &rpc, args, rets);
  if (bytes_read < 0) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "NaClSrpcReceiveAndDispatch(channel=%p):"
                "RecvRequest failed, bytes=%"NACL_PRIdS"\n",
                (void*) channel,
                bytes_read);
    dispatch_return = DISPATCH_EOF;
  }
  if (!RequestVectorTypesConform(channel, &rpc, args, rets)) {
    NaClSrpcLog(NACL_SRPC_LOG_WARNING,
                "NaClSrpcReceiveAndDispatch(channel=%p):"
                " arg/ret type mismatch (recoverable error)\n",
                (void*) channel);
    dispatch_return = DISPATCH_CONTINUE;
    goto done;
  }
  /* Then we invoke the method, which computes a return code. */
  method = NaClSrpcServiceMethod(channel->server, rpc.rpc_number);
  if (NULL == method) {
    NaClSrpcLog(NACL_SRPC_LOG_WARNING,
                "NaClSrpcReceiveAndDispatch(channel=%p):"
                " bad rpc_number %"NACL_PRIu32" (recoverable error)\n",
                (void*) channel,
                rpc.rpc_number);
    dispatch_return = DISPATCH_CONTINUE;
    goto done;
  }
  do {
    const char* rpc_name;
    const char* arg_types;
    const char* ret_types;
    int i;
    NaClSrpcServiceMethodNameAndTypes(channel->server,
                                      rpc.rpc_number,
                                      &rpc_name,
                                      &arg_types,
                                      &ret_types);
    NaClSrpcLog(1, "NaClSrpcReceiveAndDispatch:"
                " request(channel=%p, rpc_number=%"NACL_PRIu32
                ", rpc_name=\"%s\")\n",
                (void*) channel,
                rpc.rpc_number,
                rpc_name);
    for (i = 0; args[i] != NULL; i++ ) {
      char buffer[256];
      NaClSrpcFormatArg(2, args[i], buffer, NACL_ARRAY_SIZE(buffer));
      NaClSrpcLog(2,
                  "NaClSrpcReceiveAndDispatch:"
                  " request(channel=%p, args[%d]=%s)\n",
                  (void*) channel,
                  i,
                  buffer);
    }
  } while(0);
  (*method)(&rpc, args, rets, (NaClSrpcClosure*) closure);
  FreeArgs(args);
  FreeArgs(rets);
  /* The invoked method takes ownership of the closure and deletes it. */
  closure = NULL;
  /*
   * Return code to either continue or break out of the processing loop.
   * When we separate closure invocation from the dispatch loop we will
   * have to implement a barrier to make sure that all preceding RPCs are
   * completed, and then signal the dispatcher to stop.
   */
  if (rpc.dispatch_loop_should_continue) {
    dispatch_return = DISPATCH_CONTINUE;
  } else {
    dispatch_return = DISPATCH_BREAK;
  }

 done:
  free(closure);
  return dispatch_return;
}
Esempio n. 21
0
int
ResourceEntry( void )
{
  struct ISAPNPBase* ISAPNPBase;
  struct RDArgs*     rdargs;
  int                rc = -1;

  struct 
  {
    ULONG   m_ShowConfig;
    ULONG   m_ShowOptions;
/*  ULONG   m_Remove;*/
  } args = { FALSE, FALSE/*, FALSE*/ };

  if( ! OpenLibs() )
  {
    CloseLibs();
    return RETURN_FAIL;
  }

  ISAPNPBase = (struct ISAPNPBase* ) OpenResource( ISAPNPNAME );

  if( ISAPNPBase == NULL )
  {
    Printf( ISAPNPNAME " not found.\n" );
    CloseLibs();
    return RETURN_FAIL;
  }

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

  if( rdargs != NULL )
  {
    if( ! args.m_ShowConfig && args.m_ShowOptions )
    {
      Printf( "SHOWOPTIONS can only be used together with SHOWCONFIG\n" );
      rc = RETURN_ERROR;
    }
    else
    {
      if( args.m_ShowConfig )
      {
        ShowCards( args.m_ShowOptions, ISAPNPBase );
        rc = RETURN_OK;
      }
      
/*    if( args.m_Remove )
      {
        // Dangerous! Only for debugging

        FreeISAPNPBase( ISAPNPBase );

        ISAPNPBase->m_ConfigDev->cd_Flags  |= CDF_CONFIGME;
        ISAPNPBase->m_ConfigDev->cd_Driver  = NULL;
        RemResource( ISAPNPBase );

        rc = RETURN_OK;
      }*/
    }

    FreeArgs( rdargs );
  }

  if( rc == -1 )
  {
    Printf( "Usage: ISA-PnP [ SHOWCONFIG [ SHOWOPTIONS ] ] [ REMOVE ]\n" );
    rc = RETURN_ERROR;
  }
  

  CloseLibs();

  return rc;
}
Esempio n. 22
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;
}
Esempio n. 23
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);
}
Esempio n. 24
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;
}
Esempio n. 25
0
static ssize_t RecvRequest(struct NaClSrpcMessageChannel* channel,
                           NaClSrpcRpc* rpc,
                           NaClSrpcArg** inputs,
                           NaClSrpcArg** results) {
  struct NaClImcMsgIoVec iov[IOV_ENTRY_MAX];
  const size_t kMaxIovLen = NACL_ARRAY_SIZE(iov);
  size_t iov_len;
  NaClSrpcMessageHeader header;
  NaClSrpcImcDescType descs[NACL_SRPC_MAX_ARGS];
  size_t expected_bytes;
  ssize_t retval;

  /*
   * SrpcPeekMessage should have been called before this function, and should
   * have populated rpc.  Make sure that rpc points to a sane header.
   */
  if (!rpc->is_request ||
      rpc->template_len > NACL_SRPC_MAX_ARGS ||
      rpc->value_len > NACL_SRPC_MAX_ARGS) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvRequest: rpc header invalid: is_request %"NACL_PRIu32", "
                "template_len %"NACL_PRIu32", value_len %"NACL_PRIu32"\n",
                rpc->is_request,
                rpc->template_len,
                rpc->value_len);
    retval = -NACL_ABI_EINVAL;
    goto done;
  }
  /*
   * A request will contain two vectors of NaClSrpcArgs.  Set the index
   * pointers passed in to new argument vectors that will be filled during
   * the next peek.
   */
  if (!AllocateArgs(results, rpc->template_len) ||
      !AllocateArgs(inputs, rpc->value_len)) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvRequest: AllocateArgs failed\n");
    retval = -NACL_ABI_EINVAL;
    goto done;
  }

  /*
   * Having read the header we know how many elements each argument vector
   * contains.  The next peek reads the fixed portion of these argument vectors,
   * but cannot yet read the variable length portion, because we do not yet
   * know the counts of array types or strings.
   */
  iov_len = 0;
  expected_bytes = 0;
  AddIovEntry(rpc, kRpcSize, kMaxIovLen, iov, &iov_len, &expected_bytes);
  AddFixed(results, rpc->template_len, kMaxIovLen, iov, &iov_len,
           &expected_bytes);
  AddFixed(inputs, rpc->value_len, kMaxIovLen, iov, &iov_len, &expected_bytes);
  header.iov = iov;
  header.iov_length = (nacl_abi_size_t) iov_len;
  header.NACL_SRPC_MESSAGE_HEADER_DESCV = NULL;
  header.NACL_SRPC_MESSAGE_HEADER_DESC_LENGTH = 0;
  retval = NaClSrpcMessageChannelPeek(channel, &header);
  if (retval < (ssize_t) expected_bytes) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvRequest:"
                "NaClSrpcMessageChannelPeek incomplete: expected %"
                NACL_PRIdS", got %"NACL_PRIdS"\n",
                expected_bytes,
                retval);
    retval = ErrnoFromImcRet(retval);
    goto done;
  }

  /*
   * After peeking the fixed portion of the argument vectors we are ready to
   * read the nonfixed portions as well.  So the read just adds the IOV entries
   * for the nonfixed portions of the arguments.
   */
  iov_len = 0;
  expected_bytes = 0;
  AddIovEntry(rpc, kRpcSize, kMaxIovLen, iov, &iov_len, &expected_bytes);
  ClearTemplateStringLengths(results, rpc->template_len);
  AddFixed(results, rpc->template_len, kMaxIovLen, iov, &iov_len,
           &expected_bytes);
  AddFixed(inputs, rpc->value_len, kMaxIovLen, iov, &iov_len, &expected_bytes);
  if (!AddNonfixedForRead(results, rpc->template_len, kMaxIovLen,
                          1, 0, iov, &iov_len, &expected_bytes)) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvRequest: AllocateArgs failed for results\n");
    retval = -NACL_ABI_EIO;
    goto done;
  }
  if (!AddNonfixedForRead(inputs, rpc->value_len, kMaxIovLen,
                          1, 1, iov, &iov_len, &expected_bytes)) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvRequest: AllocateArgs failed for inputs\n");
    retval = -NACL_ABI_EIO;
    goto done;
  }
  header.iov = iov;
  header.iov_length = (nacl_abi_size_t) iov_len;
  header.NACL_SRPC_MESSAGE_HEADER_DESCV = descs;
  header.NACL_SRPC_MESSAGE_HEADER_DESC_LENGTH = NACL_ARRAY_SIZE(descs);
  retval = NaClSrpcMessageChannelReceive(channel, &header);
  if (retval < (ssize_t) expected_bytes) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvRequest:"
                " NaClSrpcMessageChannelReceive incomplete: expected %"
                NACL_PRIdS", got %"NACL_PRIdS"\n",
                expected_bytes,
                retval);
    retval = ErrnoFromImcRet(retval);
    goto done;
  }

  /*
   * The read left any descriptors passed in the descs array.  We need to
   * copy those descriptors to the inputs vector.
   */
  if (!GetHandles(inputs, rpc->value_len,
                  descs, header.NACL_SRPC_MESSAGE_HEADER_DESC_LENGTH)) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvRequest: GetHandles failed\n");
    retval = -NACL_ABI_EIO;
    goto done;
  }
  /*
   * Success, the caller has taken ownership of the memory we allocated
   * for inputs and results.
   */
  inputs = NULL;
  results = NULL;

 done:
  FreeArgs(inputs);
  FreeArgs(results);
  return retval;
}
Esempio n. 26
0
int main(int argc, char **argv) {
  struct RDArgs *rdargs = NULL;
  int i;
  char pubscreen[32];

  if(argc) {
    rdargs=ReadArgs( TEMPLATE , (LONG *) &args, NULL);
    SaveIcons  = FALSE;
  }
  else {
    struct WBStartup *WBenchMsg = (struct WBStartup *)argv;
    struct WBArg *wbarg;
    BPTR olddir;
    struct DiskObject *dobj;
    STRPTR* toolarray;
    UBYTE *s;

    SaveIcons  = TRUE;

    for(i=0, wbarg=WBenchMsg->sm_ArgList;
      i < WBenchMsg->sm_NumArgs;
      i++, wbarg++) {

      olddir = (BPTR) -1;
      if((wbarg->wa_Lock)&&(*wbarg->wa_Name))
          olddir = CurrentDir(wbarg->wa_Lock);


      if((*wbarg->wa_Name) && (dobj=GetDiskObject(wbarg->wa_Name))) {
        toolarray = dobj->do_ToolTypes;

        s = FindToolType(toolarray,"CREATEICONS");

        if( s != NULL ) {
          if( MatchToolValue(s,"NO") ||
              MatchToolValue(s,"FALSE")) {
            SaveIcons = FALSE;
          }
        }

        s = (char *) FindToolType(toolarray,"PUBSCREEN");

        if( s != NULL ) {
          strncpy(pubscreen, s, sizeof pubscreen);
          args.pubscreen = pubscreen;
        }

        s = (char *) FindToolType(toolarray,"ACTION");

        if( s != NULL ) {
          if(MatchToolValue(s,"EDIT")) {
            args.edit = TRUE;
          }
          else if(MatchToolValue(s,"USE")) {
            args.use = TRUE;
          }
          else if(MatchToolValue(s,"SAVE")) {
            args.save = TRUE;
          }
        }

        FreeDiskObject(dobj);
      }

      if((i>0)&&(*wbarg->wa_Name)) {
        args.from = wbarg->wa_Name;
      }

      if(olddir != (BPTR) -1) {
        CurrentDir(olddir); /* CD back where we were */
      }
    }
  
  }

  if(args.from == NULL) {
    args.from = ENVFILE;
  }

  if(args.edit) {
    args.use  = FALSE;
    args.save = FALSE;
  }

  if((SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) == 0) {
    if(Initialize()) {

      NewSettings(args.from);

      if((!args.use && !args.save) || args.edit) {
        if(BuildGUI(args.pubscreen)) {
          EventLoop();
        }
        CloseGUI();
      }

      if(args.use || args.save) {
        SaveSettings(ENVFILE, UnitList);
      }

      if(args.save) {
        SaveSettings(ENVARCFILE, UnitList);
      }
    }
  }

  if(rdargs) {
    FreeArgs(rdargs);
  }

  FreeVec(Units);
  FreeVec(Modes);
  FreeVec(Outputs);
  FreeVec(Inputs);
  FreeList(ModeList);
  FreeList(UnitList);

  CleanUp();

  return 0;
}
Esempio n. 27
0
int main(int argc, char **argv)
{
	ULONG DisplayID,Depth;
	struct Screen *CyberScreen;
	struct Window *WriteWindow;
	LONG done;
	struct IntuiMessage *IntMsg;
	IMAGE image;
	LONG src_x,src_y, old_src_x,old_src_y;
	ULONG argarray[2];
	struct RDArgs *rdargs;
	char *file;

	rdargs = ReadArgs((STRPTR)arg_template, (LONG*)argarray, NULL);
	if(!rdargs)
		return 20;

	file = (char*)argarray[0];

	IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",39L);
	if(!IntuitionBase)
		return 20;

	CyberGfxBase = OpenLibrary(CYBERGFXNAME,CYBERGFXVERSION);
	if(!CyberGfxBase)
	{
		ErrorF ("Can't open \"%s\" version %ld or newer.",
			CYBERGFXNAME,CYBERGFXVERSION);
		CloseLibrary (&IntuitionBase->LibNode);
		return 10;
	}

	if(!Load(file, &image))
	{
		ErrorF ("Can't load image.");
		FreeArgs(rdargs);
		CloseLibrary (CyberGfxBase);
		CloseLibrary (&IntuitionBase->LibNode);
		return 10;
	}

	/* Let CyberGraphX search a display mode for us! */

	if(argarray[1])
		Depth = 16;
	else
		Depth = 24;

	FreeArgs(rdargs);

	while (Depth)
	{
		DisplayID = BestCModeIDTags(CYBRBIDTG_NominalWidth, image.width,
			CYBRBIDTG_NominalHeight, image.height,
			CYBRBIDTG_Depth, Depth,
			TAG_DONE);
		if(DisplayID != INVALID_ID)
		{
			/* Because older version of the "cybergraphics.library" don't handle */
			/* CYBRBIDTG_Depth properly we query the real depth of the mode.     */
			Depth = GetCyberIDAttr(CYBRIDATTR_DEPTH,DisplayID);
			break;
		}
		/* retry with less bits per pixel */
		Depth = NextDepth(Depth);
	}

	if (Depth < SCREEN_MIN_DEPTH)
	{
		ErrorF ("Can't find suitable display mode for %ldx%ldx.",
			image.width, image.height);
		CloseLibrary (CyberGfxBase);
		CloseLibrary (&IntuitionBase->LibNode);
		Cleanup(&image);
		return 5;
	}

	/* open screen, but let Intuition choose the actual dimensions */

	CyberScreen = OpenScreenTags(
		NULL,
		SA_Title,"RayStorm Image Viewer (C) 1998 Andreas Heumann",
		SA_DisplayID,DisplayID,
		SA_Depth,Depth,
		TAG_DONE);
	if(!CyberScreen)
	{
		ErrorF ("Can't open screen.");
		CloseLibrary (CyberGfxBase);
		CloseLibrary (&IntuitionBase->LibNode);
		Cleanup(&image);
		return 5;
	}

	/* create Write window */

	WriteWindow = OpenWindowTags(
		NULL,
		WA_Title,"Viewer",
		WA_Flags,
			WFLG_ACTIVATE|WFLG_SIMPLE_REFRESH|WFLG_RMBTRAP,
		WA_IDCMP,
			IDCMP_REFRESHWINDOW|IDCMP_VANILLAKEY|IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS,
		WA_Borderless, TRUE,
		WA_Left, 0,
		WA_Top, 0,
		WA_Width, image.width,
		WA_Height, image.height,
		WA_CustomScreen,CyberScreen,
		TAG_DONE);
	if(!WriteWindow)
	{
		ErrorF ("Can't open write window.");
		CloseScreen (CyberScreen);
		CloseLibrary (CyberGfxBase);
		CloseLibrary (&IntuitionBase->LibNode);
		Cleanup(&image);
		return 5;
	}

	src_x = 0;
	src_y = 0;
	WritePixelArray(
		image.colormap,
		src_x, src_y,
		image.width*sizeof(SMALL_COLOR),
		WriteWindow->RPort,
		0, 0,
		image.width,
		image.height,
		RECTFMT_RGBA);

	/* event loop */

	done = FALSE;
	while (!done)
	{
		(void)Wait(SIGMASK(WriteWindow));

		while (IntMsg=GETIMSG(WriteWindow))
		{
			switch (IntMsg->Class)
			{
				case IDCMP_REFRESHWINDOW:
					BeginRefresh(WriteWindow);
					WritePixelArray(
						image.colormap,
						src_x, src_y,
						image.width*sizeof(SMALL_COLOR),
						WriteWindow->RPort,
						0, 0,
						image.width,
						image.height,
						RECTFMT_RGBA);
					EndRefresh(WriteWindow,TRUE);
					break;
				case IDCMP_VANILLAKEY:
					switch(IntMsg->Qualifier & 0x7fff)
					{
						case 0:
							switch (IntMsg->Code)
							{
								case 27:
									done = TRUE;
									break;
							}
							break;
					}
					break;
				case IDCMP_RAWKEY:
					old_src_x = src_x;
					old_src_y = src_y;
					switch(IntMsg->Code)
					{
						case CURSORRIGHT:
							if(src_x + WriteWindow->Width + WriteWindow->LeftEdge < image.width)
							{
								src_x += 8;
								if(src_x + WriteWindow->Width + WriteWindow->LeftEdge > image.width)
									src_x = image.width - WriteWindow->Width - WriteWindow->LeftEdge;
							}
							break;
						case CURSORLEFT:
							if(src_x > 0)
							{
								src_x -= 8;
								if(src_x < 0)
									src_x = 0;
							}
							break;
						case CURSORDOWN:
							if(src_y + WriteWindow->Height + WriteWindow->TopEdge < image.height)
							{
								src_y += 8;
								if(src_y + WriteWindow->Height + WriteWindow->TopEdge > image.height)
									src_y = image.height - WriteWindow->Height - WriteWindow->TopEdge;
							}
							break;
						case CURSORUP:
							if(src_y > 0)
							{
								src_y -= 8;
								if(src_y < 0)
									src_y = 0;
							}
							break;
					}
					if((old_src_x != src_x) || (old_src_y != src_y))
					{
						if(old_src_x < src_x)
						{
							ClipBlit(
								WriteWindow->RPort,
								src_x - old_src_x,
								0,
								WriteWindow->RPort,
								0,
								0,
								WriteWindow->Width + WriteWindow->LeftEdge - (src_x - old_src_x),
								WriteWindow->Height + WriteWindow->TopEdge,
								0xc0);
							WritePixelArray(
								image.colormap,
								old_src_x + WriteWindow->Width + WriteWindow->LeftEdge,
								src_y,
								image.width*sizeof(SMALL_COLOR),
								WriteWindow->RPort,
								WriteWindow->Width + WriteWindow->LeftEdge - (src_x - old_src_x),
								0,
								src_x - old_src_x,
								WriteWindow->Height + WriteWindow->TopEdge,
								RECTFMT_RGBA);
						}
						else if(old_src_x > src_x)
						{
							ClipBlit(
								WriteWindow->RPort,
								0,
								0,
								WriteWindow->RPort,
								old_src_x - src_x,
								0,
								WriteWindow->Width + WriteWindow->LeftEdge - (old_src_x - src_x),
								WriteWindow->Height + WriteWindow->TopEdge,
								0xc0);
							WritePixelArray(
								image.colormap,
								src_x,
								src_y,
								image.width*sizeof(SMALL_COLOR),
								WriteWindow->RPort,
								0,
								0,
								old_src_x - src_x,
								WriteWindow->Height + WriteWindow->TopEdge,
								RECTFMT_RGBA);
						}
						else if(old_src_y < src_y)
						{
							ClipBlit(
								WriteWindow->RPort,
								0,
								src_y - old_src_y,
								WriteWindow->RPort,
								0,
								0,
								WriteWindow->Width + WriteWindow->LeftEdge,
								WriteWindow->Height + WriteWindow->TopEdge - (src_y - old_src_y),
								0xc0);
							WritePixelArray(
								image.colormap,
								src_x,
								old_src_y + WriteWindow->Height + WriteWindow->TopEdge,
								image.width*sizeof(SMALL_COLOR),
								WriteWindow->RPort,
								0,
								WriteWindow->Height + WriteWindow->TopEdge - (src_y - old_src_y),
								WriteWindow->Width + WriteWindow->LeftEdge,
								src_y - old_src_y,
								RECTFMT_RGBA);
						}
						else if(old_src_y > src_y)
						{
							ClipBlit(
								WriteWindow->RPort,
								0,
								0,
								WriteWindow->RPort,
								0,
								old_src_y - src_y,
								WriteWindow->Width + WriteWindow->LeftEdge,
								WriteWindow->Height + WriteWindow->TopEdge - (old_src_y - src_y),
								0xc0);
							WritePixelArray(
								image.colormap,
								src_x,
								src_y,
								image.width*sizeof(SMALL_COLOR),
								WriteWindow->RPort,
								0,
								0,
								WriteWindow->Width + WriteWindow->LeftEdge,
								old_src_y - src_y,
								RECTFMT_RGBA);
						}
					}
					break;
				case IDCMP_MOUSEBUTTONS:
					done = TRUE;
					break;
			}

			ReplyMsg (&IntMsg->ExecMessage);
		}
	}

	/* cleanup */

	CloseWindow(WriteWindow);
	CloseScreen(CyberScreen);
	CloseLibrary(CyberGfxBase);
	CloseLibrary(&IntuitionBase->LibNode);
	Cleanup(&image);

	return 0;
}
Esempio n. 28
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;
}
Esempio n. 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;
}	
Esempio n. 30
0
static ssize_t RecvResponse(struct NaClSrpcMessageChannel* channel,
                            NaClSrpcRpc* rpc,
                            NaClSrpcArg** results) {
  NaClSrpcArg* result_copy[NACL_SRPC_MAX_ARGS + 1];
  struct NaClImcMsgIoVec iov[IOV_ENTRY_MAX];
  const size_t kMaxIovLen = NACL_ARRAY_SIZE(iov);
  size_t iov_len = 0;
  NaClSrpcMessageHeader header;
  NaClSrpcImcDescType descs[NACL_SRPC_MAX_ARGS];
  size_t expected_bytes;
  ssize_t retval;
  size_t i;

  if (results == NULL) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvResponse: results should not be NULL\n");
    retval = -NACL_ABI_EINVAL;
    goto done;
  }
  /*
   * SrpcPeekMessage should have been called before this function, and should
   * have populated rpc.  Make sure that rpc points to a sane header.
   */
  if (rpc->is_request ||
      rpc->template_len > 0 ||
      rpc->value_len > NACL_SRPC_MAX_ARGS ||
      rpc->value_len != VectorLen(results)) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvResponse: rpc header invalid: is_request %"NACL_PRIu32", "
                "template_len %"NACL_PRIu32", value_len %"NACL_PRIu32"\n",
                rpc->is_request,
                rpc->template_len,
                rpc->value_len);
    return -NACL_ABI_EINVAL;
  }

  /*
   * Having read the header we know how many elements the results vector
   * contains.  The next peek reads the fixed portion of the results vectors,
   * but cannot yet read the variable length portion, because we do not yet
   * know the counts of array types or strings.  Because the results read
   * could conflict with the expected types, we need to read the fixed portion
   * into a copy.
   */
  if (!AllocateArgs(result_copy, rpc->value_len)) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvResponse: AllocateArgs failed\n");
    retval = -NACL_ABI_EINVAL;
    goto done;
  }
  iov_len = 0;
  expected_bytes = 0;
  AddIovEntry(rpc, kRpcSize, kMaxIovLen, iov, &iov_len, &expected_bytes);
  for (i = 0; i < rpc->value_len; ++i) {
    AddIovEntry(result_copy[i], kArgSize, kMaxIovLen, iov, &iov_len,
                &expected_bytes);
  }
  header.iov = iov;
  header.iov_length = (nacl_abi_size_t) iov_len;
  header.NACL_SRPC_MESSAGE_HEADER_DESCV = NULL;
  header.NACL_SRPC_MESSAGE_HEADER_DESC_LENGTH = 0;
  retval = NaClSrpcMessageChannelPeek(channel, &header);
  if (retval < (ssize_t) expected_bytes) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvResponse: NaClSrpcMessageChannelPeek incomplete: "
                "expected %"NACL_PRIdS", got %"NACL_PRIdS"\n",
                expected_bytes,
                retval);
    retval = ErrnoFromImcRet(retval);
    goto done;
  }

  /*
   * Check that the peeked results vector's types conform to the types passed
   * in and that any nonfixed size arguments are no larger than the counts
   * passed in from the caller.  If the values are acceptable, we copy the
   * actual sizes to the caller's vector.
   */
  if (!CheckMatchAndCopyCounts(rpc->value_len, results, result_copy)) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvResponse: CheckMatchAndCopyCounts failed\n");
    retval = -NACL_ABI_EIO;
    goto done;
  }

  /*
   * After peeking the fixed portion of the results vector we are ready to
   * read the nonfixed portion as well.  So the read just adds the IOV entries
   * for the nonfixed portion of results.
   */
  iov_len = 0;
  expected_bytes = 0;
  AddIovEntry(rpc, kRpcSize, kMaxIovLen, iov, &iov_len, &expected_bytes);
  AddFixed(results, rpc->value_len, kMaxIovLen, iov, &iov_len, &expected_bytes);
  if (!AddNonfixedForRead(results, rpc->value_len, kMaxIovLen,
                          0, 1, iov, &iov_len, &expected_bytes)) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvResponse: AddNonfixedForRead failed\n");
    retval = -NACL_ABI_EIO;
    goto done;
  }
  header.iov = iov;
  header.iov_length = (nacl_abi_size_t) iov_len;
  header.NACL_SRPC_MESSAGE_HEADER_DESCV = descs;
  header.NACL_SRPC_MESSAGE_HEADER_DESC_LENGTH = NACL_ARRAY_SIZE(descs);
  retval = NaClSrpcMessageChannelReceive(channel, &header);
  if (retval < (ssize_t) expected_bytes) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvResponse: NaClSrpcMessageChannelReceive incomplete: "
                "expected %"NACL_PRIdS", got %"NACL_PRIdS"\n",
                expected_bytes,
                retval);
    retval = ErrnoFromImcRet(retval);
    goto done;
  }

  /*
   * The read left any descriptors returned in the descs array.  We need to
   * copy those descriptors to the results vector.
   */
  if (!GetHandles(results, rpc->value_len,
                  descs, header.NACL_SRPC_MESSAGE_HEADER_DESC_LENGTH)) {
    NaClSrpcLog(NACL_SRPC_LOG_ERROR,
                "RecvResponse: GetHandles failed\n");
    retval = -NACL_ABI_EIO;
  }

 done:
  FreeArgs(result_copy);
  return retval;
}