48 lines
1.1 KiB
C
48 lines
1.1 KiB
C
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
enum ERROR{NO_ARGUMENTS, WRONG_ARGUMENT};
|
||
|
|
||
|
int print_error_message(enum ERROR error_type) {
|
||
|
if (error_type == NO_ARGUMENTS) {
|
||
|
fprintf(stderr,"cp: missing file operand\n"); // TODO: Maybe replace "cp" with argv[0]?
|
||
|
fprintf(stderr,"Try cp --help for more information.\n");
|
||
|
return 0;
|
||
|
} else if (error_type == WRONG_ARGUMENT) {
|
||
|
fprintf(stderr, "cp: unrecognized option\n");
|
||
|
fprintf(stderr,"Try cp --help for more information.\n");
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int print_help() {
|
||
|
printf("HELP\n");
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int cp(char *argv[]){
|
||
|
printf("%s\n", argv[0]);
|
||
|
open();
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int main(int argc, char *argv[]) {
|
||
|
if (argc == 1) {
|
||
|
print_error_message(NO_ARGUMENTS);
|
||
|
return 1;
|
||
|
}
|
||
|
if (argc == 2) {
|
||
|
if (strcmp(argv[1], "--help") == 0) {
|
||
|
print_help();
|
||
|
return 0;
|
||
|
} else {
|
||
|
print_error_message(WRONG_ARGUMENT);
|
||
|
return 2;
|
||
|
}
|
||
|
}
|
||
|
if (argc == 3) {
|
||
|
cp(argv);
|
||
|
}
|
||
|
return 0;
|
||
|
}
|