int main(int argc, char** argv) {
  if(!parseOption(argc, argv)) {
    fprintf(stderr, "failed to parse option\n");
    return 1;
  }

  BCCScriptRef script;

  if((script = loadScript()) == NULL) {
    fprintf(stderr, "failed to load source\n");
    return 2;
  }

#if 0
  if(printTypeInformation && !reflection(script, stderr)) {
    fprintf(stderr, "failed to retrieve type information\n");
    return 3;
  }
#endif

  printPragma(script);

  if(printListing && !disassemble(script, stderr)) {
    fprintf(stderr, "failed to disassemble\n");
    return 5;
  }

  if(runResults && !runMain(script, argc, argv)) {
    fprintf(stderr, "failed to execute\n");
    return 6;
  }

  return 0;
}
Exemple #2
0
 void invoke(const std::string& cmd)
 {
   GoString str;
   str.p = const_cast<char*>(cmd.c_str());
   str.n = static_cast<GoInt>(cmd.length());
   runMain(str);
 }
int SC_TerminalClient::run(int argc, char** argv)
{
	Options& opt = mOptions;

	if (!parseOptions(argc, argv, opt)) {
		return mReturnCode;
	}

	// finish argv processing
	const char* codeFile = 0;

	if (argc > 0) {
		codeFile = argv[0];
		opt.mDaemon = true;
		argv++; argc--;
	}

	opt.mArgc = argc;
	opt.mArgv = argv;

	// read library configuration file
	if (opt.mLibraryConfigFile) {
		int argLength = strlen(opt.mLibraryConfigFile);
		SC_LanguageConfig::readLibraryConfigYAML(opt.mLibraryConfigFile);
	} else
		SC_LanguageConfig::readDefaultLibraryConfig();

	// initialize runtime
	initRuntime(opt);

	// startup library
	mShouldBeRunning = true;
	compileLibrary();

	// enter main loop
	if (codeFile) executeFile(codeFile);
	if (opt.mCallRun) runMain();

	if (opt.mDaemon) {
		daemonLoop();
	}
	else {
		initInput();
		if( shouldBeRunning() ) startInput();
		if( shouldBeRunning() ) commandLoop();
		endInput();
		cleanupInput();
	}

	if (opt.mCallStop) stopMain();

	// shutdown library
	shutdownLibrary();
	flush();

	shutdownRuntime();

	return mReturnCode;
}
Exemple #4
0
void Daemon::run( bool detach ) {
    NOTE();

    if ( detach && !daemonize() )
         return;

    loop();
    if ( _runMain ) {
        runMain();
        exit();
    }
}
Exemple #5
0
int main()
{
    try
    {
        GlobalEvrionment g;
        parseSource(readFile("1.txt"), g);
        registerBuildinFunctions(g);
        runMain(g);
    }
    catch (const std::exception& e) {
        cout << "Exception : " << e.what() << endl;
    }
}
Exemple #6
0
int main(int argc, char *argv[])
{
    if (argc == 1) {
        puts("usage : interpreter file1 [file2 ...]");
        return 0;
    }

    try
    {
        registerBuildin();
        for (int i = 1; i < argc; ++i) parseFile(argv[i]);
        runMain();
    }
    catch (const exception& e) {
        cout << "Exception : " << e.what() << endl;
    }
}
Exemple #7
0
void BlackberryMain::startMain(int argc, char *argv[]) {
	g_quitRequested = false;
	// Receive events from window manager
	screen_create_context(&screen_cxt, 0);
	// Initialise Blackberry Platform Services
	bps_initialize();
	// TODO: Enable/disable based on setting
	sensor_set_rate(SENSOR_TYPE_ACCELEROMETER, 25000);
	sensor_request_events(SENSOR_TYPE_ACCELEROMETER);

	net::Init();
	startDisplays();
	screen_request_events(screen_cxt);
	navigator_request_events(0);
	dialog_request_events(0);
	vibration_request_events(0);
	NativeInit(argc, (const char **)argv, "/accounts/1000/shared/misc/", "app/native/assets/", "BADCOFFEE");
	NativeInitGraphics();
	audio = new BlackberryAudio();
	runMain();
}
Exemple #8
0
int main() {
    int childPid = 0;
    int ourPid = getpid();

    printf("Ainda existe apenas um processo (%d)\n", ourPid);

    childPid = fork();

    printf("Agora somos dois (%i)\n", getpid());

    if(childPid > 0) {
        runMain(ourPid, childPid);
    } else {
        if(childPid < 0) {
            checkError(childPid);
        } else {
            runChild();
        }
    }

    return 0;
}
Exemple #9
0
int main( )
{
	 Book b[NUM];                 /*定义实参一维数组存储图书记录*/
     int choice,n=0;              /*n赋值0*/
	 printf("Input information from a file or keyboard? [1(file)/2(keyboard)]\n"); /*询问信息输入方式*/
	 scanf("%d",&choice);         /*读入选择*/
	 if (choice == 1)
		n=readFile(b);            /*读取文件,记录条数返回赋值给n*/
	 else if (choice == 2)
	 {
		 printf("\nInput an integer to indicate how many pieces of information to be input: \n");
		 scanf("%d",&n);
		 n=readBook(b,n);
	 }
	 else
     {
		 printf("choice error!\n");      /*输入非1、2数字按默认方式执行,从文件读取*/
         printf("Execute by default:\n");
     }
	 if (!n)                     /*如果原来的文件为空*/
	 {
         // printf("Target file is empty!\n");
		 n=createFile(b);        /*则首先要建立文件,从键盘上读入一系列记录存于文件*/
	 }	 	 
	 do
	 {
	     menu();                 /*显示菜单*/
	     printf("Please input your choice: ");
	     scanf("%d",&choice);
	     if (choice>=0 && choice<=5)
			n=runMain(b,n,choice);    /*通过调用此函数进行一级功能项的选择执行*/
	     else 
		    printf("Error input,please input your choice again!\n");
	} while (choice);
	sortBook(b,n,1);                  /*存入文件前按ISBN由小到大排序*/
	saveFile(b,n);                    /*将结果存入文件*/
    return 0;
}
Exemple #10
0
int Runtime::runShell(const char *startupBas, int fontScale, int debugPort) {
  logEntered();

  os_graphics = 1;
  os_color_depth = 16;
  opt_interactive = true;
  opt_usevmt = 0;
  opt_file_permitted = 1;
  opt_graphics = true;
  opt_pref_bpp = 0;
  opt_nosave = true;

  _output->setTextColor(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
  _output->setFontSize(getStartupFontSize(_window));
  _initialFontSize = _output->getFontSize();
  if (fontScale != 100) {
    _fontScale = fontScale;
    int fontSize = (_initialFontSize * _fontScale / 100);
    _output->setFontSize(fontSize);
  }

  SDL_Init(SDL_INIT_AUDIO);
  SDL_AudioSpec desiredSpec;
  desiredSpec.freq = FREQUENCY;
  desiredSpec.format = AUDIO_S16SYS;
  desiredSpec.channels = 1;
  desiredSpec.samples = 2048;
  desiredSpec.callback = audio_callback;

  SDL_AudioSpec obtainedSpec;
  SDL_OpenAudio(&desiredSpec, &obtainedSpec);
  net_init();

  if (debugPort > 0) {
    appLog("Debug active on port %d\n", debugPort);
    g_lock = SDL_CreateMutex();
    g_cond = SDL_CreateCond();
    opt_trace_on = 1;
    g_debugBreak = SDL_TRUE;
    SDL_Thread *thread =
      SDL_CreateThread(debugThread, "DBg", (void *)(intptr_t)debugPort);
    SDL_DetachThread(thread);
  }

  if (startupBas != NULL) {
    String bas = startupBas;
    if (opt_ide == IDE_INTERNAL) {
      runEdit(bas.c_str());
    } else {
      runOnce(bas.c_str());
    }
    while (_state == kRestartState) {
      _state = kActiveState;
      if (_loadPath.length() != 0) {
        bas = _loadPath;
      }
      runOnce(bas.c_str());
    }
  } else {
    runMain(MAIN_BAS);
  }

  if (debugPort > 0) {
    SDL_DestroyCond(g_cond);
    SDL_DestroyMutex(g_lock);
  }

  debugStop();
  net_close();
  SDL_CloseAudio();
  _state = kDoneState;
  logLeaving();
  return _fontScale;
}