Exemplo n.º 1
0
QSettings* createQSettings(const QString& KEY)
{
    QSettings* settings = 0;

#ifdef SPEEDCRUNCH_PORTABLE
#if defined(Q_WS_WIN)
    // Portable Windows version: settings are from INI file in same directory.
    QString appPath = QApplication::applicationFilePath();
    int ii = appPath.lastIndexOf('/');
    if (ii > 0)
        appPath.remove(ii, appPath.length());
    QString iniFile = appPath + '/' + KEY + ".ini";
    settings = new QSettings(iniFile, QSettings::IniFormat);
#elif defined(Q_WS_X11) || defined (Q_WS_QWS)
    // Portable X11 version: settings are from INI file in the same directory.
    BrInitError error;
    if (br_init(& error) == 0 && error != BR_INIT_ERROR_DISABLED) {
        qDebug("Warning: BinReloc failed to initialize (error code %d)", error);
        qDebug("Will fallback to hardcoded default path.");
    }

    const char* prefix = br_find_prefix(0);
    QString iniFile = QString(prefix) + '/' + KEY + QLatin1String(".ini");
    free(prefix);
    settings = new QSettings(iniFile, QSettings::IniFormat);
#endif // Q_WS_WIN / Q_WS_X11 || Q_WS_QWS
#else // SPEEDCRUNCH_PORTABLE
    settings = new QSettings(QSettings::NativeFormat, QSettings::UserScope, KEY, KEY);
#endif // SPEEDCRUNCH_PORTABLE

    return settings;
}
Exemplo n.º 2
0
int brctl_main(int argc, char **argv)
{
    if (argc == 1) {
        fprintf(stderr, "try to be professional!\n");
        return -1;
    }
    br_init();
    if (!strcmp(argv[1], "addif")) {
        if (ifexists(argv[3]))
            br_add_interface(argv[2], argv[3]);
    }
    if (!strcmp(argv[1], "delif")) {
        if (ifexists(argv[3]))
            br_del_interface(argv[2], argv[3]);
    }
    if (!strcmp(argv[1], "addbr")) {
        br_add_bridge(argv[2]);
    }
    if (!strcmp(argv[1], "stp")) {
        br_set_stp_state(argv[2], atoi(argv[3]));
    }
    if (!strcmp(argv[1], "delbr")) {
        if (!ifexists(argv[2]))
            return -1;
        br_del_bridge(argv[2]);
    }
    if (!strcmp(argv[1], "show")) {
        br_cmd_show();
    }
    br_shutdown();
}
Exemplo n.º 3
0
void InitDirs(const std::string& argv0) {
    if (g_initialized)
        return;

    /* store working dir.  some implimentations get the value of initial_path
     * from the value of current_path the first time initial_path is called,
     * so it is necessary to call initial_path as soon as possible after
     * starting the program, so that current_path doesn't have a chance to
     * change before initial_path is initialized. */
    fs::initial_path();

    br_init(0);

    fs::path p = GetUserDir();
    if (!exists(p)) {
        fs::create_directories(p);
    }

    p /= "save";
    if (!exists(p)) {
        fs::create_directories(p);
    }

    InitBinDir(argv0);

    g_initialized = true;
}
SYLPH_BEGIN_NAMESPACE

LinuxBundleAppSelf::LinuxBundleAppSelf(int argc, char * argv[]) {
    // First, make binreloc work...
    BrInitError error;

    if (br_init(&error) == 0 && error != BR_INIT_ERROR_DISABLED)
        _fail("LibSylph", "Couldn't init binreloc!", __FILE__, __LINE__);
    _location = br_find_exe("");
    if (_location == "") {
        _fail("LibSylph", "Couldn't init binreloc!", __FILE__, __LINE__);
    }

}
Exemplo n.º 5
0
/**
 * Initialize libraries
 */
