Skip to content

Commit

Permalink
Convert main to C++
Browse files Browse the repository at this point in the history
  • Loading branch information
Crayon2000 committed Dec 5, 2024
1 parent 578c921 commit d5b8203
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ FetchContent_MakeAvailable(inih)

add_executable(MiisendU-Wii-U)

target_compile_options(MiisendU-Wii-U PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wpedantic
-Wnull-dereference
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
)

target_sources(MiisendU-Wii-U PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/source/main.c
${CMAKE_CURRENT_SOURCE_DIR}/source/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/console.c
${CMAKE_CURRENT_SOURCE_DIR}/source/udp.c
${CMAKE_CURRENT_SOURCE_DIR}/source/vpad_to_json.cpp
Expand Down
28 changes: 14 additions & 14 deletions source/main.c → source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ typedef struct {
*/
static int handler(void* user, const char* section, const char* name, const char* value)
{
configuration* pconfig = (configuration*)user;
configuration* pconfig = static_cast<configuration*>(user);
if(strcmp(section, "server") == 0) {
if(strcmp(name, "ipaddress") == 0) {
pconfig->ipaddress = strdup(value);
}
else if(strcmp(name, "port") == 0) {
pconfig->port = atoi(value);
pconfig->port = std::atoi(value);
}
else {
return 0; // Unknown name
Expand Down Expand Up @@ -92,7 +92,7 @@ static void ResetOrientation()
* @param argv An array of null-terminated strings representing command-line arguments.
* @return Returns zero on success, nonzero on error.
*/
int main(int argc, char **argv)
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
{
uint8_t IP[4] = {192, 168, 1, 100};

Expand Down Expand Up @@ -122,10 +122,10 @@ int main(int argc, char **argv)

// Read default settings from file
bool ip_loaded = false;
configuration config = {NULL, 4242};
configuration config = {nullptr, 4242};
ini_parse(path, handler, &config);
unsigned short Port = config.port;
if(config.ipaddress != NULL) {
if(config.ipaddress != nullptr) {
if(inet_pton(AF_INET, config.ipaddress, &IP) > 0) {
ip_loaded = true;
}
Expand Down Expand Up @@ -253,7 +253,7 @@ int main(int argc, char **argv)

// Save settings to file
FILE * IP_file = fopen(path, "w");
if (IP_file != NULL) {
if (IP_file != nullptr) {
fprintf(IP_file,
"[server]\n"
"ipaddress=%s\n"
Expand All @@ -269,10 +269,10 @@ int main(int argc, char **argv)
uint16_t holdTime = 0;

while(running == true) {
int32_t kpad_error1 = -6;
int32_t kpad_error2 = -6;
int32_t kpad_error3 = -6;
int32_t kpad_error4 = -6;
KPADError kpad_error1 = KPADError::KPAD_ERROR_UNINITIALIZED;
KPADError kpad_error2 = KPADError::KPAD_ERROR_UNINITIALIZED;
KPADError kpad_error3 = KPADError::KPAD_ERROR_UNINITIALIZED;
KPADError kpad_error4 = KPADError::KPAD_ERROR_UNINITIALIZED;
KPADStatus kpad_data1;
KPADStatus kpad_data2;
KPADStatus kpad_data3;
Expand Down Expand Up @@ -304,19 +304,19 @@ int main(int argc, char **argv)
PADData pad_data;
memset(&pad_data, 0, sizeof(PADData));
pad_data.vpad = &vpad_data;
if(kpad_error1 == 0)
if(kpad_error1 == KPADError::KPAD_ERROR_OK)
{
pad_data.kpad[0] = &kpad_data1;
}
if(kpad_error2 == 0)
if(kpad_error2 == KPADError::KPAD_ERROR_OK)
{
pad_data.kpad[1] = &kpad_data2;
}
if(kpad_error3 == 0)
if(kpad_error3 == KPADError::KPAD_ERROR_OK)
{
pad_data.kpad[2] = &kpad_data3;
}
if(kpad_error4 == 0)
if(kpad_error4 == KPADError::KPAD_ERROR_OK)
{
pad_data.kpad[3] = &kpad_data4;
}
Expand Down

0 comments on commit d5b8203

Please sign in to comment.