Example #1
0
int main()
{
    /* Implement your own tests here. Free feel to modify. */

    char string[] = "Test string, that is different";
    char *array[] = {"This", "is", "a", "test", "string.", NULL};
    char **arr = malloc(sizeof(char*)*6);
    
    // Save pointers for later use
    char **save = arr, **begin = arr;

    for(int i=0; i<5; i++)
        arr[i] = malloc(10);
    arr[5]=NULL;

    // Test a.
    print_strarray(array);

    // Test b.
    str_to_strarray(string, arr);
    print_strarray(arr);

    // Free array
    while(*save){
        free(*save);
        save++;
    }
    free(begin);

    return 0;
}
Example #2
0
int
main(int argc, char* argv[]) {
  stralloc dir = {0, 0, 0};
  int c;
  int digit_optind = 0;
  const char* rel_to = 0;
  int index = 0;
  static const struct longopt opts[] =
  { {"help", 0, 0, 'h'},
    {"list", 0, &opt_list, 1},
    {"numeric", 0, &opt_numeric, 1},
    {"relative", 0, &opt_relative, 1},
    {"output", 1, 0, 'o'},
    {"exclude", 1, 0, 'x'},
    {"time-style", 1, 0, 't'},
    {"dereference", 0, &opt_deref, 1},
    {"min-size", 1, 0, 'm'},
#if WINDOWS
    {"separator", 1, 0, 's'},
#endif
    {0} };

#if WINDOWS && defined(O_BINARY)
  setmode(STDOUT_FILENO, O_BINARY);
#endif

  for(;;) {
    c = getopt_long(argc, argv, "hlnro:x:t:m:", opts, &index);
    if(c == -1)
      break;
    if(c == 0)
      continue;

    switch(c) {
      case 'h': usage(argv[0]); return 0;
      case 'x': {
        char* s = optarg;
        array_catb(&exclude_masks, (void*)&s, sizeof(char*));
        break;
      }
      case 'o': {
        buffer_1->fd = io_err_check(open_trunc(optarg));
        break;
      }
      case 't': {
        opt_timestyle = optarg;
        break;
      }
      case 's': {
        opt_separator = optarg[0];
        break;
      }
      case 'l': opt_list = 1; break;
      case 'L': opt_deref = 1; break;
      case 'n': opt_numeric = 1; break;
      case 'r': opt_relative = 1; break;
      case 'm': scan_ulong(optarg, &opt_minsize); break;
      default: usage(argv[0]); return 1;
    }
  }
  /*
    while(optind < argc) {
      if(!str_diff(argv[optind], "-l") || !str_diff(argv[optind], "--list")) {
        opt_list = 1;
      } else if(!str_diff(argv[optind], "-n") || !str_diff(argv[optind], "--numeric")) {
        opt_numeric = 1;
      } else if(!str_diff(argv[optind], "-r") || !str_diff(argv[optind], "--relative")) {
        relative = 1;
      } else if(!str_diff(argv[optind], "-o") || !str_diff(argv[optind], "--output")) {
        buffer_1->fd = io_err_check(open_trunc(argv[optind + 1]));
        ++optind;
      } else if(!str_diff(argv[optind], "--relative")) {
        relative = 1;
      } else if(!str_diff(argv[optind], "-t") || !str_diff(argv[optind], "--time-style")) {
        optind++;
        opt_timestyle = argv[optind];
      } else {
        break;
      }
      optind++;
    }
    */
  array_catb(&exclude_masks, "\0\0\0\0\0\0\0\0", sizeof(char**));
  print_strarray(buffer_2, &exclude_masks);
  if(optind < argc) {
    while(optind < argc) {
      if(opt_relative)
        opt_relative_to = argv[optind];
      stralloc_copys(&dir, argv[optind]);
      list_dir_internal(&dir, 0);
      optind++;
    }
  } else {
    stralloc_copys(&dir, ".");
    list_dir_internal(&dir, 0);
  }
  return 0;
}