Example #1
0
int main(int argc, char* argv[])
{
 lua_State* L;
 Proto* f;
 int i=doargs(argc,argv);
 argc-=i; argv+=i;
 if (argc<=0) usage("no input files given",NULL);
 L=lua_open();
 luaB_opentests(L);
 for (i=0; i<argc; i++)
 {
  const char* filename=IS("-") ? NULL : argv[i];
  if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1));
 }
 f=combine(L,argc);
 if (listing) luaU_print(f);
 if (dumping)
 {
  FILE* D=fopen(output,"wb");
  if (D==NULL) cannot(output,"open","out");
  if (stripping) strip(L,f);
  luaU_dump(L,f,writer,D);
  if (ferror(D)) cannot(output,"write","out");
  fclose(D);
 }
 lua_close(L);
 return 0;
}
Example #2
0
int main(int argc, char* argv[])
{
	#ifdef _WIN32
	HMODULE module = LoadLibrary("lua_shared.dll");
#else
	void* module = dlopen("lua_shared.so", RTLD_LAZY);
#endif
	if(!luaL_loadfunctions(module, &LuaFunctions, sizeof(LuaFunctions)))
	{
		printf("Error loading lua_shared\n");
		return 1;
	}
	
	{
		lua_State* L;
		struct Smain s;
		int i=doargs(argc,argv);
		argc-=i; argv+=i;
		if (argc<=0) usage("no input files given");
		L=lua_open();
		luaL_openlibs(L);
		//lua_register(L, "print", glua_print);
		if (L==NULL) fatal("not enough memory for state");
		s.argc=argc;
		s.argv=argv;
		if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1));
		lua_close(L);
	}
	return EXIT_SUCCESS;
}
Example #3
0
File: testmd.c Project: 3ki5tj/zcom
int main(int argc, char **argv)
{
  cago_t *go;
  int teql = 100000, tmax = 500000, trep = 10000, ncont;
  real mddt = 0.002f, thermdt = 0.02f;
  real epav, epdv, rdav, rddv, rmsd;
  av_t avep[1], avrmsd[1];

  doargs(argc, argv);
  if ((go = cago_open(fnpdb, kb, ka, kd1, kd3, nbe, nbc, rcc,
                      PDB_CONTACT_HEAVY, 4, CAGO_VERBOSE)) == NULL) {
    fprintf(stderr, "cannot initialize from %s\n", fnpdb);
    return 1;
  }
  cago_initmd(go, 1, 0.1, 0.0);
  rmsd = cago_rmsd(go, go->x, NULL);
  ncont = cago_ncontacts(go, go->x, 1.2, NULL, NULL);
  printf("%s n %d, tp %.3f, tps %.3f, epot %g, %g (ref), rmsd %g, cont %d/%d\n",
      fnpdb, go->n, tp, tps, go->epot, go->epotref,
      rmsd, ncont, go->ncont);

  cago_mdrun(go, mddt, thermdt, tps, tp, avep, avrmsd,
     teql, tmax, trep);
  epav = av_getave(avep);
  epdv = av_getdev(avep);
  rdav = av_getave(avrmsd);
  rddv = av_getdev(avrmsd);
  printf("tp %.3f, tps %.3f, epot %.2f(%.2f), rmsd %.4f(%.4f)\n",
      tp, tps, epav, epdv, rdav, rddv);
  cago_writepos(go, go->x, go->v, "cago.pos");
  cago_close(go);
  return 0;
}
Example #4
0
int main(int argc, char **argv)
{
  (void) argtp;
  doargs(argc, argv);
  run();
  return 0;
}
Example #5
0
int main(int argc, char* argv[]) {
    const char *input_luac, *opcodes_def;
    int i;
    lua_State* L;
    Proto* f;
    FILE* D;

    gargc = argc;
    gargv = argv;
    i = doargs(argc,argv);
    argc -= i;
    argv += i;

    if (argc < 1) {
        usage("need 1 arguments at least", NULL);
    }

    L = lua_open();
    glstate = L;
    //luaB_opentests(L);

    input_luac = argv[0];
    if (luaL_loadfile(L, input_luac) != 0) {
        fatal(lua_tostring(L, -1));
    }
    f = toproto(L, -1);

    if (cmp_gen_lua || cmp_gen_luac) {
        Proto* input_proto = f;
        Proto* allopcodes_proto;
        const char* buff = cmp_gen_lua ? allopcodes_lua : allopcodes_luac;
        int bufflen = cmp_gen_lua ? allopcodes_lua_len : allopcodes_luac_len;
        if (luaL_loadbuffer(L, buff, bufflen, "allopcodes.lua") != 0) {
            fatal(lua_tostring(L, -1));
        }
        allopcodes_proto = toproto(L, -1);
        CompareAndGenOpcodes(input_proto, allopcodes_proto);
    } else {
        opcodes_def = (argv[1]) ? (argv[1]) : OPCODES_TXT;
        if (!generateOp2op(opcodes_def)) {
            fprintf(stderr, "opcodes.txt file: %s format error!", opcodes_def);
            return EXIT_FAILURE;
        }
        swapOpCode(f);

        D = (output == NULL) ? stdout : fopen(output, "wb");
        if (D == NULL) cannot("open", output);
        lua_lock(L);
        luaU_dump(L, f, writer, D, 0);
        lua_unlock(L);
        if (ferror(D)) cannot("write", output);
        if (fclose(D)) cannot("close", output);

        printf("%s generated!\n", output);
    }

    lua_close(L);
    return EXIT_SUCCESS;
}
Example #6
0
int luac_main(int argc, char* argv[]) {
  lua_State* L;
  struct Smain s;
  int i=doargs(argc,argv);
  argc-=i; argv+=i;
  if (argc<=0) usage("no input files given");
  L=lua_open();
  if (L==NULL) fatal("not enough memory for state");
  s.argc=argc;
  s.argv=argv;
  if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1));
  lua_close(L);
  return EXIT_SUCCESS;
}
Example #7
0
File: luac.c Project: bysdxt/xLua
int luac_main(int argc, char* argv[])
{
 lua_State* L;
 int i=doargs(argc,argv);
 argc-=i; argv+=i;
 if (argc<=0) usage("no input files given");
 L=luaL_newstate();
 if (L==NULL) fatal("cannot create state: not enough memory");
 lua_pushcfunction(L,&pmain);
 lua_pushinteger(L,argc);
 lua_pushlightuserdata(L,argv);
 if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));
 lua_close(L);
 return EXIT_SUCCESS;
}
Example #8
0
//initialize and process command line parameters or user input
int main(int argc, char *argv[]) {
    printf("\n%s %s, (C) 2008-2011 AJ Siemelink\n", ExeName, Version);
    printf("single threaded, no hashing, mode=%s, extract=%s, count=%s\n",
           PERFT_NAME,
           EXTRACT_NAME,
           COUNT_NAME
           );
    Bitboard::init();
    _board.setstartpos();

    //arg-mode
    if (argc>=2) return doargs(argc, argv);

    //interactive mode
    return doinput();
}
Example #9
0
File: is1.c Project: 3ki5tj/alge
int main(int argc, char **argv)
{
  ising_t *is;

  doargs(argc, argv);
  is = is2_open(L);

  /* read in the density of states */
  die_if (is2_loadlogdos(is, NULL) != 0,
      "no dos for the %dx%d model\n", L, L);

  run(is, nsteps);
  is2_close(is);
  //mtsave(NULL);
  return 0;
}
Example #10
0
int main(int argc, char* argv[])
{
  LuaThread* L;
  int i=doargs(argc,argv);
  argc-=i; argv+=i;
  if (argc<=0) usage("no input files given");
  L=luaL_newstate();
  if (L==NULL) fatal("cannot create state: not enough memory");

  L->stack_.push(pmain);

  lua_pushinteger(L,argc);
  L->stack_.push( LuaValue::Pointer(argv) );
  if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));
  lua_close(L);
  return EXIT_SUCCESS;
}
Example #11
0
File: psort.c Project: BWK/os161
int
main(int argc, char *argv[])
{
	initprogname(argc > 0 ? argv[0] : NULL);

	doargs(argc, argv);
	correctsize = (off_t) (numkeys*sizeof(int));

	setdir();

	genkeys();
	sort();
	validate();
	complainx("Succeeded.");

	unsetdir();

	return 0;
}
Example #12
0
File: volrw.c Project: 3ki5tj/tstat
int main(int argc, char **argv)
{
  avp_t *avp;
  //hist_t *hs;
  //int row, ver;
  //unsigned fflags;
  //double vmin, vmax, vdel;

  doargs(argc, argv);

  die_if ((avp = avp_load(fnavp)) == NULL, "cannot load avp from %s\n", fnavp);
  //histgetinfo(fnhis, &row, &vmin, &vmax, &vdel, &ver, &fflags);
  //hs = hs_open(1, vmin, vmax, vdel);
  //die_if (hs_load(hs, fnhis, HIST_VERBOSE) != 0, "cannot load histogram from %s\n", fnhis);
  output(avp, "fe.dat");
  //hs_close(hs);
  avp_close(avp);
  return 0;
}
Example #13
0
int main(int argc, char* argv[])
#endif // #if LUA_COMPILER
{
 lua_State* L;
 struct Smain s;
 
 int test=1;
 target.little_endian=*(char*)&test;
 target.sizeof_int=sizeof(int);
 target.sizeof_strsize_t=sizeof(strsize_t);
 target.sizeof_lua_Number=sizeof(lua_Number);
 target.lua_Number_integral=(((lua_Number)0.5)==0);
 target.is_arm_fpa=0;

#if LUA_COMPILER
 int f=setjmp(ebuf);
 if (f == 0) {
#endif
 int i=doargs(argc,argv);
 argc-=i; argv+=i;
 if (argc<=0) usage("no input files given");
 L=lua_open();
 if (L==NULL) fatal("not enough memory for state");
 s.argc=argc;
 s.argv=argv;
 if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1));
 lua_close(L);
