コード例 #1
0
int
main(int argc, char *argv[])
{
    if (argc != 4) {
        printf("usage: bigdemo -create|-check count filename\n");
        return 0;
    }
    
    int count = strtol(argv[2], NULL, 0);
    const char *filename = argv[3];
    
    // Access the file, declare the layout and open a view
    c4_Storage storage(filename, true);
    c4_View vRoot = storage.GetAs("items[_B[name:S,data:B]]");
    // Open the blocked version of this base view.
    c4_View vStuff = vRoot.Blocked();

    // Declare our property accessors.
    c4_StringProp rName("name");
    c4_BytesProp rData("data");
    
    if (strcmp("-create", argv[1]) == 0) {
        
        // Create some data to pad out the file.
        char name[34];
        char garbage[1024];
        randfill(garbage, sizeof(garbage));
        c4_Bytes data(garbage, sizeof(garbage));

        // Pre-size the view to speed up the creation
        vStuff.SetSize(count);
        for (int n = 0; n < count; ++n) {
            sprintf_s(name, sizeof(name), "item%d", n);
            c4_RowRef row = vStuff[n];
            rData(row) = data;
            rName(row) = name;
        }
        
        // Finally actually write this to a file.
        storage.Commit();

    } else {

        char name[34];
        sprintf_s(name, sizeof(name), "item%d", count);
        
        int row = vStuff.Find(rName[name]);
        printf("looking for '%s' returned row %d\n", name, row);
        if (row == -1)
            printf("error\n");
        else
            printf("found '%s'\n", (const char *)rName(vStuff[row]));

    }
    return 0;
}
コード例 #2
0
ファイル: ogrewidget.cpp プロジェクト: sartraher/exodus
/**
 * @brief init the object
 * @author kito berg-taylor
 */
void OgreWidget::init()
{
  // create the main ogre object
  mOgreRoot = new Ogre::Root;

  mOgreRoot->loadPlugin("RenderSystem_GL");
  Ogre::String rName("OpenGL Rendering Subsystem");
  Ogre::RenderSystemList rList = mOgreRoot->getAvailableRenderers();
  Ogre::RenderSystemList::iterator it = rList.begin();
  Ogre::RenderSystem *rSys = 0;
  while(it != rList.end())
  {
    rSys = * (it++);
    Ogre::String strx=rSys->getName();
    if(strx == rName)
    {
      mOgreRoot->setRenderSystem(rSys);
      break;
    }
  }
   QString dimensions = QString( "%1x%2" )
                    .arg(this->width())
                    .arg(this->height());
 
  rSys->setConfigOption( "Video Mode", dimensions.toStdString() );
 
  // initialize without creating window
  mOgreRoot->getRenderSystem()->setConfigOption( "Full Screen", "No" );
  mOgreRoot->saveConfig();
  mOgreRoot->initialise(false); // don't create a window
}
コード例 #3
0
void
RtedTransformation::changeReturnStmt(ReturnInfo rinfo)
{
  SgReturnStmt* const   rstmt = rinfo.stmt;
  SgExpression* const   returnExpr = rstmt->get_expression();

  requiresParentIsBasicBlock(*rstmt);

  if (!returnExpr)
  {
    // function returns a value but return statement has no expression
    insertErrorReport(*rstmt, "return statement is expected to return a value");
    return;
  }

  // We need to build a new variable of type returnExpr
  // \pp why do we have to do that?
  //     most likely b/c exitScope clears all local pointers ...
  SgScopeStatement*      scope = rstmt->get_scope();
  SgType* const          typeRet = returnExpr->get_type();
  std::string            name = "rstmt";

  ROSE_ASSERT(scope);
  name.append(scope->get_qualified_name().str());

  SgName                 rName( name );
  SgAssignInitializer*   init = SB::buildAssignInitializer(returnExpr);
  SgVariableDeclaration* resDecl = SB::buildVariableDeclaration( rName, typeRet, init, scope );
  SgInitializedName&     resVar = SI::getFirstVariable(*resDecl);

  SgVarRefExp* const     vexp = SB::buildVarRefExp(rName, scope);
  SgStatement* const     newRtnStmt = SB::buildReturnStmt( vexp );

  SI::replaceStatement( rstmt, newRtnStmt );
  SI::insertStatementBefore( newRtnStmt, resDecl );

  Sg_File_Info* const    fileinfo = scope->get_endOfConstruct();

  // handle C++ only if the function returns a pointer
  if (rinfo.filetype != ftCxx)
  {
    SgStatement* const   exitStmt = (rinfo.expected_return == ReturnInfo::rtValue)
                                          ? buildExitBlockStmt(rinfo.open_blocks, *scope, fileinfo)
                                          : buildDelayedLeakCheckExitStmt(rinfo.filetype, rinfo.open_blocks, *scope, resVar, fileinfo)
                                          ;

    SI::insertStatementBefore( newRtnStmt, exitStmt );
  }
  else if (rinfo.expected_return == ReturnInfo::rtIndirection)
  {
    SgStatement* const   exitStmt = buildDelayedLeakCheckExitStmt(rinfo.filetype, rinfo.open_blocks, *scope, resVar, fileinfo);

    SI::insertStatementBefore( newRtnStmt, exitStmt );
  }
}
コード例 #4
0
ファイル: randomUserGen.c プロジェクト: joshbarry92/Personal
	int main()
	{
		//Seed Random Number Gen using MS * SEC
		struct timeb tmb;
		ftime(&tmb);
		srand(tmb.millitm * tmb.time);
		//Call Function to create Random Names
		rName();
		//End Program
		return 0;
		
	}
