summaryrefslogtreecommitdiff
path: root/old/lipsum.~1~
diff options
context:
space:
mode:
Diffstat (limited to 'old/lipsum.~1~')
-rwxr-xr-xold/lipsum.~1~90
1 files changed, 90 insertions, 0 deletions
diff --git a/old/lipsum.~1~ b/old/lipsum.~1~
new file mode 100755
index 0000000..efa71b5
--- /dev/null
+++ b/old/lipsum.~1~
@@ -0,0 +1,90 @@
+#!/usr/bin/awk -f
+
+function printusage() {
+ print "Usage: lipsum [# of] [w/words|s/sentences|p/paragraphs] [1/t/true|0/f/false output 'lorem ipsum' in first entry] [min words] [max words]\n"
+ exit 1
+}
+
+function capitalize(word) {
+ sub(/./, toupper(substr(word, 0, 1)), word)
+ print word
+}
+
+function isint(arg) {
+ return arg ~ /^[0-9]+$/
+}
+
+function randrange(min, max) {
+ return int((rand() * (max - min)) + min)
+}
+
+function genword() {
+ wc++ # There's gotta be a more efficient way of doing this
+ return (wc > 5 || !litextout) ? word[randrange(0, dictlen)] : litext[wc - 1]
+}
+
+function genwords(words) {
+ if (words > 0) {
+ capitalize(genword())
+ for (i = 1; i < words; i++)
+ print " " genword()
+ print "\n"
+ }
+}
+
+function gensentences(sentences, delim, min, max) {
+ for (; sentences > 0; sentences--) {
+ capitalize(genword())
+ words = randrange(min, max) # Isn't possible to initialize or increment multiple variables in awk for loops
+ for (i = 1; i < words; i++)
+ print (rand() < 0.10 ? ", " : " ") genword()
+ print delim
+ }
+}
+
+function genparagraphs(paragraphs, min, max) {
+ for (; paragraphs > 0; paragraphs--) {
+ print "\t"
+ gensentences(randrange(6, 10), ". ", min, max)
+ print "\n"
+ }
+}
+
+BEGIN {
+ dictionary = "/home/timmy/.local/share/lorem-ipsum-dictionary" # List of lorem ipsum words separated by newlines
+ litext[0] = "lorem"; litext[1] = "ipsum"; litext[2] = "dolor"; litext[3] = "sit"; litext[4] = "amet"
+
+ ORS = ""
+ srand()
+
+ for (dictlen = 0; getline < dictionary; dictlen++)
+ word[dictlen] = $0
+
+ # Parse Arguments
+ !isint(ARGV[1]) && ARGV[1] && printusage()
+ numof = ARGC > 1 ? ARGV[1] : 5
+ mode = ARGC > 2 ? ARGV[2] : "p"
+ litextout = 1
+ if (ARGV[3])
+ switch (ARGV[3]) {
+ case /^1$|^t$|^true$/: litextout = 1; break
+ case /^0$|^f$|^false$/: litextout = 0; break
+ default: printusage()
+ }
+ min = isint(ARGV[4]) ? ARGV[4] : 5
+ max = isint(ARGV[5]) ? ARGV[5] : 12
+
+ switch (mode) {
+ case /^w$|^words$/:
+ genwords(numof)
+ break
+ case /^s$|^sentences$/:
+ gensentences(numof, ".\n", min, max)
+ break
+ case /^p$|^paragraphs$/:
+ genparagraphs(numof, min, max)
+ break
+ default:
+ printusage()
+ }
+}