int
elicit_libs_init(void)
{
  BrInitError error;

  if (!br_init(&error) && error != BR_INIT_ERROR_DISABLED)
    fprintf(stderr, "[Elicit] Failed to initialize binreloc (error code: %d)\nFalling back to hardcoded paths.", error);

  if (!eina_init())
  {
    fprintf(stderr, "[Elicit] Failed to initialize eina.\n");
    return 0;
  }
  if (!ecore_init())
  {
    fprintf(stderr, "[Elicit] Failed to initialize ecore.\n");
    eina_shutdown();
    return 0;
  }
  if (!ecore_evas_init() ||
      !ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_XLIB))
  {
    fprintf(stderr, "[Elicit] Failed to initialize ecore_evas.\n");
    fprintf(stderr, "[Elicit] Make sure you have the evas software X11 engine installed.\n");
    eina_shutdown();
    ecore_shutdown();
    return 0;
  }
  if (!ecore_file_init())
  {
    fprintf(stderr, "[Elicit] Failed to initialize ecore_file.\n");
    eina_shutdown();
    ecore_shutdown();
    ecore_evas_shutdown();
    return 0;
  }
  if (!edje_init())
  {
    fprintf(stderr, "[Elicit] Failed to initialize edje.\n");
    eina_shutdown();
    ecore_shutdown();
    ecore_evas_shutdown();
    ecore_file_shutdown();
    return 0;
  }

  return 1;
}
Exemplo n.º 6
0
int brctl_main(int argc, char *argv[])
{
	int argindex;
	struct bridge *br;
	struct command *cmd;

	br_init();

	if (argc < 2)
		goto help;

	if ((cmd = br_command_lookup(argv[1])) == NULL) {
		fprintf(stderr, "never heard of command [%s]\n", argv[1]);
		goto help;
	}

	argindex = 2;
	br = NULL;
	if (cmd->needs_bridge_argument) {
		if (argindex >= argc) {
			fprintf(stderr,
					"this option requires a bridge name as argument\n");
			return 1;
		}

		br = br_find_bridge(argv[argindex]);

		if (br == NULL) {
			fprintf(stderr, "bridge %s doesn't exist!\n", argv[argindex]);
			return 1;
		}

		argindex++;
	}

	if (argc - argindex != cmd->num_string_arguments) {
		fprintf(stderr, "incorrect number of arguments for command\n");
		return 1;
	}

	cmd->func(br, argv[argindex], argv[argindex + 1]);

	return 0;

  help:
	bb_show_usage();
	return 1;
}
Exemplo n.º 7
0
QSettings * createQSettings( const QString & KEY )
{
    QSettings * settings = 0;

#ifdef Q_WS_WIN
#ifdef SPEEDCRUNCH_PORTABLE
    // Portable Windows version: settings are from INI file in same directory
    QString appPath = QApplication::applicationFilePath();
    int ii = appPath.lastIndexOf( '/' );
    if ( ii > 0)
        appPath.remove( ii, appPath.length() );
    QString iniFile = appPath + '/' + KEY + ".ini";
    settings = new QSettings( iniFile, QSettings::IniFormat );
#else
    // Regular Windows version:
    //   settings are from the registry HKEY_CURRENT_USER\Software\SpeedCrunch
    settings = new QSettings( QSettings::NativeFormat, QSettings::UserScope, KEY, KEY );
#endif // SPEEDCRUNCH_PORTABLE
#endif // Q_WS_WIN


#ifdef Q_WS_MAC
    settings = new QSettings( QSettings::NativeFormat, QSettings::UserScope, KEY, KEY );
#endif // Q_WS_MAC


#if defined (Q_WS_X11) || defined (Q_WS_QWS)
#ifdef SPEEDCRUNCH_PORTABLE
    // Portable X11 version: settings are from INI file in the same directory
    BrInitError error;
    if ( br_init( & error ) == 0 && error != BR_INIT_ERROR_DISABLED ) {
        qDebug( "Warning: BinReloc failed to initialize (error code %d)", error );
        qDebug( "Will fallback to hardcoded default path." );
    }

    const char * prefix = br_find_prefix( 0 );
    QString iniFile = QString( prefix ) + '/' + KEY + QLatin1String( ".ini" );
    free( prefix );
    settings = new QSettings( iniFile, QSettings::IniFormat );
#else
    // Regular Unix or Embedded Linux (not Mac) version: settings from $HOME/.conf/SpeedCrunch
    settings = new QSettings( QSettings::NativeFormat, QSettings::UserScope, KEY, KEY );
#endif // SPEEDCRUNCH_PORTABLE
#endif // Q_WS_X11 || Q_WS_QWS

    return settings;
}
Exemplo n.º 8
0
int doInit(Uint32 vidFlags, int doWipe) {
	int i;

	BrInitError error;
	if(br_init(&error, "kuri2d") == 0 && error != BR_INIT_ERROR_DISABLED) {
		printf("Warning: BinReloc failed to initialize (error code %d)\n", error);
		printf("Will fallback to hardcoded default path.\n");
	}

	if(SDL_Init((Uint32)(SDL_INIT_VIDEO | SDL_INIT_AUDIO))) {
		printf("Unable to init SDL: %s\n", SDL_GetError());
		return 0;
	}
	(void)atexit(SDL_Quit);
	(void)atexit(TTF_Quit);

	/* malloc some defaults - they *should* be reloaded later */
	level = (KuriLevel *)malloc(sizeof(KuriLevel));
	startState = malloc(sizeof(State));
	state = malloc(sizeof(State));
	strcpy(state->name, "Player");
	state->level = (Uint8)0;
	state->score = (Uint8)0;
	state->lives = (Uint8)3;

	for(i=0; i<MAX_HISCORES; i++) {
		strcpy(hiscores[i].name, "nobody");
		hiscores[i].score = 0;
		hiscores[i].level = 0;
	}

	if(level && startState && state &&
		(doWipe ? 1 : loadHiScores()) &&
		loadBackgrounds() &&
		loadBlocks() &&
		loadLevels() &&
		loadSounds() &&
		loadFonts() &&
		loadTexts() &&
		openFrame(vidFlags)) {
		return 1;
	}

	return 0;
}
Exemplo n.º 9
0
void getinstallprefix()
{
#ifdef HAVE_WINDOWS_H
    HKEY hKey;

    long res = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                            "Software\\WorldForge\\Cyphesis\\Settings",
                            0, KEY_READ, &hKey);

    if (res != ERROR_SUCCESS)
    {
        log(CYLOG_ERROR, "No install key for cyphesis");
        return;
    }

    unsigned long type=REG_SZ, size=1024;
    char path[1024]="";

    res = RegQueryValueEx(hKey, "Path", NULL, &type, (LPBYTE)&path[0], &size);

    if (res != ERROR_SUCCESS)
    {
        log(CYLOG_ERROR, "No install key for cyphesis");
    } else {
        etc_directory = String::compose("%1/etc", path);
        var_directory = String::compose("%1/var", path);
        share_directory = String::compose("%1/share", path);
    }

    RegCloseKey(hKey);
#else // HAVE_WINDOWS_H
    BrInitError error;
    if (br_init (&error) == 0) {
        return;
    }

    etc_directory = br_find_etc_dir("");
    share_directory = br_find_data_dir("data");
    var_directory = String::compose("%1/var", br_find_prefix(""));
#endif // HAVE_WINDOWS_H
}
Exemplo n.º 10
0
  path_t locate_bin_directory(const logger* log, bool verbose) {
    // locate the binary and build its path
    #if KZH_PLATFORM == KZH_PLATFORM_LINUX
      // use binreloc and fs to build up our paths
      int brres = br_init(0);
      if (brres == 0) {
        if (verbose) {
          log->error() << "binreloc could not be initialised";
        }

        throw std::runtime_error("Unable to resolve paths! binreloc could not be initialized");
      }

      char *tmp_bin_path = br_find_exe_dir(".");
      path_t bin_path = path_t(tmp_bin_path).make_preferred();
      free(tmp_bin_path);
      br_free();

      return bin_path;
    #elif KZH_PLATFORM == KZH_PLATFORM_APPLE
      // use NSBundlePath() to build up our paths
      // return path_t(macBundlePath() + "/Contents/MacOS").make_preferred();
      return path_t(macBundlePath()).make_preferred();
    #else // Windows
      // use GetModuleFileName() and fs to build up our paths on Windows
      TCHAR szPath[MAX_PATH];

      if (!GetModuleFileName(NULL, szPath, MAX_PATH)) {
        if (verbose) {
          log->error() << "Unable to resolve path: " << GetLastError();;
        }

        throw std::runtime_error("Unable to resolve paths! GetModuleFileName() failed. See the log for the error.");
      }

      return path_t(string_t(szPath)).remove_filename().make_preferred();
    #endif
  }