#if LUA_COMPILER
 }
 /*
  * If we're using luac on the MCU,
  * set these variables to their
  * default value before return;
  */
 listing=0;            /* list bytecodes? */
 dumping=1;            /* dump bytecodes? */
 stripping=0;          /* strip debug information? */
 output=Output;        /* actual output file name */
 progname=PROGNAME;    /* actual program name */
#endif
 return EXIT_SUCCESS;
}
Example #14
0
int main(int argc, const char* argv[])
{
 Proto** P,*tf;
 int i=doargs(argc,argv);
 argc-=i; argv+=i;
 if (argc<=0) usage("no input files given",NULL);
 L=lua_open(0);
 P=luaM_newvector(L,argc,Proto*);
 for (i=0; i<argc; i++)
  P[i]=load(IS("-")? NULL : argv[i]);
 tf=combine(P,argc);
 if (dumping) luaU_optchunk(tf);
 if (listing) luaU_printchunk(tf);
 if (testing) luaU_testchunk(tf);
 if (dumping)
 {
  if (stripping) strip(tf);
  luaU_dumpchunk(tf,efopen(output,"wb"));
 }
 return 0;
}
Example #15
0
int EiC_run(int argc, char **argv)
{
    char * n2 = doargs(argc,argv);
    int h = EiC_interActive;
    code_t code;
    
    EiC_interActive = 0;  /* turn off interactive mode */

    code = EiC_ENV->CODE;
    EiC_ENV->CODE.nextinst = EiC_ENV->CODE.binst = 0;
    EiC_ENV->CODE.inst = NULL;
    EiC_ENV->CODE.prev = &code;
    /*sp = EiC_ENV->sp;*/


    EiC_prolineString(n2);
    runEiC();


    if(!EiC_Include_file(argv[0],1))
	return 0;
    else 
	runEiC();

    if(doEntry()) 
	runEiC();

    /* rem: runEiC will call free_env_code */
    EiC_ENV->CODE.prev = NULL;
    EiC_ENV->CODE = code;
    /*EiC_ENV->sp = sp;*/

    xfree(n2);
	n2 = NULL; //maks

    EiC_interActive = h;
    return 1;
}    
Example #16
0
File: luac.c Project: ARMinARM/elua
int main(int argc, char* argv[])
{
 lua_State* L;
 struct Smain s;
 
 int test=1;
 target.little_endian=*(char*)&test;
 target.sizeof_int=sizeof(int);
 target.sizeof_strsize_t=sizeof(strsize_t);
 target.sizeof_lua_Number=sizeof(lua_Number);
 target.lua_Number_integral=(((lua_Number)0.5)==0);
 target.is_arm_fpa=0;

 int i=doargs(argc,argv);
 argc-=i; argv+=i;
 if (argc<=0) usage("no input files given");
 L=lua_open();
 if (L==NULL) fatal("not enough memory for state");
 s.argc=argc;
 s.argv=argv;
 if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1));
 lua_close(L);
 return EXIT_SUCCESS;
}
Example #17
0
int main(int argc, char* argv[])
{
	int oargc;
	char** oargv;
	char tmp[256];
 lua_State* L;
 Proto* f;
 int i;
 oargc = argc;
 oargv = argv;
 LDS2 = NULL;
 i=doargs(argc,argv);
 argc-=i; argv+=i;
 if (argc<=0) usage("no input files given",NULL);
 L=lua_open();
 glstate = L;
 luaB_opentests(L);
 for (i=0; i<argc; i++)
 {
  const char* filename=IS("-") ? NULL : argv[i];
  if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1));
 }
 if (disassemble) {
	 printf("; This file has been disassembled using luadec " VERSION " by sztupy (http://winmo.sztupy.hu)\n");
   printf("; Command line was: ");
 } else {
	 printf("-- Decompiled using luadec " VERSION " by sztupy (http://winmo.sztupy.hu)\n");
	 printf("-- Command line was: ");
 }
 for (i=1; i<oargc; i++) {
	 printf("%s ",oargv[i]);
 }
 printf("\n\n");
 f=combine(L,argc);
 if (guess_locals) {
	 luaU_guess_locals(f,0);
 }
 if (lds2) {
	int i,i2;
	for (i=-1; i<f->sizep; i++) {
		Proto * x = f;
		if (i!=-1) {
			x = f->p[i];
		}
		for (i2=0; i2<x->sizelocvars; i2++) {
			if (i2!=0) printf(",");
			printf("%d-%d",x->locvars[i2].startpc,x->locvars[i2].endpc);
		}
		printf(";");
	}
	return 0;
 }
 if (functions) {
	 if (disassemble) {
		 sprintf(tmp,"%d",functions);
		 luaU_disassemble(f,debugging,functions,tmp);
	 } else {
		 luaU_decompileFunctions(f, debugging, functions);
	 }
 }
 else {
	 if (disassemble) {
		 sprintf(tmp,"");
		 luaU_disassemble(f,debugging,0,tmp);
	 } else {
		 luaU_decompile(f, debugging);
	 }
 }
 return 0;
}
Example #18
0
void main(int argc, char *argv[])
{
	doargs(argc,argv);
	dosphere();
 	exit(0);
}
Example #19
0
int main(int argc, char* argv[]) {
	lua_State* L;
	const char *destfile, *destnum, *srcfile, *srcnum;
	Proto *fdestroot, *fsrcroot, *fparent, *fdest, *fsrc;
	int cdest, csrc;
	char *realdestnum = NULL, *realsrcnum = NULL;
	FILE* D;
	int diff, i;

	gargc = argc;
	gargv = argv;
	i = doargs(argc,argv);
	argc -= i;
	argv += i;

	if (printfuncnum && argc < 1) {
		usage("need 1 arguments for -pn at least", NULL);
	}
	if (argc < 4) {
		usage("need 4 arguments at least", NULL);
	}

	L = lua_open();
	glstate = L;
	luaB_opentests(L);

	destfile = argv[0];
	destnum = argv[1];
	if (luaL_loadfile(L, destfile) != 0) {
		fatal(lua_tostring(L, -1));
	}
	fdestroot = toproto(L, -1);

	if (printfuncnum) {
		printf("%d\n",0);
		printFuncStructure(fdestroot, "  0_");
		lua_close(L);
		return EXIT_SUCCESS;
	}

	realdestnum = (char*)calloc(strlen(destnum)+1, sizeof(char));
	fparent = findParentFunction(fdestroot, destnum, &cdest, realdestnum);
	if (cdest < 0) {
		if (realdestnum) { free(realdestnum); realdestnum = NULL; }
		fatal("cannot find dest function");
	}
	if (fparent == NULL) {
		fdest = fdestroot;
	} else {
		fdest = fparent->p[cdest];
	}

	srcfile = argv[2];
	srcnum = argv[3];
	if (luaL_loadfile(L, srcfile) != 0) {
		fatal(lua_tostring(L, -1));
	}
	fsrcroot = toproto(L, -1);
	realsrcnum = (char*)calloc(strlen(srcnum)+1, sizeof(char));
	fsrc = findParentFunction(fsrcroot, srcnum, &csrc, realsrcnum);
	if (csrc < 0) {
		if (realdestnum) { free(realdestnum); realdestnum = NULL; }
		if (realsrcnum) { free(realsrcnum); realsrcnum = NULL; }
		fatal("cannot find src function");
	}
	if (fsrc == NULL) {
		fsrc = fsrcroot;
	} else {
		fsrc = fsrc->p[csrc];
	}

	if (!replace_sub){
		if (fparent == NULL) {
			if (realdestnum) { free(realdestnum); realdestnum = NULL; }
			if (realsrcnum) { free(realsrcnum); realsrcnum = NULL; }
			fatal("cannot use root as dest function");
		}
		fprintf(stderr, "Replacing %s %s with %s %s ...\n", destfile, realdestnum, srcfile, realsrcnum);
		diff = replaceFunction(fparent, cdest, fsrc);
		fprintf(stderr, "1 function replaced ok.\n");
	} else {
		fprintf(stderr, "Replacing sub functions of %s %s with those of %s %s ...\n", destfile, realdestnum, srcfile, realsrcnum);
		diff = replaceSubFunctions(fdest, fsrc);
		fprintf(stderr, "%d function replaced ok.", MIN(fdest->sizep, fsrc->sizep));
		if (fdest->sizep != fsrc->sizep) {
			fprintf(stderr, " The dest has %d sub functions, but the src has %d . Please have a check.\n", fdest->sizep, fsrc->sizep);
		} else {
			fprintf(stderr, "\n");
		}
	}

	if (realdestnum) { free(realdestnum); realdestnum = NULL; }
	if (realsrcnum) { free(realsrcnum); realsrcnum = NULL; }

	if (strict == 1 && diff > 0){
		fatal("strip mode on and incompatible functions found, stop writing output.");
	}

	D = (output == NULL) ? stdout : fopen(output, "wb");
	if (D == NULL) cannot("open");
	lua_lock(L);
	luaU_dump(L, fdestroot, writer, D, 0);
	lua_unlock(L);
	if (ferror(D)) cannot("write");
	if (fclose(D)) cannot("close");

	printf("%s generated!\n", output);

	lua_close(L);
	return EXIT_SUCCESS;
}
Example #20
0
File: xymc.c Project: 3ki5tj/alge
int main(int argc, char **argv)
{
  doargs(argc, argv);
  run();
  return 0;
}