Пример #1
0
Файл: xs.c Проект: aahud/harvey
void
pause(int t)
{
	int s;
	Alt alts[NALT+1];

	alts[TIMER].c = timerc;
	alts[TIMER].v = nil;
	alts[TIMER].op = CHANRCV;
	alts[SUSPEND].c = suspc;
	alts[SUSPEND].v = &s;
	alts[SUSPEND].op = CHANRCV;
	alts[RESHAPE].c = mousectl->resizec;
	alts[RESHAPE].v = nil;
	alts[RESHAPE].op = CHANRCV;
	// avoid hanging up those writing ong mousec and kbdc
	// so just accept it all and keep mouse up-to-date
	alts[MOUSE].c = mousec;
	alts[MOUSE].v = &mouse;
	alts[MOUSE].op = CHANRCV;
	alts[KBD].c = kbdc;
	alts[KBD].v = nil;
	alts[KBD].op = CHANRCV;
	alts[NALT].op = CHANEND;

	flushimage(display, 1);
	for(;;)
		switch(alt(alts)){
		case SUSPEND:
			if (!suspended && s) {
				suspend(1);
			} else if (suspended && !s) {
				suspend(0);
				lastmx = warp(mouse.xy, lastmx);
			}
			break;
		case TIMER:
			if(suspended)
				break;
			if((t -= tsleep) < 0)
				return;
			break;
		case RESHAPE:
			redraw(1);
			break;		
		}
}
Пример #2
0
// Keymapper - a single instance of this class is used to generate Windows key
// events.
void doKeyEventWithModifiers(BYTE vkCode, BYTE modifierState, bool down)
{
  KeyStateModifier ctrl(VK_CONTROL);
  KeyStateModifier alt(VK_MENU);
  KeyStateModifier shift(VK_SHIFT);

  if (down) {
    if (modifierState & 2) ctrl.press();
    if (modifierState & 4) alt.press();
    if (modifierState & 1) {
      shift.press(); 
    } else {
      shift.release();
    }
  }
  doKeyboardEvent(vkCode, down ? 0 : KEYEVENTF_KEYUP);
}
Пример #3
0
pl_consonne_1 (struct coroutine *k, expr a0)
{
expr nx[MAX_NEW_CONS];
int pnx, i;
struct process_list *alt_process;
	pnx = 0;
	begin_decl ();
	decl_expr (&a0);
	for (i=0; i<MAX_NEW_CONS; i++)
		dle (nx[i]);
#ifdef TRACE
	printf ("\nconsonne: a0 = "); print_expr (a0);
#endif
	if (alt (k, 1, 0))
	{
	/* clause */
	expr val_X, var_X;
		alt_process = getpl (k) -> alt;
		dle(val_X) dle(var_X)
		val_X=UNDEF; var_X=mk_var(&val_X);
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
		unify (k, var_X, a0);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
		pl_lettre_1 (k, var_X);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
		pl_non_voyelle_1 (k, var_X);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
		unify (k, a0, var_X);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
	} else
	end (k);
	free_expr ();
}
Пример #4
0
RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& desc, const Font* originalFontData, bool isPlatformFont, const UChar* characters, unsigned int length)
{
    ASSERT(characters && (length==1||length==2));

    UChar32 c = 0;
    if (length==1) {
        c = characters[0];
    } else {
        c = U16_GET_SUPPLEMENTARY(characters[0], characters[1]);
    }
    FontPlatformData alt(desc, desc.familyAt(0));
    if (alt.font() && alt.font()->font()) {
        alt.font()->setSpecificUnicodeChar(c);
        return fontForPlatformData(alt);
    } else {
        return lastResortFallbackFont(desc);
    }
}
Пример #5
0
void
writer(void *arg)
{
	int lastpid;
	Alt a[4];
	Msg *s;

	lastpid = (int)(uintptr)arg;

	a[0].op = CHANRCV;
	a[0].c = quit;
	a[0].v = nil;
	a[1].op = CHANRCV;
	a[1].c = out;
	a[1].v = &s;
	a[2].op = CHANRCV;
	a[2].c = forkc;
	a[2].v = nil;
	a[3].op = CHANEND;

	for(;;)
		switch(alt(a)){
		case 0:
			nread--;
			if(nread <= 0)
				goto done;
			break;
		case 1:
			if(s->pid != lastpid){
				lastpid = s->pid;
				fprint(2, s->buf[1]=='='? "\n%d ...": "\n", lastpid);
			}
			fprint(2, "%s", s->buf);
			free(s);
			break;
		case 2:
			nread++;
			break;
		}
done:
	exits(nil);
}
Пример #6
0
void
xfidallocthread(void *v)
{
	Xfid *xfree, *x;
	enum { Alloc, Free, N };
	static Alt alts[N+1];

	USED(v);
	threadsetname("xfidallocthread");
	alts[Alloc].c = cxfidalloc;
	alts[Alloc].v = nil;
	alts[Alloc].op = CHANRCV;
	alts[Free].c = cxfidfree;
	alts[Free].v = &x;
	alts[Free].op = CHANRCV;
	alts[N].op = CHANEND;

	xfree = nil;
	for(;;){
		switch(alt(alts)){
		case Alloc:
			x = xfree;
			if(x)
				xfree = x->next;
			else{
				x = emalloc(sizeof(Xfid));
				x->c = chancreate(sizeof(void(*)(Xfid*)), 0);
				chansetname(x->c, "xc%p", x->c);
				x->arg = x;
				threadcreate(xfidctl, x->arg, STACK);
			}
			sendp(cxfidalloc, x);
			break;
		case Free:
			x->next = xfree;
			xfree = x;
			break;
		}
	}
}
Пример #7
0
void
writer(void *)
{
	Alt a[4];
	Str *s;
	int newpid;

	a[0].op = CHANRCV;
	a[0].c = quit;
	a[0].v = nil;
	a[1].op = CHANRCV;
	a[1].c = out;
	a[1].v = &s;
	a[2].op = CHANRCV;
	a[2].c = forkc;
	a[2].v = &newpid;
	a[3].op = CHANEND;

	for(;;) { 
	switch(alt(a)){
	case 0:
		nread--;
		if(nread <= 0)
			goto done;
		break;
	case 1:
		/* it's a nice null terminated thing */
		fprint(2, "%s", s->buf);
		free(s);
		break;
	case 2:
//		procrfork(reader, (void*)newpid, 8192, 0);
		nread++;
		break;
	}
	}
done:
	exits(nil);
}
Пример #8
0
/////////////////////////////////////////////////////////////////////////////
// test threads
/////////////////////////////////////////////////////////////////////////////
static void ThreadsTest()
{
 CPLog1D problem;
 CResults results(problem.GetDimensions());

// CSPUniform sp(problem.GetDimensions());

#if 0
 CPFQuadratic pf(problem.GetDimensions());
 CRegression reg(results, pf);
 reg.SetRefreshRate(0.1);
 reg.SetLocalizationHeight(2.0);
 CMERegressionMAPMax me(reg);

 CDFVarianceSamples var(reg, 1);
 var.SetMinSamples(problem.GetDimensions());
 CSPVOptimal sp(reg, var, 0);
 CArtificialExperiment artexp(problem, sp, me, results);
#else
 //CCrossEntropy alt(results, 0.9);
 //CSPSA alt(results);
 CRSPSA alt(results);
 CArtificialExperiment artexp(problem, alt, alt, results);
#endif

 CCPLConsole cplc;
 CRepeatThreads rts(79, 100000, &cplc);
 rts.AddThread(artexp);

 CPLog1D problemBis;
 CResults resultsBis(problemBis.GetDimensions());
 CRSPSA altBis(resultsBis);
 CArtificialExperiment artexpBis(problemBis, altBis, altBis, resultsBis);
 rts.AddThread(artexpBis);

 rts.Start();
 rts.WaitForTermination();
}
Пример #9
0
void
writer(void *v)
{
	int newpid;
	Alt a[4];
	Str *s;

	a[0].op = CHANRCV;
	a[0].c = quit;
	a[0].v = nil;
	a[1].op = CHANRCV;
	a[1].c = out;
	a[1].v = &s;
	a[2].op = CHANRCV;
	a[2].c = forkc;
	a[2].v = &newpid;
	a[3].op = CHANEND;

	for(;;)
		switch(alt(a)){
		case 0:			/* quit */
			nread--;
			if(nread <= 0)
				goto done;
			break;
		case 1:			/* out */
			fprint(outf, "%s", s->buf);
			free(s);
			break;
		case 2:			/* forkc */
			// procrfork(reader, (void*)newpid, Stacksize, 0);
			nread++;
			break;
		}
done:
	exits(nil);
}
Пример #10
0
static int
runop(int op, Channel *c, void *v, int nb)
{
	int r;
	Alt a[2];

	/*
	 * we could do this without calling alt,
	 * but the only reason would be performance,
	 * and i'm not convinced it matters.
	 */
	a[0].op = op;
	a[0].c = c;
	a[0].v = v;
	a[0].err = nil;
	a[1].op = CHANEND;
	if(nb)
		a[1].op = CHANNOBLK;
	switch(r=alt(a)){
	case -1:	/* interrupted */
		return -1;
	case 1:	/* nonblocking, didn't accomplish anything */
		assert(nb);
		return 0;
	case 0:
		/*
		 * Okay, but return -1 if the op is done because of a close.
		 */
		if(a[0].err != nil)
			return -1;
		return 1;
	default:
		fprint(2, "ERROR: channel alt returned %d\n", r);
		abort();
		return -1;
	}
}
Пример #11
0
static void
loop(void)
{
	Rune r;
	int n;

	Alt a[] = {
		{mc->c, &mc->Mouse, CHANRCV},
		{kc->c, &r, CHANRCV},
		{mc->resizec, &n, CHANRCV},
		{nil, nil, CHANEND}
	};
	
	for(;;){
		flushimage(display, 1);
		switch(alt(a)){
		case 0:
			if((mc->buttons & 1) != 0)
				winclick(mc);
			if((mc->buttons & 2) != 0)
				if(actw != nil && actw->tab->menu != nil)
					actw->tab->menu(actw, mc);
			if((mc->buttons & 4) != 0)
				if(rmb() < 0)
					return;
			break;
		case 1:
			if(actw != nil && actw->tab->key != nil)
				actw->tab->key(actw, r);
			break;
		case 2:
			resize();
			break;
		}
	}
}
Пример #12
0
Node *regexp(void)	/* top-level parse of reg expr */
{
    return (alt(concat(primary())));
}
Пример #13
0
void
winctl(void *arg)
{
	print_func_entry();
	Rune *rp, *bp, *kbdr;
	int nr, nb, c, wid, i, npart, lastb;
	char *s, *t, part[3];
	Window *w;
	Mousestate *mp, m;
	enum { WKey, WMouse, WMouseread, WCtl, WCwrite, WCread, WWread, NWALT };
	Alt alts[NWALT+1];
	int walt;
	Mousereadmesg mrm;
	Conswritemesg cwm;
	Consreadmesg crm;
	Consreadmesg cwrm;
	Stringpair pair;
	Wctlmesg wcm;
	char buf[4*12+1];
	w = arg;
	snprint(buf, sizeof buf, "winctl-id%d", w->id);
	threadsetname(buf);

	mrm.cm = chancreate(sizeof(Mouse), 0);
	cwm.cw = chancreate(sizeof(Stringpair), 0);
	crm.c1 = chancreate(sizeof(Stringpair), 0);
	crm.c2 = chancreate(sizeof(Stringpair), 0);
	cwrm.c1 = chancreate(sizeof(Stringpair), 0);
	cwrm.c2 = chancreate(sizeof(Stringpair), 0);


	alts[WKey].c = w->ck;
	alts[WKey].v = &kbdr;
	alts[WKey].op = CHANRCV;
	alts[WMouse].c = w->mc.c;
	alts[WMouse].v = &w->mc.Mouse;
	alts[WMouse].op = CHANNOP; // XXXCHANRCV;
	alts[WMouseread].c = w->mouseread;
	alts[WMouseread].v = &mrm;
	alts[WMouseread].op = CHANNOP; // XXXCHANSND;
	alts[WCtl].c = w->cctl;
	alts[WCtl].v = &wcm;
	alts[WCtl].op = CHANRCV;
	alts[WCwrite].c = w->conswrite;
	alts[WCwrite].v = &cwm;
	alts[WCwrite].op = CHANSND;
	alts[WCread].c = w->consread;
	alts[WCread].v = &crm;
	alts[WCread].op = CHANSND;
	alts[WWread].c = w->wctlread;
	alts[WWread].v = &cwrm;
	alts[WWread].op = CHANSND;
	alts[NWALT].op = CHANEND;

	npart = 0;
	lastb = -1;
	for(;;){
		// TODO: mouses
		if(0 && w->mouseopen && w->mouse.counter != w->mouse.lastcounter)
			alts[WMouseread].op = CHANSND;
		else
			alts[WMouseread].op = CHANNOP;
		if(w->deleted || !w->wctlready)
			alts[WWread].op = CHANNOP;
		else
			alts[WWread].op = CHANSND;
		/* this code depends on NL and EOT fitting in a single byte */
		/* kind of expensive for each loop; worth precomputing? */
		/*if(w->holding)
			alts[WCread].op = CHANNOP;
			else*/ if(npart || (w->rawing && w->nraw>0))
			alts[WCread].op = CHANSND;
		else
		{
			alts[WCread].op = CHANNOP;
			for(i=w->qh; i<w->nr; i++){
				c = w->run[i];
				if(c=='\n' || c=='\004'){
					alts[WCread].op = CHANSND;
					break;
				}
			}
		}

		walt = alt(alts);

		switch(walt){
		case WKey:
			for(i=0; kbdr[i]!=L'\0'; i++)
				wkeyctl(w, kbdr[i]);
			//wkeyctl(w, r);
///			while(nbrecv(w->ck, &r))
				//wkeyctl(w, r);
			break;
		case WMouse:
			if(w->mouseopen) {
				w->mouse.counter++;

				/* queue click events */
				if(!w->mouse.qfull && lastb != w->mc.buttons) {	/* add to ring */
					mp = &w->mouse.queue[w->mouse.wi];
					if(++w->mouse.wi == nelem(w->mouse.queue))
						w->mouse.wi = 0;
					if(w->mouse.wi == w->mouse.ri)
						w->mouse.qfull = TRUE;
					mp->Mouse = w->mc.Mouse;
					mp->counter = w->mouse.counter;
					lastb = w->mc.buttons;
				}
			} else
				fprint(2, "MOUSECTL\n"); //wmousectl(w);
			break;
		case WMouseread:
			/* send a queued event or, if the queue is empty, the current state */
			/* if the queue has filled, we discard all the events it contained. */
			/* the intent is to discard frantic clicking by the user during long latencies. */
			w->mouse.qfull = FALSE;
			if(w->mouse.wi != w->mouse.ri) {
				m = w->mouse.queue[w->mouse.ri];
				if(++w->mouse.ri == nelem(w->mouse.queue))
					w->mouse.ri = 0;
			} else
				m = (Mousestate){w->mc.Mouse, w->mouse.counter};

			w->mouse.lastcounter = m.counter;
			send(mrm.cm, &m.Mouse);
			continue;
		case WCtl:
			exits("WCtl can't do");
#if 0
			if(wctlmesg(w, wcm.type, wcm.r, wcm.image) == Exited){
				chanfree(crm.c1);
				chanfree(crm.c2);
				chanfree(mrm.cm);
				chanfree(cwm.cw);
				chanfree(cwrm.c1);
				chanfree(cwrm.c2);
				threadexits(nil);
			}
			#endif
			continue;
		case WCwrite:
			recv(cwm.cw, &pair);
			rp = pair.s;
			nr = pair.ns;
			bp = rp;
			for(i=0; i<nr; i++) {
				// See rio for the run conversion crap. For now, I'm not going to
				// worry about it. This is designed to target Akaros too.
				fprint(/*w->Console->out*/1, "%c", *bp++);
			}
			free(rp);
			break;
		case WCread:
			recv(crm.c1, &pair);
			t = pair.s;
			nb = pair.ns;
			i = npart;
			npart = 0;
			if(i)
				memmove(t, part, i);
			while(i<nb && (w->qh<w->nr || w->nraw>0)){
				if(w->qh == w->nr){
					wid = runetochar(t+i, &w->raw[0]);
					w->nraw--;
					runemove(w->raw, w->raw+1, w->nraw);
				}else
					wid = runetochar(t+i, &w->run[w->qh++]);
				c = t[i];	/* knows break characters fit in a byte */
				i += wid;
				if(!w->rawing && (c == '\n' || c=='\004')){
					if(c == '\004')
						i--;
					break;
				}
			}
			if(i==nb && w->qh<w->nr && w->run[w->qh]=='\004')
				w->qh++;
			if(i > nb){
				npart = i-nb;
				memmove(part, t+nb, npart);
				i = nb;
			}
			pair.s = t;
			pair.ns = i;
			send(crm.c2, &pair);
			continue;
		case WWread:
			w->wctlready = 0;
			recv(cwrm.c1, &pair);
			if(w->deleted)
				pair.ns = sprint(pair.s, "");
			else{
				s = "visible";
				for(i=0; i<nhidden; i++)
					if(hidden[i] == w){
						s = "hidden";
						break;
					}
				t = "notcurrent";
				if(w == input)
					t = "current";
				pair.ns = snprint(pair.s, pair.ns, "%s %s ",t, s);
			}
			send(cwrm.c2, &pair);
			continue;
		}
	}
	print_func_exit();
}
Пример #14
0
int IgcPlay::startPlaying( const QString& startPoint,
                           const int skip,
                           const int playFactor )
{
  int i_skip = skip;
  m_factor = playFactor;

  // Date from IGC file
  QString date;

  // Data from first B-Record
  QString time0;
  QString status0;
  QString latDeg0;
  QString lonDeg0;
  QString latHem0;
  QString lonHem0;
  QString baroAlt0;
  QString gssnAlt0;
  QString fixAcc0;
  QString satsInUse0;

  // Data from second B-Record
  QString time1;
  QString status1;
  QString latDeg1;
  QString lonDeg1;
  QString latHem1;
  QString lonHem1;
  QString baroAlt1;
  QString gssnAlt1;
  QString fixAcc1;
  QString satsInUse1;

  if( m_fileName.isEmpty() )
    {
      qWarning() << "IgcPlay::startPlaying: No file name is defined!";
      return -1;
    }

  QFile file(m_fileName);

  if( ! file.open(QIODevice::ReadOnly) )
    {
      qWarning() << "IgcPlay::startPlaying: Cannot open file" << m_fileName;
      return -1;
    }

  QTextStream inStream(&file);

  bool firstBRecord = true;
  bool startPositionFound = false;

  uint lineNo = 0;
  uint bRecord = 0;

  while( ! inStream.atEnd() )
    {
      lineNo++;

      QString line = inStream.readLine().trimmed();

      if( line.isEmpty() )
        {
          continue;
        }

      if( line.startsWith("HFDTE"))
	{
	  // H-Record, Date, Example HFDTE270614
	  date = line.mid( 5 );
	  continue;
	}

      if( line.startsWith("B") == false )
	{
	  // Ignore other records
	  continue;
	}

      bRecord++;

      if( i_skip > 0 )
        {
          i_skip--;
          continue;
        }

      if( startPoint.isEmpty() == false && startPositionFound == false )
	{
	  if( line.mid(1, 6).startsWith(startPoint) == false )
	    {
	      // start point not yet reached
	      continue;
	    }

	  startPositionFound = true;
	}

      if( line.size() < 40 )
	{
	  qWarning() << "Line:" << line << "B-Record to short!";
	  continue;
	}

      // qDebug() << "B:" << line;

      // Only B-Records are taken into account
      //
      // 0           1          2            3
      // 0 123456 78901234 567890123 4 56789 01234 567 89
      // B 155706 5229791N 01331393E A 00000 00081 001 08
      //
      // Extract time
      time1 = line.mid( 1, 6 );

      // Extract coordinates
      latHem1 = line.mid( 14, 1 );
      lonHem1 = line.mid( 23, 1 );

      latDeg1 = line.mid(7, 4) + "." + line.mid(11, 3);
      lonDeg1 = line.mid(15, 5) + "." + line.mid(20, 3);

      // Extract GPS fix status
      status1 = line.mid( 24, 1 );

      // Extract baro and GPS altitude
      baroAlt1 = line.mid( 25, 5 );
      gssnAlt1 = line.mid( 30, 5 );

      // Extract fix accuracy
      fixAcc1 = line.mid( 35, 3 );

      // Extract sats in use
      satsInUse1 = line.mid( 38, 2 );

      if( firstBRecord == true )
	{
	  // Store first extracted B-Record data and read the next one
	  firstBRecord = false;

	  time0 = time1;
	  status0 = status1;
	  latDeg0 = latDeg1;
	  lonDeg0 = lonDeg1;
	  latHem0 = latHem1;
	  lonHem0 = lonHem1;
	  baroAlt0 = baroAlt1;
	  gssnAlt0 = gssnAlt1;
	  fixAcc0 = fixAcc1;
	  satsInUse0 = satsInUse1;
	  continue;
	}

      // Calculate distance between coordinate points of B-Records
      double lat0, lon0, lat1, lon1;

      lat0 = latDeg0.left(2).toDouble() + latDeg0.mid(2).toDouble() / 60.;
      if( latHem0 == "S" ) lat0 = -lat0;

      lat1 = latDeg1.left(2).toDouble() + latDeg1.mid(2).toDouble() / 60.;
      if( latHem1 == "S" ) lat1 = -lat1;

      lon0 = lonDeg0.left(3).toDouble() + lonDeg0.mid(3).toDouble() / 60.;
      if( lonHem0 == "W" ) lon0 = -lon0;

      lon1 = lonDeg1.left(3).toDouble() + lonDeg1.mid(3).toDouble() / 60.;
      if( lonHem1 == "W" ) lon1 = -lon1;

      // Distance in meters
      double distBetweenPoints = distC1( lat0, lon0, lat1, lon1);

      // Calculate time difference in seconds between B-Records
      QTime qtime0 = QTime::fromString( time0, "HHmmss");
      QTime qtime1 = QTime::fromString( time1, "HHmmss");

      if( ! qtime0.isValid() || ! qtime1.isValid() )
	{
	  qWarning() << "Line:" << line << "B-Record time is wrong!";
	  continue;
	}

      int timeDiff = qtime0.secsTo( qtime1 );

      qDebug() << "--Line=" << lineNo
	       << "B-Record=" << bRecord
	       << "Time=" << qtime1.toString(("HH:mm:ss"))
	       << "TimeDiff=" << timeDiff;

      // Check time difference, if negative, make it positive
      if( timeDiff < 0 )
	{
	  qWarning() << "TimeDiff is negative!" << timeDiff;
	  timeDiff = -timeDiff;
	}

      // Take over the new values as base for the next round.
      time0 = time1;
      status0 = status1;
      latDeg0 = latDeg1;
      lonDeg0 = lonDeg1;
      latHem0 = latHem1;
      lonHem0 = lonHem1;
      baroAlt0 = baroAlt1;
      gssnAlt0 = gssnAlt1;
      fixAcc0 = fixAcc1;
      satsInUse0 = satsInUse1;

      // Check time difference, if zero something is wrong
      if( timeDiff == 0 )
	{
	  continue;
	}

      // Calculate speed in m/s
      Speed speed( distBetweenPoints / (double) timeDiff );

      // Calculate heading in degrees 0...360, if distance is > 0.5m
      double bearing = 0.0;

      if( distBetweenPoints > 0.5 )
	{
	  bearing = getBearingWgs( lat0, lon0, lat1, lon1 );
	}

      /**
        See http://www.nmea.de/nmea0183datensaetze.html

        RMC - Recommended Minimum Navigation Information

                                                                     12
                1         2 3       4 5        6 7   8   9     10  11 | 13
                |         | |       | |        | |   |   |      |   | | |
         $--RMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,ddmmyy,x.x,a,a*hh<CR><LF>

         $GPRMC,132217.00,A,5228.19856,N,01408.32249,E,47.100,267.38,300710,,,A*58

         Field Number:
          1) UTC Time
          2) Status, A = valid position, V = Navigation receiver warning
          3) Latitude ddmm.mmm
          4) Latitude hemisphere, N or S
          5) Longitude dddmm.mm
          6) Longitude hemisphere, E or W
          7) Speed over ground, knots 0.0 ... 999.9
          8) Course over ground, degrees true
          9) UTC date of position fix, ddmmyy format
         10) Magnetic Variation, degrees
         11) Magnetic Variation direction, E or W
         12) Signal integrity, A=Autonomous mode
         13) Checksum, hh
      */

      // Prepare RMC sentence
      QString rmc = "$GPRMC," + time1 + "," + status1 + "," +
	            latDeg1 + "," + latHem1 + "," +
	            lonDeg1 + "," + lonHem1 + "," +
	            QString("%1").arg( speed.getKnots(), 0, 'f', 1 ) + "," +
	            QString("%1").arg( bearing, 0, 'f', 0 ) + "," +
	            date + ",,," + "A";

      Sentence sentence;

      sentence.send( rmc, m_fifo );

      /**
        GLL - Geographic Position - Latitude/Longitude

               1       2 3        4 5         6 7
               |       | |        | |         | |
        $--GLL,llll.ll,a,yyyyy.yy,a,hhmmss.ss,A*hh<CR><LF>

         Field Number:
          1) Latitude
          2) N or S (North or South)
          3) Longitude
          4) E or W (East or West)
          5) Universal Time Coordinated (UTC)
          6) Status A - Data Valid, V - Data Invalid
          7) Checksum

          $GPGLL,4916.45,N,12311.12,W,225444,A
      */

#if 0
      // Not necessary to send this.
      QString ggl = "$GPGLL," +
	            latDeg1 + "," + latHem1 + "," +
	  	    lonDeg1 + "," + lonHem1 + "," +
	  	    time1 + "," +
	  	    status1;

      sentence.send( ggl, m_fifo );
#endif

      /**
        GGA - Global Positioning System Fix Data, Time, Position and fix related data for a GPS receiver.

                1         2       3 4        5 6 7  8   9  10 11 12 13  14   15
                |         |       | |        | | |  |   |   | |   | |   |    |
         $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh<CR><LF>

         Field Number:
          1) Universal Time Coordinated (UTC) of position fix, hhmmss format
          2) Latitude, ddmm.mmmm format (leading zeros will be transmitted)
          3) Latitude hemisphere, N or S
          4) Longitude, dddmm.mmmm format (leading zeros will be transmitted)
          5) Longitude hemisphere, E or W
          6) GPS Quality Indicator,
             0 - fix not available,
             1 - GPS fix,
             2 - Differential GPS fix
             6 - Estimated
          7) Number of satellites in view, 00 - 12
          8) Horizontal Dilution of precision 0.5...99.9
          9) Antenna Altitude above/below mean-sea-level (geoid)
         10) Units of antenna altitude, meters
         11) Geoidal separation, the difference between the WGS-84 earth
             ellipsoid and mean-sea-level (geoid), "-" means mean-sea-level
             below ellipsoid
         12) Units of geoidal separation, meters
         13) Age of differential GPS data, time in seconds since last SC104
             type 1 or 9 update, null field when DGPS is not used
         14) Differential reference station ID, 0000-1023
         15) Checksum

         $GPGGA,110959.00,5237.999230,N,01312.523391,E,1,14,1.6,81.4,M,43.0,M,,*54
      */
      QString gga = "$GPGGA," +
	            time1 + "," +
	            latDeg1 + "," + latHem1 + "," +
	            lonDeg1 + "," + lonHem1 + "," +
	            "1," +
	            satsInUse1 + "," +
	            fixAcc1 + "," +
	            gssnAlt1 + ",M,0,M,,";

      sentence.send( gga, m_fifo );

      /**
        Used by Garmin and Flarm devices
        $PGRMZ,93,f,3*21
               93,f         Altitude in feet
               3            Position fix dimensions 2 = FLARM barometric altitude
                                                    3 = GPS altitude
      */
      Altitude alt(baroAlt1.toDouble());
      QString rmz = "$PGRMZ," +
	            QString("%1").arg(alt.getFeet(), 0, 'f', 0) + ",f,2";

      sentence.send( rmz, m_fifo );

      // make a break defined by m_factor
      usleep( timeDiff * 1000000 / m_factor);
    }

  file.close();
  return 0;
}
void main()
{
	char c;
	int day,n,i,j,sum=0,stata[Nday];
	double altemp,aztemp;
	float hour,dis_;
	dis_=interval;

	struct  data
	{   
		float time[Nhour];
		double alt;
		double az;
	};

	data mydata[Nday];
	for (i=0;i<Nday;i++)       //初始化结构体
	{
		for (j=0;j<Nhour;j++)
		{
			mydata[i].time[j]=0;
		}
	}


	for (day=firstday;day<=lastday;day++)
	{
		for (hour=sunrise,n=0;hour<=sundown;)
		{
			altemp=alt(day,hour,latitude,longitude);
			aztemp=az(day,hour,latitude,longitude);

			if (altemp>0 && aztemp>=0)         //使太阳在地平线以上
			{
				mydata[day-1].alt=altemp;
				mydata[day-1].az=aztemp;
			}
			else 
			{
				hour=locate(day,hour,dis_);
				continue;
			}

			hour=locate(day,hour,dis_);
			mydata[day-1].time[n]=dataformat(hour);
			
			if (n==Nhour-2)
			{
				printf("Oh  My God!!!");
				scanf("%d",&i); 				
			}
			printf(" n=%2d    hour=%6.3f   day=%3d  \n",n,hour,day);
			n++;
			stata[day-1]=n;
		}
		sum=sum+n;
	}

	printf("\nCaculate Over!!   Sum=%d KB\n\n\n\nWritting in the file.............\n\n",sum*2/1024);

	FILE *fp;	                                //文件写入部分
	if ((fp=fopen("data.txt","w"))==NULL)
	{
		printf("Cannot open the file!!!\n");
	}

	fputs("\n\n******Generated by Neil******\n",fp);
	fprintf(fp,"\nlatitude=%6.3f\nlongitude=%6.3f\nsunrise=%6.3f\nsundown=%6.3f\nstepinterval=%6.3f\nfirstday=%6d\nlastday=%6d\ndefinition=%6.5f\ninterval=%6.3f\nNday=%6d\n\n",latitude,longitude,sunrise,sundown,stepinterval,firstday,lastday,definition,interval,Nday);         //输出宏定义量的值

	for (i=0;i<Nday;i++)
	{
		for (j=0;j<Nhour;j++)
		{
			if (mydata[i].time[j]==0)
			{
				break;
			}
			//fprintf(fp,"day=%3d   number=%2d   hour=%4.0f \n",i+1,j+1,mydata[i].time[j]);
			fprintf(fp,"code unsigned char Timedatas[%d].data[%d]=%4.0f\n",i,j,mydata[i].time[j]);

		}
	}

	for (i=0;i<Nday;i++)
	{		
		fprintf(fp,"day=%3d   %d\n",i+1,stata[i]);
	}

	fputs("\n\n******Generated by Neil******\n",fp);
	fclose(fp);                                                                 //写入完毕


	printf("Congrutulation  !!!!!!\n\n******Generated by Neil******\n\n");                 //以下是执行退出部分
	printf("All work have been done well!!\n\nYou can Press Enter to close me.\n\n");
	c=getchar();
	if (c==13)
	{
		exit(0);
	}
	else printf("All work have done well!!\nYou can Press Enter to close me.\n");
}
Пример #16
0
/**
 * Extract reference sequence region for motif discovery.
 *
 * The input is a VCF record that contains an indel.
 * 
 * If the the indel has multiple alleles, it will examine all
 * alleles.
 *
 * todo: is might be a good idea to combine this step with motif detection
 *       since there seems to be a need to have an iterative process here
 *       to ensure a good candidate motif is chosen. *  
 */
