Esempio n. 1
0
Tree::Tree(const Str &aname, BOOL aXSLTree)
    : theArena(TREE_ARENA_SIZE), theDictionary(&theArena, TREE_DICT_LOGSIZE),
      structure(0)
{
    // theDictionary.initialize();
    QName &rootname = (QName&) getTheEmptyQName();
    root = new(&theArena) RootNode(*this, rootname);
    XSLTree = aXSLTree;
    stackTop = &getRoot();
    pendingTextNode = NULL;
    getRoot().stamp = 0;
    vcount = 1;
    QName dummyName;
    theDummyElement = new(&theArena) Element(*this, dummyName);
    initDict();

    // append entry for 'the whole tree' to subtrees
    subtrees.push(new SubtreeInfo(
	aname, XSL_NONE, &structure, FALSE));
    getRoot().setSubtreeInfo(subtrees.last());

    excludeStdNamespaces();

    pendingNSList.append(new(&theArena) NSList());

    stripped = aXSLTree;
    hasAnyStripped = hasAnyPreserved = -1;// means 'who knows?'
    importUnique = 0xFFFF;
};
Esempio n. 2
0
Scene* GameOverScene::createScene(cocos2d::CCDictionary *dic)
{
	auto scene = Scene::create();
	auto layer = GameOverScene::create();
    layer->initWithColor(Color4B::WHITE);
	layer->initDict(dic);
	scene->addChild(layer);
	return scene;
}
bool OPimContactAccessBackend_XML::readInto( OPimXmlReader &rd, OPimContactAccess *target )
{
    QAsciiDict<int> dict(OPimEvent::FRecChildren+1);
    initDict( dict );

    OPimWriteBackXmlHandler<OPimContact> handler( "Contact", dict, target );
    OPimXmlStreamParser parser( handler );
    rd.read( parser );
    return true;
}
void OPimContactAccessBackend_XML::updateJournal( const OPimContact& cnt,
                           OPimRecord::ChangeAction action )
{
    if( !m_journalEnabled || m_journalName.isEmpty() )
        return;

    QFile f( m_journalName );
    bool created = !f.exists();
    if ( !f.open(IO_WriteOnly|IO_Append) )
        return;

    QString buf;
    QCString str;

    QAsciiDict<int> dict(OPimEvent::FRecChildren+1);
    initDict( dict );
    QIntDict<QString> revdict( dict.size() );
    revdict.setAutoDelete( true );
    // Now we need to reverse the dictionary (!)
    for( QAsciiDictIterator<int> it( dict ); it.current(); ++it ) {
        revdict.insert( (*it), new QString( it.currentKey() ) );
    }
    
    // if the file was created, we have to set the Tag "<CONTACTS>" to
    // get a XML-File which is readable by our parser.
    // This is just a cheat, but better than rewrite the parser.
    if ( created ) {
        buf = "<Contacts>";
        QCString cstr = buf.utf8();
        f.writeBlock( cstr.data(), cstr.length() );
    }

    buf = "<Contact ";
    saveEntry( &cnt, revdict, buf );
    buf += " action=\"" + QString::number( (int)action ) + "\" ";
    buf += "/>\n";
    QCString cstr = buf.utf8();
    f.writeBlock( cstr.data(), cstr.length() );
}
bool OPimContactAccessBackend_XML::write( OAbstractWriter &wr )
{
    QAsciiDict<int> dict(OPimEvent::FRecChildren+1);
    initDict( dict );
    QIntDict<QString> revdict( dict.size() );
    revdict.setAutoDelete( true );
    // Now we need to reverse the dictionary (!)
    for( QAsciiDictIterator<int> it( dict ); it.current(); ++it ) {
        revdict.insert( (*it), new QString( it.currentKey() ) );
    }

    // Write Header
    QString out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
        " <Groups>\n"
        " </Groups>\n"
        " <Contacts>\n";
    QCString cstr = out.utf8();
    if ( !wr.writeString( cstr ) )
        return false;

    // Write all contacts
    QListIterator<OPimContact> it( m_contactList );
    for ( ; it.current(); ++it ) {
        out = "<Contact ";
        saveEntry( (*it), revdict, out );
        out += "/>\n";
        cstr = out.utf8();
        if ( !wr.writeString( cstr ) )
            return false;
    }

    // Write Footer
    out = " </Contacts>\n</AddressBook>\n";
    cstr = out.utf8();
    if ( !wr.writeString( cstr ) )
        return false;

    return true;
}
int main(int argc, char *argv[]) {
	int i = 0, cycles = 100000;
	int numOfWords = 10, numOfSymbols = 10, numOfResults = 33, actualNumOfResults = 0;
	double fullTime = 0, enTime = 0, stTime = 0;
	struct timeval tv_st, tv_end;
	struct dict *plainDict, *structDict, *arrayDict;

	if (2 == argc) {
		cycles = atoi((char*) argv[1]);
	}
	else {
		printf("Parameter 'number of cycles' (positive integer) allowed.\n");
	}
	printf("Doing %d cycles of searching with each type of dictionary...\n", cycles);

	/* plain dict */
	plainDict = initDict(PLAIN_DICT, THREADS_UNSAFE, ONE_STORAGE, numOfWords, numOfSymbols, numOfResults);
	fillDict(plainDict);
	while (cycles > i) {
		gettimeofday(&tv_st, NULL);
		actualNumOfResults = searchInDict(plainDict, srcStr, NULL);
		gettimeofday(&tv_end, NULL);
		stTime = (tv_st.tv_sec + (tv_st.tv_usec * 0.000001));
		enTime = (tv_end.tv_sec + (tv_end.tv_usec * 0.000001));
		fullTime += (enTime - stTime);
		i++;
	}
	printf("(%d, PLAIN): [%d] dict words found in string, time (secs) = [%f], mem used: %d bytes\n", plainDict->dictType, actualNumOfResults, fullTime, plainDict->memUsed);
	freeDict(plainDict);

	/* structures dict */
	fullTime = 0;
	i = 0;
	actualNumOfResults = 0;
	structDict = initDict(STRUCT_DICT, THREADS_UNSAFE, ONE_STORAGE, numOfWords, numOfSymbols, numOfResults);
	fillDict(structDict);
	while (cycles > i) {
		gettimeofday(&tv_st, NULL);
		actualNumOfResults = searchInDict(structDict, srcStr, NULL);
		gettimeofday(&tv_end, NULL);
		stTime = (tv_st.tv_sec + (tv_st.tv_usec * 0.000001));
		enTime = (tv_end.tv_sec + (tv_end.tv_usec * 0.000001));
		fullTime += (enTime - stTime);
		i++;
	}
	printf("(%d, STRUCT): [%d] dict words found in string, time (secs) = [%f], mem used: %d bytes\n", structDict->dictType, actualNumOfResults, fullTime, structDict->memUsed);
	freeDict(structDict);

	/* arrays dict */
	fullTime = 0;
	i = 0;
	actualNumOfResults = 0;
	arrayDict = initDict(ARRAY_DICT, THREADS_UNSAFE, ONE_STORAGE, numOfWords, numOfSymbols, numOfResults);
	fillDict(arrayDict);
	while (cycles > i) {
		gettimeofday(&tv_st, NULL);
		actualNumOfResults = searchInDict(arrayDict, srcStr, NULL);
		gettimeofday(&tv_end, NULL);
		stTime = (tv_st.tv_sec + (tv_st.tv_usec * 0.000001));
		enTime = (tv_end.tv_sec + (tv_end.tv_usec * 0.000001));
		fullTime += (enTime - stTime);
		i++;
	}
	printf("(%d, ARRAY): [%d] dict words found in string, time (secs) = [%f], mem used: %d bytes\n", arrayDict->dictType, actualNumOfResults, fullTime, arrayDict->memUsed);
	freeDict(arrayDict);

	return 0;
}
Esempio n. 7
0
/*
 * Go evaluator main program
 */
