BuildSystem: Cleanup userspace directory layout
userspace programs are now in userspace/programs userspace tests are now in userspace/tests This makes listing userspace projects much cleaner. Libraries were already separated to their own directory, so other programs should also.
This commit is contained in:
9
userspace/programs/getopt/CMakeLists.txt
Normal file
9
userspace/programs/getopt/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(getopt ${SOURCES})
|
||||
banan_include_headers(getopt ban)
|
||||
banan_link_library(getopt libc)
|
||||
|
||||
install(TARGETS getopt OPTIONAL)
|
||||
44
userspace/programs/getopt/main.cpp
Normal file
44
userspace/programs/getopt/main.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <BAN/String.h>
|
||||
#include <BAN/Vector.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "usage: %s OPTSTRING [PARAMETERS]...", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
BAN::Vector<char*> argv_copy(argc - 1);
|
||||
argv_copy[0] = argv[0];
|
||||
for (int i = 2; i < argc; i++)
|
||||
argv_copy[i - 1] = argv[i];
|
||||
|
||||
int opt;
|
||||
BAN::String parsed;
|
||||
while ((opt = getopt(argc - 1, argv_copy.data(), argv[1])) != -1)
|
||||
{
|
||||
if (opt == ':' || opt == '?')
|
||||
continue;
|
||||
|
||||
MUST(parsed.append(" -"));
|
||||
MUST(parsed.push_back(opt));
|
||||
|
||||
if (optarg)
|
||||
{
|
||||
MUST(parsed.push_back(' '));
|
||||
MUST(parsed.append(optarg));
|
||||
}
|
||||
|
||||
optarg = nullptr;
|
||||
}
|
||||
|
||||
printf("%s --", parsed.data());
|
||||
for (; optind < argc - 1; optind++)
|
||||
printf(" %s", argv_copy[optind]);
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user