Ejemplo n.º 1
0
static void
parse_command_line( int argc, char *argv[] )
{

	int		i, j = 0;
	char	*s;					/* to traverse the options */
	const char	**argument = NULL;	/* option argument */

	for ( i = 1; i < argc; i++ ) {

		s = argv[i];

		if ( argument ) {
			*argument = s;
			argument = NULL;
			continue;
		}

		if ( ( '-' == *s ) && *++s ) {

			/* we're looking at an option */
			while ( *s ) {

				/* determine which one it is */
				switch ( *s++ ) {
					case 'd': enable_debug ();			break;
					case 'h': usage ();					break;
					case 'i': stdio	= true;				break;
					case 'm': argument = &mac;			break;
					case 'p': port = (int) strtol ( s, NULL, port ); break;
					case 's': argument = &mask;			break;
					default : error ( E_OPTION, *--s );	break;
				}

				/* if there is an argument to this option, stash it */
				if ( argument && *s ) {
					*argument = s;
					argument = NULL;
					break;
				}

			}

		} else {

			/* we're looking at a file name */
			switch ( j++ ) {
				case  0: fn_in  = s;		 break;
				case  1: fn_out = s;		 break;
				default: error ( E_ARGCNT ); break;
			}

		}

	}

}
Ejemplo n.º 2
0
void parse_cmd_line_args(int argc, char ** argv, bool& do_display_usage, bool& test_all) {
    int i = 1;
    while (i < argc) {
	char * arg = argv[i];    

	if (arg[0] == '-' || arg[0] == '/') {
	    char * opt_name = arg + 1;
	    char * opt_arg  = 0;
	    char * colon    = strchr(arg, ':');
	    if (colon) {
		opt_arg = colon + 1;
		*colon  = 0;
	    }
	    if (strcmp(opt_name, "h") == 0 ||
                strcmp(opt_name, "?") == 0) {
		display_usage();
                do_display_usage = true;
                return;
	    }
	    else if (strcmp(opt_name, "v") == 0) {
		if (!opt_arg)
		    error("option argument (/v:level) is missing.");
		long lvl = strtol(opt_arg, 0, 10);
		set_verbosity_level(lvl);
	    }
	    else if (strcmp(opt_name, "w") == 0) {
                enable_warning_messages(true);
	    }
	    else if (strcmp(opt_name, "a") == 0) {
                test_all = true;
	    }
#ifdef _TRACE
	    else if (strcmp(opt_name, "tr") == 0) {
		if (!opt_arg)
		    error("option argument (/tr:tag) is missing.");
		enable_trace(opt_arg);
	    }
#endif
#ifdef Z3DEBUG
	    else if (strcmp(opt_name, "dbg") == 0) {
		if (!opt_arg)
		    error("option argument (/dbg:tag) is missing.");
		enable_debug(opt_arg);
	    }
#endif
	}
	i++;
    }
}
Ejemplo n.º 3
0
void sinsp_curl::init()
{
	if(!m_curl)
	{
		throw sinsp_exception("Cannot initialize CURL.");
	}

	check_error(curl_easy_setopt(m_curl, CURLOPT_FORBID_REUSE, 1L));

	if(m_ssl)
	{
		init_ssl(m_curl, m_ssl);
	}

	if(m_bt)
	{
		init_bt(m_curl, m_bt);
	}

	enable_debug(m_curl, m_debug);
}
Ejemplo n.º 4
0
void parse_cmd_line_args(int argc, char ** argv) {
    int i = 1;
    char * eq_pos = 0;
    while (i < argc) {
        char * arg = argv[i];

        if (arg[0] == '-' && arg[1] == '-' && arg[2] == 0) {
            // Little hack used to read files with strange names such as -foo.smt2
            // z3 -- -foo.smt2
            i++;
            g_aux_input_file = "";
            for (; i < argc; i++) {
                g_aux_input_file += argv[i];
                if (i < argc - 1)
                    g_aux_input_file += " ";
            }
            if (g_input_file) {
                warning_msg("input file was already specified.");
            }
            else {
                g_input_file = g_aux_input_file.c_str();
            }
            break;
        }

        if (arg[0] == '-'
#ifdef _WINDOWS
            || arg[0] == '/'
#endif
            ) {
            char * opt_name = arg + 1;
            // allow names such as --help
            if (*opt_name == '-')
                opt_name++;
            char * opt_arg  = 0;
            char * colon    = strchr(arg, ':');
            if (colon) {
                opt_arg = colon + 1;
                *colon  = 0;
            }
            if (strcmp(opt_name, "h") == 0 || strcmp(opt_name, "?") == 0 || strcmp(opt_name, "help") == 0) {
                display_usage();
                exit(0);
            }
            if (strcmp(opt_name, "version") == 0) {
                std::cout << "Z3 version " << Z3_MAJOR_VERSION << "." << Z3_MINOR_VERSION << "." << Z3_BUILD_NUMBER << "\n";
                exit(0);
            }
            else if (strcmp(opt_name, "smt") == 0) {
                g_input_kind = IN_SMTLIB;
            }
            else if (strcmp(opt_name, "smt2") == 0) {
                g_input_kind = IN_SMTLIB_2;
            }
            else if (strcmp(opt_name, "in") == 0) {
                g_standard_input = true;
            }
            else if (strcmp(opt_name, "dimacs") == 0) {
                g_input_kind = IN_DIMACS;
            }
            else if (strcmp(opt_name, "log") == 0) {
                g_input_kind = IN_Z3_LOG;
            }
            else if (strcmp(opt_name, "st") == 0) {
                g_display_statistics = true;
            }
            else if (strcmp(opt_name, "ist") == 0) {
                g_display_istatistics = true;
            }
            else if (strcmp(opt_name, "v") == 0) {
                if (!opt_arg)
                    error("option argument (-v:level) is missing.");
                long lvl = strtol(opt_arg, 0, 10);
                set_verbosity_level(lvl);
            }
            else if (strcmp(opt_name, "file") == 0) {
                g_input_file = opt_arg;
            }
            else if (strcmp(opt_name, "T") == 0) {
                if (!opt_arg)
                    error("option argument (-T:timeout) is missing.");
                long tm = strtol(opt_arg, 0, 10);
                set_timeout(tm * 1000);
            }
            else if (strcmp(opt_name, "t") == 0) {
                if (!opt_arg)
                    error("option argument (-t:timeout) is missing.");
                gparams::set("timeout", opt_arg);
            }
            else if (strcmp(opt_name, "nw") == 0) {
                enable_warning_messages(false);
            }
            else if (strcmp(opt_name, "p") == 0) {
                gparams::display(std::cout, 0, false, false);
                exit(0);
            }
            else if (strcmp(opt_name, "pd") == 0) {
                gparams::display(std::cout, 0, false, true);
                exit(0);
            }
            else if (strcmp(opt_name, "pm") == 0) {
                if (opt_arg) {
                    gparams::display_module(std::cout, opt_arg);
                }
                else {
                    gparams::display_modules(std::cout);
                    std::cout << "\nUse -pm:name to display all parameters available at module 'name'\n";
                }
                exit(0);
            }
            else if (strcmp(opt_name, "pp") == 0) {
                if (!opt_arg)
                    error("option argument (-pp:name) is missing.");
                gparams::display_parameter(std::cout, opt_arg);
                exit(0);
            }
#ifdef _TRACE
            else if (strcmp(opt_name, "tr") == 0) {
                if (!opt_arg)
                    error("option argument (-tr:tag) is missing.");
                enable_trace(opt_arg);
            }
#endif
#ifdef Z3DEBUG
            else if (strcmp(opt_name, "dbg") == 0) {
                if (!opt_arg)
                    error("option argument (-dbg:tag) is missing.");
                enable_debug(opt_arg);
            }
#endif
            else if (strcmp(opt_name, "memory") == 0) {
                if (!opt_arg)
                    error("option argument (-memory:val) is missing.");
                gparams::set("memory_max_size", opt_arg);
            }
            else {
                std::cerr << "Error: invalid command line option: " << arg << "\n";
                std::cerr << "For usage information: z3 -h\n";
                exit(ERR_CMD_LINE);
            }
        }
        else if (argv[i][0] != '"' && (eq_pos = strchr(argv[i], '='))) {
            char * key   = argv[i];
            *eq_pos      = 0;
            char * value = eq_pos+1;
            gparams::set(key, value);
        }
        else {
            if (g_input_file) {
                warning_msg("input file was already specified.");
            }
            else {
                g_input_file = arg;
            }
        }
        i++;
    }
}
Ejemplo n.º 5
0
int main(int argc, char **argv)
{
    
    int status;
    int i;
    int debug = 0;
    int long_preamble = 0;
    
    int test = TEST_NONE;
    DataRate rate_e = DATA_RATE_1M;
    char *rate_s = "1Mbps";
    char *interface_name = NULL;
    
    
    DBG("argc=%u\n", argc);

    if(argc < 2)
    {
        print_usage();
        return -1;
    }

    interface_name = argv[1];

    
    
    for(i=2;i<argc;i++)
    {
        if(str_comp(argv[i], "-ch:", 4))
        {
            channel = atoi(argv[i]+4);
            if((channel > 14) || (channel < 1))
            {
                CON("Invalid channel: %u\n", channel);
                return -1;
            }
            continue;
        }

        if(str_comp(argv[i], "-time:", 6))
        {
            time = atoi(argv[i]+6);
            if((time > 24*3600) || (time < 1))
            {
                CON("Invalid time: %u\n", time);
                return -1;
            }
            continue;
        }

        if(str_comp(argv[i], "-rate:", 6))
        {
            int rate = atoi(argv[i]+6);
            switch(rate)
            {
                case 1:
                case 1000:
                    rate_e = DATA_RATE_1M;
                    rate_s = "1Mbps";
                    break;
                case 2:    
                case 2000:
                    rate_e = DATA_RATE_2M;
                    rate_s = "2Mbps";
                    break;
                case 5500:
                    rate_e = DATA_RATE_5_5M;
                    rate_s = "5.5Mbps";
                    break;
                //case 6: the user migh have writen "-rate:6.5"...    
                case 6000:
                    rate_e = DATA_RATE_6M;
                    rate_s = "6Mbps";
                    break;
                case 6500:
                    rate_e = DATA_RATE_MCS0;
                    rate_s = "6.5Mbps (MCS0)";
                    break;    
                case 9:    
                case 9000:
                    rate_e = DATA_RATE_9M;
                    rate_s = "9Mbps";
                    break;
                case 11:    
                case 11000:
                    rate_e = DATA_RATE_11M;
                    rate_s = "11Mbps";
                    break;
                case 12:    
                case 12000:
                    rate_e = DATA_RATE_12M;
                    rate_s = "12Mbps";
                    break;
                case 13:    
                case 13000:
                    rate_e = DATA_RATE_MCS1;
                    rate_s = "13Mbps (MSC1)";
                    break;
                case 18:    
                case 18000:
                    rate_e = DATA_RATE_18M;
                    rate_s = "18Mbps";
                    break;
                case 19500:
                    rate_e = DATA_RATE_MCS2;
                    rate_s = "19.5Mbps (MSC2)";
                    break;
                case 22:    
                case 22000:
                    rate_e = DATA_RATE_22M;
                    rate_s = "22Mbps";
                    break;
                case 24:    
                case 24000:
                    rate_e = DATA_RATE_24M;
                    rate_s = "24Mbps";
                    break;
                case 26:    
                case 26000:
                    rate_e = DATA_RATE_MCS3;
                    rate_s = "26Mbps (MSC3)";
                    break;
                case 33:    
                case 33000:
                    rate_e = DATA_RATE_33M;
                    rate_s = "33Mbps";
                    break;
                case 36:    
                case 36000:
                    rate_e = DATA_RATE_36M;
                    rate_s = "36Mbps";
                    break;
                case 39:
                case 39000:
                    rate_e = DATA_RATE_MCS4;
                    rate_s = "39Mbps (MCS4)";
                    break;
                case 48:    
                case 48000:
                    rate_e = DATA_RATE_48M;
                    rate_s = "48Mbps";
                    break;
                case 52:    
                case 52000:
                    rate_e = DATA_RATE_MCS5;
                    rate_s = "52Mbps (MCS5)";
                    break;
                case 54:    
                case 54000:
                    rate_e = DATA_RATE_54M;
                    rate_s = "54Mbps";
                    break;    
                case 58500:
                    rate_e = DATA_RATE_MCS6;
                    rate_s = "58.5Mbps (MCS6)";
                    break;
                case 65:    
                case 65000:
                    rate_e = DATA_RATE_MCS7;
                    rate_s = "65Mbps (MSC7)";
                    break;
               default:
                   CON("Invalid modulation rate %uKbps\n",rate);
                   return -1;
           }
           continue;
        }
        
        if(str_comp(argv[i], "-bi:", 4))
        {
            burst_interval = atoi(argv[i]+4);
            if(burst_interval < 0)
            {
                CON("Invalid burst interval: %u\n", burst_interval);
                return -1;
            }
            continue;
        }
         
        if(str_comp(argv[i], "-size:", 6))
        {
            packet_size = atoi(argv[i]+6);
            if((packet_size < 0) || (packet_size > 1536))
            {
                CON("Invalid packet size: %u\n", packet_size);
                return -1;
            }
            continue;
        }
        
        if(str_comp(argv[i], "-pwr:", 5))
        {
            output_power = atoi(argv[i]+5);
            if((output_power < 0) || (output_power > 30))
            {
                CON("Invalid output power: %ddBm\n", output_power);
                return -1;
            }
            continue;
        }     

        if(str_comp(argv[i], "none", 4))
        {
            test = TEST_NONE;
            continue;
        }

        if(str_comp(argv[i], "tx", 2))
        {
            test = TEST_TX;
            continue;
        }

        if(str_comp(argv[i], "rx", 2))
        {
            test = TEST_RX;
            continue;
        }
        
        if(str_comp(argv[i], "-lp", 3))
        {
            long_preamble = 1;
            continue;
        }  

        if(str_comp(argv[i], "-dbg", 4))
        {
            enable_debug();
            continue;
        }

        CON("I do not understand argument \"%s\", ignoring\n", argv[i]);
    }

    status = set_interface(interface_name);
    if(status)
    {
        CON("Could not set interface name\n");
        CON("  Driver say:\"%s\"\n",GetErrorString());
        return -1;
    }
  
  
    status = OpenDUT();
    if(status)
    {
        CON("Could not open connection to Nanoradio WiFi-chip\n");
        CON("  Driver say:\"%s\"\n",GetErrorString());
        return -1;
    }
     
    status = SetLongPreamble(long_preamble);
    if(status)
    {
        CON("Failed to set long preamble\n");
        CON("  Driver say:\"%s\"\n",GetErrorString());
        goto exit;
    }
     
    status = SetBurstInterval(burst_interval);
    if(status)
    {
        CON("Failed to set burst interval\n");
        CON("  Driver say:\"%s\"\n",GetErrorString());
        goto exit;
    }   
  
  
    status = SetChannel(channel);
    if(status)
    {
        CON("Failed to write channel to Nanoradio WiFi-chip\n");
        CON("  Driver say:\"%s\"\n",GetErrorString());
        goto exit;
    }
    
    status = SetPayload(packet_size);
    if(status)
    {
        CON("Failed to set packet size\n");
        CON("  Driver say:\"%s\"\n",GetErrorString());
        goto exit;
    }
  

  status = SetDataRate(rate_e);
  if(status)
  {
    CON("Failed to write data rate to Nanoradio WiFi-chip\n");
    CON("  Driver say:\"%s\"\n",GetErrorString());
    goto exit;
  }

    switch(test)
    {
        case TEST_NONE:
            break;
        case TEST_TX:
        {
            status = TxGain(output_power);
            if(status)
            {
                CON("Failed to set output power\n");
                CON("  Driver say:\"%s\"\n",GetErrorString());
                goto exit;
            }   
         
            status = TxStartWithMod();
            if(status)
            {
                CON("Failed to start TX\n");
                CON("  Driver say:\"%s\"\n",GetErrorString());
                goto exit;
            }
            else
            {
                CON("Sending frames continiously on channel %u with rate %s for %u seconds\n",channel,rate_s,time);
                sleep(time);
                status = TxStop();
                if(status)
                {
                    CON("Failed to stop TX\n");
                    CON("  Driver say:\"%s\"\n",GetErrorString());
                    goto exit;
                }
                
            }
        }
        break;
        
        case TEST_RX:
        {
            status = RxStart();
            if(status)
            {
                CON("Failed to start RX\n");
                CON("  Driver say:\"%s\"\n",GetErrorString());
                goto exit;
            }
            else
            {
                CON("Counting frames on channel %u with rate %s for %u seconds\n",channel,rate_s,time);
                sleep(time);
                status = RxStop();
                if(status)
                {
                    CON("Failed to stop RX\n");
                    CON("  Driver say:\"%s\"\n",GetErrorString());
                    goto exit;
                }
                else
                {
                    CON("Good frames:%u\n", GetGoodFrame());
                }
            }
      }
      break;
  }

exit:

    CloseDUT();
    return status;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[]) {
    struct USBConnection *connection;
    int opt;
    int repeatCount = 0;
    char *script = NULL;
    int delay = 10;
    int daemon = 0;
    while ((opt = getopt(argc, argv, "s:d:c:Dv")) != -1) {
        switch (opt) {
            case 's':
                script = optarg;
                break;
            case 'd':
                delay = atoi(optarg);
                break;
            case 'c':
                repeatCount = atoi(optarg);
                break;
            case 'D':
                daemon = 1;
                break;
            case 'v':
                enable_debug();
                break;
            default:
                printUsage(argv[0]);
                return -1;
        }
    }
    if (optind >= argc) {
        fprintf(stderr, "Missing USB device parameter.\n");
        printUsage(argv[0]);
        return -1;
    }
    if (daemon && script == NULL) {
        fprintf(stderr, "Missing script parameter. Running the program as a daemon implies -s.\n");
        return -1;
    }
    if (daemon) {
        initlog(1);
        daemonize();
    }
    else {
        initlog(0);
    }
    log_output(LOG_DEBUG, "Opening USB device\n");
    connection = initUSBConnection(argv[optind]);
    if (connection != NULL) {
        int i;
        int increment = 1;
        log_output(LOG_INFO, "Connection initialization successful. UVR mode 0x%X\n", (unsigned int)connection->uvr_mode);
        if (repeatCount == 0) {
            increment = 0;
            repeatCount = 1; // prepare the values in a way that the loop below runs infinitely
        }
        for (i = 0; i < repeatCount; i+=increment) {
            struct SystemState *result;
            result = readCurrentData(connection);
            if (result != NULL) {
                if (script != NULL) {
                    executeProgram(script, result);
                }
                else {
                    printf("Inputs\n");
                    printValueList("S", result->inputs);
                    printf("Outputs\n");
                    printValueList("O", result->outputs);
                    printf("Heat registers\n");
                    printValueList("", result->heatRegisters);
                }
                freeSystemState(result);
                result = NULL;
            }
            sleep(delay);
        }
    }
    else {
        fprintf(stderr, "Could not initialize connection to UVR. %s\n", strerror(errno));
        cleanupUSBConnection(connection);
        return -1;
    }
    cleanupUSBConnection(connection);
    return 0;
}