コード例 #1
0
ファイル: bitcoind.cpp プロジェクト: 1000000000001/bitcoin
//////////////////////////////////////////////////////////////////////////////
//
// Start
//
bool AppInit(int argc, char* argv[])
{
    boost::thread_group threadGroup;
    CScheduler scheduler;

    bool fRet = false;

    //
    // Parameters
    //
    // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
    ParseParameters(argc, argv);

    // Process help and version before taking care about datadir
    if (mapArgs.count("-?") || mapArgs.count("-h") ||  mapArgs.count("-help") || mapArgs.count("-version"))
    {
        std::string strUsage = strprintf(_("%s Daemon"), _(PACKAGE_NAME)) + " " + _("version") + " " + FormatFullVersion() + "\n";

        if (mapArgs.count("-version"))
        {
            strUsage += FormatParagraph(LicenseInfo());
        }
        else
        {
            strUsage += "\n" + _("Usage:") + "\n" +
                  "  bitcoind [options]                     " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n";

            strUsage += "\n" + HelpMessage(HMM_BITCOIND);
        }

        fprintf(stdout, "%s", strUsage.c_str());
        return false;
    }

    try
    {
        if (!boost::filesystem::is_directory(GetDataDir(false)))
        {
            fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
            return false;
        }
        try
        {
            ReadConfigFile(mapArgs, mapMultiArgs);
        } catch (const std::exception& e) {
            fprintf(stderr,"Error reading configuration file: %s\n", e.what());
            return false;
        }
        // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
        try {
            SelectParams(ChainNameFromCommandLine());
        } catch (const std::exception& e) {
            fprintf(stderr, "Error: %s\n", e.what());
            return false;
        }

        // Command-line RPC
        bool fCommandLine = false;
        for (int i = 1; i < argc; i++)
            if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "bitcoin:"))
                fCommandLine = true;

        if (fCommandLine)
        {
            fprintf(stderr, "Error: There is no RPC client functionality in bitcoind anymore. Use the bitcoin-cli utility instead.\n");
            exit(1);
        }
#ifndef WIN32
        fDaemon = GetBoolArg("-daemon", false);
        if (fDaemon)
        {
            fprintf(stdout, "Bitcoin server starting\n");

            // Daemonize
            pid_t pid = fork();
            if (pid < 0)
            {
                fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
                return false;
            }
            if (pid > 0) // Parent process, pid is child process id
            {
                return true;
            }
            // Child process falls through to rest of initialization

            pid_t sid = setsid();
            if (sid < 0)
                fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
        }
#endif
        SoftSetBoolArg("-server", true);

        // Set this early so that parameter interactions go to console
        InitLogging();
        InitParameterInteraction();
        fRet = AppInit2(threadGroup, scheduler);
    }
    catch (const std::exception& e) {
        PrintExceptionContinue(&e, "AppInit()");
    } catch (...) {
        PrintExceptionContinue(NULL, "AppInit()");
    }

    if (!fRet)
    {
        Interrupt(threadGroup);
        // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
        // the startup-failure cases to make sure they don't result in a hang due to some
        // thread-blocking-waiting-for-another-thread-during-startup case
    } else {
        WaitForShutdown(&threadGroup);
    }
    Shutdown();

    return fRet;
}
コード例 #2
0
/** "Help message" or "About" dialog box */
HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
    QDialog(parent),
    ui(new Ui::HelpMessageDialog)
{
    ui->setupUi(this);

    QString version = tr("CryptoMailCoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
    /* On x86 add a bit specifier to the version so that users can distinguish between
     * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
     */
#if defined(__x86_64__)
    version += " " + tr("(%1-bit)").arg(64);
#elif defined(__i386__ )
    version += " " + tr("(%1-bit)").arg(32);
#endif

    if (about)
    {
        setWindowTitle(tr("About CryptoMailCoin Core"));

        /// HTML-format the license message from the core
        QString licenseInfo = QString::fromStdString(LicenseInfo());
        QString licenseInfoHTML = licenseInfo;
        // Make URLs clickable
        QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
        uri.setMinimal(true); // use non-greedy matching
        licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
        // Replace newlines with HTML breaks
        licenseInfoHTML.replace("\n\n", "<br><br>");

        ui->aboutMessage->setTextFormat(Qt::RichText);
        ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        text = version + "\n" + licenseInfo;
        ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
        ui->aboutMessage->setWordWrap(true);
        ui->helpMessage->setVisible(false);
    } else {
        setWindowTitle(tr("Command-line options"));
        QString header = tr("Usage:") + "\n" +
            "  cryptomailcoin-qt [" + tr("command-line options") + "]                     " + "\n";
        QTextCursor cursor(ui->helpMessage->document());
        cursor.insertText(version);
        cursor.insertBlock();
        cursor.insertText(header);
        cursor.insertBlock();

        QString coreOptions = QString::fromStdString(HelpMessage(HMM_CRYPTOMAILCOIN_QT));
        text = version + "\n" + header + "\n" + coreOptions;

        QTextTableFormat tf;
        tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
        tf.setCellPadding(2);
        QVector<QTextLength> widths;
        widths << QTextLength(QTextLength::PercentageLength, 35);
        widths << QTextLength(QTextLength::PercentageLength, 65);
        tf.setColumnWidthConstraints(widths);

        QTextCharFormat bold;
        bold.setFontWeight(QFont::Bold);

        Q_FOREACH (const QString &line, coreOptions.split("\n")) {
            if (line.startsWith("  -"))
            {
                cursor.currentTable()->appendRows(1);
                cursor.movePosition(QTextCursor::PreviousCell);
                cursor.movePosition(QTextCursor::NextRow);
                cursor.insertText(line.trimmed());
                cursor.movePosition(QTextCursor::NextCell);
            } else if (line.startsWith("   ")) {
                cursor.insertText(line.trimmed()+' ');
            } else if (line.size() > 0) {
                //Title of a group
                if (cursor.currentTable())
                    cursor.currentTable()->appendRows(1);
                cursor.movePosition(QTextCursor::Down);
                cursor.insertText(line.trimmed(), bold);
                cursor.insertTable(1, 2, tf);
            }
        }

        ui->helpMessage->moveCursor(QTextCursor::Start);
        ui->scrollArea->setVisible(false);
        ui->aboutLogo->setVisible(false);
    }
}
コード例 #3
0
ファイル: darknetd.cpp プロジェクト: Darknet-Crypto/Darknet
//////////////////////////////////////////////////////////////////////////////
//
// Start
//
bool AppInit(int argc, char* argv[])
{
    boost::thread_group threadGroup;
    boost::thread* detectShutdownThread = NULL;

    bool fRet = false;

    //
    // Parameters
    //
    // If Qt is used, parameters/darknet.conf are parsed in qt/darknet.cpp's main()
    ParseParameters(argc, argv);

    // Process help and version before taking care about datadir
    if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
    {
        std::string strUsage = _("Darknet Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n";

        if (mapArgs.count("-version"))
        {
            strUsage += LicenseInfo();
        }
        else
        {
            strUsage += "\n" + _("Usage:") + "\n" +
                  "  darknetd [options]                     " + _("Start Darknet Core Daemon") + "\n";

            strUsage += "\n" + HelpMessage(HMM_BITCOIND);
        }

        fprintf(stdout, "%s", strUsage.c_str());
        return false;
    }

    try
    {
        if (!boost::filesystem::is_directory(GetDataDir(false)))
        {
            fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
            return false;
        }
        try
        {
            ReadConfigFile(mapArgs, mapMultiArgs);
        } catch(std::exception &e) {
            fprintf(stderr,"Error reading configuration file: %s\n", e.what());
            return false;
        }
        // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
        if (!SelectParamsFromCommandLine()) {
            fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
            return false;
        }

        // parse masternode.conf
        std::string strErr;
        if(!masternodeConfig.read(strErr)) {
            fprintf(stderr,"Error reading masternode configuration file: %s\n", strErr.c_str());
            return false;
        }

        // Command-line RPC
        bool fCommandLine = false;
        for (int i = 1; i < argc; i++)
            if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "darknet:"))
                fCommandLine = true;

        if (fCommandLine)
        {
            fprintf(stderr, "Error: There is no RPC client functionality in darknetd anymore. Use the darknet-cli utility instead.\n");
            exit(1);
        }
#ifndef WIN32
        fDaemon = GetBoolArg("-daemon", false);
        if (fDaemon)
        {
            fprintf(stdout, "DarkNet server starting\n");

            // Daemonize
            pid_t pid = fork();
            if (pid < 0)
            {
                fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
                return false;
            }
            if (pid > 0) // Parent process, pid is child process id
            {
                return true;
            }
            // Child process falls through to rest of initialization

            pid_t sid = setsid();
            if (sid < 0)
                fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
        }
#endif
        SoftSetBoolArg("-server", true);

        detectShutdownThread = new boost::thread(boost::bind(&DetectShutdownThread, &threadGroup));
        fRet = AppInit2(threadGroup);
    }
    catch (std::exception& e) {
        PrintExceptionContinue(&e, "AppInit()");
    } catch (...) {
        PrintExceptionContinue(NULL, "AppInit()");
    }

    if (!fRet)
    {
        if (detectShutdownThread)
            detectShutdownThread->interrupt();

        threadGroup.interrupt_all();
        // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
        // the startup-failure cases to make sure they don't result in a hang due to some
        // thread-blocking-waiting-for-another-thread-during-startup case
    }

    if (detectShutdownThread)
    {
        detectShutdownThread->join();
        delete detectShutdownThread;
        detectShutdownThread = NULL;
    }
    Shutdown();

    return fRet;
}
コード例 #4
0
ファイル: aslmain.c プロジェクト: samueldotj/AceOS
static int
AslCommandLine (
    int                     argc,
    char                    **argv)
{
    BOOLEAN                 BadCommandLine = FALSE;
    ACPI_NATIVE_INT         j;


    /* Minimum command line contains at least one option or an input file */

    if (argc < 2)
    {
        AslCompilerSignon (ASL_FILE_STDOUT);
        Usage ();
        exit (1);
    }

    /* Get the command line options */

    while ((j = AcpiGetopt (argc, argv, "2b:cd^e:fgh^i^l^o:p:r:s:t:v:w:x:")) != EOF) switch (j)
    {
    case '2':
        Gbl_Acpi2 = TRUE;
        break;


    case 'b':

        switch (AcpiGbl_Optarg[0])
        {
        case 'b':
            AslCompilerdebug = 1; /* same as yydebug */
            break;

        case 'p':
            AslCompilerdebug = 1; /* same as yydebug */
            break;

        case 't':
            break;

        default:
            printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
            BadCommandLine = TRUE;
            break;
        }

        /* Produce debug output file */

        Gbl_DebugFlag = TRUE;
        break;


    case 'c':

        /* Parse only */

        Gbl_ParseOnlyFlag = TRUE;
        break;


    case 'd':
        switch (AcpiGbl_Optarg[0])
        {
        case '^':
            Gbl_DoCompile = FALSE;
            break;

        case 'c':
            break;

        default:
            printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
            BadCommandLine = TRUE;
            break;
        }

        Gbl_DisasmFlag = TRUE;
        break;


    case 'e':
        Gbl_ExternalFilename = AcpiGbl_Optarg;
        break;


    case 'f':

        /* Ignore errors and force creation of aml file */

        Gbl_IgnoreErrors = TRUE;
        break;


    case 'g':

        /* Get all ACPI tables */

        Gbl_GetAllTables = TRUE;
        Gbl_DoCompile = FALSE;
        break;


    case 'h':

        switch (AcpiGbl_Optarg[0])
        {
        case '^':
            HelpMessage ();
            exit (0);

        case 'c':
            UtDisplayConstantOpcodes ();
            exit (0);

        case 'r':
            /* reserved names */

            MpDisplayReservedNames ();
            exit (0);

        default:
            printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
            BadCommandLine = TRUE;
            break;
        }
        break;


    case 'i':

        switch (AcpiGbl_Optarg[0])
        {
        case 'a':

            /* Produce assembly code include file */

            Gbl_AsmIncludeOutputFlag = TRUE;
            break;

        case 'c':

            /* Produce C include file */

            Gbl_C_IncludeOutputFlag = TRUE;
            break;

        default:
            printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
            BadCommandLine = TRUE;
            break;
        }
        break;


    case 'l':

        switch (AcpiGbl_Optarg[0])
        {
        case '^':
            /* Produce listing file (Mixed source/aml) */

            Gbl_ListingFlag = TRUE;
            break;

        case 'n':
            /* Produce namespace file */

            Gbl_NsOutputFlag = TRUE;
            break;

        case 's':
            /* Produce combined source file */

            Gbl_SourceOutputFlag = TRUE;
            break;

        default:
            printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
            BadCommandLine = TRUE;
            break;
        }
        break;


    case 'o':

        switch (AcpiGbl_Optarg[0])
        {
        case 'a':

            /* Disable all optimizations */

            Gbl_FoldConstants = FALSE;
            Gbl_IntegerOptimizationFlag = FALSE;
            Gbl_ReferenceOptimizationFlag = FALSE;
            break;

        case 'f':

            /* Disable folding on "normal" expressions */

            Gbl_FoldConstants = FALSE;
            break;

        case 'i':

            /* Disable integer optimization to constants */

            Gbl_IntegerOptimizationFlag = FALSE;
            break;

        case 'n':

            /* Disable named reference optimization */

            Gbl_ReferenceOptimizationFlag = FALSE;
            break;

        case 't':

            /* Display compile time(s) */

            Gbl_CompileTimesFlag = TRUE;
            break;

        default:
            printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
            BadCommandLine = TRUE;
            break;
        }
        break;


    case 'p':

        /* Override default AML output filename */

        Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
        Gbl_UseDefaultAmlFilename = FALSE;
        break;


    case 'r':
        Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
        break;


    case 's':

        switch (AcpiGbl_Optarg[0])
        {
        case 'a':

            /* Produce assembly code output file */

            Gbl_AsmOutputFlag = TRUE;
            break;

        case 'c':

            /* Produce C hex output file */

            Gbl_C_OutputFlag = TRUE;
            break;

        default:
            printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
            BadCommandLine = TRUE;
            break;
        }
        break;


    case 't':

        /* Produce hex table output file */

        switch (AcpiGbl_Optarg[0])
        {
        case 'a':
            Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
            break;

        case 'c':
            Gbl_HexOutputFlag = HEX_OUTPUT_C;
            break;

        default:
            printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
            BadCommandLine = TRUE;
            break;
        }
        break;


    case 'v':

        switch (AcpiGbl_Optarg[0])
        {
        case 'i':
            /* Less verbose error messages */

            Gbl_VerboseErrors = FALSE;
            break;

        case 'o':
            Gbl_DisplayOptimizations = TRUE;
            break;

        case 'r':
            Gbl_DisplayRemarks = FALSE;
            break;

        case 's':
            Gbl_DoSignon = FALSE;
            break;

        default:
            printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
            BadCommandLine = TRUE;
            break;
        }
        break;


    case 'w': /* Set warning levels */

        switch (AcpiGbl_Optarg[0])
        {
        case '1':
            Gbl_WarningLevel = ASL_WARNING;
            break;

        case '2':
            Gbl_WarningLevel = ASL_WARNING2;
            break;

        case '3':
            Gbl_WarningLevel = ASL_WARNING3;
            break;

        default:
            printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
            BadCommandLine = TRUE;
            break;
        }
        break;


    case 'x':

        AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
        break;


    default:

        BadCommandLine = TRUE;
        break;
    }

    /* Next parameter must be the input filename */

    if (!argv[AcpiGbl_Optind] &&
        !Gbl_DisasmFlag &&
        !Gbl_GetAllTables)
    {
        printf ("Missing input filename\n");
        BadCommandLine = TRUE;
    }

    if (Gbl_DoSignon)
    {
        AslCompilerSignon (ASL_FILE_STDOUT);
    }

    /* Abort if anything went wrong on the command line */

    if (BadCommandLine)
    {
        printf ("\n");
        Usage ();
        exit (1);
    }

    return (AcpiGbl_Optind);
}
コード例 #5
0
   ############################################################################################################################ */

