Пример #1
0
dag_network::dag_network(const char *s_dagid, rpl_debug *deb)
{
    set_dagid(s_dagid);
    init_dag();
    set_debug(deb);
}
Пример #2
0
int main(int argc, char *argv[])
{
    int c = 0;
    FILE *fp = NULL;
    int long_opt_index = 0, i = 0, channel = 0, passive = 0, mode = 0;
    int source = INTERFACE, ret_val = EXIT_FAILURE;
    struct bpf_program bpf = { 0 };
    char *out_file = NULL, *last_optarg = NULL, *target = NULL, *bssid = NULL;
    char *short_options = "i:c:n:o:b:5sfuCDhPg";
    struct option long_options[] = {
		{ "get-chipset", no_argument, NULL, 'g' },
	{ "output-piped", no_argument, NULL, 'P' },
        { "bssid", required_argument, NULL, 'b' },
        { "interface", required_argument, NULL, 'i' },
        { "channel", required_argument, NULL, 'c' },
        { "out-file", required_argument, NULL, 'o' },
        { "probes", required_argument, NULL, 'n' },
        { "daemonize", no_argument, NULL, 'D' },
        { "file", no_argument, NULL, 'f' },
        { "ignore-fcs", no_argument, NULL, 'C' },
        { "5ghz", no_argument, NULL, '5' },
        { "scan", no_argument, NULL, 's' },
        { "survey", no_argument, NULL, 'u' },
        { "help", no_argument, NULL, 'h' },
        { 0, 0, 0, 0 }
    };
	

    globule_init();
    sql_init();
    create_ap_table();
    set_auto_channel_select(0);
    set_wifi_band(BG_BAND);
    set_debug(INFO);
    set_validate_fcs(1);
    set_log_file(stdout);
    set_max_num_probes(DEFAULT_MAX_NUM_PROBES);

    while((c = getopt_long(argc, argv, short_options, long_options, &long_opt_index)) != -1)
    {
        switch(c)
        {
			case 'g':
                get_chipset_output = 1;
				o_file_p = 1;
                break;
			case 'P':
                o_file_p = 1;
                break;
            case 'f':
                source = PCAP_FILE;
                break;
            case 'i':
                set_iface(optarg);
                break;
            case 'b':
                bssid = strdup(optarg);
                break;
            case 'c':
                channel = atoi(optarg);
                set_fixed_channel(1);
				c_fix = 1;
                break;
            case '5':
                set_wifi_band(AN_BAND);
                break;
            case 'n':
                set_max_num_probes(atoi(optarg));
                break;
            case 'o':
                out_file = strdup(optarg);
                break;
            case 's':
                mode = SCAN;
                break;
            case 'u':
                mode = SURVEY;
                break;
            case 'C':
                set_validate_fcs(0);
                break;
            case 'D':
                daemonize();
                break;
            default:
                usage(argv[0]);
                goto end;
        }

        /* Track the last optarg. This is used later when looping back through any specified pcap files. */
        if(optarg)
        {
            if(last_optarg)
            {
                free(last_optarg);
            }

            last_optarg = strdup(optarg);
        }
    }
	
	if (o_file_p == 0)
	{
		printf("\nWash v%s WiFi Protected Setup Scan Tool\n", PACKAGE_VERSION);
		printf("Copyright (c) 2011, Tactical Network Solutions, Craig Heffner <*****@*****.**>\n");
		printf("mod by t6_x <*****@*****.**> & DataHead & Soxrok2212 & Wiire\n\n");
	}	

    /* The interface value won't be set if capture files were specified; else, there should have been an interface specified */
    if(!get_iface() && source != PCAP_FILE)
    {
        usage(argv[0]);
        goto end;
    }
    else if(get_iface())
    {
        /* Get the MAC address of the specified interface */
        read_iface_mac();
    }

    if(get_iface() && source == PCAP_FILE)
    {
        cprintf(CRITICAL, "[X] ERROR: -i and -f options cannot be used together.\n");
        usage(argv[0]);
        goto end;
    }

    /* If we're reading from a file, be sure we don't try to transmit probe requests */
    if(source == PCAP_FILE)
    {
        passive = 1;
    }

    /* Open the output file, if any. If none, write to stdout. */
    if(out_file)
    {
	
		fp = fopen(out_file, "wb");
		if(!fp)
		{
			cprintf(CRITICAL, "[X] ERROR: Failed to open '%s' for writing\n", out_file);
			goto end;
		}
		

        set_log_file(fp);
    }

    /* 
     * Loop through all of the specified capture sources. If an interface was specified, this will only loop once and the
     * call to monitor() will block indefinitely. If capture files were specified, this will loop through each file specified
     * on the command line and monitor() will return after each file has been processed.
     */
    for(i=argc-1; i>0; i--)
    {
        /* If the source is a pcap file, get the file name from the command line */
        if(source == PCAP_FILE)
        {
            /* If we've gotten to the arguments, we're done */
            if((argv[i][0] == '-') ||
                    (last_optarg && (memcmp(argv[i], last_optarg, strlen(last_optarg)) == 0))
              )
            {
                break;
            }
            else
            {
                target = argv[i];
            }
        }
        /* Else, use the specified interface name */
        else
        {
            target = get_iface();
        }

        set_handle(capture_init(target));
        if(!get_handle())
        {
            cprintf(CRITICAL, "[X] ERROR: Failed to open '%s' for capturing\n", get_iface());
            goto end;
        }

        if(pcap_compile(get_handle(), &bpf, PACKET_FILTER, 0, 0) != 0)
        {
            cprintf(CRITICAL, "[X] ERROR: Failed to compile packet filter\n");
            goto end;
        }

        if(pcap_setfilter(get_handle(), &bpf) != 0)
        {
            cprintf(CRITICAL, "[X] ERROR: Failed to set packet filter\n");
            goto end;
        }

        /* Do it. */
        monitor(bssid, passive, source, channel, mode);
        printf("\n");
    }

    ret_val = EXIT_SUCCESS;

end:
    globule_deinit();
    sql_cleanup();
    if(bssid) free(bssid);
    if(out_file) free(out_file);
    if(wpsmon.fp) fclose(wpsmon.fp);
    return ret_val;
}
Пример #3
0
int main(int argc, char *argv[])
{
  lprec *lp = NULL;
  char *filen, *wlp = NULL, *wmps = NULL, *wfmps = NULL, plp = FALSE;
  int i;
  int verbose = IMPORTANT /* CRITICAL */;
  int debug = -1;
  MYBOOL report = FALSE;
  MYBOOL nonames = FALSE, norownames = FALSE, nocolnames = FALSE;
  MYBOOL write_model_after = FALSE;
  MYBOOL noint = FALSE;
  int print_sol = -1;
  MYBOOL print_stats = FALSE;
  int floor_first = -1;
  MYBOOL do_set_bb_depthlimit = FALSE;
  int bb_depthlimit = 0;
  MYBOOL do_set_solutionlimit = FALSE;
  int solutionlimit = 0;
  MYBOOL break_at_first = FALSE;
  int scaling = 0;
  double scaleloop = 0;
  MYBOOL tracing = FALSE;
  short filetype = filetypeLP;
  int anti_degen1 = -1;
  int anti_degen2 = -1;
  short print_timing = FALSE;
  short parse_only = FALSE;
  int do_presolve = -1;
  short objective = 0;
  short PRINT_SOLUTION = 2;
  int improve = -1;
  int pivoting1 = -1;
  int pivoting2 = -1;
  int bb_rule1 = -1;
  int bb_rule2 = -1;
  int max_num_inv = -1;
  int scalemode1 = -1;
  int scalemode2 = -1;
  int crashmode = -1;
  char *guessbasis = NULL;
  /* short timeoutok = FALSE; */
  double sectimeout = -1;
  int result;
  MYBOOL preferdual = AUTOMATIC;
  int simplextype = -1;
  MYBOOL do_set_obj_bound = FALSE;
  REAL obj_bound = 0;
  REAL mip_absgap = -1;
  REAL mip_relgap = -1;
  REAL epsperturb = -1;
  REAL epsint = -1;
  REAL epspivot = -1;
  REAL epsd = -1;
  REAL epsb = -1;
  REAL epsel = -1;
  MYBOOL do_set_break_at_value = FALSE;
  REAL break_at_value = 0;
  FILE *fpin = stdin;
  char *bfp = NULL;
  char *rxliname = NULL, *rxli = NULL, *rxlidata = NULL, *rxlioptions = NULL, *wxliname = NULL, *wxlisol = NULL, *wxli = NULL, *wxlioptions = NULL, *wxlisoloptions = NULL;
  char *rbasname = NULL, *wbasname = NULL;
  char *debugdump_before = NULL;
  char *debugdump_after = NULL;
  char *rparname = NULL;
  char *rparoptions = NULL;
  char *wparname = NULL;
  char *wparoptions = NULL;
  char obj_in_basis = -1;
  char mps_ibm = FALSE;
  char mps_negobjconst = FALSE;
  char mps_free = FALSE;
  MYBOOL ok;
# define SCALINGTHRESHOLD 0.03

  /* read command line arguments */

# if defined FORTIFY
   Fortify_EnterScope();
# endif

  for(i = 1; i < argc; i++) {
    ok = FALSE;
    if(strncmp(argv[i], "-v", 2) == 0) {
      if (argv[i][2])
        verbose = atoi(argv[i] + 2);
      else
        verbose = NORMAL;
    }
    else if(strcmp(argv[i], "-d") == 0)
      debug = TRUE;
    else if(strcmp(argv[i], "-R") == 0)
      report = TRUE;
    else if(strcmp(argv[i], "-i") == 0)
      print_sol = TRUE;
    else if(strcmp(argv[i], "-ia") == 0)
      print_sol = AUTOMATIC;
    else if(strcmp(argv[i], "-stat") == 0)
      print_stats = TRUE;
    else if(strcmp(argv[i], "-nonames") == 0)
      nonames = TRUE;
    else if(strcmp(argv[i], "-norownames") == 0)
      norownames = TRUE;
    else if(strcmp(argv[i], "-nocolnames") == 0)
      nocolnames = TRUE;
    else if((strcmp(argv[i], "-c") == 0) || (strcmp(argv[i], "-cc") == 0))
      floor_first = BRANCH_CEILING;
    else if(strcmp(argv[i], "-cf") == 0)
      floor_first = BRANCH_FLOOR;
    else if(strcmp(argv[i], "-ca") == 0)
      floor_first = BRANCH_AUTOMATIC;
    else if((strcmp(argv[i], "-depth") == 0) && (i + 1 < argc)) {
      do_set_bb_depthlimit = TRUE;
      bb_depthlimit = atoi(argv[++i]);
    }
    else if(strcmp(argv[i], "-Bw") == 0)
      or_value(&bb_rule2, NODE_WEIGHTREVERSEMODE);
    else if(strcmp(argv[i], "-Bb") == 0)
      or_value(&bb_rule2, NODE_BRANCHREVERSEMODE);
    else if(strcmp(argv[i], "-Bg") == 0)
      or_value(&bb_rule2, NODE_GREEDYMODE);
    else if(strcmp(argv[i], "-Bp") == 0)
      or_value(&bb_rule2, NODE_PSEUDOCOSTMODE);
    else if(strcmp(argv[i], "-BR") == 0)
      or_value(&bb_rule2, NODE_PSEUDORATIOSELECT);
    else if(strcmp(argv[i], "-Bf") == 0)
      or_value(&bb_rule2, NODE_DEPTHFIRSTMODE);
    else if(strcmp(argv[i], "-Br") == 0)
      or_value(&bb_rule2, NODE_RANDOMIZEMODE);
    else if(strcmp(argv[i], "-BG") == 0)
      or_value(&bb_rule2, 0 /* NODE_GUBMODE */); /* doesn't work yet */
    else if(strcmp(argv[i], "-Bd") == 0)
      or_value(&bb_rule2, NODE_DYNAMICMODE);
    else if(strcmp(argv[i], "-Bs") == 0)
      or_value(&bb_rule2, NODE_RESTARTMODE);
    else if(strcmp(argv[i], "-BB") == 0)
      or_value(&bb_rule2, NODE_BREADTHFIRSTMODE);
    else if(strcmp(argv[i], "-Bo") == 0)
      or_value(&bb_rule2, NODE_AUTOORDER);
    else if(strcmp(argv[i], "-Bc") == 0)
      or_value(&bb_rule2, NODE_RCOSTFIXING);
    else if(strcmp(argv[i], "-Bi") == 0)
      or_value(&bb_rule2, NODE_STRONGINIT);
    else if(strncmp(argv[i], "-B", 2) == 0) {
      if (argv[i][2])
        set_value(&bb_rule1, atoi(argv[i] + 2));
      else
        set_value(&bb_rule1, NODE_FIRSTSELECT);
    }
    else if((strcmp(argv[i], "-n") == 0) && (i + 1 < argc)) {
      do_set_solutionlimit = TRUE;
      solutionlimit = atoi(argv[++i]);
    }
    else if((strcmp(argv[i], "-b") == 0) && (i + 1 < argc)) {
      obj_bound = atof(argv[++i]);
      do_set_obj_bound = TRUE;
    }
    else if(((strcmp(argv[i], "-g") == 0) || (strcmp(argv[i], "-ga") == 0)) && (i + 1 < argc))
      mip_absgap = atof(argv[++i]);
    else if((strcmp(argv[i], "-gr") == 0) && (i + 1 < argc))
      mip_relgap = atof(argv[++i]);
    else if((strcmp(argv[i], "-e") == 0) && (i + 1 < argc)) {
      epsint = atof(argv[++i]);
      if((epsint <= 0.0) || (epsint >= 0.5)) {
        fprintf(stderr, "Invalid tolerance %g; 0 < epsilon < 0.5\n",
                (double)epsint);
        EndOfPgr(FORCED_EXIT);
      }
    }
    else if((strcmp(argv[i], "-r") == 0) && (i + 1 < argc))
      max_num_inv = atoi(argv[++i]);
    else if((strcmp(argv[i], "-o") == 0) && (i + 1 < argc)) {
      break_at_value = atof(argv[++i]);
      do_set_break_at_value = TRUE;
    }
    else if(strcmp(argv[i], "-f") == 0)
      break_at_first = TRUE;
    else if(strcmp(argv[i], "-timeoutok") == 0)
      /* timeoutok = TRUE */; /* option no longer needed, but still accepted */
    else if(strcmp(argv[i], "-h") == 0) {
      print_help(argv);
      EndOfPgr(EXIT_SUCCESS);
    }
    else if(strcmp(argv[i], "-prim") == 0)
      preferdual = FALSE;
    else if(strcmp(argv[i], "-dual") == 0)
      preferdual = TRUE;
    else if(strcmp(argv[i], "-simplexpp") == 0)
      simplextype = SIMPLEX_PRIMAL_PRIMAL;
    else if(strcmp(argv[i], "-simplexdp") == 0)
      simplextype = SIMPLEX_DUAL_PRIMAL;
    else if(strcmp(argv[i], "-simplexpd") == 0)
      simplextype = SIMPLEX_PRIMAL_DUAL;
    else if(strcmp(argv[i], "-simplexdd") == 0)
      simplextype = SIMPLEX_DUAL_DUAL;
    else if(strcmp(argv[i], "-sp") == 0)
      or_value(&scalemode2, SCALE_POWER2);
    else if(strcmp(argv[i], "-si") == 0)
      or_value(&scalemode2, SCALE_INTEGERS);
    else if(strcmp(argv[i], "-se") == 0)
      or_value(&scalemode2, SCALE_EQUILIBRATE);
    else if(strncmp(argv[i], "-s", 2) == 0) {
      set_value(&scalemode1, SCALE_NONE);
      scaling = SCALE_MEAN;
      if (argv[i][2]) {
        switch (atoi(argv[i] + 2)) {
        case 0:
          scaling = SCALE_NONE;
          break;
        case 1:
          set_value(&scalemode1, SCALE_GEOMETRIC);
          break;
        case 2:
          set_value(&scalemode1, SCALE_CURTISREID);
          break;
        case 3:
          set_value(&scalemode1, SCALE_EXTREME);
          break;
        case 4:
          set_value(&scalemode1, SCALE_MEAN);
          break;
        case 5:
          set_value(&scalemode1, SCALE_MEAN | SCALE_LOGARITHMIC);
          break;
        case 6:
          set_value(&scalemode1, SCALE_RANGE);
          break;
        case 7:
          set_value(&scalemode1, SCALE_MEAN | SCALE_QUADRATIC);
          break;
        }
      }
      else
        set_value(&scalemode1, SCALE_MEAN);
      if((i + 1 < argc) && (isNum(argv[i + 1])))
        scaleloop = atoi(argv[++i]);
    }
    else if(strncmp(argv[i], "-C", 2) == 0)
      crashmode = atoi(argv[i] + 2);
    else if((strcmp(argv[i],"-gbas") == 0) && (i + 1 < argc))
      guessbasis = argv[++i];
    else if(strcmp(argv[i], "-t") == 0)
      tracing = TRUE;
    else if(strncmp(argv[i], "-S", 2) == 0) {
      if (argv[i][2])
        PRINT_SOLUTION = (short) atoi(argv[i] + 2);
      else
        PRINT_SOLUTION = 2;
    }
    else if(strncmp(argv[i], "-improve", 8) == 0) {
      if (argv[i][8])
        or_value(&improve, atoi(argv[i] + 8));
    }
    else if(strcmp(argv[i], "-pivll") == 0)
      or_value(&pivoting2, PRICE_LOOPLEFT);
    else if(strcmp(argv[i], "-pivla") == 0)
      or_value(&pivoting2, PRICE_LOOPALTERNATE);
#if defined EnablePartialOptimization
    else if(strcmp(argv[i], "-pivpc") == 0)
      or_value(&pivoting2, PRICE_AUTOPARTIALCOLS);
    else if(strcmp(argv[i], "-pivpr") == 0)
      or_value(&pivoting2, PRICE_AUTOPARTIALROWS);
    else if(strcmp(argv[i], "-pivp") == 0)
      or_value(&pivoting2, PRICE_AUTOPARTIAL);
#endif
    else if(strcmp(argv[i], "-pivf") == 0)
      or_value(&pivoting2, PRICE_PRIMALFALLBACK);
    else if(strcmp(argv[i], "-pivm") == 0)
      or_value(&pivoting2, PRICE_MULTIPLE);
    else if(strcmp(argv[i], "-piva") == 0)
      or_value(&pivoting2, PRICE_ADAPTIVE);
    else if(strcmp(argv[i], "-pivr") == 0)
      or_value(&pivoting2, PRICE_RANDOMIZE);
    else if(strcmp(argv[i], "-pivh") == 0)
      or_value(&pivoting2, PRICE_HARRISTWOPASS);
    else if(strcmp(argv[i], "-pivt") == 0)
      or_value(&pivoting2, PRICE_TRUENORMINIT);
    else if(strncmp(argv[i], "-piv", 4) == 0) {
      if (argv[i][4])
        set_value(&pivoting1, atoi(argv[i] + 4));
      else
    set_value(&pivoting1, PRICER_DEVEX | PRICE_ADAPTIVE);
    }
#if defined PARSER_LP
    else if(strcmp(argv[i],"-lp") == 0)
      filetype = filetypeLP;
#endif
    else if((strcmp(argv[i],"-wlp") == 0) && (i + 1 < argc))
      wlp = argv[++i];
    else if(strcmp(argv[i],"-plp") == 0)
      plp = TRUE;
    else if(strcmp(argv[i],"-mps") == 0)
      filetype = filetypeMPS;
    else if(strcmp(argv[i],"-mps_ibm") == 0)
      mps_ibm = TRUE;
    else if(strcmp(argv[i],"-mps_negobjconst") == 0)
      mps_negobjconst = TRUE;
    else if(strcmp(argv[i],"-mps_free") == 0)
      mps_free = TRUE;
    else if(strcmp(argv[i],"-fmps") == 0)
      filetype = filetypeFREEMPS;
    else if((strcmp(argv[i],"-wmps") == 0) && (i + 1 < argc))
      wmps = argv[++i];
    else if((strcmp(argv[i],"-wfmps") == 0) && (i + 1 < argc))
      wfmps = argv[++i];
    else if(strcmp(argv[i],"-wafter") == 0)
      write_model_after = TRUE;
    else if(strcmp(argv[i],"-degen") == 0)
      set_value(&anti_degen1, ANTIDEGEN_DEFAULT);
    else if(strcmp(argv[i],"-degenf") == 0)
      or_value(&anti_degen2, ANTIDEGEN_FIXEDVARS);
    else if(strcmp(argv[i],"-degenc") == 0)
      or_value(&anti_degen2, ANTIDEGEN_COLUMNCHECK);
    else if(strcmp(argv[i],"-degens") == 0)
      or_value(&anti_degen2, ANTIDEGEN_STALLING);
    else if(strcmp(argv[i],"-degenn") == 0)
      or_value(&anti_degen2, ANTIDEGEN_NUMFAILURE);
    else if(strcmp(argv[i],"-degenl") == 0)
      or_value(&anti_degen2, ANTIDEGEN_LOSTFEAS);
    else if(strcmp(argv[i],"-degeni") == 0)
      or_value(&anti_degen2, ANTIDEGEN_INFEASIBLE);
    else if(strcmp(argv[i],"-degend") == 0)
      or_value(&anti_degen2, ANTIDEGEN_DYNAMIC);
    else if(strcmp(argv[i],"-degenb") == 0)
      or_value(&anti_degen2, ANTIDEGEN_DURINGBB);
    else if(strcmp(argv[i],"-degenr") == 0)
      or_value(&anti_degen2, ANTIDEGEN_RHSPERTURB);
    else if(strcmp(argv[i],"-degenp") == 0)
      or_value(&anti_degen2, ANTIDEGEN_BOUNDFLIP);
    else if(strcmp(argv[i],"-time") == 0) {
      if(clock() == -1)
        fprintf(stderr, "CPU times not available on this machine\n");
      else
        print_timing = TRUE;
    }
    else if((strcmp(argv[i],"-bfp") == 0) && (i + 1 < argc))
      bfp = argv[++i];
    else if((strcmp(argv[i],"-rxli") == 0) && (i + 2 < argc)) {
      rxliname = argv[++i];
      rxli = argv[++i];
      fpin = NULL;
      filetype = filetypeXLI;
    }
    else if((strcmp(argv[i],"-rxlidata") == 0) && (i + 1 < argc))
      rxlidata = argv[++i];
    else if((strcmp(argv[i],"-rxliopt") == 0) && (i + 1 < argc))
      rxlioptions = argv[++i];
    else if((strcmp(argv[i],"-wxli") == 0) && (i + 2 < argc)) {
      wxliname = argv[++i];
      wxli = argv[++i];
    }
    else if((strcmp(argv[i],"-wxliopt") == 0) && (i + 1 < argc))
      wxlioptions = argv[++i];
    else if((strcmp(argv[i],"-wxlisol") == 0) && (i + 2 < argc)) {
      wxliname = argv[++i];
      wxlisol = argv[++i];
    }
    else if((strcmp(argv[i],"-wxlisolopt") == 0) && (i + 1 < argc))
      wxlisoloptions = argv[++i];
    else if((strcmp(argv[i],"-rbas") == 0) && (i + 1 < argc))
      rbasname = argv[++i];
    else if((strcmp(argv[i],"-wbas") == 0) && (i + 1 < argc))
      wbasname = argv[++i];
    else if((strcmp(argv[i],"-Db") == 0) && (i + 1 < argc))
      debugdump_before = argv[++i];
    else if((strcmp(argv[i],"-Da") == 0) && (i + 1 < argc))
      debugdump_after = argv[++i];
    else if((strcmp(argv[i],"-timeout") == 0) && (i + 1 < argc))
      sectimeout = atof(argv[++i]);
    else if((strcmp(argv[i],"-trej") == 0) && (i + 1 < argc))
      epspivot = atof(argv[++i]);
    else if((strcmp(argv[i],"-epsp") == 0) && (i + 1 < argc))
      epsperturb = atof(argv[++i]);
    else if((strcmp(argv[i],"-epsd") == 0) && (i + 1 < argc))
      epsd = atof(argv[++i]);
    else if((strcmp(argv[i],"-epsb") == 0) && (i + 1 < argc))
      epsb = atof(argv[++i]);
    else if((strcmp(argv[i],"-epsel") == 0) && (i + 1 < argc))
      epsel = atof(argv[++i]);
    else if(strcmp(argv[i],"-parse_only") == 0)
      parse_only = TRUE;
    else
      ok = TRUE;

    if(!ok)
      ;
    else if(strcmp(argv[i],"-presolverow") == 0)
      or_value(&do_presolve, PRESOLVE_ROWS);
    else if(strcmp(argv[i],"-presolvecol") == 0)
      or_value(&do_presolve, PRESOLVE_COLS);
    else if(strcmp(argv[i],"-presolve") == 0)
      or_value(&do_presolve, PRESOLVE_ROWS | PRESOLVE_COLS);
    else if(strcmp(argv[i],"-presolvel") == 0)
      or_value(&do_presolve, PRESOLVE_LINDEP);
    else if(strcmp(argv[i],"-presolves") == 0)
      or_value(&do_presolve, PRESOLVE_SOS);
    else if(strcmp(argv[i],"-presolver") == 0)
      or_value(&do_presolve, PRESOLVE_REDUCEMIP);
    else if(strcmp(argv[i],"-presolvek") == 0)
      or_value(&do_presolve, PRESOLVE_KNAPSACK);
    else if(strcmp(argv[i],"-presolveq") == 0)
      or_value(&do_presolve, PRESOLVE_ELIMEQ2);
    else if(strcmp(argv[i],"-presolvem") == 0)
      or_value(&do_presolve, PRESOLVE_MERGEROWS);
    else if(strcmp(argv[i],"-presolvefd") == 0)
      or_value(&do_presolve, PRESOLVE_COLFIXDUAL);
    else if(strcmp(argv[i],"-presolvebnd") == 0)
      or_value(&do_presolve, PRESOLVE_BOUNDS);
    else if(strcmp(argv[i],"-presolved") == 0)
      or_value(&do_presolve, PRESOLVE_DUALS);
    else if(strcmp(argv[i],"-presolvef") == 0)
      or_value(&do_presolve, PRESOLVE_IMPLIEDFREE);
    else if(strcmp(argv[i],"-presolveslk") == 0)
      or_value(&do_presolve, PRESOLVE_IMPLIEDSLK);
    else if(strcmp(argv[i],"-presolveg") == 0)
      or_value(&do_presolve, PRESOLVE_REDUCEGCD);
    else if(strcmp(argv[i],"-presolveb") == 0)
      or_value(&do_presolve, PRESOLVE_PROBEFIX);
    else if(strcmp(argv[i],"-presolvec") == 0)
      or_value(&do_presolve, PRESOLVE_PROBEREDUCE);
    else if(strcmp(argv[i],"-presolverowd") == 0)
      or_value(&do_presolve, PRESOLVE_ROWDOMINATE);
    else if(strcmp(argv[i],"-presolvecold") == 0)
      or_value(&do_presolve, PRESOLVE_COLDOMINATE);
    else if(strcmp(argv[i],"-min") == 0)
      objective = -1;
    else if(strcmp(argv[i],"-max") == 0)
      objective =  1;
    else if(strcmp(argv[i],"-noint") == 0)
      noint =  TRUE;
    else if((strcmp(argv[i],"-rpar") == 0) && (i + 1 < argc))
      i++;
    else if((strcmp(argv[i],"-rparopt") == 0) && (i + 1 < argc))
      i++;
    else if((strcmp(argv[i],"-wpar") == 0) && (i + 1 < argc))
      i++;
    else if((strcmp(argv[i],"-wparopt") == 0) && (i + 1 < argc))
      i++;
    else if(strcmp(argv[i],"-o0") == 0)
      obj_in_basis = FALSE;
    else if(strcmp(argv[i],"-o1") == 0)
      obj_in_basis = TRUE;
    else if(fpin == stdin) {
      filen = argv[i];
      if(*filen == '<')
        filen++;
      if((fpin = fopen(filen, "r")) == NULL) {
        print_help(argv);
        fprintf(stderr,"\nError, Unable to open input file '%s'\n",
                argv[i]);
        EndOfPgr(FORCED_EXIT);
      }
    }
    else {
      filen = argv[i];
      if(*filen != '>') {
        print_help(argv);
        fprintf(stderr, "\nError, Unrecognized command line argument '%s'\n",
                argv[i]);
        EndOfPgr(FORCED_EXIT);
      }
    }
  }

  signal(SIGABRT,/* (void (*) OF((int))) */ SIGABRT_func);

  if ((filetype != filetypeXLI) && (fpin == NULL)) {
    lp = NULL;
    fprintf(stderr, "Cannot combine -rxli option with -lp, -mps, -fmps.\n");
  }
  else {
    switch(filetype) {
  #if defined PARSER_LP
    case filetypeLP:
      lp = read_lp(fpin, verbose, NULL);
      break;
  #endif
    case filetypeMPS:
      lp = read_mps(fpin, verbose | (mps_free ? MPS_FREE : 0) | (mps_ibm ? MPS_IBM : 0) | (mps_negobjconst ? MPS_NEGOBJCONST : 0));
      break;
    case filetypeFREEMPS:
      lp = read_freemps(fpin, verbose | (mps_ibm ? MPS_IBM : 0) | (mps_negobjconst ? MPS_NEGOBJCONST : 0));
      break;
    case filetypeXLI:
      lp = read_XLI(rxliname, rxli, rxlidata, rxlioptions, verbose);
      break;
    }
  }

  if((fpin != NULL) && (fpin != stdin))
    fclose(fpin);

  if(print_timing)
    print_cpu_times("Parsing input");

  if(lp == NULL) {
    fprintf(stderr, "Unable to read model.\n");
    EndOfPgr(FORCED_EXIT);
  }

  for(i = 1; i < argc; i++) {
    if((strcmp(argv[i],"-rpar") == 0) && (i + 1 < argc)) {
      if(rparname != NULL) {
        if(!read_params(lp, rparname, rparoptions)) {
          fprintf(stderr, "Unable to read parameter file (%s)\n", rparname);
          delete_lp(lp);
          EndOfPgr(FORCED_EXIT);
        }
      }
      rparname = argv[++i];
    }
    else if((strcmp(argv[i],"-rparopt") == 0) && (i + 1 < argc))
      rparoptions = argv[++i];
    else if((strcmp(argv[i],"-wpar") == 0) && (i + 1 < argc))
      wparname = argv[++i];
    else if((strcmp(argv[i],"-wparopt") == 0) && (i + 1 < argc))
      wparoptions = argv[++i];
  }

  if(rparname != NULL)
    if(!read_params(lp, rparname, rparoptions)) {
      fprintf(stderr, "Unable to read parameter file (%s)\n", rparname);
      delete_lp(lp);
      EndOfPgr(FORCED_EXIT);
    }

  if((nonames) || (nocolnames))
    set_use_names(lp, FALSE, FALSE);
  if((nonames) || (norownames))
    set_use_names(lp, TRUE, FALSE);

  if(objective != 0) {
    if(objective == 1)
      set_maxim(lp);
    else
      set_minim(lp);
  }

  if (obj_in_basis != -1)
    set_obj_in_basis(lp, obj_in_basis);

  if(noint) { /* remove integer conditions */
    for(i = get_Ncolumns(lp); i >= 1; i--) {
      if(is_SOS_var(lp, i)) {
        fprintf(stderr, "Unable to remove integer conditions because there is at least one SOS constraint\n");
        delete_lp(lp);
        EndOfPgr(FORCED_EXIT);
      }
      set_semicont(lp, i, FALSE);
      set_int(lp, i, FALSE);
    }
  }

  if(!write_model_after)
    write_model(lp, plp, wlp, wmps, wfmps, wxli, NULL, wxliname, wxlioptions);

  if(print_stats)
    print_statistics(lp);

  if(parse_only) {
    if(!write_model_after) {
      delete_lp(lp);
      EndOfPgr(0);
    }
    /* else if(!sectimeout) */
      sectimeout = 1;
  }

  if(PRINT_SOLUTION >= 5)
    print_lp(lp);

#if 0
  put_abortfunc(lp,(abortfunc *) myabortfunc, NULL);
#endif

  if(sectimeout > 0.)
    set_timeout(lp, sectimeout);
  if(print_sol >= 0)
    set_print_sol(lp, print_sol);
  if(epsint >= 0)
    set_epsint(lp, epsint);
  if(epspivot >= 0)
    set_epspivot(lp, epspivot);
  if(epsperturb >= 0)
    set_epsperturb(lp, epsperturb);
  if(epsd >= 0)
    set_epsd(lp, epsd);
  if(epsb >= 0)
    set_epsb(lp, epsb);
  if(epsel >= 0)
    set_epsel(lp, epsel);
  if(debug >= 0)
    set_debug(lp, (MYBOOL) debug);
  if(floor_first != -1)
    set_bb_floorfirst(lp, floor_first);
  if(do_set_bb_depthlimit)
    set_bb_depthlimit(lp, bb_depthlimit);
  if(do_set_solutionlimit)
    set_solutionlimit(lp, solutionlimit);
  if(tracing)
    set_trace(lp, tracing);
  if(do_set_obj_bound)
    set_obj_bound(lp, obj_bound);
  if(do_set_break_at_value)
    set_break_at_value(lp, break_at_value);
  if(break_at_first)
    set_break_at_first(lp, break_at_first);
  if(mip_absgap >= 0)
    set_mip_gap(lp, TRUE, mip_absgap);
  if(mip_relgap >= 0)
    set_mip_gap(lp, FALSE, mip_relgap);
  if((anti_degen1 != -1) || (anti_degen2 != -1)) {
    if((anti_degen1 == -1) || (anti_degen2 != -1))
      anti_degen1 = 0;
    if(anti_degen2 == -1)
      anti_degen2 = 0;
    set_anti_degen(lp, anti_degen1 | anti_degen2);
  }
  set_presolve(lp, ((do_presolve == -1) ? get_presolve(lp): do_presolve) | ((PRINT_SOLUTION >= 4) ? PRESOLVE_SENSDUALS : 0), get_presolveloops(lp));
  if(improve != -1)
    set_improve(lp, improve);
  if(max_num_inv >= 0)
    set_maxpivot(lp, max_num_inv);
  if(preferdual != AUTOMATIC)
    set_preferdual(lp, preferdual);
  if((pivoting1 != -1) || (pivoting2 != -1)) {
    if(pivoting1 == -1)
      pivoting1 = get_pivoting(lp) & PRICER_LASTOPTION;
    if(pivoting2 == -1)
      pivoting2 = 0;
    set_pivoting(lp, pivoting1 | pivoting2);
  }
  if((scalemode1 != -1) || (scalemode2 != -1)) {
    if(scalemode1 == -1)
      scalemode1 = get_scaling(lp) & SCALE_CURTISREID;
    if(scalemode2 == -1)
      scalemode2 = 0;
    set_scaling(lp, scalemode1 | scalemode2);
  }
  if(crashmode != -1)
    set_basiscrash(lp, crashmode);
  if((bb_rule1 != -1) || (bb_rule2 != -1)) {
    if(bb_rule1 == -1)
      bb_rule1 = get_bb_rule(lp) & NODE_USERSELECT;
    if(bb_rule2 == -1)
      bb_rule2 = 0;
    set_bb_rule(lp, bb_rule1 | bb_rule2);
  }
  if(simplextype != -1)
    set_simplextype(lp, simplextype);
  if(bfp != NULL)
    if(!set_BFP(lp, bfp)) {
      fprintf(stderr, "Unable to set BFP package.\n");
      delete_lp(lp);
      EndOfPgr(FORCED_EXIT);
    }
  if(debugdump_before != NULL)
    print_debugdump(lp, debugdump_before);
  if(report)
    put_msgfunc(lp, LPMessageCB, NULL, MSG_LPFEASIBLE | MSG_LPOPTIMAL | MSG_MILPFEASIBLE | MSG_MILPBETTER | MSG_PERFORMANCE);

  if(scaling) {
    if(scaleloop <= 0)
      scaleloop = 5;
    if(scaleloop - (int) scaleloop < SCALINGTHRESHOLD)
      scaleloop = (int) scaleloop + SCALINGTHRESHOLD;
    set_scalelimit(lp, scaleloop);
  }

  if(guessbasis != NULL) {
    REAL *guessvector, a;
    int *basisvector;
    int Nrows = get_Nrows(lp);
    int Ncolumns = get_Ncolumns(lp);
    int col;
    char buf[50], *ptr;
    FILE *fp;

    if ((fp = fopen(guessbasis, "r")) != NULL) {
      guessvector = (REAL *) calloc(1+Ncolumns, sizeof(*guessvector));
      basisvector = (int *) malloc((1+Nrows+Ncolumns)*sizeof(*basisvector));
      if ((guessvector != NULL) && (basisvector != NULL)) {
        while ((!feof(fp)) && (fgets(buf, sizeof(buf), fp) != NULL)) {
          ptr = strrchr(buf, ':');
          if (ptr == NULL) {
            printf("Mallformed line: %s\n", buf);
          }
          else {
            a = atof(ptr + 1);
            while ((ptr > buf) && (isspace(ptr[-1])))
              ptr--;
            *ptr = 0;
            col = get_nameindex(lp, buf, FALSE);
            if (col < 1)
              printf("guess_basis: Unknown variable name %s\n", buf);
            else
              guessvector[col] = a;
          }
        }
        if (guess_basis(lp, guessvector, basisvector)) {
          if (!set_basis(lp, basisvector, TRUE))
            printf("Unable to set guessed basis.\n");
        }
        else
          printf("Unable to guess basis from provided variables.\n");
      }
      else
        printf("guess_basis: Out of memory.\n");
      if (basisvector != NULL)
        free(basisvector);
      if (guessvector != NULL)
        free(guessvector);
      fclose(fp);
    }
    else
      printf("Unable to open file %s\n", guessbasis);
  }

  if(rbasname != NULL)
    if(!read_basis(lp, rbasname, NULL)) {
      fprintf(stderr, "Unable to read basis file.\n");
      delete_lp(lp);
      EndOfPgr(FORCED_EXIT);
    }

  result = solve(lp);

  if(wbasname != NULL)
    if(!write_basis(lp, wbasname))
      fprintf(stderr, "Unable to write basis file.\n");

  if(write_model_after)
    write_model(lp, plp, wlp, wmps, wfmps, wxli, NULL, wxliname, wxlioptions);

  write_model(lp, FALSE, NULL, NULL, NULL, NULL, wxlisol, wxliname, wxlisoloptions);

  if(PRINT_SOLUTION >= 6)
    print_scales(lp);

  if((print_timing) && (!parse_only))
    print_cpu_times("solving");

  if(debugdump_after != NULL)
    print_debugdump(lp, debugdump_after);

  if(wparname != NULL)
    if(!write_params(lp, wparname, wparoptions)) {
      fprintf(stderr, "Unable to write parameter file (%s)\n", wparname);
      delete_lp(lp);
      EndOfPgr(FORCED_EXIT);
    }

  if(parse_only) {
    delete_lp(lp);
    EndOfPgr(0);
  }

/*
  if((timeoutok) && (result == TIMEOUT) && (get_solutioncount(lp) > 0))
    result = OPTIMAL;
*/

  switch(result) {
  case SUBOPTIMAL:
  case PRESOLVED:
  case OPTIMAL:
  case PROCBREAK:
  case FEASFOUND:
    if ((result == SUBOPTIMAL) && (PRINT_SOLUTION >= 1))
      printf("Suboptimal solution\n");

    if (result == PRESOLVED)
      printf("Presolved solution\n");

    if (PRINT_SOLUTION >= 1)
      print_objective(lp);

    if (PRINT_SOLUTION >= 2)
      print_solution(lp, 1);

    if (PRINT_SOLUTION >= 3)
      print_constraints(lp, 1);

    if (PRINT_SOLUTION >= 4)
      print_duals(lp);

    if(tracing)
      fprintf(stderr,
              "Branch & Bound depth: %d\nNodes processed: %.0f\nSimplex pivots: %.0f\nNumber of equal solutions: %d\n",
              get_max_level(lp), (REAL) get_total_nodes(lp), (REAL) get_total_iter(lp), get_solutioncount(lp));
    break;
  case NOMEMORY:
    if (PRINT_SOLUTION >= 1)
      printf("Out of memory\n");
    break;
  case INFEASIBLE:
    if (PRINT_SOLUTION >= 1)
      printf("This problem is infeasible\n");
    break;
  case UNBOUNDED:
    if (PRINT_SOLUTION >= 1)
      printf("This problem is unbounded\n");
    break;
  case PROCFAIL:
   if (PRINT_SOLUTION >= 1)
      printf("The B&B routine failed\n");
    break;
  case TIMEOUT:
    if (PRINT_SOLUTION >= 1)
      printf("Timeout\n");
    break;
  case USERABORT:
    if (PRINT_SOLUTION >= 1)
      printf("User aborted\n");
    break;
  default:
    if (PRINT_SOLUTION >= 1)
      printf("lp_solve failed\n");
    break;
  }

  if (PRINT_SOLUTION >= 7)
    print_tableau(lp);

  delete_lp(lp);

  EndOfPgr(result);
  return(result);
}
Пример #4
0
dag_network::dag_network(dagid_t n_dagid, rpl_debug *deb)
{
    set_dagid(n_dagid);
    init_dag();
    set_debug(deb);
}
Пример #5
0
Файл: init.c Проект: caius/fio
int parse_cmd_line(int argc, char *argv[])
{
	struct thread_data *td = NULL;
	int c, ini_idx = 0, lidx, ret = 0, do_exit = 0, exit_val = 0;
	char *ostr = cmd_optstr;
	void *pid_file = NULL;
	void *cur_client = NULL;
	int backend = 0;

	/*
	 * Reset optind handling, since we may call this multiple times
	 * for the backend.
	 */
	optind = 1;

	while ((c = getopt_long_only(argc, argv, ostr, l_opts, &lidx)) != -1) {
		did_arg = 1;

		if ((c & FIO_CLIENT_FLAG) || client_flag_set(c)) {
			parse_cmd_client(cur_client, argv[optind - 1]);
			c &= ~FIO_CLIENT_FLAG;
		}

		switch (c) {
		case 'a':
			smalloc_pool_size = atoi(optarg);
			break;
		case 't':
			def_timeout = atoi(optarg);
			break;
		case 'l':
			write_lat_log = 1;
			break;
		case 'b':
			write_bw_log = 1;
			break;
		case 'o':
			f_out = fopen(optarg, "w+");
			if (!f_out) {
				perror("fopen output");
				exit(1);
			}
			f_err = f_out;
			break;
		case 'm':
			terse_output = 1;
			break;
		case 'h':
			if (!cur_client) {
				usage(argv[0]);
				do_exit++;
			}
			break;
		case 'c':
			if (!cur_client) {
				fio_show_option_help(optarg);
				do_exit++;
			}
			break;
		case 'i':
			if (!cur_client) {
				fio_show_ioengine_help(optarg);
				do_exit++;
			}
			break;
		case 's':
			dump_cmdline = 1;
			break;
		case 'r':
			read_only = 1;
			break;
		case 'v':
			if (!cur_client) {
				log_info("%s\n", fio_version_string);
				do_exit++;
			}
			break;
		case 'V':
			terse_version = atoi(optarg);
			if (!(terse_version == 2 || terse_version == 3)) {
				log_err("fio: bad terse version format\n");
				exit_val = 1;
				do_exit++;
			}
			break;
		case 'e':
			if (!strcmp("always", optarg))
				eta_print = FIO_ETA_ALWAYS;
			else if (!strcmp("never", optarg))
				eta_print = FIO_ETA_NEVER;
			break;
		case 'd':
			if (set_debug(optarg))
				do_exit++;
			break;
		case 'x': {
			size_t new_size;

			if (!strcmp(optarg, "global")) {
				log_err("fio: can't use global as only "
					"section\n");
				do_exit++;
				exit_val = 1;
				break;
			}
			new_size = (nr_job_sections + 1) * sizeof(char *);
			job_sections = realloc(job_sections, new_size);
			job_sections[nr_job_sections] = strdup(optarg);
			nr_job_sections++;
			break;
			}
		case 'p':
			exec_profile = strdup(optarg);
			break;
		case FIO_GETOPT_JOB: {
			const char *opt = l_opts[lidx].name;
			char *val = optarg;

			if (!strncmp(opt, "name", 4) && td) {
				ret = add_job(td, td->o.name ?: "fio", 0);
				if (ret)
					return 0;
				td = NULL;
			}
			if (!td) {
				int is_section = !strncmp(opt, "name", 4);
				int global = 0;

				if (!is_section || !strncmp(val, "global", 6))
					global = 1;

				if (is_section && skip_this_section(val))
					continue;

				td = get_new_job(global, &def_thread, 1);
				if (!td || ioengine_load(td))
					return 0;
				fio_options_set_ioengine_opts(l_opts, td);
			}

			ret = fio_cmd_option_parse(td, opt, val);

			if (!ret && !strcmp(opt, "ioengine")) {
				free_ioengine(td);
				if (ioengine_load(td))
					return 0;
				fio_options_set_ioengine_opts(l_opts, td);
			}
			break;
		}
		case FIO_GETOPT_IOENGINE: {
			const char *opt = l_opts[lidx].name;
			char *val = optarg;
			opt = l_opts[lidx].name;
			val = optarg;
			ret = fio_cmd_ioengine_option_parse(td, opt, val);
			break;
		}
		case 'w':
			warnings_fatal = 1;
			break;
		case 'j':
			max_jobs = atoi(optarg);
			if (!max_jobs || max_jobs > REAL_MAX_JOBS) {
				log_err("fio: invalid max jobs: %d\n", max_jobs);
				do_exit++;
				exit_val = 1;
			}
			break;
		case 'S':
			if (nr_clients) {
				log_err("fio: can't be both client and server\n");
				do_exit++;
				exit_val = 1;
				break;
			}
			if (optarg)
				fio_server_set_arg(optarg);
			is_backend = 1;
			backend = 1;
			break;
		case 'D':
			pid_file = strdup(optarg);
			break;
		case 'C':
			if (is_backend) {
				log_err("fio: can't be both client and server\n");
				do_exit++;
				exit_val = 1;
				break;
			}
			if (fio_client_add(optarg, &cur_client)) {
				log_err("fio: failed adding client %s\n", optarg);
				do_exit++;
				exit_val = 1;
				break;
			}
			break;
		default:
			do_exit++;
			exit_val = 1;
			break;
		}
		if (do_exit)
			break;
	}
Пример #6
0
int main(int argc, char *argv[])
{
	char buff[1024];
	size_t len;
	fd_set rfds;
	struct timeval tv;
	struct knet_host_search print_search;
	int logpipefd[2];

	if (argc < 3) {
		print_usage(argv[0]);
		exit(EXIT_FAILURE);
	}

	if (socketpair(AF_UNIX, SOCK_STREAM, IPPROTO_IP, knet_sock) != 0) {
		printf("Unable to create socket\n");
		exit(EXIT_FAILURE);
	}

	if (pipe(logpipefd)) {
		printf("Unable to create log pipe\n");
		exit(EXIT_FAILURE);
	}

	knet_h = NULL;

	if (signal(SIGINT, sigint_handler) == SIG_ERR) {
		printf("Unable to configure SIGINT handler\n");
		exit(EXIT_FAILURE);
	}

	set_debug(argc, argv);

	memset(&knet_handle_cfg, 0, sizeof(struct knet_handle_cfg));
	knet_handle_cfg.to_net_fd = knet_sock[0];
	knet_handle_cfg.node_id = 1;
	knet_handle_cfg.log_fd = logpipefd[1];
	knet_handle_cfg.default_log_level = loglevel;

	if ((knet_h = knet_handle_new(&knet_handle_cfg)) == NULL) {
		printf("Unable to create new knet_handle_t\n");
		exit(EXIT_FAILURE);
	}

	if (set_crypto(argc, argv)) {
		memset(knet_handle_crypto_cfg.private_key, 0, KNET_MAX_KEY_LEN);
		knet_handle_crypto_cfg.private_key_len = KNET_MAX_KEY_LEN;	
		if (knet_handle_crypto(knet_h, &knet_handle_crypto_cfg)) {
			printf("Unable to init crypto\n");
			exit(EXIT_FAILURE);
		}
	} else {
		printf("Crypto not activated\n");
	}

	argv_to_hosts(argc, argv);
	knet_handle_setfwd(knet_h, 1);	

	while (1) {
		ssize_t wlen;
		knet_host_foreach(knet_h, print_link, &print_search);

		printf("Sending 'Hello World!' frame\n");
		wlen = write(knet_sock[1], "Hello World!", 13);
		if (wlen != 13)
			printf("Unable to send Hello World! to socket!\n");

		tv.tv_sec = 5;
		tv.tv_usec = 0;

 select_loop:
		FD_ZERO(&rfds);
		FD_SET(knet_sock[1], &rfds);
		FD_SET(logpipefd[0], &rfds);

		len = select(FD_SETSIZE, &rfds, NULL, NULL, &tv);

		/* uncomment this to replicate the one-message problem */
		/* usleep(500000); */

		if (len < 0) {
			printf("Unable select over knet_handle_t\n");
			exit(EXIT_FAILURE);
		} else if (FD_ISSET(knet_sock[1], &rfds)) {
			len = read(knet_sock[1], buff, sizeof(buff));
			printf("Received data (%zu bytes): '%s'\n", len, buff);
		} else if (FD_ISSET(logpipefd[0], &rfds)) {
			struct knet_log_msg msg;
			size_t bytes_read = 0;

			while (bytes_read < sizeof(struct knet_log_msg)) {
				len = read(logpipefd[0], &msg + bytes_read,
					   sizeof(struct knet_log_msg) - bytes_read);
				if (len <= 0) {
					printf("Error from log fd, unable to read data\n");
					exit(EXIT_FAILURE);
				}
				bytes_read += len;
			}

			printf("[%s] %s: %s\n",
			       knet_get_loglevel_name(msg.msglevel),
			       knet_get_subsystem_name(msg.subsystem),
			       msg.msg);
		}

		if ((tv.tv_sec > 0) || (tv.tv_usec > 0))
			goto select_loop;
	}

	/* FIXME: allocated hosts should be free'd */

	return 0;
}
Пример #7
0
/* Processes Reaver command line options */
int process_arguments(int argc, char **argv)
{
	int ret_val = EXIT_SUCCESS;
	int c = 0, channel = 0;
	int long_opt_index = 0;
	char bssid[MAC_ADDR_LEN] = { 0 };
	char mac[MAC_ADDR_LEN] = { 0 };
	const char *short_options = "b:e:m:i:t:d:c:T:x:r:g:l:o:p:s:C:aA5ELfnqvDShwN";
	struct option long_options[] = {
		{ "interface", required_argument, NULL, 'i' },
		{ "bssid", required_argument, NULL, 'b' },
		{ "essid", required_argument, NULL, 'e' },
		{ "mac", required_argument, NULL, 'm' },
		{ "timeout", required_argument, NULL, 't' },
		{ "m57-timeout", required_argument, NULL, 'T' },
		{ "delay", required_argument, NULL, 'd' },
		{ "lock-delay", required_argument, NULL, 'l' },
		{ "fail-wait", required_argument, NULL, 'x' },
		{ "channel", required_argument, NULL, 'c' },
		{ "session", required_argument, NULL, 's' },
		{ "recurring-delay", required_argument, NULL, 'r' },
		{ "max-attempts", required_argument, NULL, 'g' },
		{ "out-file", required_argument, NULL, 'o' },
		{ "pin", required_argument, NULL, 'p' },
		{ "exec", required_argument, NULL, 'C' },
		{ "no-associate", no_argument, NULL, 'A' },
		{ "ignore-locks", no_argument, NULL, 'L' },
		{ "no-nacks", no_argument, NULL, 'N' },
		{ "eap-terminate", no_argument, NULL, 'E' },
		{ "dh-small", no_argument, NULL, 'S' },
		{ "auto", no_argument, NULL, 'a' },
		{ "fixed", no_argument, NULL, 'f' },
		{ "daemonize", no_argument, NULL, 'D' },
		{ "5ghz", no_argument, NULL, '5' },
		{ "nack", no_argument, NULL, 'n' },
		{ "quiet", no_argument, NULL, 'q' },
		{ "verbose", no_argument, NULL, 'v' },
		{ "win7", no_argument, NULL, 'w' },
		{ "help", no_argument, NULL, 'h' },
		{ 0, 0, 0, 0 }
	};

	/* Since this function may be called multiple times, be sure to set opt index to 0 each time */
	optind = 0;

	while((c = getopt_long(argc, argv, short_options, long_options, &long_opt_index)) != -1)
        {
                switch(c)
                {
                        case 'i':
                                set_iface(optarg);
                                break;
                        case 'b':
                                str2mac((unsigned char *) optarg, (unsigned char *) &bssid);
                                set_bssid((unsigned char *) &bssid);
                                break;
                        case 'e':
                                set_ssid(optarg);
                                break;
                        case 'm':
                                str2mac((unsigned char *) optarg, (unsigned char *) &mac);
                                set_mac((unsigned char *) &mac);
                                break;
                        case 't':
                                set_rx_timeout(atoi(optarg));
                                break;
                        case 'T':
                                set_m57_timeout(strtof(optarg, NULL) * SEC_TO_US);
                                break;
                        case 'c':
				channel = strtod(optarg, NULL);
                                set_fixed_channel(1);
                                break;
                        case '5':
                                set_wifi_band(AN_BAND);
                                break;
                        case 'd':
                                set_delay(atoi(optarg));
                                break;
                        case 'l':
                                set_lock_delay(atoi(optarg));
                                break;
			case 'p':
				parse_static_pin(optarg);
				break;
			case 's':       
				set_session(optarg);   
				break;
			case 'C':
				set_exec_string(optarg);
				break;
			case 'A':
				set_external_association(1);
				break;
                        case 'L':
                                set_ignore_locks(1);
                                break;
			case 'a':       
				set_auto_detect_options(1); 
				break;
			case 'o':
				set_log_file(fopen(optarg, "w"));
				break;
                        case 'x':
                                set_fail_delay(atoi(optarg));
                                break;
                        case 'r':
                                parse_recurring_delay(optarg);
                                break;
                        case 'g':
                                set_max_pin_attempts(atoi(optarg));
                                break;
                        case 'D':
				daemonize();
				break;
			case 'E':
                                set_eap_terminate(1);
                                break;
			case 'S':
				set_dh_small(1);
				break;
                        case 'n':
                                set_timeout_is_nack(0);
                                break;
                        case 'f':
                                set_fixed_channel(1);
                                break;
                        case 'v':
                                set_debug(get_debug() + 1);
                                break;
                        case 'q':
                                set_debug(CRITICAL);
                                break;
			case 'w':
				set_win7_compat(1);
				break;
			case 'N':
				set_oo_send_nack(0);
				break;
                        default:
                                ret_val = EXIT_FAILURE;
                }
        }

	if(channel)
	{
		change_channel(channel);
	}

	return ret_val;
}
Пример #8
0
/*********************************************************************
** module_std_init()
**
** Description:	Perform basic initialization common to ALL Arbor background
**		modules. This includes verifying calling format (correct
**		number of args), $ARBORDATA directory is accessible, etc.
**		Also, logs into *SPECIFIED* database. This is done by logging
**		into Catalog database (ARBOR_CATALOG_QUERY / ARBOR_CATALOG_
**		DATABASE) and looking up the SERVER_DEFINITION entry for the
**		given server_id.  The result is that a single connection to
**		the specified server (database) will be returned as output.
**
** NOTE:	If we are EC/Arbor, we will delay setting debug mode until
**		after counting EMFs (EC/Arbor is restricted to number of
**		active EMFs). As of this writting (24-jul-97), counting of
**		EMFs is only done for BIP (hardcoded in count_equip()).
**
** Input:	argc - from main(), # parameters supplied on cmd line
**		argv = from main(), pointers to parameters supplied on cmd line
**		module_name = e.g., "CAP", "BIP",
**		debug_flag = if true, debug SQL log file will be opened. even
**			if false, if tra_switch is found to be true, debug SQL
**			log will be opened.
** Output:	server_id - server_id supplied on command line. This is
**			server_id module is to run against, regardless of default
**			server / database.
**		arbordata - value of $ARBORDATA env variable. must be an
**			accessible directory. This function returns pointer to
**			static memory. Could be overwritten on successive calls
**			but this function should only be called once!
**		ctrl_rpt_fname - full pathname for control report (pathname and
**			filename). Caller must still open file and write ctrl rpt.
**			This function returns pointer to static memory. Could be
**			overwritten on successive calls but this function should
**			only be called once!
**		tra_switch - value of module's TRA_SWITCH (SYSTEM_PARAMETERS).
**			If true, debug SQL log file will be opened.
**		tim_switch - value of module's TIM_SWITCH (SYSTEM_PARAMETERS).
**		dbp - open database connection.
**
** Returns:	SUCCESS, or EXITS on failure.
************************************************************************
*/
int module_std_init(	int	argc,		/* input: */
			char	**argv,		/* input: */
			char	*module_name,	/* input: e.g., "CAP" */
			int	debug_flag,	/* input:  true/false: if true, turn on debugging */
			int	*server_id,	/* OUTPUT: Arbor server_id number */
			char	**arbordata,	/* OUTPUT: $ARBORDATA */
			char	**ctrl_rpt_fname,/* OUTPUT: full pathname for ctrl rpt file */
			int	*tra_switch,	/* OUTPUT: module's TRA_SWITCH, turns on debugging */
			int	*tim_switch,	/* OUTPUT: module's TIM_SWITCH, turns on debugging */
			Arb_connection	**dbp)	/* OUTPUT: connection to DB */
{
   static char	static_arbordata[szPATHNAME];
   static char	static_ctrl_rpt[szPATHNAME];

   char	*p;
   Arb_connection dbpCat, *dbpCatalog;
   ARBOR_SERVER_DEFINITION asd;

   char	char_server_id[6];	/* char representation of server_id for other lib calls */

   dbpCatalog = &dbpCat;

   if(argc < 3) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		basename(argv[0]), 0,
		"Bad Parameter list, Usage: %s process_name server_id",
		basename(argv[0]));
	exit(1);
   }
   arb_set_process_id(argv[1]);

   if((! numeric_string(argv[2])) || (strlen(argv[2]) < 1) || (strlen(argv[2]) > 3)) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), 0,
		"Bad Parameter list (Invalid server_id: %s), Usage: %s process_name server_id",
		argv[2], basename(argv[0]));
	exit(1);
   }
   *server_id = atoi(argv[2]);

   if((*server_id <= 0) || (*server_id > 99)) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"Invalid server_id: %s, Usage: %s process_name server_id",
		argv[2], basename(argv[0]));
	exit(1);
   }
   sprintf(char_server_id, "%02d", *server_id);	/* char string server_id */

   if((p = getenv("ARBORDATA")) == NULL) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: unable to get ARBORDATA env variable",
		basename(argv[0]));
	exit(1);
   }
   strcpy(static_arbordata, p);
   *arbordata = static_arbordata;

   if(access(*arbordata, R_OK + X_OK)) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: unable to access ARBORDATA directory: %s",
		basename(argv[0]), *arbordata);
	exit(1);
   }

   if(open_activity_log(arb_get_process_id(), *server_id) == FAILURE) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: Unable to open activity log file",
		basename(argv[0]));
	exit(1);
   }

   if(init_login_record(arb_get_process_id()) == FAILURE) {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: Database login record initialization failed!",
		basename(argv[0]));
	exit(1);
   }

   /* Register default database error handler before any database work
   ** gets done.
   */
   arb_set_db_err_fn(mod_default_db_err);

   /* Note this isn't the only chance. Once DB connection is open, we will
   ** look for a DEBUG parameter for the given module in SYSTEM_PARAMETERS.
   ** If there is one, that will also result in debug SQL log file being
   ** opened.
   **
   ** If we are *NOT* EC/Arbor, start debug now, if appropriate. If we *ARE*
   ** EC/Arbor, then delay setting debug mode until after counting EMFs.
   */
