Skip to content

Commit

Permalink
Issue #53 on Solve , and working for #23
Browse files Browse the repository at this point in the history
  • Loading branch information
amanuel2 committed Dec 9, 2016
1 parent 5b6163b commit efdb49e
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 5 deletions.
3 changes: 3 additions & 0 deletions arch/i386/init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ void kernelMain(multiboot_info_t* multiboot_structure,uint32_t magicnumber)
sti();

video_drivers[VGA_VIDEO_DRIVER_INDEX]->clear();
char *s = "kkekerkernkernelernelrnelnelell";
str_t ss = strstr(s, "kernel");
printk("HERE:%s",ss.str);
init_terminal();

while(1)
Expand Down
10 changes: 10 additions & 0 deletions include/libc/string/str_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _STRING_STR_T_
#define _STRING_STR_T_

typedef
struct
{
char str[200];
}str_t;

#endif /*_STRING_STR_T_*/
1 change: 1 addition & 0 deletions include/libc/string/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "strlen/strlen.h"
#include "strcat/strcat.h"
#include "strcmp/strcmp.h"
#include "strstr/strstr.h"
#include "eat_front_whitespace/eat_front_whitespace.h"
#include "validate_char/validate_char.h"
#include "memmove/memmove.h"
Expand Down
8 changes: 8 additions & 0 deletions include/libc/string/strstr/strstr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _LIBC_STRING_STRSTR_H_
#define _LIBC_STRING_STRSTR_H_

#include <str_t.h>

extern str_t strstr(char* __str, char* __substr);

#endif /*_LIBC_STRING_STRSTR_H_*/
6 changes: 1 addition & 5 deletions include/libc/unistd/get_opt/get_opt.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#ifndef _LIBC_UNISTD_GETOPT_H_
#define _LIBC_UNISTD_GETOPT_H_

typedef
struct
{
char str[200];
}str_t;
#include <str_t.h>


extern void get_opt(const char* s, str_t str_p[]);
Expand Down
1 change: 1 addition & 0 deletions libc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CSRCS = \
string/memmove/memmove.c \
string/eat_front_whitespace/eat_front_whitespace.c \
string/validate_char/validate_char.c \
string/strstr/strstr.c \
stdio/printck/printck.c \
stdlib/itoa/itoa.c \
stdlib/atoi/atoi.c \
Expand Down
84 changes: 84 additions & 0 deletions libc/string/strstr/strstr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
** This file is part of BoneOS.
**
** BoneOS is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
** BoneOS is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Amanuel Bogale
**
** @contributors:
** Amanuel Bogale <amanuel2> : start
**/

/*
* @function strstr:
* Returns substring + rest of
* string , from the string.
*
* @param __str (char*):
* Specified string
* to find substring from.
*
* @param __substr (char*):
* the Substring to be searched
* for.
* @return (str_t):
* Returns the substring + rest
* of string.
*/

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <strstr/strstr.h>
#include <strlen/strlen.h>
#include <strcmp/strcmp.h>

str_t strstr(char* __str, char* __substr)
{
size_t strlen__substr = strlen(__substr);
size_t strlen__str = strlen(__str);
char __temp[strlen__substr];
str_t __return_str;
int __start_index=0;
bool __found=false;

int index=0;
while(__str[index])
{
if(__str[index] == __substr[0])
{
int i=0;
for(; __substr[i]; i++)
__temp[i] = __str[i+index];

if(strcmp(__temp,__substr)==0)
{
__start_index = (i+index)-strlen__substr;
__found=true;
for(uint32_t i=__start_index,j=0; i<strlen__str;i++,j++)
__return_str.str[j]=__str[i];
}
index++;
}
else
index++;
}

if(__found==false)
__return_str.str[0] = 0;
return __return_str;
}

0 comments on commit efdb49e

Please sign in to comment.