Exemplo n.º 1
0
void InputProfileEditor::slotAddClicked()
{
    QLCInputChannel* channel = new QLCInputChannel();
    InputChannelEditor ice(this, m_profile, channel);
add:
    if (ice.exec() == QDialog::Accepted)
    {
        channel->setType(ice.type());
        channel->setName(ice.name());

        if (m_profile->channel(ice.channel()) == NULL)
        {
            m_profile->insertChannel(ice.channel(), channel);
            updateChannelItem(new QTreeWidgetItem(m_tree), channel);
        }
        else
        {
            QMessageBox::warning(this,
                                 tr("Channel already exists"),
                                 tr("Channel %1 already exists")
                                 .arg(ice.channel() + 1));
            goto add;
        }
    }
    else
    {
        delete channel;
    }
}
Exemplo n.º 2
0
void UTIL_DecodeICE( unsigned char * buffer, int size, const unsigned char *key)
{
	if ( !key )
		return;

	IceKey ice( 0 ); // level 0 = 64bit key
	ice.set( key ); // set key

	int blockSize = ice.blockSize();

	unsigned char *temp = (unsigned char *)_alloca( PAD_NUMBER( size, blockSize ) );
	unsigned char *p1 = buffer;
	unsigned char *p2 = temp;
				
	// encrypt data in 8 byte blocks
	int bytesLeft = size;
	while ( bytesLeft >= blockSize )
	{
		ice.decrypt( p1, p2 );
		bytesLeft -= blockSize;
		p1+=blockSize;
		p2+=blockSize;
	}

	// copy encrypted data back to original buffer
	Q_memcpy( buffer, temp, size-bytesLeft );
}
Exemplo n.º 3
0
bool Scope::visitASTExprChar(AST::Node& node, uint32_t& localvar) {
	char c /*= '\0'*/;
	switch (node.children.size()) {
		case 0: {
			// simple char
			if (unlikely(node.text.size() != 3)) // 'X'
				return (ice(node) << "invalid char node");
			c = node.text[1];
			break;
		}
		case 1: {
			auto& extended = node.children[0];
			switch (extended.rule) {
				case AST::rgCharExtended: {
					if (extended.text.size() == 1) {
						char extC = '\0';
						if (not convertCharExtended(extC, extended.text[0]))
							return (error(extended) << "invalid escaped character '\\" << extended.text << '\'');
						c = extC;
					}
					else {
						error(extended) << "invalid escaped character '\\" << extended.text << '\'';
						return false;
					}
					break;
				}
				default:
					return unexpectedNode(node, "[char/extended]");
			}
			break;
		}
		default:
			return unexpectedNode(node, "[char]");
	}
	if (!context.reuse.ascii.node)
		context.prepareReuseForAsciis();
	uint32_t hardcodedlvid = createLocalBuiltinInt(node, nyt_u8, static_cast<uint8_t>(c));
	ShortString16 lvidstr;
	lvidstr = hardcodedlvid;
	context.reuse.ascii.lvidnode->text = lvidstr;
	bool success = visitASTExprNew(*(context.reuse.ascii.node), localvar);
	// avoid crap in the debugger
	context.reuse.ascii.lvidnode->text.clear();
	return success;
}
void ctrl_icecrystals(int secs)
{
  int nsdelay = 1000000/60;
  time_t start = time(NULL);
  time_t now;
  IceCrystalsMode ice(MAXLEDS);
  ice.init();

  time(&start);
  while (1) {
    ice.loop(&ledbuffer[0]);
    flushbuffer();
    now = time(NULL);
    if (start + secs < now)
      break;
    usleep(nsdelay);
  }
}
Exemplo n.º 5
0
Arquivo: sem.c Projeto: aji/nursery
static struct s_decls *s_decls(struct p_decls *p)
{
	struct s_decls *s;

	if (p == NULL)
		return NULL;

	s = malloc(sizeof(*s));

