2024-05-22 17:33:42 +00:00
# include <stdint.h>
int strlen ( char * s ) {
char * p = s ;
while ( * p ! = ' \0 ' )
p + + ;
return p - s ;
}
void strcpy ( char * s , char * t )
{
while ( * s + + = * t + + ) ;
}
2024-05-25 16:39:06 +00:00
2024-05-25 17:08:02 +00:00
// Effective C++ by Scott Meyers
// page. 6
// Item 1: Prefer const and inline to #define.
//
class NewDefine {
2024-05-25 16:39:06 +00:00
private :
2024-05-25 17:08:02 +00:00
static const int ALLOCSIZE = 10000 ;
2024-05-25 16:39:06 +00:00
2024-05-25 17:08:02 +00:00
} ;
2024-05-25 16:39:06 +00:00
2024-05-25 17:08:02 +00:00
const int NewDefine : : ALLOCSIZE ;
2024-05-25 16:39:06 +00:00
2024-05-22 17:33:42 +00:00
# define ALLOCSIZE 10000
static char allocbuf [ ALLOCSIZE ] ;
static char * allocp = allocbuf ;
char * alloc ( int n )
{
if ( n % 4 ! = 0 ) {
n + = 4 - ( n % 4 ) ;
}
if ( allocbuf + ALLOCSIZE - allocp > = n ) {
allocp + = n ;
return allocp - n ;
} else
return 0 ;
}
2024-05-22 18:51:39 +00:00
// def. model danych
2024-05-22 17:33:42 +00:00
2024-05-22 18:51:39 +00:00
//pre processor
# define LEN (8+2)*10
2024-05-22 17:33:42 +00:00
2024-05-22 18:51:39 +00:00
struct model {
2024-05-24 10:20:44 +00:00
char * ptr ;
2024-05-22 18:51:39 +00:00
uint32_t len ;
} ;
2024-05-22 17:33:42 +00:00
2024-05-22 19:15:48 +00:00
//alg
// prosta implementacji func. z bibl. std. strok przy uzyciu gpt3.5
//
# define NULL ((void*) 0)
bool is_delim ( char c , const char * delims ) {
while ( * delims ) {
if ( c = = * delims ) {
return true ;
}
delims + + ;
}
return false ;
}
char * simple_strtok ( char * str , const char * delims ) {
2024-05-24 16:12:13 +00:00
char * static_str = ( char * ) NULL ; // Przechowuje wskaźnik do bieżącej pozycji w ciągu
2024-05-25 15:54:58 +00:00
if ( str ! = ( char * ) NULL ) {
static_str = str ;
}
2024-05-22 19:15:48 +00:00
2024-05-25 15:54:58 +00:00
if ( static_str = = ( char * ) NULL ) {
return ( char * ) NULL ;
2024-05-22 19:15:48 +00:00
}
2024-05-25 15:54:58 +00:00
// Skip initial delimiters
2024-05-22 19:15:48 +00:00
while ( * static_str & & is_delim ( * static_str , delims ) ) {
static_str + + ;
}
2024-05-25 15:54:58 +00:00
2024-05-22 19:15:48 +00:00
if ( * static_str = = ' \0 ' ) {
2024-05-25 15:54:58 +00:00
return ( char * ) NULL ;
2024-05-22 19:15:48 +00:00
}
char * token_start = static_str ;
2024-05-24 10:20:44 +00:00
2024-05-25 15:54:58 +00:00
// Find the end of the token
2024-05-22 19:15:48 +00:00
while ( * static_str & & ! is_delim ( * static_str , delims ) ) {
static_str + + ;
}
if ( * static_str ) {
* static_str = ' \0 ' ;
static_str + + ;
}
return token_start ;
}
2024-05-24 10:20:44 +00:00
char buf [ 1000 ] ;
2024-05-23 16:16:34 +00:00
struct model * p = ( struct model * ) buf ; //p[1]
2024-05-25 17:03:14 +00:00
< < < < < < < HEAD
2024-05-25 15:54:58 +00:00
2024-05-25 17:03:14 +00:00
= = = = = = =
> > > > > > > mpabi
2024-05-24 10:20:44 +00:00
2024-05-25 15:54:58 +00:00
int alg ( char * ptr ) {
const char * delims = " ,.!?:; \n \t " ;
int pos = 0 ;
2024-05-24 10:20:44 +00:00
2024-05-25 15:54:58 +00:00
char * token = simple_strtok ( ptr , delims ) ;
while ( token ! = ( char * ) NULL ) {
2024-05-24 10:20:44 +00:00
p [ pos ] . ptr = token ;
2024-05-25 15:54:58 +00:00
p [ pos ] . len = strlen ( token ) ;
+ + pos ;
token = simple_strtok ( ( char * ) NULL , delims ) ; // Set ptr to NULL after the first call to continue tokenizing the same string
2024-05-24 10:20:44 +00:00
}
2024-05-23 16:16:34 +00:00
2024-05-25 15:54:58 +00:00
return pos ;
2024-05-22 20:25:06 +00:00
}
2024-05-22 18:51:39 +00:00
2024-05-24 10:20:44 +00:00
int main ( ) {
char * str = " Success is often defined as the ability to reach your goals in life, whatever those goals may be. In some ways, a better word for success might be attainment, accomplishment, or progress. It is not necessarily a destination but a journey that helps develop the skills and resources you need to thrive. " ;
2024-05-23 16:16:34 +00:00
alg ( str ) ;
asm ( " nop " ) ;
2024-05-22 17:33:42 +00:00
return 1 ;
}