Example #1
0
int main(int argc, char **argv)
{
    struct myargs args = {NULL};
    struct RDArgs *rda;

    if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0))) 
    {
	if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0))) 
        {
	    if ((DOSBase = (struct DosLibrary *) OpenLibrary("dos.library",0)))
	    {
		rda = ReadArgs("LEFT/K/N,TOP/K/N,WIDTH/N,HEIGHT/N,DEPTH/K/N,MODEID/K,OVERSCAN/K/N,SCROLL/K/N,DRAG/K/N,LIKEWB/K/N", (IPTR *)&args, NULL);
		if (rda) {
		    struct Screen *screen;
		    struct Window *w1;
		    ULONG oserr = 0;
		    struct TagItem tags[] = {
			{SA_Width,     640			         },
			{SA_Height,    480			         },
			{SA_Depth,     4			         },
			{TAG_IGNORE,   0			         },
			{TAG_IGNORE,   0			         },
			{TAG_IGNORE,   0			         },
			{TAG_IGNORE,   0			         },
			{TAG_IGNORE,   0			         },
			{TAG_IGNORE,   0			         },
			{TAG_IGNORE,   0			         },
			{SA_Title,     (IPTR)"Screen opening and movement test"},
			{SA_ErrorCode, (IPTR)&oserr			         },
			{TAG_DONE,     0				 }
		    };

		    if (args.width)
		        tags[0].ti_Data = *args.width;
		    if (args.height)
		        tags[1].ti_Data = *args.height;
		    if (args.depth)
		        tags[2].ti_Data = *args.depth;
		    printf("Opening screen, size: %lux%lu, depth: %lu\n", tags[0].ti_Data, tags[1].ti_Data, tags[3].ti_Data);
		    if (args.mode) {
		        tags[3].ti_Tag  = SA_DisplayID;
			tags[3].ti_Data = strtoul(args.mode, NULL, 16);
			printf("ModeID: 0x%08lX\n", tags[3].ti_Data);
		    }
		    if (args.scroll) {
			tags[4].ti_Tag = SA_AutoScroll;
			tags[4].ti_Data = *args.scroll;
			printf("SA_AutoScroll: %ld\n", tags[4].ti_Data);
		    }
		    if (args.drag) {
			tags[5].ti_Tag = SA_Draggable;
			tags[5].ti_Data = *args.drag;
			printf("SA_Draggable: %ld\n", tags[5].ti_Data);
		    }
		    if (args.likewb) {
			tags[6].ti_Tag = SA_LikeWorkbench;
			tags[6].ti_Data = *args.likewb;
			printf("SA_LikeWorkbench: %ld\n", tags[6].ti_Data);
		    }
		    if (args.oscan) {
			tags[7].ti_Tag = SA_Overscan;
			tags[7].ti_Data = *args.oscan;
			printf("SA_Overscan: %ld\n", tags[7].ti_Data);
		    }
		    if (args.left) {
			tags[8].ti_Tag = SA_Left;
			tags[8].ti_Data = *args.left;
			printf("SA_Left: %ld\n", tags[8].ti_Data);
		    }
		    if (args.top) {
			tags[9].ti_Tag = SA_Top;
			tags[9].ti_Data = *args.top;
			printf("SA_Top: %ld\n", tags[9].ti_Data);
		    }

		    screen = OpenScreenTagList(NULL, tags);
                    if (screen) {
			w1 = openwindow(screen, "Screen data",  W1_LEFT, W1_TOP, W1_WIDTH, W1_HEIGHT);
			if (w1) {
			    WORD x = w1->BorderLeft;
		            WORD y = w1->BorderTop;
			    struct BitMap *bitmap = screen->RastPort.BitMap;

			    y = drawtext(w1, x, y, "Requested size: %lux%lu", tags[0].ti_Data, tags[1].ti_Data);
			    y = drawtext(w1, x, y, "Requested depth: %lu", tags[2].ti_Data);
			    if (args.mode)
			        y = drawtext(w1, x, y, "Requested ModeID: 0x%08lX", tags[3].ti_Data);
			    y = drawtext(w1, x, y, "Actual size: %ux%u", screen->Width, screen->Height);
			    y = drawtext(w1, x, y, "Actual ModeID: 0x%08X", screen->ViewPort.ColorMap->VPModeID);
			    y = drawtext(w1, x, y, "Flags: 0x%04lX", screen->Flags);
			    y = drawtext(w1, x, y, "BitMap size: %ux%u", GetBitMapAttr(bitmap, BMA_WIDTH), GetBitMapAttr(bitmap, BMA_HEIGHT));
			    y = drawtext(w1, x, y, "BitMap depth: %u", GetBitMapAttr(bitmap, BMA_DEPTH));
			    handleevents(w1, screen, x, y);
			    CloseWindow(w1);
			}
		        CloseScreen(screen);
		    } else
		        printf("Failed to open screen, error: %d\n", (int)oserr);
		    FreeArgs(rda);
	        } else
		    printf("Error parsing arguments\n");
                CloseLibrary((struct Library *)DOSBase);
	    }
	    CloseLibrary((struct Library *)GfxBase);
	}
	CloseLibrary((struct Library *) IntuitionBase);
    }
    return 0;
} /* main */
Example #2
0
File: main.c Project: michalsc/AROS
        timerPort->mp_Flags = PA_IGNORE;
    }

    if (tr)
    {
        if (!OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)tr, 0))
        {
            TimerBase = (struct TimerBase *)tr->tr_node.io_Device;
        }
    } else return 0;

    GetCPUInfo(tags);

    D(bug("[SMP-Smallpt] %s: detected %d CPU cores\n", __func__, coreCount);)

    rda = ReadArgs(ARG_TEMPLATE, args, NULL);
    if (rda != NULL)
    {
        LONG *ptr = (LONG *)args[ARG_MAXCPU];
        if (ptr)
            max_cpus = *ptr;

        ptr = (LONG *)args[ARG_RAYDEPTH];
        if (ptr) {
            maximal_ray_depth = *ptr;
            if (maximal_ray_depth < 2)
                maximal_ray_depth = 2;
        }

        ptr = (LONG *)args[ARG_MAXITER];
        if (ptr)
Example #3
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. Did you try C:BindDrivers?\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;
}
Example #4
0
LONG
main(VOID)
{
  struct DosLibrary *DOSBase;

  struct RDArgs  *readargs;
  LONG            rargs[5], vargs[5];
  UBYTE          *source, *target;
  ULONG           buffersize = 0;
  UBYTE          *sourcedir, *targetdir;
  UBYTE          *textbuffer, *tmp, *tmp1, *tmp2;
  struct AnchorPath *anchorpath;
  struct FileInfoBlock *fib, *targetfib;
  struct Process *process;
  APTR            wptr;
  BPTR            dirlock, filelock;
  BOOL            checkdatestamp, all;
  LONG            date, error, rc = 0;


  /* Fail silently if < 37 */
  if (DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37))
  {
    rargs[0] = 0L;
    rargs[1] = 0L;
    rargs[2] = 0L;
    rargs[3] = 0L;
    rargs[4] = 0L;

    if (readargs = ReadArgs("SOURCE/A,TARGET/A,DATE/S,ALL/S,BUFFER/K/N", rargs, NULL))
    {

      source = (UBYTE *) rargs[0];
      target = (UBYTE *) rargs[1];
      checkdatestamp = (BOOL) rargs[2];
      all = (BOOL) rargs[3];

      if (!(sourcedir = AllocMem(StrLen(source) + 129, MEMF_CLEAR)))
        error = ERROR_NO_FREE_STORE;
      else
      {
        /* 128 bytes to print informative text */
        textbuffer = sourcedir + StrLen(source) + 1;

        /* use user specified buffersize if indicated */
        if (rargs[4])
          buffersize = *((LONG *) rargs[4]);
        if (buffersize < BUFFERSIZE || buffersize > 4096)
          buffersize = BUFFERSIZE;

        if (!(targetdir = AllocMem(buffersize, MEMF_CLEAR)))
          error = ERROR_NO_FREE_STORE;
        else
        {
          if (!(targetfib = AllocDosObject(DOS_FIB, NULL)))
            error = ERROR_NO_FREE_STORE;
          else
          {

            /*
             * Check if source and target are valid.
             *
             * Separate source path from pattern (if any). Use the source path figure
             * out what to append to the target.
             */

            /* No requesters */
            process = (struct Process *) FindTask(NULL);
            wptr = process->pr_WindowPtr;
            process->pr_WindowPtr = (APTR) - 1L;

            if ((error = GetPath(source, sourcedir, StrLen(source) + 1) == 0))
            {
              if (!(dirlock = Lock(sourcedir, SHARED_LOCK)))
                error = IoErr();
              else
              {
                UnLock(dirlock);
                if (!(dirlock = Lock(target, SHARED_LOCK)))
                  error = IoErr();
                else
                {
                  UnLock(dirlock);

                  if (anchorpath = AllocMem(sizeof(struct AnchorPath) + buffersize,
                                            MEMF_CLEAR))
                  {
                    anchorpath->ap_Strlen = buffersize;

                    /* Allow to break on CTRL-C */
                    anchorpath->ap_BreakBits = SIGBREAKF_CTRL_C;

                    if ((error = MatchFirst(source, anchorpath)) == 0)
                    {

                      do
                      {
                        fib = &(anchorpath->ap_Info);

                        /*
                         * APF_DIDDIR indicates that we used returned from a
                         * directory. In that case we clear both APF_DIDDIR and
                         * APF_DODIR, so we can start afresh with the next one.
                         */


                        if (anchorpath->ap_Flags & APF_DIDDIR)
                          anchorpath->ap_Flags &= ~(APF_DODIR | APF_DIDDIR);
                        else
                        {

                          /*
                           * Make a filename for the target directory. First copy
                           * targetname into buffer.
                           */
                          targetdir[0] = '\0';
                          tmp = targetdir;
                          tmp1 = target;
                          while (*tmp++ = *tmp1++);

                          /* Skip sourcename in ap_Buf */
                          tmp1 = sourcedir;
                          tmp2 = anchorpath->ap_Buf;
                          while (*tmp1++ == *tmp2++);
                          /* Skip back 1 if not after a separator */
                          if (*(tmp2 - 1) != '/')
                            tmp2--;

                          /*
                           * We hit the source itself, don't compare it, but enter
                           * it.
                           */
                          if (*tmp2 == 0)
                          {
                            anchorpath->ap_Flags |= APF_DODIR;
                            continue;
                          }

                          /* Build it */
                          if (AddPart(targetdir, tmp2, buffersize - 1))
                            vargs[0] = (LONG) targetdir;
                          else
                          {
                            PrintFault(ERROR_NO_FREE_STORE, NULL);
                            break;
                          }

                          /* Lock it and check it out */
                          if (filelock = Lock(targetdir, SHARED_LOCK))
                          {
                            if ((Examine(filelock, targetfib)) == DOSTRUE)
                            {
                              textbuffer[0] = '\0';

                              /*
                               * To get nice output without work I use AddPart() to
                               * add differences to the textbuffer.
                               */
                              if (targetfib->fib_DirEntryType
                                  != fib->fib_DirEntryType)
                                AddPart(textbuffer, "of different type", 128);
                              else
                              {
                                if (targetfib->fib_Size < fib->fib_Size)
                                  AddPart(textbuffer, "smaller", 128);
                                else if (targetfib->fib_Size > fib->fib_Size)
                                  AddPart(textbuffer, "larger", 128);

                                if (checkdatestamp)
                                {
                                  date = CompareDates((struct DateStamp *)
                                        & (fib->fib_Date),
                                      (struct DateStamp *) & (targetfib->fib_Date));
                                  if (date < 0)
                                    AddPart(textbuffer, "older", 128);
                                  else if (date > 0)
                                    AddPart(textbuffer, "newer", 128);
                                }
                              }


                              if (*textbuffer != NULL)
                              {
                                vargs[1] = (LONG) textbuffer;
                                VFPrintf(Output(), "%s: object %s\n", vargs);
                              }
                            }
                            else
                              PrintFault(IoErr(), targetdir);
                            UnLock(filelock);
                          }
                          else
                          {
                            PrintFault(IoErr(), targetdir);

                            /*
                             * If and error occured on a directory name, don't enter
                             * it.
                             */
                            if (fib->fib_DirEntryType > 0)
                              continue;

                          }

                          /*
                           * If the ALL keyword has been used and this is a directory
                           * enter it by setting the APF_DODIR flag.
                           */

                          if (fib->fib_DirEntryType > 0 && all != FALSE)
                            anchorpath->ap_Flags |= APF_DODIR;

                        }

                      } while ((error = MatchNext(anchorpath)) == 0);
                    }

                    MatchEnd(anchorpath);

                    if (error == ERROR_NO_MORE_ENTRIES)
                      error = 0;

                    FreeMem(anchorpath, sizeof(struct AnchorPath) + buffersize);
                  }
                }
              }
              /* Reset windowpointer */
              process->pr_WindowPtr = wptr;
            }
            else
              PrintFault(error, NULL);
            FreeDosObject(DOS_FIB, targetfib);
          }
          FreeMem(targetdir, buffersize);
        }
        FreeMem(sourcedir, StrLen(sourcedir) + 129);
      }
      FreeArgs(readargs);
    }
    else
      error = IoErr();

    SetIoErr(error);
    if (error)
    {
      PrintFault(error, NULL);
      if (error = ERROR_BREAK)
        rc = RETURN_WARN;
      else
        error = RETURN_FAIL;
    }
    CloseLibrary((struct Library *) DOSBase);
  }
  return (rc);
}