aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE21
-rw-r--r--README.md3
-rwxr-xr-xcolor-utils.c91
-rwxr-xr-xiceys-utils.c119
4 files changed, 234 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..e4e5954
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 iceyrazor
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..3ded677
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# iceys C Libs
+
+Common stuff I use acrossed my C projects.
diff --git a/color-utils.c b/color-utils.c
new file mode 100755
index 0000000..d01da3a
--- /dev/null
+++ b/color-utils.c
@@ -0,0 +1,91 @@
+#ifndef color_utils_c
+#define color_utils_c
+#include <math.h>
+
+struct RGB
+{
+ unsigned char R;
+ unsigned char G;
+ unsigned char B;
+};
+struct HSV
+{
+ double H;
+ double S;
+ double V;
+};
+struct RGB HSVToRGB(struct HSV hsv) {
+ double r = 0, g = 0, b = 0;
+
+ if (hsv.S == 0)
+ {
+ r = hsv.V;
+ g = hsv.V;
+ b = hsv.V;
+ }
+ else
+ {
+ int i;
+ double f, p, q, t;
+
+ if (hsv.H == 360)
+ hsv.H = 0;
+ else
+ hsv.H = hsv.H / 60;
+
+ i = (int)trunc(hsv.H);
+ f = hsv.H - i;
+
+ p = hsv.V * (1.0 - hsv.S);
+ q = hsv.V * (1.0 - (hsv.S * f));
+ t = hsv.V * (1.0 - (hsv.S * (1.0 - f)));
+
+ switch (i)
+ {
+ case 0:
+ r = hsv.V;
+ g = t;
+ b = p;
+ break;
+
+ case 1:
+ r = q;
+ g = hsv.V;
+ b = p;
+ break;
+
+ case 2:
+ r = p;
+ g = hsv.V;
+ b = t;
+ break;
+
+ case 3:
+ r = p;
+ g = q;
+ b = hsv.V;
+ break;
+
+ case 4:
+ r = t;
+ g = p;
+ b = hsv.V;
+ break;
+
+ default:
+ r = hsv.V;
+ g = p;
+ b = q;
+ break;
+ }
+
+ }
+
+ struct RGB rgb;
+ rgb.R = r * 255;
+ rgb.G = g * 255;
+ rgb.B = b * 255;
+
+ return rgb;
+}
+#endif
diff --git a/iceys-utils.c b/iceys-utils.c
new file mode 100755
index 0000000..2331322
--- /dev/null
+++ b/iceys-utils.c
@@ -0,0 +1,119 @@
+#ifndef iceys_utils_c
+#define iceys_utils_c
+#include <string.h>
+#include <stdlib.h>
+#include <regex.h>
+#include <stdio.h>
+
+char *strremove(char *str, const char *sub) {
+ size_t len = strlen(sub);
+ if (len > 0) {
+ char *p = str;
+ size_t size = 0;
+ while ((p = strstr(p, sub)) != NULL) {
+ size = (size == 0) ? (p - str) + strlen(p + len) + 1 : size - len;
+ memmove(p, p + len, size - (p - str));
+ }
+ }
+ return str;
+}
+
+float map(float value, float start1, float stop1, float start2, float stop2){
+ return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
+}
+
+//i made this one :)
+void str_first(char *str, char *str2, char eraser, int found_count){
+ int i=0;
+ int found=0;
+
+ while(str[i]!='\0'){
+ if(str[i]==eraser){
+ if(found>=found_count){
+ break;
+ } else { found++; }
+ }
+ i++;
+ }
+
+ memcpy(str2,str,sizeof(char)*i);
+}
+
+regex_t regex;
+int reti;
+
+int is_number(char *number){
+ if(!number){
+ return -1;
+ }
+
+ /* Compile regular expression */
+ reti = regcomp(&regex, "^[0-9]*$", 0);
+ if (reti) {
+ fprintf(stderr, "Could not compile regex\n");
+ exit(1);
+ }
+
+
+ reti = regexec(&regex, number, 0, NULL, 0);
+ if (reti == REG_NOMATCH) {
+ return -2;
+ }
+
+ regfree(&regex);
+
+ return 1;
+}
+
+int execret(char *return_buffer, char *command){
+ // Open a process by creating a pipe
+ FILE *fp = popen(command, "r");
+ if (fp == NULL) {
+ perror("popen");
+ return 1;
+ }
+
+ // Read the output from the command
+ char buffer[128];
+ while (fgets(buffer, sizeof(buffer) - 1, fp) != NULL) {
+ strcat(return_buffer,buffer);
+ }
+
+ // Close the pipe
+ if (pclose(fp) == -1) {
+ perror("pclose");
+ return 1;
+ }
+
+ return 0;
+}
+
+int execretarr(char **return_arr, char *command){
+ // Open a process by creating a pipe
+ FILE *fp = popen(command, "r");
+ int i=0;
+ if (fp == NULL) {
+ perror("popen");
+ return 1;
+ }
+
+ // Read the output from the command
+ char buffer[128];
+ while (fgets(buffer, sizeof(buffer) - 1, fp) != NULL) {
+ for( int i=0;i<sizeof(buffer);i++){
+ if(buffer[i]=='\n')
+ buffer[i]=' ';
+ }
+ memcpy(return_arr[i],buffer,sizeof(buffer));
+ i++;
+ }
+
+ // Close the pipe
+ if (pclose(fp) == -1) {
+ perror("pclose");
+ return 1;
+ }
+
+ return 0;
+}
+#endif