void CandidateRegionExtractor::extract_regions_by_exact_alignment(bcf_hdr_t* h, bcf1_t* v, Variant& variant)
{
    if (debug)
    {
        if (debug) std::cerr << "********************************************\n";
        std::cerr << "EXTRACTIING REGION BY EXACT LEFT AND RIGHT ALIGNMENT\n\n";
    }

    VNTR& vntr = variant.vntr;
    const char* chrom = bcf_get_chrom(h, v);

    int32_t min_beg1 = bcf_get_pos1(v);
    int32_t max_end1 = min_beg1;

    if (debug)
    {
       bcf_print_liten(h, v);
    }

    //merge candidate search region
    for (size_t i=1; i<bcf_get_n_allele(v); ++i)
    {
        std::string ref(bcf_get_alt(v, 0));
        std::string alt(bcf_get_alt(v, i));
        int32_t pos1 = bcf_get_pos1(v);

        //this prevents introduction of flanks that do not harbour the repeat unit
        trim(pos1, ref, alt);

        int32_t end1 = pos1 + ref.size() - 1;
        right_align(chrom, end1, ref, alt);

        int32_t beg1 = end1 - ref.size() + 1;
        left_align(chrom, beg1, ref, alt);

        min_beg1 = beg1<min_beg1 ? beg1 : min_beg1;
        max_end1 = end1>max_end1 ? end1 : max_end1;

        int32_t seq_len;
        char* seq = faidx_fetch_seq(fai, chrom, min_beg1-1, max_end1-1, &seq_len);

        if (debug)
        {
            std::cerr << "EXACT REGION " << min_beg1 << "-" << max_end1 << " (" << max_end1-min_beg1+1 <<") from " << pos1 << ":" << ref << ":" << alt << "\n";
            std::cerr << "             " << seq << "\n";
        }

        if (seq_len) free(seq);
    }

    int32_t seq_len;
    char* seq = faidx_fetch_seq(fai, chrom, min_beg1-1, max_end1-1, &seq_len);

    if (debug)
    {
        std::cerr << "FINAL EXACT REGION " << min_beg1 << "-" << max_end1 << " (" << max_end1-min_beg1+1 <<") " << "\n";
        std::cerr << "                   " << seq << "\n";
    }

    vntr.exact_repeat_tract = seq;
    vntr.rid = bcf_get_rid(v);
    vntr.exact_rbeg1 = min_beg1;
    vntr.exact_rend1 = max_end1;
    
    if (seq_len) free(seq);
}
Пример #17
0
int main(int argc, char ** argv)
{
    int i;
    int mode = 0;

    if (argc == 2)
    {
        mode = argv[1][0] - '0';
        if (mode < 0 || mode > 4)
        {
            mode = 0;
        }
    }

    //mode:
    // 0x00  D9 켜기
    // 0x01  D8 켜기
    // 0x02  D8 켜기, D10 블링킹

    io_init();

    for (i = 0; i < sizeof(pinmaps)/sizeof(struct led_pinmap); i++)
    {
        alt(pinmaps[i].module, pinmaps[i].bit, 0);
        dir(pinmaps[i].module, pinmaps[i].bit, 1);
        pinmaps[i].value = 1;
        output(pinmaps[i].module, pinmaps[i].bit, pinmaps[i].value);
    }
    
    // Init
    switch(mode)
    {
        case 0:
            pinmaps[2].value = 0;
            output(pinmaps[2].module, pinmaps[2].bit, pinmaps[2].value);
            break;
        case 1:
            pinmaps[0].value = 0;
            output(pinmaps[0].module, pinmaps[0].bit, pinmaps[0].value);
            break;
        case 2:
            pinmaps[0].value = 0;
            output(pinmaps[0].module, pinmaps[0].bit, pinmaps[0].value);
            break;
    }

    // Blinking
    while (1)
    {
        switch(mode)
        {
            case 1:
                break;
            case 2:
                pinmaps[1].value = !pinmaps[1].value;
                output(pinmaps[1].module, pinmaps[1].bit, pinmaps[1].value);
                break;
            case 3:
                break;
        }
        usleep(500 * 1000);
    }

    io_exit();

    return 0;
}
Пример #18
0
void
waitthread(void *v)
{
	Waitmsg *w;
	Command *c, *lc;
	uint pid;
	int found, ncmd;
	Rune *cmd;
	char *err;
	Text *t;
	Pid *pids, *p, *lastp;
	enum { WErr, WKill, WWait, WCmd, NWALT };
	Alt alts[NWALT+1];

	USED(v);
	threadsetname("waitthread");
	pids = nil;
	alts[WErr].c = cerr;
	alts[WErr].v = &err;
	alts[WErr].op = CHANRCV;
	alts[WKill].c = ckill;
	alts[WKill].v = &cmd;
	alts[WKill].op = CHANRCV;
	alts[WWait].c = cwait;
	alts[WWait].v = &w;
	alts[WWait].op = CHANRCV;
	alts[WCmd].c = ccommand;
	alts[WCmd].v = &c;
	alts[WCmd].op = CHANRCV;
	alts[NWALT].op = CHANEND;

	command = nil;
	for(;;){
		switch(alt(alts)){
		case WErr:
			qlock(&row.lk);
			warning(nil, "%s", err);
			free(err);
			flushimage(display, 1);
			qunlock(&row.lk);
			break;
		case WKill:
			found = FALSE;
			ncmd = runestrlen(cmd);
			for(c=command; c; c=c->next){
				/* -1 for blank */
				if(runeeq(c->name, c->nname-1, cmd, ncmd) == TRUE){
					if(postnote(PNGROUP, c->pid, "kill") < 0)
						warning(nil, "kill %S: %r\n", cmd);
					found = TRUE;
				}
			}
			if(!found)
				warning(nil, "Kill: no process %S\n", cmd);
			free(cmd);
			break;
		case WWait:
			pid = w->pid;
			lc = nil;
			for(c=command; c; c=c->next){
				if(c->pid == pid){
					if(lc)
						lc->next = c->next;
					else
						command = c->next;
					break;
				}
				lc = c;
			}
			qlock(&row.lk);
			t = &row.tag;
			textcommit(t, TRUE);
			if(c == nil){
				/* helper processes use this exit status */
				if(strncmp(w->msg, "libthread", 9) != 0){
					p = emalloc(sizeof(Pid));
					p->pid = pid;
					strncpy(p->msg, w->msg, sizeof(p->msg));
					p->next = pids;
					pids = p;
				}
			}else{
				if(search(t, c->name, c->nname)){
					textdelete(t, t->q0, t->q1, TRUE);
					textsetselect(t, 0, 0);
				}
				if(w->msg[0])
					warning(c->md, "%.*S: exit %s\n", c->nname-1, c->name, w->msg);
				flushimage(display, 1);
			}
			qunlock(&row.lk);
			free(w);
    Freecmd:
			if(c){
				if(c->iseditcmd)
					sendul(cedit, 0);
				free(c->text);
				free(c->name);
				fsysdelid(c->md);
				free(c);
			}
			break;
		case WCmd:
			/* has this command already exited? */
			lastp = nil;
			for(p=pids; p!=nil; p=p->next){
				if(p->pid == c->pid){
					if(p->msg[0])
						warning(c->md, "%s\n", p->msg);
					if(lastp == nil)
						pids = p->next;
					else
						lastp->next = p->next;
					free(p);
					goto Freecmd;
				}
				lastp = p;
			}
			c->next = command;
			command = c;
			qlock(&row.lk);
			t = &row.tag;
			textcommit(t, TRUE);
			textinsert(t, 0, c->name, c->nname, TRUE);
			textsetselect(t, 0, 0);
			flushimage(display, 1);
			qunlock(&row.lk);
			break;
		}
	}
}
Пример #19
0
/*
 * watch the exiting children
 */
