summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-05-06 04:47:40 +0530
committerAndinus <andinus@nand.sh>2020-05-06 04:47:40 +0530
commit1386c084c8356d524cce25152ec8c64f4bd5e910 (patch)
tree97c78933bd5749ee37ba77732ddeb1a9b720244e
downloadpictor-1386c084c8356d524cce25152ec8c64f4bd5e910.tar.gz
Initial commit
-rw-r--r--LICENSE13
-rw-r--r--README.org14
-rw-r--r--pictor.pl64
3 files changed, 91 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..8cb5164
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) 2020, Andinus <andinus@nand.sh>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..e523e3e
--- /dev/null
+++ b/README.org
@@ -0,0 +1,14 @@
+#+HTML_HEAD: <link rel="stylesheet" href="../static/style.css">
+#+HTML_HEAD: <link rel="icon" href="../static/pictor.png" type="image/png">
+#+EXPORT_FILE_NAME: index
+#+TITLE: Pictor
+
+Pictor is a simple acronym expander.
+
+| Project Home    | [[https://andinus.nand.sh/pictor/][Pictor]] |
+| Source Code     | [[https://git.tilde.institute/andinus/pictor/][Andinus / Pictor]] |
+| GitHub (Mirror) | [[https://github.com/andinus/pictor/][Pictor - GitHub]] |
+
+*Tested on*:
+- OpenBSD 6.6
+  - Perl v5.28
diff --git a/pictor.pl b/pictor.pl
new file mode 100644
index 0000000..6d4a523
--- /dev/null
+++ b/pictor.pl
@@ -0,0 +1,64 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+use OpenBSD::Pledge;
+use OpenBSD::Unveil;
+
+pledge( qw( rpath unveil ) ) or
+    die "Unable to pledge: $!";
+
+# $term will store the user input.
+my $term;
+
+# User must pass at least one argument.
+if (@ARGV < 1) {
+    say STDERR "usage: wtf.pl term";
+    exit 1;
+} else {
+    $term = $ARGV[0];
+}
+
+# files contains list of all files to search for acronyms.
+my @files = (
+    '/usr/local/share/misc/acronyms',
+    '/usr/local/share/misc/acronyms-o',
+    '/usr/local/share/misc/acronyms.comp'
+    );
+
+# Unveil each file with only read permission.
+foreach my $file (@files) {
+    unveil( $file, "r" ) or
+    	die "Unable to unveil: $!";
+}
+
+# Block further unveil calls.
+unveil() or
+    die "Unable to lock unveil: $!";
+
+# drop pledge permissions
+pledge( qw( rpath )) or
+    die "Unable to pledge: $!";
+
+# Search for acronym in every file.
+foreach my $file (@files) {
+    open my $fh, '<', $file or
+	# The program should continue if the file doesn't exist but
+	# warn the user about it.
+	do {
+	    warn "Unable to open $file: $!";
+	    next;
+    };
+
+    while (my $line = readline $fh) {
+	# \Q is quotemeta, \E terminates it because otherwise it would
+	# mess with \s. This regex matches when $line starts with
+	# "$term\s", \s being any kind of whitespace.
+	print $line if ($line =~ /^\Q${term}\E\s/i);
+    }
+}
+
+# drop pledge permissions
+pledge() or
+    die "Unable to pledge: $!";