diff --git a/.gitignore b/.gitignore index 9053540..27b1df6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .history .vscode +publish diff --git a/isspam b/isspam index bfde85c..645427c 100755 Binary files a/isspam and b/isspam differ diff --git a/isspam.c b/isspam.c index 3a7988d..6b389e8 100644 --- a/isspam.c +++ b/isspam.c @@ -24,6 +24,25 @@ char *forbidden_words[] = { "stolen", "freeze", "quick", "crucial", "tracing", "scammers", "expers", "hire", "century", "transaction", "essential", "managing", "contact", "contacting", "understanding", "assets", "funds", NULL}; + +bool show_capitalized = false; +bool show_sentences = false; +bool show_words = false; +bool show_numbers = false; +bool show_forbidden_words = true; + + + + +bool file_exists(char * path){ + FILE * f = fopen(path, "r"); + bool result = f != NULL; + if(f){ + fclose(f); + } + return result; +} + void sld(sl *lst) { for (uint i = 0; i < lst->count; i++) { printf("<%u:%s>\n", i, lst->strings[i]); @@ -244,7 +263,6 @@ sl *get_forbidden_words(char *content) { slf(words); return found; } - void analyze(FILE *f) { char *data = fread_till_eof(f); @@ -259,6 +277,8 @@ void analyze(FILE *f) { sl *capitalized_words = get_capitalized_words(data); uint capitalized_words_count = capitalized_words->count; printf("Capitalized words: %u\n", capitalized_words_count); + if(show_capitalized) + sld(capitalized_words); sbuf = slds(capitalized_words); stra(all, sbuf); free(sbuf); @@ -267,7 +287,8 @@ void analyze(FILE *f) { // All sentences printf("Sentences: %u\n", sentences->count); - // sld(sentences); + if(show_sentences) + sld(sentences); sbuf = slds(sentences); stra(all, sbuf); free(sbuf); @@ -276,7 +297,8 @@ void analyze(FILE *f) { // All words printf("Words: %u\n", words->count); - // sld(words); + if(show_words) + sld(words); sbuf = slds(words); stra(all, sbuf); free(sbuf); @@ -284,7 +306,8 @@ void analyze(FILE *f) { // Numbers sl *numbers = get_numbers(data); printf("Numbers: %u\n", numbers->count); - // sld(numbers); + if(show_numbers) + sld(numbers); sbuf = slds(numbers); stra(all, sbuf); free(sbuf); @@ -292,11 +315,11 @@ void analyze(FILE *f) { // Forbidden words sl *fw = get_forbidden_words(data); printf("Forbidden words: %u\n", fw->count); - // sld(fw); + if(show_forbidden_words) + sld(fw); sbuf = slds(fw); stra(all, sbuf); free(sbuf); - strd(all); uint word_count_per_sentence = words->count / sentences->count; printf("Word count per sentence: %u\n", word_count_per_sentence); @@ -317,17 +340,40 @@ void analyze_file(char *path) { } int main(int argc, char *argv[]) { - + if (argc > 1) { for (int i = 1; i < argc; i++) { + if(!strcmp(argv[1],"--hide-capitalized")){ + show_capitalized=false; + }else if(!strcmp(argv[1],"--show-sentences")){ + show_sentences=true; + }else if(!strcmp(argv[1],"--show-words")){ + show_words=true; + }else if(!strcmp(argv[1],"--show-numbers")){ + show_words=true; + }else if(!strcmp(argv[1],"--hide-forbidden-words")){ + show_forbidden_words=false; + }else if(!strcmp(argv[1],"help") || !strcmp(argv[1],"--help")){ + printf("%s", + "Usage: spam [file] [file] [file]\n" + "Flag defaults:\n" + " hide-capitalized = true\n" + " show-sentences = false\n" + " show-words = false\n" + " show-numbers = false\n" + " hide-forbidden-words = false\n"); + return 0; + } + printf("File: %s\n", argv[i]); analyze_file(argv[i]); + printf("%s\n", rmalloc_stats()); printf("\n"); } - printf("%s\n", rmalloc_stats()); + return 0; } analyze(stdin); printf("%s\n", rmalloc_stats()); return 0; -} \ No newline at end of file +}