1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#include <string.h>
#include <stdlib.h>
#include <regex.h>
#include <stdio.h>
#include <iceys-utils.h>
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;
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;
}
void str_before_nth(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);
}
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;
}
|