int main (int argc, char **argv)
{

/* **************************************************************************************************************************** */

 	/* Pointeurs vers l'application */
	glutInit(&argc, argv);         

  	/*  Activation des buffers :   
     	Double buffer 
     	RGBA color
     	Depth buffer */               
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); 

  	/* Création de la fenêtre */
	glutInitWindowSize(1024, 768);

	/* Positionnement de la fenêtre */
	glutInitWindowPosition(100, 100);

	/* Ouverture de la fenêtre */  
	glutCreateWindow("TD_Animation_3D");

	/* Spécification de la fontion de dessin */
	glutDisplayFunc(display);

  	/* Spécification de la fontion de redimensionnement */
	glutReshapeFunc(reshape);

  	/* Spécification des fontions de gestion du clavier */
	glutKeyboardFunc(keyboardDown);
	glutKeyboardUpFunc(keyboardUp);
	glutSpecialFunc(keyboardSpecDown);
	glutSpecialUpFunc(keyboardSpecUp);

 	/* Spécification des fontions de gestion de la souris */
	glutMouseFunc(mouse);
	glutMotionFunc(motion);

 	/* Spécification de la fonction de mise-à-jour */
	glutIdleFunc(timeTick);

/* **************************************************************************************************************************** */

	/* Affichage des fonctions clavier */
	HelpMessage();

/* **************************************************************************************************************************** */

	/* Intitialisation des paramètres de l'affichage et de la fenêtre */
	GLInit();

	/* Intitialisation des paramètres du squelette */ 
	SkeletInit();

	/* Intitialisation de la scène cinématique */
	IKInit();

/* **************************************************************************************************************************** */

  	/* Lancement de la boucle OpenGL */  
	glutMainLoop();

/* **************************************************************************************************************************** */

	return 0;
