162 lines
3.3 KiB
C++
162 lines
3.3 KiB
C++
#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++);
|
|
}
|
|
#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;
|
|
}
|
|
|
|
// def. model danych
|
|
|
|
//pre processor
|
|
#define LEN (8+2)*10
|
|
|
|
struct model {
|
|
char * ptr;
|
|
uint32_t len ;
|
|
};
|
|
|
|
|
|
//alg
|
|
// prosta implementacji func. z bibl. std. strok przy uzyciu gpt3.5
|
|
//
|
|
|
|
#define NULL ((void*) 0)
|
|
|
|
//
|
|
// Funkcja pomocnicza do sprawdzania, czy znak jest wśród delimiterów
|
|
bool is_delim(char c, const char *delims) {
|
|
while (*delims) {
|
|
if (c == *delims) {
|
|
return true;
|
|
}
|
|
delims++;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Najprostsza implementacja funkcji strtok
|
|
char *simple_strtok(char *str, const char *delims) {
|
|
char *static_str = (char *) NULL; // Przechowuje wskaźnik do bieżącej pozycji w ciągu
|
|
|
|
// Jeśli przekazano nowy ciąg, zaktualizuj static_str
|
|
if (str == NULL) {
|
|
return (char *) NULL; // str nie wskazuje na zdanie !!!
|
|
}
|
|
static_str = str;
|
|
|
|
// " .,mpabi"
|
|
// ^
|
|
// Pomiń początkowe delimitery
|
|
while (*static_str && is_delim(*static_str, delims)) {
|
|
static_str++;
|
|
}
|
|
|
|
// Jeśli doszliśmy do końca ciągu, zwróć NULL
|
|
if (*static_str == '\0') {
|
|
return (char *) NULL;
|
|
}
|
|
|
|
// Zapisz początek tokenu
|
|
char *token_start = static_str;
|
|
|
|
|
|
//,. mpabi pabi
|
|
// Znajdź koniec tokenu
|
|
while (*static_str && !is_delim(*static_str, delims)) {
|
|
static_str++;
|
|
}
|
|
|
|
// Jeśli znaleziono delimitery, zamień je na '\0' i zaktualizuj static_str
|
|
if (*static_str) {
|
|
*static_str = '\0';
|
|
static_str++;
|
|
}
|
|
|
|
// Zwróć początek tokenu
|
|
return token_start;
|
|
}
|
|
|
|
|
|
char buf[1000];
|
|
struct model * p = (struct model *) buf; //p[1]
|
|
//
|
|
|
|
|
|
////func alg
|
|
//in: ptr to date
|
|
//return: count of words
|
|
int alg (char * ptr) {
|
|
|
|
const char *delims = " ,.!?:;\n\t";
|
|
|
|
int pos = 0;
|
|
|
|
while (char *token = simple_strtok(ptr, delims)) {
|
|
|
|
p[pos].ptr = token;
|
|
//p[pos].len = strlen(token);
|
|
p[pos].len = pos;
|
|
|
|
token = token + strlen(token) + 1;
|
|
++pos;
|
|
}
|
|
|
|
return pos;
|
|
}
|
|
|
|
/*
|
|
struct model {
|
|
char * str;
|
|
uint32_t len ;
|
|
} tab [10] ;
|
|
*/
|
|
|
|
int main() {
|
|
// Seccess is often
|
|
// ^
|
|
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.";
|
|
|
|
/*
|
|
struct model *ptr = (struct model *) alloc(LEN);
|
|
if (ptr != (struct model *)NULL) {
|
|
ptr->str = alloc(strlen((char *)str) + 1);
|
|
if (ptr->str != (char *)NULL) {
|
|
strcpy (ptr->str, (char *)str);
|
|
ptr->len = strlen(ptr->str);
|
|
|
|
int8_t count = alg(ptr->str);
|
|
}
|
|
}
|
|
*/
|
|
int w = alg(str);
|
|
asm ("nop");
|
|
|
|
return 1;
|
|
}
|