diff options
| author | iceyrazor <iceyrazor@mailfence.com> | 2026-07-21 03:37:29 -0500 |
|---|---|---|
| committer | iceyrazor <iceyrazor@mailfence.com> | 2026-07-21 03:37:29 -0500 |
| commit | effc9a1a4f4c6108ba14fe457ba1add547e86244 (patch) | |
| tree | 8a7aa7cda08d80fb2d938620460b00414c967f4a /iceys-utils.c | |
Diffstat (limited to 'iceys-utils.c')
| -rwxr-xr-x | iceys-utils.c | 119 |
1 files changed, 119 insertions, 0 deletions
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(®ex, "^[0-9]*$", 0); + if (reti) { + fprintf(stderr, "Could not compile regex\n"); + exit(1); + } + + + reti = regexec(®ex, number, 0, NULL, 0); + if (reti == REG_NOMATCH) { + return -2; + } + + regfree(®ex); + + 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 |
