Exemplo n.º 1
0
static Bool
xf86RandR12CrtcSet (ScreenPtr	    pScreen,
		    RRCrtcPtr	    randr_crtc,
		    RRModePtr	    randr_mode,
		    int		    x,
		    int		    y,
		    Rotation	    rotation,
		    int		    num_randr_outputs,
		    RROutputPtr	    *randr_outputs)
{
    XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
    xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
    xf86CrtcPtr		crtc = randr_crtc->devPrivate;
    RRTransformPtr	transform;
    Bool		changed = FALSE;
    int			o, ro;
    xf86CrtcPtr		*save_crtcs;
    Bool		save_enabled = crtc->enabled;

    if (!crtc->scrn->vtSema)
	return FALSE;

    save_crtcs = xalloc(config->num_output * sizeof (xf86CrtcPtr));
    if ((randr_mode != NULL) != crtc->enabled)
	changed = TRUE;
    else if (randr_mode && !xf86RandRModeMatches (randr_mode, &crtc->mode))
	changed = TRUE;
    
    if (rotation != crtc->rotation)
	changed = TRUE;

    transform = RRCrtcGetTransform (randr_crtc);
    if ((transform != NULL) != crtc->transformPresent)
	changed = TRUE;
    else if (transform && memcmp (&transform->transform, &crtc->transform.transform,
				  sizeof (transform->transform)) != 0)
	changed = TRUE;

    if (x != crtc->x || y != crtc->y)
	changed = TRUE;
    for (o = 0; o < config->num_output; o++) 
    {
	xf86OutputPtr  output = config->output[o];
	xf86CrtcPtr    new_crtc;

	save_crtcs[o] = output->crtc;
	
	if (output->crtc == crtc)
	    new_crtc = NULL;
	else
	    new_crtc = output->crtc;
	for (ro = 0; ro < num_randr_outputs; ro++) 
	    if (output->randr_output == randr_outputs[ro])
	    {
		new_crtc = crtc;
		break;
	    }
	if (new_crtc != output->crtc)
	{
	    changed = TRUE;
	    output->crtc = new_crtc;
	}
    }
    for (ro = 0; ro < num_randr_outputs; ro++) 
        if (randr_outputs[ro]->pendingProperties)
	    changed = TRUE;

    /* XXX need device-independent mode setting code through an API */
    if (changed)
    {
	crtc->enabled = randr_mode != NULL;

	if (randr_mode)
	{
	    DisplayModeRec  mode;
	    RRTransformPtr  transform = RRCrtcGetTransform (randr_crtc);

	    xf86RandRModeConvert (pScrn, randr_mode, &mode);
	    if (!xf86CrtcSetModeTransform (crtc, &mode, rotation, transform, x, y))
	    {
		crtc->enabled = save_enabled;
		for (o = 0; o < config->num_output; o++)
		{
		    xf86OutputPtr	output = config->output[o];
		    output->crtc = save_crtcs[o];
		}
		xfree(save_crtcs);
		return FALSE;
	    }
	    xf86RandR13VerifyPanningArea (crtc, pScreen->width, pScreen->height);
	    xf86RandR13Pan (crtc, randrp->pointerX, randrp->pointerY);
	    /*
	     * Save the last successful setting for EnterVT
	     */
	    crtc->desiredMode = mode;
	    crtc->desiredRotation = rotation;
	    if (transform) {
		crtc->desiredTransform = *transform;
		crtc->desiredTransformPresent = TRUE;
	    } else
		crtc->desiredTransformPresent = FALSE;

	    crtc->desiredX = x;
	    crtc->desiredY = y;
	}
	xf86DisableUnusedFunctions (pScrn);
    }
    xfree(save_crtcs);
    return xf86RandR12CrtcNotify (randr_crtc);
}
Exemplo n.º 2
0
#include "testutils.h"

#include "eddsa.h"
#include "eddsa-internal.h"