Channel *twaitchan;	/* chan(Waitreq) */
void
waitthread(void *v)
{
	Alt a[3];
	Waitmsg *w, **wq;
	Waitreq *rq, r;
	int i, nrq, nwq;

	threadsetname("waitthread");
	a[0].c = threadwaitchan();
	a[0].v = &w;
	a[0].op = CHANRCV;
	a[1].c = twaitchan;
	a[1].v = &r;
	a[1].op = CHANRCV;
	a[2].op = CHANEND;

	nrq = 0;
	nwq = 0;
	rq = nil;
	wq = nil;
	dprint("wait: start\n");
	for(;;){
	cont2:;
		dprint("wait: alt\n");
		switch(alt(a)){
		case 0:
			dprint("wait: pid %d exited\n", w->pid);
			for(i=0; i<nrq; i++){
				if(rq[i].pid == w->pid){
					dprint("wait: match with rq chan %p\n", rq[i].c);
					sendp(rq[i].c, w);
					rq[i] = rq[--nrq];
					goto cont2;
				}
			}
			if(i == nrq){
				dprint("wait: queueing waitmsg\n");
				wq = erealloc(wq, (nwq+1)*sizeof(wq[0]));
				wq[nwq++] = w;
			}
			break;
		
		case 1:
			dprint("wait: req for pid %d chan %p\n", r.pid, r.c);
			for(i=0; i<nwq; i++){
				if(w->pid == r.pid){
					dprint("wait: match with waitmsg\n");
					sendp(r.c, w);
					wq[i] = wq[--nwq];
					goto cont2;
				}
			}
			if(i == nwq){
				dprint("wait: queueing req\n");
				rq = erealloc(rq, (nrq+1)*sizeof(rq[0]));
				rq[nrq] = r;
				dprint("wait: queueing req pid %d chan %p\n", rq[nrq].pid, rq[nrq].c);
				nrq++;
			}
			break;
		}
	}
}
Пример #20
0
/**
 * @brief Creates an XsOutputConfigurationArray and pushes it to the sensor.
 * @details
 * - Configures the sensor with desired modules
 * - Refer to xsdataidentifier.h
 */