Exemplo n.º 11
0
void InitDirs(const std::string& argv0) {
    if (g_initialized)
        return;

    /* store working dir.  some implimentations get the value of initial_path
     * from the value of current_path the first time initial_path is called,
     * so it is necessary to call initial_path as soon as possible after
     * starting the program, so that current_path doesn't have a chance to
     * change before initial_path is initialized. */
    fs::initial_path();

    br_init(nullptr);

    MigrateOldConfigDirsToXDGLocation();

    fs::path cp = GetUserConfigDir();
    if (!exists(cp)) {
        fs::create_directories(cp);
    }

    fs::path p = GetUserDataDir();
    if (!exists(p)) {
        fs::create_directories(p);
    }

    p /= "save";
    if (!exists(p)) {
        fs::create_directories(p);
    }

    // Intentionally do not create the server save dir.
    // The server save dir is publically accessible and should not be
    // automatically created for the user.

    InitBinDir(argv0);

    g_initialized = true;
}
Exemplo n.º 12
0
/*
 * Open the diagnostic device, return a file descriptor,
 * record the original state of term interface so we can restore later
 */
static int br_open(struct diag_l0_device *dl0d, int iProtocol) {
	struct br_device *dev = dl0d->l0_int;
	int rv;
	uint8_t buf[4];	/* Was MAXRBUF. We only use 1! */
	struct diag_serial_settings set;

	br_init();

	dev->protocol = iProtocol;
	dev->dev_rdoffset = 0;
	dev->dev_txlen = 0;
	dev->dev_framenr = 0;
	dev->dev_state = BR_STATE_CLOSED;
	dev->dev_features = BR_FEATURE_SETADDR;

	/* try to open TTY */
	dev->tty_int = diag_tty_open(dev->port.val.str);
	if (dev->tty_int == NULL) {
		return diag_iseterr(DIAG_ERR_GENERAL);
	}

	DIAG_DBGM(diag_l0_debug, DIAG_DEBUG_OPEN, DIAG_DBGLEVEL_V,
		FLFMT "features 0x%X\n", FL, dev->dev_features);

	/* Set serial line to 19200 baud , 8N1 */
	set.speed = 19200;
	set.databits = diag_databits_8;
	set.stopbits = diag_stopbits_1;
	set.parflag = diag_par_n;

	if (diag_tty_setup(dev->tty_int, &set)) {
		fprintf(stderr, FLFMT "open: TTY setup failed\n", FL);
		br_close(dl0d);
		return diag_iseterr(DIAG_ERR_GENERAL);
	}

	diag_tty_iflush(dev->tty_int);	/* Flush unread input data */

	/*
	 * Initialise the BR1 interface by sending the CHIP CONNECT
	 * (0x20h) command, we should get a 0xFF back
	 */
	buf[0] = 0x20;
	if (br_write(dl0d, buf, 1)) {
		DIAG_DBGM(diag_l0_debug, DIAG_DEBUG_OPEN, DIAG_DBGLEVEL_V,
			FLFMT "CHIP CONNECT write failed link %p\n",
			FL, (void *)dl0d);

		br_close(dl0d);
		return diag_iseterr(DIAG_ERR_BADIFADAPTER);
	}
	/* And expect 0xff as a response */
	if (diag_tty_read(dev->tty_int, buf, 1, 100) != 1) {
		DIAG_DBGM(diag_l0_debug, DIAG_DEBUG_OPEN, DIAG_DBGLEVEL_V,
			FLFMT "CHIP CONNECT read failed link %p\n",
			FL, (void *)dl0d);

		br_close(dl0d);
		return diag_iseterr(DIAG_ERR_BADIFADAPTER);
	}
	if (buf[0] != 0xff) {
		DIAG_DBGM(diag_l0_debug, DIAG_DEBUG_OPEN, DIAG_DBGLEVEL_V,
			FLFMT "CHIP CONNECT rcvd 0x%X != 0xff, link %p\n",
			FL, buf[0], (void *)dl0d);

		br_close(dl0d);
		return diag_iseterr(DIAG_ERR_BADIFADAPTER);
	}

	/* If it's J1850, send initialisation string now */
	rv = 0;
	switch (iProtocol) {
	case DIAG_L1_J1850_VPW:
		rv = br_initialise(dl0d, 0, 0);
		break;
	case DIAG_L1_J1850_PWM:
		rv = br_initialise(dl0d, 1, 0);
		break;
	case DIAG_L1_ISO9141:
	case DIAG_L1_ISO14230:
		/* This initialisation is done in the SLOWINIT code */
		break;
	}
	if (rv) {
		br_close(dl0d);
		return diag_ifwderr(rv);
	}

	DIAG_DBGM(diag_l0_debug, DIAG_DEBUG_OPEN, DIAG_DBGLEVEL_V,
		FLFMT "open succeeded link %p features 0x%X\n",
		FL, (void *)dl0d, dev->dev_features);

	dl0d->opened = 1;
	return 0;
}
Exemplo n.º 13
0
int main(int argc,char *argv[])
{
  AMX amx;
  cell ret = 0;
  int err, i;
  clock_t start,end;
  STACKINFO stackinfo = { 0 };
  AMX_IDLE idlefunc;

  if (argc < 2)
    PrintUsage(argv[0]);        /* function "usage" aborts the program */

  #if !defined AMX_NODYNALOAD && defined ENABLE_BINRELOC && (defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__)
    /* see www.autopackage.org for the BinReloc module */
    if (br_init(NULL)) {
      char *libroot=br_find_exe_dir("");
      setenv("AMXLIB",libroot,0);
      free(libroot);
    } /* if */
  #endif

  /* Load the program and initialize the abstract machine. */
  err = aux_LoadProgram(&amx, argv[1]);
  if (err != AMX_ERR_NONE) {
    /* try adding an extension */
    char filename[_MAX_PATH];
    strcpy(filename, argv[1]);
    strcat(filename, ".amx");
    err = aux_LoadProgram(&amx, filename);
    if (err != AMX_ERR_NONE)
      PrintUsage(argv[0]);
  } /* if */

  /* To install the debug hook "just-in-time", the signal function needs
   * a pointer to the abstract machine(s) to abort. There are various ways
   * to implement this; here I have done so with a simple global variable.
   */
  global_amx = &amx;
  signal(SIGINT, sigabort);

  /* Initialize two core extension modules (more extension modules may be
   * loaded & initialized automatically as DLLs or shared libraries.
   */
  amx_ConsoleInit(&amx);
  err = amx_CoreInit(&amx);
  ExitOnError(&amx, err);

  /* save the idle function, if set by any of the extension modules */
  if (amx_GetUserData(&amx, AMX_USERTAG('I','d','l','e'), (void**)&idlefunc) != AMX_ERR_NONE)
    idlefunc = NULL;

  for (i = 2; i < argc; i++) {
    if (strcmp(argv[i],"-stack") == 0) {
      uint16_t flags;
      amx_Flags(&amx, &flags);
      if ((flags & AMX_FLAG_NOCHECKS) != 0)
        printf("This script was compiled with debug information removed.\n"
               "Stack monitoring is disfunctional\n\n");
      /* Set "user data" with which the debug monitor can monitor stack usage
       * per abstract machine (in this example, though, there is only one abstract
       * machine, so a global variable would have sufficed).
       */
      memset(&stackinfo, 0, sizeof stackinfo);
      err = amx_SetUserData(&amx, AMX_USERTAG('S','t','c','k'), &stackinfo);
      ExitOnError(&amx, err);
      /* Install the debug hook, so that we can start monitoring the stack/heap
       * usage right from the beginning of the script.
       */
      amx_SetDebugHook(&amx, prun_Monitor);
    } /* if */
  } /* for */

  start=clock();

  /* Run the compiled script and time it. The "sleep" instruction causes the
   * abstract machine to return in a "restartable" state (it restarts from
   * the point that it stopped. This allows for a kind of light-weight
   * cooperative multi-tasking. As native functions (or the debug hook) can
   * also force an abstract machine to "sleep", you can also use it to create
   * "latent functions": functions that allow the host application to continue
   * processing, and/or other abstract machines to run, while they wait for
   * some resource.
   */
  err = amx_Exec(&amx, &ret, AMX_EXEC_MAIN);
  while (err == AMX_ERR_SLEEP) {
    if (idlefunc != NULL) {
      /* If the abstract machine was put to sleep, we can handle events during
       * that time. To save the "restart point", we must make a copy of the AMX
       * (keeping the stack, frame, instruction pointer and other vital
       * registers), but without cloning the entire abstract machine.
       * There should be some criterion on when the abstract machine must be
       * "woken up". In this example run-time, the parameter of the sleep
       * instruction is taken to be a delay in milliseconds. In your own host
       * application, you can choose to wait on a resource/semaphore or other.
       */
      AMX nested_amx = amx;
      clock_t stamp = clock();
      while (((clock() - stamp)*1000)/CLOCKS_PER_SEC < amx.pri
             && (err = idlefunc(&nested_amx,amx_Exec)) == AMX_ERR_NONE)
        /* nothing */;
      ExitOnError(&nested_amx, err);
    } /* if */
    err = amx_Exec(&amx, &ret, AMX_EXEC_CONT);
  } /* while */
  if (idlefunc == NULL || err != AMX_ERR_INDEX)
    ExitOnError(&amx, err);     /* event-driven programs may not have main() */

  /* For event-driven programs, we also need to loop over the idle/monitor
   * function that some extension module installed (this could be the console
   * module, for example). We did this if the main program was put to "sleep",
   * but we do that here too.
   */
  if (idlefunc != NULL) {
    while ((err = idlefunc(&amx,amx_Exec)) == AMX_ERR_NONE)
      /* nothing */;
    ExitOnError(&amx, err);
  } /* if */

  end=clock();

  /* Free the compiled script and resources. This also unloads and DLLs or
   * shared libraries that were registered automatically by amx_Init().
   */
  aux_FreeProgram(&amx);

  /* Print the return code of the compiled script (often not very useful),
   * its run time, and its stack usage.
   */
  if (ret!=0)
    printf("\nReturn value: %ld\n", (long)ret);

  printf("\nRun time:     %.2f seconds\n",(double)(end-start)/CLOCKS_PER_SEC);
  if (stackinfo.maxstack != 0 || stackinfo.maxheap != 0) {
    printf("Stack usage:  %ld cells (%ld bytes)\n",
           stackinfo.maxstack / sizeof(cell), stackinfo.maxstack);
    printf("Heap usage:   %ld cells (%ld bytes)\n",
           stackinfo.maxheap / sizeof(cell), stackinfo.maxheap);
  } /* if */

  #if defined AMX_TERMINAL
    /* This is likely a graphical terminal, which should not be closed
     * automatically
     */
    {
      extern int amx_termctl(int,int);
      while (amx_termctl(4,0))
        /* nothing */;
    }
  #endif

  return 0;
}
Exemplo n.º 14
0
int main(int argc, const char **argv)
#endif
{
	bContext *C = CTX_create();
	SYS_SystemHandle syshandle;

#ifndef WITH_PYTHON_MODULE
	bArgs *ba;
#endif

#ifdef WIN32
	wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc);
	int argci = 0;
	char **argv = MEM_mallocN(argc * sizeof(char *), "argv array");
	for (argci = 0; argci < argc; argci++) {
		argv[argci] = alloc_utf_8_from_16(argv_16[argci], 0);
	}
	LocalFree(argv_16);