static void
test_eddsa_sign (const struct ecc_curve *ecc,
		 const struct nettle_hash *H,
		 const struct tstring *public,
		 const struct tstring *private,
		 const struct tstring *msg,
		 const struct tstring *ref)
{
  mp_limb_t *scratch = xalloc_limbs (_eddsa_sign_itch (ecc));
  size_t nbytes = 1 + ecc->p.bit_size / 8;
  uint8_t *signature = xalloc (2*nbytes);
  void *ctx = xalloc (H->context_size);
  uint8_t *public_out = xalloc (nbytes);
  uint8_t *digest = xalloc (2*nbytes);
  const uint8_t *k1 = digest + nbytes;
  mp_limb_t *k2 = xalloc_limbs (ecc->p.size);

  ASSERT (public->length == nbytes);
  ASSERT (private->length == nbytes);
  ASSERT (ref->length == 2*nbytes);

  _eddsa_expand_key (ecc, H, ctx, private->data,
		     digest, k2);
  _eddsa_public_key (ecc, k2, public_out, scratch);

  if (!MEMEQ (nbytes, public_out, public->data))
Exemplo n.º 3
0
/* This function builds a note list from an event list.  This note list
   is sorted by increasing starting time.  And notes are broken up so
   that each pair of notes either cover the identical time interval or
   they cover disjoint intervals. 
   
   The following fields of each note are filled in:
   start, duration, pitch, npc, base_tpc, next
   */
Note * build_note_list_from_event_list(Event * e) {
  int event_time, previous_event_time;
  int on_event, i, xet, event_n;
  Pitch pitch;
  Note * note_list, * new_note;
  char pitch_in_use[MAX_PITCH];
  DirectNote * directnote[MAX_PITCH];  /* for each pitch in use we need the
                                          direct note that created it */
  char already_emitted[MAX_PITCH];  /* to compute the is_first_note fields */
  int pitch_count[MAX_PITCH];  /* the number of times the pitch is turned on */
  Event *el;
  Event ** etable;
  int N_events;
    
  for (N_events=0, el = e; el != NULL; el = el->next) N_events++;
  etable = (Event **) xalloc (N_events * sizeof (Event *));
  for (i=0, el = e; el != NULL; el = el->next, i++) etable[i] = el;
    
  qsort(etable, N_events, sizeof (Event *), (int (*)(const void *, const void *))comp_event2);
    
  for(i=0; i<MAX_PITCH; i++) {
    pitch_in_use[i] = 0;
    already_emitted[i] = 0;
    directnote[i] = NULL;
    pitch_count[i] = 0;
  }
    
  event_time = 0;
  note_list = NULL;
    
  /*
    for (i=0; i<N_events; i++) {
    el = etable[i];
    printf("event: pitch = %d  note_on = %d  time = %d \n", el->pitch, el->note_on, el->time);
    }
  */
    
  for (event_n=0; event_n<N_events; event_n++) {
    el = etable[event_n];
    xet = el->time;
    pitch = el->pitch;
    on_event = el->note_on;

    /* we ignore an event that doesn't change which pitches are currently on,
       that is, a situation where two notes are overlapping */
    if (on_event) {
      pitch_count[pitch]++;
      if (pitch_count[pitch] > 1) continue;
    } else {
      pitch_count[pitch]--;
      if (pitch_count[pitch] > 0) continue;
    }

    previous_event_time = event_time;
    event_time = xet;
  
    /* now, for each pitch that's turned on, we generate a note */
    /* the onset time is previous_event_time, the duration is */
    /* the diff between that and event_time */
      
    if (previous_event_time > event_time) {
      fprintf(stderr, "%s: Events are not sorted by time.\n", this_program);
      my_exit(1);
    }
      
    if (previous_event_time != event_time) {
      /* Don't create any notes unless some time has elapsed */
      for(i=0; i<MAX_PITCH; i++) {
        if (pitch_in_use[i]) {
          new_note = (Note*) xalloc(sizeof(Note));
          new_note->pitch = i;
          new_note->start = previous_event_time;
          new_note->duration = event_time - previous_event_time;
          new_note->npc = new_note->base_tpc = new_note->tpc = 0;
          new_note->orn_dis_penalty = 0.0;
          new_note->next = note_list;
          new_note->is_first_note = (!already_emitted[i]);
          new_note->directnote = directnote[i];
          already_emitted[i] = 1;
          note_list = new_note;
        }
      }
    }
    pitch_in_use[pitch] = on_event;
    directnote[pitch] = el->directnote;  /* NULL if not an on_event */
    already_emitted[pitch] = 0;
  }
    
  for(i=0; i<MAX_PITCH; i++) {
    if (pitch_in_use[i]) {
      fprintf(stderr, "%s: Pitch %d was still in use at the end.\n", this_program, i);
      my_exit(1);
    }
  }
    
  for (new_note =  note_list; new_note != NULL; new_note = new_note->next) {
    new_note->npc = Pitch_to_NPC(new_note->pitch);
    new_note->base_tpc = base_TPC(new_note->npc);
  }
    
  xfree(etable);
    
  return reverse(note_list);
}
Exemplo n.º 4
0
Arquivo: PclLine.c Projeto: aosm/X11
void
PclPolyLine(
     DrawablePtr pDrawable,
     GCPtr pGC,
     int mode,
     int nPoints,
     xPoint *pPoints)
{
    char t[80];
    FILE *outFile;
    int xoffset = 0, yoffset = 0;
    int nbox;
    BoxPtr pbox;
    xRectangle *drawRects, *r;
    RegionPtr drawRegion, region;
    short fudge;
    int i;
    XpContextPtr pCon;
    PclContextPrivPtr pConPriv;

    if( PclUpdateDrawableGC( pGC, pDrawable, &outFile ) == FALSE )
      return;

    pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
    pConPriv = (PclContextPrivPtr)
			pCon->devPrivates[PclContextPrivateIndex].ptr;

    /*
     * Allocate the storage required to deal with the clipping
     * regions.
     */
    region = REGION_CREATE( pGC->pScreen, NULL, 0 );
    drawRects = (xRectangle *)
      xalloc( ( nPoints - 1 ) * sizeof( xRectangle ) );

    /*
     * Calculate the "fudge factor" based on the line width.
     * Multiplying by three seems to be a good first guess.
     * XXX I need to think of a way to test this.
     */
    fudge = 3 * pGC->lineWidth + 1;

    /*
     * Generate the PCL code to draw the polyline, by defining it as a
     * macro which uses the HP-GL/2 line drawing function.
     */

    MACRO_START( outFile, pConPriv );
    SAVE_PCL( outFile, pConPriv, "\033%0B" );

    sprintf( t, "PU%d,%dPD\n", pPoints[0].x + pDrawable->x,
	    pPoints[0].y + pDrawable->y );
    SAVE_PCL( outFile, pConPriv, t ); /* Move to the start of the polyline */

    switch( mode )
      {
	case CoordModeOrigin:
	  xoffset = pDrawable->x;
	  yoffset = pDrawable->y;
	  SAVE_PCL( outFile, pConPriv, "PA" );
	  break;
	case CoordModePrevious:
	  xoffset = yoffset = 0;
	  SAVE_PCL( outFile, pConPriv, "PR" );
	  break;
      }

    /*
     * Build the "drawing region" as we build the PCL to draw the
     * line.
     */
    for(i = 1, r = drawRects; i < nPoints; i++, r++ )
      {
	  if( i != 1 )
	    SAVE_PCL( outFile, pConPriv, "," );

	  sprintf( t, "%d,%d", pPoints[i].x + xoffset,
		  pPoints[i].y + yoffset );
	  SAVE_PCL( outFile, pConPriv, t );

	  r->x = MIN( pPoints[i-1].x, pPoints[i].x ) + xoffset - fudge;
	  r->y = MIN( pPoints[i-1].y, pPoints[i].y ) + yoffset - fudge;
	  r->width = abs( pPoints[i-1].x - pPoints[i].x ) + 2 * fudge;
	  r->height = abs( pPoints[i-1].y - pPoints[i].y ) + 2 * fudge;
      }
    SAVE_PCL( outFile, pConPriv, ";\033%0A" ); /* End the macro */
    MACRO_END( outFile );

    /*
     * Convert the collection of rectangles into a proper region, then
     * intersect it with the clip region.
     */
    drawRegion = RECTS_TO_REGION( pGC->pScreen, nPoints - 1,
				  drawRects, CT_UNSORTED );
    if( mode == CoordModePrevious )
      REGION_TRANSLATE( pGC->pScreen, drawRegion, pPoints[0].x, pPoints[0].y );
    REGION_INTERSECT( pGC->pScreen, region, drawRegion, pGC->pCompositeClip );

    /*
     * For each rectangle in the clip region, set the HP-GL/2 "input
     * window" and render the entire polyline to it.
     */
    pbox = REGION_RECTS( region );
    nbox = REGION_NUM_RECTS( region );

    PclSendData(outFile, pConPriv, pbox, nbox, 1.0);

    /*
     * Clean up the temporary regions
     */
    REGION_DESTROY( pGC->pScreen, drawRegion );
    REGION_DESTROY( pGC->pScreen, region );
    xfree( drawRects );
}
Exemplo n.º 5
0
void
test_cipher_stream(const struct nettle_cipher *cipher,
		   const struct tstring *key,
		   const struct tstring *cleartext,
		   const struct tstring *ciphertext)
{
  unsigned block;
  
  void *ctx = xalloc(cipher->context_size);
  uint8_t *data;
  unsigned length;

  ASSERT (cleartext->length == ciphertext->length);
  length = cleartext->length;

  data = xalloc(length + 1);

  for (block = 1; block <= length; block++)
    {
      unsigned i;

      memset(data, 0x17, length + 1);
      cipher->set_encrypt_key(ctx, key->length, key->data);

      for (i = 0; i + block < length; i += block)
	{
	  cipher->encrypt(ctx, block, data + i, cleartext->data + i);
	  ASSERT (data[i + block] == 0x17);
	}

      cipher->encrypt(ctx, length - i, data + i, cleartext->data + i);
      ASSERT (data[length] == 0x17);
      
      if (!MEMEQ(length, data, ciphertext->data))
	{
	  fprintf(stderr, "Encrypt failed, block size %d\nInput:", block);
	  tstring_print_hex(cleartext);
	  fprintf(stderr, "\nOutput: ");
	  print_hex(length, data);
	  fprintf(stderr, "\nExpected:");
	  tstring_print_hex(ciphertext);
	  fprintf(stderr, "\n");
	  FAIL();	    
	}
    }
  
  cipher->set_decrypt_key(ctx, key->length, key->data);
  cipher->decrypt(ctx, length, data, data);

  ASSERT (data[length] == 0x17);

  if (!MEMEQ(length, data, cleartext->data))
    {
      fprintf(stderr, "Decrypt failed\nInput:");
      tstring_print_hex(ciphertext);
      fprintf(stderr, "\nOutput: ");
      print_hex(length, data);
      fprintf(stderr, "\nExpected:");
      tstring_print_hex(cleartext);
      fprintf(stderr, "\n");
      FAIL();	    
    }

  free(ctx);
  free(data);
}
Exemplo n.º 6
0
char *
TRANS(GetPeerNetworkId) (XtransConnInfo ciptr)

{
    int		family = ciptr->family;
    char	*peer_addr = ciptr->peeraddr;
    char	*hostname;
    char	addrbuf[256];
    const char	*addr = NULL;

    switch (family)
    {
    case AF_UNSPEC:
#if defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
    case AF_UNIX:
    {
	if (gethostname (addrbuf, sizeof (addrbuf)) == 0)
	    addr = addrbuf;
	break;
    }
#endif /* defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN) */

#if defined(TCPCONN) || defined(STREAMSCONN)
    case AF_INET:
#if defined(IPv6) && defined(AF_INET6)
    case AF_INET6:
#endif
    {
	struct sockaddr_in *saddr = (struct sockaddr_in *) peer_addr;
#if defined(IPv6) && defined(AF_INET6)
	struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *) peer_addr;
#endif
	char *address;
	int addresslen;
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
	_Xgethostbynameparams hparams;
#endif
	struct hostent * volatile hostp = NULL;

#if defined(IPv6) && defined(AF_INET6)
	if (family == AF_INET6)
	{
	    address = (char *) &saddr6->sin6_addr;
	    addresslen = sizeof (saddr6->sin6_addr);
	}
	else
#endif
	{
	    address = (char *) &saddr->sin_addr;
	    addresslen = sizeof (saddr->sin_addr);
	}

#ifdef SIGALRM
	/*
	 * gethostbyaddr can take a LONG time if the host does not exist.
	 * Assume that if it does not respond in NAMESERVER_TIMEOUT seconds
	 * that something is wrong and do not make the user wait.
	 * gethostbyaddr will continue after a signal, so we have to
	 * jump out of it. 
	 */

	nameserver_timedout = 0;
	signal (SIGALRM, nameserver_lost);
	alarm (4);
	if (setjmp(env) == 0) {
#endif
	    hostp = _XGethostbyaddr (address, addresslen, family, hparams);
#ifdef SIGALRM
	}
	alarm (0);
#endif
	if (hostp != NULL)
	  addr = hostp->h_name;
	else
#if defined(IPv6) && defined(AF_INET6)
	  addr = inet_ntop (family, address, addrbuf, sizeof (addrbuf));
#else
	  addr = inet_ntoa (saddr->sin_addr);
#endif
	break;
    }

#endif /* defined(TCPCONN) || defined(STREAMSCONN) */

#if defined(DNETCONN)
    case AF_DECnet:
    {
	struct sockaddr_dn *saddr = (struct sockaddr_dn *) peer_addr;
	struct nodeent *np;

	if (np = getnodebyaddr(saddr->sdn_add.a_addr,
	    saddr->sdn_add.a_len, AF_DECnet)) {
	    sprintf(addrbuf, "%s:", np->n_name);
	} else {
	    sprintf(addrbuf, "%s:", dnet_htoa(&saddr->sdn_add));
	}
	addr = addrbuf;
	break;
    }
#endif /* defined(DNETCONN) */

    default:
	return (NULL);
    }


    hostname = (char *) xalloc (
	strlen (ciptr->transptr->TransName) + strlen (addr) + 2);
    strcpy (hostname, ciptr->transptr->TransName);
    strcat (hostname, "/");
    if (addr)
	strcat (hostname, addr);

    return (hostname);
}
Exemplo n.º 7
0
Arquivo: set.c Projeto: L3oV1nc3/VMGL
static RecordSetPtr
IntervalListCreateSet(RecordSetInterval *pIntervals, int nIntervals,
		      void *pMem, int memsize)
{
    IntervalListSetPtr prls;
    int i, j, k;
    RecordSetInterval *stackIntervals = NULL;
    CARD16 first;

    if (nIntervals > 0)
    {
	stackIntervals = (RecordSetInterval *)xalloc(
				sizeof(RecordSetInterval) * nIntervals);
	if (!stackIntervals) return NULL;

	/* sort intervals, store in stackIntervals (insertion sort) */

	for (i = 0; i < nIntervals; i++)
	{
	    first = pIntervals[i].first;
	    for (j = 0; j < i; j++)
	    {
		if (first < stackIntervals[j].first)
		    break;
	    }
	    for (k = i; k > j; k--)
	    {
		stackIntervals[k] = stackIntervals[k-1];
	    }
	    stackIntervals[j] = pIntervals[i];
	}

	/* merge abutting/overlapping intervals */

	for (i = 0; i < nIntervals - 1; )
	{
	    if ( (stackIntervals[i].last + (unsigned int)1) <
		  stackIntervals[i + 1].first)
	    {
		i++; /* disjoint intervals */
	    }
	    else
	    {
		stackIntervals[i].last = max(stackIntervals[i].last,
					  stackIntervals[i + 1].last);
		nIntervals--;
		for (j = i + 1; j < nIntervals; j++)
		    stackIntervals[j] = stackIntervals[j + 1];
	    }
	}
    }

    /* allocate and fill in set structure */

    if (pMem)
    {
	prls = (IntervalListSetPtr)pMem;
	prls->baseSet.ops = &IntervalListNoFreeOperations;
    }
    else
    {
	prls = (IntervalListSetPtr)
	    xalloc(sizeof(IntervalListSet) + nIntervals * sizeof(RecordSetInterval));
	if (!prls) goto bailout;
	prls->baseSet.ops = &IntervalListSetOperations;
    }
    memcpy(&prls[1], stackIntervals, nIntervals * sizeof(RecordSetInterval));
    prls->nIntervals = nIntervals;
bailout:
    if (stackIntervals) xfree(stackIntervals);
    return (RecordSetPtr)prls;
}
Exemplo n.º 8
0
static void
XAAValidateGC(
   GCPtr         pGC,
   unsigned long changes,
   DrawablePtr   pDraw 
){
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
    XAA_GC_FUNC_PROLOGUE(pGC);

    (*pGC->funcs->ValidateGC)(pGC, changes, pDraw);

    if((changes & GCPlaneMask) &&
       ((pGC->planemask & infoRec->FullPlanemasks[pGC->depth - 1]) == 
	 infoRec->FullPlanemasks[pGC->depth - 1]))
    {	
	pGC->planemask = ~0;
    }

    if(pGC->depth != 32) {
	/* 0xffffffff is reserved for transparency */
	if(pGC->bgPixel == 0xffffffff)
	    pGC->bgPixel = 0x7fffffff;
	if(pGC->fgPixel == 0xffffffff)
	    pGC->fgPixel = 0x7fffffff;
    }

    if((pDraw->type == DRAWABLE_PIXMAP) && !IS_OFFSCREEN_PIXMAP(pDraw)){
	pGCPriv->flags = OPS_ARE_PIXMAP;
        pGCPriv->changes |= changes;

	/* make sure we're not using videomemory pixmaps to render
	   onto system memory drawables */

	if((pGC->fillStyle == FillTiled) && 
	    IS_OFFSCREEN_PIXMAP(pGC->tile.pixmap) &&
	    !OFFSCREEN_PIXMAP_LOCKED(pGC->tile.pixmap)) {

	    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
	    FBAreaPtr area = pPriv->offscreenArea;

	    XAARemoveAreaCallback(area); /* clobbers pPriv->offscreenArea */
	    xf86FreeOffscreenArea(area);
	}
    } 
    else if(!infoRec->pScrn->vtSema && (pDraw->type == DRAWABLE_WINDOW)) {
	pGCPriv->flags = 0;
        pGCPriv->changes |= changes;
    }
    else {
	if(!(pGCPriv->flags & OPS_ARE_ACCEL)) {	
	    changes |= pGCPriv->changes;
	    pGCPriv->changes = 0;
	}
	pGCPriv->flags = OPS_ARE_ACCEL;

#if 1
	/* Ugh.  If we can't use the blitter on offscreen pixmaps used
	   as tiles, then we need to move them out as cfb can't handle
	   tiles with non-zero origins */

	if((pGC->fillStyle == FillTiled) && 
	    IS_OFFSCREEN_PIXMAP(pGC->tile.pixmap) &&
	    (DO_PIXMAP_COPY != (*infoRec->TiledFillChooser)(pGC))) {

	    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
	    FBAreaPtr area = pPriv->offscreenArea;

	    XAARemoveAreaCallback(area); /* clobbers pPriv->offscreenArea */
	    xf86FreeOffscreenArea(area);
	}
#endif
    }

    XAA_GC_FUNC_EPILOGUE(pGC);

    if(!(pGCPriv->flags & OPS_ARE_ACCEL)) return;

    if((changes & GCTile) && !pGC->tileIsPixel && pGC->tile.pixmap){
	XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
		
	if(pixPriv->flags & DIRTY) {
	    pixPriv->flags &= ~(DIRTY | REDUCIBILITY_MASK);
	    pGC->tile.pixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
	}
    }
    if((changes & GCStipple) && pGC->stipple){
	XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
		
	if(pixPriv->flags & DIRTY) {
	    pixPriv->flags &= ~(DIRTY | REDUCIBILITY_MASK);
	    pGC->stipple->drawable.serialNumber = NEXT_SERIAL_NUMBER;
	}
    }

    /* If our Ops are still the default ones we need to allocate new ones */
    if(pGC->ops == &XAAFallbackOps) {
	if(!(pGCPriv->XAAOps = xalloc(sizeof(GCOps)))) {	
	    pGCPriv->XAAOps = &XAAFallbackOps;
	    return;
	}
	/* make a modifiable copy of the default ops */
	memcpy(pGCPriv->XAAOps, &XAAFallbackOps, sizeof(GCOps));
	pGC->ops = pGCPriv->XAAOps;
	changes = ~0;
    }

    if(!changes) return;

    if((changes & GCDashList) && infoRec->ComputeDash)
	infoRec->ComputeDash(pGC);

    if(changes & infoRec->FillSpansMask)
	(*infoRec->ValidateFillSpans)(pGC, changes, pDraw); 	

    if(changes & infoRec->SetSpansMask)
	(*infoRec->ValidateSetSpans)(pGC, changes, pDraw); 	

    if(changes & infoRec->PutImageMask)
	(*infoRec->ValidatePutImage)(pGC, changes, pDraw); 	

    if(changes & infoRec->CopyAreaMask)
	(*infoRec->ValidateCopyArea)(pGC, changes, pDraw); 	

    if(changes & infoRec->CopyPlaneMask)
	(*infoRec->ValidateCopyPlane)(pGC, changes, pDraw); 	

    if(changes & infoRec->PolyPointMask)
	(*infoRec->ValidatePolyPoint)(pGC, changes, pDraw); 	

    if(changes & infoRec->PolylinesMask)
	(*infoRec->ValidatePolylines)(pGC, changes, pDraw); 	

    if(changes & infoRec->PolySegmentMask)
	(*infoRec->ValidatePolySegment)(pGC, changes, pDraw); 	

    if(changes & infoRec->PolyRectangleMask)
	(*infoRec->ValidatePolyRectangle)(pGC, changes, pDraw); 	

    if(changes & infoRec->PolyArcMask)
	(*infoRec->ValidatePolyArc)(pGC, changes, pDraw); 	

    if(changes & infoRec->FillPolygonMask)
	(*infoRec->ValidateFillPolygon)(pGC, changes, pDraw); 	

    if(changes & infoRec->PolyFillRectMask)
	(*infoRec->ValidatePolyFillRect)(pGC, changes, pDraw); 	
 
    if(changes & infoRec->PolyFillArcMask)
	(*infoRec->ValidatePolyFillArc)(pGC, changes, pDraw); 	

    if(changes & infoRec->PolyGlyphBltMask)
	(*infoRec->ValidatePolyGlyphBlt)(pGC, changes, pDraw);

    if(changes & infoRec->ImageGlyphBltMask)
	(*infoRec->ValidateImageGlyphBlt)(pGC, changes, pDraw);

    if(changes & infoRec->PolyText8Mask)
	(*infoRec->ValidatePolyText8)(pGC, changes, pDraw);
    
    if(changes & infoRec->PolyText16Mask)
	(*infoRec->ValidatePolyText16)(pGC, changes, pDraw);

    if(changes & infoRec->ImageText8Mask)
	(*infoRec->ValidateImageText8)(pGC, changes, pDraw);
    
    if(changes & infoRec->ImageText16Mask)
	(*infoRec->ValidateImageText16)(pGC, changes, pDraw);
 
    if(changes & infoRec->PushPixelsMask) 
	(*infoRec->ValidatePushPixels)(pGC, changes, pDraw); 	
}
Exemplo n.º 9
0
void
xf86scanpci()
{
    unsigned long tmplong1, tmplong2, config_cmd;
    unsigned char tmp1, tmp2;
    unsigned int i, j, idx = 0;
    struct pci_config_reg pcr;
    unsigned PCI_CtrlIOPorts[] = { 0xCF8, 0xCFA, 0xCFC };
    int Num_PCI_CtrlIOPorts = 3;
    unsigned PCI_DevIOPorts[16];
    int Num_PCI_DevIOPorts = 16;
    unsigned PCI_DevIOAddrPorts[16*16];
    int Num_PCI_DevIOAddrPorts = 16*16;

    for (i=0; i<16; i++) {
        PCI_DevIOPorts[i] = 0xC000 + (i*0x0100);
        for (j=0; j<16; j++)
            PCI_DevIOAddrPorts[(i*16)+j] = PCI_DevIOPorts[i] + (j*4);
    }

    xf86ClearIOPortList(0);
    xf86AddIOPorts(0, Num_PCI_CtrlIOPorts, PCI_CtrlIOPorts);
    xf86AddIOPorts(0, Num_PCI_DevIOPorts, PCI_DevIOPorts);
    xf86AddIOPorts(0, Num_PCI_DevIOAddrPorts, PCI_DevIOAddrPorts);

    /* Enable I/O access */
    xf86EnableIOPorts(0);

    outb(0xCF8, 0x00);
    outb(0xCFA, 0x00);
    tmp1 = inb(0xCF8);
    tmp2 = inb(0xCFA);
    if ((tmp1 == 0x00) && (tmp2 == 0x00)) {
	pcr._configtype = 2;
#ifdef DEBUGPCI
        printf("PCI says configuration type 2\n");
#endif
    } else {
        tmplong1 = inl(0xCF8);
        outl(0xCF8, PCI_EN);
        tmplong2 = inl(0xCF8);
        outl(0xCF8, tmplong1);
        if (tmplong2 == PCI_EN) {
	    pcr._configtype = 1;
#ifdef DEBUGPCI
            printf("PCI says configuration type 1\n");
#endif
	} else {
	    pcr._configtype = 0;
#ifdef DEBUGPCI
            printf("No PCI !\n");
#endif
            xf86DisableIOPorts(0);
            xf86ClearIOPortList(0);
	    return;
	}
    }

    /* Try pci config 1 probe first */

#ifdef DEBUGPCI
    printf("\nPCI probing configuration type 1\n");
#endif

    pcr._pcibuses[0] = 0;
    pcr._pcinumbus = 1;
    pcr._pcibusidx = 0;

#ifndef DEBUGPCI
    if (pcr._configtype == 1)
#endif
    do {
        for (pcr._cardnum = 0x0; pcr._cardnum < 0x20; pcr._cardnum += 0x1) {
	    config_cmd = PCI_EN | (pcr._pcibuses[pcr._pcibusidx]<<16) |
                                  (pcr._cardnum<<11);

            outl(0xCF8, config_cmd);         /* ioreg 0 */
            pcr._device_vendor = inl(0xCFC);

            if (pcr._vendor == 0xFFFF)   /* nothing there */
                continue;

#ifdef DEBUGPCI
	    printf("\npci bus 0x%x cardnum 0x%02x, vendor 0x%04x device 0x%04x\n",
	        pcr._pcibuses[pcr._pcibusidx], pcr._cardnum, pcr._vendor,
                pcr._device);
#endif

            outl(0xCF8, config_cmd | 0x04); pcr._status_command  = inl(0xCFC);
            outl(0xCF8, config_cmd | 0x08); pcr._class_revision  = inl(0xCFC);
            outl(0xCF8, config_cmd | 0x0C); pcr._bist_header_latency_cache
								= inl(0xCFC);
            outl(0xCF8, config_cmd | 0x10); pcr._base0  = inl(0xCFC);
            outl(0xCF8, config_cmd | 0x14); pcr._base1  = inl(0xCFC);
            outl(0xCF8, config_cmd | 0x18); pcr._base2  = inl(0xCFC);
            outl(0xCF8, config_cmd | 0x1C); pcr._base3  = inl(0xCFC);
            outl(0xCF8, config_cmd | 0x20); pcr._base4  = inl(0xCFC);
            outl(0xCF8, config_cmd | 0x24); pcr._base5  = inl(0xCFC);
            outl(0xCF8, config_cmd | 0x30); pcr._baserom = inl(0xCFC);
            outl(0xCF8, config_cmd | 0x3C); pcr._max_min_ipin_iline
								= inl(0xCFC);

            /* check for pci-pci bridges (currently we only know Digital) */
            if ((pcr._vendor == 0x1011) && (pcr._device == 0x0001))
                if (pcr._secondary_bus_number > 0)
                    pcr._pcibuses[pcr._pcinumbus++] = pcr._secondary_bus_number;

	    if (idx >= MAX_PCI_DEVICES)
	        continue;

	    if ((pci_devp[idx] = (struct pci_config_reg *)xalloc(sizeof(
		 struct pci_config_reg))) == (struct pci_config_reg *)NULL) {
                outl(0xCF8, 0x00);
                xf86DisableIOPorts(0);
                xf86ClearIOPortList(0);
		return;
	    }

	    memcpy(pci_devp[idx++], &pcr, sizeof(struct pci_config_reg));
        }
    } while (++pcr._pcibusidx < pcr._pcinumbus);

#ifndef DEBUGPCI
    if (pcr._configtype == 1) {
        outl(0xCF8, 0x00);
	return;
    }
#endif
    /* Now try pci config 2 probe (deprecated) */

    outb(0xCF8, 0xF1);
    outb(0xCFA, 0x00); /* bus 0 for now */

#ifdef DEBUGPCI
    printf("\nPCI probing configuration type 2\n");
#endif

    pcr._pcibuses[0] = 0;
    pcr._pcinumbus = 1;
    pcr._pcibusidx = 0;

    do {
        for (pcr._ioaddr = 0xC000; pcr._ioaddr < 0xD000; pcr._ioaddr += 0x0100){
	    outb(0xCFA, pcr._pcibuses[pcr._pcibusidx]); /* bus 0 for now */
            pcr._device_vendor = inl(pcr._ioaddr);
	    outb(0xCFA, 0x00); /* bus 0 for now */

            if (pcr._vendor == 0xFFFF)   /* nothing there */
                continue;
	    /* opti chipsets that use config type 1 look like this on type 2 */
            if ((pcr._vendor == 0xFF00) && (pcr._device == 0xFFFF))
                continue;

#ifdef DEBUGPCI
	    printf("\npci bus 0x%x slot at 0x%04x, vendor 0x%04x device 0x%04x\n",
	        pcr._pcibuses[pcr._pcibusidx], pcr._ioaddr, pcr._vendor,
                pcr._device);
#endif

	    outb(0xCFA, pcr._pcibuses[pcr._pcibusidx]); /* bus 0 for now */
            pcr._status_command = inl(pcr._ioaddr + 0x04);
            pcr._class_revision = inl(pcr._ioaddr + 0x08);
            pcr._bist_header_latency_cache = inl(pcr._ioaddr + 0x0C);
            pcr._base0 = inl(pcr._ioaddr + 0x10);
            pcr._base1 = inl(pcr._ioaddr + 0x14);
            pcr._base2 = inl(pcr._ioaddr + 0x18);
            pcr._base3 = inl(pcr._ioaddr + 0x1C);
            pcr._base4 = inl(pcr._ioaddr + 0x20);
            pcr._base5 = inl(pcr._ioaddr + 0x24);
            pcr._baserom = inl(pcr._ioaddr + 0x30);
            pcr._max_min_ipin_iline = inl(pcr._ioaddr + 0x3C);
	    outb(0xCFA, 0x00); /* bus 0 for now */

            /* check for pci-pci bridges (currently we only know Digital) */
            if ((pcr._vendor == 0x1011) && (pcr._device == 0x0001))
                if (pcr._secondary_bus_number > 0)
                    pcr._pcibuses[pcr._pcinumbus++] = pcr._secondary_bus_number;

	    if (idx >= MAX_PCI_DEVICES)
	        continue;

	    if ((pci_devp[idx] = (struct pci_config_reg *)xalloc(sizeof(
		 struct pci_config_reg))) == (struct pci_config_reg *)NULL) {
                outb(0xCF8, 0x00);
                outb(0xCFA, 0x00);
                xf86DisableIOPorts(0);
                xf86ClearIOPortList(0);
		return;
	    }

	    memcpy(pci_devp[idx++], &pcr, sizeof(struct pci_config_reg));
	}
    } while (++pcr._pcibusidx < pcr._pcinumbus);

    outb(0xCF8, 0x00);
    outb(0xCFA, 0x00);

    xf86DisableIOPorts(0);
    xf86ClearIOPortList(0);
}
Exemplo n.º 10
0
Arquivo: db.c Projeto: keltia/calife
int 
verify_auth_info (char * name, char * user_to_be)
{
    int     allowed = 0;
    char    ** user_list = NULL;
    size_t  l_line = 0;
    int     nb_users = 0;
    char    * line, * ptr;
    char    * line_name, * line_shell;
    char    * group_name = NULL, * group = NULL, **p;
    struct group *gr_group;
    
    /*
     * let's search if user allowed or not
     */
#ifdef HAVE_WORKING_SYSCONF
    l_line = (size_t) sysconf (_SC_LINE_MAX);   /* returns long usually */
#else
    l_line = MAX_STRING;
#endif /* HAVE_WORKING_SYSCONF */    

    line = (char *) xalloc (l_line);
    while (!feof (fp))
    {
        int lastc;

        if (fgets (line, l_line, fp) == NULL)
            break;
        /*
         * remove trailing '\n' if present
         */
        lastc = strlen (line) - 1;
        if (line [lastc] == '\n')
            line [lastc] = '\0';
        /*
         * empty line or comment  or null login -- not allowed but ignored
         */
        if (!line || (*line) == '#' || (*line) == '\0')
            continue;
        MESSAGE_1 ("Line read = |%s|\n", line);
        line_name = line;
        /*
         * Look for a @ or % as first character (for groups)
         */
        if (*line == '@' || *line == '%')
        {
            group = strdup(line);
            group_name = strtok(group, ":");
            group_name++;           /* skip '@' */
            /*
             *  Look into /etc/groups (or its equivalent with get)
             */
             gr_group = (struct group *) getgrnam(group_name);
             if (gr_group == NULL)
             {
                 die(1, "No such group %s", group_name);
                 allowed = 0;
                 goto end;
             }
             for ( p = &gr_group->gr_mem[0]; *p ; p++ )
             {
                 MESSAGE_3 ("matching %s to %s in %s\n", name, *p, group_name);  
                 if (strcmp(name, *p) == 0)
                 {
                     MESSAGE_2 ("User %s Allowed through group %s\n", name, group_name);
                     _group = strdup (group_name);
                     strcpy (_group, group_name);
                     allowed = 2;
                     break;
                 }
             }
        }
        /*
         * Look for first ':'
         */
        ptr = strchr (line, ':');
        if (ptr == NULL)
        {
            /*
             * No shell and no user list
             */
            custom_shell = 0;
            
            /*
             * Bypass if already allowed through group
             */
            if (group_name != NULL && allowed == 1)
                goto escape;
            if (strcmp (line_name, name))   /* not us */
                continue;
            goto escape;            
        }
        /*
         * I got a ':', put a '\0' instead.
         */
        *ptr++ = '\0';
        /*
         * Do we have anything behind ?
         */
        if (*ptr == '\0')
            custom_shell = 0;

        MESSAGE_2 ("Current line_name = |%s| / name = |%s|\n", line_name,name);

        /*
         * Bypass if already allowed through group
         */
        if (group_name != NULL && allowed != 0)
            goto end;
        if (strcmp (line_name, name))   /* not us */
            continue;

        line_shell = ptr;
        /*
         * Look for another ':', maybe just after the first one
         */
        ptr = strchr (line_shell, ':');
        if (ptr == line_shell)
            custom_shell = 0;            
        /*
         * If we got another one, put a '\0' instead
         */
        if (ptr)
            *ptr++ = '\0';
        /*
         * Analyze the shell candidate
         */
        if (*(line_shell) == '*')   /* LOCKED ACCOUNT */
        {
            allowed = 0;
            goto end;
        }
        /*
         * look for pathname
         */
        if (*(line_shell) == '/')
        {
            /*
             * Is this a real shell ?
             */
            if (access (line_shell, R_OK | X_OK))
            {
                MESSAGE_1 (" access of |%s| failed, no custom_shell\n",
                           line_shell);
                custom_shell = 0;
            }
            else
            {
                custom_shell = 1;
                shell = (char *) xalloc (strlen (line_shell) + 1);
                strncpy (shell, line_shell, strlen (line_shell));
                shell [strlen (line_shell)] = '\0';
                MESSAGE_1 (" current line_shell = |%s|\n", line_shell);
            }
        }
        else
        {
            custom_shell = 0;
        }
        MESSAGE_1 (" custom_shell = |%d|\n", custom_shell);

        /*
         * Analyze the rest of the line
         */
        if (ptr)
        {
            MESSAGE_1 ("ptr = %s\n", ptr);
            /*
             * we've got a user list
             */
            if (*ptr)
            {
                char  * p, ** q;
                
                MESSAGE_1 (" current user_list = |%s|\n", ptr);
                /*
                 * the list should be user1,user2,...,user_n
                 */
                p = ptr;     /* count users # in the list */
                while (p && *p)
                    if (*p++ == ',')
                        nb_users++;
                if (*--p != ',')    /* last char is not a ',' */
                    nb_users++;

                MESSAGE_1 ("  users # = |%d|\n", nb_users);

                /*
                 * two passes to avoid fixed size allocations
                 */ 
                user_list = (char **) xalloc((nb_users + 1) * sizeof(char *));
                /*
                 * put pointers in user_list
                 */
                p = ptr;     
                q = user_list;
                /*
                 * 1st user is immediate
                 */
                (*q++) = p;
                while (p && *p)
                {
                    if (*p == ',')    /* found a ',' */
                    {
                        *p = '\0';
                        if (*++p == ',')
                            continue;
                        (*q++) = p++;     /* next char is user name */
                    }            
                    else
                        p++;        /* only regular letters */
                }            
            }
        }        
        /*
         * user_list is complete, now compare
         */
escape:
        if (user_list)
        {
            int i;
            
            for ( i = 0; i < nb_users; i++ )
            {
                MESSAGE_2(" comparing |%s| to |%s|\n", 
                          user_to_be, user_list [i]);
                if (!strcmp (user_list [i], user_to_be))
                {
                    allowed = 1;
                    goto end;   /* beuh but too many loops */
                }
            }            
        }
        else
        {
            allowed = 1;
            break;            
        }
    }
end:
    free (line);
    if (group)
        free(group);
    if (user_list)
        free (user_list);
    fclose (fp);
    if (geteuid() == 0)
        allowed = 1;
    MESSAGE_1 ("Exit from verify_auth_info with allowed=%d\n", allowed);
    return allowed;    
}
Exemplo n.º 11
0
_X_EXPORT Bool
xf86CrtcRotate (xf86CrtcPtr crtc)
{
    ScrnInfoPtr		pScrn = crtc->scrn;
    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
    /* if this is called during ScreenInit() we don't have pScrn->pScreen yet */
    ScreenPtr		pScreen = screenInfo.screens[pScrn->scrnIndex];
    PictTransform	crtc_to_fb;
    struct pict_f_transform f_crtc_to_fb, f_fb_to_crtc;
    xFixed		*new_params = NULL;
    int			new_nparams = 0;
    PictFilterPtr	new_filter = NULL;
    int			new_width = 0;
    int			new_height = 0;
    RRTransformPtr	transform = NULL;
    Bool		damage = FALSE;

    if (crtc->transformPresent)
	transform = &crtc->transform;

    if (!RRTransformCompute (crtc->x, crtc->y,
			     crtc->mode.HDisplay, crtc->mode.VDisplay,
			     crtc->rotation,
			     transform,

			     &crtc_to_fb,
			     &f_crtc_to_fb,
			     &f_fb_to_crtc) &&
	xf86CrtcFitsScreen (crtc, &f_crtc_to_fb))
    {
	/*
	 * If the untranslated transformation is the identity,
	 * disable the shadow buffer
	 */
	xf86RotateDestroy (crtc);
	crtc->transform_in_use = FALSE;
	if (new_params)
	    xfree (new_params);
	new_params = NULL;
	new_nparams = 0;
	new_filter = NULL;
	new_width = 0;
	new_height = 0;
    }
    else
    {
	/*
	 * these are the size of the shadow pixmap, which
	 * matches the mode, not the pre-rotated copy in the
	 * frame buffer
	 */
	int	    width = crtc->mode.HDisplay;
	int	    height = crtc->mode.VDisplay;
	void	    *shadowData = crtc->rotatedData;
	PixmapPtr   shadow = crtc->rotatedPixmap;
	int	    old_width = shadow ? shadow->drawable.width : 0;
	int	    old_height = shadow ? shadow->drawable.height : 0;

	/* Allocate memory for rotation */
	if (old_width != width || old_height != height)
	{
	    if (shadow || shadowData)
	    {
		crtc->funcs->shadow_destroy (crtc, shadow, shadowData);
		crtc->rotatedPixmap = NULL;
		crtc->rotatedData = NULL;
	    }
	    shadowData = crtc->funcs->shadow_allocate (crtc, width, height);
	    if (!shadowData)
		goto bail1;
	    crtc->rotatedData = shadowData;
	    /* shadow will be damaged in xf86RotatePrepare */
	}
	else
	{
	    /* mark shadowed area as damaged so it will be repainted */
	    damage = TRUE;
	}

	if (!xf86_config->rotation_damage)
	{
	    /* Create damage structure */
	    xf86_config->rotation_damage = DamageCreate (NULL, NULL,
						DamageReportNone,
						TRUE, pScreen, pScreen);
	    if (!xf86_config->rotation_damage)
		goto bail2;
	    
	    /* Wrap block handler */
	    if (!xf86_config->BlockHandler) {
		xf86_config->BlockHandler = pScreen->BlockHandler;
		pScreen->BlockHandler = xf86RotateBlockHandler;
	    }
	}
#ifdef RANDR_12_INTERFACE
	if (transform)
	{
	    if (transform->nparams) {
		new_params = xalloc (transform->nparams * sizeof (xFixed));
		if (new_params) {
		    memcpy (new_params, transform->params,
			    transform->nparams * sizeof (xFixed));
		    new_nparams = transform->nparams;
		    new_filter = transform->filter;
		}
	    } else
		new_filter = transform->filter;
	    if (new_filter)
	    {
		new_width = new_filter->width;
		new_height = new_filter->height;
	    }
	}
#endif

	if (0)
	{
    bail2:
	    if (shadow || shadowData)
	    {
		crtc->funcs->shadow_destroy (crtc, shadow, shadowData);
		crtc->rotatedPixmap = NULL;
		crtc->rotatedData = NULL;
	    }
    bail1:
	    if (old_width && old_height)
		crtc->rotatedPixmap = crtc->funcs->shadow_create (crtc,
								  NULL,
								  old_width,
								  old_height);
	    return FALSE;
	}
	crtc->transform_in_use = TRUE;
    }
    crtc->crtc_to_framebuffer = crtc_to_fb;
    crtc->f_crtc_to_framebuffer = f_crtc_to_fb;
    crtc->f_framebuffer_to_crtc = f_fb_to_crtc;
    if (crtc->params)
	xfree (crtc->params);
    crtc->params = new_params;
    crtc->nparams = new_nparams;
    crtc->filter = new_filter;
    crtc->filter_width = new_width;
    crtc->filter_height = new_height;
    crtc->bounds.x1 = 0;
    crtc->bounds.x2 = crtc->mode.HDisplay;
    crtc->bounds.y1 = 0;
    crtc->bounds.y2 = crtc->mode.VDisplay;
    pixman_f_transform_bounds (&f_crtc_to_fb, &crtc->bounds);

    if (damage)
        xf86CrtcDamageShadow (crtc);

    /* All done */
    return TRUE;
}
Exemplo n.º 12
0
Exp * restricted_expression(Dictionary dict, int and_ok, int or_ok) {
    Exp * nl=NULL, * nr, * n;
    E_list *ell, *elr;
    if (is_equal(dict, L'(')) {
	if (!advance(dict)) {
	    return NULL;
	}
	nl = expression(dict);
	if (nl == NULL) {
	    return NULL;
	}
	if (!is_equal(dict, L')')) {
	    dict_error(dict, L"Expecting a \")\".");
	    return NULL;
	}
	if (!advance(dict)) {
	    return NULL;
	}
    } else if (is_equal(dict, L'{')) {
	if (!advance(dict)) {
	    return NULL;
	}
	nl = expression(dict);
	if (nl == NULL) {
	    return NULL;
	}
	if (!is_equal(dict, L'}')) {
	    dict_error(dict, L"Expecting a \"}\".");
	    return NULL;
	}
	if (!advance(dict)) {
	    return NULL;
	}
	nl = make_optional_node(dict, nl);
    } else if (is_equal(dict, L'[')) {
	if (!advance(dict)) {
	    return NULL;
	}
	nl = expression(dict);
	if (nl == NULL) {
	    return NULL;
	}
	if (!is_equal(dict, L']')) {
	    dict_error(dict, L"Expecting a \"]\".");
	    return NULL;
	}
	if (!advance(dict)) {
	    return NULL;
	}
	nl->cost += 1;
    } else if (!dict->is_special) {
	nl = connector(dict);
	if (nl == NULL) {
	    return NULL;
	}
    } else if (is_equal(dict, L')') || is_equal(dict, L']')) {    
	/* allows "()" or "[]" */
        nl = make_zeroary_node(dict);
    } else {
    	dict_error(dict, L"Connector, \"(\", \"[\", or \"{\" expected.");
	return NULL;
    }
    
    if (is_equal(dict, L'&') || (wcscmp(dict->token, L"and")==0)) {
	if (!and_ok) {
	    warning(dict, L"\"and\" and \"or\" at the same level in an expression");
	}
	if (!advance(dict)) {
	    return NULL;
	}
	nr = restricted_expression(dict, TRUE,FALSE);
	if (nr == NULL) {
	    return NULL;
	}
	n = Exp_create(dict);
	n->u.l = ell = (E_list *) xalloc(sizeof(E_list));
	ell->next = elr = (E_list *) xalloc(sizeof(E_list));
	elr->next = NULL;
	
	ell->e = nl;
	elr->e = nr;
	n->type = AND_type;
	n->cost = 0;
    } else if (is_equal(dict, L'|') || (wcscmp(dict->token, L"or")==0)) {
	if (!or_ok) {
	    warning(dict, L"\"and\" and \"or\" at the same level in an expression");
	}
	if (!advance(dict)) {
	    return NULL;
	}
	nr = restricted_expression(dict, FALSE,TRUE);
	if (nr == NULL) {
	    return NULL;
	}
	n = Exp_create(dict);
	n->u.l = ell = (E_list *) xalloc(sizeof(E_list));
	ell->next = elr = (E_list *) xalloc(sizeof(E_list));
	elr->next = NULL;

	ell->e = nl;
	elr->e = nr;
	n->type = OR_type;
	n->cost = 0;
    } else return nl;
    return n;
}
Exemplo n.º 13
0
static int
ProcXDGAQueryModes(ClientPtr client)
{
    int i, num, size;
    REQUEST(xXDGAQueryModesReq);
    xXDGAQueryModesReply rep;
    xXDGAModeInfo info;
    XDGAModePtr mode;

    if (stuff->screen > screenInfo.numScreens)
        return BadValue;

    REQUEST_SIZE_MATCH(xXDGAQueryModesReq);
    rep.type = X_Reply;
    rep.length = 0;
    rep.number = 0;
    rep.sequenceNumber = client->sequence;

    if (!DGAAvailable(stuff->screen)) {
	rep.number = 0;
	rep.length = 0;
	WriteToClient(client, sz_xXDGAQueryModesReply, (char*)&rep);
	return (client->noClientException);
    }

    if(!(num = DGAGetModes(stuff->screen))) {
	WriteToClient(client, sz_xXDGAQueryModesReply, (char*)&rep);
	return (client->noClientException);
    }

    if(!(mode = (XDGAModePtr)xalloc(num * sizeof(XDGAModeRec))))
	return BadAlloc;

    for(i = 0; i < num; i++)
	DGAGetModeInfo(stuff->screen, mode + i, i + 1);

    size = num * sz_xXDGAModeInfo;
    for(i = 0; i < num; i++)
	size += (strlen(mode[i].name) + 4) & ~3L;  /* plus NULL */

    rep.number = num;
    rep.length = size >> 2;

    WriteToClient(client, sz_xXDGAQueryModesReply, (char*)&rep);

    for(i = 0; i < num; i++) {
	size = strlen(mode[i].name) + 1;

	info.byte_order = mode[i].byteOrder;
	info.depth = mode[i].depth;
	info.num = mode[i].num;
	info.bpp = mode[i].bitsPerPixel;
	info.name_size = (size + 3) & ~3L;
	info.vsync_num = mode[i].VSync_num;
	info.vsync_den = mode[i].VSync_den;
	info.flags = mode[i].flags;
	info.image_width = mode[i].imageWidth;
	info.image_height = mode[i].imageHeight;
	info.pixmap_width = mode[i].pixmapWidth;
	info.pixmap_height = mode[i].pixmapHeight;
	info.bytes_per_scanline = mode[i].bytesPerScanline;
	info.red_mask = mode[i].red_mask;
	info.green_mask = mode[i].green_mask;
	info.blue_mask = mode[i].blue_mask;
	info.visual_class = mode[i].visualClass;
	info.viewport_width = mode[i].viewportWidth;
	info.viewport_height = mode[i].viewportHeight;
	info.viewport_xstep = mode[i].xViewportStep;
	info.viewport_ystep = mode[i].yViewportStep;
 	info.viewport_xmax = mode[i].maxViewportX;
	info.viewport_ymax = mode[i].maxViewportY;
	info.viewport_flags = mode[i].viewportFlags;
	info.reserved1 = mode[i].reserved1;
	info.reserved2 = mode[i].reserved2;
	
	WriteToClient(client, sz_xXDGAModeInfo, (char*)(&info));
	WriteToClient(client, size, mode[i].name);
    }

    xfree(mode);

    return (client->noClientException);
}
Exemplo n.º 14
0
/*
 * Mirror the current mode configuration to RandR
 */