void mtiG::configure(){

	XsOutputConfigurationArray configArray;

	if(mSettings.orientationData){			//Quaternion - containsOrientation
			XsOutputConfiguration quat(XDI_Quaternion, mSettings.orientationFreq);// para pedir quaternion
			configArray.push_back(quat);
	}
	
	if(mSettings.gpsData){
			//LATITUDE E LONGITUDE -containsLatitudeLongitude
			XsOutputConfiguration gps(XDI_LatLon, mSettings.gpsFreq);// para pedir gps, //XDI_Quaternion 06/04
			configArray.push_back(gps);

			XsOutputConfiguration gps_age(XDI_GpsAge, mSettings.gpsFreq);// para pedir gps, //XDI_Quaternion 06/04
			configArray.push_back(gps_age);

			XsOutputConfiguration gps_sol(XDI_GpsSol, mSettings.gpsFreq);// para pedir gps, //XDI_Quaternion 06/04
			configArray.push_back(gps_sol);

			XsOutputConfiguration gps_dop(XDI_GpsDop, mSettings.gpsFreq);// para pedir gps, //XDI_Quaternion 06/04
			configArray.push_back(gps_dop);
	}
	
	if(mSettings.temperatureData){	
			//TEMPERATURA - containsTemperature
			XsOutputConfiguration temp(XDI_Temperature, mSettings.temperatureFreq);
			configArray.push_back(temp);
	}	
	
	if(mSettings.accelerationData){
			//ACCELERATION - containsCalibratedAcceleration
			XsOutputConfiguration accel(XDI_Acceleration, mSettings.accelerationFreq);
			configArray.push_back(accel);
	}

	if(mSettings.pressureData){	
			//PRESSURE - containsPressure
			XsOutputConfiguration baro(XDI_BaroPressure, mSettings.pressureFreq);
			configArray.push_back(baro);
	}

	if(mSettings.magneticData){
			//MAGNETIC FIELD - containsCalibratedMagneticField
			XsOutputConfiguration magnet(XDI_MagneticField, mSettings.magneticFreq);
			configArray.push_back(magnet);
	}

	if(mSettings.altitudeData){
			//ALTITUDE - containsAltitude
			XsOutputConfiguration alt(XDI_AltitudeEllipsoid, mSettings.altitudeFreq);
			configArray.push_back(alt);
	}

	if(mSettings.gyroscopeData){
			//GYRO - containsCalibratedGyroscopeData
			XsOutputConfiguration gyro(XDI_RateOfTurn, mSettings.gyroscopeFreq);
			configArray.push_back(gyro);
	}	

	if(mSettings.velocityData){
			//VELOCIDADE XYZ
			XsOutputConfiguration vel_xyz(XDI_VelocityXYZ, mSettings.velocityFreq);
			configArray.push_back(vel_xyz);
	}
	
	// Puts configArray into the device, overwriting the current configuration
	if (!device->setOutputConfiguration(configArray))
	{
			throw std::runtime_error("Could not configure MTmk4 device. Aborting.");
	}
}
Пример #21
0
Файл: xs.c Проект: npe9/harvey
int
play(void)
{
    int i;
    Mouse om;
    int s;
    Rune r;
    Alt alts[NALT+1];

    alts[TIMER].c = timerc;
    alts[TIMER].v = nil;
    alts[TIMER].op = CHANRCV;
    alts[MOUSE].c = mousec;
    alts[MOUSE].v = &mouse;
    alts[MOUSE].op = CHANRCV;
    alts[SUSPEND].c = suspc;
    alts[SUSPEND].v = &s;
    alts[SUSPEND].op = CHANRCV;
    alts[RESHAPE].c = mousectl->resizec;
    alts[RESHAPE].v = nil;
    alts[RESHAPE].op = CHANRCV;
    alts[KBD].c = kbdc;
    alts[KBD].v = &r;
    alts[KBD].op = CHANRCV;
    alts[NALT].op = CHANEND;

    dt = 64;
    lastmx = -1;
    lastmx = movemouse();
    choosepiece();
    lastmx = warp(mouse.xy, lastmx);
    for(;;)
        switch(alt(alts)) {
        case MOUSE:
            if(suspended) {
                om = mouse;
                break;
            }
            if(lastmx < 0)
                lastmx = mouse.xy.x;
            if(mouse.xy.x > lastmx+DMOUSE) {
                mright();
                lastmx = mouse.xy.x;
            }
            if(mouse.xy.x < lastmx-DMOUSE) {
                mleft();
                lastmx = mouse.xy.x;
            }
            if(mouse.buttons&1 && !(om.buttons&1))
                rleft();
            if(mouse.buttons&2 && !(om.buttons&2))
                if(drop(1))
                    return 1;
            if(mouse.buttons&4 && !(om.buttons&4))
                rright();
            om = mouse;
            break;
        case SUSPEND:
            if (!suspended && s)
                suspend(1);
            else if (suspended && !s) {
                suspend(0);
                lastmx = warp(mouse.xy, lastmx);
            }
            break;
        case RESHAPE:
            redraw(1);
            break;
        case KBD:
            if(suspended)
                break;
            switch(r) {
            case 'f':
            case ';':
                mright();
                break;
            case 'a':
            case 'j':
                mleft();
                break;
            case 'd':
            case 'l':
                rright();
                break;
            case 's':
            case 'k':
                rleft();
                break;
            case ' ':
                if(drop(1))
                    return 1;
                break;
            }
            break;
        case TIMER:
            if(suspended)
                break;
            dt -= tsleep;
            if(dt < 0) {
                i = 1;
                dt = 16 * (points+nrand(10000)-5000) / 10000;
                if(dt >= 32) {
                    i += (dt-32)/16;
                    dt = 32;
                }
                dt = 52-dt;
                while(i-- > 0)
                    if(movepiece()==0 && ++fusst==40) {
                        if(drop(0))
                            return 1;
                        break;
                    }
            }
            break;
        }
}
Пример #22
0
  void keyEvent(rdr::U32 keysym, bool down, bool jap)
  {
	  vnclog.Print(LL_INTWARN, " keysym 0x%x",keysym);
	if (keysym>=XK_dead_grave && keysym <=XK_dead_belowdot)// && down)
	{
		keysymDead=keysym;
		vnclog.Print(LL_INTWARN, " ************** DEAD KEY");
		//we have a dead key
		//Record dead key
		return;
	}

    if ((keysym >= 32 && keysym <= 126) ||
        (keysym >= 160 && keysym <= 255))
    {
	if (keysymDead!=0 && down)
	{
		vnclog.Print(LL_INTWARN, " Compose dead 0x%x 0x%x",keysymDead,keysym);
		switch (keysymDead)
		{
		case XK_dead_grave:
			switch(keysym)
			{
			case XK_A: keysym=XK_Agrave;break;
			case XK_E: keysym=XK_Egrave;break;
			case XK_I: keysym=XK_Igrave;break;
			case XK_O: keysym=XK_Ograve;break;
			case XK_U: keysym=XK_Ugrave;break;
			case XK_a: keysym=XK_agrave;break;
			case XK_e: keysym=XK_egrave;break;
			case XK_i: keysym=XK_igrave;break;
			case XK_o: keysym=XK_ograve;break;
			case XK_u: keysym=XK_ugrave;break;
			}
		case XK_dead_acute:
			switch(keysym)
			{
			case XK_A: keysym=XK_Aacute;break;
			case XK_E: keysym=XK_Eacute;break;
			case XK_I: keysym=XK_Iacute;break;
			case XK_O: keysym=XK_Oacute;break;
			case XK_U: keysym=XK_Uacute;break;
			case XK_a: keysym=XK_aacute;break;
			case XK_e: keysym=XK_eacute;break;
			case XK_i: keysym=XK_iacute;break;
			case XK_o: keysym=XK_oacute;break;
			case XK_u: keysym=XK_uacute;break;
			case XK_y: keysym=XK_yacute;break;
			case XK_Y: keysym=XK_Yacute;break;

			}
		case XK_dead_circumflex:
			switch(keysym)
			{
			case XK_A: keysym=XK_Acircumflex;break;
			case XK_E: keysym=XK_Ecircumflex;break;
			case XK_I: keysym=XK_Icircumflex;break;
			case XK_O: keysym=XK_Ocircumflex;break;
			case XK_U: keysym=XK_Ucircumflex;break;
			case XK_a: keysym=XK_acircumflex;break;
			case XK_e: keysym=XK_ecircumflex;break;
			case XK_i: keysym=XK_icircumflex;break;
			case XK_o: keysym=XK_ocircumflex;break;
			case XK_u: keysym=XK_ucircumflex;break;
			}
		case XK_dead_tilde:
			switch(keysym)
			{
			case XK_A : keysym=XK_Ntilde;break;
			case XK_O : keysym=XK_Otilde;break;
			case XK_a : keysym=XK_atilde;break;
			case XK_n : keysym=XK_ntilde;break;
			case XK_o : keysym=XK_otilde;break;
			}

		case XK_dead_diaeresis:
			switch(keysym)
			{
			case XK_A: keysym=XK_Adiaeresis;break;
			case XK_E: keysym=XK_Ediaeresis;break;
			case XK_I: keysym=XK_Idiaeresis;break;
			case XK_O: keysym=XK_Odiaeresis;break;
			case XK_U: keysym=XK_Udiaeresis;break;
			case XK_a: keysym=XK_adiaeresis;break;
			case XK_e: keysym=XK_ediaeresis;break;
			case XK_i: keysym=XK_idiaeresis;break;
			case XK_o: keysym=XK_odiaeresis;break;
			case XK_u: keysym=XK_udiaeresis;break;
			case XK_y: keysym=XK_ydiaeresis;break;

			}
		case XK_dead_cedilla:
			switch(keysym)
			{
			case XK_C: keysym=XK_Ccedilla;break;
			case XK_c: keysym=XK_ccedilla;break;
			}
		}
		keysymDead=0;
		vnclog.Print(LL_INTWARN, " Composed 0x%x",keysym);

	}
      // ordinary Latin-1 character

      SHORT s = VkKeyScan(keysym);

      //	[v1.0.2-jp1 fix] yak!'s patch
	  // This break Other keyboards, we need an easy way of fixing this
	  if (jap)
	  {
		  if (keysym==XK_kana_WO) {
			s = 0x0130;
		  } else if (keysym==XK_backslash) {
			s = 0x00e2;
		  } else if (keysym==XK_yen) {
			s = 0x00dc;
		  }
	  }

	  vnclog.Print(LL_INTWARN, " SHORT s %i",s);

	 if (s == -1)
	 {
		 
      if (down) {
		  vnclog.Print(LL_INTWARN, "down");
        // not a single keypress - try synthesizing dead chars.
			{
			  vnclog.Print(LL_INTWARN, " Found key");
			  //Lookup ascii representation
			  int ascii=0;
#if 0
              // 11 Dec 2008 jdp disabled since the viewer is sending unicode now
			  for (ascii=0;ascii<256;ascii++)
			  {
				  if (keysym==ascii_to_x[ascii]) break;
			  }
#endif
              ascii = keysym;
			  if (ascii <= 255)
			  {

			  rdr::U8 a0=ascii/100;
			  ascii=ascii%100;
			  rdr::U8 a1=ascii/10;
			  ascii=ascii%10;
			  rdr::U8 a2=ascii;

              KeyStateModifier shift(VK_SHIFT);
              KeyStateModifier lshift(VK_LSHIFT);
              KeyStateModifier rshift(VK_RSHIFT);

              if (vncService::IsWin95()) {
                shift.release();
              } else {
                lshift.release();
                rshift.release();
			  }

              vnclog.Print(LL_INTWARN, " Simulating ALT+%d%d%d\n", a0, a1 ,a2);

			  keybd_event(VK_MENU,MapVirtualKey( VK_MENU, 0 ), 0 ,0);
              /**
                Pressing the Alt+NNN combinations without leading zero (for example, Alt+20, Alt+130, Alt+221) 
                will insert characters from the Extended ASCII (or MS DOS ASCII, or OEM) table. The character 
                glyphs contained by this table depend on the language of Windows. See the table below for the 
                list of characters that can be inserted through the Alt+NNN combinations (without leading zero)
                in English Windows.

                Pressing the Alt+0NNN combinations will insert the ANSI characters corresponding to the activate 
                keyboard layout. Please see Windows Character Map utility (charmap.exe) for the possible Alt+0NNN
                combinations.

                Finally, the Alt+00NNN combinations (two leading zeros) will insert Unicode characters. The Unicode 
                codes of characters are displayed in Charmap.

              **/
              // jdp 11 December 2008 - Need the leading 0! 
			  keybd_event(VK_NUMPAD0,    MapVirtualKey(VK_NUMPAD0,    0), 0, 0);
			  keybd_event(VK_NUMPAD0,    MapVirtualKey(VK_NUMPAD0,    0),KEYEVENTF_KEYUP,0);
			  keybd_event(VK_NUMPAD0+a0, MapVirtualKey(VK_NUMPAD0+a0, 0), 0, 0);
			  keybd_event(VK_NUMPAD0+a0, MapVirtualKey(VK_NUMPAD0+a0, 0),KEYEVENTF_KEYUP,0);
			  keybd_event(VK_NUMPAD0+a1, MapVirtualKey(VK_NUMPAD0+a1, 0),0,0);
			  keybd_event(VK_NUMPAD0+a1, MapVirtualKey(VK_NUMPAD0+a1, 0),KEYEVENTF_KEYUP, 0);
			  keybd_event(VK_NUMPAD0+a2, MapVirtualKey(VK_NUMPAD0+a2, 0) ,0, 0);
			  keybd_event(VK_NUMPAD0+a2, MapVirtualKey(VK_NUMPAD0+a2, 0),KEYEVENTF_KEYUP, 0);
			  keybd_event(VK_MENU, MapVirtualKey( VK_MENU, 0 ),KEYEVENTF_KEYUP, 0);
			  return;
			  }
        }
        vnclog.Print(LL_INTWARN, "ignoring unrecognised Latin-1 keysym 0x%x",keysym);
      }
      return;
    }

      /*if (s == -1) {
        vnclog.Print(LL_INTWARN, "ignoring unrecognised Latin-1 keysym %d\n",
                     keysym);
		keybd_event( VK_MENU, MapVirtualKey(VK_MENU, 0),0, 0);
		keybd_event( VK_MENU, MapVirtualKey(VK_MENU, 0),KEYEVENTF_KEYUP, 0);


        return;
      }*/

      BYTE vkCode = LOBYTE(s);

      // 18 March 2008 jdp
      // Correct the keymask shift state to cope with the capslock state
      BOOL capslockOn = (GetKeyState(VK_CAPITAL) & 1) != 0;

      BYTE modifierState = HIBYTE(s);
      modifierState = capslockOn ? modifierState ^ 1 : modifierState;
      KeyStateModifier ctrl(VK_CONTROL);
      KeyStateModifier alt(VK_MENU);
      KeyStateModifier shift(VK_SHIFT);
      KeyStateModifier lshift(VK_LSHIFT);
      KeyStateModifier rshift(VK_RSHIFT);

      if (down) {
        if (modifierState & 2) ctrl.press();
        if (modifierState & 4) alt.press();
        if (modifierState & 1) {
          shift.press(); 
        } else {
		  // [v1.0.2-jp1 fix] Even if "SHIFT + SPACE" are pressed, "SHIFT" is valid
          if (vkCode == 0x20){
		  }
		  else{
            if (vncService::IsWin95()) {
              shift.release();
			} else {
              lshift.release();
              rshift.release();
			}
		  }
        }
      }
      vnclog.Print(LL_INTINFO,
                   "latin-1 key: keysym %d(0x%x) vkCode 0x%x down %d capslockOn %d\n",
                   keysym, keysym, vkCode, down, capslockOn);

      doKeyboardEvent(vkCode, down ? 0 : KEYEVENTF_KEYUP);

    } else {

      // see if it's a recognised keyboard key, otherwise ignore it

      if (vkMap.find(keysym) == vkMap.end()) {
        vnclog.Print(LL_INTWARN, "ignoring unknown keysym %d\n",keysym);
        return;
      }
      BYTE vkCode = vkMap[keysym];
      DWORD flags = 0;
      if (extendedMap[keysym]) flags |= KEYEVENTF_EXTENDEDKEY;
      if (!down) flags |= KEYEVENTF_KEYUP;

//      vnclog.Print(LL_INTINFO,
  //                "keyboard key: keysym %d(0x%x) vkCode 0x%x ext %d down %d\n",
    //               keysym, keysym, vkCode, extendedMap[keysym], down);

      if (down && (vkCode == VK_DELETE) &&
          ((GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0) &&
          ((GetAsyncKeyState(VK_MENU) & 0x8000) != 0) &&
          vncService::IsWinNT())
      {
		vnclog.Print(LL_INTINFO,
                 "CAD\n");
		// If running under Vista and started from Session0 in Application mode
		if (vncService::VersionMajor()>=6 && vncService::RunningFromExternalService() )
		{
			      vnclog.Print(LL_INTINFO,
                 "Vista and runnning as system -> CAD\n");

				// Try to run the special Vista cad.exe file...
				HANDLE ThreadHandle2;
				DWORD dwTId;
				ThreadHandle2 = CreateThread(NULL, 0, Cadthread, NULL, 0, &dwTId);
				CloseHandle(ThreadHandle2);
		}
		else if (vncService::VersionMajor()>=6)
		{
			vnclog.Print(LL_INTINFO,
                 "Vista and runnning as user -> Taskmgr\n");
			WinExec("taskmgr.exe", SW_SHOWNORMAL);
		}
		else if (vncService::VersionMajor()<6 && vncService::RunningFromExternalService() )
		{
			vnclog.Print(LL_INTINFO,
                 "Not Vista and runnning as system, use old method\n");
			vncService::SimulateCtrlAltDel();
		}
		else if (vncService::VersionMajor()<6)
		{
			vnclog.Print(LL_INTINFO,
                 "Not Vista and runnning as user -> Taskmgr\n");
			WinExec("taskmgr.exe", SW_SHOWNORMAL);
		}
        return;
      }

      if (vncService::IsWin95()) {
        switch (vkCode) {
        case VK_RSHIFT:   vkCode = VK_SHIFT;   break;
        case VK_RCONTROL: vkCode = VK_CONTROL; break;
        case VK_RMENU:    vkCode = VK_MENU;    break;
        }
      }

      doKeyboardEvent(vkCode, flags);
    }
  }
Пример #23
0
void
decproc(void*)
{
	Pmsg playstate, newstate;
	int fd;
	Pacbuf *pb;
	Alt a[3] = {
		{empty, &pb, CHANNOP},
		{playc, &newstate.m, CHANRCV},
		{nil, nil, CHANEND},
	};

	threadsetname("decproc");
	close(srvfd[1]);
	newstate.cmd = playstate.cmd = Stop;
	newstate.off = playstate.off = 0;
	fd = -1;
	for(;;){
		switch(alt(a)){
		case 0:
			/* Play out next buffer (pb points to one already) */
			assert(fd >= 0);	/* Because we must be in Play mode */
			pb->m = playstate.m;
			pb->len = read(fd, pb->data, sizeof pb->data);
			if(pb->len > 0){
				sendp(full, pb);
				break;
			}
			if(pb->len < 0){
				if(debug & DbgPlayer)
					fprint(2, "pac, error: %d\n", playstate.off);
				pb->cmd = Error;
				pb->len = snprint(pb->data, sizeof pb->data, "%s: %r", curfile);
				sendp(full, pb);
			}else{
				/* Simple end of file */
				sendp(empty, pb); /* Don't need buffer after all */
			}
			close(fd);
			fd = -1;
			if(debug & DbgPlayer)
				fprint(2, "pac, eof: %d\n", playstate.off);
			/* End of file, do next by falling through */
			newstate.cmd = playstate.cmd;
			newstate.off = playstate.off + 1;
		case 1:
			if((debug & DbgPac) && newstate.cmd)
				fprint(2, "Pacproc: newstate %s-%d, playstate %s-%d\n",
					statetxt[newstate.cmd], newstate.off,
					statetxt[playstate.cmd], playstate.off);
			/* Deal with an incoming command */
			if(newstate.cmd == Pause || newstate.cmd == Resume){
				/* Just pass them on, don't change local state */
				pb = recvp(spare);
				pb->m = newstate.m;
				sendp(full, pb);
				break;
			}
			/* Stop whatever we're doing */
			if(fd >= 0){
				if(debug & DbgPlayer)
					fprint(2, "pac, stop\n");
				/* Stop any active (pac) decoders */
				close(fd);
				fd = -1;
			}
			a[0].op = CHANNOP;
			switch(newstate.cmd){
			default:
				sysfatal("decproc: unexpected newstate %d", newstate.cmd);
			case Stop:
				/* Wait for state to change */
				break;
			case Skip:
			case Play:
				fd = startplay(newstate.off);
				if(fd >=0){
					playstate = newstate;
					a[0].op = CHANRCV;
					continue;	/* Start reading */
				}
				newstate.cmd = Stop;
			}
			pb = recvp(spare);
			pb->m = newstate.m;
			sendp(full, pb);
			playstate = newstate;
		}
	}
}
Пример #24
0
int
nbnsfindname(uchar *serveripaddr, NbName name, uchar *ipaddr, ulong *ttlp)
{
	NbnsMessage *nq;
	Alt aa[3];
	int tries = NbnsRetryBroadcast;
	NbnsAlarm *a;
	int rv;
	NbnsMessage *response;

	nq = nbnsmessagenamequeryrequestnew(0, serveripaddr == nil, name);
	if (nq == nil)
		return -1;
	a = nbnsalarmnew();
	if (a == nil) {
		free(nq);
		return -1;
	}
	aa[0].c = a->c;
	aa[0].v = nil;
	aa[0].op = CHANRCV;
	aa[1].op = CHANRCV;
	aa[2].op = CHANEND;
	while (tries > 0) {
		NbnsTransaction *t;
		nq->id = nbnsnextid();
		t = nbnstransactionnew(nq, serveripaddr);
		aa[1].c = t->c;
		aa[1].v = &response;
		nbnsalarmset(a, NbnsTimeoutBroadcast);
		for (;;) {
			int i;
			i = alt(aa);
			if (i == 0) {
				tries--;
				break;
			}
			else if (i == 1) {
				if (response->opcode == NbnsOpQuery) {
					nbnstransactionfree(&t);
					goto done;
				}
				nbnsmessagefree(&response);
			}
		}
		nbnstransactionfree(&t);
	}
done:
	if (tries == 0)
		rv = -1;
	else {
		if (response->rcode != 0)
			rv = response->rcode;
		else if (response->an == nil)
			rv = -1;
		else {
			rv = 0;
			v4tov6(ipaddr, response->an->rdata + 2);
			if (ttlp)
				*ttlp = response->an->ttl;
		}
		nbnsmessagefree(&response);
	}
	nbnsalarmfree(&a);
	nbnsmessagefree(&nq);
	return rv;
}
Пример #25
0
void
pcmproc(void*)
{
	Pmsg localstate, newstate, prevstate;
	int fd, n;
	Pacbuf *pb, *b;
	Alt a[3] = {
		{full, &pb, CHANRCV},
		{playout, &pb, CHANRCV},
		{nil, nil, CHANEND},
	};

	/*
	 * This is the real-time proc.
	 * It gets its input from two sources, full data/control buffers from the decproc
	 * which mixes decoded data with control messages, and data buffers from the pcmproc's
	 * (*this* proc's) own internal playout buffer.
	 * When a command is received on the `full' channel containing a command that warrants
	 * an immediate change of audio source (e.g., to silence or to another number), we just
	 * toss everything in the pipeline -- i.e., the playout channel
	 * Finally, we report all state changes using `playupdate' (another message channel)
	 */
	threadsetname("pcmproc");
	close(srvfd[1]);
	fd = -1;
	localstate.cmd = 0;	/* Force initial playupdate */
	newstate.cmd = Stop;
	newstate.off = 0;
//	rtsched();
	boost();
	for(;;){
		if(newstate.m != localstate.m){
			playupdate(newstate, nil);
			localstate = newstate;
		}
		switch(alt(a)){
		case 0:
			/* buffer received from decproc */
			if((debug & DbgPcm) && localstate.m != prevstate.m){
				fprint(2, "pcm, full: %s-%d, local state is %s-%d\n",
					statetxt[pb->cmd], pb->off,
					statetxt[localstate.cmd], localstate.off);
				prevstate.m = localstate.m;
			}
			switch(pb->cmd){
			default:
				sysfatal("pcmproc: unknown newstate: %s-%d", statetxt[pb->cmd], pb->off);
			case Resume:
				a[1].op = CHANRCV;
				newstate.cmd = Play;
				break;
			case Pause:
				a[1].op = CHANNOP;
				newstate.cmd = Pause;
				if(fd >= 0){
					close(fd);
					fd = -1;
				}
				break;
			case Stop:
				/* Dump all data in the buffer */
				while(b = nbrecvp(playout))
					if(b->cmd == Error){
						playupdate(b->Pmsg, b->data);
						sendp(spare, b);
					}else
						sendp(empty, b);
				newstate.m = pb->m;
				a[1].op = CHANRCV;
				if(fd >= 0){
					close(fd);
					fd = -1;
				}
				break;
			case Skip:
				/* Dump all data in the buffer, then fall through */
				while(b = nbrecvp(playout))
					if(b->cmd == Error){
						playupdate(pb->Pmsg, pb->data);
						sendp(spare, pb);
					}else
						sendp(empty, b);
				a[1].op = CHANRCV;
				newstate.cmd = Play;
			case Error:
			case Play:
				/* deal with at playout, just requeue */
				sendp(playout, pb);
				pb = nil;
				localstate = newstate;
				break;
			}
			/* If we still have a buffer, free it */
			if(pb)
				sendp(spare, pb);
			break;
		case 1:
			/* internal buffer */
			if((debug & DbgPlayer) && localstate.m != prevstate.m){
				fprint(2, "pcm, playout: %s-%d, local state is %s-%d\n",
					statetxt[pb->cmd], pb->off,
					statetxt[localstate.cmd], localstate.off);
				prevstate.m = localstate.m;
			}
			switch(pb->cmd){
			default:
				sysfatal("pcmproc: unknown newstate: %s-%d", statetxt[pb->cmd], pb->off);
			case Error:
				playupdate(pb->Pmsg, pb->data);
				localstate = newstate;
				sendp(spare, pb);
				break;
			case Play:
				if(fd < 0 && (fd = open("/dev/audio", OWRITE)) < 0){
					a[1].op = CHANNOP;
					newstate.cmd = Pause;
					pb->cmd = Error;
					snprint(pb->data, sizeof(pb->data),
						"/dev/audio: %r");
					playupdate(pb->Pmsg, pb->data);
					sendp(empty, pb);
					break;
				}
				/* play out this buffer */
				totbytes += pb->len;
				totbuffers++;
				n = write(fd, pb->data, pb->len);
				if (n != pb->len){
					if (debug & DbgPlayer)
						fprint(2, "pcmproc: file %d: %r\n", pb->off);
					if (n < 0)
						sysfatal("pcmproc: write: %r");
				}
				newstate.m = pb->m;
				sendp(empty, pb);
				break;
			}
			break;
		}
	}
}
Пример #26
0
int main()
{
    printf("Mallocing\n");
    alt();
}
Пример #27
0
void
keyboardthread(void *v)
{
	Rune r;
	Timer *timer;
	Text *t;
	enum { KTimer, KKey, NKALT };
	static Alt alts[NKALT+1];

	USED(v);
	alts[KTimer].c = nil;
	alts[KTimer].v = nil;
	alts[KTimer].op = CHANNOP;
	alts[KKey].c = keyboardctl->c;
	alts[KKey].v = &r;
	alts[KKey].op = CHANRCV;
	alts[NKALT].op = CHANEND;

	timer = nil;
	typetext = nil;
	threadsetname("keyboardthread");
	for(;;){
		switch(alt(alts)){
		case KTimer:
			timerstop(timer);
			t = typetext;
			if(t!=nil && t->what==Tag){
				winlock(t->w, 'K');
				wincommit(t->w, t);
				winunlock(t->w);
				flushimage(display, 1);
			}
			alts[KTimer].c = nil;
			alts[KTimer].op = CHANNOP;
			break;
		case KKey:
		casekeyboard:
			typetext = rowtype(&row, r, mouse->xy);
			t = typetext;
			if(t!=nil && t->col!=nil && !(r==Kdown || r==Kleft || r==Kright))	/* scrolling doesn't change activecol */
				activecol = t->col;
			if(t!=nil && t->w!=nil)
				t->w->body.file->curtext = &t->w->body;
			if(timer != nil)
				timercancel(timer);
			if(t!=nil && t->what==Tag) {
				timer = timerstart(500);
				alts[KTimer].c = timer->c;
				alts[KTimer].op = CHANRCV;
			}else{
				timer = nil;
				alts[KTimer].c = nil;
				alts[KTimer].op = CHANNOP;
			}
			if(nbrecv(keyboardctl->c, &r) > 0)
				goto casekeyboard;
			flushimage(display, 1);
			break;
		}
	}
}
Пример #28
0
// [[Rcpp::export]]
Rcpp::DataFrame vcf_body(std::string x, Rcpp::NumericVector stats) {
  // Read in the fixed and genotype portion of the file.

  // Stats contains:
  // "meta", "header", "variants", "columns"

  Rcpp::CharacterVector chrom(stats[2]);
  Rcpp::IntegerVector   pos(stats[2]);
  Rcpp::StringVector    id(stats[2]);
  Rcpp::StringVector    ref(stats[2]);
  Rcpp::StringVector    alt(stats[2]);
  Rcpp::NumericVector   qual(stats[2]);
  Rcpp::StringVector    filter(stats[2]);
  Rcpp::StringVector    info(stats[2]);

//  if(stats[3])
  Rcpp::CharacterMatrix gt(stats[2], stats[3] - 8);
  
  std::string line;  // String for reading file into

  // Open file.
  std::ifstream myfile;
  myfile.open (x.c_str(), std::ios::in);

  if (!myfile.is_open()){
    Rcpp::Rcout << "Unable to open file";
  }

  // Iterate past meta.
  int i = 0;
  int j = 0;
  while ( i < stats[0] ){
    getline (myfile,line);
    i++;
  }
  
  // Get header.
  getline (myfile,line);
  std::string header = line;
  
  // Get body.
  i = 0;
  char buffer [50];

  while ( getline (myfile,line) ){
    Rcpp::checkUserInterrupt();
    std::vector < std::string > temps = tabsplit(line, stats[3]);

    if(temps[0] == "."){
      chrom[i] = NA_STRING;
    } else {
      chrom[i] = temps[0];
    }
    if(temps[1] == "."){
      pos[i] = NA_INTEGER;
    } else {
        pos[i] = atoi(temps[1].c_str());
    }
    if(temps[2] == "."){
      id[i] = NA_STRING;
    } else {
      id[i] = temps[2];
    }
    if(temps[3] == "."){
      ref[i] = NA_STRING;
    } else {
      ref[i] = temps[3];
    }
    if(temps[4] == "."){
      alt[i] = NA_STRING;
    } else {
      alt[i] = temps[4];
    }
    if(temps[5] == "."){
      qual[i] = NA_REAL;
    } else {
      qual[i] = atof(temps[5].c_str());
    }
    if(temps[6] == "."){
      filter[i] = NA_STRING;
    } else {
      filter[i] = temps[6];
    }
    if(temps[7] == "."){
      info[i] = NA_STRING;
    } else {
      info[i] = temps[7];
    }

    for(j=8; j<stats[3]; j++){
      gt(i, j-8) = temps[j];
//      body(i, j-8) = temps[j];
    }
    i++;
    
    if( i % nreport == 0){
      Rcpp::Rcout << "\rProcessed variant: " << i;
    }

  }
  myfile.close();
  
  Rcpp::Rcout << "\rProcessed variant: " << i;
  Rcpp::Rcout << "\nAll variants processed\n";
  
  Rcpp::DataFrame df1 = Rcpp::DataFrame::create(
    Rcpp::_["CHROM"]= chrom,
    Rcpp::_["POS"]= pos,
    Rcpp::_["ID"] = id,
    Rcpp::_["REF"] = ref,
    Rcpp::_["ALT"] = alt,
    Rcpp::_["QUAL"] = qual,
    Rcpp::_["FILTER"] = filter,
    Rcpp::_["INFO"] = info,
    gt);

  std::vector < std::string > temps = tabsplit(header, stats[3]);
  temps[0].erase(0,1);
  df1.names() = temps;
  
  Rcpp::Rcout << "Rcpp::DataFrame created.\n";
  
  return df1;
}
Пример #29
0
pl_lettre_1 (struct coroutine *k, expr a0)
{
expr nx[MAX_NEW_CONS];
int pnx, i;
struct process_list *alt_process;
	pnx = 0;
	begin_decl ();
	decl_expr (&a0);
	for (i=0; i<MAX_NEW_CONS; i++)
		dle (nx[i]);
#ifdef TRACE
	printf ("\nlettre: a0 = "); print_expr (a0);
#endif
	if (alt (k, 1, 0))
	{
	/* clause */
		alt_process = getpl (k) -> alt;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
		unify (k, nx[pnx++] = cons (symbol("a"),
			0), a0);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
		unify (k, a0, nx[pnx++] = cons (symbol("a"),
			0));
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
	} else
	if (alt (k, 1, 0))
	{
	/* clause */
		alt_process = getpl (k) -> alt;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
		unify (k, nx[pnx++] = cons (symbol("b"),
			0), a0);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
		unify (k, a0, nx[pnx++] = cons (symbol("b"),
			0));
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
	} else
	if (alt (k, 1, 0))
	{
	/* clause */
		alt_process = getpl (k) -> alt;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
		unify (k, nx[pnx++] = cons (symbol("c"),
			0), a0);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
		unify (k, a0, nx[pnx++] = cons (symbol("c"),
			0));
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
	} else
	if (alt (k, 1, 0))
	{
	/* clause */
		alt_process = getpl (k) -> alt;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
		unify (k, nx[pnx++] = cons (symbol("d"),
			0), a0);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
		unify (k, a0, nx[pnx++] = cons (symbol("d"),
			0));
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
	} else
	if (alt (k, 1, 0))
	{
	/* clause */
		alt_process = getpl (k) -> alt;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
		unify (k, nx[pnx++] = cons (symbol("e"),
			0), a0);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
		unify (k, a0, nx[pnx++] = cons (symbol("e"),
			0));
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
	} else
	if (alt (k, 1, 0))
	{
	/* clause */
		alt_process = getpl (k) -> alt;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
		unify (k, nx[pnx++] = cons (symbol("f"),
			0), a0);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
		unify (k, a0, nx[pnx++] = cons (symbol("f"),
			0));
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
	} else
	if (alt (k, 1, 0))
	{
	/* clause */
		alt_process = getpl (k) -> alt;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
		unify (k, nx[pnx++] = cons (symbol("g"),
			0), a0);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
		unify (k, a0, nx[pnx++] = cons (symbol("g"),
			0));
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
	} else
	if (alt (k, 1, 0))
	{
	/* clause */
		alt_process = getpl (k) -> alt;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
		unify (k, nx[pnx++] = cons (symbol("h"),
			0), a0);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
		unify (k, a0, nx[pnx++] = cons (symbol("h"),
			0));
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
	} else
	if (alt (k, 1, 0))
	{
	/* clause */
		alt_process = getpl (k) -> alt;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
		unify (k, nx[pnx++] = cons (symbol("i"),
			0), a0);
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
		unify (k, a0, nx[pnx++] = cons (symbol("i"),
			0));
		for (i=0; i<pnx; i++)
			nx[i] = 0;
		pnx=0;
#ifdef TRACE
		printf ("\n\ta0 = "); print_expr (a0);
#endif
	} else
	end (k);
	free_expr ();
}
Пример #30
0
void
mousethread(void *v)
{
	Text *t, *argt;
	int but;
	uint q0, q1;
	Window *w;
	Plumbmsg *pm;
	Mouse m;
	char *act;
	enum { MResize, MMouse, MPlumb, MWarnings, NMALT };
	static Alt alts[NMALT+1];

	USED(v);
	threadsetname("mousethread");
	alts[MResize].c = mousectl->resizec;
	alts[MResize].v = nil;
	alts[MResize].op = CHANRCV;
	alts[MMouse].c = mousectl->c;
	alts[MMouse].v = &mousectl->m;
	alts[MMouse].op = CHANRCV;
	alts[MPlumb].c = cplumb;
	alts[MPlumb].v = &pm;
	alts[MPlumb].op = CHANRCV;
	alts[MWarnings].c = cwarn;
	alts[MWarnings].v = nil;
	alts[MWarnings].op = CHANRCV;
	if(cplumb == nil)
		alts[MPlumb].op = CHANNOP;
	alts[NMALT].op = CHANEND;

	for(;;){
		qlock(&row.lk);
		flushwarnings();
		qunlock(&row.lk);
		flushimage(display, 1);
		switch(alt(alts)){
		case MResize:
			if(getwindow(display, Refnone) < 0)
				error("attach to window");
			draw(screen, screen->r, display->white, nil, ZP);
			iconinit();
			scrlresize();
			rowresize(&row, screen->clipr);
			break;
		case MPlumb:
			if(strcmp(pm->type, "text") == 0){
				act = plumblookup(pm->attr, "action");
				if(act==nil || strcmp(act, "showfile")==0)
					plumblook(pm);
				else if(strcmp(act, "showdata")==0)
					plumbshow(pm);
			}
			plumbfree(pm);
			break;
		case MWarnings:
			break;
		case MMouse:
			/*
			 * Make a copy so decisions are consistent; mousectl changes
			 * underfoot.  Can't just receive into m because this introduces
			 * another race; see /sys/src/libdraw/mouse.c.
			 */
			m = mousectl->m;
			qlock(&row.lk);
			t = rowwhich(&row, m.xy);
			if(t!=mousetext && mousetext!=nil && mousetext->w!=nil){
				winlock(mousetext->w, 'M');
				mousetext->eq0 = ~0;
				wincommit(mousetext->w, mousetext);
				winunlock(mousetext->w);
			}
			mousetext = t;
			if(t == nil)
				goto Continue;
			w = t->w;
			if(t==nil || m.buttons==0)
				goto Continue;
			but = 0;
			if(m.buttons == 1)
				but = 1;
			else if(m.buttons == 2)
				but = 2;
			else if(m.buttons == 4)
				but = 3;
			barttext = t;
			if(t->what==Body && ptinrect(m.xy, t->scrollr)){
				if(but){
					if(swapscrollbuttons){
						if(but == 1)
							but = 3;
						else if(but == 3)
							but = 1;
					}
					winlock(w, 'M');
					t->eq0 = ~0;
					textscroll(t, but);
					winunlock(w);
				}
				goto Continue;
			}
			/* scroll buttons, wheels, etc. */
			if(w != nil && (m.buttons & (8|16))){
				if(m.buttons & 8)
					but = Kscrolloneup;
				else
					but = Kscrollonedown;
				winlock(w, 'M');
				t->eq0 = ~0;
				texttype(t, but);
				winunlock(w);
				goto Continue;
			}
			if(ptinrect(m.xy, t->scrollr)){
				if(but){
					if(t->what == Columntag)
						rowdragcol(&row, t->col, but);
					else if(t->what == Tag){
						coldragwin(t->col, t->w, but);
						if(t->w)
							barttext = &t->w->body;
					}
					if(t->col)
						activecol = t->col;
				}
				goto Continue;
			}
			if(m.buttons){
				if(w)
					winlock(w, 'M');
				t->eq0 = ~0;
				if(w)
					wincommit(w, t);
				else
					textcommit(t, TRUE);
				if(m.buttons & 1){
					textselect(t);
					if(w)
						winsettag(w);
					argtext = t;
					seltext = t;
					if(t->col)
						activecol = t->col;	/* button 1 only */
					if(t->w!=nil && t==&t->w->body)
						activewin = t->w;
				}else if(m.buttons & 2){
					if(textselect2(t, &q0, &q1, &argt))
						execute(t, q0, q1, FALSE, argt);
				}else if(m.buttons & 4){
					if(textselect3(t, &q0, &q1))
						look3(t, q0, q1, FALSE);
				}
				if(w)
					winunlock(w);
				goto Continue;
			}
    Continue:
			qunlock(&row.lk);
			break;
		}
	}
}