int main (int argc, const char * argv[]) { // Get the current directory char cwd[1024]; if (getcwd(cwd, sizeof(cwd)) != NULL) ; else perror("getcwd() error"); int numargs, all=0, asc=0, desc=0, push=0, uk=0, help=0, current=0, clean=0; const char *c; numargs = argc; while (--numargs > 0) { c = argv[numargs]; if (!strcmp(argv[numargs], "all")) all = 1; else if (!strcmp(argv[numargs], "-h") || !strcmp(argv[numargs], "--help")) help = 1; else if (!strcmp(argv[numargs], ".")) current = 1; else if (!strcmp(argv[numargs], "-p") || !strcmp(argv[numargs], "--push")) push = 1; else if (!strcmp(argv[numargs], "-")) desc = 1; else if (!strcmp(argv[numargs], "+")) asc = 1; else if (!strcmp(argv[numargs], "clean")) clean = 1; else uk++; } int args; args = argc; if (uk > 2) { printUsage(); return 1; } switch(args) { // Show the comment for the current directory case 1: printUsage(); return 1; break; case 2: // Show the help menu if (help) { printUsage(); return 1; } // Show all the files else if (all) { makeDir(cwd); printFiles(cwd); } // Show comment for the current directory else if (current) { // checkComment(argv[1], cwd); printCurrentComment(cwd); } // Show comment for the entered file else { // char *file = argv[1]; makeDir(cwd); checkComment(argv[1], cwd); } break; case 3: if ( current && !clean ) { // Add comment to the current directory // char *file; // file = "CURRENT"; addComment(argv[1], cwd, argv[2], false); } else if (all && desc) { // Print all files in descending order makeDir(cwd); printAllOrder(cwd, true); } else if (all && asc) { // Print all files in ascending order makeDir(cwd); printAllOrder(cwd, false); } else if ( clean ){ cleanComment( argv[1] ); // Clean file comment } else { // Add comment to to given file makeDir(cwd); addComment(argv[1], cwd, argv[2], false); } break; case 4: // Push comment to the current directory if (current && push) { addComment(argv[1], cwd, argv[3], true); // Add a comment to the given filename } // Push comment to given file else if ( push) { makeDir(cwd); addComment(argv[1], cwd, argv[3], true); } break; // Not certain default: printUsage(); } return 0; }
int main (int argc, const char *argv[]) { // Get the current directory char cwd[1024]; if (!getcwd(cwd, sizeof(cwd))) { perror("getcwd() error"); } int numargs, all = 0, asc = 0, desc = 0, push = 0, uk = 0, help = 0, current = 0; const char *c; numargs = argc; // TODO: Convert to getopt while (--numargs > 0) { c = argv[numargs]; if (!strcmp(argv[numargs], "all")) all = 1; else if (!strcmp(argv[numargs], "-h") || !strcmp(argv[numargs], "--help")) help = 1; else if (!strcmp(argv[numargs], ".")) current = 1; else if (!strcmp(argv[numargs], "-p") || !strcmp(argv[numargs], "--push")) push = 1; else if (!strcmp(argv[numargs], "-")) desc = 1; else if (!strcmp(argv[numargs], "+")) asc = 1; else uk++; } int args; args = argc; if (uk > 2) { printUsage(); return EXIT_FAILURE; } if (args == 1) { printUsage(); return EXIT_FAILURE; } else if (args == 2) { // Show the help menu if (help) { printUsage(); return EXIT_FAILURE; } // Show all the files else if (all) { makeDir(cwd); printFiles(cwd); } // Show comment for the current directory else if (current) { // checkComment(argv[1], cwd); printCurrentComment(cwd); } // Show comment for the entered file else { // char *file = argv[1]; makeDir(cwd); checkComment(argv[1], cwd); } } else if (args == 3) { if (current) { // Add comment to the current directory // char *file; // file = "CURRENT"; addComment(argv[1], cwd, argv[2], false); } else if (all && desc) { // Print all files in descending order makeDir(cwd); printAllOrder(cwd, true); } else if (all && asc) { // Print all files in ascending order makeDir(cwd); printAllOrder(cwd, false); } else { // Add comment to to given file makeDir(cwd); addComment(argv[1], cwd, argv[2], false); } } else if (args == 4) { if (current && push) { // Push comment to the current directory // Add a comment to the given filename addComment(argv[1], cwd, argv[3], true); } else if (push) { // Push comment to given file makeDir(cwd); addComment(argv[1], cwd, argv[3], true); } } else { // Not certain printUsage(); } return EXIT_SUCCESS; }