Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Antonako1/ATRC
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.1
Choose a base ref
...
head repository: Antonako1/ATRC
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.2
Choose a head ref
  • 4 commits
  • 12 files changed
  • 1 contributor

Commits on Jan 12, 2025

  1. Update README.md

    Antonako1 committed Jan 12, 2025
    Copy the full SHA
    5b410d3 View commit details
  2. 2.0.2

    Antonako1 committed Jan 12, 2025
    Copy the full SHA
    1832876 View commit details
  3. 2.0.2

    Antonako1 committed Jan 12, 2025
    Copy the full SHA
    b898378 View commit details
  4. Update version

    Antonako1 committed Jan 12, 2025
    Copy the full SHA
    fad1e24 View commit details
Showing with 137 additions and 35 deletions.
  1. +6 −1 .vscode/settings.json
  2. +6 −6 ATRC.Test/ATRC.Test.cpp
  3. +26 −4 ATRC/ATRCFiledata.cpp
  4. +4 −4 ATRC/c.c
  5. +23 −1 ATRC/c_cpp.cpp
  6. +10 −4 ATRC/include/ATRC.h
  7. +6 −1 ATRC/include/filer.h
  8. +5 −5 README.md
  9. +2 −2 cmake/FindATRC.cmake
  10. +47 −5 docs/ATRC_C-CPP.html
  11. +1 −1 scripts/fullbuild.bat
  12. +1 −1 scripts/loop.sh
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -67,6 +67,11 @@
"stdlib.h": "c",
"sstream": "cpp",
"limits.h": "c",
"stdint.h": "c"
"stdint.h": "c",
"chrono": "cpp",
"filesystem": "cpp",
"forward_list": "cpp",
"iomanip": "cpp",
"ratio": "cpp"
}
}
12 changes: 6 additions & 6 deletions ATRC.Test/ATRC.Test.cpp
Original file line number Diff line number Diff line change
@@ -4,18 +4,18 @@
using namespace atrc;
void cpp_main(void)
{
ATRC_FD fd = ATRC_FD("file.atrc");
ATRC_FD fd = ATRC_FD("file.atrc");
if (!fd.CheckStatus()) {
std::cout << "File parsed unsuccesfully!" << std::endl;
return;
}
std::cout << "File parsed unsuccesfully!" << std::endl;
return;
}
std::cout << fd["var_name"] << std::endl;

C_PATRC_FD c_fd = fd.ToCStruct();
std::string line = fd["block_name"]["key"];
const char* line = fd["block_name"]["key"];
const char* args[] = {"Hello everyone", nullptr};
std::cout << "Before: " << line << std::endl;
char* res = InsertVar_S(line.c_str(), args);
char* res = InsertVar_S(line, args);
std::cout << "After: " << res << std::endl;
delete[] res;
}
30 changes: 26 additions & 4 deletions ATRC/ATRCFiledata.cpp
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
#include <filer.h>
#include <iostream>
#include <cstring>

#include <fstream>

