added kiwix launcher for static

This commit is contained in:
reg_ 2012-04-05 11:51:44 +00:00
parent 8268ecb5f4
commit 2ee5e41f2c
2 changed files with 52 additions and 56 deletions

View File

@ -1,56 +0,0 @@
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#ifdef _WIN32
const char * sep = "\\";
#else
const char * sep = "/";
#endif
int main() {
char cwd[1024];
char * previous_env = getenv("LD_LIBRARY_PATH");
if (getcwd(cwd, sizeof(cwd)) != NULL) {
char env[1024] = "LD_LIBRARY_PATH=";
strcat(env, cwd);
strcat(env, ":");
strcat(env, previous_env);
putenv(env);
// fprintf(stdout, "LD_LIBRARY_PATH: %s\n", env);
// fprintf(stdout, "Current working dir: %s\n", cwd);
} else
perror("Unable to find current directory");
char *path = (char *)malloc(2048);
strcpy(path, cwd);
strcat(path, sep);
strcat(path, "xulrunner");
strcat(path, sep);
strcat(path, "xulrunner");
// fprintf(stdout, "path: %s\n", path);
char *inifile = (char *)malloc(2048);
strcpy(inifile, cwd);
strcat(inifile, sep);
strcat(inifile, "application.ini");
// fprintf(stdout, "ini: %s\n", inifile);
if (file_exist(path) == 0) {
perror("Unable to find xulrunner binary");
}
return execl(path, "xulrunner", inifile, NULL);
}
int file_exist (char *filename) {
struct stat buffer;
return (stat (filename, &buffer) == 0);
}

View File

@ -0,0 +1,52 @@
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <iostream>
#include "pathTools.h"
using namespace std;
int main(int argc, char *argv[])
{
// find current binary path
string progpath = getExecutablePath();
string cwd = removeLastPathElement(progpath);
string ld_path = computeAbsolutePath(cwd, "xulrunner");
// retrieve existing env if exist.
string previous_env;
char *previous_env_buf = getenv("LD_LIBRARY_PATH");
if (previous_env_buf == NULL)
previous_env = "";
else
previous_env = string(previous_env_buf);
// generate putenv string
string env_str = "LD_LIBRARY_PATH=" + ld_path + ":" + previous_env;
putenv((char *)env_str.c_str());
string xulrunner_path = computeAbsolutePath(cwd, "xulrunner/xulrunner");
string application_ini = computeAbsolutePath(cwd, "application.ini");
// debug prints
// cout << "CurProg: " << progpath << endl;
// cout << "cwd: " << cwd << endl;
// cout << "LD path: " << ld_path << endl;
// cout << "xulrunner_path: " << xulrunner_path << endl;
// cout << "application_ini: " << application_ini << endl;
// exist if xulrunner can't be found
if (!fileExists(xulrunner_path)) {
perror("Unable to find xulrunner binary");
return EXIT_FAILURE;
}
// execute xulrunner
return execl(xulrunner_path.c_str(), "xulrunner", application_ini.c_str(), "-jsconsole", NULL);
}