コード例 #6
0
ファイル: aslmain.c プロジェクト: luciang/haiku
static int
AslDoOptions (
    int                     argc,
    char                    **argv,
    BOOLEAN                 IsResponseFile)
{
    int                     j;


    /* Get the command line options */

    while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
    {
    case '@':   /* Begin a response file */

        if (IsResponseFile)
        {
            printf ("Nested command files are not supported\n");
            return -1;
        }

        if (AslDoResponseFile (AcpiGbl_Optarg))
        {
            return -1;
        }
        break;


    case '2':

        Gbl_Acpi2 = TRUE;
        break;


    case 'b':

        switch (AcpiGbl_Optarg[0])
        {
        case 'b':
            AslCompilerdebug = 1; /* same as yydebug */
            break;

        case 'p':
            AslCompilerdebug = 1; /* same as yydebug */
            break;

        case 't':
            break;

        default:
            printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
            return (-1);
        }

        /* Produce debug output file */

        Gbl_DebugFlag = TRUE;
        break;


    case 'c':
        switch (AcpiGbl_Optarg[0])
        {
        case 'r':
            Gbl_NoResourceChecking = TRUE;
            break;

        default:
            printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
            return (-1);
        }
        break;


    case 'd':
        switch (AcpiGbl_Optarg[0])
        {
        case '^':
            Gbl_DoCompile = FALSE;
            break;

        case 'c':
            break;

        default:
            printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
            return (-1);
        }

        Gbl_DisasmFlag = TRUE;
        break;


    case 'e':
        Gbl_ExternalFilename = AcpiGbl_Optarg;
        break;


    case 'f':

        /* Ignore errors and force creation of aml file */

        Gbl_IgnoreErrors = TRUE;
        break;


    case 'g':

        /* Get all ACPI tables */

        Gbl_GetAllTables = TRUE;
        Gbl_DoCompile = FALSE;
        break;


    case 'h':

        switch (AcpiGbl_Optarg[0])
        {
        case '^':
            HelpMessage ();
            exit (0);

        case 'c':
            UtDisplayConstantOpcodes ();
            exit (0);

        case 'r':
            /* reserved names */

            ApDisplayReservedNames ();
            exit (0);

        default:
            printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
            return (-1);
        }
        break;


    case 'I': /* Add an include file search directory */

        FlAddIncludeDirectory (AcpiGbl_Optarg);
        break;


    case 'i':

        switch (AcpiGbl_Optarg[0])
        {
        case 'a':

            /* Produce assembly code include file */

            Gbl_AsmIncludeOutputFlag = TRUE;
            break;

        case 'c':

            /* Produce C include file */

            Gbl_C_IncludeOutputFlag = TRUE;
            break;

        default:
            printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
            return (-1);
        }
        break;


    case 'l':

        switch (AcpiGbl_Optarg[0])
        {
        case '^':
            /* Produce listing file (Mixed source/aml) */

            Gbl_ListingFlag = TRUE;
            break;

        case 'n':
            /* Produce namespace file */

            Gbl_NsOutputFlag = TRUE;
            break;

        case 's':
            /* Produce combined source file */

            Gbl_SourceOutputFlag = TRUE;
            break;

        default:
            printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
            return (-1);
        }
        break;


    case 'o':

        switch (AcpiGbl_Optarg[0])
        {
        case 'a':

            /* Disable all optimizations */

            Gbl_FoldConstants = FALSE;
            Gbl_IntegerOptimizationFlag = FALSE;
            Gbl_ReferenceOptimizationFlag = FALSE;
            break;

        case 'f':

            /* Disable folding on "normal" expressions */

            Gbl_FoldConstants = FALSE;
            break;

        case 'i':

            /* Disable integer optimization to constants */

            Gbl_IntegerOptimizationFlag = FALSE;
            break;

        case 'n':

            /* Disable named reference optimization */

            Gbl_ReferenceOptimizationFlag = FALSE;
            break;

        case 't':

            /* Display compile time(s) */

            Gbl_CompileTimesFlag = TRUE;
            break;

        default:
            printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
            return (-1);
        }
        break;


    case 'n':

        /* Parse only */

        Gbl_ParseOnlyFlag = TRUE;
        break;


    case 'p':

        /* Override default AML output filename */

        Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
        Gbl_UseDefaultAmlFilename = FALSE;
        break;


    case 'r':
        Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
        break;


    case 's':

        switch (AcpiGbl_Optarg[0])
        {
        case 'a':

            /* Produce assembly code output file */

            Gbl_AsmOutputFlag = TRUE;
            break;

        case 'c':

            /* Produce C hex output file */

            Gbl_C_OutputFlag = TRUE;
            break;

        default:
            printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
            return (-1);
        }
        break;


    case 't':

        /* Produce hex table output file */

        switch (AcpiGbl_Optarg[0])
        {
        case 'a':
            Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
            break;

        case 'c':
            Gbl_HexOutputFlag = HEX_OUTPUT_C;
            break;

        case 's':
            Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
            break;

        default:
            printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
            return (-1);
        }
        break;


    case 'v':

        switch (AcpiGbl_Optarg[0])
        {
        case 'a':
            /* Disable All error/warning messages */

            Gbl_NoErrors = TRUE;
            break;

        case 'i':
            /* Less verbose error messages */

            Gbl_VerboseErrors = FALSE;
            break;

        case 'o':
            Gbl_DisplayOptimizations = TRUE;
            break;

        case 'r':
            Gbl_DisplayRemarks = FALSE;
            break;

        case 's':
            Gbl_DoSignon = FALSE;
            break;

        default:
            printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
            return (-1);
        }
        break;


    case 'w': /* Set warning levels */

        switch (AcpiGbl_Optarg[0])
        {
        case '1':
            Gbl_WarningLevel = ASL_WARNING;
            break;

        case '2':
            Gbl_WarningLevel = ASL_WARNING2;
            break;

        case '3':
            Gbl_WarningLevel = ASL_WARNING3;
            break;

        default:
            printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
            return (-1);
        }
        break;


    case 'x':

        AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
        break;


    default:

        return (-1);
    }

    return (0);
}
コード例 #7
0
/** "Help message" or "About" dialog box */
HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
    QDialog(parent),
    ui(new Ui::HelpMessageDialog)
{
    ui->setupUi(this);
    this->setWindowModality(Qt::NonModal);
            
    GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this);

    QString version = tr("Bitcredit Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
    /* On x86 add a bit specifier to the version so that users can distinguish between
     * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
     */
#if defined(__x86_64__)
    version += " " + tr("(%1-bit)").arg(64);
#elif defined(__i386__ )
    version += " " + tr("(%1-bit)").arg(32);
#endif

    if (about)
    {
        setWindowTitle(tr("About Bitcredit Core"));

        /// HTML-format the license message from the core
        QString licenseInfo = QString::fromStdString(LicenseInfo());
        QString licenseInfoHTML = licenseInfo;
        // Make URLs clickable
        QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
        uri.setMinimal(true); // use non-greedy matching
        licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
        // Replace newlines with HTML breaks
        licenseInfoHTML.replace("\n\n", "<br><br>");

        //ui->helpMessage->setTextFormat(Qt::RichText);
        //ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        text = version + "\n" + licenseInfo;
        ui->helpMessage->setText(version + "<br><br>" + licenseInfoHTML);
        //ui->helpMessage->setWordWrap(true);
        
        connect(ui->pushButtonBCT, SIGNAL(clicked()), this, SLOT(BCT()));
        connect(ui->pushButtonForum, SIGNAL(clicked()), this, SLOT(Forum()));
        connect(ui->pushButtonWiki, SIGNAL(clicked()), this, SLOT(Wiki()));
        connect(ui->pushButtonExplorer, SIGNAL(clicked()), this, SLOT(Explorer()));
       
        
        
        
    } else {
        setWindowTitle(tr("Command-line options"));
        QString header = tr("Usage:") + "\n" +
            "  bitcredit-qt [" + tr("command-line options") + "]                     " + "\n";

        QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCREDIT_QT));

        QString uiOptions = tr("UI options") + ":\n" +
            "  -choosedatadir            " + tr("Choose data directory on startup (default: 0)") + "\n" +
            "  -lang=<lang>              " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" +
            "  -min                      " + tr("Start minimized") + "\n" +
            "  -rootcertificates=<file>  " + tr("Set SSL root certificates for payment request (default: -system-)") + "\n" +
            "  -splash                   " + tr("Show splash screen on startup (default: 1)");

        ui->helpMessage->setFont(GUIUtil::bitcreditAddressFont());
        text = version + "\n" + header + "\n" + coreOptions + "\n" + uiOptions;
        ui->helpMessage->setText(text);
    }
}
コード例 #8
0
ファイル: bitcoind.cpp プロジェクト: Tinege/Tinege
//////////////////////////////////////////////////////////////////////////////
//
// Start
//
bool AppInit(int argc, char* argv[])
{
    boost::thread_group threadGroup;
    boost::thread* detectShutdownThread = NULL;

    bool fRet = false;
    try
    {
        //
        // Parameters
        //
        // If Qt is used, parameters/tinege.conf are parsed in qt/bitcoin.cpp's main()
        ParseParameters(argc, argv);
        if (!boost::filesystem::is_directory(GetDataDir(false)))
        {
            fprintf(stderr, "Error: Specified directory does not exist\n");
            Shutdown();
        }
        ReadConfigFile(mapArgs, mapMultiArgs);

        if (mapArgs.count("-?") || mapArgs.count("--help"))
        {
            // First part of help message is specific to tineged / RPC client
            std::string strUsage = _("Tinege version") + " " + FormatFullVersion() + "\n\n" +
                _("Usage:") + "\n" +
                  "  tineged [options]                     " + "\n" +
                  "  tineged [options] <command> [params]  " + _("Send command to -server or tineged") + "\n" +
                  "  tineged [options] help                " + _("List commands") + "\n" +
                  "  tineged [options] help <command>      " + _("Get help for a command") + "\n";

            strUsage += "\n" + HelpMessage();

            fprintf(stdout, "%s", strUsage.c_str());
            return false;
        }

        // Command-line RPC
        for (int i = 1; i < argc; i++)
            if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "tinege:"))
                fCommandLine = true;

        if (fCommandLine)
        {
            if (!SelectParamsFromCommandLine()) {
                fprintf(stderr, "Error: invalid combination of -regtest and -testnet.\n");
                return false;
            }
            int ret = CommandLineRPC(argc, argv);
            exit(ret);
        }
#if !defined(WIN32)
        fDaemon = GetBoolArg("-daemon", false);
        if (fDaemon)
        {
            // Daemonize
            pid_t pid = fork();
            if (pid < 0)
            {
                fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
                return false;
            }
            if (pid > 0) // Parent process, pid is child process id
            {
                CreatePidFile(GetPidFile(), pid);
                return true;
            }
            // Child process falls through to rest of initialization

            pid_t sid = setsid();
            if (sid < 0)
                fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
        }
