示例#1
0
文件: js0n.c 项目: denis-beurive/js0n
int js0n(const unsigned char *js, unsigned int len, unsigned short *out, unsigned int olen)
{
	unsigned short prev = 0, *oend;
	const unsigned char *cur, *end;
	int depth=0;
	int utf8_remain=0;
	static void *gostruct[] = 
	{
		[0 ... 255] = &&l_bad,
		['\t'] = &&l_loop, [' '] = &&l_loop, ['\r'] = &&l_loop, ['\n'] = &&l_loop,
		['"'] = &&l_qup,
		[':'] = &&l_loop,[','] = &&l_loop,
		['['] = &&l_up, [']'] = &&l_down, // tracking [] and {} individually would allow fuller validation but is really messy
		['{'] = &&l_up, ['}'] = &&l_down,
		['-'] = &&l_bare, [48 ... 57] = &&l_bare, // 0-9
		['t'] = &&l_bare, ['f'] = &&l_bare, ['n'] = &&l_bare // true, false, null
	};
	static void *gobare[] = 
	{
		[0 ... 31] = &&l_bad,
		[32 ... 126] = &&l_loop, // could be more pedantic/validation-checking
		['\t'] = &&l_unbare, [' '] = &&l_unbare, ['\r'] = &&l_unbare, ['\n'] = &&l_unbare,
		[','] = &&l_unbare, [']'] = &&l_unbare, ['}'] = &&l_unbare,
		[127 ... 255] = &&l_bad
	};
	static void *gostring[] = 
	{
		[0 ... 31] = &&l_bad, [127] = &&l_bad,
		[32 ... 126] = &&l_loop,
		['\\'] = &&l_esc, ['"'] = &&l_qdown,
		[128 ... 191] = &&l_bad,
		[192 ... 223] = &&l_utf8_2,
		[224 ... 239] = &&l_utf8_3,
		[240 ... 247] = &&l_utf8_4,
		[248 ... 255] = &&l_bad
	};
	static void *goutf8_continue[] =
	{
		[0 ... 127] = &&l_bad,
		[128 ... 191] = &&l_utf_continue,
		[192 ... 255] = &&l_bad
	};
	static void *goesc[] = 
	{
		[0 ... 255] = &&l_bad,
		['"'] = &&l_unesc, ['\\'] = &&l_unesc, ['/'] = &&l_unesc, ['b'] = &&l_unesc,
		['f'] = &&l_unesc, ['n'] = &&l_unesc, ['r'] = &&l_unesc, ['t'] = &&l_unesc, ['u'] = &&l_unesc
	};
	void **go = gostruct;
	
	for(cur=js,end=js+len,oend=out+olen; cur<end && out<oend; cur++)
	{
			goto *go[*cur];
			l_loop:;
	}
	
  if(out < oend) *out = 0;
	return depth; // 0 if successful full parse, >0 for incomplete data
	
	l_bad:
		return 1;
	
	l_up:
		PUSH(0);
		++depth;
		goto l_loop;

	l_down:
		--depth;
		CAP(0);
		goto l_loop;

	l_qup:
		PUSH(1);
		go=gostring;
		goto l_loop;

	l_qdown:
		CAP(-1);
		go=gostruct;
		goto l_loop;
		
	l_esc:
		go = goesc;
		goto l_loop;
		
	l_unesc:
		go = gostring;
		goto l_loop;

	l_bare:
		PUSH(0);
		go = gobare;
		goto l_loop;

	l_unbare:
		CAP(-1);
		go = gostruct;
		goto *go[*cur];

	l_utf8_2:
		go = goutf8_continue;
		utf8_remain = 1;
		goto l_loop;

	l_utf8_3:
		go = goutf8_continue;
		utf8_remain = 2;
		goto l_loop;

	l_utf8_4:
		go = goutf8_continue;
		utf8_remain = 3;
		goto l_loop;

	l_utf_continue:
		if (!--utf8_remain)
			go=gostring;
		goto l_loop;

}
示例#2
0
/*
 * __config_next --
 *	Get the next config item in the string without processing the value.
 */