#endif

#ifdef WITH_PYTHON_MODULE
#ifdef __APPLE__
	environ = *_NSGetEnviron();
#endif

#undef main
	evil_C = C;
#endif



#ifdef WITH_BINRELOC
	br_init(NULL);
#endif

#ifdef WITH_LIBMV
	libmv_initLogging(argv[0]);
#endif

	setCallbacks();
#if defined(__APPLE__) && !defined(WITH_PYTHON_MODULE)
	/* patch to ignore argument finder gives us (pid?) */
	if (argc == 2 && strncmp(argv[1], "-psn_", 5) == 0) {
		extern int GHOST_HACK_getFirstFile(char buf[]);
		static char firstfilebuf[512];

		argc = 1;

		if (GHOST_HACK_getFirstFile(firstfilebuf)) {
			argc = 2;
			argv[1] = firstfilebuf;
		}
	}

#endif

#ifdef __FreeBSD__
	fpsetmask(0);
#endif

	/* initialize path to executable */
	BLI_init_program_path(argv[0]);

	BLI_threadapi_init();

	initglobals();  /* blender.c */

	IMB_init();
	BKE_images_init();

	BKE_brush_system_init();

	BLI_callback_global_init();

#ifdef WITH_GAMEENGINE
	syshandle = SYS_GetSystem();