#endif

        detectShutdownThread = new boost::thread(boost::bind(&DetectShutdownThread, &threadGroup));
        fRet = AppInit2(threadGroup);
    }
    catch (std::exception& e) {
        PrintExceptionContinue(&e, "AppInit()");
    } catch (...) {
        PrintExceptionContinue(NULL, "AppInit()");
    }
    if (!fRet) {
        if (detectShutdownThread)
            detectShutdownThread->interrupt();
        threadGroup.interrupt_all();
    }

    if (detectShutdownThread)
    {
        detectShutdownThread->join();
        delete detectShutdownThread;
        detectShutdownThread = NULL;
    }
    Shutdown();

    return fRet;
}
コード例 #9
0
ファイル: ffind.cpp プロジェクト: datareel/datareel
int ProcessArgs(char *arg)
{
  char line_buf[1024];
  gxString dash_arg, dash_option, line;
  int has_dash_arg = 0;
  int num_lines = 0;
  DiskFileB infile;

  switch(arg[1]) {
    case 'a':
      append_lines = 0;
      break;
      
    case 'c':
      cat_file = 1;
      break;

    case 'f':				
      if(arg[2] == '\0') {
	GXSTD::cerr << "\n";
	GXSTD::cerr << "You must enter a string following the -f option." 
		    << "\n";
	GXSTD::cerr << "Example usage: " << ProgramName << " -f\"string\"" 
		    << "\n"; 
	GXSTD::cerr << "\n";
	return 0;
      }
      find_string = 1;
      find_all = 0;
      replacing_line = 0;  
      replacing_string = 0;  
      inserting_string = 0;
      string_to_find = arg+2;
      InsertEscapeSeq(string_to_find);
      break;

    case 'F':				
      if(arg[2] == '\0') {
	GXSTD::cerr << "\n";
	GXSTD::cerr << "You must enter a string following the -F option." 
		    << "\n";
	GXSTD::cerr << "Example usage: " << ProgramName << " -F\"string\"" 
		    << "\n"; 
	GXSTD::cerr << "\n";
	return 0;
      }
      find_string = 1;
      find_all =1;
      replacing_line = 0;  
      replacing_string = 0;  
      inserting_string = 0;
      string_to_find = arg+2;
      InsertEscapeSeq(string_to_find);
      break;

    case 'i':
      check_case = 0;
      break;

    case 'R':
      if(arg[2] == '\0') {
	GXSTD::cerr << "\n";
	GXSTD::cerr << "You must enter a string following the -R option." 
		    << "\n";
	GXSTD::cerr << "Example usage: " << ProgramName << " -R\"string\"" 
		    << "\n"; 
	GXSTD::cerr << "\n";
	return 0;
      }
      string_to_replace = arg+2;
      replacing_string = 1;  
      replacing_line = 0;
      inserting_string = 0;
      find_string = 0;
      find_all = 0;
      InsertEscapeSeq(string_to_replace);
      break;

    case 'L':
      if(arg[2] == '\0') {
	GXSTD::cerr << "\n";
	GXSTD::cerr << "You must enter a string following the -L option." 
		    << "\n";
	GXSTD::cerr << "Example usage: " << ProgramName << " -L\"string\"" 
		    << "\n"; 	GXSTD::cerr << "\n";
	return 0;
      }
      string_to_replace = arg+2;
      replacing_line = 1;  
      replacing_string = 0;
      inserting_string = 0;
      find_string = 0;
      find_all = 0;
      InsertEscapeSeq(string_to_replace);
      break;

    case 'I':
      if(arg[2] == '\0') {
	GXSTD::cerr << "\n";
	GXSTD::cerr << "You must enter a string following the -I option." 
		    << "\n";
	GXSTD::cerr << "Example usage: " << ProgramName << " -I\"string\"" 
		    << "\n"; 
	GXSTD::cerr << "\n";
	return 0;
      }
      string_to_replace = arg+2;
      InsertEscapeSeq(string_to_replace);
      inserting_string = 1;
      replacing_line = 0;  
      replacing_string = 0;  
      find_string = 0;
      find_all = 0;
      InsertEscapeSeq(string_to_replace);
      break;

    case 'W':
      if(arg[2] == '\0') {
	GXSTD::cerr << "\n";
	GXSTD::cerr << "You must enter a string following the -W option." 
		    << "\n";
	GXSTD::cerr << "Example usage: " << ProgramName << " -W\"string\"" 
		    << "\n"; 
	GXSTD::cerr << "\n";
	return 0;
      }

      if(string_to_replace.is_null()) {
	GXSTD::cerr << "\n";
	GXSTD::cerr << "The -W option must be used with the -R, -L, or -I option." << "\n";
	GXSTD::cerr << "Usage: -R\"string\" -W\"replacement\"" << "\n";
	GXSTD::cerr << "\n";
	return 0;
      }

      string_to_insert = arg+2;
      InsertEscapeSeq(string_to_insert);
      break;
      
    case '-':
      if(arg[2] == '\0') {
	GXSTD::cerr << "\n";
	GXSTD::cerr << "You must enter an option and -- argument." 
		    << "\n";
	GXSTD::cerr << "Example usage: " << ProgramName << " --infile=\"textfile.txt\"" 
		    << "\n"; 
	GXSTD::cerr << "\n";
	return 0;
      }

      dash_arg = arg+2;
      if(dash_arg.Find("=") != -1) {
	dash_option = arg+2;
	dash_option.DeleteAfterIncluding("=");
	dash_arg.DeleteBeforeIncluding("=");
      }
      else {
	dash_option.Clear();
      }

      if(dash_option == "infile") {
	if(dash_option.is_null()) {
	  GXSTD::cerr << "\n";
	  GXSTD::cerr << "Error you must supply a file name with the --infile argument" 
		      << "\n";
	  GXSTD::cerr << "Exiting..." << "\n";
	  GXSTD::cerr << "\n";
	  return 0;
	}
	input_file_name = dash_arg;
	has_dash_arg = 1;
	infile.df_Open(input_file_name.c_str());
	if(infile.df_CheckError()) {
	  GXSTD::cerr << "\n";
	  GXSTD::cerr << "Error opening infile " << input_file_name.c_str() << "\n";
	  GXSTD::cerr << "Exiting..." << "\n";
	  GXSTD::cerr << "\n";
	  return 0;
	}
	string_to_insert.Clear();
	while(!infile.df_EOF()) {
	  memset(line_buf, 0, sizeof(line_buf));
	  infile.df_Read(line_buf, sizeof(line_buf));
	  if(infile.df_GetError() != DiskFileB::df_NO_ERROR) {
	    if(infile.df_GetError() != DiskFileB::df_EOF_ERROR) {
	      GXSTD::cerr << "Error reading from the text file" << "\n";
	      GXSTD::cerr << infile.df_ExceptionMessage() << "\n";
	      GXSTD::cerr << "\n";
	      GXSTD::cerr << "Error reading infile " << input_file_name.c_str() << "\n";
	      GXSTD::cerr << "Exiting..." << "\n";
	      GXSTD::cerr << "\n";
	      return 0;
	    }
	  }
	  string_to_insert.Cat(line_buf, infile.df_gcount());
	} 
	infile.df_Close();
	string_to_insert.ReplaceString("\r\n", "\n");
	InsertEscapeSeq(string_to_insert);
      }

      if(dash_option == "SurroundBy") {
	surround_by = 1;
	has_dash_arg = 1;
	if(dash_option.is_null()) {
	  surround_by_str = "\""; // Assume double quotes
	}
	else {
	  if(dash_arg == "Quotes") {
	    surround_by_str = "\"";
	  }
	  else if(dash_arg == "SingleQuotes") {
	    surround_by_str = "\'";
	  }
	  else {
	    surround_by_str = dash_arg;
	  }
	}
      }

      if(dash_option == "TerminateWith") {
	if(dash_option.is_null()) {
	  GXSTD::cerr << "\n";
	  GXSTD::cerr << "Error you must supply a string with the --TerminateWith argument" 
		      << "\n";
	  GXSTD::cerr << "Exiting..." << "\n";
	  GXSTD::cerr << "\n";
	  return 0;
	}
	has_dash_arg = 1;
	terminate_line = 1;
	terminate_str = dash_arg;
	InsertEscapeSeq(terminate_str);
      }
      
      if(dash_option == "TrimLeading") {
	if(dash_option.is_null()) {
	  GXSTD::cerr << "\n";
	  GXSTD::cerr << "Error you must supply a string with the --TrimLeading argument" 
		      << "\n";
	  GXSTD::cerr << "Exiting..." << "\n";
	  GXSTD::cerr << "\n";
	  return 0;
	}
	has_dash_arg = 1;
	trim_leading_char << dash_arg;
	InsertEscapeSeq(trim_leading_char);
      }

      if(dash_option == "TrimTrailing") {
	if(dash_option.is_null()) {
	  GXSTD::cerr << "\n";
	  GXSTD::cerr << "Error you must supply a string with the --TrimTrialing argument" 
		      << "\n";
	  GXSTD::cerr << "Exiting..." << "\n";
	  GXSTD::cerr << "\n";
	  return 0;
	}
	has_dash_arg = 1;


	trim_trailing_char << dash_arg;
	InsertEscapeSeq(trim_trailing_char);
      }

      if(dash_option == "ReplaceSection") {
	replace_section = 1;
	has_dash_arg = 1;
	if(!dash_arg.is_null()) {
	  replace_file_name = dash_arg;
	  if(!replace_file_name.is_null()) {
	    infile.df_Open(replace_file_name.c_str());
	    if(infile.df_CheckError()) {
	      GXSTD::cerr << "\n";
	      GXSTD::cerr << "Error opening replace section file " << replace_file_name.c_str() << "\n";
	      GXSTD::cerr << "Exiting..." << "\n";
	      GXSTD::cerr << "\n";
	      return 0;
	    }
	    string_to_replace.Clear();
	    while(!infile.df_EOF()) {
	      memset(line_buf, 0, sizeof(line_buf));
	      infile.df_Read(line_buf, sizeof(line_buf));
	      if(infile.df_GetError() != DiskFileB::df_NO_ERROR) {
		if(infile.df_GetError() != DiskFileB::df_EOF_ERROR) {
		  GXSTD::cerr << "Error reading from the text file" << "\n";
		  GXSTD::cerr << infile.df_ExceptionMessage() << "\n";
		  GXSTD::cerr << "\n";
		  GXSTD::cerr << "Error reading replace section file " << replace_file_name.c_str() << "\n";
		  GXSTD::cerr << "Exiting..." << "\n";
		  GXSTD::cerr << "\n";
		}
	      }
	      string_to_replace.Cat(line_buf, infile.df_gcount());
	    } 
	    infile.df_Close();
	    string_to_replace.ReplaceString("\r\n", "\n");
	    InsertEscapeSeq(string_to_replace);
	  }
	}
      }

      if(dash_arg == "version") {
	VersionMessage();
	return 0;
      }

      if(dash_arg == "help") {
	HelpMessage();
	return 0;
      }

      if(dash_arg == "ReplaceOnce") {
	replace_once = 1;
	has_dash_arg = 1;
      }

      if(dash_arg == "NoEscapeSeq") {
	no_escape_seq = 1;
	has_dash_arg = 1;
      }

      if(!has_dash_arg) {
	GXSTD::cerr << "\n";
	GXSTD::cerr << "Invalid option and -- argument " << "\n";
	GXSTD::cerr << arg << "\n";
	GXSTD::cerr << "Exiting..." << "\n";
	GXSTD::cerr << "\n";
	return 0;
      }
      break;

    default:
      GXSTD::cerr << "\n";
      GXSTD::cerr << "Unknown switch " << arg << "\n";
      GXSTD::cerr << "Exiting..." << "\n";
      GXSTD::cerr << "\n";
      return 0;
  }
  arg[0] = '\0';
  return 1; // All command line arguments were valid
}
コード例 #10
0
ファイル: eccoind.cpp プロジェクト: AltJ/ECCoin
//////////////////////////////////////////////////////////////////////////////
//
// Start
//
bool AppInit(int argc, char *argv[])
{
    shutdown_threads.store(false);
    thread_group threadGroup(&shutdown_threads);

    bool fRet = false;

    //
    // Parameters
    //
    gArgs.ParseParameters(argc, argv);

    // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
    try
    {
        CheckParams(ChainNameFromCommandLine());
    }
    catch (const std::exception &e)
    {
        fprintf(stderr, "Error: %s\n", e.what());
        return false;
    }
    try
    {
        gArgs.ReadConfigFile();
    }
    catch (const std::exception &e)
    {
        fprintf(stderr, "Error reading configuration file: %s\n", e.what());
        return false;
    }

    GenerateNetworkTemplates();

    // Process help and version before taking care about datadir
    if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version"))
    {
        std::string strUsage = "Eccoind version " + FormatFullVersion() + "\n";

        if (gArgs.IsArgSet("-version"))
        {
            strUsage += LicenseInfo();
        }
        else
        {
            strUsage += "\nUsage:\neccoind [options]                     Start Eccoind\n";

            strUsage += "\n" + HelpMessage();
        }

        fprintf(stdout, "%s", strUsage.c_str());
        return false;
    }

    try
    {
        if (!fs::is_directory(GetDataDir(false)))
        {
            fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n",
                gArgs.GetArg("-datadir", "").c_str());
            return false;
        }
        // Command-line RPC
        bool fCommandLine = false;
        for (int i = 1; i < argc; i++)
        {
            if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "ECC:"))
            {
                fCommandLine = true;
            }
        }
        if (fCommandLine)
        {
            int ret = CommandLineRPC(argc, argv);
            exit(ret);
        }
