diff options
| -rwxr-xr-x | iceys-utils.c | 43 | ||||
| -rw-r--r-- | iceys-utils.h | 18 |
2 files changed, 25 insertions, 36 deletions
diff --git a/iceys-utils.c b/iceys-utils.c index 2331322..be56eef 100755 --- a/iceys-utils.c +++ b/iceys-utils.c @@ -1,11 +1,14 @@ -#ifndef iceys_utils_c -#define iceys_utils_c #include <string.h> #include <stdlib.h> #include <regex.h> #include <stdio.h> +#include <iceys-utils.h> -char *strremove(char *str, const char *sub) { +float map(float value, float start1, float stop1, float start2, float stop2){ + return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1)); +} + +char *str_remove_all(char *str, const char *sub) { size_t len = strlen(sub); if (len > 0) { char *p = str; @@ -18,12 +21,7 @@ char *strremove(char *str, const char *sub) { 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){ +void str_before_nth(char *str, char *str2, char eraser, int found_count){ int i=0; int found=0; @@ -39,32 +37,6 @@ void str_first(char *str, char *str2, char eraser, int found_count){ 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"); @@ -116,4 +88,3 @@ int execretarr(char **return_arr, char *command){ return 0; } -#endif diff --git a/iceys-utils.h b/iceys-utils.h new file mode 100644 index 0000000..15ce86f --- /dev/null +++ b/iceys-utils.h @@ -0,0 +1,18 @@ +#ifndef iceys_utils_h +#define iceys_utils_h + + +float map(float value, float start1, float stop1, float start2, float stop2); + +// remove all strings in str that match sub +char *str_remove_all(char *str, const char *sub); + +// look for character eraser and delete everything after it putting it in str2 +void str_before_nth(char *str, char *str2, char eraser, int found_count); + +// execute command into buffer +int execret(char *return_buffer, char *command); + +// execute command into array of buffers +int execretarr(char **return_arr, char *command); +#endif |