static Bool
xf86RandR12SetInfo12 (ScreenPtr pScreen)
{
    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
    xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
    RROutputPtr		*clones;
    RRCrtcPtr		*crtcs;
    int			ncrtc;
    int			o, c, l;
    RRCrtcPtr		randr_crtc;
    int			nclone;
    
    clones = xalloc(config->num_output * sizeof (RROutputPtr));
    crtcs = xalloc (config->num_crtc * sizeof (RRCrtcPtr));
    for (o = 0; o < config->num_output; o++)
    {
	xf86OutputPtr	output = config->output[o];
	
	ncrtc = 0;
	for (c = 0; c < config->num_crtc; c++)
	    if (output->possible_crtcs & (1 << c))
		crtcs[ncrtc++] = config->crtc[c]->randr_crtc;

	if (output->crtc)
	    randr_crtc = output->crtc->randr_crtc;
	else
	    randr_crtc = NULL;

	if (!RROutputSetCrtcs (output->randr_output, crtcs, ncrtc))
	{
	    xfree (crtcs);
	    xfree (clones);
	    return FALSE;
	}

	RROutputSetPhysicalSize(output->randr_output, 
				output->mm_width,
				output->mm_height);
	xf86RROutputSetModes (output->randr_output, output->probed_modes);

	switch (output->status) {
	case XF86OutputStatusConnected:
	    RROutputSetConnection (output->randr_output, RR_Connected);
	    break;
	case XF86OutputStatusDisconnected:
	    RROutputSetConnection (output->randr_output, RR_Disconnected);
	    break;
	case XF86OutputStatusUnknown:
	    RROutputSetConnection (output->randr_output, RR_UnknownConnection);
	    break;
	}

	RROutputSetSubpixelOrder (output->randr_output, output->subpixel_order);

	/*
	 * Valid clones
	 */
	nclone = 0;
	for (l = 0; l < config->num_output; l++)
	{
	    xf86OutputPtr	    clone = config->output[l];
	    
	    if (l != o && (output->possible_clones & (1 << l)))
		clones[nclone++] = clone->randr_output;
	}
	if (!RROutputSetClones (output->randr_output, clones, nclone))
	{
	    xfree (crtcs);
	    xfree (clones);
	    return FALSE;
	}
    }
    xfree (crtcs);
    xfree (clones);
    return TRUE;
}
static int
ProcXResQueryClientResources (ClientPtr client)
{
    REQUEST(xXResQueryClientResourcesReq);
    xXResQueryClientResourcesReply rep;
    int i, clientID, num_types;
    int *counts;

    REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq);

    clientID = CLIENT_ID(stuff->xid);

    if((clientID >= currentMaxClients) || !clients[clientID]) {
        client->errorValue = stuff->xid;
        return BadValue;
    }

    counts = xalloc((lastResourceType + 1) * sizeof(int));

    memset(counts, 0, (lastResourceType + 1) * sizeof(int));

    FindAllClientResources(clients[clientID], ResFindAllRes, counts);

    num_types = 0;

    for(i = 0; i <= lastResourceType; i++) {
       if(counts[i]) num_types++;
    }

    rep.type = X_Reply;
    rep.sequenceNumber = client->sequence;
    rep.num_types = num_types;
    rep.length = rep.num_types * sz_xXResType >> 2;
    if (client->swapped) {
        int n;
        swaps (&rep.sequenceNumber, n);
        swapl (&rep.length, n);
        swapl (&rep.num_types, n);
    }   

    WriteToClient (client,sizeof(xXResQueryClientResourcesReply),(char*)&rep);

    if(num_types) {
        xXResType scratch;
	char *name;

        for(i = 0; i < lastResourceType; i++) {
            if(!counts[i]) continue;

	    name = (char *)LookupResourceName(i + 1);
            if (strcmp(name, XREGISTRY_UNKNOWN))
		scratch.resource_type = MakeAtom(name, strlen(name), TRUE);
	    else {
                char buf[40];
                snprintf(buf, sizeof(buf), "Unregistered resource %i", i + 1);
		scratch.resource_type = MakeAtom(buf, strlen(buf), TRUE);
            }

            scratch.count = counts[i];

            if(client->swapped) {
                register int n;
                swapl (&scratch.resource_type, n);
                swapl (&scratch.count, n);
            }
            WriteToClient (client, sz_xXResType, (char *) &scratch);
        }
    }

    xfree(counts);
    
    return (client->noClientException);
}
Exemplo n.º 16
0
static void savecontext(void)
{
    struct codecontext *con = xalloc(sizeof(struct codecontext));
    con->next = contextbase;
    contextbase = con;
    con->head = head;
    con->tail = tail;
    con->headptr = headptr;
    headptr = &head;
    head = tail = 0;
    con->errfile = errfile;
    con->interject = interjectptr;
    con->line = lineno;
    con->errline = errlineno;
    con->file = infile;
    strcpy(con->id, lastid);
    con->cbautoinithead = cbautoinithead;
    con->cbautoinittail = cbautoinittail;
    con->cbautorundownhead = cbautorundownhead;
    con->cbautorundowntail = cbautorundowntail;
    cbautoinithead = 0;
    cbautoinittail = 0;
    cbautorundownhead = 0;
    cbautorundowntail = 0;
    con->blockrundown = block_rundown;
    con->blocknest = block_nesting;
    block_rundown = 0;
    block_nesting = 0;
    con->funcendstmt = funcendstmt;
    con->xlsyms = lsyms;
    con->xoldlsyms = oldlsym;
    con->xltags = ltags;
    con->xoldltags = oldltag;
    lsyms.head = lsyms.tail = 0;
    oldlsym.head = oldlsym.tail = 0;
    oldltag.head = oldltag.tail = 0;
    con->goodcode = goodcode;
    con->asntyp = asntyp;
    asntyp = 0;
    con->andtyp = andtyp;
    andtyp = 0;
    con->typequal = typequal;
    typequal = 0;
    con->declclass = declclass;
    declclass = 0;
    con->defaulttype = defaulttype;
    con->cfhold = currentfunc;
    currentfunc = 0;
    con->chhold = lastch;
    con->sthold = lastst;
    con->oldvirtual = virtualfuncs;
    con->vlisthead = varlisthead;
    varlisthead = 0;
    con->vlisttail = varlisttail;
    varlisttail = 0;
    con->conscount = conscount;
    conscount = 0;
    con->statictemplate = statictemplate;
	con->used_alloca = used_alloca;
	used_alloca = FALSE;
	con->allocaSP = allocaSP ;
	allocaSP = NULL;
	con->blockVarArraySP = blockVarArraySP ;
	blockVarArraySP = NULL;
}
Exemplo n.º 17
0
char *
TRANS(GetMyNetworkId) (XtransConnInfo ciptr)

