Ejemplo n.º 1
0
void ReadParameters(int *xlength, float *tau, float *velocity_wall, int *timesteps,
		int *timesteps_per_plotting, int argc, char *argv[], int *gpu_enabled, int *gpu_streaming,
        int *gpu_collision, int *gpu_boundaries){
    float *velocity_wall_1, *velocity_wall_2, *velocity_wall_3;
    
    if(argc<3) PrintHelpMessage();
    if(!strcmp(argv[1], "-help") || !strcmp(argv[2], "-help")) PrintHelpMessage();
    if(access(argv[1], R_OK) != 0)
        ERROR("Provided configuration file path either doesn't exist or can not be read.");
    
    if(!strcmp(argv[2], "-gpu")) *gpu_enabled=1; else *gpu_enabled=0;
    if(!strcmp(argv[2], "-gpu-streaming")) *gpu_streaming=1; else *gpu_streaming=0;
    if(!strcmp(argv[2], "-gpu-collision")) *gpu_collision=1; else *gpu_collision=0;
    if(!strcmp(argv[2], "-gpu-boundaries")) *gpu_boundaries=1; else *gpu_boundaries=0;

    READ_FLOAT(argv[1], *tau);

    velocity_wall_1=&velocity_wall[0];
    velocity_wall_2=&velocity_wall[1];
    velocity_wall_3=&velocity_wall[2];

    READ_FLOAT(argv[1], *velocity_wall_1);
    READ_FLOAT(argv[1], *velocity_wall_2);
    READ_FLOAT(argv[1], *velocity_wall_3);
    
    READ_INT(argv[1], *xlength);
    READ_INT(argv[1], *timesteps);
    READ_INT(argv[1], *timesteps_per_plotting);
}
Ejemplo n.º 2
0
/*
 * Program entry point.
 */
void main( int argc, char *argv[] )
/*********************************/
{
    OPT_STORAGE         cmdOpts;
    CmdLine *           cmdLine;
    int                 itemsParsed;

#ifndef __WATCOMC__
    _argc = argc;
    _argv = argv;
#endif
    /*** Initialize ***/
    SetBannerFuncError( BannerMessage );
    cmdLine = InitCmdLine( LINK_NUM_SECTIONS );
    SetDefaultFile( TYPE_OBJ_FILE, "object" );
    AllowTypeFile( TYPE_OBJ_FILE, TYPE_LIB_FILE, TYPE_RES_FILE,
                   TYPE_RBJ_FILE, TYPE_RS_FILE, TYPE_EXP_FILE,
                   TYPE_INVALID_FILE );

    /*** Parse the command line and translate to Watcom options ***/
    InitParse( &cmdOpts );
    itemsParsed = do_parsing( &cmdOpts );
    if( itemsParsed == 0 ) {
        PrintHelpMessage();
        exit( EXIT_SUCCESS );
    }
    OptionsTranslate( &cmdOpts, cmdLine );

    /*** Spawn the linker ***/
    if( link( &cmdOpts, cmdLine )  ==  LINK_NOACTION ) {
        FatalError( "Nothing to do!" );
    }
    FiniParse( &cmdOpts );
    exit( EXIT_SUCCESS );
}
Ejemplo n.º 3
0
/*
 * Program entry point.
 */
