#ifndef iceys_utils_c #define iceys_utils_c #include #include #include #include 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