{
    int		family = ciptr->family;
    char 	*addr = ciptr->addr;
    char	hostnamebuf[256];
    char 	*networkId = NULL;
    char	*transName = ciptr->transptr->TransName;

    if (gethostname (hostnamebuf, sizeof (hostnamebuf)) < 0)
    {
	return (NULL);
    }

    switch (family)
    {
#if defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
    case AF_UNIX:
    {
	struct sockaddr_un *saddr = (struct sockaddr_un *) addr;
	networkId = (char *) xalloc (3 + strlen (transName) +
	    strlen (hostnamebuf) + strlen (saddr->sun_path));
	sprintf (networkId, "%s/%s:%s", transName,
	    hostnamebuf, saddr->sun_path);
	break;
    }
#endif /* defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN) */

#if defined(TCPCONN) || defined(STREAMSCONN)
    case AF_INET:
#if defined(IPv6) && defined(AF_INET6)
    case AF_INET6:
#endif
    {
	struct sockaddr_in *saddr = (struct sockaddr_in *) addr;
#if defined(IPv6) && defined(AF_INET6)
	struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *) addr;
#endif
	int portnum;
	char portnumbuf[10];


#if defined(IPv6) && defined(AF_INET6)
	if (family == AF_INET6)
	    portnum = ntohs (saddr6->sin6_port);
	else
#endif
	    portnum = ntohs (saddr->sin_port);

	snprintf (portnumbuf, sizeof(portnumbuf), "%d", portnum);
	networkId = (char *) xalloc (3 + strlen (transName) +
	    strlen (hostnamebuf) + strlen (portnumbuf));
	sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, portnumbuf);
	break;
    }