void main( int argc, char *argv[] )
/*********************************/
{
    OPT_STORAGE         cmdOpts;
    CmdLine *           compCmdLine;
    CmdLine *           linkCmdLine;
    int                 itemsParsed;
    int                 compRc = COMPILE_NOACTION;
    int                 linkRc = LINK_NOACTION;

#ifndef __WATCOMC__
    _argc = argc;
    _argv = argv;
#endif
    /*** Initialize ***/
    SetBannerFuncError( BannerMessage );
    compCmdLine = InitCmdLine( CL_C_NUM_SECTIONS );
    linkCmdLine = InitCmdLine( CL_L_NUM_SECTIONS );
    SetDefaultFile( TYPE_C_FILE, "source" );
    AllowTypeFile( TYPE_C_FILE, TYPE_CPP_FILE, TYPE_DEF_FILE, TYPE_OBJ_FILE,
                   TYPE_LIB_FILE, TYPE_RES_FILE, TYPE_INVALID_FILE );
    InitMacro();

    /*** Parse the command line and translate to Watcom options ***/
    InitParse( &cmdOpts );
    itemsParsed = do_parsing( &cmdOpts );
    if( itemsParsed==0 || cmdOpts.help ) {
        if( !cmdOpts.nologo )
            BannerMessage();
        PrintHelpMessage();
        exit( EXIT_SUCCESS );
    }
    OptionsTranslate( &cmdOpts, compCmdLine, linkCmdLine );

    /*** Spawn the compiler ***/
    compRc = compile( &cmdOpts, compCmdLine );
    if( compRc == COMPILE_ERROR )  exit( EXIT_FAILURE );
    if( !cmdOpts.c ) {
        linkRc = link( &cmdOpts, linkCmdLine );
    }
    if( compRc == COMPILE_NOACTION  &&  linkRc == LINK_NOACTION ) {
        FatalError( "Nothing to do!" );
    }
    FiniParse( &cmdOpts );
    exit( EXIT_SUCCESS );
}
Ejemplo n.º 4
0
/*
 * Program entry point.
 */
void main( int argc, char *argv[] )
/*********************************/
{
    OPT_STORAGE         cmdOpts;
    int                 itemsParsed;
    int                 rc = CVTRES_NOACTION;

#ifndef __WATCOMC__
    _argc = argc;
    _argv = argv;
#endif
    /*** Initialize ***/
    SetBannerFuncError( BannerMessage );
    SetDefaultFile( TYPE_RES_FILE, "res" );
    AllowTypeFile( TYPE_RES_FILE, TYPE_INVALID_FILE );

    /*** Parse the command line ***/
    InitParse( &cmdOpts );
    itemsParsed = do_parsing( &cmdOpts );
    if( itemsParsed==0 || cmdOpts.help ) {
        PrintHelpMessage();
        exit( EXIT_SUCCESS );
    }

    /*** Do the conversion ***/
    rc = res_convert( &cmdOpts );
    switch( rc ) {
      case CVTRES_ERROR:
        exit( EXIT_FAILURE );
        break;
      case CVTRES_NOACTION:
        FatalError( "Nothing to do!" );
        break;
      case CVTRES_SUCCESS:
        FiniParse( &cmdOpts );
        exit( EXIT_SUCCESS );
        break;
      default:
        Zoinks();
    }
}
Ejemplo n.º 5
0
/*
 * Program entry point.
 */
