-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.c
83 lines (76 loc) · 1.94 KB
/
utilities.c
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
#include "header.h"
void addProc(char* name, pid_t pid) {
printf("Adding Process: %s with pid: %d and length: %d\n", name, pid, plen);
processes[plen].name = name;
processes[plen].pid = pid;
processes[plen].srno = plen + 1;
processes[plen].display = true;
plen++;
}
void delProc(pid_t pid) {
for(int i=0;i<plen;i++) {
if(processes[i].pid == pid) {
processes[i].display = false;
processes[i].pid = -1;
}
}
}
char* removeSpace(char* line) {
size_t linelen = strlen(line);
size_t newlen = MAXLEN;
char* newline = (char *) malloc(sizeof(char)*newlen);
char prev = ' ';
long index = 0;
for(long i=0;i<linelen;i++) {
if (prev == ' ' && line[i] == ' ') {
;
} else {
newline[index] = line[i];
index++;
}
prev = line[i];
}
newline[index] = '\0';
return newline;
}
char* strip(char* string) {
char* copy = string;
printf("copy: %s\n", copy);
size_t size = strlen(copy);
char* end;
if (!size || (copy[0] != ' ' && copy[size-1] != ' ')) {
printf("final: %s\n", copy);
return copy;
} else {
end = copy + size - 1;
while(end >= copy && isspace(*end)) {
end--;
}
*(end+1) = '\0';
while(*copy && isspace(copy)) {
copy++;
}
printf("final: %s\n", copy);
return copy;
}
}
char* fileName(char* string, long len) {
char* file = (char *) malloc(sizeof(char)*len);
long index = 0;
for(long i=0;i<len;i++) {
if(string[i] == '/') {
free(file);
char* file = (char *) malloc(sizeof(char)*len);
index = 0;
} else {
file[index] = string[i];
index++;
}
}
file[index] = '\0';
return file;
}
char* findChar(char* string, char c) {
char* pointer = strchr(string, c);
return pointer;
}