#endif /* defined(TCPCONN) || defined(STREAMSCONN) */

#if defined(DNETCONN)
    case AF_DECnet:
    {
	struct sockaddr_dn *saddr = (struct sockaddr_dn *) addr;

	networkId = (char *) xalloc (
	    13 + strlen (hostnamebuf) + saddr->sdn_objnamel);
	sprintf (networkId, "dnet/%s::%s",
	    hostnamebuf, saddr->sdn_objname);
	break;
    }
#endif /* defined(DNETCONN) */

    default:
	break;
    }

    return (networkId);
}
Exemplo n.º 18
0
/***====================================================================***/
static Status
XkbDDXListComponent(	DeviceIntPtr 		dev,
			int			what,
			XkbSrvListInfoPtr	list,
			ClientPtr		client)
{
char 	*file,*map,*tmp,*buf=NULL;
FILE 	*in;
Status	status;
int	rval;
Bool	haveDir;
#ifdef WIN32
char	tmpname[PATH_MAX];
#endif

    if ((list->pattern[what]==NULL)||(list->pattern[what][0]=='\0'))
	return Success;
    file= list->pattern[what];
    map= strrchr(file,'(');
    if (map!=NULL) {
	char *tmp;
	map++;
	tmp= strrchr(map,')');
	if ((tmp==NULL)||(tmp[1]!='\0')) {
	    /* illegal pattern.  No error, but no match */
	    return Success;
	}
    }

    in= NULL;
    haveDir= True;
#ifdef WIN32
    strcpy(tmpname, Win32TempDir());
    strcat(tmpname, "\\xkb_XXXXXX");
    (void) mktemp(tmpname);
#endif
    if (XkbBaseDirectory!=NULL) {
	if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) {
	    buf = Xprintf("%s/%s.dir",XkbBaseDirectory,componentDirs[what]);
	    in= fopen(buf,"r");
	}
	if (!in) {
	    haveDir= False;
	    buf = Xprintf(
		"'%s/xkbcomp' '-R%s/%s' -w %ld -l -vlfhpR '%s'" W32_tmparg,
                XkbBinDirectory,XkbBaseDirectory,componentDirs[what],(long)
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)),
		file W32_tmpfile
                );
	}
    }
    else {
	if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) {
	    buf = Xprintf("%s.dir",componentDirs[what]);
	    in= fopen(buf,"r");
	}
	if (!in) {
	    haveDir= False;
	    buf = Xprintf(
		"xkbcomp -R%s -w %ld -l -vlfhpR '%s'" W32_tmparg,
                componentDirs[what],(long)
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)),
		file W32_tmpfile
                );
	}
    }
    status= Success;
    if (!haveDir)
    {  
#ifndef WIN32
	in= Popen(buf,"r");
#else
#ifdef DEBUG_CMD
	ErrorF("xkb executes: %s\n",buf);
#endif
	if (System(buf) < 0)
	    ErrorF("Could not invoke keymap compiler\n");
	else
	    in= fopen(tmpname, "r");
#endif
    }
    if (!in)
    {
        if (buf != NULL)
	    xfree (buf);
#ifdef WIN32
	unlink(tmpname);
#endif
	return BadImplementation;
    }
    list->nFound[what]= 0;
    if (buf) {
        xfree(buf);
        buf = NULL;
    }
    buf = xalloc(PATH_MAX * sizeof(char));
    if (!buf)
        return BadAlloc;
    while ((status==Success)&&((tmp=fgets(buf,PATH_MAX,in))!=NULL)) {
	unsigned flags;
	register unsigned int i;
	if (*tmp=='#') /* comment, skip it */
	    continue;
	if (!strncmp(tmp, "Warning:", 8) || !strncmp(tmp, "        ", 8))
	    /* skip warnings too */
	    continue;
	flags= 0;
	/* each line in the listing is supposed to start with two */
	/* groups of eight characters, which specify the general  */
	/* flags and the flags that are specific to the component */
	/* if they're missing, fail with BadImplementation	  */
	for (i=0;(i<8)&&(status==Success);i++) { /* read the general flags */
	   if (isalpha(*tmp))	flags|= (1L<<i);
	   else if (*tmp!='-')	status= BadImplementation;
	   tmp++;
	}
	if (status != Success)  break;
	if (!isspace(*tmp)) {
	     status= BadImplementation;
	     break;
	}
	else tmp++;
	for (i=0;(i<8)&&(status==Success);i++) { /* read the component flags */
	   if (isalpha(*tmp))	flags|= (1L<<(i+8));
	   else if (*tmp!='-')	status= BadImplementation;
	   tmp++;
	}
	if (status != Success)  break;
	if (isspace(*tmp)) {
	    while (isspace(*tmp)) {
		tmp++;
	    }
	}
	else {
	    status= BadImplementation;
	    break;
	}
	status= _AddListComponent(list,what,flags,tmp,client);
    }