#ifndef ECARBOR
   if(debug_flag) {
	arb_set_db_debug_level(MEDIUM_DEBUG);
	set_debug(module_name, *server_id, argv[0]);
   }
#endif

   /* Temporarily login to Catalog db. This connection will be used
   ** for the SERVER_DEFINITION lookup to get entry for server_id from
   ** command line. This is Arbor server for process to run against.
   */
   if(arborm_login_to_catalog(ARB_STD_CONNECT, &dbpCatalog) != SUCCESS) {
	   arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: Unable to login to Catalog DB",
		basename(argv[0]));
	   exit(1);
   }

   /* Now login to proper Arbor server.
   */
   if(arborm_login_to_server_id(dbpCatalog, *server_id,
				ARB_STD_CONNECT, dbp) != SUCCESS) {
	   arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR logging into Arbor server_id %d",
		basename(argv[0]), *server_id);
	   exit(1);
   }

   /* EC/Arbor: max active EMF check. Number of EMF's for EC/Arbor is
   ** restricted (client should use full-license Arbor/BP if they need
   ** to exceed the HARDCODED EC/Arbor limit).
   */
   if(count_equip(*dbp, module_name) != SUCCESS) {
      exit(1);
   }

   /* If we are EC, we skipped start of debug mode above.
   /* In this case, start debug now, if appropriate.
   */
