add version

This commit is contained in:
NishiOwO 2025-03-26 17:23:05 +09:00
parent afec45954c
commit ca98b075c3
No known key found for this signature in database
GPG Key ID: 27EF69B208EB9343
6 changed files with 72 additions and 6 deletions

20
.clang-format Normal file
View File

@ -0,0 +1,20 @@
---
# $Id: .clang-format 16 2025-01-30 10:59:29Z nishi $
Language: Cpp
UseTab: Always
TabWidth: 8
AlignConsecutiveAssignments:
Enabled: true
AlignConsecutiveDeclarations:
Enabled: true
IndentWidth: 8
PointerAlignment: Left
ColumnLimit: 1024
AllowShortIfStatementsOnASingleLine: Always
AllowShortBlocksOnASingleLine: Never
AllowShortLoopsOnASingleLine: true
SpaceBeforeParens: Never
AlignEscapedNewlines: DontAlign
SortIncludes: false
AllowShortEnumsOnASingleLine: false
#IndentPPDirectives: AfterHash

View File

@ -8,16 +8,19 @@ GL_LIBS = `pkg-config --libs gl`
AR = $(TARGET_PREFIX)ar AR = $(TARGET_PREFIX)ar
CC = $(TARGET_PREFIX)gcc CC = $(TARGET_PREFIX)gcc
CFLAGS = -D_DEFAULT_SOURCE $(ODE_CFLAGS) $(AMX_CFLAGS) $(GL_CFLAGS) CFLAGS = -D_DEFAULT_SOURCE -I../engine $(ODE_CFLAGS) $(AMX_CFLAGS) $(GL_CFLAGS)
LDFLAGS = LDFLAGS =
LIBS = $(ODE_LIBS) $(AMX_LIBS) $(GL_LIBS) LIBS = $(ODE_LIBS) $(AMX_LIBS) $(GL_LIBS)
EXEC = EXEC =
.PHONY: all clean ./engine ./src .PHONY: all format clean ./engine ./src
all: ./src all: ./src
format:
clang-format --verbose -i `find ./src ./engine -name "*.c" -or -name "*.h"`
./engine:: ./engine::
$(MAKE) -C $@ $(MAKE) -C $@

View File

@ -1,5 +1,5 @@
TARGET = libnishbox.a TARGET = libnishbox.a
OBJS = OBJS = version.o
include ../common.mk include ../common.mk

13
engine/nb_version.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef __NB_VERSION_H__
#define __NB_VERSION_H__
typedef struct nb_version {
int major;
int minor;
int patch;
char full[64];
} nb_version_t;
void nb_get_version(nb_version_t* version);
#endif

32
engine/version.c Normal file
View File

@ -0,0 +1,32 @@
#include "nb_version.h"
#include <string.h>
#include <stdlib.h>
#define NB_VERSION "1.0.0"
void nb_get_version(nb_version_t* version) {
char* cpstr = malloc(strlen(NB_VERSION) + 1);
int i;
int incr = 0;
int old = 0;
strcpy(cpstr, NB_VERSION);
strcpy(version->full, NB_VERSION);
for(i = 0;; i++) {
if(cpstr[i] == '.' || cpstr[i] == 0) {
int num;
cpstr[i] = 0;
num = atoi(cpstr + old);
if(incr == 0) {
version->major = num;
} else if(incr == 1) {
version->minor = num;
} else if(incr == 2) {
version->patch = num;
}
old = i + 1;
incr++;
if(incr == 3) break;
}
}
}

View File

@ -1,5 +1,3 @@
#include <stdio.h> #include <stdio.h>
int main(int argc, char** argv){ int main(int argc, char** argv) { return 0; }
return 0;
}