Changeset 15103


Ignore:
Timestamp:
2008-03-20T17:09:16+13:00 (14 years ago)
Author:
oranfry
Message:

massaged search4j to work in windows and linux

Location:
release-kits/shared/search4j
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • release-kits/shared/search4j/search4j.cpp

    r15093 r15103  
    77#include <iostream>
    88#include <fstream>
     9#include <string>
    910#include <sstream>
    10 #include <string>
     11
     12using namespace std;
     13
     14#ifdef WINDOWS
    1115#include <windows.h>
    12 using namespace std;
    13 
    1416
    1517//minimal launch4j stuff
     
    2022char foundJavaVer[128] = {0};
    2123
     24//windows functions
     25#define popen _popen
     26#define strcmp _stricmp
     27#endif /* WINDOWS */
     28
    2229
    2330//global variables
     
    5057int process( string command, string &output ) {
    5158   
    52     FILE   *pPipe;
     59    FILE *pPipe;
    5360
    5461    /* Run command so that it writes its output to a pipe. Open this
     
    5764    char cmd[1024]; strcpy(cmd, command.c_str());
    5865    //if ( verbose ) cout << "process(): running '" << command << "'" << endl;
    59     if( (pPipe = _popen( cmd, "rt" )) == NULL ) {
     66    #ifdef WINDOWS
     67    if( (pPipe = popen( cmd, "rt" )) == NULL ) {
    6068        if ( verbose ) cout << "could not start process" << endl;
    61         _pclose( pPipe );
     69        pclose( pPipe );
    6270        return -1;
    6371    }
     72    #endif
     73    #ifndef WINDOWS
     74    if( (pPipe = popen( cmd, "r" )) == NULL ) {
     75        if ( verbose ) cout << "could not start process" << endl;
     76        pclose( pPipe );
     77        return -1;
     78    }
     79    #endif
     80
    6481    //if ( verbose ) cout << "started process" << endl;
    6582
     
    8097
    8198    /* Close pipe and return return value of pPipe. */
    82     int code = _pclose( pPipe );
     99    int code = pclose( pPipe );
    83100    return code;
    84101}
     
    116133        string exec = "";
    117134        exec.append( javaHome );
     135       
     136        #ifdef WINDOWS
    118137        exec.append( "\\bin\\java.exe" );
     138        #endif
     139
     140        #ifndef WINDOWS
     141        exec.append( "/bin/java" );
     142        #endif
     143       
    119144        return exec;
    120145    }
     
    181206        command.append( "\"" );
    182207        command.append(" -version 2>&1");
     208        //cout << "(command: " << command << ")";
    183209        int result = process( command, output );
     210        //cout << "(output: " << output << ")";
    184211        if ( result == 0 ) {
    185             if ( _stricmp( output.substr( 0, 12 ).c_str() , "java version" ) == 0 || true ) {
     212            if ( strcmp( output.substr( 0, 12 ).c_str() , "java version" ) == 0 || true ) {
    186213                era = atoi( output.substr(14,1).c_str() );
    187214                major = atoi( output.substr(16,1).c_str() );
     
    265292Jvm minimum;
    266293
    267 
     294#ifdef WINDOWS
    268295void regSearch(HKEY hKey, const char* keyName, int searchType) {
    269296    DWORD x = 0;
     
    285312    }
    286313}
    287 
     314#endif
    288315
    289316/*
     
    303330        javaHome = getenv( "JAVA_HOME" );
    304331        if ( javaHome != NULL ) {
     332            if ( verbose ) cout << "(" << javaHome << ")";
    305333            jvm.setJavaHome( javaHome );
    306334            if ( jvm.check() ) {
     
    322350        javaHome = getenv( "JRE_HOME" );
    323351        if ( javaHome != NULL ) {
     352            if ( verbose ) cout << "(" << javaHome << ")";
    324353            jvm.setJavaHome( javaHome );
    325354            if ( jvm.check() ) {
     
    335364        if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
    336365    }
    337    
     366
     367    #ifdef WINDOWS
    338368    if ( !jvmFound ) {
    339369        //try the registry - this code based on launch4j code
     
    391421        if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; }
    392422    }
     423    #endif
    393424
    394425    return jvmFound;
     
    409440    //parse commandline arguments
    410441    for (int i=1; i<argc; i++) {
    411         if ( _stricmp(argv[i], "--verbose") == 0 ) {
     442        if ( strcmp(argv[i], "--verbose") == 0 ) {
    412443            verbose = true;
    413         } else if ( _stricmp(argv[i], "--help") == 0 || _stricmp(argv[i], "--usage") == 0 ) {
     444        } else if ( strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "--usage") == 0 ) {
    414445            usage();
    415446            return 0;
    416         } else if ( _stricmp(argv[i], "-v") == 0 ) {
     447        } else if ( strcmp(argv[i], "-v") == 0 ) {
    417448            jvmProperty = Version;
    418         } else if ( _stricmp(argv[i], "-e") == 0 ) {
     449        } else if ( strcmp(argv[i], "-e") == 0 ) {
    419450            jvmProperty = Executable;
    420         } else if ( _stricmp(argv[i], "-c") == 0 ) {
     451        } else if ( strcmp(argv[i], "-c") == 0 ) {
    421452            action = Compare;
    422453            if ( i == argc-1 ) {
     
    427458            }
    428459
    429             } else if ( _stricmp(argv[i], "-m") == 0 ) {
     460            } else if ( strcmp(argv[i], "-m") == 0 ) {
    430461            if ( i == argc-1 ) {
    431462                usage();
     
    439470            }
    440471
    441         } else if ( _stricmp(argv[i], "-l") == 0 ) {
     472        } else if ( strcmp(argv[i], "-l") == 0 ) {
    442473            action = Launch;
    443474            arg1 = argv[++i];
     
    521552    return 0;
    522553}
     554
Note: See TracChangeset for help on using the changeset viewer.