int main(int argc, char **argv) {
  int narg;

#ifdef HAVE_LOCALECONV
  setlocale(LC_ALL,"");		/* set up locale */
#endif

#ifdef LOCALEDIR
  bindtextdomain(PACKAGE,LOCALEDIR);
  textdomain(PACKAGE);
#endif

  initLogfile((char *) "-");
  initFileIo();        /* Set up special file handling */

  strMsg(entryPoint, NumberOf(entryPoint), "lo.boot@__boot"); /* standard entry point */

  if ((narg = getOptions(argc, argv)) < 0) {
    outMsg(logFile, _("usage: %s [-v] [-L log] [-g host:port] [-V] [-b boot:ver] [-m entry] [-r repo] [-d wd]"
                        " [-h sizeK] [-s sizeK] [-d rootdir] args ...\n"), argv[0]);
    exit(1);
  }

  // Set up repository directory
  if (uniIsLit(repoDir, "")) { // overridden?
    char *dir = getenv("LO_DIR"); /* pick up the installation directory */
    if (dir == NULL)
      dir = LODIR;                  /* Default installation path */
    uniCpy(repoDir, NumberOf(repoDir), dir);
  }

  // set up working directory
  if (uniIsLit(loCWD, "")) {
    char cbuff[MAXPATHLEN];
    char *cwd = getcwd(cbuff, NumberOf(cbuff)); /* compute current starting directory */
    if (cwd == NULL)
      syserr("cant determine current directory");
    else
      strMsg(loCWD, NumberOf(loCWD), "%s/", cwd);
  }

  if (loadManifest(repoDir) != Ok) {
    outMsg(logFile, "error in loading repository from %s", repoDir);
    exit(99);
  }

  /* IMPORTANT -- Keep the order of these set up calls */
  initGlobal(initHeapSize);    /* start up the global space */
  initClass();        /* Initialize the class handlers */
  initPrograms();      /* Initialize program handling */
  initDict();        /* Start up the dictionaries */
  install_escapes();      /* Initialize the escape table */
  initFiles();        /* initialize file tables */
  init_args(argv, argc, narg);    /* Initialize the argument list */
  init_time();        /* Initialize time stuff */

  setupSignals();

#ifdef EXECTRACE
  if (traceCount)
    atexit(dumpInsCount);
#endif

  bootstrap(entryPoint, bootPkg, bootVer);

  return EXIT_SUCCEED;          /* exit the lo system cleanly */
}
Esempio n. 8
0
void handleKey(std::vector<const char*> fdvec, int fdf) {
	struct input_event ie;
    int mode = 0; // 0 number; 1 alpha; 2 symbol
    __u16 lastcode = (__u16)-1;
	__u16 lastpush = (__u16)-1 -1;
    int delaytime = 1;

	fd_set sset, backset;
	FD_ZERO(&sset);
	int maxfd = -1;
	for (auto name: fdvec) {
		int fd = open(name, O_RDONLY);
		if (fd >= 0) {
			FD_SET(fd, &sset);
			maxfd = fd > maxfd ? fd : maxfd;
		} else {
			printf("can not open eventdev %s\n", name);
		}
	}

	if (maxfd < 0) {
		printf("not find any event input, stop\n");
		return;
	} else {
		printf("max fd is %d\n", maxfd);
	}

    // map from keycode to keycode, we have three mode, use vector 
    std::vector<std::map<__u16, __u16>> mvec{std::map<__u16,__u16>(), std::map<__u16,__u16>(), std::map<__u16,__u16>()};

    initDict(mvec, sec);

	backset = sset;
	while (1) {
		sset = backset;
		int res = select(maxfd+1, &sset, NULL, NULL, NULL);
		if (res > 0) {
			for (int i = 0; i < maxfd+1; ++i) {
				if( FD_ISSET(i, &sset)) {
					if (read(i, &ie, sizeof(ie)) != sizeof(ie)) {
						printf("read error size from event dev\n");
						continue;
					} 
//					printf("get type %d, code %d, value %d from eventdev\n", ie.type, ie.code, ie.value);
					if (ie.type != EV_KEY) { // if not keycode or is pop
						// if not key event, just send thourgh
						if (write(fdf, &ie, sizeof(ie)) != sizeof(ie)) {
							printf("unmodified send: write error into fifo\n");
						}
						continue;
					}

					switch (ie.code) {
						case KEY_F1:
							if (ie.value == 0) { // handle model change after key pop
								mode = (mode+1)%3; // current only number and alpha mode and navigation mode
								alarm(0); //cancel any alarm
								lastcode = (__u16)-1;
								printf("changing mode to %d\n", mode);
							}
							break;
						default:
							// only transfer recognized code
							if (mvec[mode].find(ie.code) != mvec[mode].end()) {
								
								if (ie.value == 0) { // pop
									/*
									if (lastcode != (__u16)-1) {
										ie.code = lastcode;
									}
									*/
									ie.code = lastpush;
									if (write(fdf, &ie, sizeof(ie)) != sizeof(ie)) {
										printf("pop send: write error into fifo\n");
									}
									break;
								}
									
								// handle mode 1's alpha transform
								if (mode == 1 && (ie.code >= KEY_1 && ie.code <= KEY_9)) { // we have char change 
									ie.code = mvec[mode][ie.code];
									if (!samefield(lastcode, ie.code)) {
										alarm(delaytime);
										lastcode = ie.code;
									} else {
										int restime = alarm(delaytime);
										if (restime != 0) { // we should change
											ie.code = changecurcode(lastcode); 
											sendbackspace(fdf);
										}
										lastcode = ie.code;
									}
								} else {
									ie.code = mvec[mode][ie.code];
								}
								lastpush = ie.code;
								if (write(fdf, &ie, sizeof(ie)) != sizeof(ie)) {
									printf("modify send: write error into fifo\n");
								}
							}
							break;
					}
				}
			}
		}else {
			perror("some error while select: ");
		}
	}
}
/* This function loads the xml-database and the journalfile */
bool OPimContactAccessBackend_XML::loadXml( XMLElement *root, bool isJournal )
{
    OPimRecord::ChangeAction action = OPimRecord::ACTION_ADD;
    QMap<int, QString> contactMap;
    QMap<QString, QString> customMap;
    QMap<QString, QString>::Iterator customIt;
    QAsciiDict<int> dict( 47 );
    initDict( dict );

    if(root != 0l ) { // start parsing
        /* Parse all XML-Elements and put the data into the
         * Contact-Class
         */
        XMLElement *element = root->firstChild();
        element = element ? element->firstChild() : 0;

        m_journalEnabled = false;
        
        /* Search Tag "Contacts" which is the parent of all Contacts */
        while( element && !isJournal ) {
            if( element->tagName() != QString::fromLatin1("Contacts") ) {
                element = element->nextChild();
            }
            else {
                element = element->firstChild();
                break;
            }
        }
        /* Parse all Contacts and ignore unknown tags */
        while( element ) {
            if( element->tagName() != QString::fromLatin1("Contact") ) {
                element = element->nextChild();
                continue;
            }
            /* Found alement with tagname "contact", now parse and store all
             * attributes contained
             */
            QString dummy;
            action = OPimRecord::ACTION_ADD;

            XMLElement::AttributeMap aMap = element->attributes();
            XMLElement::AttributeMap::Iterator it;
            contactMap.clear();
            customMap.clear();
            for( it = aMap.begin(); it != aMap.end(); ++it ) {
                int *find = dict[ it.key() ];
                /* Unknown attributes will be stored as "Custom" elements */
                if ( !find ) {
                    //contact.setCustomField(it.key(), it.data());
                    customMap.insert( it.key(),  it.data() );
                    continue;
                }

                /* Check if special conversion is needed and add attribute
                 * into Contact class
                 */
                switch( *find ) {
                    /*
                      case Qtopia::AddressUid:
                      contact.setUid( it.data().toInt() );
                      break;
                      case Qtopia::AddressCategory:
                      contact.setCategories( Qtopia::Record::idsFromString( it.data( )));
                      break;
                    */
                case FIELDID_ACTION:
                    action = OPimRecord::ChangeAction(it.data().toInt());
                    owarn << "ODefBack(journal)::ACTION found: " << action << oendl;
                    break;
                default: // no conversion needed add them to the map
                    contactMap.insert( *find, it.data() );
                    break;
                }
            }
            /* now generate the Contact contact */
            OPimContact contact( contactMap );

            for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) {
                contact.setCustomField( customIt.key(),  customIt.data() );
            }

            applyAction( action, contact );

            /* Move to next element */
            element = element->nextChild();
        }

        m_journalEnabled = true;
        
        return true;
    }
    else {
        owarn << "XML document null!" << oendl;
        return false;
    }
}
Esempio n. 10
0
void MainWindow::on_actionDict_triggered()
{
    initDict();
    initFirstLetter();
}