From 6961e4237f24306ab2475f4f527a7c802134c4d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20L=2E=20=C5=A0ijanec?= Date: Fri, 1 May 2020 15:18:12 +0200 Subject: added working inline command tag detector, more constants ability to change inline command tag characters, variable length and count and buffer size from define headers. TODO: line-commands (lines, starting with ?) comments (lines, starting with #) --- lib/jsmin.c | 2 +- lib/mkdirp.c | 5 +---- lib/randstring.c | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 lib/randstring.c (limited to 'lib') diff --git a/lib/jsmin.c b/lib/jsmin.c index 402c6c9..3cb0e9b 100644 --- a/lib/jsmin.c +++ b/lib/jsmin.c @@ -29,7 +29,7 @@ This file was modified by Anton Šijanec in 2020 in order to allow it being used as a library for minifying JS inside other programs. All I've added is the option to read from a source file and output to the minified file. */ - +#pragma once #include #include #include diff --git a/lib/mkdirp.c b/lib/mkdirp.c index 8c79cf4..a6c58e6 100644 --- a/lib/mkdirp.c +++ b/lib/mkdirp.c @@ -1,12 +1,9 @@ // borrowed from https://gist.github.com/JonathonReinhart/8c0d90191c38af2dcadb102c4e202950 - +#pragma once #include #include /* PATH_MAX */ #include /* mkdir(2) */ #include -#ifndef PATH_MAX -#define PATH_MAX 255 -#endif int mkdir_p(const char *path) { /* Adapted from http://stackoverflow.com/a/2336245/119527 */ const size_t len = strlen(path); diff --git a/lib/randstring.c b/lib/randstring.c new file mode 100644 index 0000000..2eeed8f --- /dev/null +++ b/lib/randstring.c @@ -0,0 +1,21 @@ +#pragma once +char *randstring(size_t length) { + + static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + char *randomString = NULL; + + if (length) { + randomString = malloc(sizeof(char) * (length +1)); + + if (randomString) { + for (int n = 0;n < length;n++) { + int key = rand() % (int)(sizeof(charset) -1); + randomString[n] = charset[key]; + } + + randomString[length] = '\0'; + } + } + + return randomString; +} -- cgit v1.2.3