Compare commits
No commits in common. "fabianq" and "dev" have entirely different histories.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"user": "borysr",
|
||||
"email": "borysr@gmail.com",
|
||||
"remotes": [
|
||||
{
|
||||
"name": "r",
|
||||
"protocol": "http",
|
||||
"domain": "qstack.pl",
|
||||
"port": "3000",
|
||||
"token_name": "t",
|
||||
"token": "8ee3f1b7980197aeceadee3cf4d980f817d44f06",
|
||||
"group": "1i-2023",
|
||||
"project": "homework"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
Binary file not shown.
|
@ -22,11 +22,7 @@ CFLAGS+= -g
|
|||
|
||||
|
||||
LDFLAGS+=-nostdlib
|
||||
<<<<<<< HEAD
|
||||
LDFLAGS+=-Wl,-Ttext=0x00000000
|
||||
=======
|
||||
LDFLAGS+=-Wl,-Ttext=0x80000000
|
||||
>>>>>>> origin/fabian
|
||||
|
||||
# see: https://github.com/riscv/riscv-gcc/issues/120
|
||||
#LDFLAGS+=-Wl,--no-relax
|
||||
|
|
11
cpp/Makefile
11
cpp/Makefile
|
@ -2,7 +2,6 @@ TOP=./
|
|||
include $(TOP)/Make.rules
|
||||
|
||||
LDLIBS=
|
||||
<<<<<<< HEAD
|
||||
#CFLAGS+=-O0 -g
|
||||
# CFLAGS+=-Og -ggdb3
|
||||
CFLAGS+=-O0 -ggdb3
|
||||
|
@ -10,22 +9,12 @@ CFLAGS+=-O0 -ggdb3
|
|||
LDFLAGS+=-Wl,--no-relax
|
||||
LDFLAGS+=-Wl,-Ttext=0x80000000,-Tdata=0x80010000
|
||||
# LDFLAGS+=-T murax_128k_ram.ld
|
||||
=======
|
||||
CFLAGS+=-O0 -g
|
||||
|
||||
LDFLAGS+=-Wl,--no-relax
|
||||
LDFLAGS+=-Wl,-Tdata=0x10000
|
||||
>>>>>>> origin/fabian
|
||||
|
||||
PROGS=prog prog.bin prog.lst
|
||||
|
||||
all:: $(PROGS)
|
||||
|
||||
<<<<<<< HEAD
|
||||
prog: _crt0.o _rvmain.o myfunc.o
|
||||
=======
|
||||
prog: _crt0.o _rvmain.o myfunc.o myfuncStruct.o myfuncStructOOP.o myfuncOOP.o
|
||||
>>>>>>> origin/fabian
|
||||
$(LINK.cc) -o $@ $^ $(LDLIBS)
|
||||
$(SIZE) -A -x $@
|
||||
|
||||
|
|
|
@ -9,20 +9,12 @@ _start:
|
|||
la gp, __global_pointer$
|
||||
.option pop
|
||||
|
||||
<<<<<<< HEAD
|
||||
li sp, 0x800ffff0
|
||||
|
||||
=======
|
||||
li sp, 0x80020000
|
||||
>>>>>>> origin/fabian
|
||||
# Clear the bss segment
|
||||
la a0, __bss_start
|
||||
la a1, __BSS_END__
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
j finish_bss
|
||||
>>>>>>> origin/fabian
|
||||
clear_bss:
|
||||
bgeu a0, a1, finish_bss
|
||||
sb x0, 0(a0)
|
||||
|
|
BIN
cpp/_crt0.o
BIN
cpp/_crt0.o
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
riscv64-unknown-elf-objdump -S --disassemble prog > prog.dis
|
|
@ -1 +0,0 @@
|
|||
readelf -S -W prog
|
|
@ -1,4 +1,3 @@
|
|||
<<<<<<< HEAD
|
||||
#include <stdint.h>
|
||||
|
||||
int strlen(char *s) {
|
||||
|
@ -162,23 +161,3 @@ int main() {
|
|||
|
||||
// p[6].str = all
|
||||
// p[6].len = 3
|
||||
=======
|
||||
#include <stdio.h>
|
||||
|
||||
size_t my_strlen(const char *str) {
|
||||
size_t len = 0;
|
||||
while (*str++) {
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int main() {
|
||||
const char *test_string = "Hello, world!";
|
||||
size_t length = my_strlen(test_string);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
>>>>>>> origin/fabian
|
||||
|
|
|
@ -1,142 +0,0 @@
|
|||
#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 * str;
|
||||
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) {
|
||||
static 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) {
|
||||
static_str = str;
|
||||
}
|
||||
|
||||
// Jeśli static_str jest NULL, zwróć NULL
|
||||
if (static_str == NULL) {
|
||||
return (char *) NULL;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
////func alg
|
||||
//in: ptr to date
|
||||
//return: count of words
|
||||
int alg (const char * ptr) {
|
||||
|
||||
char bufer[ALLOCSIZE];
|
||||
strcpy(bufer, (char *)ptr);
|
||||
|
||||
const char *delims = " ,.!?:;\n\t";
|
||||
|
||||
int8_t count = 0;
|
||||
|
||||
char *token = simple_strtok(bufer, delims);
|
||||
while (token != (char *)NULL) {
|
||||
count++;
|
||||
token = simple_strtok((char *)NULL, delims);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
const char *str = "If wantered relation no surprise of all";
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
BIN
cpp/_rvmain.o
BIN
cpp/_rvmain.o
Binary file not shown.
17
cpp/gdb/z.py
17
cpp/gdb/z.py
|
@ -1,17 +0,0 @@
|
|||
# set args 0x1FF80 0x80 0x30
|
||||
# source gdb/z.py
|
||||
|
||||
import gdb
|
||||
import sys
|
||||
|
||||
# Parse arguments from the GDB command
|
||||
args = gdb.string_to_argv(gdb.parameter("args"))
|
||||
if len(args) != 3:
|
||||
print("Usage: source gdb/zero_with_params.py <start_address> <num_bytes> <pattern>")
|
||||
else:
|
||||
start_address = int(args[0], 16) # Convert start address from hex to int
|
||||
num_bytes = int(args[1], 16) # Convert number of bytes from hex to int
|
||||
pattern = int(args[2], 16) # Convert pattern from hex to int
|
||||
|
||||
for i in range(num_bytes):
|
||||
gdb.execute("set *((char*)%x + %x) = %x" % (start_address, i, pattern))
|
|
@ -1,5 +0,0 @@
|
|||
#source gdb/z.py
|
||||
|
||||
import gdb
|
||||
for i in range(0, 128): # 128 bajtów
|
||||
gdb.execute("set *((char*)(0x1FF80 + %x)) = 0xaa" % i)
|
BIN
cpp/myfunc.o
BIN
cpp/myfunc.o
Binary file not shown.
|
@ -1,38 +0,0 @@
|
|||
#include "myfuncOOP.hpp"
|
||||
|
||||
MyfuncOOP::MyfuncOOP(const char* alfabet, const char* slowo, uint8_t* wynik)
|
||||
: alfabet(alfabet), slowo(slowo), wynik(wynik) {
|
||||
}
|
||||
|
||||
void MyfuncOOP::countCharacters() {
|
||||
int alfabet_length = myStrlen(alfabet);
|
||||
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
wynik[i] = 0; // Initialize counts to zero
|
||||
}
|
||||
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
for (int j = 0; slowo[j] != '\0'; ++j) {
|
||||
if (alfabet[i] == slowo[j]) {
|
||||
wynik[i]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const uint8_t* MyfuncOOP::getResults() const {
|
||||
return wynik;
|
||||
}
|
||||
|
||||
int MyfuncOOP::myStrlen(const char* str) {
|
||||
int length = 0;
|
||||
while (str[length] != '\0') {
|
||||
++length;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
// MyfuncOOP zliczacz(alfabet, slowo, wynik);
|
||||
// zliczacz.countCharacters();
|
||||
// const uint8_t* results = zliczacz.getResults();
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef MYFUNC_OOP_HPP
|
||||
#define MYFUNC_OOP_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
class MyfuncOOP {
|
||||
public:
|
||||
MyfuncOOP(const char* alfabet, const char* slowo, uint8_t* wynik);
|
||||
|
||||
void countCharacters();
|
||||
|
||||
const uint8_t* getResults() const;
|
||||
|
||||
private:
|
||||
const char* alfabet;
|
||||
const char* slowo;
|
||||
uint8_t* wynik;
|
||||
|
||||
static int myStrlen(const char* str);
|
||||
};
|
||||
|
||||
#endif // MYFUNC_OOP_HPP
|
BIN
cpp/myfuncOOP.o
BIN
cpp/myfuncOOP.o
Binary file not shown.
|
@ -1,29 +0,0 @@
|
|||
#include "myfuncStruct.h"
|
||||
|
||||
// Static function for string length calculation
|
||||
static int my_strlen(const char *str) {
|
||||
int length = 0;
|
||||
while (str[length] != '\0') {
|
||||
length++;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
// Function to count occurrences of each character in 'alfabet' within 'slowo'
|
||||
void count_charactersStruct(ZliczaczStruct* zliczacz) {
|
||||
int alfabet_length = my_strlen(zliczacz->alfabet);
|
||||
|
||||
// Initialize the result array to zero
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
zliczacz->wynik[i] = 0;
|
||||
}
|
||||
|
||||
// Count occurrences
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
for (int j = 0; zliczacz->slowo[j] != '\0'; ++j) {
|
||||
if (zliczacz->alfabet[i] == zliczacz->slowo[j]) {
|
||||
zliczacz->wynik[i]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
#ifndef MYFUNCSTRUCT_H
|
||||
#define MYFUNCSTRUCT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
const char* alfabet;
|
||||
const char* slowo;
|
||||
uint8_t* wynik; // Pointer to an array for results
|
||||
} ZliczaczStruct;
|
||||
|
||||
// Function declaration for counting character occurrences
|
||||
void count_charactersStruct(ZliczaczStruct* zliczacz);
|
||||
|
||||
#endif // MYFUNCSTRUCT_H
|
Binary file not shown.
|
@ -1,44 +0,0 @@
|
|||
#include "myfuncStructOOP.h"
|
||||
|
||||
// Static function for string length calculation
|
||||
static int my_strlen(const char *str) {
|
||||
int length = 0;
|
||||
while (str[length] != '\0') {
|
||||
length++;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
// 'Method' to count occurrences of each character
|
||||
static void count_charactersStructOOP(ZliczaczStructOOP* zliczacz) {
|
||||
int alfabet_length = my_strlen(zliczacz->alfabet);
|
||||
|
||||
// Initialize the result array to zero
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
zliczacz->wynik[i] = 0;
|
||||
}
|
||||
|
||||
// Count occurrences
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
for (int j = 0; zliczacz->slowo[j] != '\0'; ++j) {
|
||||
if (zliczacz->alfabet[i] == zliczacz->slowo[j]) {
|
||||
zliczacz->wynik[i]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor-like function to initialize a ZliczaczStructOOP
|
||||
void initializeZliczaczStructOOP(ZliczaczStructOOP* zliczacz, const char* alfabet, const char* slowo, uint8_t* wynik) {
|
||||
zliczacz->alfabet = alfabet;
|
||||
zliczacz->slowo = slowo;
|
||||
zliczacz->wynik = wynik;
|
||||
zliczacz->count_characters = count_charactersStructOOP;
|
||||
}
|
||||
|
||||
// #include "myfuncStructOOP.h"
|
||||
|
||||
// ZliczaczStructOOP zliczacz;
|
||||
// initializeZliczaczStructOOP(&zliczacz, alfabet, slowo, wynik);
|
||||
|
||||
// zliczacz.count_characters(&zliczacz);
|
|
@ -1,21 +0,0 @@
|
|||
#ifndef MYFUNCSTRUCTOOP_H
|
||||
#define MYFUNCSTRUCTOOP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct ZliczaczStructOOP ZliczaczStructOOP;
|
||||
|
||||
struct ZliczaczStructOOP {
|
||||
// Data members
|
||||
const char* alfabet;
|
||||
const char* slowo;
|
||||
uint8_t* wynik; // Pointer to an array for results
|
||||
|
||||
// Function pointers, acting as 'methods'
|
||||
void (*count_characters)(ZliczaczStructOOP*);
|
||||
};
|
||||
|
||||
void initializeZliczaczStructOOP(ZliczaczStructOOP* zliczacz, const char* alfabet, const char* slowo, uint8_t* wynik);
|
||||
|
||||
|
||||
#endif // MYFUNCSTRUCTOOP_H
|
Binary file not shown.
BIN
cpp/prog.bin
BIN
cpp/prog.bin
Binary file not shown.
4083
cpp/prog.lst
4083
cpp/prog.lst
File diff suppressed because it is too large
Load Diff
BIN
cpp/program
BIN
cpp/program
Binary file not shown.
|
@ -1,5 +0,0 @@
|
|||
_crt0.S
|
||||
main.cpp
|
||||
myfunc.cpp
|
||||
myfunc.h
|
||||
_rvmain.cc
|
16
cpp/try/3.py
16
cpp/try/3.py
|
@ -1,16 +0,0 @@
|
|||
import asyncio
|
||||
import websockets
|
||||
|
||||
async def consume_ws_latest_records():
|
||||
uri = "ws://172.24.0.3:3333/ws_latest_records"
|
||||
|
||||
async with websockets.connect(uri) as websocket:
|
||||
while True:
|
||||
message = input("Enter a message to send: ")
|
||||
await websocket.send(message)
|
||||
|
||||
response = await websocket.recv()
|
||||
print(f"Received from server: {response}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.get_event_loop().run_until_complete(consume_ws_latest_records())
|
|
@ -1 +0,0 @@
|
|||
g++ -std=c++17 -o websocket-client-sync main.cpp myfunc.cpp -lboost_system -lboost_thread -lboost_coroutine -ljsoncpp
|
|
@ -1 +0,0 @@
|
|||
./websocket-client-sync ws://localhost:3333/ws
|
155
cpp/try/main.cpp
155
cpp/try/main.cpp
|
@ -1,155 +0,0 @@
|
|||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <boost/asio/connect.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <jsoncpp/json/json.h>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <regex>
|
||||
|
||||
namespace beast = boost::beast;
|
||||
namespace websocket = beast::websocket;
|
||||
namespace net = boost::asio;
|
||||
using tcp = boost::asio::ip::tcp;
|
||||
|
||||
struct Person {
|
||||
std::string name;
|
||||
int age;
|
||||
long long timestamp;
|
||||
};
|
||||
|
||||
Json::Value serializePerson(const Person& person) {
|
||||
Json::Value jsonPerson;
|
||||
jsonPerson["name"] = person.name;
|
||||
jsonPerson["age"] = person.age;
|
||||
jsonPerson["timestamp"] = static_cast<Json::Value::Int64>(person.timestamp);
|
||||
return jsonPerson;
|
||||
}
|
||||
|
||||
std::tuple<std::string, std::string, std::string> parseURI(const std::string& uri) {
|
||||
std::regex uriRegex(R"(^ws://([^:/]+):(\d+)(/.+)$)");
|
||||
std::smatch match;
|
||||
|
||||
if (std::regex_match(uri, match, uriRegex)) {
|
||||
return std::make_tuple(match[1].str(), match[2].str(), match[3].str());
|
||||
} else {
|
||||
throw std::invalid_argument("Nieprawidłowe URI");
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T getInput(const std::string& prompt) {
|
||||
T value;
|
||||
while (true) {
|
||||
std::cout << prompt;
|
||||
std::cin >> value;
|
||||
|
||||
if (std::cin.fail()) {
|
||||
std::cin.clear();
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
std::cerr << "Błąd! Spróbuj ponownie." << std::endl;
|
||||
} else {
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void iterateCharBuffer(const char* charBuffer, std::size_t bufferSize) {
|
||||
for (std::size_t i = 0; i < bufferSize; ++i) {
|
||||
std::cout << charBuffer[i];
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
// Example: Call the function you want to apply to the char buffer
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
try {
|
||||
if (argc != 2) {
|
||||
std::cerr << "Sposób użycia: " << argv[0] << " <adres URI>\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
std::string uri = argv[1];
|
||||
auto uriParts = parseURI(uri);
|
||||
std::string host, port, endpoint;
|
||||
std::tie(host, port, endpoint) = uriParts;
|
||||
|
||||
net::io_context io_context;
|
||||
|
||||
websocket::stream<tcp::socket> ws(io_context);
|
||||
tcp::resolver resolver(io_context);
|
||||
auto endpoints = resolver.resolve(host, port);
|
||||
net::connect(ws.next_layer(), endpoints);
|
||||
|
||||
ws.handshake(host, endpoint);
|
||||
|
||||
while (true) {
|
||||
std::cout << "Menu:\n";
|
||||
std::cout << "1. Dodaj rekord\n";
|
||||
std::cout << "2. Zwróć ostatnie rekordy\n";
|
||||
std::cout << "3. Wyjście\n";
|
||||
|
||||
int choice = getInput<int>("Wybierz opcję: ");
|
||||
|
||||
if (choice == 1) {
|
||||
|
||||
std::string name = getInput<std::string>("Podaj imię: ");
|
||||
int age = getInput<int>("Podaj wiek: ");
|
||||
|
||||
Person personToSend{name, age, std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch()).count()};
|
||||
|
||||
Json::Value jsonPerson = serializePerson(personToSend);
|
||||
|
||||
ws.write(net::buffer(Json::writeString(Json::StreamWriterBuilder(), jsonPerson)));
|
||||
|
||||
} else if (choice == 2) {
|
||||
|
||||
ws.write(net::buffer("get_latest_records"));
|
||||
|
||||
beast::flat_buffer buffer;
|
||||
ws.read(buffer);
|
||||
|
||||
std::cout << "Otrzymano: " << beast::make_printable(buffer.data()) << std::endl;
|
||||
|
||||
const char* bufferData = boost::asio::buffer_cast<const char*>(buffer.data());
|
||||
std::size_t bufferSize = boost::asio::buffer_size(buffer.data());
|
||||
|
||||
char* charBuffer = new char[bufferSize + 1];
|
||||
std::memcpy(charBuffer, bufferData, bufferSize);
|
||||
charBuffer[bufferSize] = '\0';
|
||||
|
||||
iterateCharBuffer(charBuffer, bufferSize);
|
||||
|
||||
delete[] charBuffer;
|
||||
|
||||
buffer.consume(buffer.size());
|
||||
|
||||
} else if (choice == 3) {
|
||||
|
||||
std::cout << "Zamykanie programu...\n";
|
||||
break;
|
||||
|
||||
} else {
|
||||
|
||||
std::cout << "Nieprawidłowy wybór. Spróbuj ponownie.\n";
|
||||
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
} catch (std::exception const& e) {
|
||||
std::cerr << "Błąd: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
#include <iostream>
|
||||
#include <tuple>
|
||||
#include <regex>
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/beast.hpp>
|
||||
#include <jsoncpp/json/json.h>
|
||||
|
||||
namespace beast = boost::beast;
|
||||
namespace websocket = beast::websocket;
|
||||
namespace net = boost::asio;
|
||||
using tcp = boost::asio::ip::tcp;
|
||||
|
||||
std::tuple<std::string, std::string, std::string> parseURI(const std::string& uri) {
|
||||
std::regex uriRegex(R"(^ws://([^:/]+):(\d+)(/.+)$)");
|
||||
std::smatch match;
|
||||
|
||||
if (std::regex_match(uri, match, uriRegex)) {
|
||||
return std::make_tuple(match[1].str(), match[2].str(), match[3].str());
|
||||
} else {
|
||||
throw std::invalid_argument("Nieprawidłowe URI");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::string uri = "ws://172.24.0.3:3333";
|
||||
std::cout << "Dostarczone URI: " << uri << std::endl;
|
||||
|
||||
try {
|
||||
auto uriParts = parseURI(uri);
|
||||
std::string host, port, endpoint;
|
||||
std::tie(host, port, endpoint) = uriParts;
|
||||
|
||||
net::io_context io_context;
|
||||
|
||||
// Utwórz obiekt WebSocket
|
||||
websocket::stream<tcp::socket> ws(io_context);
|
||||
|
||||
// Połącz z serwerem WebSocket
|
||||
tcp::resolver resolver(io_context);
|
||||
auto endpoints = resolver.resolve(host, port);
|
||||
net::connect(ws.next_layer(), endpoints);
|
||||
|
||||
// Wysyłanie danych na serwer WebSocket
|
||||
ws.handshake(host, endpoint);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Błąd: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
https://www.mediafire.com/file/c5d9ad65bxiln6o/MojaGra1.zip/file
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
import argparse
|
||||
import json
|
||||
import sys
|
||||
import subprocess
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
DEFAULT_CONFIG = {
|
||||
"user": "borysr",
|
||||
"email": "borysr@gmail.com",
|
||||
"remotes": [{
|
||||
"name": "r", # Zaktualizowano z "default" na "mpabi"
|
||||
"protocol": "http",
|
||||
"domain": "qstack.pl",
|
||||
"port": "3000",
|
||||
"token_name": "t",
|
||||
"token": "8ee3f1b7980197aeceadee3cf4d980f817d44f06",
|
||||
"group": "1i-2023",
|
||||
"project": "homework"
|
||||
}]
|
||||
}
|
||||
|
||||
def load_or_create_config(config_file, args):
|
||||
config_exists = os.path.exists(config_file) and os.stat(config_file).st_size != 0
|
||||
if config_exists:
|
||||
with open(config_file, 'r') as file:
|
||||
config = json.load(file)
|
||||
else:
|
||||
config = DEFAULT_CONFIG.copy()
|
||||
|
||||
# Znajdź istniejące zdalne repozytorium o podanej nazwie
|
||||
remote = next((remote for remote in config['remotes'] if remote['name'] == args.remote), None)
|
||||
|
||||
# Jeśli istnieje zdalne repozytorium i podano argumenty związane z konfiguracją zdalnego repozytorium
|
||||
if remote:
|
||||
for field in ['protocol', 'domain', 'port', 'token_name', 'token', 'group', 'project']:
|
||||
# Aktualizuj tylko, jeśli argument został jawnie podany
|
||||
if getattr(args, field, None) is not None:
|
||||
remote[field] = getattr(args, field)
|
||||
|
||||
# Jeśli zdalne repozytorium nie istnieje, ale podano nazwę, tworzymy nowe zdalne repozytorium
|
||||
elif args.remote:
|
||||
new_remote = {'name': args.remote}
|
||||
for field in ['protocol', 'domain', 'port', 'token_name', 'token', 'group', 'project']:
|
||||
new_remote[field] = getattr(args, field, DEFAULT_CONFIG['remotes'][0].get(field, ''))
|
||||
if new_remote[field] == None:
|
||||
new_remote[field] = DEFAULT_CONFIG['remotes'][0].get(field, '')
|
||||
config['remotes'].append(new_remote)
|
||||
|
||||
# Aktualizuj informacje o użytkowniku i email, tylko jeśli zostały podane
|
||||
if getattr(args, 'user', None):
|
||||
config['user'] = args.user
|
||||
if getattr(args, 'email_domain', None):
|
||||
config['email'] = f"{args.user}@{args.email_domain}"
|
||||
|
||||
# Zapisz zmodyfikowaną konfigurację
|
||||
with open(config_file, 'w') as file:
|
||||
json.dump(config, file, indent=4)
|
||||
|
||||
return config
|
||||
|
||||
|
||||
def init_git_repo(config):
|
||||
user_name = config['user']
|
||||
user_email = config['email']
|
||||
branch_name = f"{user_name}-{datetime.now().strftime('%Y-%m-%d')}"
|
||||
|
||||
if subprocess.run(["git", "rev-parse", "--git-dir"], stderr=subprocess.DEVNULL).returncode != 0:
|
||||
subprocess.run(["git", "init"])
|
||||
subprocess.run(["git", "config", "user.name", user_name])
|
||||
subprocess.run(["git", "config", "user.email", user_email])
|
||||
subprocess.run(["git", "checkout", "-b", branch_name])
|
||||
print("Git repository initialized.")
|
||||
else:
|
||||
print("Already inside a Git repository. Skipping initialization.")
|
||||
|
||||
remotesFromList = str(subprocess.run(["git", "remote", "-v"], capture_output=True).stdout)
|
||||
remotesFromList = remotesFromList.replace('b\'', "").replace('\'', "").split('\\n')
|
||||
for rm in remotesFromList:
|
||||
name = rm.split("\\t")[0]
|
||||
subprocess.run(["git", "remote", "remove", name], stderr=subprocess.DEVNULL)
|
||||
|
||||
for remote in config['remotes']:
|
||||
remote_url = f"{remote['protocol']}://{remote['token_name']}:{remote['token']}@{remote['domain']}:{remote['port']}/{remote['group']}/{remote['project']}"
|
||||
# Usunięcie i ponowne dodanie zdalnego repozytorium, jeśli jest zaktualizowane
|
||||
#subprocess.run(["git", "remote", "remove", remote['name']], stderr=subprocess.DEVNULL)
|
||||
subprocess.run(["git", "remote", "add", remote['name'], remote_url])
|
||||
print(f"Remote '{remote['name']}' added or updated.")
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Git repository initializer with custom configuration.")
|
||||
parser.add_argument("--user", help="User name")
|
||||
parser.add_argument("--email_domain", help="Email domain")
|
||||
parser.add_argument("--config", help="Path to the JSON config file", default="conf.json")
|
||||
parser.add_argument("--remote", help="Name of the remote to add or update")
|
||||
parser.add_argument("--protocol", help="Remote protocol")
|
||||
parser.add_argument("--domain", help="Remote domain")
|
||||
parser.add_argument("--port", help="Remote port")
|
||||
parser.add_argument("--token_name", help="Remote token name")
|
||||
parser.add_argument("--token", help="Remote token")
|
||||
parser.add_argument("--group", help="Group name")
|
||||
parser.add_argument("--project", help="Project name")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
config = load_or_create_config(args.config, args)
|
||||
init_git_repo(config)
|
||||
print("Git repository initialized and configured based on the provided configuration.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue