Ejemplo n.º 1
0
int
main(int argc, char *argv[])
{
    char **hostandport;
    /* check argument */
    if( argc < NUMARG ) {
        usage_get();
        fprintf(stderr, "missing URL or filename\n");
        return EXIT_FAILURE;
    }

    hostandport = gethostandport( argv[1] );


    wget( hostandport[0] ,hostandport[1], hostandport[2], argv[2]);

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char * const *argv) {
  if (argc < 2) {
    usage();
    return 0;
  }
  const char *command = argv[1];
  if (strcmp(command, "info") == 0) {
    if (argc < 3) {
      usage_info();
      return 1;
    }
    return info(argc - 2, argv + 2);
  } else if (strcmp(command, "get") == 0) {
    if (argc < 4) {
      usage_get();
      return 1;
    }
    const char *index_filename = argv[2];
    char *log_filename = sparkey_create_log_filename(index_filename);
    if (log_filename == NULL) {
      fprintf(stderr, "index filename must end with .spi\n");
      return 1;
    }
    int retval = get(argv[2], log_filename, argv[3]);
    free(log_filename);
    return retval;
  } else if (strcmp(command, "writehash") == 0) {
    if (argc < 3) {
      usage_writehash();
      return 1;
    }
    const char *log_filename = argv[2];
    char *index_filename = sparkey_create_index_filename(log_filename);
    if (index_filename == NULL) {
      fprintf(stderr, "log filename must end with .spl\n");
      return 1;
    }
    int retval = writehash(index_filename, log_filename);
    free(index_filename);
    return retval;
  } else if (strcmp(command, "createlog") == 0) {
    opterr = 0;
    optind = 2;
    int opt_char;
    int block_size = SNAPPY_DEFAULT_BLOCKSIZE;
    sparkey_compression_type compression_type = SPARKEY_COMPRESSION_NONE;
    while ((opt_char = getopt (argc, argv, "b:c:")) != -1) {
      switch (opt_char) {
      case 'b':
        if (sscanf(optarg, "%d", &block_size) != 1) {
          fprintf(stderr, "Block size must be an integer, but was '%s'\n", optarg);
          return 1;
        }
        if (block_size > SNAPPY_MAX_BLOCKSIZE || block_size < SNAPPY_MIN_BLOCKSIZE) {
          fprintf(stderr, "Block size %d, not in range. Max is %d, min is %d\n",
          block_size, SNAPPY_MAX_BLOCKSIZE, SNAPPY_MIN_BLOCKSIZE);
          return 1;
        }
        break;
      case 'c':
        if (strcmp(optarg, "none") == 0) {
          compression_type = SPARKEY_COMPRESSION_NONE;
        } else if (strcmp(optarg, "snappy") == 0) {
          compression_type = SPARKEY_COMPRESSION_SNAPPY;
        } else {
          fprintf(stderr, "Invalid compression type: '%s'\n", optarg);
          return 1;
        }
        break;
      case '?':
        if (optopt == 'b' || optopt == 'c') {
          fprintf(stderr, "Option -%c requires an argument.\n", optopt);
        } else if (isprint(optopt)) {
          fprintf(stderr, "Unknown option '-%c'.\n", optopt);
        } else {
          fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt);
        }
        return 1;
      default:
        fprintf(stderr, "Unknown option parsing failure\n");
        return 1;
      }
    }

    if (optind >= argc) {
      usage_createlog();
      return 1;
    }

    const char *log_filename = argv[optind];
    sparkey_logwriter *writer;
    assert(sparkey_logwriter_create(&writer, log_filename,
      compression_type, block_size));
    assert(sparkey_logwriter_close(&writer));
    return 0;
  } else if (strcmp(command, "appendlog") == 0) {
    opterr = 0;
    optind = 2;
    int opt_char;
    char delimiter = '\t';
    while ((opt_char = getopt (argc, argv, "d:")) != -1) {
      switch (opt_char) {
      case 'd':
        if (strlen(optarg) != 1) {
          fprintf(stderr, "delimiter must be one character, but was '%s'\n", optarg);
          return 1;
        }
        delimiter = optarg[0];
        break;
      case '?':
        if (optopt == 'd') {
          fprintf(stderr, "Option -%c requires an argument.\n", optopt);
        } else if (isprint(optopt)) {
          fprintf(stderr, "Unknown option '-%c'.\n", optopt);
        } else {
          fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt);
        }
        return 1;
      default:
        fprintf(stderr, "Unknown option parsing failure\n");
        return 1;
      }
    }

    if (optind >= argc) {
      usage_appendlog();
      return 1;
    }

    const char *log_filename = argv[optind];
    sparkey_logwriter *writer;
    assert(sparkey_logwriter_append(&writer, log_filename));
    int rc = append(writer, delimiter, stdin);
    assert(sparkey_logwriter_close(&writer));
    return rc;
  } else if (strcmp(command, "help") == 0 || strcmp(command, "--help") == 0 || strcmp(command, "-h") == 0) {
    usage();
    return 0;
  } else {
    fprintf(stderr, "Unknown command: %s\n", command);
    return 1;
  }
}