void main( int argc, char *argv[] )
/*********************************/
{
    OPT_STORAGE         cmdOpts;
    CmdLine *           cmdLine;
    int                 itemsParsed;
    int                 rc = RC_NOACTION;

    /*** Initialize ***/
    SetBannerFuncError( BannerMessage );
    cmdLine = InitCmdLine( RC_NUM_SECTIONS );
    SetDefaultFile( TYPE_RC_FILE, "rc" );
    AllowTypeFile( TYPE_RC_FILE, TYPE_INVALID_FILE );

    /*** Parse the command line and translate to Watcom options ***/
    InitParse( &cmdOpts );
    itemsParsed = do_parsing( &cmdOpts );
    if( itemsParsed==0 || cmdOpts.help ) {
        PrintHelpMessage();
        exit( EXIT_SUCCESS );
    }
    OptionsTranslate( &cmdOpts, cmdLine );

    /*** Spawn the compiler ***/
    rc = res_compile( &cmdOpts, cmdLine );
    switch( rc ) {
      case RC_ERROR:
        exit( EXIT_FAILURE );
        break;
      case RC_NOACTION:
        FatalError( "Nothing to do!" );
        break;
      case RC_SUCCESS:
        FiniParse( &cmdOpts );
        exit( EXIT_SUCCESS );
        break;
      default:
        Zoinks();
    }
}
Ejemplo n.º 6
0
// Functions achievement
int ParseCmdlineParameters(int arg, char *argv[]) {

    if (arg < 2) {
        printf("\nError: Invalid parameters!\n\n");
        PrintHelpMessage();
        return -1;
    }
    
    memset(&cmdline_params, 0x00, sizeof(CmdLineParams_t));
    
    for (uint8_t i = 1; i < arg; i++) {
        if ( !strcmp(argv[i], "--upload") ) {     // --upload
            if (cmdline_option == OPTION_NOT_SPECIFIED) cmdline_option = OPTION_UPLOAD_FIRMWARE;
        }
        else if ( !strcmp(argv[i], "--version") ) {    // --version
            if(cmdline_option == OPTION_NOT_SPECIFIED) cmdline_option = OPTION_FETCH_VERSIONS;
        }
        else if ( !strcmp(argv[i], "--device-id") ) {    // --device-id
            if (cmdline_option == OPTION_NOT_SPECIFIED) cmdline_option = OPTION_FETCH_DEV_ID;
        }
        else if (!strcmp(argv[i], "--credential")) {    // --credential
            if (cmdline_option == OPTION_NOT_SPECIFIED) cmdline_option = OPTION_CHECK_CREDENTIAL;
        }
        else if (!strcmp(argv[i], "--scan-ap")) {    // --scan-ap
            if (cmdline_option == OPTION_NOT_SPECIFIED) cmdline_option = OPTION_SCAN_AP;
        }
        else if(!strcmp(argv[i], "--config-ap")) {    // --config-ap
            if(cmdline_option == OPTION_NOT_SPECIFIED) cmdline_option = OPTION_CONFIG_AP;
        }
        else if (!strcmp(argv[i], "--connect-ap")) {    // --connect-ap
            if (cmdline_option == OPTION_NOT_SPECIFIED) cmdline_option = OPTION_CONNECT_AP;
        }
        else if(!strcmp(argv[i], "--public-key")) {    // --public-key
            if(cmdline_option == OPTION_NOT_SPECIFIED) cmdline_option = OPTION_PUBLIC_KEY;
        }
        else if ( (!strcmp(argv[i], "--verbose")) || (!strcmp(argv[i], "-v")) ) {    // --verbose
            cmdline_params.verbose = 1;
        }
        else if ( (!strcmp(argv[i], "--file")) || (!strcmp(argv[i], "-f")) ) {    // --file
            i++;
            if (i < arg) {
                if (cmdline_params.file_num >= MAX_OTA_FILE_NUM) {
                    printf("\nERROR: Too many file to be uploaded while the OTA region\n");
                    printf("       is only capable of storing %d images simultaneously!\n\n", cmdline_params.file_num);
                    return -1;
                }
                char form[5] = ".bin";
                char format[5] = "    ";
                int fLen = strlen(argv[i]);
                if (fLen < 5) {
                    printf("\nERROR: The selcted file \"%s\" is invalid!\n\n", argv[i]);
                    return -1;  
                }
                format[3] = argv[i][fLen-1];
                format[2] = argv[i][fLen-2];
                format[1] = argv[i][fLen-3];
                format[0] = argv[i][fLen-4];
                if (0 != strcmp(form, format)) {
                    printf("\nERROR: Selected file \"%s\" format must be .bin!\n\n", argv[i]);
                    return -1;
                }
                
                cmdline_params.file_name[cmdline_params.file_num] = argv[i];
                cmdline_params.file_num++;
            }
            else {
                printf("\nERROR: File is not specified by parameter \"--file\"!\n\n");
                PrintHelpMessage();
                return -1;
            }
        }
        else if ( !strcmp(argv[i], "-fac") ) {    // -fac
            i++;
            if (i < arg) {
                char form[5] = ".bin";
                char format[5] = "    ";
                int fLen = strlen(argv[i]);
                if (fLen < 5) {
                    printf("\nERROR: The selcted file \"%s\" is invalid!\n\n", argv[i]);
                    return -1;  
                }
                format[3] = argv[i][fLen-1];
                format[2] = argv[i][fLen-2];
                format[1] = argv[i][fLen-3];
                format[0] = argv[i][fLen-4];    
                if (0 != strcmp(form, format)) {
                    printf("\nERROR: Selected file \"%s\" format must be .bin!\n\n", argv[i]);
                    return -1;
                }
                
                cmdline_params.fac_set = 1;
                cmdline_params.fac_name = argv[i];
            }
            else {
                printf("\nERROR: File is not specified by parameter \"-fac\"!\n\n");
                PrintHelpMessage();
                return -1;
            }
        }
        else if ( (!strcmp(argv[i], "--safe")) || (!strcmp(argv[i], "-s")) ) {    // --safe
            cmdline_params.safe = 1;
        }
        else if ( (!strcmp(argv[i], "--leave")) || (!strcmp(argv[i], "-l")) ) {    // --leave
            cmdline_params.leave = 1;
        }
        else {
            printf("\nERROR: Unknown option or parameter \"%s\" .\n", argv[i]);
            PrintHelpMessage();
            return -1;
        }
    }
    
    return 0;
}
Ejemplo n.º 7
0
// NOTE: arg_i is used here to avoid ugly *i so many times in this function
void ParseArgs(const int argc, char** argv,
                  const char** lang,
                  const char** image,
                  const char** outputbase,
                  const char** datapath,
                  bool* list_langs,
                  bool* print_parameters,
                  GenericVector<STRING>* vars_vec,
                  GenericVector<STRING>* vars_values,
                  int* arg_i,
                  tesseract::PageSegMode* pagesegmode) {
  if (argc == 1) {
    PrintHelpMessage(argv[0]);
    exit(0);
  }

  if (argc == 2) {
    if ((strcmp(argv[1], "-h") == 0) ||
         (strcmp(argv[1], "--help") == 0)) {
      PrintHelpMessage(argv[0]);
      exit(0);
    }
    if ((strcmp(argv[1], "--help-psm") == 0)) {
      PrintHelpForPSM();
      exit(0);
    }
    if ((strcmp(argv[1], "-v") == 0) ||
         (strcmp(argv[1], "--version") == 0)) {
      PrintVersionInfo();
      exit(0);
    }
  }

  bool noocr = false;
  int i = 1;
  while (i < argc && (*outputbase == NULL || argv[i][0] == '-')) {
    if (strcmp(argv[i], "-l") == 0 && i + 1 < argc) {
      *lang = argv[i + 1];
      ++i;
    } else if (strcmp(argv[i], "--tessdata-dir") == 0 && i + 1 < argc) {
      *datapath = argv[i + 1];
      ++i;
    } else if (strcmp(argv[i], "--user-words") == 0 && i + 1 < argc) {
      vars_vec->push_back("user_words_file");
      vars_values->push_back(argv[i + 1]);
      ++i;
    } else if (strcmp(argv[i], "--user-patterns") == 0 && i + 1 < argc) {
      vars_vec->push_back("user_patterns_file");
      vars_values->push_back(argv[i + 1]);
      ++i;
    } else if (strcmp(argv[i], "--list-langs") == 0) {
      noocr = true;
      *list_langs = true;
    } else if (strcmp(argv[i], "-psm") == 0 && i + 1 < argc) {
      *pagesegmode = static_cast<tesseract::PageSegMode>(atoi(argv[i + 1]));
      ++i;
    } else if (strcmp(argv[i], "--print-parameters") == 0) {
      noocr = true;
      *print_parameters = true;
    } else if (strcmp(argv[i], "-c") == 0 && i + 1 < argc) {
      // handled properly after api init
      ++i;
    } else if (*image == NULL) {
      *image = argv[i];
    } else if (*outputbase == NULL) {
      *outputbase = argv[i];
    }
    ++i;
  }

  *arg_i = i;

  if (argc == 2 && strcmp(argv[1], "--list-langs") == 0) {
    *list_langs = true;
    noocr = true;
  }

  if (*outputbase == NULL && noocr == false) {
    PrintHelpMessage(argv[0]);
    exit(1);
  }
}
Ejemplo n.º 8
0
/** @brief Parse command line arguments */
int ParseParams(programparams *Params, int argc, const char *argv[])
{
    static const char *DefaultOutputFile = (char *)"out.bmp";
    const char *Param, *Value;
    num NumValue;
    char TokenBuf[256];
    int k, kread, Skip;
    
        
    /* Set parameter defaults */
    Params->InputFile = NULL;
    Params->OutputFile = DefaultOutputFile;
    Params->JpegQuality = 85;
    
    Params->Lambda = 20;    
    Params->Kernel = NullImage;
    Params->Noise = "gaussian";
        
    if(argc < 2)
    {
        PrintHelpMessage();
        return 0;
    }    
    
    k = 1;
    
    while(k < argc)
    {
        Skip = (argv[k][0] == '-') ? 1 : 0;        
        kread = CliParseArglist(&Param, &Value, TokenBuf, sizeof(TokenBuf),
            k, &argv[k][Skip], argc, argv, ":");        
       
        if(!Param)
        {
            if(!Params->InputFile)
                Param = (char *)"f";
            else
                Param = (char *)"u";
        }
        
        if(Param[0] == '-')     /* Argument begins with two dashes "--" */
        {
            PrintHelpMessage();
            return 0;
        }

        if(!strcmp(Param, "f") || !strcmp(Param, "input"))
        {
            if(!Value)
            {
                fprintf(stderr, "Expected a value for option %s.\n", Param);
                return 0;
            }
            Params->InputFile = Value;
        }
        else if(!strcmp(Param, "u") || !strcmp(Param, "output"))
        {
            if(!Value)
            {
                fprintf(stderr, "Expected a value for option %s.\n", Param);
                return 0;
            }
            Params->OutputFile = Value;
        }
        else if(!strcmp(Param, "K"))
        {
            if(!Value)
            {
                fprintf(stderr, "Expected a value for option %s.\n", Param);
                return 0;
            }
            else if(!ReadKernel(&Params->Kernel, Value))
                return 0;
        }
        else if(!strcmp(Param, "lambda"))
        {
            if(!CliGetNum(&NumValue, Value, Param))
                return 0;
            else if(NumValue <= 0)
            {
                fputs("Parameter lambda must be positive.\n", stderr);
                return 0;
            } 
            else
                Params->Lambda = (int)NumValue;
        }
        else if(!strcmp(Param, "noise"))
        {
            if(!Value)
            {
                fprintf(stderr, "Expected a value for option %s.\n", Param);
                return 0;
            }
            else
                Params->Noise = Value;
        }
        else if(!strcmp(Param, "jpegquality"))
        {
            if(!CliGetNum(&NumValue, Value, Param))
                return 0;
            else if(NumValue < 0 || 100 < NumValue)
            {
                fputs("JPEG quality must be between 0 and 100.\n", stderr);
                return 0;
            } 
            else
                Params->JpegQuality = (int)NumValue;
        }
        else if(Skip)
        {
            fprintf(stderr, "Unknown option \"%s\".\n", Param);
            return 0;
        }
        else
        {
            if(!Params->InputFile)
                Params->InputFile = argv[k];
            else
                Params->OutputFile = argv[k];
            
            kread = k;
        }
        
        k = kread + 1;
    }
    
    if(!Params->Kernel.Data && !ReadKernel(&Params->Kernel, "disk:0"))
        return 0;
    
    if(!Params->InputFile)
    {
        PrintHelpMessage();
        return 0;
    }

    return 1;
}