コード例 #1
0
/**
 * @brief: parse the command line
 *         this is the simple template which will be used by falab projects
 *
 * @param:argc
 * @param:argv[]
 *
 * @return: 0 if success, -1 if error(input value maybe not right)
 */
int fa_parseopt(int argc, char *argv[])
{
    int ret;
    const char *die_msg = NULL;

    while (1) {
        static char * const     short_options = "hHLi:o:l:t:";  
        static struct option    long_options[] = 
                                {
                                    { "help"       , 0, 0, 'h'}, 
                                    { "long-help"  , 0, 0, 'H'},
                                    { "license"    , 0, 0, 'L'},
                                    { "input"      , 1, 0, 'i'},                 
                                    { "output"     , 1, 0, 'o'},                 
                                    { "framelen"   , 1, 0, 'l'},        
                                    { "wintype"    , 1, 0, 't'},        
                                    { "winlen"     , 1, 0, OPT_WINLEN},
                                    { "firtype"    , 1, 0, OPT_FIRTYPE},
                                    { "cutoff"     , 1, 0, OPT_CUTOFF},
                                    { "cutoff1"    , 1, 0, OPT_CUTOFF1},
                                    { "cutoff2"    , 1, 0, OPT_CUTOFF2},
                                    {0             , 0, 0,  0},
                                };
        int c = -1;
        int option_index = 0;

        c = getopt_long(argc, argv, 
                        short_options, long_options, &option_index);

        if (c == -1) {
            break;
        }

        if (!c) {
            die_msg = usage;
            break;
        }

        switch (c) {
            case 'h': {
                          die_msg = short_help;
                          break;
                      }

            case 'H': {
                          die_msg = long_help;
                          break;
                      }
                      
            case 'L': {
                          die_msg = license;
                          break;
                      }

            case 'i': {
                          if (sscanf(optarg, "%s", opt_inputfile) > 0) {
                              FA_PRINT("SUCC: inputfile is %s\n", opt_inputfile);
                          }else {
                              FA_PRINT_ERR("FAIL: no inputfile\n");
                          }
                          break;
                      }

            case 'o': {
                          if (sscanf(optarg, "%s", opt_outputfile) > 0) {
                              FA_PRINT("SUCC: outputfile is %s\n", opt_outputfile);
                          }else {
                              FA_PRINT_ERR("FAIL: no outputfile\n");
                          }
                          break;
                      }

            case 'l': {
                          unsigned int i;
                          if (sscanf(optarg, "%u", &i) > 0) {
                              opt_framelen = i;
                              FA_PRINT("SUCC: set frame length = %u\n", opt_framelen);
                          }
                          break;
                      }

            case 't': {
                          unsigned int i;
                          if (sscanf(optarg, "%u", &i) > 0) {
                              opt_wintype = i;
                              FA_PRINT("SUCC: set win type = %u\n", opt_wintype);
                          }
                          break;
                      }
                      
            case OPT_WINLEN: {
                                  unsigned int i;
                                  if (sscanf(optarg, "%u", &i) > 0) {
                                      opt_winlen = i;
                                      FA_PRINT("SUCC: set window length = %u\n", opt_winlen);
                                  }
                                  break;
                             }
                             
            case OPT_FIRTYPE: {
                                  unsigned int i;
                                  if (sscanf(optarg, "%u", &i) > 0) {
                                      opt_firtype = i;
                                      FA_PRINT("SUCC: set fir type = %u\n", opt_firtype);
                                  }
                                  break;
                              }
                             
            case OPT_CUTOFF: {
                                  float i;
                                  if (sscanf(optarg, "%f", &i) > 0) {
                                      opt_fc = i;
                                      FA_PRINT("SUCC: set fir cutoff freqency = %f\n", opt_fc);
                                  }
                                  break;
                              }
                             
            case OPT_CUTOFF1:{
                                  float i;
                                  if (sscanf(optarg, "%f", &i) > 0) {
                                      opt_fc1 = i;
                                      FA_PRINT("SUCC: set fir cutoff start freqency = %f\n", opt_fc1);
                                  }
                                  break;
                              }
                             
            case OPT_CUTOFF2:{
                                  float i;
                                  if (sscanf(optarg, "%f", &i) > 0) {
                                      opt_fc2 = i;
                                      FA_PRINT("SUCC: set fir cutoff stop freqency = %f\n", opt_fc2);
                                  }
                                  break;
                              }

            case '?':
            default:
                      die_msg = usage;
                      break;
        }
    }

    if(die_msg) {
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*check the input validity*/
    ret = fa_checkopt(argc);
    if(ret) {
        die_msg = usage;
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*print the settings*/
    fa_printopt();

    return 0;
fail:
    return -1;
}
コード例 #2
0
/**
 * @brief: parse the command line
 *         this is the simple template which will be used by falab projects
 *
 * @param:argc
 * @param:argv[]
 *
 * @return: 0 if success, -1 if error(input value maybe not right)
 */
int fa_parseopt(int argc, char *argv[])
{
    int ret;
    const char *die_msg = NULL;

    while (1) {
        static char * const     short_options = "hHLvfb:R:";  
        static struct option    long_options[] = 
                                {
                                    { "help"       , 0, 0, 'h'}, 
                                    { "long-help"  , 0, 0, 'H'},
                                    { "license"    , 0, 0, 'L'},
                                    { "verbose"    , 0, 0, 'v'},  
                                    { "fast"       , 0, 0, 'f'},  
                                    { "bitrate"    , 1, 0, 'b'},                // need 1 argument 
                                    { "samplerate" , 1, 0, 'R'},                // need 1 argument 
                                    { "switch1"    , 0, 0, SWITCH1_FLAG},       // --switch1 will return SWIATCH1_FLAG 
                                    { "switch2"    , 1, 0, SWITCH2_FLAG},       // --switch2 will return SWIATCH2_FLAG 
                                    {0             , 0, 0, 0},
                                };
        int c = -1;
        int option_index = 0;

        c = getopt_long(argc, argv, 
                        short_options, long_options, &option_index);

        if (c == -1) {
            break;
        }

        if (!c) {
            die_msg = usage;
            break;
        }

        switch (c) {
            case 'h': {
                          die_msg = short_help;
                          break;
                      }

            case 'H': {
                          die_msg = long_help;
                          break;
                      }
                      
            case 'L': {
                          die_msg = license;
                          break;
                      }

            case 'v': {
                          opt_verbose = 1;
                          FA_PRINT("SUCC: verbose mode active\n");
                          break;
                      }

            case 'f': {
                          opt_fast = 1;
                          FA_PRINT("SUCC: fast mode active\n");
                          break;
                      }

            case 'b': {
                          unsigned int i;
                          if (sscanf(optarg, "%u", &i) > 0) {
                              opt_bitrate = 1000 * i;
                              FA_PRINT("SUCC: set bitrate=%u\n", opt_bitrate);
                          }else {
                              opt_bitrate = 0;
                              FA_PRINT("WARN: bitrate not set\n");
                          }
                          break;
                      }

            case 'R': {
                          unsigned int i;
                          if (sscanf(optarg, "%u", &i) > 0) {
                              opt_samplerate = i;
                              FA_PRINT("SUCC: set samplerate=%u\n", opt_samplerate);
                          }else {
                              opt_samplerate = 0;
                              FA_PRINT("WARN: samplerate not set\n");
                          }
                          break;
                      }

            case SWITCH1_FLAG:{
                                  opt_switch1 = 1;
                                  FA_PRINT("SUCC: switch1 set, default = 1 \n");
                                  break;
                              }

            case SWITCH2_FLAG:{
                                  unsigned int i;
                                  if (sscanf(optarg, "%d", &i) > 0) {
                                      opt_switch2 = i;
                                      FA_PRINT("SUCC: set switch2=%d\n", opt_switch2);
                                  }else {
                                      opt_switch2 = 0;
                                      FA_PRINT("WARN: switch2 not set\n");
                                  }
                                  break;
                              }

            case '?':
            default:
                      die_msg = usage;
                      break;
        }
    }

    if(die_msg) {
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*check the input validity*/
    ret = fa_checkopt(argc);
    if(ret) {
        die_msg = usage;
        goto fail;
    }

    /*print the settings*/
    fa_printopt();

    return 0;
fail:
    return -1;
}
コード例 #3
0
/**
 * @brief: parse the command line
 *         this is the simple template which will be used by falab projects
 *
 * @param:argc
 * @param:argv[]
 *
 * @return: 0 if success, -1 if error(input value maybe not right)
 */
int fa_parseopt(int argc, char *argv[])
{
    int ret;
    const char *die_msg = NULL;

    while (1) {
        static char * const     short_options = "hHLi:o:l:";  
        static struct option    long_options[] = 
                                {
                                    { "help"       , 0, 0, 'h'}, 
                                    { "long-help"  , 0, 0, 'H'},
                                    { "license"    , 0, 0, 'L'},
                                    { "input"      , 1, 0, 'i'},                 
                                    { "output"     , 1, 0, 'o'},                 
                                    { "framelen"   , 1, 0, 'l'},        
                                    {0             , 0, 0,  0},
                                };
        int c = -1;
        int option_index = 0;

        c = getopt_long(argc, argv, 
                        short_options, long_options, &option_index);

        if (c == -1) {
            break;
        }

        if (!c) {
            die_msg = usage;
            break;
        }

        switch (c) {
            case 'h': {
                          die_msg = short_help;
                          break;
                      }

            case 'H': {
                          die_msg = long_help;
                          break;
                      }
                      
            case 'L': {
                          die_msg = license;
                          break;
                      }

            case 'i': {
                          if (sscanf(optarg, "%s", opt_inputfile) > 0) {
                              FA_PRINT("SUCC: inputfile is %s\n", opt_inputfile);
                          }else {
                              FA_PRINT_ERR("FAIL: no inputfile\n");
                          }
                          break;
                      }

            case 'o': {
                          if (sscanf(optarg, "%s", opt_outputfile) > 0) {
                              FA_PRINT("SUCC: outputfile is %s\n", opt_outputfile);
                          }else {
                              FA_PRINT_ERR("FAIL: no outputfile\n");
                          }
                          break;
                      }

            case 'l': {
                          unsigned int i;
                          if (sscanf(optarg, "%u", &i) > 0) {
                              opt_framelen = i;
                              FA_PRINT("SUCC: set frame length = %u\n", opt_framelen);
                          }
                          break;
                      }

            case '?':
            default:
                      die_msg = usage;
                      break;
        }
    }

    if(die_msg) {
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*check the input validity*/
    ret = fa_checkopt(argc);
    if(ret) {
        die_msg = usage;
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*print the settings*/
    fa_printopt();

    return 0;
fail:
    return -1;
}
コード例 #4
0
ファイル: fa_parseopt.c プロジェクト: TernenceHsu/tsdemux
/**
 * @brief: parse the command line
 *         this is the simple template which will be used by falab projects
 *
 * @param:argc
 * @param:argv[]
 *
 * @return: 0 if success, -1 if error(input value maybe not right)
 */
int fa_parseopt(int argc, char *argv[])
{
    int ret;
    const char *die_msg = NULL;

    while (1) {
        static char * const     short_options = "hHLli:v:a:";
        static struct option    long_options[] =
        {
            { "help"           , 0, 0, 'h'},
            { "help"           , 0, 0, 'H'},
            { "license"        , 0, 0, 'L'},
            { "license"        , 0, 0, 'l'},
            { "input"          , 1, 0, 'i'},
            { "video output"   , 1, 0, 'v'},
            { "audio output"   , 1, 0, 'a'},
            {0                 , 0, 0,  0},
        };
        int c = -1;
        int option_index = 0;

        c = getopt_long(argc, argv, short_options, long_options, &option_index);

        if (c == -1) {
            break;
        }

        if (!c) {
            die_msg = usage;
            break;
        }

        switch (c) {
        case 'h': {
            die_msg = help;
            break;
        }

        case 'H': {
            die_msg = help;
            break;
        }

        case 'L': {
            die_msg = license;
            break;
        }

        case 'l': {
            die_msg = license;
            break;
        }

        case 'i': {
            if (sscanf(optarg, "%s", opt_inputfile) > 0) {
                FA_PRINT("SUCC: inputfile is %s\n", opt_inputfile);
            } else {
                FA_PRINT_ERR("FAIL: no inputfile\n");
            }
            break;
        }

        case 'v': {
            if (sscanf(optarg, "%s", opt_video_outputfile) > 0) {
                FA_PRINT("SUCC: video outputfile is %s\n", opt_video_outputfile);
            } else {
                FA_PRINT_ERR("FAIL: no video outputfile\n");
            }
            break;
        }

        case 'a': {
            if (sscanf(optarg, "%s", opt_audio_outputfile) > 0) {
                FA_PRINT("SUCC: audio outputfile is %s\n", opt_audio_outputfile);
            } else {
                FA_PRINT_ERR("FAIL: no audio outputfile\n");
            }
            break;
        }

        case '?':
        default:
            die_msg = usage;
            break;
        }
    }

    if(die_msg) {
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*check the input validity*/
    ret = fa_checkopt(argc);
    if(ret) {
        die_msg = usage;
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*print the settings*/
    fa_printopt();

    return 0;
fail:
    return -1;
}