summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Abbott <george@gabbott.dev>2025-02-13 22:50:55 +0000
committerGeorge Abbott <george@gabbott.dev>2025-02-13 22:50:55 +0000
commitf34d4bbbeec9601c416863fb1459db06e5e3d81a (patch)
tree2d40ee89d60601235fce694759f725eb088c204c
parent3ded86d0e493b191c747fb017d3b9d1e61eb06ef (diff)
added fexHEADmaster
-rw-r--r--scripts/fex.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/fex.c b/scripts/fex.c
new file mode 100644
index 0000000..7abdc5f
--- /dev/null
+++ b/scripts/fex.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+// Grab the file extension of the filename passed.
+// TODO: current just does it until the first. Add in variations to grab all,
+// only specific entries like .tar.gz, etc.
+
+void usage(void)
+{
+ printf("fex: returns the extension of the filename passed\n");
+ exit(0);
+}
+
+int main(int argc, char **argv)
+{
+ if (argc <= 1)
+ usage();
+
+ const char *file = argv[1]; // FIXME: unsafe.
+ size_t len = strlen(file);
+ if (len == 0)
+ fprintf(stderr, "length of file cannot be zero\n"), exit(-1);
+
+ for (len--; len != 0; len--)
+ {
+ if (file[len] == '.')
+ {
+ printf("%s\n", file + len + 1);
+ return 0;
+ }
+ }
+ return 0;
+}