	switch (p->type) {
	case T_FN:
		s->type = T_FN;
		s->fn = s_fn_decl(p->fn);
		break;

	default:
		ice("unknown declaration type `%s'", lx_names[p->type]);
	}

	s->next = s_decls(p->next);

	return s;
}
Exemplo n.º 6
0
bool Scope::visitASTExprNumber(AST::Node& node, uint32_t& localvar) {
	assert(node.rule == AST::rgNumber);
	assert(not node.children.empty());
	// Number definition
	NumberDef numdef;
	// is a builtin ? (__i32, __f64...)
	// (always generate builtin types when not importing the NSL)
	bool builtin = (not config::importNSL);
	emitDebugpos(node);
	for (auto& child : node.children) {
		switch (child.rule) {
			case AST::rgNumberValue: { // standard number definition
				bool firstPart = true;
				for (auto& subnode : child.children) {
					switch (subnode.rule) {
						case AST::rgInteger: {
							if (likely(firstPart)) {
								if (not subnode.text.to<uint64>(numdef.part1)) {
									error(subnode) << "invalid integer value";
									return false;
								}
								firstPart = false;
							}
							else {
								numdef.part2 = subnode.text;
								numdef.part2.trimRight('0'); // remove useless zeros
								// as far as we know, it is a float64 by default
								numdef.isFloat = true;
							}
							break;
						}
						default: {
							ice(subnode) << "[expr-number]";
							return false;
						}
					}
				}
				break;
			}
			case AST::rgNumberSign: { // + -
				assert(not child.text.empty() and "invalid ast");
				numdef.sign = child.text[0];
				assert(numdef.sign == '+' or numdef.sign == '-');
				break;
			}
			case AST::rgNumberQualifier: { // unsigned / signed / float
				for (auto& subnode : child.children) {
					switch (subnode.rule) {
						case AST::rgNumberQualifierType: {
							assert(not subnode.text.empty());
							uint offset = 0;
							if (subnode.text.first() == '_' and subnode.text[1] == '_') {
								offset = 2;
								builtin = true;
							}
							for (uint i = offset; i < subnode.text.size(); ++i) {
								switch (subnode.text[i]) {
									case 'i':
										numdef.isUnsigned = false;
										break;
									case 'u':
										numdef.isUnsigned = true;
										break;
									case 'f':
										numdef.isFloat = true;
										break;
									default:
										error(node) << "invalid number qualifier. Got '"
													<< subnode.text.first() << "', expected 'i', 'u' or 'f'";
								}
							}
							break;
						}
						case AST::rgInteger: {
							if (likely(subnode.text.size() < 10)) {
								numdef.bits = subnode.text.to<uint>();
								if (unlikely(not validNumberOfBits(numdef.bits)))
									return (error(subnode) << "invalid integer size");
							}
							else {
								error(subnode) << "integer too large";
								return false;
							}
							break;
						}
						default: {
							ice(subnode) << "[expr-number]";
							return false;
						}
					}
				}
				break;
			}
			default: {
				ice(child) << "[expr-number]";
				return false;
			}
		}
	}
	assert(numdef.bits == 64 or numdef.bits == 32 or numdef.bits == 16 or numdef.bits == 8);
	return (not builtin)
		   ? generateNumberCode<false>(*this, localvar, numdef, node)
		   : generateNumberCode<true> (*this, localvar, numdef, node);
}
Exemplo n.º 7
0
void InputProfileEditor::slotEditClicked()
{
    QLCInputChannel* channel;
    quint32 chnum;
    QTreeWidgetItem* item;

    if (m_tree->selectedItems().count() == 1)
    {
        /* Just one item selected. Edit that. */
        item = m_tree->currentItem();
        if (item == NULL)
            return;

        /* Find the channel object associated to the selected item */
        chnum = item->text(KColumnNumber).toUInt() - 1;
        channel = m_profile->channel(chnum);
        Q_ASSERT(channel != NULL);

        /* Edit the channel and update its item if necessary */
        InputChannelEditor ice(this, m_profile, channel);
edit:
        if (ice.exec() == QDialog::Accepted)
        {
            QLCInputChannel* another;
            another = m_profile->channel(ice.channel());

            if (another == NULL || another == channel)
            {
                if (ice.channel() != QLCChannel::invalid())
                    m_profile->remapChannel(channel, ice.channel());
                if (ice.name().isEmpty() == false)
                    channel->setName(ice.name());
                if (ice.type() != QLCInputChannel::NoType)
                    channel->setType(ice.type());

                updateChannelItem(item, channel);
            }
            else
            {
                QMessageBox::warning(this,
                                     tr("Channel already exists"),
                                     tr("Channel %1 already exists")
                                     .arg(ice.channel() + 1));
                goto edit;
            }
        }
    }
    else if (m_tree->selectedItems().count() > 1)
    {
        /* Multiple channels selected. Apply changes to all of them */
        InputChannelEditor ice(this, NULL, NULL);
        if (ice.exec() == QDialog::Accepted)
        {
            QListIterator <QTreeWidgetItem*>
            it(m_tree->selectedItems());
            while (it.hasNext() == true)
            {
                item = it.next();
                Q_ASSERT(item != NULL);

                chnum = item->text(KColumnNumber).toUInt() - 1;
                channel = m_profile->channel(chnum);
                Q_ASSERT(channel != NULL);

                /* Set only name and type and only if they
                   have been modified. */
                if (ice.name().isEmpty() == false)
                    channel->setName(ice.name());
                if (ice.type() != QLCInputChannel::NoType)
                    channel->setType(ice.type());

                updateChannelItem(item, channel);
            }
        }
    }
}
Exemplo n.º 8
0
Statement* makeForEach(Array<VarDecl*> iterators, Expr *range, ScopeStatement *body, SourceLocation loc)
{
	SliceExpr *intRange = dynamic_cast<SliceExpr*>(range);
	if (intRange)
	{
		if (iterators.length > 1)
			error("file", loc.line, "only one iterator supported for range foreach");

		MutableString64 iteratorName;
		// if no explicit iterator was defined, we need an implicit one
		if (iterators.length == 0)
		{
			iteratorName = MutableString64(Sprintf, "__it%d", loc.line);
			iterators.push_back(new VarDecl(iteratorName, intRange->from()->type(), intRange->from(), nullptr, loc));
		}
		else
		{
			iteratorName = iterators[0]->name();

			// if the iterator was un-typed, infer the type from the range
			if (!iterators[0]->_type)
				iterators[0]->_type = intRange->from()->type();

			// update the iterator's init value to the start of the range
			iterators[0]->_init = intRange->from()->makeConversion(iterators[0]->type(), true);
		}

		Identifier *pIterIdent = new Identifier(iteratorName, loc);
		BinaryExpr *cond = new BinaryExpr(BinOp::Ne, pIterIdent, intRange->to(), loc);
		UnaryExpr *inc = new UnaryExpr(UnaryOp::PreInc, pIterIdent, loc);
//		AssignExpr *inc = new AssignExpr(pIterIdent, new PrimitiveLiteralExpr(PrimType::u8, 1ull, loc), BinOp::Add, loc);

		return new LoopStatement(std::move(iterators), cond, Array<Expr*>(Concat, (Expr*)inc), body, loc);
	}

	ice("TODO"); // TODO!!

	// only [value], or [key, value] are allowed!
	assert(iterators.length <= 2);

	// assign void initialisation for counters (initialised at head of loop body)
	for (auto &i : iterators)
		((VarDecl*)i)->_init = new PrimitiveLiteralExpr(PrimType::v, 0ull, loc);

	VarDecl *r = new VarDecl("__loop_range", nullptr, range, Array<Node*>(), loc);
	iterators = Array<VarDecl*>(Concat, r, iterators);

	Expr *cond = nullptr; // cast(bool)__loop_range.empty()

	Array<Statement*> entry;
	if (iterators.length)
	{
		if (iterators.length == 3)
		{
			// iterators[1] = __loop_range.front.key;
			// entry = entry.append(assignment);
		}

		// iterators[iterators.length-1] = __loop_range.front.value;
		// entry = entry.append(assignment);
	}
	body->_statements = entry.append(body->_statements);

	Expr *increment = nullptr; // __loop_range = __loop_range.popFront();

	return new LoopStatement(std::move(iterators), cond, Array<Expr*>(Concat, increment), body, loc);
}
Exemplo n.º 9
0
Arquivo: sem.c Projeto: aji/nursery
static struct s_expr *s_expr(struct symtab *tab, struct p_expr *p)
{
	struct s_expr *ex, *s;
	int i, children;