#else
	syshandle = 0;
#endif

	/* first test for background */
#ifndef WITH_PYTHON_MODULE
	ba = BLI_argsInit(argc, (const char **)argv); /* skip binary path */
	setupArguments(C, ba, &syshandle);

	BLI_argsParse(ba, 1, NULL, NULL);

	if (use_crash_handler) {
		/* after parsing args */
		signal(SIGSEGV, blender_crash_handler);
	}
#else
	G.factory_startup = true;  /* using preferences or user startup makes no sense for py-as-module */
	(void)syshandle;
#endif

#ifdef WITH_FFMPEG
	IMB_ffmpeg_init();
#endif

	/* after level 1 args, this is so playanim skips RNA init */
	RNA_init();

	RE_engines_init();
	init_nodesystem();
	/* end second init */


#if defined(WITH_PYTHON_MODULE) || defined(WITH_HEADLESS)
	G.background = true; /* python module mode ALWAYS runs in background mode (for now) */
#else
	/* for all platforms, even windos has it! */
	if (G.background) {
		signal(SIGINT, blender_esc);  /* ctrl c out bg render */
	}
#endif

	/* background render uses this font too */
	BKE_vfont_builtin_register(datatoc_bfont_pfb, datatoc_bfont_pfb_size);

	/* Initialize ffmpeg if built in, also needed for bg mode if videos are
	 * rendered via ffmpeg */
	sound_init_once();
	
	init_def_material();

	if (G.background == 0) {
#ifndef WITH_PYTHON_MODULE
		BLI_argsParse(ba, 2, NULL, NULL);
		BLI_argsParse(ba, 3, NULL, NULL);
#endif
		WM_init(C, argc, (const char **)argv);

		/* this is properly initialized with user defs, but this is default */
		/* call after loading the startup.blend so we can read U.tempdir */
		BLI_init_temporary_dir(U.tempdir);

#ifdef WITH_SDL
		BLI_setenv("SDL_VIDEODRIVER", "dummy");
#endif
	}
	else {
#ifndef WITH_PYTHON_MODULE
		BLI_argsParse(ba, 3, NULL, NULL);
#endif

		WM_init(C, argc, (const char **)argv);

		/* don't use user preferences temp dir */
		BLI_init_temporary_dir(NULL);
	}
#ifdef WITH_PYTHON
	/**
	 * NOTE: the U.pythondir string is NULL until WM_init() is executed,
	 * so we provide the BPY_ function below to append the user defined
	 * python-dir to Python's sys.path at this point.  Simply putting
	 * WM_init() before #BPY_python_start() crashes Blender at startup.
	 */

	/* TODO - U.pythondir */
#else
	printf("\n* WARNING * - Blender compiled without Python!\nthis is not intended for typical usage\n\n");
#endif
	
	CTX_py_init_set(C, 1);
	WM_keymap_init(C);

#ifdef WITH_FREESTYLE
	/* initialize Freestyle */
	FRS_initialize();
	FRS_set_context(C);
#endif

	/* OK we are ready for it */
#ifndef WITH_PYTHON_MODULE
	BLI_argsParse(ba, 4, load_file, C);
	
	if (G.background == 0) {
		if (!G.file_loaded)
			if (U.uiflag2 & USER_KEEP_SESSION)
				WM_recover_last_session(C, NULL);
	}

#endif

#ifndef WITH_PYTHON_MODULE
	BLI_argsFree(ba);
#endif

#ifdef WIN32
	while (argci) {
		free(argv[--argci]);
	}
	MEM_freeN(argv);
	argv = NULL;
#endif

#ifdef WITH_PYTHON_MODULE
	return 0; /* keep blender in background mode running */
