about summary refs log blame commit diff stats
path: root/apps/hex
blob: 8312b87ab4b01de0d30b844555eb0ed5732a0afd (plain) (tree)
blob is binary.
72c12385cb28b3355'>kernel.soso/systemfs.h
blob: 23068af1387a7b6a57bd41f8e925464592451e87 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
>23
24
25
26
27
28
29
30
31
32
33
34
35
#include<cstdlib>
#include<dirent.h>
#include<vector>
using std::vector;
#include<string>
using std::string;
#include<iostream>
using std::cout;

int enumerate_files_in_cwd_until(string last_file);
string flag_value(const string& flag, int argc, const char* argv[]);

int main(int argc, const char* argv[]) {
  return enumerate_files_in_cwd_until(flag_value("--until", argc, argv));
}

int enumerate_files_in_cwd_until(string last_file) {
  dirent** files;
  int num_files = scandir(".", &files, NULL, alphasort);
  for (int i = 0; i < num_files; ++i) {
    string curr_file = files[i]->d_name;
    if (!isdigit(curr_file[0])) continue;
    if (!last_file.empty() && curr_file > last_file) break;
    cout << curr_file << '\n';
  }
  // don't bother freeing files
  return 0;
}

string flag_value(const string& flag, int argc, const char* argv[]) {
  for (int i = 1; i < argc-1; ++i)
    if (string(argv[i]) == flag)
      return argv[i+1];
  return "";
}