From b93e412feb8275cefbc641f6e0b6f9719f134952 Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 6 Mar 2024 20:03:19 -0500 Subject: [PATCH 1/4] removed unneeded prng de/init --- src/Program.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index 6dd8bbe..4373915 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -12,15 +12,11 @@ if(!Directory.Exists(resourcePath)) { // pull file list var files = Directory.GetFiles(resourcePath, "*.txt"); -var prng = RandomNumberGenerator.Create(); - // choose a file and line var file = files[RandomNumberGenerator.GetInt32(files.Length)]; var lines = File.ReadAllLines(file); var line = lines[RandomNumberGenerator.GetInt32(lines.Length)]; -prng.Dispose(); - // process escape codes line = line.Replace("\\n", "\n"); From 6e31e23001bb405eb50735449ea33f9118428d52 Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 8 Mar 2024 21:59:39 -0500 Subject: [PATCH 2/4] general fortune fixes --- data/love.txt | 2 +- data/political.txt | 2 +- data/pride.txt | 1 - data/{social.txt => socials.txt} | 0 4 files changed, 2 insertions(+), 3 deletions(-) rename data/{social.txt => socials.txt} (100%) diff --git a/data/love.txt b/data/love.txt index 9a950e6..b7f80e1 100644 --- a/data/love.txt +++ b/data/love.txt @@ -1,4 +1,4 @@ PLYADES I'll take care of you.\nORESTES It's rotten work.\nPLYADES Not to me. Not if it's you.\n\n - Anne Carson, Euripides me: good night darling. I'm so happy to be able to fall asleep\nnext to you\n\nmy gf: *already rotating like a kebab to ensure maximum duvet\ntheft*\n\n - @davideastUK, Twitter. \nidc anymore i think we should be a burden to each other\n\nand yes this includes a certain degree of tolerance for emotional\nburden, all else being equal. my love for you, and loyalty to\nyou, is not dependent on how easy you make it for me to love you.\ni don't value you for how little trouble you cause me. i want to\nlearn how to take you for who you are, instead of who i want you\nto be or who i think you should be\n\n\nThe measure of any relationship should not be whether loving\nsomeone is work, but whether it is work that you are glad to do.\n\n - tumblr exchange -I want to eat the sunbeam flaring in your lovel body,\nthe sovereign nose of your arrogant face,\nI want to eat the fleeting shade of your lashes,\n - Pablo Neruda +I want to eat the sunbeam flaring in your lovely body,\nthe sovereign nose of your arrogant face,\nI want to eat the fleeting shade of your lashes,\n - Pablo Neruda diff --git a/data/political.txt b/data/political.txt index 608b96a..8a16568 100644 --- a/data/political.txt +++ b/data/political.txt @@ -1,3 +1,3 @@ the distortion of "there is potential profit we did not earn" as\n"there is money we lost" is fascinating and disgusting to me.\n"megamediacongolmerate lost $1,000,000,000 to piracy this year"\nis a flat out lie. it is not true. they did not have a billion\ndollars, that they now do not have. they felt entitled to one\nbillion dollars, that they did not have, and still do not have.\nit's an infuriating perversion of the truth.\n\n - strawberry-bundae, tumblr post I'm tired of being the butt of everyone's jokes.\nI'm tired of being talked about like I'm not here.\nI'm tired of being a political token. Tired of being under\nscrutiny for no reason. Tired of being presumed guilty until\nproven innocent. Tired of being used as a cudgel to put down\nother trans people. I'm tired of having to constantly be on my\nbest behavior lest someone decide to ruin my life over some\ninsignificant slight. And I'm tired, most of all, because the\npeople who do all this stuff also surround themselves with legions\nof sycophants who'll constantly jerk them off about how good and\nwoke and progressive they are and about how the big scary\nhysterical ****** is just being mean for no reason.\n\nI'm tired. I just wanna play video games and read books about\nelves. I didn't sign up for whatever the fuck this is.\n\n - natalieironside, tumblr post. -> The less you eat, drink and read books; the less you go to the\n> theatre, the dance hall, the public-house; the less you think,\n> love, theorize, paint, sing, fence, etc., the more you save—the\n> greater becomes your treasure which neither moths nor dust will\n> devour—your capital. The less you are, the more you have; the\n> less you express your own life, the greater is your alienated\n> life—the greater is the store of your estranged being.\n\n - Karl Marx, Economic and Philosophic Manuscripts or 1844 +"The less you eat, drink and read books; the less you go to the theatre, the\ndance hall, the public-house; the less you think, love, theorize, paint, sing,\nfence, etc., the more you save—the greater becomes your treasure which neither\nmoths nor dust will devour—your capital. The less you are, the more you have;\nthe less you express your own life, the greater is your alienated life—the\ngreater is the store of your estranged being."\n\n - Karl Marx, Economic and Philosophic Manuscripts or 1844 diff --git a/data/pride.txt b/data/pride.txt index f714efc..d00aaa0 100644 --- a/data/pride.txt +++ b/data/pride.txt @@ -1,7 +1,6 @@ █████████████████████\n█████████████████████\n█████████████████████\n█████████████████████\n█████████████████████\n█████████████████████ ██████████████████\n██████████████████\n██████████████████\n██████████████████\n██████████████████ ██████████████████\n█████████████████\n████████████████\n████████████████\n█████████████████\n██████████████████ -BE GAY DO CRIME! "Can you write in it that I said thank you to gay people"\n\n - Gianni Matragrano, ULTRAKILL credits > I'd like to see the gay revolution get started... If a\n> transvestite doesn't say "I'm gay and I'm proud and I'm a\n> transvestite," then nobody else is going to hop up there and\n> say "I'm gay and I'm proud and I'm a transvestite" for them.\n\n - Marsha P Johnson, Stonewall Rioter "No pride for some of us without liberation for all of us."\n\n - Marsha P Johnson, Stonewall Rioter diff --git a/data/social.txt b/data/socials.txt similarity index 100% rename from data/social.txt rename to data/socials.txt From 7d42eaf2b8670b7476749081268d5500a9a5882f Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 11 Mar 2024 22:57:45 -0400 Subject: [PATCH 3/4] added usage information --- src/Info.cs | 31 +++++++++++++++++++++++++++++++ src/Program.cs | 20 ++++++++++++++++++-- src/Util.cs | 17 +++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/Info.cs create mode 100644 src/Util.cs diff --git a/src/Info.cs b/src/Info.cs new file mode 100644 index 0000000..c004bba --- /dev/null +++ b/src/Info.cs @@ -0,0 +1,31 @@ +using System; +using System.IO; + +public static class Globals { + public const string VERSION = "0.1.0"; + public const string DEFAULT_PATH = "/usr/share/fortune-cs/"; +} + +public static class Usage { + + public static void HelpText() { + VersionText(); + Console.WriteLine(@"Valerie Wolfe +Shows quotes from a set of files. + +usage: fortune-cs [files...]"); + } + + public static void ListText(string[] files) { + foreach(var file in files) { + var fileName = Path.GetFileNameWithoutExtension(file); + Console.WriteLine(fileName); + } + } + + public static void VersionText() { + Console.WriteLine("fortune-cs v" + Globals.VERSION); + } + +} + diff --git a/src/Program.cs b/src/Program.cs index 4373915..531943e 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -2,16 +2,32 @@ using System; using System.IO; using System.Security.Cryptography; +// handle help and version flags +if(Utilities.HasFlags(args, "-h", "--help")) { + Usage.HelpText(); + return 0; +} +if(Utilities.HasFlags(args, "-v", "--version")) { + Usage.VersionText(); + return 0; +} + // make sure fortune directory exists -var resourcePath = "/usr/share/fortune-cs/"; +var resourcePath = Globals.DEFAULT_PATH; if(!Directory.Exists(resourcePath)) { - Console.WriteLine("fortune-cs: directory '/usr/share/fortune-cs/' does not exist"); + Console.WriteLine($"fortune-cs: directory '${resourcePath}' does not exist"); return 1; } // pull file list var files = Directory.GetFiles(resourcePath, "*.txt"); +// handle list flag +if(Utilities.HasFlags(args, "-l", "--list")) { + Usage.ListText(files); + return 0; +} + // choose a file and line var file = files[RandomNumberGenerator.GetInt32(files.Length)]; var lines = File.ReadAllLines(file); diff --git a/src/Util.cs b/src/Util.cs new file mode 100644 index 0000000..eed31cc --- /dev/null +++ b/src/Util.cs @@ -0,0 +1,17 @@ +using System; + +public static class Utilities { + + /// + /// Checks if a given flag is set in `args`. + /// + public static bool HasFlags(string[] args, params string[] flags) { + foreach(string flag in flags) + // using `Array.IndexOf` since including Linq for `array.Contains` increases binary size + if(Array.IndexOf(args, flag) != -1) + return true; + return false; + } + +} + From 54cceabdcefefd75ee09931dcfeb60fb2acb7e79 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 11 Mar 2024 22:59:08 -0400 Subject: [PATCH 4/4] removed unimplemented args from usage text --- src/Info.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Info.cs b/src/Info.cs index c004bba..f109ac4 100644 --- a/src/Info.cs +++ b/src/Info.cs @@ -13,7 +13,7 @@ public static class Usage { Console.WriteLine(@"Valerie Wolfe Shows quotes from a set of files. -usage: fortune-cs [files...]"); +usage: fortune-cs"); } public static void ListText(string[] files) {