Initial commit

This commit is contained in:
Marek Kraus 2022-08-24 12:06:39 +02:00
commit 019c7dd845
15 changed files with 347 additions and 0 deletions

58
.clang-format Normal file
View File

@ -0,0 +1,58 @@
---
Language: Cpp
BasedOnStyle: GNU
IndentWidth: 4
AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: None
BreakBeforeBraces: Custom
BraceWrapping:
AfterFunction: false
AfterCaseLabel: false
AfterEnum: false
AfterControlStatement: Never
AfterStruct : false
AfterUnion : false
AfterExternBlock : false
BeforeElse : false
BeforeWhile : false
AlignAfterOpenBracket: Align
AlignArrayOfStructures: Left
AlignEscapedNewlines: Right
AlignOperands: Align
AllowShortEnumsOnASingleLine: False
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine : false
AlwaysBreakAfterReturnType: AllDefinitions
AlignTrailingComments : true
AlignConsecutiveMacros: AcrossEmptyLines
KeepEmptyLinesAtTheStartOfBlocks : false
PointerAlignment : Left
QualifierAlignment : Left
ReferenceAlignment : Left
RemoveBracesLLVM : false
SpaceAfterCStyleCast : false
SpaceAfterLogicalNot : false
SpaceAfterTemplateKeyword : false
SpaceAroundPointerQualifiers : Before
SpaceBeforeAssignmentOperators : true
SpaceBeforeCaseColon : false
SpaceBeforeCpp11BracedList : false
SpaceBeforeParens : ControlStatements
SpaceBeforeParensOptions :
AfterControlStatements : true
AfterFunctionDeclarationName : false
AfterFunctionDefinitionName : false
AfterOverloadedOperator : false
SpaceBeforeRangeBasedForLoopColon : false
SpaceBeforeSquareBrackets : false
SpaceInEmptyBlock : false
SpaceInEmptyParentheses : false
SpacesInCStyleCastParentheses : false
SpacesInConditionalStatement : false
SpacesInContainerLiterals : false
SpacesInParentheses: false
SpacesInSquareBrackets : false
UseTab : Never
BitFieldColonSpacing: None
BreakBeforeBinaryOperators: All

77
.gitignore vendored Normal file
View File

@ -0,0 +1,77 @@
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "vendor/argtable3"]
path = vendor/argtable3
url = https://github.com/argtable/argtable3

8
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

2
.idea/blisp.iml generated Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

7
.idea/codeStyles/Project.xml generated Normal file
View File

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<clangFormatSettings>
<option name="ENABLED" value="true" />
</clangFormatSettings>
</code_scheme>
</component>

5
.idea/codeStyles/codeStyleConfig.xml generated Normal file
View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

4
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/blisp.iml" filepath="$PROJECT_DIR$/.idea/blisp.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

11
CMakeLists.txt Normal file
View File

@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.22)
project(blisp C)
set(CMAKE_C_STANDARD 23)
add_subdirectory(vendor/argtable3)
add_executable(blisp src/main.c src/cmd/write.c)
target_include_directories(blisp PRIVATE vendor/argtable3/src)
target_link_libraries(blisp PRIVATE argtable3)

16
src/cmd.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef BLISP_CMD_H
#define BLISP_CMD_H
#include <stdint.h>
struct cmd {
const char* name;
int8_t (*args_init)();
uint8_t (*args_parse_exec)(int argc, char** argv);
void (*args_print_syntax)();
void (*args_free)();
};
extern struct cmd cmd_write;
#endif // BLISP_CMD_H

47
src/cmd/write.c Normal file
View File

@ -0,0 +1,47 @@
#include "../cmd.h"
#include <argtable3.h>
#define REG_EXTENDED 1
#define REG_ICASE (REG_EXTENDED << 1)
static struct arg_rex* cmd;
static struct arg_file* binary_to_write;
static struct arg_end* end;
static void* cmd_write_argtable[3];
int8_t
cmd_write_args_init() {
cmd_write_argtable[0] = cmd
= arg_rex1(NULL, NULL, "write", NULL, REG_ICASE, NULL);
cmd_write_argtable[1] = binary_to_write
= arg_file0(NULL, NULL, "<input>", "Binary to write");
cmd_write_argtable[2] = end = arg_end(10);
if (arg_nullcheck(cmd_write_argtable) != 0) {
fprintf(stderr, "insufficient memory\n");
return -1;
}
}
uint8_t
cmd_write_parse_exec(int argc, char** argv) {
int errors = arg_parse(argc, argv, cmd_write_argtable);
if (errors == 0) {
printf("yeet\n");
return 1;
}
return 0;
}
void cmd_write_args_print_syntax() {
arg_print_syntax(stdout,cmd_write_argtable,"\n");
}
void
cmd_write_free() {
arg_freetable(cmd_write_argtable,
sizeof(cmd_write_argtable) / sizeof(cmd_write_argtable[0]));
}
struct cmd cmd_write
= { "write", cmd_write_args_init, cmd_write_parse_exec, cmd_write_args_print_syntax, cmd_write_free };

94
src/main.c Normal file
View File

@ -0,0 +1,94 @@
#include "cmd.h"
#include <argtable3.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
struct cmd* cmds[] = {
&cmd_write,
};
static struct arg_lit* help;
static struct arg_lit* version;
static struct arg_end* end;
static void* argtable[3];
int8_t args_init() {
argtable[0] = help = arg_lit0(NULL, "help", "print this help and exit");
argtable[1] = version = arg_lit0(NULL, "version", "print version information and exit");
argtable[2] = end = arg_end(20);
if (arg_nullcheck(argtable) != 0) {
fprintf(stderr, "insufficient memory\n");
return -1;
}
}
void print_help() {
puts("Usage:");
for (uint8_t i = 0; cmds[i] != NULL; i++) {
fputs("\tblisp", stdout);
cmds[i]->args_print_syntax();
}
fputs("\tblisp", stdout);
arg_print_syntax(stdout, argtable,"\n");
}
int8_t args_parse_exec(int argc, char** argv) {
int error = arg_parse(argc, argv, argtable);
if (error == 0) {
if (help->count) {
print_help();
return 1;
} else if (version->count) {
printf("blisp 1.0.0\n");
printf("Copyright (C) 2022 Marek Kraus and PINE64 Community\n");
return 1;
}
}
return 0;
}
void args_free() {
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
}
int
main(int argc, char** argv) {
int exit_code = 0;
if (args_init() != 0) {
exit_code = -1;
goto exit;
}
for (uint8_t i = 0; cmds[i] != NULL; i++) {
if (cmds[i]->args_init() != 0) {
exit_code = -1;
goto exit;
}
}
if (args_parse_exec(argc, argv)) {
goto exit;
}
uint8_t command_found = false;
for (uint8_t i = 0; cmds[i] != NULL; i++) {
if (cmds[i]->args_parse_exec(argc, argv)) {
command_found = true;
break;
}
}
if (!command_found) {
}
exit:
for (uint8_t i = 0; cmds[i] != NULL; i++) {
cmds[i]->args_free();
}
args_free();
return exit_code;
}

1
vendor/argtable3 vendored Submodule

@ -0,0 +1 @@
Subproject commit 6f0e40bc44c99af353ced367c6fafca8705f5fca