src/sg_logs.c
static int
process_cl_new(struct opts_t * op, int argc, char * argv[])
{
    int c, n;

    while (1) {
        int option_index = 0;

        c = getopt_long(argc, argv, "aAbc:ef:hHi:lLm:nNOp:P:qQrRsStTvVxX",
                        long_options, &option_index);
        if (c == -1)
            break;

        switch (c) {
        case 'a':
            ++op->do_all;
            break;
        case 'A':    /* not documented: compatibility with old interface */
            op->do_all += 2;
            break;
        case 'b':
            ++op->do_brief;
            break;
        case 'c':
            n = sg_get_num(optarg);
            if ((n < 0) || (n > 3)) {
                pr2serr("bad argument to '--control='\n");
                usage(2);
                return SG_LIB_SYNTAX_ERROR;
            }
            op->page_control = n;
            break;
        case 'e':
            ++op->do_enumerate;
            break;
        case 'f':
            if ('-' == optarg[0]) {
                n = sg_get_num(optarg + 1);
                if ((n < 0) || (n > 0x30)) {
                    pr2serr("bad negated argument to '--filter='\n");
                    return SG_LIB_SYNTAX_ERROR;
                }
                op->filter = -n;
            } else {
                n = sg_get_num(optarg);
                if ((n < 0) || (n > 0xffff)) {
                    pr2serr("bad argument to '--filter='\n");
                    usage(1);
                    return SG_LIB_SYNTAX_ERROR;
                }
                op->filter = n;
            }
            ++op->filter_given;
            break;
        case 'h':
        case '?':
            ++op->do_help;
            break;
        case 'H':
            ++op->do_hex;
            break;
        case 'i':
            op->in_fn = optarg;
            break;
        case 'l':
            ++op->do_list;
            break;
        case 'L':
            op->do_list += 2;
            break;
        case 'm':
            n = sg_get_num(optarg);
            if ((n < 0) || (1 == n) || (n > 0xffff)) {
                pr2serr("bad argument to '--maxlen=', from 2 to 65535 "
                        "(inclusive) expected\n");
                usage(2);
                return SG_LIB_SYNTAX_ERROR;
            }
            op->maxlen = n;
            break;
        case 'n':
            ++op->do_name;
            break;
        case 'N':
            break;      /* ignore */
        case 'O':
            op->opt_new = 0;
            return 0;
        case 'p':
            op->pg_arg = optarg;
            break;
        case 'P':
            n = sg_get_num(optarg);
            if (n < 0) {
                pr2serr("bad argument to '--paramp='\n");
                usage(2);
                return SG_LIB_SYNTAX_ERROR;
            }
            op->paramp = n;
            break;
        case 'q':
            ++op->do_pcb;
            break;
        case 'Q':       /* N.B. PPC bit obsoleted in SPC-4 rev 18 */
            ++op->do_ppc;
            break;
        case 'r':
            ++op->do_raw;
            break;
        case 'R':
            ++op->do_pcreset;
            ++op->do_select;
            break;
        case 's':
            ++op->do_sp;
            break;
        case 'S':
            ++op->do_select;
            break;
        case 't':
            ++op->do_temperature;
            break;
        case 'T':
            ++op->do_transport;
            break;
        case 'v':
            ++op->verbose;
            break;
        case 'V':
            ++op->do_version;
            break;
        case 'x':
            ++op->no_inq;
            break;
        case 'X':
            ++op->o_readonly;
            break;
        default:
            pr2serr("unrecognised option code %c [0x%x]\n", c, c);
            if (op->do_help)
                break;
            usage(1);
            return SG_LIB_SYNTAX_ERROR;
        }
    }
    if (optind < argc) {
        if (NULL == op->device_name) {
            op->device_name = argv[optind];
            ++optind;
        }
        if (optind < argc) {
            for (; optind < argc; ++optind)
                pr2serr("Unexpected extra argument: %s\n", argv[optind]);
            usage(1);
            return SG_LIB_SYNTAX_ERROR;
        }
    }
    return 0;
}
/* Processes command line options according to new option format. Returns
 * 0 is ok, else SG_LIB_SYNTAX_ERROR is returned. */