#endif

	if (G.background) {
		/* actually incorrect, but works for now (ton) */
		WM_exit(C);
	}
	else {
		if (G.fileflags & G_FILE_AUTOPLAY) {
			if (G.f & G_SCRIPT_AUTOEXEC) {
				if (WM_init_game(C)) {
					return 0;
				}
			}
			else {
				if (!(G.f & G_SCRIPT_AUTOEXEC_FAIL_QUIET)) {
					G.f |= G_SCRIPT_AUTOEXEC_FAIL;
					BLI_snprintf(G.autoexec_fail, sizeof(G.autoexec_fail), "Game AutoStart");
				}
			}
		}

		if (!G.file_loaded) {
			WM_init_splash(C);
		}
	}

	WM_main(C);

	return 0;
} /* end of int main(argc, argv)	*/
Exemplo n.º 15
0
int WebEmberManager::start(const std::string& windowHandle, const std::string& prefix)
{
	assert((windowHandle != "") && (windowHandle != "0") && (mWindowHandle == ""));
	mWindowHandle = windowHandle;

	int exitStatus(0);
	bool exit_program = false;
	std::string homeDir("");
	Ember::Application::ConfigMap configMap;
	std::map<std::string, std::string> ogremap;
	ogremap.insert(std::make_pair("suppressconfigdialog", "true"));
	ogremap.insert(std::make_pair("windowhandle", mWindowHandle));
	configMap.insert(std::make_pair("ogre", ogremap));


#if defined (ENABLE_BINRELOC)
	if (prefix == "")
	{
		BrInitError error;

		if (br_init (&error) == 0 && error != BR_INIT_ERROR_DISABLED)
		{
			printf ("Warning: BinReloc failed to initialize (error code %d)\n", error);
			printf ("Will fallback to hardcoded default path.\n");
		}

		char* br_prefixdir = br_find_prefix(PREFIX);
		const std::string prefixDir(br_prefixdir);
		free(br_prefixdir);
		prefix = prefixDir;
	}

#endif
	//put the application object in its own scope so it gets destroyed before we signal all clear
	{
		try
		{
			// Create application object
			Ember::Application app(prefix, "", configMap);
			//Ember::OgreView::EmberOgre app;

			std::cout << "Starting Ember version " << VERSION << std::endl;

			app.registerComponents();

			// Initialize all Ember services needed for this application
			app.prepareComponents();
			app.initializeServices();

			app.start();
		} catch (const std::exception& ex)
		{
			std::cerr << "Unexpected error, aborting.\n\r" << ex.what();
			exitStatus = 1;
		} catch (...){
			std::cerr << "Unexpected error, aborting.\n\r";
			exitStatus = 1;
		}
	}

	std::cout << "Ember shut down successfully." << std::endl;
	mWindowHandle = "";
	return exitStatus;
}
Exemplo n.º 16
0
void myinit(void)
{
#pragma message "myinit()"
#pragma message "HAL_Init()"
#pragma message "SystemClock_Config()"
    HAL_Init();
    SystemClock_Config();

#ifdef ENABLE_GPIO
#pragma message "led_init()"
    led_init();
#ifdef btn_init
#pragma message "btn_init()"
    btn_init();
#endif
#endif

#ifdef ENABLE_RNG
#pragma message "rng_init()"
    rng_init();
#endif

#ifdef ENABLE_UART
#pragma message "uart_init()"
    uart_init();
#endif

#ifdef ENABLE_I2C
#pragma message "i2c_init()"
    i2c_init();
#endif

#ifdef ENABLE_SPI
#pragma message "spi_init()"
    spi_init();
#endif

#ifdef ENABLE_TIM
#pragma message "tim_init()"
    tim_init();
#endif

#ifdef ENABLE_ADC
#pragma message "adc_init()"
    adc_init();
#endif

#ifdef ENABLE_CAN
#pragma message "can_init()"
    can_init();
#endif

#ifdef ENABLE_DAC
#pragma message "dac_init()"
    dac_init();
#endif

#ifdef ENABLE_DMA
#pragma message "dma_init()"
    dma_init();
#endif

#ifdef ENABLE_FLASH
#pragma message "flash_erase_img1()"
    flash_erase_img1();
#endif

#ifdef ENABLE_ETH
#pragma message "eth_init()"
    eth_init();
#endif

#ifdef ENABLE_DSP
#pragma message "dsp_init()"
    dsp_init();
#endif

#ifdef ENABLE_USB
#pragma message "usb_init()"
    usb_init();
#endif

#ifdef ENABLE_PCL
#pragma message "pcl_init()"
    pcl_init();
#endif

#ifdef ENABLE_SDIO
#pragma message "sdio_init()"
    sdio_init();
#endif

#ifdef ENABLE_DISPLAY
#pragma message "display_init()"
    display_init();
#endif

#ifdef ENABLE_BR
#pragma message "br_init()"
    br_init();
#endif
}
Exemplo n.º 17
0
int main (int argc, char* argv[])
{
	char **newargs;
	int i, k = 0;

#ifdef _WIN32
	/* CommandLineToArgvW() might return a different argc than the
	 * one passed to main(), so let it overwrite that, as we won't
	 * use argv[] on Windows anyway.
	 */
	wchar_t **wargv = CommandLineToArgvW (GetCommandLineW (), &argc);
#endif

	newargs = (char **) malloc (sizeof (char *) * (argc + 2) + count_mono_options_args ());

#ifdef _WIN32
	newargs [k++] = g_utf16_to_utf8 (wargv [0], -1, NULL, NULL, NULL);
#else
	newargs [k++] = argv [0];
#endif

	if (mono_options != NULL) {
		i = 0;
		while (mono_options[i] != NULL)
			newargs[k++] = mono_options[i++];
	}

	BrInitError err = 0;
	if (br_init(&err) == 1) {
		char *exedir = br_find_exe_dir(NULL);
		if (exedir) {
			setenv("MONO_PATH",exedir,1);
			mono_set_dirs(exedir, exedir);
			chdir(exedir);
			free(exedir);
		}
	} else {
		switch (err) {
		case BR_INIT_ERROR_NOMEM:
			printf("Could not allocate enough memory\n");
			break;
		case BR_INIT_ERROR_OPEN_MAPS:
		case BR_INIT_ERROR_READ_MAPS:
		case BR_INIT_ERROR_INVALID_MAPS:
			printf("Couldn't access /proc/self/maps!\n");
			break;
		case BR_INIT_ERROR_DISABLED:
			printf("BinReloc disabled!!\n");
			break;
		}
		return 1;
	}
	
	// Calculate image_name
	char *image_name;
	char *exe = br_find_exe(NULL);
	char *pos = strrchr(exe, '/');
	if (pos != NULL) {
		image_name = strdup(pos+1);
		pos = strstr(image_name,".bin.");
		if (pos != NULL) {
			strcpy(pos, ".exe");
		}
	}
	free(exe);

	newargs [k++] = image_name;

	for (i = 1; i < argc; i++) {
#ifdef _WIN32
		newargs [k++] = g_utf16_to_utf8 (wargv [i], -1, NULL, NULL, NULL);
#else
		newargs [k++] = argv [i];
#endif
	}
#ifdef _WIN32
	LocalFree (wargv);
#endif
	newargs [k] = NULL;

	return mono_main (k, newargs);
}
Exemplo n.º 18
0
void initPhysfs(const char* argv0)
{
    if(!PHYSFS_init(argv0)) {
        std::stringstream msg;
        msg << "Couldn't initialize physfs: " << PHYSFS_getLastError();
        throw std::runtime_error(msg.str());
    }

    // Initialize physfs (this is a slightly modified version of
    // PHYSFS_setSaneConfig
    const char* application = /* PACKAGE_NAME */ "lincity";
    const char* userdir = PHYSFS_getUserDir();
    const char* dirsep = PHYSFS_getDirSeparator();
    char* writedir = new char[strlen(userdir) + strlen(application) + 2];

    // Set configuration directory
    sprintf(writedir, "%s.%s", userdir, application);
    if(!PHYSFS_setWriteDir(writedir)) {
        // try to create the directory
        char* mkdir = new char[strlen(application) + 2];
        sprintf(mkdir, ".%s", application);
        if(!PHYSFS_setWriteDir(userdir) || !PHYSFS_mkdir(mkdir)) {
            std::ostringstream msg;
            msg << "Failed creating configuration directory '" <<
                writedir << "': " << PHYSFS_getLastError();
            delete[] writedir;
            delete[] mkdir;
            throw std::runtime_error(msg.str());
        }
        delete[] mkdir;

        if(!PHYSFS_setWriteDir(writedir)) {
            std::ostringstream msg;
            msg << "Failed to use configuration directory '" <<            
                writedir << "': " << PHYSFS_getLastError();
            delete[] writedir;
            throw std::runtime_error(msg.str());
        }
    }
    PHYSFS_addToSearchPath(writedir, 0);
    delete[] writedir;
   
    // Search for archives and add them to the search path
    const char* archiveExt = "zip";
    char** rc = PHYSFS_enumerateFiles("/");
    size_t extlen = strlen(archiveExt);

    for(char** i = rc; *i != 0; ++i) {
        size_t l = strlen(*i);
        if((l > extlen) && ((*i)[l - extlen - 1] == '.')) {
            const char* ext = (*i) + (l - extlen);
            if(strcasecmp(ext, archiveExt) == 0) {
                const char* d = PHYSFS_getRealDir(*i);
                char* str = new char[strlen(d) + strlen(dirsep) + l + 1];
                sprintf(str, "%s%s%s", d, dirsep, *i);
                PHYSFS_addToSearchPath(str, 1);
                delete[] str;
            }
        }
    }

    PHYSFS_freeList(rc);
            
    // when started from source dir...
    std::string dir = PHYSFS_getBaseDir();
    dir += "/data";
    std::string testfname = dir;
    testfname += "/images/tiles/images.xml";
    FILE* f = fopen(testfname.c_str(), "r");
    if(f) {
        fclose(f);
        if(!PHYSFS_addToSearchPath(dir.c_str(), 1)) {
#ifdef DEBUG
            std::cout << "Warning: Couldn't add '" << dir << 
                "' to physfs searchpath: " << PHYSFS_getLastError() << "\n";
#endif
        }
    }

#if defined(APPDATADIR) || defined(ENABLE_BINRELOC)
    std::string datadir;
#ifdef ENABLE_BINRELOC
    BrInitError error;
    if (br_init (&error) == 0 && error != BR_INIT_ERROR_DISABLED) {
        printf ("Warning: BinReloc failed to initialize (error code %d)\n",
                error);
        printf ("Will fallback to hardcoded default path.\n");
    }
    
    char* brdatadir = br_find_data_dir("/usr/local/share");
    datadir = brdatadir;
    datadir += "/" PACKAGE_NAME;
    free(brdatadir);
#else
    datadir = APPDATADIR;
#endif
    
    if(!PHYSFS_addToSearchPath(datadir.c_str(), 1)) {
        std::cout << "Couldn't add '" << datadir
            << "' to physfs searchpath: " << PHYSFS_getLastError() << "\n";
    }
#endif

    // allow symbolic links
    PHYSFS_permitSymbolicLinks(1);

    //show search Path 
    for(char** i = PHYSFS_getSearchPath(); *i != NULL; i++)
        printf("[%s] is in the search path.\n", *i);

    // ugly: set LINCITY_HOME environment variable
    const char* lincityhome = PHYSFS_getRealDir("colour.pal");
    if(lincityhome == 0) {
        throw std::runtime_error("Couldn't locate lincity data (colour.pal).");
    }
    std::cout << "LINCITY_HOME: " << lincityhome << "\n";
    char tmp[256];
    snprintf(tmp, sizeof(tmp), "LINCITY_HOME=%s", lincityhome);
    putenv(tmp);
}
Exemplo n.º 19
0
int main(int argc, char **argv)
{
	int exitStatus(0);
	bool exit_program = false;
	std::string prefix("");
	std::string homeDir("");
	Ember::Application::ConfigMap configMap;
#ifndef __WIN32__
	if (argc > 1)
	{
		(argv)++;
		argc--;
		while (argc > 0)
		{
			std::string arg = std::string((char *) argv[0]);
			argv++;
			argc--;
			if (arg == "-v" || arg == "--version")
			{
				std::cout << "Ember version: " << VERSION << std::endl;
				exit_program = true;
			}
			else if (arg == "-h" || arg == "--help")
			{
				std::cout << "-h, --help    - display this message" << std::endl;
				std::cout << "-v, --version - display version info" << std::endl;
				std::cout << "--home <path> - sets the home directory to something different than the default (~/.ember on *NIX systems, $APPDATA\\Ember on win32 systems)" << std::endl;
				std::cout << "-p <path>, --prefix <path> - sets the prefix to something else than the one set at compilation (only valid on *NIX systems)" << std::endl;
				std::cout << "--config <section>:<key> <value> - allows you to override config file settings. See the ember.conf file for examples. (~/.ember/ember.conf on *NIX systems)" << std::endl;
				exit_program = true;
				break;
			}
			else if (arg == "-p" || arg == "--prefix")
			{
				if (!argc)
				{
					std::cout << "You didn't supply a prefix.";
					exit_program = true;
				}
				else
				{
					prefix = std::string((char *) argv[0]);
					argv++;
					argc--;
				}

			}
			else if (arg == "--home")
			{
				if (!argc)
				{
					std::cout << "You didn't supply a home directory.";
					exit_program = true;
				}
				else
				{
					homeDir = std::string((char *) argv[0]);
					argv++;
					argc--;
				}

			}
			else if (arg == "--config")
			{
				if (argc < 2)
				{
					std::cout << "You didn't supply any config arguments.";
				}
				else
				{
					std::string fullkey(argv[0]);
					std::string value(argv[1]);
					Ember::Tokeniser tokeniser(fullkey, ":");
					if (tokeniser.remainingTokens() != "")
					{
						std::string category(tokeniser.nextToken());
						if (tokeniser.remainingTokens() != "")
						{
							std::string key(tokeniser.nextToken());
							configMap[category][key] = value;
						}
					}
				}
			}
		}
	}

#if !defined(__WIN32__) && !defined(__APPLE__)
	if (exit_program)
	{
		return 0;
	}
#endif

#ifdef ENABLE_BINRELOC
	if (prefix == "")
	{
		BrInitError error;

		if (br_init (&error) == 0 && error != BR_INIT_ERROR_DISABLED)
		{
			printf ("Warning: BinReloc failed to initialize (error code %d)\n", error);
			printf ("Will fallback to hardcoded default path.\n");
		}

		char* br_prefixdir = br_find_prefix(PREFIX);
		const std::string prefixDir(br_prefixdir);
		free(br_prefixdir);
		prefix = prefixDir;
	}

#endif
	// 	if (prefix == "") {
	// 		prefix = PREFIX;
	// 	}

#else
	//  char tmp[64];

	//  unsigned int floatSetting = _controlfp( 0, 0 );
	//sprintf(tmp, "Original: 0x%.4x\n", floatSetting );
	//   MessageBox( 0, tmp, "floating point control", MB_OK | MB_ICONERROR | MB_TASKMODAL);
	//_fpreset();
	//_controlfp(_PC_64, _MCW_PC);
	//_controlfp(_RC_NEAR , _MCW_RC);
	//floatSetting = _controlfp( 0, 0 );
	//sprintf(tmp, "New: 0x%.4x\n", floatSetting );
	//   MessageBox( 0, tmp, "floating point control", MB_OK | MB_ICONERROR | MB_TASKMODAL);

#endif

	try
	{
	//put the application object in its own scope so it gets destroyed before we signal all clear
		{
			// Create application object
			Ember::Application app(prefix, homeDir, configMap);
			//Ember::OgreView::EmberOgre app;

			std::cout << "Starting Ember version " << VERSION << std::endl;

			app.registerComponents();

			// Initialize all Ember services needed for this application
			app.prepareComponents();
			app.initializeServices();

			app.start();
		}
	} catch (const std::exception& ex)
	{
		std::cerr << "Unexpected error, aborting.\n\r\t" << ex.what() << std::endl;
		exitStatus = 1;
	}
    std::cout << "Ember shut down successfully." << std::endl;

	return exitStatus;
}
Exemplo n.º 20
0
Arquivo: dev.c Projeto: 0xffea/gnumach
int net_dev_init(void)
{
	struct device *dev, **dp;

	/*
	 *	Initialise the packet receive queue.
	 */

#ifndef MACH
	skb_queue_head_init(&backlog);
#endif
	
	/*
	 *	The bridge has to be up before the devices
	 */

#ifdef CONFIG_BRIDGE	 
	br_init();
#endif	
	
	/*
	 * This is Very Ugly(tm).
	 *
	 * Some devices want to be initialized early..
	 */
#if defined(CONFIG_PI)
	pi_init();
#endif	
#if defined(CONFIG_PT)
	pt_init();
#endif
#if defined(CONFIG_DLCI)
	dlci_setup();
#endif
#if defined(CONFIG_SDLA)
	sdla_setup();
#endif
	/*
	 *	SLHC if present needs attaching so other people see it
	 *	even if not opened.
	 */
#if (defined(CONFIG_SLIP) && defined(CONFIG_SLIP_COMPRESSED)) \
	 || defined(CONFIG_PPP) \
    || (defined(CONFIG_ISDN) && defined(CONFIG_ISDN_PPP))
	slhc_install();
#endif	

	/*
	 *	Add the devices.
	 *	If the call to dev->init fails, the dev is removed
	 *	from the chain disconnecting the device until the
	 *	next reboot.
	 */

	dp = &dev_base;
	while ((dev = *dp) != NULL)
	{
		int i;
		for (i = 0; i < DEV_NUMBUFFS; i++)  {
			skb_queue_head_init(dev->buffs + i);
		}

		if (dev->init && dev->init(dev)) 
		{
			/*
			 *	It failed to come up. Unhook it.
			 */
			*dp = dev->next;
		} 
		else
		{
			dp = &dev->next;
		}
	}

#ifdef CONFIG_PROC_FS
	proc_net_register(&(struct proc_dir_entry) {
		PROC_NET_DEV, 3, "dev",
		S_IFREG | S_IRUGO, 1, 0, 0,
		0, &proc_net_inode_operations,
		dev_get_info
	});