#ifndef WIN32
        fDaemon = gArgs.GetBoolArg("-daemon", false);
        if (fDaemon)
        {
            fprintf(stdout, "Eccoind server starting\n");

            // Daemonize
            pid_t pid = fork();
            if (pid < 0)
            {
                fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
                return false;
            }
            if (pid > 0) // Parent process, pid is child process id
            {
                return true;
            }
            // Child process falls through to rest of initialization

            pid_t sid = setsid();
            if (sid < 0)
                fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
        }
#endif
        gArgs.SoftSetBoolArg("-server", true);
        // Set this early so that parameter interactions go to console
        InitLogging();
        InitParameterInteraction();
        fRet = AppInit2(threadGroup);
    }
    catch (const std::exception &e)
    {
        PrintExceptionContinue(&e, "AppInit()");
    }
    catch (...)
    {
        PrintExceptionContinue(NULL, "AppInit()");
    }

    if (!fRet)
    {
        Interrupt(threadGroup);
    }
    else
    {
        WaitForShutdown(&threadGroup);
    }
    Shutdown();

    return fRet;
}
コード例 #11
0
ファイル: ffind.cpp プロジェクト: datareel/datareel
// Program's main thread of execution.
// ----------------------------------------------------------- 
int main(int argc,   // Number of strings in array argv.
	 char *argv[], // Array of command-line argument strings.
	 char *envp[]) // Array of environment variable strings.
