Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a start for pwd #50

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 62 additions & 4 deletions src/pwd/pwd.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,64 @@
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
printf("Hello, World!\n");
return 0;
}
#define NAME "pwd (canoutils)"
#define VERSION "0.0.1"
#define AUTHOR "cospplredman"

#include "cgetopt.h"
#include "version_info.h"

static const char usage[] = {"Usage: pwd [Option]...\n"
" --version version information\n"
" --help display this help and exit\n"
" -L print contents of PWD if it is the "
"current directory (default)\n"
" -P path written to standard out shall "
"not have any symbolic names in it\n"};

// flags
static int output_format = 'L';

static struct option long_options[] = {
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
};

int main(int argc, char **argv) {

int opt, option_index;
while ((opt = getopt_long(argc, argv, "LP", long_options, &option_index)) !=
-1) {
switch (opt) {
case 0:
break;
case 'v':
print_version();
return EXIT_SUCCESS;
break;
case 'h':
printf("%s\n", usage);
return EXIT_SUCCESS;
case 'L':
output_format = 'L';
break; // TODO implement
case 'P':
output_format = 'P';
break; // TODO
}
}

argc -= optind;
argv += optind;

if (argc > 0) {
fprintf(stderr, "%s\n", usage);
return EXIT_FAILURE;
}

char *path = getenv("PWD");
printf("%s\n", path);
}