#ifndef WIN32
    if (haveDir)
	fclose(in);
    else if ((rval=Pclose(in))!=0) {
	if (xkbDebugFlags)
	    ErrorF("xkbcomp returned exit code %d\n",rval);
    }
#else
    fclose(in);
    unlink(tmpname);
#endif
    if (buf != NULL)
        xfree (buf);
    return status;
}
Exemplo n.º 19
0
int
TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)

{

    PRMSG(2,"ConvertAddress(%d,%d,%x)\n",*familyp,*addrlenp,*addrp);

    switch( *familyp )
    {
#if defined(TCPCONN) || defined(STREAMSCONN)
    case AF_INET:
    {
	/*
	 * Check for the BSD hack localhost address 127.0.0.1.
	 * In this case, we are really FamilyLocal.
	 */

	struct sockaddr_in saddr;
#ifdef CRAY
#ifdef OLDTCP
	int len = sizeof(saddr.sin_addr);
#else
	int len = SIZEOF_in_addr;
#endif /* OLDTCP */
	char *cp = (char *) &saddr.sin_addr;
#else /* else not CRAY */
	int len = sizeof(saddr.sin_addr.s_addr);
	char *cp = (char *) &saddr.sin_addr.s_addr;
#endif /* CRAY */

	memcpy (&saddr, *addrp, sizeof (struct sockaddr_in));

	if ((len == 4) && (cp[0] == 127) && (cp[1] == 0) &&
	    (cp[2] == 0) && (cp[3] == 1))
	{
	    *familyp=FamilyLocal;
	}
	else
	{
	    *familyp=FamilyInternet;
	    *addrlenp=len;
	    memcpy(*addrp,&saddr.sin_addr,len);
	}
	break;
    }

#if defined(IPv6) && defined(AF_INET6)
    case AF_INET6:
    {
	struct sockaddr_in6 saddr6;

	memcpy (&saddr6, *addrp, sizeof (struct sockaddr_in6));

	if (IN6_IS_ADDR_LOOPBACK(&saddr6.sin6_addr))
	{
	    *familyp=FamilyLocal;
	}
	else if (IN6_IS_ADDR_V4MAPPED(&(saddr6.sin6_addr))) {
	    char *cp = (char *) &saddr6.sin6_addr.s6_addr[12];

	    if ((cp[0] == 127) && (cp[1] == 0) &&
	      (cp[2] == 0) && (cp[3] == 1))
	    {
		*familyp=FamilyLocal;
	    }
	    else 
	    {
		*familyp=FamilyInternet;
		*addrlenp = sizeof (struct in_addr);
		memcpy(*addrp,cp,*addrlenp);
	    }
	}
	else
	{
	    *familyp=FamilyInternet6;
	    *addrlenp=sizeof(saddr6.sin6_addr);
	    memcpy(*addrp,&saddr6.sin6_addr,sizeof(saddr6.sin6_addr));
	}
	break;
    }
#endif /* IPv6 */
#endif /* defined(TCPCONN) || defined(STREAMSCONN) */

#if defined(DNETCONN)
    case AF_DECnet:
    {
	struct sockaddr_dn saddr;

	memcpy (&saddr, *addrp, sizeof (struct sockaddr_dn));

	*familyp=FamilyDECnet;
	*addrlenp=sizeof(struct dn_naddr);
	memcpy(*addrp,&saddr.sdn_add,*addrlenp);

	break;
    }
#endif /* defined(DNETCONN) */

#if defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
    case AF_UNIX:
    {
	*familyp=FamilyLocal;
	break;
    }
#endif /* defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)*/

#if (defined(__SCO__) || defined(__UNIXWARE__)) && defined(LOCALCONN)
    case 0:
    {
	*familyp=FamilyLocal;
	break;
    }
#endif

    default:
	PRMSG(1,"ConvertAddress: Unknown family type %d\n",
	      *familyp, 0,0 );
	return -1;
    }


    if (*familyp == FamilyLocal)
    {
	/*
	 * In the case of a local connection, we need to get the
	 * host name for authentication.
	 */
	
	char hostnamebuf[256];
	int len = TRANS(GetHostname) (hostnamebuf, sizeof hostnamebuf);

	if (len > 0) {
	    if (*addrp && *addrlenp < (len + 1))
	    {
		xfree ((char *) *addrp);
		*addrp = NULL;
	    }
	    if (!*addrp)
		*addrp = (Xtransaddr *) xalloc (len + 1);
	    if (*addrp) {
		strcpy ((char *) *addrp, hostnamebuf);
		*addrlenp = len;
	    } else {
		*addrlenp = 0;
	    }
	}
	else
	{
	    if (*addrp)
		xfree ((char *) *addrp);
	    *addrp = NULL;
	    *addrlenp = 0;
	}
    }

    return 0;
}
Exemplo n.º 20
0
ExtensionEntry *
AddExtension(char *name, int NumEvents, int NumErrors, 
	     int (*MainProc)(ClientPtr c1), 
	     int (*SwappedMainProc)(ClientPtr c2), 
	     void (*CloseDownProc)(ExtensionEntry *e), 
	     unsigned short (*MinorOpcodeProc)(ClientPtr c3))
{
    int i;
    register ExtensionEntry *ext, **newexts;

    if (!MainProc || !SwappedMainProc || !CloseDownProc || !MinorOpcodeProc)
        return((ExtensionEntry *) NULL);
    if ((lastEvent + NumEvents > LAST_EVENT) || 
	        (unsigned)(lastError + NumErrors > LAST_ERROR))
        return((ExtensionEntry *) NULL);

    ext = (ExtensionEntry *) xalloc(sizeof(ExtensionEntry));
    if (!ext)
	return((ExtensionEntry *) NULL);
    ext->name = (char *)xalloc(strlen(name) + 1);
    ext->num_aliases = 0;
    ext->aliases = (char **)NULL;
    if (!ext->name)
    {
	xfree(ext);
	return((ExtensionEntry *) NULL);
    }
    strcpy(ext->name,  name);
    i = NumExtensions;
    newexts = (ExtensionEntry **) xrealloc(extensions,
					   (i + 1) * sizeof(ExtensionEntry *));
    if (!newexts)
    {
	xfree(ext->name);
	xfree(ext);
	return((ExtensionEntry *) NULL);
    }
    NumExtensions++;
    extensions = newexts;
    extensions[i] = ext;
    ext->index = i;
    ext->base = i + EXTENSION_BASE;
    ext->CloseDown = CloseDownProc;
    ext->MinorOpcode = MinorOpcodeProc;
    ProcVector[i + EXTENSION_BASE] = MainProc;
    SwappedProcVector[i + EXTENSION_BASE] = SwappedMainProc;
    if (NumEvents)
    {
        ext->eventBase = lastEvent;
	ext->eventLast = lastEvent + NumEvents;
	lastEvent += NumEvents;
    }
    else
    {
        ext->eventBase = 0;
        ext->eventLast = 0;
    }
    if (NumErrors)
    {
        ext->errorBase = lastError;
	ext->errorLast = lastError + NumErrors;
	lastError += NumErrors;
    }
    else
    {
        ext->errorBase = 0;
        ext->errorLast = 0;
    }
#ifdef XCSECURITY
    ext->secure = FALSE;
#endif

#ifdef LBX
    (void) LbxAddExtension(name, ext->base, ext->eventBase, ext->errorBase);
#endif
    return(ext);
}
Exemplo n.º 21
0
Arquivo: PclLine.c Projeto: aosm/X11
void
PclPolySegment(
     DrawablePtr pDrawable,
     GCPtr pGC,
     int nSegments,
     xSegment *pSegments)
{
    FILE *outFile, *dummy;
    char t[80];
    int xoffset, yoffset;
    int nbox, i;
    unsigned long valid;
    BoxPtr pbox;
    xRectangle *drawRects, *r;
    RegionPtr drawRegion, region;
    short fudge;
    XpContextPtr pCon;
    PclContextPrivPtr pConPriv;
    GC cacheGC;


    if( PclUpdateDrawableGC( pGC, pDrawable, &outFile ) == FALSE )
      return;

    pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
    pConPriv = (PclContextPrivPtr)
			pCon->devPrivates[PclContextPrivateIndex].ptr;

    /*
     * Allocate the storage for the temporary regions.
     */
    region = REGION_CREATE( pGC->pScreen, NULL, 0 );
    drawRects = (xRectangle *)
      xalloc( nSegments * sizeof( xRectangle ) );

    /*
     * Calculate the fudge factor, based on the line width
     */
    fudge = pGC->lineWidth * 3 + 1;

    /*
     * Turn off line joining.
     */
    SEND_PCL( outFile, "\033%0BLA2,6;\033%0A" );

    /*
     * Generate the PCL code to draw the segments, by defining them as
     * a macro which uses the HP-GL/2 line drawing function.
     *
     * XXX I wonder if this should be implemented using the Encoded
     * XXX Polyline function.  Since I'm only sending it once, it's not
     * XXX necessarily too important.
     */

    MACRO_START( outFile, pConPriv );
    SAVE_PCL( outFile, pConPriv, "\033%0B" );

    xoffset = pDrawable->x;
    yoffset = pDrawable->y;

    for( i = 0, r = drawRects; i < nSegments; i++, r++ )
      {
	  r->x = MIN( pSegments[i].x1, pSegments[i].x2 ) + xoffset;
	  r->y = MIN( pSegments[i].y1, pSegments[i].y2 ) + yoffset;
	  r->width = abs( pSegments[i].x1 - pSegments[i].x2 );
	  r->height = abs( pSegments[i].y1 - pSegments[i].y2 );

	  sprintf( t, "PU%d,%d;PD%d,%d;", pSegments[i].x1 + xoffset,
		  pSegments[i].y1 + yoffset, pSegments[i].x2 +
		  xoffset, pSegments[i].y2 + yoffset );
	  SAVE_PCL( outFile, pConPriv, t );

	  r->x -= fudge;
	  r->y -= fudge;
	  r->width += 2 * fudge;
	  r->height += 2 * fudge;
      }
    SAVE_PCL( outFile, pConPriv, "\033%0A" );
    MACRO_END ( outFile );

    /*
     * Convert the collection of rectangles into a proper region, then
     * intersect it with the clip region.
     */
    drawRegion = RECTS_TO_REGION( pGC->pScreen, nSegments,
				  drawRects, CT_UNSORTED );
    REGION_INTERSECT( pGC->pScreen, region, drawRegion, pGC->pCompositeClip );

    /*
     * For each rectangle in the clip region, set the HP-GL/2 "input
     * window" and render the entire set of segments to it.
     */
    pbox = REGION_RECTS( region );
    nbox = REGION_NUM_RECTS( region );

    PclSendData(outFile, pConPriv, pbox, nbox, 1.0);

    /*
     * Now we need to reset the line join mode to whatever it was at before.
     * The easiest way is to force the cached GC's joinstyle to be different
     * from the current GC's joinstyle, then re-update the GC.  This way, we
     * don't have to duplicate code unnecessarily.
     */
    PclGetDrawablePrivateStuff( pDrawable, &cacheGC, &valid, &dummy );
    cacheGC.joinStyle = !cacheGC.joinStyle;
    PclSetDrawablePrivateGC( pDrawable, cacheGC );
    PclUpdateDrawableGC( pGC, pDrawable, &outFile );

    /*
     * Clean up
     */
    REGION_DESTROY( pGC->pScreen, drawRegion );
    REGION_DESTROY( pGC->pScreen, region );
    xfree( drawRects );
}
Exemplo n.º 22
0
void allocate(int datareg, int addreg, int floatreg, SNODE *block )
/*
 *      allocate will allocate registers for the expressions that have
 *      a high enough desirability.
 */
{       CSE      *csp;
        ENODE    *exptr;
        unsigned      mask, rmask,i,fmask,frmask,size;
        AMODE    *ap, *ap2;
				framedepth = 4+lc_maxauto;
        mask = 0;
				rmask = 0;
				fmask = frmask = 0;
				for (i=cf_freedata; i < datareg; i++) {
						framedepth+=4;
						rmask = rmask | (1 << (15 - i));
                        mask = mask | (1 << i);
				}
				for (i=cf_freeaddress+16; i < addreg; i++) {
						framedepth+=4;
						rmask = rmask | (1 << (23 - i));
                        mask = mask | (1 << (i-8));
				}
        while( bsort(&olist) );         /* sort the expression list */
        csp = olist;
        while( csp != 0 ) {
						if (csp->reg == -1 && !(csp->exp->cflags & DF_VOL) && !csp->voidf) {
                if( desire(csp) < 3 )
                        csp->reg = -1;
								else {
									if (csp->exp->nodetype == en_rcon || csp->exp->nodetype == en_fcon || csp->exp->nodetype == en_lrcon
								  			|| csp->exp->nodetype == en_floatref || csp->exp->nodetype ==en_doubleref
												|| csp->exp->nodetype == en_longdoubleref) {
										if (floatreg <24 && floatregs)
											csp->reg = floatreg++;
									}
			            else if( (datareg < cf_maxdata) && (csp->duses <= csp->uses/4) && dataregs)
                    csp->reg = (datareg)++;
      	      		else if( !(csp->size == 1 || csp->size == -1) && (addreg < cf_maxaddress) &&addrregs)
        	          csp->reg = (addreg)++;
								}
						}
            if( csp->reg != -1 )
				{
						if (lvalue(csp->exp) && !((SYM *)csp->exp->v.p[0]->v.p[0])->funcparm) {
							((SYM *)csp->exp->v.p[0]->v.p[0])->inreg = TRUE;
							((SYM *)csp->exp->v.p[0]->v.p[0])->value.i = -csp->reg;
						}
						if (csp->reg < 16) {
							framedepth+=4;
							rmask = rmask | (1 << (15 - csp->reg));
                        mask = mask | (1 << csp->reg);
						}
						else if (csp->reg < 32) {
							framedepth+=4;
							rmask = rmask | (1 << (23 - csp->reg));
                        mask = mask | (1 << (csp->reg-8));
						}
						else {
							framedepth+=12;
							frmask = frmask | (1 << (39 - csp->reg));
              fmask = fmask | (1 << (csp->reg-32));
						}
				}
                csp = csp->next;
                }
				allocstack();								/* Allocate stack space for the local vars */
				if (currentfunc->tp->lst.head !=0 && currentfunc->tp->lst.head != (SYM *)-1) {
					if (prm_phiform || currentfunc->intflag) {
						mask |= (1 << (linkreg +8));
						rmask |= (1 << (15 - linkreg -8));
						framedepth+=4;
					}
					if (currentfunc->intflag) {
						mask |= 0xffff;
						rmask |= 0xffff;
						framedepth = lc_maxauto;
					}
				}
				if (prm_linkreg && !currentfunc->intflag && (currentfunc->tp->lst.head && currentfunc->tp->lst.head != (SYM *)-1 || lc_maxauto)) {
					gen_code(op_link,0,makeareg(linkreg),make_immed(-lc_maxauto));
				}				
			  if( mask != 0 ) 
              gen_code(op_movem,4,make_mask(rmask,0,0),push);
        save_mask = mask;
				if (fmask!=0)
                gen_code(op_fmovem,10,make_mask(frmask,0,1),push);
				fsave_mask = fmask;
				if ((prm_phiform || currentfunc->intflag) && currentfunc->tp->lst.head && currentfunc->tp->lst.head != (SYM *) -1) {
					gen_code(op_move,4,makeareg(0), makeareg(linkreg));
				}
				if ((!prm_linkreg || currentfunc->intflag) && lc_maxauto) {
					AMODE *ap = xalloc(sizeof(AMODE)); 
					ap->mode = am_indx;
					ap->offset = makenode(en_icon,(char *)-lc_maxauto,0);
					ap->preg = 7;
          gen_code(op_lea,0,ap,makeareg(7));
				}
				
				if (prm_stackcheck) {
					AMODE *ap1;
					ap = set_symbol("_stackerror",1);
					ap1 = set_symbol("_stackbottom",0);
					if (prm_rel) {
						ap1->mode = am_indx;
						ap1->preg = basereg;
					}
					else {
						ap1->mode = am_adirect;
						if (prm_smalldata)
							ap1->preg = 2;
						else
							ap1->preg = 4;
					}
					gen_code(op_cmp,4,ap1,makeareg(7));
					gen_code(op_bhi,0,ap,0);
				}
}
Exemplo n.º 23
0
void
test_cipher_ctr(const struct nettle_cipher *cipher,
		const struct tstring *key,
		const struct tstring *cleartext,
		const struct tstring *ciphertext,
		const struct tstring *ictr)
{
  void *ctx = xalloc(cipher->context_size);
  uint8_t *data;
  uint8_t *ctr = xalloc(cipher->block_size);
  uint8_t *octr = xalloc(cipher->block_size);
  unsigned length;
  unsigned low, nblocks;

  ASSERT (cleartext->length == ciphertext->length);
  length = cleartext->length;

  ASSERT (ictr->length == cipher->block_size);

  /* Compute expected counter value after the operation. */
  nblocks = (length + cipher->block_size - 1) / cipher->block_size;
  ASSERT (nblocks < 0x100);

  memcpy (octr, ictr->data, cipher->block_size - 1);
  low = ictr->data[cipher->block_size - 1] + nblocks;
  octr[cipher->block_size - 1] = low;

  if (low >= 0x100)
    INCREMENT (cipher->block_size - 1, octr);

  data = xalloc(length);  

  cipher->set_encrypt_key(ctx, key->length, key->data);
  memcpy(ctr, ictr->data, cipher->block_size);

  ctr_crypt(ctx, cipher->encrypt,
	    cipher->block_size, ctr,
	    length, data, cleartext->data);

  if (!MEMEQ(length, data, ciphertext->data))
    {
      fprintf(stderr, "CTR encrypt failed:\nInput:");
      tstring_print_hex(cleartext);
      fprintf(stderr, "\nOutput: ");
      print_hex(length, data);
      fprintf(stderr, "\nExpected:");
      tstring_print_hex(ciphertext);
      fprintf(stderr, "\n");
      FAIL();
    }

  ASSERT (MEMEQ (cipher->block_size, ctr, octr));

  memcpy(ctr, ictr->data, cipher->block_size);

  ctr_crypt(ctx, cipher->encrypt,
	    cipher->block_size, ctr,
	    length, data, data);

  if (!MEMEQ(length, data, cleartext->data))
    {
      fprintf(stderr, "CTR decrypt failed:\nInput:");
      tstring_print_hex(ciphertext);
      fprintf(stderr, "\nOutput: ");
      print_hex(length, data);
      fprintf(stderr, "\nExpected:");
      tstring_print_hex(cleartext);
      fprintf(stderr, "\n");
      FAIL();
    }

  ASSERT (MEMEQ (cipher->block_size, ctr, octr));

  free(ctx);
  free(data);
  free(octr);
  free(ctr);
}
Exemplo n.º 24
0
static I82365*
i82365probe(int x, int d, int dev)
{
	uchar c, id;
	I82365 *cp;
	ISAConf isa;
	int i, nslot;

	outb(x, Rid + (dev<<7));
	id = inb(d);
	if((id & 0xf0) != 0x80)
		return 0;		/* not a memory & I/O card */
	if((id & 0x0f) == 0x00)
		return 0;		/* no revision number, not possible */

	cp = xalloc(sizeof(I82365));
	cp->xreg = x;
	cp->dreg = d;
	cp->dev = dev;
	cp->type = Ti82365;
	cp->nslot = 2;

	switch(id){
	case 0x82:
	case 0x83:
	case 0x84:
		/* could be a cirrus */
		outb(x, Rchipinfo + (dev<<7));
		outb(d, 0);
		c = inb(d);
		if((c & 0xc0) != 0xc0)
			break;
		c = inb(d);
		if((c & 0xc0) != 0x00)
			break;
		if(c & 0x20){
			cp->type = Tpd6720;
		} else {
			cp->type = Tpd6710;
			cp->nslot = 1;
		}

		/* low power mode */
		outb(x, Rmisc2 + (dev<<7));
		c = inb(d);
		outb(d, c & ~Flowpow);
		break;
	}

	/* if it's not a Cirrus, it could be a Vadem... */
	if(cp->type == Ti82365){
		/* unlock the Vadem extended regs */
		outb(x, 0x0E + (dev<<7));
		outb(x, 0x37 + (dev<<7));

		/* make the id register show the Vadem id */
		outb(x, 0x3A + (dev<<7));
		c = inb(d);
		outb(d, c|0xC0);
		outb(x, Rid + (dev<<7));
		c = inb(d);
		if(c & 0x08)
			cp->type = Tvg46x;

		/* go back to Intel compatible id */
		outb(x, 0x3A + (dev<<7));
		c = inb(d);
		outb(d, c & ~0xC0);
	}

	memset(&isa, 0, sizeof(ISAConf));
	if(isaconfig("pcmcia", ncontroller, &isa) && isa.irq)
		cp->irq = isa.irq;
	else
		cp->irq = IrqPCMCIA;

	for(i = 0; i < isa.nopt; i++){
		if(cistrncmp(isa.opt[i], "nslot=", 6))
			continue;
		nslot = strtol(&isa.opt[i][6], nil, 0);
		if(nslot > 0 && nslot <= 2)
			cp->nslot = nslot;
	}

	controller[ncontroller++] = cp;
	return cp;
}
Exemplo n.º 25
0
mp_limb_t *
xalloc_limbs (mp_size_t n)
{
  return xalloc (n * sizeof (mp_limb_t));
}
Exemplo n.º 26
0
/*
 *  set up for slot cards
 */