	ex = malloc(sizeof(*ex));
	children = 0;

	switch (p->type) {
	case T_ID:
		s = symtab_get(tab, p->id);
		if (s == NULL) {
			ex->type = S_EXPR_LABEL;
			ex->id = p->id;
		} else {
			free(ex);
			ex = s;
		}
		break;

	case T_INT:
		ex->type = S_EXPR_IMMEDIATE;
		ex->n = p->num;
		break;

	case T_FN:
		ex->type = S_EXPR_APPLICATION;
		ex->app = s_apply(tab, p->fn);
		break;

	case T_LBRACK:
	case T_NEG:
		children = 1;
		break;

	case T_ADD:
	case T_SUB:
	case T_MUL:
	case T_DIV:
	case T_MOD:
	case T_AND:
	case T_OR:
	case T_XOR:
	case T_EQ:
	case T_NE:
	case T_GT:
	case T_LT:
	case T_COMMA:
		children = 2;
		break;

	case T_QUES:
		children = 3;
		break;

	default:
		ice("unknown expression type `%s'", lx_names[p->type]);
	}

	if (children > 0) {
		ex->op = p->type;
		switch (children) {
		case 1: ex->type = S_EXPR_UNARY_OPERATION; break;
		case 2: ex->type = S_EXPR_BINARY_OPERATION; break;
		case 3: ex->type = S_EXPR_CONDITIONAL; break;
		default: ice("can't expression with %d children", children);
		}
		for (i=0; i<children; i++)
			ex->child[i] = s_expr(tab, p->child[i]);
	}