// NOTE: None of the MSVC compilers will expand wildcard characters
// used in command-line arguments unless linked with the setargv.obj
// library. All the UNIX compliers will expand wildcard characters
// by default.
{
#ifdef __MSVC_DEBUG__
  InitLeakTest();
#endif

  // If no arguments are given print usage message to the screen 
  if(argc < 2) {
    HelpMessage();
    return 0;
  }

  // Process command ling arguments and files 
  int narg;
  char *arg = argv[narg = 1];
  while (narg < argc) {
    if (arg[0] != '\0') {
      if (arg[0] == '-') { // Look for command line arguments
	if(!ProcessArgs(arg)) return 0; // Exit if argument is not valid
      }
      else { 
	if(futils_isdirectory((const char *)arg)) {
	  // Do not process directories
	  arg = argv[++narg];
	  continue;
	}
	open_file = arg; // Update the open file name pointer
	DiskFileB iofile(open_file);
	if(!iofile) { // Skip over directory names
	  if(narg < argc) {
	    arg = argv[++narg];
	    iofile.df_Close();
	    continue; 
	  }
	  else { // Cannot open the specified file
	    GXSTD::cerr << "\n";
	    GXSTD::cerr << "Cannot open file: " << open_file << "\n";
	    GXSTD::cerr << "Exiting..." << "\n";
	    GXSTD::cerr << "\n";
	    return 0;
	  }
	}
	num_files++;

	if(replace_section) {
	  num_matches = 0; num_replaced = 0; num_processed = 0;
	  if(!ReplaceBySection(iofile, GXSTD::cout)) return 0;
	  arg = argv[++narg];
	  if(num_files) iofile.df_Close();
	  continue;
	}

	// Echo the name of the file and search operation
	// ----------------------------------------------------------- 
	if(replacing_string == 1) {
	  if(string_to_insert.is_null()) {
	    GXSTD::cerr << "\n";
	    GXSTD::cerr << "The -R option must be used with the -W option." 
			<< "\n";
	    GXSTD::cerr << "Usage: -R\"string\" -W\"replacement\"" << "\n";
	    GXSTD::cerr << "\n";
	    return 0;
	  }
	  num_processed = 0; // Number of string processed for this file
	  GXSTD::cout << "\n";
	  GXSTD::cout << "Opening file: " << open_file << "\n";
	  GXSTD::cout << "Replacing: " << string_to_replace.c_str() << "\n";
	  GXSTD::cout << "With: " << string_to_insert.c_str() << "\n";
	}

	if(replacing_line) {
	  if(string_to_insert.is_null()) {
	    GXSTD::cerr << "\n";
	    GXSTD::cerr << "The -L option must be used with the -W option." 
			<< "\n";
	    GXSTD::cerr << "Usage: -L\"string\" -W\"replacement\"" << "\n";
	    return 0;
	  }
	  num_processed = 0; // Number of string processed for this file
	  GXSTD::cout << "\n";
	  GXSTD::cout << "Opening file: " << open_file << "\n";
	  GXSTD::cout << "Replacing line after: " << string_to_replace.c_str() << "\n";
	  GXSTD::cout << "With: " << string_to_insert.c_str() << "\n";
	}

	if(inserting_string ) {
	  if(string_to_insert.is_null()) {
	    GXSTD::cerr << "\n";
	    GXSTD::cerr << "The -I option must be used with the -W option." 
			<< "\n";
	    GXSTD::cerr << "Usage: -I\"string\" -W\"insert\"" << "\n";
	    GXSTD::cerr << "\n";
	    return 0;
	  }
	  num_processed = 0; // Number of string processed for this file
	  GXSTD::cout << "\n";
	  GXSTD::cout << "Opening file: " << open_file << "\n";
	  GXSTD::cout << "Inserting: " << string_to_replace.c_str() << "\n";
	  GXSTD::cout << "After: " << string_to_insert.c_str() << "\n";
	}

	if(find_string) {
	  num_processed = 0; // Number of string processed for this file
	  // Do not echo file status to the console
	}

	// Process the test file
	num_matches = 0; num_replaced = 0; num_processed = 0;
	ProcessTextFile(iofile, GXSTD::cout);
	if(num_files) iofile.df_Close();
	
	// Report the total number of strings replaced/inserted 
	// ----------------------------------------------------------- 
	if(replacing_string) {
	  GXSTD::cout << "Replaced " << num_processed << " occurrence(s)." 
		      << "\n";
	  GXSTD::cout << "\n";
	}

	if(replacing_line) {
	  GXSTD::cout << "Replaced " << num_processed << " occurrence(s)." 
		      << "\n";
	  GXSTD::cout << "\n";
	}

	if(inserting_string ) {
	  GXSTD::cout << "Inserted " << num_processed << " line(s)." << "\n";
	  GXSTD::cout << "\n";
	}

	if(find_string) {
	  if(find_all) {
	    if(num_processed > 0) {
	      GXSTD::cout << "\n";
	      GXSTD::cout << "File name: " << open_file << " String: " 
			  << string_to_find.c_str() << "\n";
	      if(num_processed > 1) 
		GXSTD::cout << "Found " << num_processed << " matches" << "\n";
	      else
		GXSTD::cout << "Found 1 match" << "\n";
	    }
	  }
	  if(num_matches == 0) { // Used by -f command if search fails
	    // Do not echo results to the console
	  }
	}
      }
      arg = argv[++narg];
    }
  }
  
  if(num_files == 0) {
    GXSTD::cerr << "\n";
    GXSTD::cerr << "You must enter a file name." << "\n";
    GXSTD::cerr << "Exiting..." << "\n";
    GXSTD::cerr << "\n";
    return 0;
  }
  
  // Return the total number of strings replaced/inserted 
  // ----------------------------------------------------------- 
  if(replacing_string) return num_replaced;
  if(replacing_line) return num_replaced;
  if(inserting_string ) return num_replaced;
  if(find_string) return num_matches;

  return 0;
}
コード例 #12
0
ファイル: mainWindow.cpp プロジェクト: alcap-org/AlcapDAQ
int main(int argc, char **argv)
{
	int c;
	std::string server_name = "localhost";
	int server_port = 9090;
	std::string root_file_name = "";
	std::string module_file_name = "";

	while ((c = getopt(argc, argv, "hH:p:i:M:")) != -1)
	{
		switch (c)
		{
			case 'h':
				HelpMessage();
				return 0;
			case 'H':
				server_name = optarg;
				break;
			case 'p':
				server_port = atoi(optarg);
				break;
			case 'i':
				root_file_name = optarg;
				break;
			case 'M':
				module_file_name = optarg;
				break;
			default:
				break;
		}
	}

  int fake_argc = 1;
  char fake_arg_str[256];
  sprintf(fake_arg_str,"./online-display");
  char *fake_argv[] = {fake_arg_str};
  
  TApplication theApp("RMidas", &fake_argc, fake_argv);
  
  if (gROOT->IsBatch()) {
    printf("%s: cannot run in batch mode\n", argv[0]);
    return 1;
  }

 std::cout<<module_file_name<<std::endl;
  TOnlineFrame *onlineFrame = new TOnlineFrame(gClient->GetRoot(),module_file_name);   
	
	if (root_file_name.length() != 0)
		onlineFrame->OpenRootFile(root_file_name.c_str());
	else
	{
		onlineFrame->setServerName(server_name.c_str());
		onlineFrame->setServerPort(server_port);
		onlineFrame->ConnectToServer();
		onlineFrame->Print();

#if 0
		// Get list of all histograms, then copy them to the current directory
		std::vector<TString> vHistTitles = onlineFrame->GetHistTitles();
		for (unsigned int i = 0; i < vHistTitles.size(); ++i)
		{
			//printf("%d: %s\n", i, vHistTitles.at(i).Data());
			TH1 *hist = onlineFrame->GetHist(vHistTitles.at(i).Data());
			if(hist)
			{
				//hist->Draw();
				hist->Clone(vHistTitles.at(i).Data());
			}
		}
#endif
	}

	//onlineFrame->runMacro("modules/common/root_init.C");

  /*
    TThread *ct = new TThread(cycleThread, onlineFrame);
    ct->Run();
  */
  
  //theApp.SetIdleTimer(1,".q");

		onlineFrame->UpdateDisplay();
		theApp.Run(1);
#if 0
  time_t lastCycleTime = 0;//time(NULL);
  while(true) 
	{
		theApp.Run(1);
		if(time(NULL) > lastCycleTime + onlineFrame->getAutoUpdateTime()) 
		{
			//printf("Considering cycling\n");
			onlineFrame->ConsiderCycling(); 
			onlineFrame->ConsiderAutoupdate(); 
			lastCycleTime = time(NULL);
		}
		else 
		{
			usleep(10000);
		}
	}
#endif
  
  return 0;
}
コード例 #13
0
ファイル: cmdtab.c プロジェクト: pfg504/hercules-plus
/*-------------------------------------------------------------------*/
int HelpCommand( CMDFUNC_ARGS_PROTO )
{
    static int didinit = 0;
    CMDTAB* pCmdTab;
    int     rc = 1;
    int     pfxlen = -1;
    char   *p = NULL;

    UNREFERENCED( cmdline );

    if (!didinit)
    {
        qsort( cmdtab, _countof( cmdtab ), sizeof( CMDTAB ), SortCmdTab );
        didinit = 1;
    }

    /* Too many arguments? */
    if (argc > 2)
    {
        // "Invalid command usage. Type 'help %s' for assistance."
        WRMSG( HHC02299, "E", "help" );
        return 1;
    }

    /* If "help pfx*", calculate prefix length */
    if (argc == 2)
    {
        p = strchr(argv[1], '*');
        if (p != NULL)
        {
            pfxlen = (int)(p - argv[1]);
            if (strlen( argv[1] ) > (unsigned) (pfxlen + 1))
            {
                // "Invalid command usage. Type 'help %s' for assistance."
                WRMSG( HHC02299, "E", argv[0] );
                return -1;
            }
        }
    }

    /* List all commands or those matching given prefix?  */
    if (argc < 2 || pfxlen >= 0)    /* "help" or "help pfx*" ? */
    {
        int found = FALSE;
        int didlong = FALSE;
        char longflag;

        if (argc < 2)
            pfxlen = 0;

        /* List standard formatted commands from our routing table */
        for (pCmdTab = cmdtab; pCmdTab->statement; pCmdTab++)
        {
            if (  (pCmdTab->type & sysblk.sysgroup)
               && (pCmdTab->shortdesc)
               && (pfxlen == 0 || !strncasecmp( argv[1], pCmdTab->statement, pfxlen ))
               )
            {
                longflag = ' ';
                if (pCmdTab->longdesc)
                {
                    longflag = '*';
                    didlong = TRUE;
                }
                if (!found)
                {
                    found = TRUE;
                    WRMSG( HHC01603, "I", "" );
                    WRMSG( HHC01602, "I", "Command", ' ', "Description" );
                    WRMSG( HHC01602, "I", "-------", ' ', "-----------------------------------------------" );
                }
                WRMSG( HHC01602, "I", pCmdTab->statement, longflag, pCmdTab->shortdesc );
            }
        }

        /* Prefix given but no matches found? */
        if (pfxlen > 0 && !found)
        {
            // "No help available for mask '%s'"
            WRMSG( HHC01609, "E", argv[1] );
            rc = -1;
        }
        else
        {
            WRMSG( HHC01603, "I", "" );
            if (didlong)
            {
                // " (*)  More help available."
                WRMSG( HHC01610, "I" );
                WRMSG( HHC01603, "I", "" );
            }
            rc = 0;
        }
    }
    else /* (argc == 2 && pfxlen < 0) "help cmd": Show help for given command */
    {
        char longflag;
        size_t cmdlen, matchlen;

        for (pCmdTab = cmdtab; pCmdTab->statement; pCmdTab++)
        {
            cmdlen = pCmdTab->mincmdlen ? pCmdTab->mincmdlen : strlen( pCmdTab->statement );
            matchlen = MAX( strlen(argv[1]), cmdlen );

            if (1
                && (pCmdTab->shortdesc)
                && (pCmdTab->type & sysblk.sysgroup)
                && !strncasecmp( argv[1], pCmdTab->statement, matchlen )
            )
            {
                longflag = (pCmdTab->longdesc) ? '*' : ' ';

                WRMSG( HHC01603, "I", "" );
                WRMSG( HHC01602, "I", "Command", ' ', "Description" );
                WRMSG( HHC01602, "I", "-------", ' ', "-------------------------------------------------------" );
                WRMSG( HHC01602, "I", pCmdTab->statement, longflag, pCmdTab->shortdesc);

                if (pCmdTab->longdesc)
                {
                    char buf[257];
                    int i = 0;
                    int j;

                    WRMSG( HHC01603, "I", "" );
                    while(pCmdTab->longdesc[i])
                    {
                        for(j = 0; j < (int)sizeof(buf)      &&
                                   pCmdTab->longdesc[i] &&
                                   pCmdTab->longdesc[i] != '\n'; i++, j++)
                        {
                            buf[j] = pCmdTab->longdesc[i];
                        }

                        buf[j] = '\0';
                        if(pCmdTab->longdesc[i] == '\n')
                            i++;
                        WRMSG( HHC01603, "I", buf );
                    }
                }
                WRMSG( HHC01603, "I", "" );
                rc = 0;
                break;
            }
        }

        /* If command not found, check if message help (e.g. "help HHCnnnnn[s]") */
        if (rc == 1)  /* (not found?) */
        {
            /* "help HHCnnnnn" or "help HHCnnnnns" */
            if (strncasecmp( argv[1], "HHC", 3 ) == 0
                && (strlen( argv[1] ) == 8 ||
                    strlen( argv[1] ) == 9))
            {
                rc = HelpMessage( argv[1] );
            }
            else
            {
                // "Unknown herc command '%s', no help available"
                WRMSG( HHC01604, "I", argv[1] );
                rc = -1;
            }
        }
    }
    return rc;
}
コード例 #14
0
ファイル: utilitydialog.cpp プロジェクト: terracoin/terracoin
/** "Help message" or "About" dialog box */
HelpMessageDialog::HelpMessageDialog(QWidget *parent, HelpMode helpMode) :
    QDialog(parent),
    ui(new Ui::HelpMessageDialog)
{
    ui->setupUi(this);

    QString version = tr("Terracoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
    /* On x86 add a bit specifier to the version so that users can distinguish between
     * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
     */
#if defined(__x86_64__)
    version += " " + tr("(%1-bit)").arg(64);
#elif defined(__i386__ )
    version += " " + tr("(%1-bit)").arg(32);
#endif

    if (helpMode == about)
    {
        setWindowTitle(tr("About Terracoin Core"));

        /// HTML-format the license message from the core
        QString licenseInfo = QString::fromStdString(LicenseInfo());
        QString licenseInfoHTML = licenseInfo;

        // Make URLs clickable
        QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
        uri.setMinimal(true); // use non-greedy matching
        licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
        // Replace newlines with HTML breaks
        licenseInfoHTML.replace("\n\n", "<br><br>");

        ui->aboutMessage->setTextFormat(Qt::RichText);
        ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        text = version + "\n" + licenseInfo;
        ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
        ui->aboutMessage->setWordWrap(true);
        ui->helpMessage->setVisible(false);
    } else if (helpMode == cmdline) {
        setWindowTitle(tr("Command-line options"));
        QString header = tr("Usage:") + "\n" +
            "  terracoin-qt [" + tr("command-line options") + "]                     " + "\n";
        QTextCursor cursor(ui->helpMessage->document());
        cursor.insertText(version);
        cursor.insertBlock();
        cursor.insertText(header);
        cursor.insertBlock();

        std::string strUsage = HelpMessage(HMM_BITCOIN_QT);
        const bool showDebug = GetBoolArg("-help-debug", false);
        strUsage += HelpMessageGroup(tr("UI Options:").toStdString());
        if (showDebug) {
            strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS));
        }
        strUsage += HelpMessageOpt("-choosedatadir", strprintf(tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR));
        strUsage += HelpMessageOpt("-lang=<lang>", tr("Set language, for example \"de_DE\" (default: system locale)").toStdString());
        strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString());
        strUsage += HelpMessageOpt("-rootcertificates=<file>", tr("Set SSL root certificates for payment request (default: -system-)").toStdString());
        strUsage += HelpMessageOpt("-splash", strprintf(tr("Show splash screen on startup (default: %u)").toStdString(), DEFAULT_SPLASHSCREEN));
        strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changed in the GUI").toStdString());
        if (showDebug) {
            strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM));
        }
        QString coreOptions = QString::fromStdString(strUsage);
        text = version + "\n" + header + "\n" + coreOptions;

        QTextTableFormat tf;
        tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
        tf.setCellPadding(2);
        QVector<QTextLength> widths;
        widths << QTextLength(QTextLength::PercentageLength, 35);
        widths << QTextLength(QTextLength::PercentageLength, 65);
        tf.setColumnWidthConstraints(widths);

        QTextCharFormat bold;
        bold.setFontWeight(QFont::Bold);

        Q_FOREACH (const QString &line, coreOptions.split("\n")) {
            if (line.startsWith("  -"))
            {
                cursor.currentTable()->appendRows(1);
                cursor.movePosition(QTextCursor::PreviousCell);
                cursor.movePosition(QTextCursor::NextRow);
                cursor.insertText(line.trimmed());
                cursor.movePosition(QTextCursor::NextCell);
            } else if (line.startsWith("   ")) {
                cursor.insertText(line.trimmed()+' ');
            } else if (line.size() > 0) {
                //Title of a group
                if (cursor.currentTable())
                    cursor.currentTable()->appendRows(1);
                cursor.movePosition(QTextCursor::Down);
                cursor.insertText(line.trimmed(), bold);
                cursor.insertTable(1, 2, tf);
            }
        }

        ui->helpMessage->moveCursor(QTextCursor::Start);
        ui->scrollArea->setVisible(false);
        ui->aboutLogo->setVisible(false);
    } else if (helpMode == pshelp) {
コード例 #15
0
ファイル: sharkfundd.cpp プロジェクト: sharkfund001/sharkfund
//////////////////////////////////////////////////////////////////////////////
//
// Start
//
bool AppInit(int argc, char* argv[],boost::thread_group &threadGroup) {
//	boost::thread* detectShutdownThread = NULL;

	bool fRet = false;
	try {
		//
		// Parameters
		//
		// If Qt is used, parameters/sharkfund.conf are parsed in qt/Sharkfund.cpp's main()
		CBaseParams::IntialParams(argc, argv);
		SysCfg().InitalConfig();

		if (SysCfg().IsArgCount("-?") || SysCfg().IsArgCount("--help")) {
			// First part of help message is specific to Dacrsd / RPC client
			std::string strUsage = _("Sharkfund Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n\n"
					+ _("Usage:") + "\n" + "  Dacrsd [options]                     " + _("Start Sharkfund Core Daemon")
					+ "\n" + _("Usage (deprecated, use Sharkfund-cli):") + "\n"
					+ "  sharkfund [options] <command> [params]  " + _("Send command to Sharkfund Core") + "\n"
					+ "  sharkfund [options] help                " + _("List commands") + "\n"
					+ "  sharkfund [options] help <command>      " + _("Get help for a command") + "\n";

			strUsage += "\n" + HelpMessage(HMM_BITCOIND);
			strUsage += "\n" + HelpMessageCli(false);

			fprintf(stdout, "%s", strUsage.c_str());
			return false;
		}

		// Command-line RPC
		bool fCommandLine = false;
		for (int i = 1; i < argc; i++)
			if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "Sharkfund:"))
				fCommandLine = true;

		if (fCommandLine) {
			int ret = CommandLineRPC(argc, argv);
			exit(ret);
		}
#ifndef WIN32
		fDaemon = SysCfg().GetBoolArg("-daemon", false);
		if (fDaemon)
		{
			fprintf(stdout, "Sharkfund server starting\n");

			// Daemonize
			pid_t pid = fork();
			if (pid < 0)
			{
				fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
				return false;
			}
			if (pid > 0) // Parent process, pid is child process id
			{
				CreatePidFile(GetPidFile(), pid);
				return true;
			}
			// Child process falls through to rest of initialization

			pid_t sid = setsid();
			if (sid < 0)
			fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
		}
#endif
		SysCfg().SoftSetBoolArg("-server", true);


		fRet = AppInit2(threadGroup);
	} catch (std::exception& e) {
		PrintExceptionContinue(&e, "AppInit()");
	} catch (...) {
		PrintExceptionContinue(NULL, "AppInit()");
	}



	return fRet;
}
コード例 #16
0
ファイル: bitcoind.cpp プロジェクト: 13971643458/qtum
//////////////////////////////////////////////////////////////////////////////
//
// Start
//
bool AppInit(int argc, char* argv[])
{
    boost::thread_group threadGroup;
    CScheduler scheduler;

    bool fRet = false;

    //
    // Parameters
    //
    // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
    ParseParameters(argc, argv);

    // Process help and version before taking care about datadir
    if (IsArgSet("-?") || IsArgSet("-h") ||  IsArgSet("-help") || IsArgSet("-version"))
    {
        std::string strUsage = strprintf(_("%s Daemon"), _(PACKAGE_NAME)) + " " + _("version") + " " + FormatFullVersion() + "\n";

        if (IsArgSet("-version"))
        {
            strUsage += FormatParagraph(LicenseInfo());
        }
        else
        {
            strUsage += "\n" + _("Usage:") + "\n" +
                  "  qtumd [options]                     " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n";

            strUsage += "\n" + HelpMessage(HMM_BITCOIND);
        }

        fprintf(stdout, "%s", strUsage.c_str());
        return true;
    }

    try
    {
        if (!boost::filesystem::is_directory(GetDataDir(false)))
        {
            fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", GetArg("-datadir", "").c_str());
            return false;
        }
        try
        {
            ReadConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME));
        } catch (const std::exception& e) {
            fprintf(stderr,"Error reading configuration file: %s\n", e.what());
            return false;
        }
        // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
        try {
            SelectParams(ChainNameFromCommandLine());
        } catch (const std::exception& e) {
            fprintf(stderr, "Error: %s\n", e.what());
            return false;
        }

        // Command-line RPC
        bool fCommandLine = false;
        for (int i = 1; i < argc; i++)
            if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "qtum:"))
                fCommandLine = true;

        if (fCommandLine)
        {
            fprintf(stderr, "Error: There is no RPC client functionality in qtumd anymore. Use the qtum-cli utility instead.\n");
            exit(EXIT_FAILURE);
        }
        // -server defaults to true for bitcoind but not for the GUI so do this here
        SoftSetBoolArg("-server", true);
        // Set this early so that parameter interactions go to console
        InitLogging();
        InitParameterInteraction();
        if (!AppInitBasicSetup())
        {
            // InitError will have been called with detailed error, which ends up on console
            exit(1);
        }
        if (!AppInitParameterInteraction())
        {
            // InitError will have been called with detailed error, which ends up on console
            exit(1);
        }
        if (!AppInitSanityChecks())
        {
            // InitError will have been called with detailed error, which ends up on console
            exit(1);
        }
        if (GetBoolArg("-daemon", false))
        {
#if HAVE_DECL_DAEMON
            fprintf(stdout, "Qtum server starting\n");

            // Daemonize
            if (daemon(1, 0)) { // don't chdir (1), do close FDs (0)
                fprintf(stderr, "Error: daemon() failed: %s\n", strerror(errno));
                return false;
            }
#else
            fprintf(stderr, "Error: -daemon is not supported on this operating system\n");
            return false;
#endif // HAVE_DECL_DAEMON
        }

        fRet = AppInitMain(threadGroup, scheduler);
    }
    catch (const std::exception& e) {
        PrintExceptionContinue(&e, "AppInit()");
    } catch (...) {
        PrintExceptionContinue(NULL, "AppInit()");
    }

    if (!fRet)
    {
        Interrupt(threadGroup);
        // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
        // the startup-failure cases to make sure they don't result in a hang due to some
        // thread-blocking-waiting-for-another-thread-during-startup case
    } else {
        WaitForShutdown(&threadGroup);
    }
    Shutdown();

    return fRet;
}
コード例 #17
0
ファイル: utilitydialog.cpp プロジェクト: ethought/Unobtanium
/** "Help message" or "About" dialog box */
HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
    QDialog(parent),
    ui(new Ui::HelpMessageDialog)
{
    ui->setupUi(this);
    GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this);

    QString version = tr("Unobtanium Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
    /* On x86 add a bit specifier to the version so that users can distinguish between
     * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
     */
#if defined(__x86_64__)
    version += " " + tr("(%1-bit)").arg(64);
#elif defined(__i386__ )
    version += " " + tr("(%1-bit)").arg(32);
#endif

    if (about)
    {
        setWindowTitle(tr("About Unobtanium Core"));

        /// HTML-format the license message from the core
        QString licenseInfo = QString::fromStdString(LicenseInfo());
        QString licenseInfoHTML = licenseInfo;
        // Make URLs clickable
        QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
        uri.setMinimal(true); // use non-greedy matching
        licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
        // Replace newlines with HTML breaks
        licenseInfoHTML.replace("\n\n", "<br><br>");

        ui->aboutMessage->setTextFormat(Qt::RichText);
        ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        text = version + "\n" + licenseInfo;
        ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
        ui->aboutMessage->setWordWrap(true);
        ui->helpMessage->setVisible(false);
    } else {
        setWindowTitle(tr("Command-line options"));
        QTextCursor cursor(ui->helpMessage->document());
        cursor.insertText(version);
        cursor.insertBlock();
        cursor.insertText(tr("Usage:") + '\n' +
            "  bitcoin-qt [" + tr("command-line options") + "]\n");

        cursor.insertBlock();
        QTextTableFormat tf;
        tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
        tf.setCellPadding(2);
        QVector<QTextLength> widths;
        widths << QTextLength(QTextLength::PercentageLength, 35);
        widths << QTextLength(QTextLength::PercentageLength, 65);
        tf.setColumnWidthConstraints(widths);
        QTextTable *table = cursor.insertTable(2, 2, tf);

        QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT));
        bool first = true;
        QTextCharFormat bold;
        bold.setFontWeight(QFont::Bold);
        // note that coreOptions is not translated.
        foreach (const QString &line, coreOptions.split('\n')) {
            if (!first) {
                table->appendRows(1);
                cursor.movePosition(QTextCursor::NextRow);
            }
            first = false;

            if (line.startsWith("  ")) {
                int index = line.indexOf(' ', 3);
                if (index > 0) {
                    cursor.insertText(line.left(index).trimmed());
                    cursor.movePosition(QTextCursor::NextCell);
                    cursor.insertText(line.mid(index).trimmed());
                    continue;
                }
            }
            cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor);
            table->mergeCells(cursor);
            cursor.insertText(line.trimmed(), bold);
        }

        table->appendRows(6);
        cursor.movePosition(QTextCursor::NextRow);
        cursor.insertText(tr("UI options") + ":", bold);
        cursor.movePosition(QTextCursor::NextRow);
        if (GetBoolArg("-help-debug", false)) {
            cursor.insertText("-allowselfsignedrootcertificates");
            cursor.movePosition(QTextCursor::NextCell);
            cursor.insertText(tr("Allow self signed root certificates (default: 0)"));
            cursor.movePosition(QTextCursor::NextCell);
        }
        cursor.insertText("-choosedatadir");
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText(tr("Choose data directory on startup (default: 0)"));
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText("-lang=<lang>");
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText(tr("Set language, for example \"de_DE\" (default: system locale)"));
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText("-min");
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText(tr("Start minimized"));
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText("-rootcertificates=<file>");
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText(tr("Set SSL root certificates for payment request (default: -system-)"));
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText("-splash");
        cursor.movePosition(QTextCursor::NextCell);
        cursor.insertText(tr("Show splash screen on startup (default: 1)"));

        ui->helpMessage->moveCursor(QTextCursor::Start);
        ui->scrollArea->setVisible(false);
        ui->aboutLogo->setVisible(false);
    }
}
コード例 #18
0
ファイル: darksilkd.cpp プロジェクト: kevinjulio/fantom
//////////////////////////////////////////////////////////////////////////////
//
// Start
//
bool AppInit(int argc, char* argv[])
{
    boost::thread_group threadGroup;
    boost::thread* detectShutdownThread = NULL;

    bool fRet = false;
    try
    {
        //
        // Parameters
        //
        // If Qt is used, parameters/darksilk.conf are parsed in qt/darksilk.cpp's main()
        ParseParameters(argc, argv);
        if (!boost::filesystem::is_directory(GetDataDir(false)))
        {
            fprintf(stderr, "Error: Specified directory does not exist\n");
            Shutdown();
        }
        ReadConfigFile(mapArgs, mapMultiArgs);

        if (mapArgs.count("-?") || mapArgs.count("--help"))
        {
            // First part of help message is specific to darksilkd / RPC client
            std::string strUsage = _("DarkSilk version") + " " + FormatFullVersion() + "\n\n" +
                _("Usage:") + "\n" +
                  "  darksilkd [options]                     " + "\n" +
                  "  darksilkd [options] <command> [params]  " + _("Send command to -server or darksilkd") + "\n" +
                  "  darksilkd [options] help                " + _("List commands") + "\n" +
                  "  darksilkd [options] help <command>      " + _("Get help for a command") + "\n";

            strUsage += "\n" + HelpMessage();

            fprintf(stdout, "%s", strUsage.c_str());
            return false;
        }

        // Command-line RPC
        for (int i = 1; i < argc; i++)
            if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "darksilk:"))
                fCommandLine = true;

        if (fCommandLine)
        {
            if (!SelectParamsFromCommandLine()) {
                fprintf(stderr, "Error: invalid use of -testnet.\n");
                return false;
            }
            int ret = CommandLineRPC(argc, argv);
            exit(ret);
        }
