Skip to content

Commit 4a420e2

Browse files
committed
* Implemented most of string operations
* Updated system.h * Incremented kernel version * Updated README.md
1 parent 734c4ca commit 4a420e2

File tree

5 files changed

+190
-17
lines changed

5 files changed

+190
-17
lines changed

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A new rewrite of SectorOS_RE2.
44

5-
The kernel is currently v0.23.03.2ALPR
5+
The kernel is currently v0.23.03.3ALPR
66

77
## Build
88

docs/changelog.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@
2626
* Moved reboot function to its own file
2727
* Updated Makefile
2828
* Removed system.c
29-
* Updated system.h
29+
* Updated system.h
30+
31+
27-03-2023: 06:45 PM IST v0.23.03.3ALPR
32+
* Implemented most of string operations
33+
* Updated system.h
34+
* Incremented kernel version
35+
* Updated README.md

src/common/libs/string.c

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,167 @@ char* strstr(const char* in, const char* str)
142142
} while (strncmp(in, str, len) != 0);
143143

144144
return (char *)(in - 1);
145+
}
146+
147+
148+
void strcat(void *dest, const void *src)
149+
{
150+
char *end = (char *)dest + strlen((char*)dest);
151+
memcpy((char *)end, (char *)src, strlen((char *)src));
152+
end = end + strlen((char *)src);
153+
*end = '\0';
154+
}
155+
156+
157+
void itoa(char *buf, unsigned long int n, int base)
158+
{
159+
unsigned long int tmp;
160+
int i, j;
161+
162+
tmp = n;
163+
i = 0;
164+
165+
do
166+
{
167+
tmp = n % base;
168+
buf[i++] = (tmp < 10) ? (tmp + '0') : (tmp + 'a' - 10);
169+
} while (n /= base);
170+
buf[i--] = 0;
171+
172+
for (j = 0; j < i; j++, i--)
173+
{
174+
tmp = buf[j];
175+
buf[j] = buf[i];
176+
buf[i] = tmp;
177+
}
178+
}
179+
180+
int atoi(char *string)
181+
{
182+
int result = 0;
183+
unsigned int digit;
184+
int sign;
185+
186+
while (isspace(*string))
187+
{
188+
string += 1;
189+
}
190+
191+
if (*string == '-')
192+
{
193+
sign = 1;
194+
string += 1;
195+
}
196+
else
197+
{
198+
sign = 0;
199+
if (*string == '+')
200+
{
201+
string += 1;
202+
}
203+
}
204+
205+
for (;; string += 1)
206+
{
207+
digit = *string - '0';
208+
if (digit > 9)
209+
{
210+
break;
211+
}
212+
result = (10 * result) + digit;
213+
}
214+
215+
if (sign)
216+
{
217+
return -result;
218+
}
219+
return result;
220+
}
221+
222+
223+
char* itoa_r(unsigned long int n, int base)
224+
{
225+
}
226+
227+
int isspace(char c)
228+
{
229+
return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
230+
}
231+
232+
uint32_t chbc(char* str, char c)
233+
{
234+
uint32_t i = 0;
235+
while (str[i] != '\0')
236+
{
237+
if (str[i] == c)
238+
return i;
239+
i++;
240+
}
241+
return -1;
242+
}
243+
244+
int isprint(char c)
245+
{
246+
return ((c >= ' ' && c <= '~') ? 1 : 0);
247+
}
248+
249+
char *strdup(const char *src)
250+
{
251+
}
252+
253+
char *strndup(const char *src, uint32_t len)
254+
{
255+
}
256+
257+
char *strsep(char **stringp, const char *delim) {
258+
char *s;
259+
const char *spanp;
260+
int c, sc;
261+
char *tok;
262+
if ((s = *stringp) == NULL)
263+
return (NULL);
264+
for (tok = s;;) {
265+
c = *s++;
266+
spanp = delim;
267+
do {
268+
if ((sc = *spanp++) == c) {
269+
if (c == 0)
270+
s = NULL;
271+
else
272+
s[-1] = 0;
273+
*stringp = s;
274+
return (tok);
275+
}
276+
} while (sc != 0);
277+
}
278+
}
279+
280+
bool alloc = false;
281+
282+
void stoc(size_t n, char* buf)
283+
{
284+
if(((n / MB) >> 10) != 0)
285+
{
286+
strcpy(buf, itoa_r(n / GB, 10));
287+
strcat(buf, "GB");
288+
}
289+
else if (((n / KB) >> 10) != 0)
290+
{
291+
strcpy(buf, itoa_r(n / MB, 10));
292+
strcat(buf, "MB");
293+
}
294+
else if (((n) >> 10) != 0)
295+
{
296+
strcpy(buf, itoa_r(n / KB, 10));
297+
strcat(buf, "KB");
298+
}
299+
else
300+
{
301+
strcpy(buf, itoa_r(n, 10));
302+
strcat(buf, "B");
303+
}
304+
}
305+
306+
char* stoc_r(size_t n)
307+
{
145308
}