	return ex;
}
Exemplo n.º 10
0
/*
 * Update the weather.
 */
void weather_update( void )
{
    char buf[MAX_STRING_LENGTH];
    DESCRIPTOR_DATA *d;

    buf[0] = '\0';

    switch ( ++time_info.hour )
    {
    case  5:
	weather_info.sunlight = SUN_LIGHT;
	strcat( buf, "The {yday{x has begun.\n\r" );
	break;

    case  6:
	weather_info.sunlight = SUN_RISE;
	strcat( buf, "The {Ysun{x rises in the east.\n\r" );
	break;

    case 19:
	weather_info.sunlight = SUN_SET;
	strcat( buf, "The {Ysun{x slowly disappears in the west.\n\r" );
	break;

    case 20:
	weather_info.sunlight = SUN_DARK;
	strcat( buf, "The {Dnight{x has begun.\n\r" );
	break;

    case 24:
	time_info.hour = 0;
	time_info.day++;
	break;

    }

    if ( time_info.day   >= 35 )
    {
	time_info.day = 0;
	time_info.month++;
    }

    if ( time_info.month >= 12 )
    {
	time_info.month = 0;
	time_info.year++;
    }

    /*
     * Weather change.
     */
    switch ( weather_info.sky )
    {
    default: 
	    weather_info.sky = SKY_CLOUDLESS;
	break;

    case SKY_CLOUDLESS:
if ((number_chance(10))&&  (time_info.hour <= 6) )
      {
	    weather_info.sky = SKY_FOGGY;
     }
      else  if (number_chance(15))
      {
	    weather_info.sky = SKY_CLOUDY;
     }
      else   if (number_chance(30))
      {
	    weather_info.sky = SKY_RAINING;
     }
else
      if (number_chance(45))
      {
            weather_info.sky = SKY_CLOUDLESS;
     }


	break;

    case SKY_CLOUDY:
      if (number_chance(15))
	{
	    weather_info.sky = SKY_SNOWING;
	}
	else
      if (number_chance(15))
	{
	    weather_info.sky = SKY_HAILSTORM;
	}
	else
      if (number_chance(15))
	{
	    weather_info.sky = SKY_THUNDERSTORM;
	}
	else
      if (number_chance(15))
	{
	    weather_info.sky = SKY_ICESTORM;
	}      
else      if (number_chance(15))
	{
	    weather_info.sky = SKY_CLOUDLESS;
	}
else if (number_chance(25))
	{
	    weather_info.sky = SKY_CLOUDY;
	}
    case SKY_RAINING:
      if (number_chance(15))
        {
            weather_info.sky = SKY_LIGHTNING;
            lightning       ( );
        }
      else
      if (number_chance(10))
        {
            weather_info.sky = SKY_HAILSTORM;
	    hail();
        }
      else
      if (number_chance(10))
        {
            weather_info.sky = SKY_THUNDERSTORM;
        }
      else
      if (number_chance(10))
        {
            weather_info.sky = SKY_CLOUDY;
        }
else  if (number_chance(55))
        {
            weather_info.sky = SKY_RAINING;
        }
        break;

    case SKY_SNOWING:
if (number_chance(15))
	{
	    weather_info.sky = SKY_BLIZZARD;
	}
else if (number_chance(15))
	{
	    weather_info.sky = SKY_CLOUDY;
	}
else if (number_chance(15))
	{
	    weather_info.sky = SKY_RAINING;
	}
	else 
 if (number_chance(55))
	{
	    weather_info.sky = SKY_SNOWING;
	}

	break;
    case SKY_LIGHTNING:
if (number_chance(15))
	{
	    weather_info.sky = SKY_THUNDERSTORM;
          }
else if (number_chance(15))
	{
	    weather_info.sky = SKY_RAINING;
	}
else if (number_chance(15))
	{
	    weather_info.sky = SKY_CLOUDY;
	}
else if (number_chance(15))
	{
	    weather_info.sky = SKY_HAILSTORM;
          }
else if (number_chance(40))
	{
	    weather_info.sky = SKY_LIGHTNING;
          }
	break;
    case SKY_FOGGY:
 if (number_chance(45))
	{
 weather_info.sky = SKY_CLOUDY;
	}
else if (number_chance(55))
	{
        fog();
  weather_info.sky = SKY_FOGGY;
	break;
	}

    case SKY_THUNDERSTORM:
if (number_chance(15))
	{
	    weather_info.sky = SKY_RAINING;
          }
else if (number_chance(15))
	{
	    weather_info.sky = SKY_CLOUDY;
	}
else if (number_chance(15))
	{
	    weather_info.sky = SKY_LIGHTNING;
	}
else if (number_chance(15))
	{
	    weather_info.sky = SKY_HAILSTORM;
hail ();          }
else if (number_chance(40))
	{
	    weather_info.sky = SKY_THUNDERSTORM;
          }
	break;

    case SKY_HAILSTORM:
 if (number_chance(15))
	{
	    weather_info.sky = SKY_CLOUDY;
	}
 else
if (number_chance(30))
	{
	    weather_info.sky = SKY_RAINING;
          }
      else
 if (number_chance(55))
	{
	    weather_info.sky = SKY_HAILSTORM;
	hail();
	}
	break;

    case SKY_ICESTORM:
 if (number_chance(15))
	{
	    weather_info.sky = SKY_CLOUDY;
          }
      else
 if (number_chance(15))
	{
	    weather_info.sky = SKY_BLIZZARD;
          }
else
 if (number_chance(15))
	{
	    weather_info.sky = SKY_SNOWING;
	}
      else
 if (number_chance(55))
	{
ice();
   weather_info.sky = SKY_ICESTORM;
  }
	break;


    case SKY_BLIZZARD:
 if (number_chance(15))
	{
	    weather_info.sky = SKY_SNOWING;
	}
else if (number_chance(15))
	{
           blizzard();
	    weather_info.sky = SKY_ICESTORM;
ice();
	}
else if (number_chance(15))
	{
           blizzard();
	    weather_info.sky = SKY_CLOUDY;
	}
else
 if (number_chance(55))
	{
           blizzard();
	    weather_info.sky = SKY_BLIZZARD;
	}
break;

    }

    if ( buf[0] != '\0' )
    {
	for ( d = descriptor_list; d != NULL; d = d->next )
	{
	    if ( d->connected == CON_PLAYING
	    &&   IS_OUTDOORS(d->character)
	    &&   IS_AWAKE(d->character) )
		send_to_char( buf, d->character );
	}
    }

    return;
}
Exemplo n.º 11
0
bool DEncrypt(const char* filename)
{
		//Open allocate/read a file into memory
	FILE *pFile;
	pFile = fopen (filename, "rb");
	if(! pFile)
		Exit("Failed to open input file\n");

	long lFileSize; //Size of input file
	unsigned char *pBuff; //Holds the input file contents
	unsigned char *pOutBuff; //Holds the output goodies

	// obtain file size.
	fseek (pFile , 0 , SEEK_END);
	lFileSize= ftell (pFile);
	rewind (pFile);

	// allocate memory to contain the whole file.
	pBuff = (unsigned char*) malloc (lFileSize);
	pOutBuff = (unsigned char*) malloc (lFileSize);

	if (pBuff == NULL || pOutBuff == NULL)
	{
		fclose(pFile);
		std::cout << "Could not allocate buffer" << std::endl;
                return false;
	}

	// copy the file into the buffer.
	fread (pBuff,1,lFileSize,pFile);
	
	//clean the output buffer
	memset(pOutBuff,NULL,lFileSize);

	fclose(pFile);

	//Lets start the ice goodies!
	IceKey ice( 0 ); // level 0 = 64bit key
	ice.set( (unsigned char*) g_ICEKey ); // set key

	int blockSize = ice.blockSize();

	unsigned char *p1 = pBuff;
	unsigned char *p2 = pOutBuff;

	// encrypt data in 8 byte blocks
	int bytesLeft = lFileSize;

	while ( bytesLeft >= blockSize )
	{
		if ( g_Encrypt )
			ice.encrypt( p1, p2 );
		else
			ice.decrypt( p1, p2 );

		bytesLeft -= blockSize;
		p1+=blockSize;
		p2+=blockSize;
	}

	//The end chunk doesn't get an encryption?  that sux...
	memcpy( p2, p1, bytesLeft );

	size_t outLength = strlen(filename) + MAX_EXTENSION + 1;
	char *pOutPath = (char *)malloc(outLength);
	strncpy(pOutPath,filename,outLength);

	SetExtension(pOutPath, outLength, g_Extension);

	pFile = fopen (pOutPath , "wb");
	if(pFile == NULL)
	{
		fprintf( stderr, "Was not able to open output file for writing.\n" );
		free(pBuff);
		free(pOutBuff);
		free(pOutPath);
		return false;
	}

	fwrite (pOutBuff , 1 , lFileSize , pFile);
	fclose (pFile);

	free(pBuff);
	free(pOutBuff);
	free(pOutPath);

	return true;
}