#if !WIN32
        fDaemon = GetBoolArg("-daemon", false);
        if (fDaemon)
        {
            fprintf(stdout, "DarkSilk server starting\n");

            // Daemonize
            pid_t pid = fork();
            if (pid < 0)
            {
                fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
                return false;
            }
            if (pid > 0) // Parent process, pid is child process id
            {
                CreatePidFile(GetPidFile(), pid);
                return true;
            }
            // Child process falls through to rest of initialization

            pid_t sid = setsid();
            if (sid < 0)
                fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
        }
#endif
        SoftSetBoolArg("-server", true);

        detectShutdownThread = new boost::thread(boost::bind(&DetectShutdownThread, &threadGroup));
        fRet = AppInit2(threadGroup);
    }
    catch (std::exception& e) {
        PrintException(&e, "AppInit()");
    } catch (...) {
        PrintException(NULL, "AppInit()");
    }

    if (!fRet)
    {
        if (detectShutdownThread)
            detectShutdownThread->interrupt();

        threadGroup.interrupt_all();
        // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
        // the startup-failure cases to make sure they don't result in a hang due to some
        // thread-blocking-waiting-for-another-thread-during-startup case
    }

    if (detectShutdownThread)
    {
        detectShutdownThread->join();
        delete detectShutdownThread;
        detectShutdownThread = NULL;
    }
    Shutdown();

    return fRet;
}
コード例 #19
0
ファイル: bitcoind.cpp プロジェクト: TinyUlt/bitcoin
//////////////////////////////////////////////////////////////////////////////
//
// Start
//
bool AppInit(int argc, char* argv[])
{
    boost::thread_group threadGroup;
    CScheduler scheduler;

    bool fRet = false;

    //
    // Parameters
    //
    // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
    gArgs.ParseParameters(argc, argv);

    // Process help and version before taking care about datadir
    if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") ||  gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version"))
    {
        std::string strUsage = strprintf(_("%s Daemon"), _(PACKAGE_NAME)) + " " + _("version") + " " + FormatFullVersion() + "\n";

        if (gArgs.IsArgSet("-version"))
        {
            strUsage += FormatParagraph(LicenseInfo());
        }
        else
        {
            strUsage += "\n" + _("Usage:") + "\n" +
                  "  bitcoind [options]                     " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n";

            strUsage += "\n" + HelpMessage(HMM_BITCOIND);
        }

        fprintf(stdout, "%s", strUsage.c_str());
        return true;
    }

    try
    {
        if (!fs::is_directory(GetDataDir(false)))
        {
            fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str());
            return false;
        }
        try
        {
            gArgs.ReadConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME));
        } catch (const std::exception& e) {
            fprintf(stderr,"Error reading configuration file: %s\n", e.what());
            return false;
        }
        // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
        try {
            SelectParams(ChainNameFromCommandLine());
        } catch (const std::exception& e) {
            fprintf(stderr, "Error: %s\n", e.what());
            return false;
        }

        // Error out when loose non-argument tokens are encountered on command line
        for (int i = 1; i < argc; i++) {
            if (!IsSwitchChar(argv[i][0])) {
                fprintf(stderr, "Error: Command line contains unexpected token '%s', see bitcoind -h for a list of options.\n", argv[i]);
                return false;
            }
        }

        // -server defaults to true for bitcoind but not for the GUI so do this here
        gArgs.SoftSetBoolArg("-server", true);
        // Set this early so that parameter interactions go to console
        InitLogging();
        InitParameterInteraction();
        if (!AppInitBasicSetup())
        {
            // InitError will have been called with detailed error, which ends up on console
            return false;
        }
        if (!AppInitParameterInteraction())
        {
            // InitError will have been called with detailed error, which ends up on console
            return false;
        }
        if (!AppInitSanityChecks())
        {
            // InitError will have been called with detailed error, which ends up on console
            return false;
        }
        if (gArgs.GetBoolArg("-daemon", false))
        {
#if HAVE_DECL_DAEMON
            fprintf(stdout, "Bitcoin server starting\n");

            // Daemonize
            if (daemon(1, 0)) { // don't chdir (1), do close FDs (0)
                fprintf(stderr, "Error: daemon() failed: %s\n", strerror(errno));
                return false;
            }
#else
            fprintf(stderr, "Error: -daemon is not supported on this operating system\n");
            return false;
#endif // HAVE_DECL_DAEMON
        }
        // Lock data directory after daemonization
        if (!AppInitLockDataDirectory())
        {
            // If locking the data directory failed, exit immediately
            return false;
        }
        fRet = AppInitMain(threadGroup, scheduler);
    }
    catch (const std::exception& e) {
        PrintExceptionContinue(&e, "AppInit()");
    } catch (...) {
        PrintExceptionContinue(nullptr, "AppInit()");
    }

    if (!fRet)
    {
        Interrupt(threadGroup);
        threadGroup.join_all();
    } else {
        WaitForShutdown(&threadGroup);
    }
    Shutdown();

    return fRet;
}