diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..5d30bf6 --- /dev/null +++ b/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +cd go +go build -buildmode c-shared -ldflags="-w -s" -trimpath -v -o "go_p2fa.so" +rm -rf ../c/libs/go_p2fa.h +cp go_p2fa.h ../c/libs/go_p2fa.h +cd ../c/src +make -j1 diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt deleted file mode 100644 index 2a35e20..0000000 --- a/c/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required(VERSION 3.10) -project(P2FA) - -set(CMAKE_C_STANDARD 99) -set(CMAKE_CXX_STANDARD 11) - -include_directories(${CMAKE_SOURCE_DIR}/libs/include) -link_directories(${CMAKE_SOURCE_DIR}/libs) - -add_library(p2fa SHARED src/p2fa.c - src/images.c) - -target_link_libraries(p2fa) - -set_target_properties(p2fa PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build" - OUTPUT_NAME "p2fa" -) \ No newline at end of file diff --git a/c/build.ps1 b/c/build.ps1 deleted file mode 100644 index 5e9c9c8..0000000 --- a/c/build.ps1 +++ /dev/null @@ -1,4 +0,0 @@ -Get-ChildItem -Path build -Recurse | Remove-Item -force -recurse -if (Test-Path -Path .\build) { Remove-Item -Path .\build -Recurse -Force } -cmake -DCMAKE_BUILD_TYPE=Release -G "CodeBlocks - MinGW Makefiles" -S . -B .\build -cmake --build .\build --target p2fa -- -j 14 \ No newline at end of file diff --git a/c/libs/go_p2fa.h b/c/libs/go_p2fa.h deleted file mode 100644 index cdac00b..0000000 --- a/c/libs/go_p2fa.h +++ /dev/null @@ -1,85 +0,0 @@ -/* Code generated by cmd/cgo; DO NOT EDIT. */ - -/* package P2FA */ - - -#line 1 "cgo-builtin-export-prolog" - -#include - -#ifndef GO_CGO_EXPORT_PROLOGUE_H -#define GO_CGO_EXPORT_PROLOGUE_H - -#ifndef GO_CGO_GOSTRING_TYPEDEF -typedef struct { const char *p; ptrdiff_t n; } _GoString_; -#endif - -#endif - -/* Start of preamble from import "C" comments. */ - - - - -/* End of preamble from import "C" comments. */ - - -/* Start of boilerplate cgo prologue. */ -#line 1 "cgo-gcc-export-header-prolog" - -#ifndef GO_CGO_PROLOGUE_H -#define GO_CGO_PROLOGUE_H - -typedef signed char GoInt8; -typedef unsigned char GoUint8; -typedef short GoInt16; -typedef unsigned short GoUint16; -typedef int GoInt32; -typedef unsigned int GoUint32; -typedef long long GoInt64; -typedef unsigned long long GoUint64; -typedef GoInt64 GoInt; -typedef GoUint64 GoUint; -typedef size_t GoUintptr; -typedef float GoFloat32; -typedef double GoFloat64; -#ifdef _MSC_VER -#include -typedef _Fcomplex GoComplex64; -typedef _Dcomplex GoComplex128; -#else -typedef float _Complex GoComplex64; -typedef double _Complex GoComplex128; -#endif - -/* - static assertion to make sure the file is being used on architecture - at least with matching size of GoInt. -*/ -typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; - -#ifndef GO_CGO_GOSTRING_TYPEDEF -typedef _GoString_ GoString; -#endif -typedef void *GoMap; -typedef void *GoChan; -typedef struct { void *t; void *v; } GoInterface; -typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; - -#endif - -/* End of boilerplate cgo prologue. */ - -#ifdef __cplusplus -extern "C" { -#endif - -extern __declspec(dllexport) void loadConfigs(); -extern __declspec(dllexport) GoSlice getConfigNames(); -extern __declspec(dllexport) GoString getCode(GoString configName); -extern __declspec(dllexport) GoUint64 getTimeRemaining(GoInt n); -extern __declspec(dllexport) GoUint64 getTimeRemainingMS(GoInt n); - -#ifdef __cplusplus -} -#endif diff --git a/c/src/p2fa.c b/c/src/p2fa.c index b79cd29..4c56070 100644 --- a/c/src/p2fa.c +++ b/c/src/p2fa.c @@ -27,7 +27,8 @@ int draw() { Paint_Clear(WHITE); const char *confName = "default"; - Paint_DrawString(5, 5, getCode(GoString{confName, strlen(confName)}).p, &Font24, WHITE, BLACK); + GoString confStr = {confName, strlen(confName)}; + Paint_DrawString(5, 5, getCode(confStr).p, &Font24, WHITE, BLACK); DEV_Delay_ms(5000); diff --git a/c/src/p2fa.h b/c/src/p2fa.h deleted file mode 100644 index 12a289c..0000000 --- a/c/src/p2fa.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// Created by steven on 11/14/2024. -// - -#ifndef P2FA_P2FA_H -#define P2FA_P2FA_H - -void Handler(int sigNum); - -//__declspec(dllexport) void init(); - -__declspec(dllexport) int draw(); - -#endif //P2FA_P2FA_H diff --git a/go/main.go b/go/totp.go similarity index 99% rename from go/main.go rename to go/totp.go index 2edd6cf..dc9ae03 100644 --- a/go/main.go +++ b/go/totp.go @@ -146,5 +146,3 @@ func getTimeRemaining(n int) uint64 { func getTimeRemainingMS(n int) uint64 { return (uint64(n) * 1000) - (uint64(time.Now().UnixNano()/1e6) % (uint64(n) * 1000)) } - -func main() {} diff --git a/go/ui.go.old b/go/ui.go.old deleted file mode 100644 index 7bd1eac..0000000 --- a/go/ui.go.old +++ /dev/null @@ -1,35 +0,0 @@ -package main - -/* -#cgo CFLAGS: -I. -#cgo LDFLAGS: -L. -llibp2fa - -#include "../c/src/p2fa.h" -*/ -import "C" - -import ( - "time" - "unsafe" -) - -func startUI() { - if C.SDL_Init(C.SDL_INIT_VIDEO) != 0 { - panic("Failed to initialize SDL") - } - defer C.SDL_Quit() - - window := C.createWindow() - if window == nil { - panic("Error creating window") - } - - renderer := C.createRenderer((*C.SDL_Window)(unsafe.Pointer(window))) - if renderer == nil { - panic("Error creating renderer") - } - C.draw(renderer) - - time.Sleep(10 * time.Second) - C.destroy(renderer, window) -}