Compare commits
No commits in common. "3902f5e3b791e9f983aac9b068df3b20421d79bd" and "eb328210a5cb29a31d0f5c34398a54489e98f626" have entirely different histories.
3902f5e3b7
...
eb328210a5
3 changed files with 4 additions and 46 deletions
11
README.md
11
README.md
|
@ -11,17 +11,6 @@ A no-nonsense, user-extensible `fortune-mod` replacement.
|
|||
This project was originally built in Rust, and I migrated it to C# primarily to
|
||||
test out [bflat](https://github.com/bflattened/bflat).
|
||||
|
||||
<details>
|
||||
<summary><h2>Methodology</h2></summary>
|
||||
|
||||
`fortune-cs` starts by selecting a category file, then a line, so the user will
|
||||
see a normal representation of each file. Then, it selects a line from the file.
|
||||
|
||||
The fortune files themselves can be extended just by appending;
|
||||
`cat b.txt >> a.txt` is a perfectly valid way of merging two files.
|
||||
|
||||
</details>
|
||||
|
||||
## Installation
|
||||
|
||||
### Application
|
||||
|
|
|
@ -2,12 +2,6 @@ using System;
|
|||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
// use merge function if given multiple arguments
|
||||
if(args.Length > 0) {
|
||||
Utilities.Merge(args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// make sure fortune directory exists
|
||||
var resourcePath = "/usr/share/fortune-cs/";
|
||||
if(!Directory.Exists(resourcePath)) {
|
||||
|
@ -18,11 +12,15 @@ 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");
|
||||
|
||||
|
|
29
src/Util.cs
29
src/Util.cs
|
@ -1,29 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
public static class Utilities {
|
||||
|
||||
public static void Merge(params string[] files) {
|
||||
// hashset to prevent duplicates
|
||||
var members = new HashSet<string>();
|
||||
// iterate over all paths given
|
||||
foreach(var file in files) {
|
||||
// skip nonexistent files gracefully
|
||||
if(!File.Exists(file))
|
||||
continue;
|
||||
// iterate over lines
|
||||
var lines = File.ReadAllLines(file);
|
||||
foreach(var line in lines) {
|
||||
// prevent duplicates
|
||||
if(members.Contains(line))
|
||||
continue;
|
||||
members.Add(line);
|
||||
// emit to stdout
|
||||
Console.WriteLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in a new issue