Processes command line options according to new option format. Returns
0 is ok, else SG_LIB_SYNTAX_ERROR is returned.
Processes command line options according to new option format . Returns 0 is ok else SG_LIB_SYNTAX_ERROR is returned .
static int
process_cl_new(struct opts_t * op, int argc, char * argv[])
{
    int c, n;
    while (1) {
        int option_index = 0;
        c = getopt_long(argc, argv, "aAbc:ef:hHi:lLm:nNOp:P:qQrRsStTvVxX",
                        long_options, &option_index);
        if (c == -1)
            break;
        switch (c) {
        case 'a':
            ++op->do_all;
            break;
        case 'A':    
            op->do_all += 2;
            break;
        case 'b':
            ++op->do_brief;
            break;
        case 'c':
            n = sg_get_num(optarg);
            if ((n < 0) || (n > 3)) {
                pr2serr("bad argument to '--control='\n");
                usage(2);
                return SG_LIB_SYNTAX_ERROR;
            }
            op->page_control = n;
            break;
        case 'e':
            ++op->do_enumerate;
            break;
        case 'f':
            if ('-' == optarg[0]) {
                n = sg_get_num(optarg + 1);
                if ((n < 0) || (n > 0x30)) {
                    pr2serr("bad negated argument to '--filter='\n");
                    return SG_LIB_SYNTAX_ERROR;
                }
                op->filter = -n;
            } else {
                n = sg_get_num(optarg);
                if ((n < 0) || (n > 0xffff)) {
                    pr2serr("bad argument to '--filter='\n");
                    usage(1);
                    return SG_LIB_SYNTAX_ERROR;
                }
                op->filter = n;
            }
            ++op->filter_given;
            break;
        case 'h':
        case '?':
            ++op->do_help;
            break;
        case 'H':
            ++op->do_hex;
            break;
        case 'i':
            op->in_fn = optarg;
            break;
        case 'l':
            ++op->do_list;
            break;
        case 'L':
            op->do_list += 2;
            break;
        case 'm':
            n = sg_get_num(optarg);
            if ((n < 0) || (1 == n) || (n > 0xffff)) {
                pr2serr("bad argument to '--maxlen=', from 2 to 65535 "
                        "(inclusive) expected\n");
                usage(2);
                return SG_LIB_SYNTAX_ERROR;
            }
            op->maxlen = n;
            break;
        case 'n':
            ++op->do_name;
            break;
        case 'N':
            break;      
        case 'O':
            op->opt_new = 0;
            return 0;
        case 'p':
            op->pg_arg = optarg;
            break;
        case 'P':
            n = sg_get_num(optarg);
            if (n < 0) {
                pr2serr("bad argument to '--paramp='\n");
                usage(2);
                return SG_LIB_SYNTAX_ERROR;
            }
            op->paramp = n;
            break;
        case 'q':
            ++op->do_pcb;
            break;
        case 'Q':       
            ++op->do_ppc;
            break;
        case 'r':
            ++op->do_raw;
            break;
        case 'R':
            ++op->do_pcreset;
            ++op->do_select;
            break;
        case 's':
            ++op->do_sp;
            break;
        case 'S':
            ++op->do_select;
            break;
        case 't':
            ++op->do_temperature;
            break;
        case 'T':
            ++op->do_transport;
            break;
        case 'v':
            ++op->verbose;
            break;
        case 'V':
            ++op->do_version;
            break;
        case 'x':
            ++op->no_inq;
            break;
        case 'X':
            ++op->o_readonly;
            break;
        default:
            pr2serr("unrecognised option code %c [0x%x]\n", c, c);
            if (op->do_help)
                break;
            usage(1);
            return SG_LIB_SYNTAX_ERROR;
        }
    }
    if (optind < argc) {
        if (NULL == op->device_name) {
            op->device_name = argv[optind];
            ++optind;
        }
        if (optind < argc) {
            for (; optind < argc; ++optind)
                pr2serr("Unexpected extra argument: %s\n", argv[optind]);
            usage(1);
            return SG_LIB_SYNTAX_ERROR;
        }
    }
    return 0;
}
static int process_cl_new ( struct opts_t * op , int argc , char * argv [ ] ) { int c , n ; while ( 1 ) { int option_index = 0 ; c = getopt_long ( argc , argv , " " , long_options , & option_index ) ; if ( c == -1 ) break ; switch ( c ) { case ' ' : ++ op -> do_all ; break ; case ' ' : op -> do_all += 2 ; break ; case ' ' : ++ op -> do_brief ; break ; case ' ' : n = sg_get_num ( optarg ) ; if ( ( n < 0 ) || ( n > 3 ) ) { pr2serr ( " \n " ) ; usage ( 2 ) ; return SG_LIB_SYNTAX_ERROR ; } op -> page_control = n ; break ; case ' ' : ++ op -> do_enumerate ; break ; case ' ' : if ( ' ' == optarg [ 0 ] ) { n = sg_get_num ( optarg + 1 ) ; if ( ( n < 0 ) || ( n > 0x30 ) ) { pr2serr ( " \n " ) ; return SG_LIB_SYNTAX_ERROR ; } op -> filter = - n ; } else { n = sg_get_num ( optarg ) ; if ( ( n < 0 ) || ( n > 0xffff ) ) { pr2serr ( " \n " ) ; usage ( 1 ) ; return SG_LIB_SYNTAX_ERROR ; } op -> filter = n ; } ++ op -> filter_given ; break ; case ' ' : case ' ' : ++ op -> do_help ; break ; case ' ' : ++ op -> do_hex ; break ; case ' ' : op -> in_fn = optarg ; break ; case ' ' : ++ op -> do_list ; break ; case ' ' : op -> do_list += 2 ; break ; case ' ' : n = sg_get_num ( optarg ) ; if ( ( n < 0 ) || ( 1 == n ) || ( n > 0xffff ) ) { pr2serr ( " " " \n " ) ; usage ( 2 ) ; return SG_LIB_SYNTAX_ERROR ; } op -> maxlen = n ; break ; case ' ' : ++ op -> do_name ; break ; case ' ' : break ; case ' ' : op -> opt_new = 0 ; return 0 ; case ' ' : op -> pg_arg = optarg ; break ; case ' ' : n = sg_get_num ( optarg ) ; if ( n < 0 ) { pr2serr ( " \n " ) ; usage ( 2 ) ; return SG_LIB_SYNTAX_ERROR ; } op -> paramp = n ; break ; case ' ' : ++ op -> do_pcb ; break ; case ' ' : ++ op -> do_ppc ; break ; case ' ' : ++ op -> do_raw ; break ; case ' ' : ++ op -> do_pcreset ; ++ op -> do_select ; break ; case ' ' : ++ op -> do_sp ; break ; case ' ' : ++ op -> do_select ; break ; case ' ' : ++ op -> do_temperature ; break ; case ' ' : ++ op -> do_transport ; break ; case ' ' : ++ op -> verbose ; break ; case ' ' : ++ op -> do_version ; break ; case ' ' : ++ op -> no_inq ; break ; case ' ' : ++ op -> o_readonly ; break ; default : pr2serr ( " \n " , c , c ) ; if ( op -> do_help ) break ; usage ( 1 ) ; return SG_LIB_SYNTAX_ERROR ; } } if ( optind < argc ) { if ( NULL == op -> device_name ) { op -> device_name = argv [ optind ] ; ++ optind ; } if ( optind < argc ) { for ( ; optind < argc ; ++ optind ) pr2serr ( " \n " , argv [ optind ] ) ; usage ( 1 ) ; return SG_LIB_SYNTAX_ERROR ; } } return 0 ; }
Processes command line options according to new option format.
Processes command line options according to new option format .
/* not documented: compatibility with old interface */ /* ignore */ /* N.B. PPC bit obsoleted in SPC-4 rev 18 */