src/include/string.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
int memcmp(uint8_t *data1, uint8_t *data2, int n); //* Implemented
77
void *memcpy(void *dst, const void *src, int n); //* Implemented
88

9-
uint16_t *memsetw(uint16_t *dest, uint16_t val, uint32_t count);
10-
uint16_t *memsetdw(uint32_t *dest, uint32_t val, uint32_t count);
9+
uint16_t *memsetw(uint16_t *dest, uint16_t val, uint32_t count); //! Not implemented
10+
uint16_t *memsetdw(uint32_t *dest, uint32_t val, uint32_t count); //! Not implemented
1111
void *memset(void *dst, char val, int n); //* Implemented
1212

1313
int strlen(const char *s); //* Implemented
@@ -19,21 +19,21 @@ int strcmp(const char *dst, char *src); //* Implemented
1919
int strncmp(const char *s1, const char *s2, int c); //* Implemented
2020

2121
char *strstr(const char *in, const char *str); //* Implemented
22-
void strcat(void *dest, const void *src);
22+
void strcat(void *dest, const void *src); //* Implemented
2323

24-
char* itoa_r(unsigned long int n, int base);
25-
void itoa(char *buf, unsigned long int n, int base);
26-
int atoi(char *string);
24+
char* itoa_r(unsigned long int n, int base); //! Not implemented
25+
void itoa(char *buf, unsigned long int n, int base); //* Implemented
26+
int atoi(char *string); //* Implemented
2727

28-
int isspace(char c);
29-
int isprint(char c);
28+
int isspace(char c); //* Implemented
29+
int isprint(char c); //* Implemented
3030

31-
char *strdup(const char *src);
32-
char *strndup(const char *src, uint32_t len);
33-
char *strsep(char **stringp, const char *delim);
31+
char *strdup(const char *src); //! Not implemented
32+
char *strndup(const char *src, uint32_t len); //! Not implemented
33+
char *strsep(char **stringp, const char *delim); //* Implemented
3434

35-
void stoc(size_t n, char* buffer);
36-
char* stoc_r(size_t n);
37-
uint32_t chbc(char* str, char c);
35+
void stoc(size_t n, char* buffer); //? Partially implemented
36+
char* stoc_r(size_t n); //! Not implemented
37+
uint32_t chbc(char* str, char c); //* Implemented
3838

3939
#endif /*__STRING_H__*/

src/include/system.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ void kernel_panic(char* message);
2626
* RELN: index of current release in the current month
2727
* STATUS: [PR]:Prerelease, [AL]:alpha, [NR]:Normal release
2828
*/
29-
#define KERNEL_VERSION "0.23.03.2ALPR"
29+
#define KERNEL_VERSION "0.23.03.3ALPR"
30+
31+
#define KB 1024
32+
#define MB (1024*KB)
33+
#define GB (1024*MB)
3034

3135
void reboot();
3236

0 commit comments

Comments
 (0)