void
devi82365link(void)
{
	static int already;
	int i, j;
	I82365 *cp;
	PCMslot *pp;
	char buf[32], *p;

	if(already)
		return;
	already = 1;

	if((p=getconf("pcmcia0")) && strncmp(p, "disabled", 8)==0)
		return;

	if(_pcmspecial)
		return;
	
	/* look for controllers if the ports aren't already taken */
	if(ioalloc(0x3E0, 2, 0, "i82365.0") >= 0){
		i82365probe(0x3E0, 0x3E1, 0);
		i82365probe(0x3E0, 0x3E1, 1);
		if(ncontroller == 0)
			iofree(0x3E0);
	}
	if(ioalloc(0x3E2, 2, 0, "i82365.1") >= 0){
		i = ncontroller;
		i82365probe(0x3E2, 0x3E3, 0);
		i82365probe(0x3E2, 0x3E3, 1);
		if(ncontroller == i)
			iofree(0x3E2);
	}

	if(ncontroller == 0)
		return;

	_pcmspecial = pcmcia_pcmspecial;
	_pcmspecialclose = pcmcia_pcmspecialclose;

	for(i = 0; i < ncontroller; i++)
		nslot += controller[i]->nslot;
	slot = xalloc(nslot * sizeof(PCMslot));

	lastslot = slot;
	for(i = 0; i < ncontroller; i++){
		cp = controller[i];
		print("#y%d: %d slot %s: port 0x%uX irq %d\n",
			i, cp->nslot, chipname[cp->type], cp->xreg, cp->irq);
		for(j = 0; j < cp->nslot; j++){
			pp = lastslot++;
			pp->slotno = pp - slot;
			pp->memlen = 64*MB;
			pp->base = (cp->dev<<7) | (j<<6);
			pp->cp = cp;
			pp->msec = ~0;
			pp->verstr[0] = 0;
			slotdis(pp);

			/* interrupt on status change */
			wrreg(pp, Rcscic, (cp->irq<<4) | Fchangeena);
			rdreg(pp, Rcsc);
		}

		/* for card management interrupts */
		snprint(buf, sizeof buf, "i82365.%d", i);
		intrenable(cp->irq, i82365intr, 0, BUSUNKNOWN, buf);
	}
}
Exemplo n.º 27
0
void
MultibufferExtensionInit()
{
    ExtensionEntry	    *extEntry;
    int			    i, j;
    ScreenPtr		    pScreen;
    MultibufferScreenPtr    pMultibufferScreen;

    /*
     * allocate private pointers in windows and screens.  Allocating
     * window privates may seem like an unnecessary expense, but every
     * PositionWindow call must check to see if the window is
     * multi-buffered; a resource lookup is too expensive.
     */
    MultibufferScreenIndex = AllocateScreenPrivateIndex ();
    if (MultibufferScreenIndex < 0)
	return;
    MultibufferWindowIndex = AllocateWindowPrivateIndex ();
    for (i = 0; i < screenInfo.numScreens; i++)
    {
	pScreen = screenInfo.screens[i];
	if (!AllocateWindowPrivate (pScreen, MultibufferWindowIndex, 0) ||
	    !(pMultibufferScreen = (MultibufferScreenPtr) xalloc (sizeof (MultibufferScreenRec))))
	{
	    for (j = 0; j < i; j++)
		xfree (screenInfo.screens[j]->devPrivates[MultibufferScreenIndex].ptr);
	    return;
	}
	pScreen->devPrivates[MultibufferScreenIndex].ptr = (pointer) pMultibufferScreen;
	/*
 	 * wrap PositionWindow to resize the pixmap when the window
	 * changes size
 	 */
	pMultibufferScreen->PositionWindow = pScreen->PositionWindow;
	pScreen->PositionWindow = MultibufferPositionWindow;
    }
    /*
     * create the resource types
     */
    MultibufferDrawableResType =
	CreateNewResourceType(MultibufferDrawableDelete)|RC_CACHED|RC_DRAWABLE;
    MultibufferResType = CreateNewResourceType(MultibufferDelete);
    MultibuffersResType = CreateNewResourceType(MultibuffersDelete);
    OtherClientResType = CreateNewResourceType(OtherClientDelete);
    if (MultibufferDrawableResType && MultibufferResType &&
	MultibuffersResType && 	OtherClientResType &&
	(extEntry = AddExtension(MULTIBUFFER_PROTOCOL_NAME,
				 MultibufferNumberEvents, 
				 MultibufferNumberErrors,
				 ProcMultibufferDispatch, SProcMultibufferDispatch,
				 MultibufferResetProc, StandardMinorOpcode)))
    {
#if 0
	MultibufferReqCode = (unsigned char)extEntry->base;
#endif
	MultibufferEventBase = extEntry->eventBase;
	MultibufferErrorBase = extEntry->errorBase;
	EventSwapVector[MultibufferEventBase + MultibufferClobberNotify] = (EventSwapPtr) SClobberNotifyEvent;
	EventSwapVector[MultibufferEventBase + MultibufferUpdateNotify] = (EventSwapPtr) SUpdateNotifyEvent;
    }
}
Exemplo n.º 28
0
static char *
FindModule(const char *module, const char *dir, const char **subdirlist,
	   PatternPtr patterns)
{
    char buf[PATH_MAX + 1];
    char *dirpath = NULL;
    char *name = NULL;
    struct stat stat_buf;
    int len, dirlen;
    char *fp;
    DIR *d;
    const char **subdirs = NULL;
    PatternPtr p = NULL;
    const char **s;
    struct dirent *dp;
    regmatch_t match[2];

    subdirs = InitSubdirs(subdirlist);
    if (!subdirs)
	return NULL;

#ifndef __EMX__
    dirpath = (char *)dir;
#else
    dirpath = xalloc(strlen(dir) + 10);
    strcpy(dirpath, (char *)__XOS2RedirRoot(dir));
#endif
    if (strlen(dirpath) > PATH_MAX)
	return NULL;
    /*xf86Msg(X_INFO,"OS2DIAG: FindModule: dirpath=%s\n",dirpath); */

    for (s = subdirs; *s; s++) {
	if ((dirlen = strlen(dirpath) + strlen(*s)) > PATH_MAX)
	    continue;
	strcpy(buf, dirpath);
	strcat(buf, *s);
	/*xf86Msg(X_INFO,"OS2DIAG: FindModule: buf=%s\n",buf); */
	fp = buf + dirlen;
	if (stat(buf, &stat_buf) == 0 && S_ISDIR(stat_buf.st_mode) &&
	    (d = opendir(buf))) {
	    if (buf[dirlen - 1] != '/') {
		buf[dirlen++] = '/';
		fp++;
	    }
	    while ((dp = readdir(d))) {
		if (dirlen + strlen(dp->d_name) + 1 > PATH_MAX)
		    continue;
		strcpy(fp, dp->d_name);
		if (!(stat(buf, &stat_buf) == 0 && S_ISREG(stat_buf.st_mode)))
		    continue;
		for (p = patterns; p->pattern; p++) {
		    if (regexec(&p->rex, dp->d_name, 2, match, 0) == 0 &&
			match[1].rm_so != -1) {
			len = match[1].rm_eo - match[1].rm_so;
			if (len == strlen(module) &&
			    strncmp(module, dp->d_name + match[1].rm_so,
				    len) == 0) {
			    /*xf86Msg(X_INFO,"OS2DIAG: matching %s\n",buf); */
			    name = buf;
			    break;
			}
		    }
		}
		if (name)
		    break;
	    }
	    closedir(d);
	    if (name)
		break;
	}
    }
    FreeSubdirs(subdirs);
    if (dirpath != dir)
	xfree(dirpath);

    if (name) {
	return xstrdup(name);
    }
    return NULL;
}
Exemplo n.º 29
0
Event * build_event_list_and_beat_list_from_input(void) {
  char first_part[100];
  int second_part;
  int third_part;
  int fourth_part;
  int event_time;
  int N_parts;
  int on_event, both_event, off_event;
  int on_time, off_time;
  int i;
  Pitch pitch;
  Event * event_list, * new_event;
  Beat * new_beat;
    
  beatlevel[0].count = 1;
  beatlevel[0].start = 0;
  beatlevel[0].units = 1;
  N_beatlevel = 1;
    
  event_time = 0;
  event_list = NULL;
  global_beat_list = NULL;
    
  for (line_no = 1; fgets(line, sizeof(line), instream) != NULL; line_no++) {
    for (i=0; isspace(line[i]); i++);
    if (line[i] == '%' || line[i] == '\0') continue;  /* ignore comment lines */
    N_parts = sscanf(line, 
                     "%99s %d %d %d", 
                     first_part, &second_part, &third_part, &fourth_part);
    if (N_parts < 2) {
	    warn();
	    continue;
    }
	
    if (strcasecmp(first_part, "BaseUnit") == 0) {
	    if (N_parts != 2) {
        fprintf(stderr, 
                "%s: Error (line %d) BaseUnit expects one integer parameter.\n", 
                this_program, line_no);
        my_exit(1);
	    }
	    baseunit = second_part;
	    continue;
    }
	
    if (strcasecmp(first_part, "BeatLevel") == 0) {
	    if (N_parts != 4) {
        fprintf(stderr, 
                "%s: Error (line %d) BeatLevel expects three integer parameters.\n", 
                this_program, line_no);
        my_exit(1);
	    }
	    
	    if (N_beatlevel != second_part) {
        fprintf(stderr,
                "%s: Error (line %d) A BeatLevel numbers must be in increasing order"\
                " starting from 1.\n", this_program, line_no);
        my_exit(1);	
	    }
	    
	    if (N_beatlevel+1 > MAX_BEAT_LEVEL) {
        fprintf(stderr,
                "%s: Error (line %d) A BeatLevel cannot be greater than %d\n", 
                this_program, line_no, MAX_BEAT_LEVEL);
        my_exit(1);	
	    }
	    beatlevel[N_beatlevel].count = third_part;
	    beatlevel[N_beatlevel].start = fourth_part;
	    beatlevel[N_beatlevel].units = beatlevel[N_beatlevel].count * beatlevel[N_beatlevel-1].units;
	    
	    if (verbosity >= 3) {
        printf(" beatlevel[%d].count(start)(units) =%d (%d)(%d)\n", 
               N_beatlevel, third_part, fourth_part, beatlevel[N_beatlevel].units);
	    }
	    
	    N_beatlevel++;
	    continue;
    }
	
    if (strcasecmp(first_part, "Beat") == 0) {
	    new_beat = (Beat *) xalloc(sizeof(Beat));
	    new_beat->start = second_part;
	    new_beat->level = third_part;
	    if(print_beats) printf("Beat %6d %2d\n", new_beat->start, new_beat->level);
	    new_beat->next = global_beat_list;
	    global_beat_list = new_beat;
	    
	    if (new_beat->level+1 > N_beatlevel) N_beatlevel = new_beat->level+1;
	    
	    continue;
    }
	
    on_event = (strcasecmp(first_part, "Note-on") == 0);
    both_event = (strcasecmp(first_part, "Note") == 0);
    off_event = (strcasecmp(first_part, "Note-off") == 0);
	
    if (!(on_event || off_event || both_event)) {
	    warn();
	    continue;
    }
	
    if ((on_event || off_event || both_event) && (verbosity>2 || prechord_mode==1)) {   
      /* This prints out the inputted Note statements */
	    printf("%s", line);
    }
    if (on_event || off_event) {
	    if (N_parts != 3) {
        fprintf(stderr, 
                "%s: Error (line %d) a note needs a time and a pitch\n", 
                this_program, line_no);
        my_exit(1);		
	    }
	    
	    event_time = second_part;
	    pitch = third_part;
	    
	    test_pitch(pitch);
	    new_event = (Event *) xalloc(sizeof(Event));
	    new_event->pitch = pitch;
	    new_event->note_on = on_event;
	    new_event->time = event_time;
	    new_event->next = event_list;
	    new_event->directnote = NULL;
	    event_list = new_event;
    } else {
	    /* it's a both event */
	    if (N_parts != 4) {
        fprintf(stderr, 
                "%s: Error (line %d) a note needs an on-time an off-time and a pitch\n", 
                this_program, line_no);
        my_exit(1);		
	    }
	    on_time = second_part;
	    off_time = third_part;
	    pitch = fourth_part;
	    
	    test_pitch(pitch);      
	    new_event = (Event *) xalloc(sizeof(Event));
	    new_event->pitch = pitch;
	    new_event->note_on = 1;
	    new_event->time = on_time;
	    new_event->next = event_list;
	    new_event->directnote = NULL;
	    event_list = new_event;
	    
	    new_event = (Event *) xalloc(sizeof(Event));
	    new_event->pitch = pitch;
	    new_event->note_on = 0;
	    new_event->time = off_time;
	    new_event->next = event_list;
	    new_event->directnote = NULL;
	    event_list = new_event;
    }
  }
    
  return event_list;
}
Exemplo n.º 30
0
static int
ProcAppleWMSelectInput (register ClientPtr client)
{
    REQUEST(xAppleWMSelectInputReq);
    WMEventPtr      pEvent, pNewEvent, *pHead;
    XID             clientResource;
    int             i;

    REQUEST_SIZE_MATCH (xAppleWMSelectInputReq);
    i = dixLookupResourceByType((pointer *)&pHead, eventResource, EventType, client, DixWriteAccess);
    if (stuff->mask != 0) {
        if (i == Success && pHead) {
            /* check for existing entry. */
            for (pEvent = *pHead; pEvent; pEvent = pEvent->next)
            {
                if (pEvent->client == client)
                {
                    pEvent->mask = stuff->mask;
                    updateEventMask (pHead);
                    return Success;
                }
            }
        }

        /* build the entry */
        pNewEvent = (WMEventPtr) xalloc (sizeof (WMEventRec));
        if (!pNewEvent)
            return BadAlloc;
        pNewEvent->next = 0;
        pNewEvent->client = client;
        pNewEvent->mask = stuff->mask;
        /*
         * add a resource that will be deleted when
         * the client goes away
         */
        clientResource = FakeClientID (client->index);
        pNewEvent->clientResource = clientResource;
        if (!AddResource (clientResource, ClientType, (pointer)pNewEvent))
            return BadAlloc;
        /*
         * create a resource to contain a pointer to the list
         * of clients selecting input.  This must be indirect as
         * the list may be arbitrarily rearranged which cannot be
         * done through the resource database.
         */
        if (i != Success || !pHead)
        {
            pHead = (WMEventPtr *) xalloc (sizeof (WMEventPtr));
            if (!pHead ||
                    !AddResource (eventResource, EventType, (pointer)pHead))
            {
                FreeResource (clientResource, RT_NONE);
                return BadAlloc;
            }
            *pHead = 0;
        }
        pNewEvent->next = *pHead;
        *pHead = pNewEvent;
        updateEventMask (pHead);
    } else if (stuff->mask == 0) {
        /* delete the interest */
        if (i == Success && pHead) {
            pNewEvent = 0;
            for (pEvent = *pHead; pEvent; pEvent = pEvent->next) {
                if (pEvent->client == client)
                    break;
                pNewEvent = pEvent;
            }
            if (pEvent) {
                FreeResource (pEvent->clientResource, ClientType);
                if (pNewEvent)
                    pNewEvent->next = pEvent->next;
                else
                    *pHead = pEvent->next;
                xfree (pEvent);
                updateEventMask (pHead);
            }
        }
    } else {
        client->errorValue = stuff->mask;
        return BadValue;
    }
    return Success;
}