コード例 #5
0
ファイル: motet.c プロジェクト: cckayne/MOTE
int main(int argc, char *argv[])
{
	// stir depth and nonce length
	ub4 dep, sdep = MAXM, lnce = NLEN;
	ub4 rounds = 7;
	#ifdef MOTE-REPO
	enum CSPRNG rng = MOTE8;
	enum CSPRNG hasher = BB512;
	#else
	#ifdef BB-REPO
	enum CSPRNG rng = BB128;
	enum CSPRNG hasher = MOTE32;	
	#else
	enum CSPRNG rng = MOTE32;
	enum CSPRNG hasher = BB512;
	#endif
	#endif
	enum ciphermode cmode   = cmNone;
	enum ciphertype ctype	= ctNone;
	enum outputform oform	= ofASC;
	// input: message & key-phrase
	char msg[MAXM] = ""; 
	char key[MAXM] = "";
	// ciphertext & plaintext
	char ctx[MAXM], ptx[MAXM];
	// derived & stretched key
	char kdf[MAXK] = "";
	// IV/nonce
	char nce[MAXK] = "";
	// check the command line
	if (argc >= 5) {
		if ((argc>=2) && strlen(argv[1])<MAXM) strcpy(msg,argv[1]);
		if ((argc>=3) && strlen(argv[1])<MAXK) strcpy(key,argv[2]);
		if (argc>=4)
			if ((strcmp(argv[3],"d")==0) || (strcmp(argv[3],"D")==0))
				 cmode = cmDecipher; else
			if ((strcmp(argv[3],"e")==0) || (strcmp(argv[3],"E")==0)) 
				 cmode = cmEncipher; else cmode = cmNone;
		if (argc>=5)
			#ifdef NEVER
			if ((strcmp(argv[4],"v")==0) || (strcmp(argv[4],"V")==0))
				 ctype = ctVernam; else
			#endif
			if ((strcmp(argv[4],"c")==0) || (strcmp(argv[4],"C")==0))
				 ctype = ctCaesar; else
			if ((strcmp(argv[4],"m")==0) || (strcmp(argv[4],"M")==0)) 
				ctype = ctCaesarM; else ctype = ctNone;
		if (argc>=6) 
			if ((strcmp(argv[5],"a")==0) || (strcmp(argv[5],"A")==0))
				oform = ofASC; else oform = ofHEX;
		if (argc>=7) rng = (enum CSPRNG)(atoi(argv[6]) % 7);
	}
	// sanity checks
	if (TRUE) {
		if ((strlen(msg)<MINM) || (strlen(key)<MINK)) { info(); exit(0); }
		if ((cmode==cmNone) || (ctype==ctNone))       { info(); exit(0); }
		// only hex output available for Vernam
		if (ctype==ctVernam) oform=ofHEX;
		// output mode MOD 26? (not possible with Vernam)
		if ((oform==ofASC) && (ctype!=ctVernam)) { MOD=26; START='A'; }
		// no nonce scrambling or mixing available with hex output
		if (oform==ofHEX) SCRAMBLER=NONCE=MIX=FALSE;
	}
	// B E G I N  P R E P A R A T I O N
	// preliminary seeding
	rSeedAll(key,rounds);
	
	if (SCRAMBLER) {
		sdep = SetDepth(rng,strlen(key));
		#ifdef LOG
		char tmp[12]=""; sprintf(tmp,"%d",sdep);
		log_add("RNG",rName(rng));
		log_add("HSH",rName(hasher));
		log_add("DEP",tmp);
		#endif
	}
	
	if (NONCE) {
		// obtain nonce/IV hash of fixed or random length
		strcpy(nce,rNonce(hasher,FALSE));
		// note nonce length for later
		lnce = strlen(nce);
	}

	// Key-derivation starts:
	if (TRUE) {
		// 1) seed MOTE with a key-derived hash
		strcpy(kdf,rHash(hasher,key,rStateSize(rng)*4));
		rSeed(rng,kdf,rounds);
		// 2) calculate stir-depth
		dep = rDepth(rng,kdf);
		// 3) warm up MOTE with <dep> rounds
		rStir(rng,dep); 
	}
	#ifdef TEST
		#ifdef LOG
		log_add("DKY",leftstr(kdf,LINE));
		#endif
	#endif
	// Key-derivation ends.
	
	if (SCRAMBLER) {
		// prepare scrambler's random pool
		RandPool_Fill(rng);
	}
	// E N D  P R E P A R A T I O N.
	
	// B E G I N  M A I N  C I P H E R  S E Q U E N C E
	// Mode: Encipher
	if (cmode==cmEncipher) {
		// pre-process message if output is mod 26
		if (oform==ofASC) strcpy(msg, PreProcessText(msg));
			#ifdef LOG
			if (oform==ofASC) log_add("MSG",msg);
			#endif
		// Encrypt: Vernam XOR
		if (ctype==ctVernam)  strcpy(ctx, Vernam(rng,msg));
		// Encrypt: Caesar MOD
		if (ctype==ctCaesar)  strcpy(ctx, rCaesarStr(rng, cmEncipher, msg, MOD, START));
		// Encrypt: Caesar MIX
		if (ctype==ctCaesarM) strcpy(ctx, rmCaesarStr(rng, cmEncipher, msg, MOD, START));
		// convert to hexadecimal as appropriate
		if (oform==ofHEX) strcpy(ctx,ascii2hex(ctx));
			#ifdef LOG
			log_add(" CT",ctx);
			#endif
		if (MIX) {
			// Mix: Vigenere-cipher the ciphertext on the nonce
			strcpy(ctx,Vig(rng,cmode,ctx,nce,MOD,START,FALSE));
				#ifdef LOG
				log_add("NCE",nce);
				log_add("VCT",ctx);
				#endif
		}
		if (NONCE) {
			// append ciphertext to nonce
			strcat(nce,ctx); strcpy(ctx,nce);
				#ifdef LOG
				log_add("NCT",ctx);
				#endif
		}
		if (SCRAMBLER) {
			// prepare scrambler context & scramble ciphertext
			InitRandPairs(rng,sdep,strlen(ctx));
			strcpy(ctx,Scrambled(ctx,sdep));
				#ifdef LOG
				log_add("SCT",ctx);
				#endif
		}
	}
	// Mode: Decipher
	if (cmode==cmDecipher) {
		// Convert hexadecimal ciphertext to ASCII (not in mod 26)
		if (oform==ofHEX) strcpy(ctx, hex2ascii(msg)); else strcpy(ctx, msg);
		if (SCRAMBLER) {
				#ifdef LOG
				log_add("SCT",ctx);
				#endif
			// prepare scrambler context & unscramble ciphertext
			InitRandPairs(rng,sdep,strlen(ctx));
			strcpy(ctx,unScrambled(ctx,sdep));
				#ifdef LOG
				log_add("UST",ctx);
				#endif
		}
		if (NONCE) {
			// detach ciphertext from nonce
			strcpy(nce,leftstr(ctx,lnce));
			strcpy(ctx,rightstr(ctx,strlen(msg)-lnce));
				#ifdef LOG
				log_add("VCT",ctx);
				log_add("NCE",nce);
				#endif
		}
		if (MIX) {
			// Un-mix: Vigenere-decipher the ciphertext on the nonce
			strcpy(ctx,Vig(rng,cmode,ctx,nce,MOD,START,FALSE));
				#ifdef LOG
				log_add("UVC",ctx);
				#endif
		}
		// Decrypt: Vernam XOR
		if (ctype==ctVernam) strcpy(ptx, Vernam(rng,ctx));
		// Decrypt: Caesar MOD
		if (ctype==ctCaesar)  strcpy(ptx, rCaesarStr(rng, cmDecipher, ctx, MOD, START));
		// Decrypt: Caesar MIX
		if (ctype==ctCaesarM) strcpy(ptx, rmCaesarStr(rng, cmDecipher,ctx, MOD, START));
		// post-process plaintext if output is mod 26
		if (oform==ofASC) strcpy(ptx, PostProcessText(ptx));
	}  
	// E N D  M A I N  C I P H E R  S E Q U E N C E .
	#ifdef LOG
	log_show ();
	log_clear();
	#endif
	// P R O G R A M  O U T P U T
	if ((strcmp(ptx,"") != 0) || (strcmp(ctx,"") != 0)) {
		// Mode: Encipher
		if (cmode==cmEncipher) puts(ctx);
		// Mode: Decipher
		if (cmode==cmDecipher) puts(ptx);
		
		// belt'n'braces memory wipe
		if (TRUE) {
			rResetAll(); rResetAll();
			memset(msg,0,sizeof(msg));memset(msg,0xFF,sizeof(msg));memset(msg,0,sizeof(msg));
			memset(key,0,sizeof(key));memset(key,0xFF,sizeof(key));memset(key,0,sizeof(key));
			memset(kdf,0,sizeof(kdf));memset(kdf,0xFF,sizeof(kdf));memset(kdf,0,sizeof(kdf));
			memset(ctx,0,sizeof(ctx));memset(ctx,0xFF,sizeof(ctx));memset(ctx,0,sizeof(ctx));
			memset(ptx,0,sizeof(ptx));memset(ptx,0xFF,sizeof(ptx));memset(ptx,0,sizeof(ctx));
			dep=0;
		}
		
	} else info();

	return 0;
}