#ifdef ECARBOR
      if(debug_flag) {
	arb_set_db_debug_level(MEDIUM_DEBUG);
	set_debug(module_name, *server_id, argv[0]);
      }
#endif	/* ECARBOR */

   /* Get SERVER_DEFINITION info for server process is running
   ** against (i.e., one just logged into above). This is just
   ** used to reset the login record so that future login's to
   ** "default" log into the proper server.
   */
   memset(&asd, 0, sizeof(asd));
   asd.server_id = *server_id;	/* info for this server */
   if(retrieve_server_info(dbpCatalog, &asd) != SUCCESS) {
	   arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: Unable to get server info for server %d from Catalog DB",
		basename(argv[0]), *server_id);
	   exit(1);
   }

   /* Resetting login record, incase application uses it again,
   ** i.e., for future calls to arborm_login_to_default().
   ** Note that NULL args means not to change corresponding login
   ** record field.
   */
   set_login_record(asd.dsquery, asd.ds_database, NULL, NULL, NULL);

   /* We no longer need temporary Catalog DB connection, so close it.
   */
   if(arb_close(dbpCatalog, TRUE) != SUCCESS) {
	   arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR logging out of default database",
		basename(argv[0]));
	   exit(1);
   }

   initialize_message_system(module_name, *dbp);
   emit(module_name, __FILE__, __LINE__, STARTUP_MSG_MSA,
	module_name, arb_get_process_id(), char_server_id);

   /* Check msg_q & BEM status, unless we are BEM */

   /* The "ARBOR_SKIP_BEM_CHECK" unix environment variable can be
   ** used to cause module to skip the BEM alive check.  This is
   ** purposely undocumented and should only be used for unit
   ** testing and the like. Clients should NEVER become aware of
   ** this "feature".
   */
   if((p = getenv("ARBOR_SKIP_BEM_CHECK")) == NULL) {

     if(strcmp(module_name, "BEM") != 0) {

       if(msg_q_init() == FAILURE) {
	  emit(module_name, __FILE__, __LINE__, MSG_Q_INIT_ERR,
		module_name, arb_get_process_id(), errno);
	  exit(1);
       }

       if(check_bem_status(*dbp) == FAILURE) {
	  emit(module_name, __FILE__, __LINE__, BEM_NOT_RUNNING,
		module_name, arb_get_process_id());
	  exit(1);
       }
     }
   }

   /* If we get this far, dbp is connected to the proper Arbor server.
   ** Get module's TRA_SWITCH (trace / debug) and TIM_SWITCH (timing).
   ** If debug_flag not already set, and module's TRA_SWITCH is TRUE,
   ** then turn on debug SQL log. If debug_flag already set, then we've
   ** already opened debug SQL log.
   **
   ** If TIM_SWITCH was set, we will initialize the perf timer, i.e.,
   ** initialize the timing structures. We will not actually start any
   ** timers, that is up to the individual calling application.  Note
   ** that the init_perf_timer() can be safely called multiple times
   ** Thus it's okay for the calling application to also call it.
   */
   if(get_system_parameter_int(*dbp, module_name, "TRA_SWITCH", tra_switch) == FAILURE)
	*tra_switch = FALSE;

   if(get_system_parameter_int(*dbp, module_name, "TIM_SWITCH", tim_switch) == FAILURE)
	*tim_switch = FALSE;

   if(!debug_flag && *tra_switch) {
	arb_set_db_debug_level(MEDIUM_DEBUG);
	set_debug(module_name, *server_id, argv[0]);
   }

   if(*tim_switch)
   {
      if(init_perf_timer() != SUCCESS)
      {
	printf("\n\nCAP ERROR: Cannot initialize timing structures\n\n");
	exit(-1);
      }
   }

   strcpy(static_ctrl_rpt, ctrl_rpt_path(arb_get_process_id()));
   if(static_ctrl_rpt[0] == '\0') {
	arb_fatal_log_and_exit(module_name, __FILE__, __LINE__,
		arb_get_process_id(), *server_id,
		"%s ERROR: unable to determine ctrl report pathname",
		basename(argv[0]));
	exit(1);
   }
   *ctrl_rpt_fname = static_ctrl_rpt;

   return SUCCESS;
}
Пример #9
0
int do_host_autok(int id)
{
    int i, j;
    int param_count;
    int vol_count;
    //std::list<unsigned int> undo_vol_list;
    struct autok_predata predata;
    unsigned int *param_list;
    unsigned int *vol_list;
    struct autok_predata full_data;
    std::list<struct res_data*> res_list;
    std::list<struct res_data*>::iterator it_res;
    struct res_data *p_res;
    char devnode[BUF_LEN]=""; 
    char resnode[BUF_LEN]="";
    char data_node[BUF_LEN]="";
    int need_to_recover = 0;
    param_count = get_param_count();
    
    printf("Param_count:%d\n", param_count);

    if(get_nvram_param_count(id)!=param_count){
        system("rm -rf /data/autok_*");
        system("rm -rf /data/nvram/APCFG/APRDCL/SDIO");
        close_nvram();
        init_autok_nvram();
        need_to_recover = 1;
    }
    //duplicate nvram data partition
    //if(!is_nvram_mode()){
        for(i=0; i<VCORE_NO; i++){
            //char nvram_node[BUF_LEN]="";
            //snprintf(nvram_node, BUF_LEN, "%s/%s_%d_%d", AUTOK_NVRAM_PATH, RESULT_FILE_PREFIX, id, g_autok_vcore[i]);
            snprintf(data_node, BUF_LEN, "%s/%s_%d_%d", AUTOK_RES_PATH, RESULT_FILE_PREFIX, id, g_autok_vcore[i]);
            // Check environment
            // 1. nvram data partition should exist
            // 2. autok parameter in data partion should not exist
            // 3. param_count should be the same 
            if(is_nvram_data_exist(id, g_autok_vcore[i])>0 && is_file_valid(data_node)<=0){
                //data_copy(nvram_node, data_node);
                int data_length;
                char *data_buf;
                read_from_nvram(id, g_autok_vcore[i], (unsigned char**)&data_buf, &data_length);
                if(write_to_file(data_node, data_buf, data_length)<0){
                    free(data_buf);
                    return -1;
                }
                free(data_buf);
                printf("duplicata from [%s] to [%s]\n", AUTOK_NVRAM_PATH, data_node);
            }
        }
    //}
    
    
    //check autok folder
    for(i=0; i<VCORE_NO; i++){
        // [FIXME] Normal mode & factory mode should store to different path
        snprintf(resnode, BUF_LEN, "%s/%s_%d_%d", AUTOK_RES_PATH, RESULT_FILE_PREFIX, id, g_autok_vcore[i]);
        printf("1-0 done\n");
        //if(!is_nvram_mode()){
            //std::string res_str(resnode);
            p_res = (struct res_data*)malloc(sizeof(struct res_data));
            p_res->id = id;
            p_res->voltage = g_autok_vcore[i];
            strcpy(p_res->filepath, resnode);
            res_list.push_back(p_res);
        //} 
        /*else {
            snprintf(resnode, BUF_LEN, "%s/%s_%d_%d", AUTOK_RES_PATH, RESULT_FILE_PREFIX, id, g_autok_vcore[i]);
            write_file_to_nvram(resnode, id);
            
        }*/
        struct timespec tstart={0,0}, tend={0,0};
        printf("1-1 done\n");
        if(is_file_valid(resnode)<=0){
            //undo_vol_list.push_back(g_autok_vcore[i]);
            set_stage1_voltage(id, g_autok_vcore[i]);
            set_stage1_done(id, 0);
            printf("[%s] set done to 0\n", resnode);
            // prepare zero data to drive autok algorithm 
            param_list = (unsigned int*)malloc(sizeof(unsigned int)*param_count);
            for(j=0; j<param_count; j++){
                param_list[j] = 0;        
            }
            vol_count = 1;            
            vol_list = (unsigned int*)malloc(sizeof(unsigned int)*vol_count); 
            vol_list[0] = g_autok_vcore[i];                  
            pack_param(&predata, vol_list, vol_count, param_list, param_count);
            clock_gettime(CLOCK_MONOTONIC, &tstart);
            set_stage1_params(id, &predata);
            
            printf("operation col_count[%d] vcore[%d] param_count[%d]\n", vol_count, vol_list[0], param_count);     
            release_predata(&predata);
            printf("release col_count[%d] param_count[%d]\n", vol_count, param_count); 
            // Wait for autok stage1 for a specific voltage done
            // [FIXME] can switch to uevent?
            while(1){
                if(get_stage1_done(id))
                    break;
                usleep(10*1000); 
            }
            clock_gettime(CLOCK_MONOTONIC, &tend);
            printf("autok once %.5f seconds\n",((double)tend.tv_sec + 1.0e-9*tend.tv_nsec) - ((double)tstart.tv_sec + 1.0e-9*tstart.tv_nsec));
            set_debug(0);
            snprintf(devnode, BUF_LEN, "%s/%d/%s", STAGE1_DEVNODE, id, "PARAMS");
            if(!is_nvram_mode()){
                printf("[NON_NV]From dev[%s] to res[%s]\n", devnode, resnode);
                from_dev_to_data(devnode, resnode);
                // For recover different version param_count
                if(need_to_recover){
                    write_dev_to_nvram(devnode, id);
                }
            } else {
                printf("[NV]From dev[%s] to nvram\n", devnode);
                from_dev_to_data(devnode, resnode);
                write_dev_to_nvram(devnode, id);
            }
        }
        printf("1-2 done\n");
    }
    
    // Set stage2 data to apply autok parameter
    //if(!is_nvram_mode()){
        // Merge Phase
        full_data.vol_count = VCORE_NO;
        full_data.param_count = param_count;
        full_data.vol_list = (unsigned int*)malloc(sizeof(unsigned int)*VCORE_NO);
        full_data.ai_data = (U_AUTOK_INTERFACE_DATA**)malloc(sizeof(U_AUTOK_INTERFACE_DATA*)*VCORE_NO);
        i = 0;
        for(it_res=res_list.begin(); it_res!=res_list.end(); ++it_res){
            full_data.ai_data[i] = (U_AUTOK_INTERFACE_DATA*)malloc(sizeof(U_AUTOK_INTERFACE_DATA)*param_count);
            struct res_data *p_temp_res = *it_res;
            predata = get_param((char*)p_temp_res->filepath);
            full_data.vol_list[i] = p_temp_res->voltage;
            memcpy(full_data.ai_data[i], predata.ai_data[0], sizeof(U_AUTOK_INTERFACE_DATA)*param_count);
            release_predata(&predata);
            free(p_temp_res);
            i++;
        }
        printf("1-3 done\n");
        set_stage2(id, &full_data);
        release_predata(&full_data);
        printf("1-4 done\n");
    /*}else{
        set_ready(id);
    }*/
    return 0;
}
Пример #10
0
int main() {
    if (set_debug("?") != -1) {
	fprintf(stderr, "set_debug(\"?\") returned wrong result code\n");
    }
    exit(0);
}
Пример #11
0
int main(void)
{
# if defined ERROR
#  undef ERROR
# endif
# define ERROR() { fprintf(stderr, "Error\n"); exit(1); }
  lprec *lp;
  int majorversion, minorversion, release, build;

#if defined FORTIFY
  Fortify_EnterScope();
#endif

  lp_solve_version(&majorversion, &minorversion, &release, &build);
  printf("lp_solve %d.%d.%d.%d demo\n\n", majorversion, minorversion, release, build);
  printf("This demo will show most of the features of lp_solve %d.%d.%d.%d\n", majorversion, minorversion, release, build);
  press_ret();
  printf("\nWe start by creating a new problem with 4 variables and 0 constraints\n");
  printf("We use: lp=make_lp(0,4);\n");
  if ((lp=make_lp(0,4)) == NULL)
    ERROR();
  press_ret();

  printf("We can show the current problem with print_lp(lp)\n");
  print_lp(lp);
  press_ret();
  printf("Now we add some constraints\n");
  printf("str_add_constraint(lp, \"3 2 2 1\" ,LE,4)\n");
  printf("This is the string version of add_constraint. For the normal version\n");
  printf("of add_constraint see the help file\n");
  if (!str_add_constraint(lp, "3 2 2 1", LE, 4))
    ERROR();
  print_lp(lp);
  press_ret();
  printf("str_add_constraint(lp, \"0 4 3 1\" ,GE,3)\n");
  if (!str_add_constraint(lp, "0 4 3 1", GE, 3))
    ERROR();
  print_lp(lp);
  press_ret();
  printf("Set the objective function\n");
  printf("str_set_obj_fn(lp, \"2 3 -2 3\")\n");
  if (!str_set_obj_fn(lp, "2 3 -2 3"))
    ERROR();
  print_lp(lp);
  press_ret();
  printf("Now solve the problem with printf(solve(lp));\n");
  printf("%d",solve(lp));
  press_ret();
  printf("The value is 0, this means we found an optimal solution\n");
  printf("We can display this solution with print_objective(lp) and print_solution(lp)\n");
  print_objective(lp);
  print_solution(lp, 1);
  print_constraints(lp, 1);

  press_ret();
  printf("The dual variables of the solution are printed with\n");
  printf("print_duals(lp);\n");
  print_duals(lp);
  press_ret();
  printf("We can change a single element in the matrix with\n");
  printf("set_mat(lp,2,1,0.5)\n");
  if (!set_mat(lp,2,1,0.5))
    ERROR();
  print_lp(lp);
  press_ret();
  printf("If we want to maximize the objective function use set_maxim(lp);\n");
  set_maxim(lp);
  print_lp(lp);
  press_ret();
  printf("after solving this gives us:\n");
  solve(lp);
  print_objective(lp);
  print_solution(lp, 1);
  print_constraints(lp, 1);
  print_duals(lp);
  press_ret();
  printf("Change the value of a rhs element with set_rh(lp,1,7.45)\n");
  set_rh(lp,1,7.45);
  print_lp(lp);
  solve(lp);
  print_objective(lp);
  print_solution(lp, 1);
  print_constraints(lp, 1);
  press_ret();
  printf("We change %s to the integer type with\n", get_col_name(lp, 4));
  printf("set_int(lp, 4, TRUE)\n");
  set_int(lp, 4, TRUE);
  print_lp(lp);
  printf("We set branch & bound debugging on with set_debug(lp, TRUE)\n");
  set_debug(lp, TRUE);
  printf("and solve...\n");
  press_ret();
  solve(lp);
  print_objective(lp);
  print_solution(lp, 1);
  print_constraints(lp, 1);
  press_ret();
  printf("We can set bounds on the variables with\n");
  printf("set_lowbo(lp,2,2); & set_upbo(lp,4,5.3)\n");
  set_lowbo(lp,2,2);
  set_upbo(lp,4,5.3);
  print_lp(lp);
  press_ret();
  solve(lp);
  print_objective(lp);
  print_solution(lp, 1);
  print_constraints(lp, 1);
  press_ret();
  printf("Now remove a constraint with del_constraint(lp, 1)\n");
  del_constraint(lp,1);
  print_lp(lp);
  printf("Add an equality constraint\n");
  if (!str_add_constraint(lp, "1 2 1 4", EQ, 8))
    ERROR();
  print_lp(lp);
  press_ret();
  printf("A column can be added with:\n");
  printf("str_add_column(lp,\"3 2 2\");\n");
  if (!str_add_column(lp,"3 2 2"))
    ERROR();
  print_lp(lp);
  press_ret();
  printf("A column can be removed with:\n");
  printf("del_column(lp,3);\n");
  del_column(lp,3);
  print_lp(lp);
  press_ret();
  printf("We can use automatic scaling with:\n");
  printf("set_scaling(lp, SCALE_MEAN);\n");
  set_scaling(lp, SCALE_MEAN);
  print_lp(lp);
  press_ret();
  printf("The function get_mat(lprec *lp, int row, int column) returns a single\n");
  printf("matrix element\n");
  printf("%s get_mat(lp,2,3), get_mat(lp,1,1); gives\n","printf(\"%f %f\\n\",");
  printf("%f %f\n", (double)get_mat(lp,2,3), (double)get_mat(lp,1,1));
  printf("Notice that get_mat returns the value of the original unscaled problem\n");
  press_ret();
  printf("If there are any integer type variables, then only the rows are scaled\n");
  printf("set_int(lp,3,FALSE);\n");
  printf("set_scaling(lp, SCALE_MEAN);\n");
  set_scaling(lp, SCALE_MEAN);
  set_int(lp,3,FALSE);
  print_lp(lp);
  press_ret();
  solve(lp);
  printf("print_objective, print_solution gives the solution to the original problem\n");
  print_objective(lp);
  print_solution(lp, 1);
  print_constraints(lp, 1);
  press_ret();
  printf("Scaling is turned off with unscale(lp);\n");
  unscale(lp);
  print_lp(lp);
  press_ret();
  printf("Now turn B&B debugging off and simplex tracing on with\n");
  printf("set_debug(lp, FALSE), set_trace(lp, TRUE) and solve(lp)\n");
  set_debug(lp, FALSE);
  set_trace(lp, TRUE);
  press_ret();
  solve(lp);
  printf("Where possible, lp_solve will start at the last found basis\n");
  printf("We can reset the problem to the initial basis with\n");
  printf("default_basis(lp). Now solve it again...\n");
  press_ret();
  default_basis(lp);
  solve(lp);

  printf("It is possible to give variables and constraints names\n");
  printf("set_row_name(lp,1,\"speed\"); & set_col_name(lp,2,\"money\")\n");
  if (!set_row_name(lp,1,"speed"))
    ERROR();
  if (!set_col_name(lp,2,"money"))
    ERROR();
  print_lp(lp);
  printf("As you can see, all column and rows are assigned default names\n");
  printf("If a column or constraint is deleted, the names shift place also:\n");
  press_ret();
  printf("del_column(lp,1);\n");
  del_column(lp,1);
  print_lp(lp);
  press_ret();

  delete_lp(lp);

#if FALSE
  printf("A lp structure can be created and read from a .lp file\n");
  printf("lp = read_lp(\"lp_examples/demo_lag.lp\", TRUE);\n");
  printf("The verbose option is used\n");
  if ((lp = read_LP("lp_examples/demo_lag.lp", TRUE, "test")) == NULL)
    ERROR();
  press_ret();
  printf("lp is now:\n");
  print_lp(lp);

  press_ret();
  printf("solution:\n");
  set_debug(lp, TRUE);
  solve(lp);
  set_debug(lp, FALSE);
  print_objective(lp);
  print_solution(lp, 1);
  print_constraints(lp, 1);
  press_ret();
  printf("You can see that branch & bound was used in this problem\n");

  printf("Now remove the last constraint and use lagrangian relaxation\n");
  printf("del_constraint(lp,6);\n");
  printf("str_add_lag_con(lp, \"1 1 1 0 0 0\", LE, 2);\n");
  del_constraint(lp,6);
  if (!str_add_lag_con(lp, "1 1 1 0 0 0", LE, 2))
    ERROR();
  print_lp(lp);

  printf("Lagrangian relaxation is used in some heuristics. It is now possible\n");
  printf("to get a feasible integer solution without usage of branch & bound.\n");
  printf("Use lag_solve(lp, 0, 30); 0 is the initial bound, 30 the maximum\n");
  printf("number of iterations, the last variable turns the verbose mode on.\n");
  press_ret();
  set_lag_trace(lp, TRUE);
  printf("%d\n",lag_solve(lp, 0, 30));
  printf("The returncode of lag_solve is 6 or FEAS_FOUND. this means that a feasible\n");
  printf("solution has been found. For a list of other possible return values\n");
  printf("see the help file. Print this solution with print_objective, print_solution\n");
  print_objective(lp);
  print_solution(lp, 1);
  print_constraints(lp, 1);

  delete_lp(lp);

  press_ret();
#endif

#if defined FORTIFY
  Fortify_LeaveScope();
#endif

  return(0);
}