static int
__config_next(WT_CONFIG *conf, WT_CONFIG_ITEM *key, WT_CONFIG_ITEM *value)
{
	WT_CONFIG_ITEM *out = key;
	int utf8_remain = 0;
	static const WT_CONFIG_ITEM true_value = {
		"", 0, 1, WT_CONFIG_ITEM_BOOL
	};

	key->len = 0;
	/* Keys with no value default to true. */
	*value = true_value;

	if (conf->go == NULL)
		conf->go = gostruct;

	while (conf->cur < conf->end) {
		switch (conf->go[(int)*conf->cur]) {
		case A_LOOP:
			break;

		case A_BAD:
			return (__config_err(
			    conf, "Unexpected character", EINVAL));

		case A_DOWN:
			--conf->depth;
			CAP(0);
			break;

		case A_UP:
			if (conf->top == -1)
				conf->top = 1;
			PUSH(0, WT_CONFIG_ITEM_STRUCT);
			++conf->depth;
			break;

		case A_VALUE:
			if (conf->depth == conf->top) {
				/*
				 * Special case: ':' is permitted in unquoted
				 * values.
				 */
				if (out == value && *conf->cur != ':')
					return (__config_err(conf,
					    "Value already complete", EINVAL));
				out = value;
			}
			break;

		case A_NEXT:
			/*
			 * If we're at the top level and we have a complete
			 * key (and optional value), we're done.
			 */
			if (conf->depth == conf->top && key->len > 0) {
				++conf->cur;
				return (0);
			} else
				break;

		case A_QDOWN:
			CAP(-1);
			conf->go = gostruct;
			break;

		case A_QUP:
			PUSH(1, WT_CONFIG_ITEM_STRING);
			conf->go = gostring;
			break;

		case A_ESC:
			conf->go = goesc;
			break;

		case A_UNESC:
			conf->go = gostring;
			break;

		case A_BARE:
			PUSH(0, WT_CONFIG_ITEM_ID);
			conf->go = gobare;
			break;

		case A_NUMBARE:
			PUSH(0, WT_CONFIG_ITEM_NUM);
			conf->go = gobare;
			break;

		case A_UNBARE:
			CAP(-1);
			conf->go = gostruct;
			continue;

		case A_UTF8_2:
			conf->go = goutf8_continue;
			utf8_remain = 1;
			break;

		case A_UTF8_3:
			conf->go = goutf8_continue;
			utf8_remain = 2;
			break;

		case A_UTF8_4:
			conf->go = goutf8_continue;
			utf8_remain = 3;
			break;

		case A_UTF_CONTINUE:
			if (!--utf8_remain)
				conf->go = gostring;
			break;
		}

		conf->cur++;
	}

	/* Might have a trailing key/value without a closing brace */
	if (conf->go == gobare) {
		CAP(-1);
		conf->go = gostruct;
	}

	/* Did we find something? */
	if (conf->depth <= conf->top && key->len > 0)
		return (0);

	/* We're either at the end of the string or we failed to parse. */
	if (conf->depth == 0)
		return (WT_NOTFOUND);

	return (__config_err(conf,
	    "Closing brackets missing from config string", EINVAL));
}
示例#3
0
文件: mon.c 项目: ChrisAubuchon/bard
static monster_t *convertMonster(b2mon_t *inMonster)
{
	monster_t	*m;
	int		i;

	for (i = 0; i < 16; i++) {
		if (inMonster->name[i] & 0x80)
			inMonster->name[i] ^= 0x80;
		if ((inMonster->name[i] == '/') || (inMonster->name[i] == '\\'))
			inMonster->name[i] = '^';
		if (inMonster->name[i] == 0x7f)
			inMonster->name[i] = '\0';
	}

	if (inMonster->name[0] == '\0')
		return NULL;
	
	m = monster_new();

	m->singular	= prepName(inMonster->name, 0);
	m->plural	= prepName(inMonster->name, 1);
	m->picture	= getPicMacro(inMonster->picindex);
	m->reward	= ((inMonster->numattacks + 1) * inMonster->basemelee) << 7;

	m->hpRndNdice	= 1;
	m->hpRndDie	= inMonster->hpRnd;
	m->hpBase	= inMonster->hpBase;

	m->groupSize	= (inMonster->maxgrp << 1) + 1;
	m->distance	= (inMonster->flags >> 4) * 10;
	m->advSpeed	= inMonster->advancespeed * 10;
	m->willAdvance	= willAdvance(inMonster);
	m->baseAC	= 10 - inMonster->baseac2hit;

	m->breathSaveLo = inMonster->basemelee >> 3;
	m->breathSaveHi = (inMonster->basemelee >> 3) + 8;
	m->spellSaveLo	= m->breathSaveLo;
	m->spellSaveHi	= m->breathSaveHi;
	m->toHitLo	= inMonster->baseac2hit;
	m->toHitHi	= inMonster->baseac2hit + 3;
	m->pronoun	= (inMonster->flags & 1) ? 0 : 1;

	m->numAttacks	= inMonster->numattacks + 1;

#define CAP(x,y)  ((x) > (y)) ? (y) : (x)
	m->priorityLo	= CAP(((inMonster->basemelee << 2) | 1), 0xff);
	m->priorityLo	= CAP((((inMonster->basemelee << 2) | 1) + 31), 0xff);
#undef CAP

	switch (inMonster->picindex) {
	case 33:
	case 53:
	case 57:
	case 60:
		m->repel.spellcaster = 1;
		break;
	case 34:
	case 35:
	case 37:
	case 40:
	case 41:
	case 54:
		m->repel.evil = 1;
		break;
	}

	for (i = 0; i < 4; i++) {
		monsterAttack_t	*ma = NULL;
		uint8_t		att;

		att = inMonster->attTypes[i];

		if (att == 0) {
			bteAttack_t	*ba;

			ma = monsterAttack_new(ACT_MELEE);
			ma->action = btAction_new(FUNC_NONE, EFFECT_ATTACK);
			ba = btEffect_attack(ma->action->effect);

			ba->dieval	= 4;
			ba->ndice	= inMonster->basemelee;
			ba->spAttack	= inMonster->meleeatttype & 0x0f;
			if (ba->spAttack > 9)
				ba->spAttack = 0;
			ba->attype	= 8;
			ba->meleeString	= ((inMonster->meleeatttype & 0xf0) >> 4) + 1;
		} else if (att < 79) {
示例#4
0
bool loadOBJ(Surface *sur, const char *fileName, float boxSize){
  //  init the model
  sur->vertices.setSize(0);
  sur->triangles.setSize(0);

  //  open the file
  FILE *f = fopen(fileName, "r");
  if (!f)
    return false;

  //  read the file and process each line
  char buffer[1024];
  while (!feof(f) && fgets(buffer, 1023, f)){
    //  get length
    int len = strlen(buffer);

    //  trim off any leading spaces
    int i;
    for (i = 0; i < len; i++){
      if (buffer[i] != ' ' && buffer[i] != '\t')
        break;
      }

    if (CAP(buffer[i]) == 'V' && buffer[i+1] == ' '){
      //  do new VERTEX
      float x, y, z;
      sscanf(buffer+i+1, "%f %f %f", &x, &y, &z);
      
      Surface::Point *p = &sur->vertices.addItem();
      p->p.x = x;
      p->p.y = y;
      p->p.z = z;
      }
    else if (CAP(buffer[i]) == 'F'){
      //  do new FACE
      Surface::Triangle *tri = &sur->triangles.addItem();

      for (int j = 0; j < 3; j++){
        //  read token
        const char *token = strtok(j == 0 ? (buffer+i+1) : NULL, " ");

        //  decode token
        int a = 0, b = 0, c = 0;
        if (token == NULL ||
            (sscanf(token, "%d/%d/%d", &a, &b, &c) != 3  &&
             sscanf(token, "%d//%d", &a, &c) != 2)){
          fclose(f);
          return false;
          }

        tri->v[j] = a-1;
        tri->f[j] = -1;      //  neighbouring face not given in OBJ
        }

      //  setup triangle normal
      Vector3D V1, V2;
      V1.difference(sur->vertices.index(tri->v[1]).p, sur->vertices.index(tri->v[0]).p);
      V2.difference(sur->vertices.index(tri->v[2]).p, sur->vertices.index(tri->v[0]).p);
      tri->n.cross(V1,V2);
      tri->n.norm();
      }
    }

  //  setup bounding box
  sur->setupBoundingBox();

  //  scale the box :)
  if (boxSize > 0)
    sur->fitIntoBox(boxSize);

  //  work out vertex normals
  sur->setupNormals(0, sur->vertices.getSize(), 0, sur->triangles.getSize());

  //  connection to other triangles
  sur->setupAdjacent(0, sur->triangles.getSize());

  //  fix neighbours
  sur->stitchTriangles();

  fclose(f);
  return true;
}
void AccountModifyDlg::init() 
{
	//connect(pa->psi(), SIGNAL(pgpToggled(bool)), SLOT(pgpToggled(bool)));
	if (pa)
		pa->dialogRegister(this);

	setWindowTitle(CAP(windowTitle()));
#ifndef Q_WS_MAC
	setWindowIcon(IconsetFactory::icon("psi/account").icon());
#endif

	le_pass->setEnabled(true);
	le_host->setEnabled(false);
	lb_host->setEnabled(false);
	le_port->setEnabled(false);
	lb_port->setEnabled(false);

	// FIXME: Temporarily removing security level settings
	ck_req_mutual->hide();
	cb_security_level->hide();
	lb_security_level->hide();

	connect(ck_host, SIGNAL(toggled(bool)), SLOT(hostToggled(bool)));
	connect(pb_key, SIGNAL(clicked()), SLOT(chooseKey()));
	connect(pb_keyclear, SIGNAL(clicked()), SLOT(clearKey()));
	connect(buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), SLOT(save()));
	connect(ck_automatic_resource, SIGNAL(toggled(bool)), le_resource, SLOT(setDisabled(bool)));
	connect(ck_automatic_resource, SIGNAL(toggled(bool)), lb_resource, SLOT(setDisabled(bool)));

	gb_pgp->setEnabled(false);

	if (pa) {
		connect(pb_vcard, SIGNAL(clicked()), SLOT(detailsVCard()));
		connect(pb_changepw, SIGNAL(clicked()), SLOT(detailsChangePW()));
	}
	else {
		pb_vcard->setEnabled(false);
		pb_changepw->setEnabled(false);
	}

	// Hide the name if necessary
	le_name->setText(acc.name);
	le_jid->setText(JIDUtil::accountToString(acc.jid,false));

	cb_ssl->addItem(tr("Always"),UserAccount::SSL_Yes);
	cb_ssl->addItem(tr("When available"),UserAccount::SSL_Auto);
	cb_ssl->addItem(tr("Never"), UserAccount::SSL_No);
	cb_ssl->addItem(tr("Legacy SSL"), UserAccount::SSL_Legacy);
	cb_ssl->setCurrentIndex(cb_ssl->findData(acc.ssl));
	connect(cb_ssl, SIGNAL(activated(int)), SLOT(sslActivated(int)));
	
	cb_plain->addItem(tr("Always"),ClientStream::AllowPlain);
	cb_plain->addItem(tr("Over encrypted connection"), ClientStream::AllowPlainOverTLS);
	cb_plain->addItem(tr("Never"), ClientStream::NoAllowPlain);
	cb_plain->setCurrentIndex(cb_plain->findData(acc.allow_plain));
	
	if (acc.opt_pass)
		le_pass->setText(acc.pass);

	ck_host->setChecked(acc.opt_host);
	le_host->setText(acc.host);
	le_port->setText(QString::number(acc.port));
	ck_req_mutual->setChecked(acc.req_mutual_auth);
	ck_legacy_ssl_probe->setChecked(acc.legacy_ssl_probe);

	ck_automatic_resource->setChecked(acc.opt_automatic_resource);
	le_resource->setText(acc.resource);
	le_priority->setText(QString::number(acc.priority));

	connect(ck_custom_auth,SIGNAL(toggled(bool)), lb_authid, SLOT(setEnabled(bool)));
	connect(ck_custom_auth,SIGNAL(toggled(bool)), le_authid, SLOT(setEnabled(bool)));
	connect(ck_custom_auth,SIGNAL(toggled(bool)), lb_realm, SLOT(setEnabled(bool)));
	connect(ck_custom_auth,SIGNAL(toggled(bool)), le_realm, SLOT(setEnabled(bool)));
	ck_custom_auth->setChecked(acc.customAuth);
	le_authid->setText(acc.authid);
	le_realm->setText(acc.realm);
		
	ck_compress->setChecked(acc.opt_compress);
	ck_auto->setChecked(acc.opt_auto);
	ck_reconn->setChecked(acc.opt_reconn);
	ck_connectAfterSleep->setChecked(acc.opt_connectAfterSleep);
	ck_log->setChecked(acc.opt_log);
	ck_keepAlive->setChecked(acc.opt_keepAlive);
	le_dtProxy->setText(acc.dtProxy.full());
	le_stunHost->setText(acc.stunHost);
	le_stunPort->setText(QString::number(acc.stunPort));
	le_stunUser->setText(acc.stunUser);
	le_stunPass->setText(acc.stunPass);

	key = acc.pgpSecretKey;
	updateUserID();
#ifdef HAVE_PGPUTIL
	PGPUtil::instance().clearPGPAvailableCache();
	if(PGPUtil::instance().pgpAvailable()) {
		gb_pgp->setEnabled(true);
	}
#else
	gb_pgp->setEnabled(false);
#endif

	pc = psi->proxy()->createProxyChooser(tab_connection);
	replaceWidget(lb_proxychooser, pc);
	pc->setCurrentItem(acc.proxyID);

	// Security level
	cb_security_level->addItem(tr("None"),QCA::SL_None);
	cb_security_level->addItem(tr("Integrity"),QCA::SL_Integrity);
	cb_security_level->addItem(tr("Baseline"),QCA::SL_Baseline);
	cb_security_level->addItem(tr("High"),QCA::SL_High);
	cb_security_level->addItem(tr("Highest"),QCA::SL_Highest);
	cb_security_level->setCurrentIndex(cb_security_level->findData(acc.security_level));

	// Name
	if(le_name->text().isEmpty())
		le_name->setFocus();
	else if(le_jid->text().isEmpty())
		le_jid->setFocus();
	else
		buttonBox->button(QDialogButtonBox::Save)->setFocus();

	// Privacy
	privacyInitialized = false;
	lb_customPrivacy->hide();
	privacyBlockedModel.setSourceModel(&privacyModel);
	lv_blocked->setModel(&privacyBlockedModel);
	if (pa) {
		connect(pa->privacyManager(),SIGNAL(defaultListAvailable(const PrivacyList&)),SLOT(updateBlockedContacts(const PrivacyList&)));
		connect(pa->privacyManager(),SIGNAL(defaultListError()),SLOT(getDefaultList_error()));
		connect(pa->privacyManager(),SIGNAL(changeList_error()),SLOT(changeList_error()));
		connect(pa,SIGNAL(updatedActivity()),SLOT(updatePrivacyTab()));
	}
	connect(tab_main,SIGNAL(currentChanged(int)),SLOT(tabChanged(int)));
	connect(pb_privacy, SIGNAL(clicked()), SLOT(privacyClicked()));
	connect(pb_removeBlock, SIGNAL(clicked()), SLOT(removeBlockClicked()));
	connect(pb_addBlock, SIGNAL(clicked()), SLOT(addBlockClicked()));
	// FIXME: Temporarily disabling blocking
	pb_removeBlock->hide();
	pb_addBlock->hide();

	// QWhatsThis helpers
	cb_plain->setWhatsThis(
		tr("Normally, Psi logs in using the <i>digest</i> authentication "
		"method.  Check this box to force a plain text login "
		"to the Jabber server. Use this option only if you have "
		"problems connecting with the normal login procedure, as it "
		"makes your connection potentially vulnerable to "
		"attacks."));
	ck_auto->setWhatsThis(
		tr("Automatically login to this account on Psi startup.  Useful if "
		"you have Psi automatically launched when an Internet "
		"connection is detected."));
	ck_connectAfterSleep->setWhatsThis(
		tr("Makes Psi try to connect when the computer resumes "
		"after a sleep."));
	ck_reconn->setWhatsThis(
		tr("Makes Psi try to reconnect if the connection was broken.  "
		"Useful, if you have an unstable connection and have to "
		"reconnect often."));
	ck_log->setWhatsThis(
		tr("Keep a log of message history.  Disable this "
		"option if you want to conserve disk space or if you need "
		"maximum security."));
	ck_keepAlive->setWhatsThis(
		tr("Sends so called \"Keep-alive\" packets periodically.  "
		"It is useful if your connection is set to be "
		"automatically disconnected after a certain period of "
		"inactivity (for example, by your ISP) and you want to keep it "
		"up all the time."));
	cb_ssl->setWhatsThis(
		tr("Check this option to use an encrypted SSL connection to "
		"the Jabber server.  You may use this option if your "
		"server supports it and if you have the necessary QCA-OpenSSL "
		"plugin installed.  For more information, check the "
		"Psi homepage."));
	ck_compress->setWhatsThis(
		tr("Check this option to use a compressed connection to "
		"the Jabber server, if the server supports it."));
	ck_host->setWhatsThis(
		tr("Use this option for manual configuration of your Jabber host "
		"if it is not the same as the host you are connecting to.  This option is mostly useful "
		"if you have some sort of proxy route on your "
		"local machine (i.e. you connect to localhost), but your "
		"account is registered on an external server."));
	le_resource->setWhatsThis(
		tr("You can have multiple clients connected to the Jabber server "
		"with your single account.  Each login is distinguished by a \"resource\" "
		"name, which you can specify in this field."));
	ck_custom_auth->setWhatsThis(
		tr("This option sets the user (and realm) you want to "
			"authenticate as. This overrides the Jabber ID you are logging in "
			"as."));
	le_priority->setWhatsThis(
		tr("<p>You can have multiple clients connected to the Jabber "
		"server with your single account.  In such a situation, "
		"the client with the highest priority (that is specified in "
		"this field) will be the one that will receive "
		"all incoming events.</p>"
		"<p>For example, if you have a permanent connection "
		"to the Internet at your work location, and have a dial-up at home, "
		"you can have your Jabber client permanently running at work "
		"with a low priority, and you can still use the same account "
		"from home, using a client with higher priority to "
		"temporary \"disable\" the lower priority client at work.</p>"));

	// Hiding of UI components
	if ((!pa && acc.name.isEmpty()) || PsiOptions::instance()->getOption("options.ui.account.single").toBool()) {
		le_name->hide();
		lb_name->hide();
	}
	
	if (!PsiOptions::instance()->getOption("options.account.domain").toString().isEmpty()) {
		lb_example->hide();
		lb_jid->setText(tr("Username:"******"options.pgp.enable").toBool()) {
		gb_pgp->hide();
	}
	
	if (!PsiOptions::instance()->getOption("options.ui.account.privacy.show").toBool()) 
		tab_main->removeTab(tab_main->indexOf(tab_privacy));
	
	if (!PsiOptions::instance()->getOption("options.ui.account.proxy.show").toBool()) {
		lb_proxy->hide();
		pc->hide();
	}

	if (!PsiOptions::instance()->getOption("options.ui.account.manual-host").toBool()) {
		ck_host->hide();
		lb_host->hide();
		le_host->hide();
		lb_port->hide();
		le_port->hide();
	}
	
	if (!PsiOptions::instance()->getOption("options.ui.account.keepalive").toBool()) 
		ck_keepAlive->hide();
	
	if (!PsiOptions::instance()->getOption("options.ui.account.legacy-ssl-probe").toBool()) 
		ck_legacy_ssl_probe->hide();

	if (!PsiOptions::instance()->getOption("options.ui.account.security.show").toBool()) {
		lb_plain->hide();
		cb_plain->hide();
		ck_req_mutual->hide();
		lb_security_level->hide();
		cb_security_level->hide();
	}

	if (!PsiOptions::instance()->getOption("options.ui.account.security.show").toBool() && !PsiOptions::instance()->getOption("options.ui.account.legacy-ssl-probe").toBool() && !PsiOptions::instance()->getOption("options.ui.account.keepalive").toBool() && !PsiOptions::instance()->getOption("options.ui.account.manual-host").toBool() && !PsiOptions::instance()->getOption("options.ui.account.proxy.show").toBool()) {
		tab_main->removeTab(tab_main->indexOf(tab_connection));
	}
	
	if (!PsiOptions::instance()->getOption("options.ui.account.resource").toBool()) {
		ck_automatic_resource->hide();
		lb_resource->hide();
		le_resource->hide();
	}
	
	if (!PsiOptions::instance()->getOption("options.ui.account.custom-authid").toBool()) {
		ck_custom_auth->hide();
		lb_authid->hide();
		le_authid->hide();
		lb_realm->hide();
		le_realm->hide();
	}
	
	if (!PsiOptions::instance()->getOption("options.ui.account.priority").toBool()) {
		lb_priority->hide();
		le_priority->hide();
	}
	
	if (!PsiOptions::instance()->getOption("options.ui.account.data-proxy").toBool()) {
		lb_dtProxy->hide();
		le_dtProxy->hide();
	}

	if (!PsiOptions::instance()->getOption("options.ui.account.resource").toBool() && !PsiOptions::instance()->getOption("options.ui.account.priority").toBool() && !PsiOptions::instance()->getOption("options.ui.account.data-proxy").toBool()) {
		tab_main->removeTab(tab_main->indexOf(tab_misc));
	}
	
	resize(minimumSizeHint());
}
示例#6
0
 inline int __phi() { return CEF(CAND(CAP(A==1),CEG(CAP(R!=1)))); }
示例#7
0
文件: optionsdlg.cpp 项目: Vitozz/psi
OptionsDlg::OptionsDlg(PsiCon *psi, QWidget *parent) :
	OptionsDlgBase(psi, parent)
{
	setWindowTitle(CAP(windowTitle()));
	setWindowIcon(IconsetFactory::icon("psi/options").icon());

	QList<OptionsTab*> tabs;

	// tabs - base
	/*tabs.append( new OptionsTabGeneral(this) );
	//tabs.append( new OptionsTabBase(this, "general",  "", "psi/logo_16",	tr("General"),		tr("General preferences list")) );
	tabs.append( new OptionsTabEvents(this) );
	//tabs.append( new OptionsTabBase(this, "events",   "", "psi/system",	tr("Events"),		tr("Change the events behaviour")) );
	tabs.append( new OptionsTabPresence(this) );
	//tabs.append( new OptionsTabBase(this, "presence", "", "status/online",	tr("Presence"),		tr("Presence configuration")) );
	tabs.append( new OptionsTabLookFeel(this) );
	tabs.append( new OptionsTabIconset(this) );
	//tabs.append( new OptionsTabBase(this, "lookfeel", "", "psi/smile",	tr("Look and Feel"),	tr("Change the Psi's Look and Feel")) );
	tabs.append( new OptionsTabSound(this) );
	//tabs.append( new OptionsTabBase(this, "sound",    "", "psi/playSounds",	tr("Sound"),		tr("Configure how Psi sounds")) );
	*/

	OptionsTabApplication* applicationTab = new OptionsTabApplication(this);
	applicationTab->setHaveAutoUpdater(psi->haveAutoUpdater());
	tabs.append( applicationTab );
	tabs.append( new OptionsTabRoster(this) );
	tabs.append( new OptionsTabChat(this) );
	tabs.append( new OptionsTabEvents(this) );
	tabs.append( new OptionsTabPopups(this) );
	tabs.append( new OptionsTabStatus(this) );
	tabs.append( new OptionsTabAppearance(this) );
	//tabs.append( new OptionsTabIconsetSystem(this) );
	//tabs.append( new OptionsTabIconsetRoster(this) );
	//tabs.append( new OptionsTabIconsetEmoticons(this) );
	tabs.append( new OptionsTabGroupchat(this) );
	tabs.append( new OptionsTabSound(this) );
	if(AvCallManager::isSupported())
		tabs.append( new OptionsTabAvCall(this) );
	tabs.append( new OptionsTabToolbars(this) );
#ifdef PSI_PLUGINS
	tabs.append( new OptionsTabPlugins(this) );
#endif
	tabs.append( new OptionsTabShortcuts(this) );
	tabs.append( new OptionsTabAdvanced(this) );
	tabs.append( new OptionsTabTree(this) );

	// tabs - general
	/*tabs.append( new OptionsTabGeneralRoster(this) );
	tabs.append( new OptionsTabGeneralDocking(this) );
	tabs.append( new OptionsTabGeneralNotifications(this) );
	tabs.append( new OptionsTabGeneralGroupchat(this) );
	tabs.append( new OptionsTabGeneralMisc(this) );*/

	// tabs - events
	/*tabs.append( new OptionsTabEventsReceive(this) );
	tabs.append( new OptionsTabEventsMisc(this) );*/

	// tabs - presence
	/*tabs.append( new OptionsTabPresenceAuto(this) );
	tabs.append( new OptionsTabPresencePresets(this) );
	tabs.append( new OptionsTabPresenceMisc(this) );*/

	// tabs - look and feel
	/*tabs.append( new OptionsTabLookFeelColors(this) );
	tabs.append( new OptionsTabLookFeelFonts(this) );
	tabs.append( new OptionsTabIconsetSystem(this) );
	tabs.append( new OptionsTabIconsetEmoticons(this) );
	tabs.append( new OptionsTabIconsetRoster(this) );
	tabs.append( new OptionsTabLookFeelToolbars(this) );
	tabs.append( new OptionsTabLookFeelMisc(this) );*/

	// tabs - sound
	/*tabs.append( new OptionsTabSoundPrefs(this) );
	tabs.append( new OptionsTabSoundEvents(this) );*/

	setTabs(tabs);

	psi->dialogRegister(this);
	resize(640, 480);

	openTab( "application" );
}
示例#8
0
WbDlg::WbDlg(SxeSession* session, PsiAccount* pa) {
	groupChat_ = session->groupChat();
	pending_ = 0;
	keepOpen_ = false;
	allowEdits_ = true;

	selfDestruct_ = 0;
	setAttribute(Qt::WA_DeleteOnClose, false); // we want deferred endSession call and delete from manager

	setWindowTitle(CAP(tr("Whiteboard (%1)").arg(pa->jid().bare())));
	QVBoxLayout *vb1 = new QVBoxLayout(this);

	// first row
	le_jid_ = new QLineEdit(this);
	le_jid_->setReadOnly(true);
	le_jid_->setFocusPolicy(Qt::NoFocus);
	le_jid_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
	lb_ident_ = new AccountLabel(this);
	lb_ident_->setAccount(pa);
	lb_ident_->setShowJid(false);
	lb_ident_->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
	QHBoxLayout *hb1 = new QHBoxLayout();
	hb1->addWidget(le_jid_);
	hb1->addWidget(lb_ident_);
	vb1->addLayout(hb1);

	// mid area
	wbWidget_ = new WbWidget(session, this);
	wbWidget_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
	vb1->addWidget(wbWidget_);

	// Bottom (tool) area
	act_save_ = new IconAction(tr("Save session"), "psi/saveBoard", tr("Save the contents of the whiteboard"), 0, this );
	act_geometry_ = new IconAction(tr("Change the geometry"), "psi/whiteboard", tr("Change the geometry"), 0, this );
	act_clear_ = new IconAction(tr("End session"), "psi/clearChat", tr("Clear the whiteboard"), 0, this );
	act_end_ = new IconAction(tr("End session"), "psi/closetab", tr("End session"), 0, this );

	// Black is the default color
	QPixmap pixmap(16, 16);
	pixmap.fill(QColor(Qt::black));
	act_color_ = new QAction(QIcon(pixmap), tr("Stroke color"), this);
	pixmap.fill(QColor(Qt::lightGray));
	act_fill_ = new IconAction(tr("Fill color"), "psi/select", tr("Fill color"),0, this, 0, true);
	act_fill_->setIcon(QIcon(pixmap));
	act_fill_->setChecked(false);

	act_widths_ = new IconAction(tr("Stroke width" ), "psi/drawPaths", tr("Stroke width"), 0, this );
	act_modes_ = new IconAction(tr("Edit mode" ), "psi/select", tr("Edit mode"), 0, this );
	group_widths_ = new QActionGroup(this);
	group_modes_ = new QActionGroup(this);

	connect(act_color_, SIGNAL(triggered()), SLOT(setStrokeColor()));
	connect(act_fill_, SIGNAL(triggered(bool)), SLOT(setFillColor(bool)));
	connect(group_widths_, SIGNAL(triggered(QAction *)), SLOT(setStrokeWidth(QAction *)));
	connect(group_modes_, SIGNAL(triggered(QAction *)), SLOT(setMode(QAction *)));
	connect(act_save_, SIGNAL(triggered()), SLOT(save()));
	connect(act_geometry_, SIGNAL(triggered()), SLOT(setGeometry()));
	connect(act_clear_, SIGNAL(triggered()), wbWidget_, SLOT(clear()));
	connect(act_end_, SIGNAL(triggered()), SLOT(endSession()));

	pixmap = QPixmap(2, 2);
	pixmap.fill(QColor(Qt::black));
	QAction* widthaction = new QAction(QIcon(pixmap), tr("Thin stroke"), group_widths_);
	widthaction->setData(QVariant(1));
	widthaction->setCheckable(true);
	widthaction->trigger();
	pixmap = QPixmap(6, 6);
	pixmap.fill(QColor(Qt::black));
	widthaction = new QAction(QIcon(pixmap), tr("Medium stroke"), group_widths_);
	widthaction->setData(QVariant(3));
	widthaction->setCheckable(true);
	pixmap = QPixmap(12, 12);
	pixmap.fill(QColor(Qt::black));
	widthaction = new QAction(QIcon(pixmap), tr("Thick stroke"), group_widths_);
	widthaction->setData(QVariant(6));
	widthaction->setCheckable(true);

	IconAction* action;
	action = new IconAction(tr("Select"), "psi/select", tr("Select"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::Select));
	action->setCheckable(true);
	action = new IconAction(tr( "Translate"), "psi/translate", tr("Translate"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::Translate));
	action->setCheckable(true);
	action = new IconAction(tr( "Rotate"), "psi/rotate", tr("Rotate"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::Rotate));
	action->setCheckable(true);
	action = new IconAction(tr( "Scale"), "psi/scale", tr("Scale"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::Scale));
	action->setCheckable(true);
	action = new IconAction(tr( "Erase"), "psi/erase", tr("Erase"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::Erase));
	action->setCheckable(true);
	QAction *separator = new QAction(group_modes_);
	separator->setSeparator(true);
	action = new IconAction(tr( "Scroll view"), "psi/scroll", tr("Scroll"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::Scroll));
	action->setCheckable(true);
	separator = new QAction(group_modes_);
	separator->setSeparator(true);
	action = new IconAction(tr( "Draw paths"), "psi/drawPaths", tr("Draw paths"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::DrawPath));
	action->setCheckable(true);
	action->trigger();
	// action = new IconAction(tr( "Draw lines"), "psi/drawLines", tr("Draw lines"), 0, group_modes_ );
	// action->setData(QVariant(WbWidget::DrawLine));
	// action->setCheckable(true);
	// action = new IconAction(tr( "Draw ellipses"), "psi/drawEllipses", tr("Draw ellipses"), 0, group_modes_ );
	// action->setData(QVariant(WbWidget::DrawEllipse));
	// action->setCheckable(true);
	// action = new IconAction(tr( "Draw circles"), "psi/drawCircles", tr("Draw circles"), 0, group_modes_ );
	// action->setData(QVariant(WbWidget::DrawCircle));
	// action->setCheckable(true);
	// action = new IconAction(tr( "Draw rectangles"), "psi/drawRectangles", tr("Draw rectangles"), 0, group_modes_ );
	// action->setData(QVariant(WbWidget::DrawRectangle));
	// action->setCheckable(true);
	// 	action = new IconAction(tr( "Add text"), "psi/addText", tr("Add text"), 0, group_modes_ );
	// 	action->setData(QVariant(WbWidget::DrawText));
	// 	action->setCheckable(true);
	action = new IconAction(tr( "Add images"), "psi/addImage", tr("Add images"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::DrawImage));
	action->setCheckable(true);

	menu_widths_ = new QMenu(this);
	menu_widths_->addActions(group_widths_->actions());
	act_widths_->setMenu(menu_widths_);

	menu_modes_ = new QMenu(this);
	menu_modes_->addActions(group_modes_->actions());
	act_modes_->setMenu(menu_modes_);

	toolbar_ = new QToolBar(tr("Whiteboard toolbar"), this);
	toolbar_->setIconSize(QSize(16,16));
	toolbar_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
	toolbar_->addAction(act_end_);
	toolbar_->addAction(act_clear_);
	toolbar_->addAction(act_save_);
	toolbar_->addAction(act_geometry_);
	toolbar_->addWidget(new StretchWidget(this));
	toolbar_->addAction(act_fill_);
	toolbar_->addAction(act_color_);
	QToolButton *bw = new QToolButton;
	bw->setIcon(IconsetFactory::icon("psi/drawPaths").icon());
	bw->setMenu(menu_widths_);
	bw->setPopupMode(QToolButton::InstantPopup);
	toolbar_->addWidget(bw);
	QToolButton *bm = new QToolButton;
	bm->setIcon(IconsetFactory::icon("psi/select").icon());
	bm->setMenu(menu_modes_);
	bm->setPopupMode(QToolButton::InstantPopup);
	toolbar_->addWidget(bm);
	vb1->addWidget(toolbar_);

	// Context menu
	pm_settings_ = new QMenu(this);
	connect(pm_settings_, SIGNAL(aboutToShow()), SLOT(buildMenu()));

	X11WM_CLASS("whiteboard");

	// set the Jid -> le_jid.
	le_jid_->setText(QString("%1 (session: %2)").arg(session->target().full()).arg(session->session()));
	le_jid_->setCursorPosition(0);
	le_jid_->setToolTip(session->target().full());

	// update the widget icon
#ifndef Q_OS_MAC
	setWindowIcon(IconsetFactory::icon("psi/whiteboard").icon());
#endif
	
	setWindowOpacity(double(qMax(MINIMUM_OPACITY, PsiOptions::instance()->getOption("options.ui.chat.opacity").toInt())) / 100);

	setGeometryOptionPath(geometryOption);
}
/* prove that either IoCompleteRequest is called, 
   or a value other than STATUS_SUCCESS is returned. */
int __phi() { return COR(
			 CAF(CAP(phi_io_compl == 1)),
			 CAF(CAP(phi_nSUC_ret  == 1))); }
示例#10
0
void show_char_to_char(struct char_data *i, struct char_data *ch, int mode)
{
    char buffer[MAX_STRING_LENGTH];
    int j, found, percent;
    struct obj_data *tmp_obj;

    if (mode == 0) {

        if (IS_AFFECTED(i, AFF_HIDE) || !CAN_SEE(ch,i)) {
            if (IS_AFFECTED(ch, AFF_SENSE_LIFE))
                send_to_char("You sense a hidden life form in the room.\n\r", ch);
            return;
        }

        if (!(i->player.long_descr)||(GET_POS(i) != i->specials.default_pos)) {
            /* A player char or a mobile without long descr, or not in default pos. */
            if (!IS_NPC(i)) {
                strcpy(buffer,GET_NAME(i));
                strcat(buffer," ");
                strcat(buffer,GET_TITLE(i));
            } else {
                strcpy(buffer, i->player.short_descr);
                CAP(buffer);
            }

            if ( IS_AFFECTED(i,AFF_INVISIBLE))
                strcat(buffer," (invisible)");

            switch(GET_POS(i)) {
            case POSITION_STUNNED  :
                strcat(buffer," is lying here, stunned.");
                break;
            case POSITION_INCAP    :
                strcat(buffer," is lying here, incapacitated.");
                break;
            case POSITION_MORTALLYW:
                strcat(buffer," is lying here, mortally wounded.");
                break;
            case POSITION_DEAD     :
                strcat(buffer," is lying here, dead.");
                break;
            case POSITION_STANDING :
                strcat(buffer," is standing here.");
                break;
            case POSITION_SITTING  :
                strcat(buffer," is sitting here.");
                break;
            case POSITION_RESTING  :
                strcat(buffer," is resting here.");
                break;
            case POSITION_SLEEPING :
                strcat(buffer," is sleeping here.");
                break;
            case POSITION_FIGHTING :
                if (i->specials.fighting) {

                    strcat(buffer," is here, fighting ");
                    if (i->specials.fighting == ch)
                        strcat(buffer," YOU!");
                    else {
                        if (i->in_room == i->specials.fighting->in_room)
                            if (IS_NPC(i->specials.fighting))
                                strcat(buffer, i->specials.fighting->player.short_descr);
                            else
                                strcat(buffer, GET_NAME(i->specials.fighting));
                        else
                            strcat(buffer, "someone who has already left.");
                    }
                } else /* NIL fighting pointer */
                    strcat(buffer," is here struggling with thin air.");
                break;
            default :
                strcat(buffer," is floating here.");
                break;
            }
            if (IS_AFFECTED(ch, AFF_DETECT_EVIL)) {
                if (IS_EVIL(i))
                    strcat(buffer, " (Red Aura)");
            }

            strcat(buffer,"\n\r");
            send_to_char(buffer, ch);
        }
        else  /* npc with long */
        {
            if (IS_AFFECTED(i,AFF_INVISIBLE))
                strcpy(buffer,"*");
            else
                *buffer = '\0';

            if (IS_AFFECTED(ch, AFF_DETECT_EVIL)) {
                if (IS_EVIL(i))
                    strcat(buffer, " (Red Aura)");
            }

            strcat(buffer, i->player.long_descr);

            send_to_char(buffer, ch);
        }

        if (IS_AFFECTED(i,AFF_SANCTUARY))
            act("$n glows with a bright light!", FALSE, i, 0, ch, TO_VICT);

    } else if (mode == 1) {

        if (i->player.description)
            send_to_char(i->player.description, ch);
        else {
            act("You see nothing special about $m.", FALSE, i, 0, ch, TO_VICT);
        }

        /* Show a character to another */

        if (GET_MAX_HIT(i) > 0)
            percent = (100*GET_HIT(i))/GET_MAX_HIT(i);
        else
            percent = -1; /* How could MAX_HIT be < 1?? */

        if (IS_NPC(i))
            strcpy(buffer, i->player.short_descr);
        else
            strcpy(buffer, GET_NAME(i));

        if (percent >= 100)
            strcat(buffer, " is in an excellent condition.\n\r");
        else if (percent >= 90)
            strcat(buffer, " has a few scratches.\n\r");
        else if (percent >= 75)
            strcat(buffer, " has some small wounds and bruises.\n\r");
        else if (percent >= 50)
            strcat(buffer, " has quite a few wounds.\n\r");
        else if (percent >= 30)
            strcat(buffer, " has some big nasty wounds and scratches.\n\r");
        else if (percent >= 15)
            strcat(buffer, " looks pretty hurt.\n\r");
        else if (percent >= 0)
            strcat(buffer, " is in an awful condition.\n\r");
        else
            strcat(buffer, " is bleeding awfully from big wounds.\n\r");

        send_to_char(buffer, ch);

        found = FALSE;
        for (j=0; j< MAX_WEAR; j++) {
            if (i->equipment[j]) {
                if (CAN_SEE_OBJ(ch,i->equipment[j])) {
                    found = TRUE;
                }
            }
        }
        if (found) {
            act("\n\r$n is using:", FALSE, i, 0, ch, TO_VICT);
            for (j=0; j< MAX_WEAR; j++) {
                if (i->equipment[j]) {
                    if (CAN_SEE_OBJ(ch,i->equipment[j])) {
                        send_to_char(where[j],ch);
                        show_obj_to_char(i->equipment[j],ch,1);
                    }
                }
            }
        }
        if ((GET_CLASS(ch) == CLASS_THIEF) && (ch != i)) {
            found = FALSE;
            send_to_char("\n\rYou attempt to peek at the inventory:\n\r", ch);
            for(tmp_obj = i->carrying; tmp_obj; tmp_obj = tmp_obj->next_content) {
                if (CAN_SEE_OBJ(ch, tmp_obj) && (number(0,20) < GET_LEVEL(ch))) {
                    show_obj_to_char(tmp_obj, ch, 1);
                    found = TRUE;
                }
            }
            if (!found)
                send_to_char("You can't see anything.\n\r", ch);
        }

    } else if (mode == 2) {

        /* Lists inventory */
        act("$n is carrying:", FALSE, i, 0, ch, TO_VICT);
        list_obj_to_char(i->carrying,ch,1,TRUE);
    }
}
示例#11
0
int __phi() { return CAG(CAF(CAP(wakend == 1))); }
int __phi() { return CAND(CAP(c>5),CAG(CAP(resp<=5))); }
int __phi() { return CEF(CEG(CAP(wakend != 1))); }
示例#14
0
文件: slime.c 项目: smokeless/eotl
{
    string vil = victim->query_name();
    string att = attacker->query_name();
    int dam = 100 + random( 30 );
    
    ansi_tell_room( ENV( attacker ), sprintf(
      "%s screams as the slime touches %s "
      "skin! The slime burbles and changes form. "
      "It looks almost identical to %s!!!!\n", vil, possessive( vil ),
      vil ), color, ({ victim }) );
    ansi_tell( victim, sprintf(
      "The slime touches you, the pain is incredible. "
      "It begins to change form!!! It has become a copy of you!!!\n" ),
      color );
    
    set_short( sprintf( "%s, covered in slime", CAP( vil ) ) );
    set_ansi_short ( sprintf( "%s%s, covered in slime", color, CAP( vil ) ) );
    
    set_long( " " );
    
    set_name( sprintf( "%s", victim->query_real_name() ) );
    
    add_alias( sprintf( "%s", victim->query_real_name() ) );
   
    set_gender( victim->query_gender() );
    set_race( victim->query_race() );
    
    set_stat( "str" , victim->query_stat( "str" ) + 100 );
    set_stat( "con" , victim->query_stat( "con" ) + 100 );
    
    attacker->full_heal();
示例#15
0
 inline int __phi() { return CAG(CEF(CAP(wakend == 1))); }
示例#16
0
static int show_capabilities (unsigned int cap)
{
#define CAP(x)					\
  if (cap & CAP1284_##x)			\
    printf (#x " ");

  CAP(RAW);
  CAP(NIBBLE);
  CAP(BYTE);
  CAP(COMPAT);
  CAP(BECP);
  CAP(ECP);
  CAP(ECPRLE);
  CAP(ECPSWE);
  CAP(EPP);
  CAP(EPPSL);
  CAP(EPPSWE);
  CAP(IRQ);
  CAP(DMA);
  putchar ('\n');
  return 0;
}
示例#17
0
文件: imap-send.c 项目: 0369/git
static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
				       struct imap_cmd_cb *cb,
				       const char *fmt, va_list ap)
{
	struct imap *imap = ctx->imap;
	struct imap_cmd *cmd;
	int n, bufl;
	char buf[1024];

	cmd = xmalloc(sizeof(struct imap_cmd));
	nfvasprintf(&cmd->cmd, fmt, ap);
	cmd->tag = ++imap->nexttag;

	if (cb)
		cmd->cb = *cb;
	else
		memset(&cmd->cb, 0, sizeof(cmd->cb));

	while (imap->literal_pending)
		get_cmd_result(ctx, NULL);

	if (!cmd->cb.data)
		bufl = nfsnprintf(buf, sizeof(buf), "%d %s\r\n", cmd->tag, cmd->cmd);
	else
		bufl = nfsnprintf(buf, sizeof(buf), "%d %s{%d%s}\r\n",
				  cmd->tag, cmd->cmd, cmd->cb.dlen,
				  CAP(LITERALPLUS) ? "+" : "");

	if (0 < verbosity) {
		if (imap->num_in_progress)
			printf("(%d in progress) ", imap->num_in_progress);
		if (!starts_with(cmd->cmd, "LOGIN"))
			printf(">>> %s", buf);
		else
			printf(">>> %d LOGIN <user> <pass>\n", cmd->tag);
	}
	if (socket_write(&imap->buf.sock, buf, bufl) != bufl) {
		free(cmd->cmd);
		free(cmd);
		if (cb)
			free(cb->data);
		return NULL;
	}
	if (cmd->cb.data) {
		if (CAP(LITERALPLUS)) {
			n = socket_write(&imap->buf.sock, cmd->cb.data, cmd->cb.dlen);
			free(cmd->cb.data);
			if (n != cmd->cb.dlen ||
			    socket_write(&imap->buf.sock, "\r\n", 2) != 2) {
				free(cmd->cmd);
				free(cmd);
				return NULL;
			}
			cmd->cb.data = NULL;
		} else
			imap->literal_pending = 1;
	} else if (cmd->cb.cont)
		imap->literal_pending = 1;
	cmd->next = NULL;
	*imap->in_progress_append = cmd;
	imap->in_progress_append = &cmd->next;
	imap->num_in_progress++;
	return cmd;
}
示例#18
0
int __phi() { return CAG(CIMP(CAP(A==1),CAF(CAP(R==5)))); }
示例#19
0
int tinyjson_parse_err(const char* json, int length, struct tinyjson_token *out, int max_tokens) {
	const unsigned char* cur;
	const unsigned char* end;
	struct tinyjson_token* out_end  = out + max_tokens;
	unsigned char (*st)[256] = &st_struct;
	int utf8_remain = 0;
	int depth = 0;
	struct tinyjson_token dummy[2];
	struct tinyjson_token* current = out;
	int ntokens = 0;

	end = (unsigned char*)json+length;
	for (cur = (unsigned char*)json; cur < end; ++cur) {
		const enum opcode opcode = (enum opcode)(*st)[*cur];
		switch (opcode) {
		case op_bad:
			return -1;

		case op_up:
			PUSH(0);
			if (depth == 1)
				current->type = (*cur) == '[' ? MYJSON_TOKEN_ARRAY : MYJSON_TOKEN_OBJECT;
			++depth;
			break;

		case op_down:
			--depth;
			CAP(0);
			break;

		case op_quote_up:
			PUSH(1);
			if (depth == 1)
				current->type = MYJSON_TOKEN_STRING;
			st = &st_string;
			break;

		case op_quote_down:
			st = &st_struct;
			CAP(-1);
			break;

		case op_escape:
			st = &st_escape;
			break;

		case op_unescape:
			st = &st_string;
			break;

		case op_bare:
			PUSH(0);
			if (depth == 1)
				current->type = MYJSON_TOKEN_LITERAL;
			st = &st_bare;
			break;

		case op_unbare:
			CAP(-1);
			--cur;
			st = &st_struct;
			break;

		case op_utf8_2:
			utf8_remain = 1;
			st = &st_utf8cont;
			break;

		case op_utf8_3:
			utf8_remain = 2;
			break;

		case op_utf8_4:
			utf8_remain = 3;
			break;

		case op_utf8_continue:
			if (--utf8_remain == 0)
				st = &st_struct;
			break;

		case op_loop:
			break;
		}
	}

	return ntokens;
}
示例#20
0
static void
gtk2hs_closure_marshal(GClosure *closure,
                    GValue *return_value,
                    guint n_param_values,
                    const GValue *param_values,
                    gpointer invocation_hint,
                    gpointer marshal_data)
{

    Gtk2HsClosure *hc = (Gtk2HsClosure *)closure;
    HaskellObj call, ret;
#ifdef GHC_RTS_USES_CAPABILITY
    Capability *cap;
#else
    SchedulerStatus cap;
#endif
    guint i;
    
    WHEN_DEBUG(g_debug("gtk2hs_closure_marshal(%p): about to run callback, n_param_values=%d", hc->callback, n_param_values));
#ifdef GHC_RTS_USES_CAPABILITY
    cap = rts_lock();
#else
    rts_lock();
#endif
    
    call = (StgClosure *)deRefStablePtr(hc->callback);
   
    /* construct the function call */
    for (i = 0; i < n_param_values; i++) {
        WHEN_DEBUG(g_debug("gtk2hs_closure_marshal(%p): param_values[%d]=%s :: %s",
	                   hc->callback,
                           i,
                           g_strdup_value_contents(&param_values[i]),
                           g_type_name(G_VALUE_TYPE(&param_values[i]))));
        call = rts_apply(CAP call, gtk2hs_value_as_haskellobj(CAP &param_values[i]));
    }
    
    WHEN_DEBUG(g_debug("gtk2hs_closure_marshal(%p): about to rts_evalIO", hc->callback));
    
    /* perform the call */
    #if __GLASGOW_HASKELL__>=704
    rts_evalIO(&cap, rts_apply(CAP (HaskellObj)runIO_closure, call),&ret);
    #else
    cap=rts_evalIO(CAP rts_apply(CAP (HaskellObj)runIO_closure, call),&ret);
    #endif

    WHEN_DEBUG(g_debug("gtk2hs_closure_marshal(%p): about to rts_checkSchedStatus", hc->callback));
    
    /* barf if anything went wrong */
    /* TODO: pass a sensible value for call site so we get better error messages */
    /* or perhaps we can propogate any error? */
    rts_checkSchedStatus("gtk2hs_closure_marshal", cap);
    WHEN_DEBUG(g_debug("gtk2hs_closure_marshal(%p): ret=%p", hc->callback, ret));
    
    if (return_value) {
        WHEN_DEBUG(g_debug("gtk2hs_closure_marshal(%p): return_value :: %s, ret=%p, UNTAG_CLOSURE(ret)=%p",
	                   hc->callback,
/*                           g_strdup_value_contents(return_value), */
                           g_type_name(G_VALUE_TYPE(return_value)),
			   ret,
			   UNTAG_CLOSURE(ret)));
        gtk2hs_value_from_haskellobj(return_value, ret);
    }
    
#ifdef GHC_RTS_USES_CAPABILITY
    rts_unlock(cap);
#else
    rts_unlock();
#endif
    WHEN_DEBUG(g_debug("gtk2hs_closure_marshal(%p): done running callback", hc->callback));
}
示例#21
0
int __phi() { return CAG(CIMP(CAP(keA==1),CEF(CAP(keR==1)))); }