void atrc::ATRC_FD::MAINCONSTRUCTOR(){
this->AutoSave = false;
@@ -14,10 +14,10 @@ void atrc::ATRC_FD::MAINCONSTRUCTOR(){
}

atrc::ATRC_FD::ATRC_FD(){this->MAINCONSTRUCTOR();}
atrc::ATRC_FD::ATRC_FD(const char *path){
atrc::ATRC_FD::ATRC_FD(const char *path, ReadMode mode){
this->MAINCONSTRUCTOR();
this->Filename = path;
this->Read();
this->Read(mode);
}

atrc::ATRC_FD::ATRC_FD(C_PATRC_FD fd){
@@ -63,10 +63,32 @@ atrc::PROXY_ATRC_FD atrc::ATRC_FD::operator[](const std::string& key) const {



bool atrc::ATRC_FD::Read(){
bool atrc::ATRC_FD::Read(ReadMode mode){
std::string filename = this->Filename;
std::string encoding = "UTF-8";
std::string extension = "atrc";
if (mode == ATRC_FORCE_READ) {
// Delete previous file and create a new one
std::ofstream ofs(filename, std::ios::out | std::ios::trunc);
if (ofs.is_open()) {
ofs << FILEHEADER;
} else {
atrc::errormsg(FILE_MODE_ERR, -1, filename, filename);
return false;
}
} else if (mode == ATRC_CREATE_READ) {
std::ifstream ifs(filename);
if (!ifs.good()) {
std::ofstream ofs(filename, std::ios::out | std::ios::trunc);
if (ofs.is_open()) {
ofs << FILEHEADER;
} else {
atrc::errormsg(FILE_MODE_ERR, -1, filename, filename);
return false;
}
}
}

auto parsedData = atrc::ParseFile(filename, encoding, extension);
if (parsedData.first->empty() && parsedData.second->empty()) {
std::cerr << "Failed to parse file: " << filename << std::endl;
8 changes: 4 additions & 4 deletions ATRC/c.c
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
#include <stdlib.h>
#include <string.h>

bool Read(C_PATRC_FD self, const char* path) {
return _ATRC_WRAP_FUNC_1(self, path);
bool Read(C_PATRC_FD self, const char* path, ReadMode mode) {
return _ATRC_WRAP_FUNC_1(self, path, mode);
}

const char* ReadVariable(C_PATRC_FD self, const char* varname) {
@@ -463,11 +463,11 @@ bool ModifyKey(C_PATRC_FD self, const char* block, const char* key, const char*
return true;
}

C_PATRC_FD Create_ATRC_FD(char *filename){
C_PATRC_FD Create_ATRC_FD(char *filename, ReadMode mode){
C_PATRC_FD res = Create_Empty_ATRC_FD();
if(res == NULL) return NULL;
strcpy(res->Filename, filename);
if(!Read(res, filename)) return NULL;
if(!Read(res, filename, mode)) return NULL;
return res;
}
C_PATRC_FD Create_Empty_ATRC_FD(void){
24 changes: 23 additions & 1 deletion ATRC/c_cpp.cpp
Original file line number Diff line number Diff line change
@@ -4,15 +4,37 @@
#include <cstring>
#include <vector>
#include <filer.h>
#include <fstream>
/*+++
Wrap around functions from C++ to c
---*/

/*_ATRC_WRAP_READ*/
bool _ATRC_WRAP_FUNC_1(C_PATRC_FD self, const char* path) {
bool _ATRC_WRAP_FUNC_1(C_PATRC_FD self, const char* path, ReadMode readMode) {
std::string filename = path;
std::string encoding = "UTF-8";
std::string extension = "atrc";
if (readMode == ATRC_FORCE_READ) {
// Delete previous file and create a new one
std::ofstream ofs(filename, std::ios::out | std::ios::trunc);
if (ofs.is_open()) {
ofs << FILEHEADER;
} else {
atrc::errormsg(FILE_MODE_ERR, -1, filename, filename);
return false;
}
} else if (readMode == ATRC_CREATE_READ) {
std::ifstream ifs(filename);
if (!ifs.good()) {
std::ofstream ofs(filename, std::ios::out | std::ios::trunc);
if (ofs.is_open()) {
ofs << FILEHEADER;
} else {
atrc::errormsg(FILE_MODE_ERR, -1, filename, filename);
return false;
}
}
}
auto parsedData = atrc::ParseFile(filename, encoding, extension);
#if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)
self->Filename = _strdup(filename.c_str());
14 changes: 10 additions & 4 deletions ATRC/include/ATRC.h
Original file line number Diff line number Diff line change
@@ -55,6 +55,12 @@ C declarations
extern "C" {
#endif // __cplusplus

typedef enum ReadMode {
ATRC_READ_ONLY,
ATRC_CREATE_READ,
ATRC_FORCE_READ,
} ReadMode;


typedef struct C_Variable {
char *Name;
@@ -92,7 +98,7 @@ typedef struct _ATRCFiledata{
bool AutoSave;
} C_ATRC_FD, *C_PATRC_FD;

ATRC_API bool Read(C_PATRC_FD self, const char* path);
ATRC_API bool Read(C_PATRC_FD self, const char* path, ReadMode readMode);
ATRC_API const char* ReadVariable(C_PATRC_FD self, const char* varname);
ATRC_API const char* ReadKey(C_PATRC_FD self, const char* block, const char* key);
ATRC_API bool DoesExistBlock(C_PATRC_FD self, const char* block);
@@ -110,7 +116,7 @@ ATRC_API bool RemoveKey(C_PATRC_FD self, const char* block, const char* key);
ATRC_API bool ModifyKey(C_PATRC_FD self, const char* block, const char* key, const char* value);


ATRC_API C_PATRC_FD Create_ATRC_FD(char *filename);
ATRC_API C_PATRC_FD Create_ATRC_FD(char *filename, ReadMode readMode);
ATRC_API C_PATRC_FD Create_Empty_ATRC_FD();
ATRC_API void Destroy_ATRC_FD_Blocks_And_Keys(C_PATRC_FD self);
ATRC_API void Destroy_ATRC_FD_Variables(C_PATRC_FD self);
@@ -148,10 +154,10 @@ class ATRC_API PROXY_ATRC_FD;
class ATRC_API ATRC_FD {
public:
ATRC_FD();
ATRC_FD(const char* path);
ATRC_FD(const char* path, ReadMode mode = ATRC_READ_ONLY);
ATRC_FD(C_PATRC_FD filedata);
~ATRC_FD();
bool Read();
bool Read(ReadMode mode = ATRC_READ_ONLY);
std::string ReadVariable(const std::string& varname);
std::string ReadKey(const std::string& block, const std::string& key);
bool DoesExistBlock(const std::string& block);
7 changes: 6 additions & 1 deletion ATRC/include/filer.h
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
#define ERR_REREFERENCED_KEY 107
#define ERR_INSERT_VAR 108
#define ERR_INVALID_FILE 109
#define FILE_MODE_ERR 110


// File
@@ -78,7 +79,7 @@ typedef enum {
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
bool _ATRC_WRAP_FUNC_1(C_PATRC_FD a, const char* b);
bool _ATRC_WRAP_FUNC_1(C_PATRC_FD a, const char* b, ReadMode mode);
void _ATRC_WRAP_FUNC_2(int a, int b, const char *c, const char *d);
void _ATRC_WRAP_FUNC_3(
C_PATRC_FD self,
@@ -170,6 +171,10 @@ inline void errormsg(int err_num=-1,
msg = "No variable vector found";
err_class = ERR_CLASS_FILEHANDLER;
break;
case FILE_MODE_ERR:
msg = "Error with file mode";
err_class = ERR_CLASS_FILEHANDLER;
break;
case ERR_REREFERENCED_VAR:
msg = "Re-Rereferenced variable: '" + var_name + "' at line " + std::to_string(line_number);
err_class = ERR_CLASS_FILEHANDLER;
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
cmake_minimum_required(VERSION 3.15)
project(MyProject)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/ATRC_2.0.1/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/ATRC_2.0.2/cmake")
# Include the FindATRC script
include(FindATRC)
@@ -19,7 +19,7 @@ add_executable(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} PRIVATE ${ATRC})
# Include ATRC headers
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/ATRC_2.0.1/include")
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/ATRC_2.0.2/include")
```

## Example program
@@ -33,18 +33,18 @@ int main()
ATRC_FD fd = ATRC_FD("file.atrc");
if (!fd.CheckStatus()) {
std::cout << "File parsed unsuccesfully!" << std::endl;
return;
return 1;
}
std::cout << fd["var_name"] << std::endl;

C_PATRC_FD c_fd = fd.ToCStruct();
const char* line = fd["block_name"]["key"];
const char* args[] = {"Hello everyone", nullptr};
std::cout << "Before: " << line << std::endl;
char* res = InsertVar_S(line.c_str(), args);
char* res = InsertVar_S(line, args);
std::cout << "After: " << res << std::endl;
delete[] res;
return 1;
return 0;
}
```

4 changes: 2 additions & 2 deletions cmake/FindATRC.cmake
Original file line number Diff line number Diff line change
@@ -24,13 +24,13 @@ else()
endif()

# Construct ATRC directory path
set(ATRC_DIR "${CMAKE_SOURCE_DIR}/ATRC_2.0.1/${CompilePlatform}/${Arch}/${BuildConfig}")
set(ATRC_DIR "${CMAKE_SOURCE_DIR}/ATRC_2.0.2/${CompilePlatform}/${Arch}/${BuildConfig}")

# Find the ATRC library
find_library(ATRC NAMES ATRC REQUIRED PATHS ${ATRC_DIR})

# Include ATRC headers
include_directories("${CMAKE_SOURCE_DIR}/ATRC_2.0.1/include")
include_directories("${CMAKE_SOURCE_DIR}/ATRC_2.0.2/include")

# Link the ATRC library
if (NOT TARGET ATRC_FOUND)
Loading