Initial commit
added just a few helper functions and structures that will use later. still missing a lot of important functions that will be important, but they will be implemented as i go.
This commit is contained in:
commit
a34348be60
288
.clang-format
Normal file
288
.clang-format
Normal file
@ -0,0 +1,288 @@
|
|||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
AccessModifierOffset: -2
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignArrayOfStructures: None
|
||||||
|
AlignConsecutiveAssignments:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: true
|
||||||
|
AlignConsecutiveBitFields:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveDeclarations:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: true
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveMacros:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveShortCaseStatements:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCaseArrows: false
|
||||||
|
AlignCaseColons: false
|
||||||
|
AlignConsecutiveTableGenBreakingDAGArgColons:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveTableGenCondOperatorColons:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveTableGenDefinitionColons:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignEscapedNewlines: Right
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments:
|
||||||
|
Kind: Always
|
||||||
|
OverEmptyLines: 0
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowBreakBeforeNoexceptSpecifier: Never
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseExpressionOnASingleLine: true
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortCompoundRequirementOnASingleLine: true
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AllowShortNamespacesOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: All
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AttributeMacros:
|
||||||
|
- __capability
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: BinPack
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: true
|
||||||
|
AfterClass: true
|
||||||
|
AfterControlStatement: Always
|
||||||
|
AfterEnum: true
|
||||||
|
AfterExternBlock: true
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: true
|
||||||
|
AfterObjCDeclaration: true
|
||||||
|
AfterStruct: true
|
||||||
|
AfterUnion: true
|
||||||
|
BeforeCatch: true
|
||||||
|
BeforeElse: true
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
BeforeWhile: true
|
||||||
|
IndentBraces: true
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakAdjacentStringLiterals: true
|
||||||
|
BreakAfterAttributes: Leave
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakAfterReturnType: AllDefinitions
|
||||||
|
BreakArrays: true
|
||||||
|
BreakBeforeBinaryOperators: All
|
||||||
|
BreakBeforeConceptDeclarations: Always
|
||||||
|
BreakBeforeBraces: GNU
|
||||||
|
BreakBeforeInlineASMColon: OnlyMultiline
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakBinaryOperations: Never
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakFunctionDefinitionParameters: false
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakStringLiterals: true
|
||||||
|
BreakTemplateDeclarations: MultiLine
|
||||||
|
ColumnLimit: 79
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: false
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
EmptyLineAfterAccessModifier: Never
|
||||||
|
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
FixNamespaceComments: false
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IfMacros:
|
||||||
|
- KJ_IF_MAYBE
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||||
|
Priority: 2
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||||
|
Priority: 3
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 1
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
IncludeIsMainRegex: '(Test)?$'
|
||||||
|
IncludeIsMainSourceRegex: ''
|
||||||
|
IndentAccessModifiers: false
|
||||||
|
IndentCaseBlocks: false
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentExportBlock: true
|
||||||
|
IndentExternBlock: AfterExternBlock
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentRequiresClause: true
|
||||||
|
IndentWidth: 2
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
InsertBraces: false
|
||||||
|
InsertNewlineAtEOF: false
|
||||||
|
InsertTrailingCommas: None
|
||||||
|
IntegerLiteralSeparator:
|
||||||
|
Binary: 0
|
||||||
|
BinaryMinDigits: 0
|
||||||
|
Decimal: 0
|
||||||
|
DecimalMinDigits: 0
|
||||||
|
Hex: 0
|
||||||
|
HexMinDigits: 0
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLines:
|
||||||
|
AtEndOfFile: false
|
||||||
|
AtStartOfBlock: true
|
||||||
|
AtStartOfFile: true
|
||||||
|
KeepFormFeed: true
|
||||||
|
LambdaBodyIndentation: Signature
|
||||||
|
LineEnding: DeriveLF
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MainIncludeChar: Quote
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Auto
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCBreakBeforeNestedBlockParam: true
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PackConstructorInitializers: BinPack
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakBeforeMemberAccess: 150
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakOpenParenthesis: 0
|
||||||
|
PenaltyBreakScopeResolution: 500
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyIndentedWhitespace: 0
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
PointerAlignment: Right
|
||||||
|
PPIndentWidth: -1
|
||||||
|
QualifierAlignment: Leave
|
||||||
|
ReferenceAlignment: Pointer
|
||||||
|
ReflowComments: Always
|
||||||
|
RemoveBracesLLVM: false
|
||||||
|
RemoveEmptyLinesInUnwrappedLines: false
|
||||||
|
RemoveParentheses: Leave
|
||||||
|
RemoveSemicolon: false
|
||||||
|
RequiresClausePosition: OwnLine
|
||||||
|
RequiresExpressionIndentation: OuterScope
|
||||||
|
SeparateDefinitionBlocks: Leave
|
||||||
|
ShortNamespaceLines: 1
|
||||||
|
SkipMacroDefinitionBody: false
|
||||||
|
SortIncludes: CaseSensitive
|
||||||
|
SortJavaStaticImport: Before
|
||||||
|
SortUsingDeclarations: LexicographicNumeric
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceAroundPointerQualifiers: Default
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeJsonColon: false
|
||||||
|
SpaceBeforeParens: Always
|
||||||
|
SpaceBeforeParensOptions:
|
||||||
|
AfterControlStatements: false
|
||||||
|
AfterForeachMacros: false
|
||||||
|
AfterFunctionDefinitionName: false
|
||||||
|
AfterFunctionDeclarationName: false
|
||||||
|
AfterIfMacros: false
|
||||||
|
AfterOverloadedOperator: false
|
||||||
|
AfterPlacementOperator: true
|
||||||
|
AfterRequiresInClause: false
|
||||||
|
AfterRequiresInExpression: false
|
||||||
|
BeforeNonEmptyParentheses: false
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: Never
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInLineCommentPrefix:
|
||||||
|
Minimum: 1
|
||||||
|
Maximum: -1
|
||||||
|
SpacesInParens: Never
|
||||||
|
SpacesInParensOptions:
|
||||||
|
ExceptDoubleParentheses: false
|
||||||
|
InCStyleCasts: false
|
||||||
|
InConditionalStatements: false
|
||||||
|
InEmptyParentheses: false
|
||||||
|
Other: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Latest
|
||||||
|
StatementAttributeLikeMacros:
|
||||||
|
- Q_EMIT
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
TableGenBreakInsideDAGArg: DontBreak
|
||||||
|
TabWidth: 8
|
||||||
|
UseTab: Never
|
||||||
|
VerilogBreakBetweenInstancePorts: true
|
||||||
|
WhitespaceSensitiveMacros:
|
||||||
|
- BOOST_PP_STRINGIZE
|
||||||
|
- CF_SWIFT_NAME
|
||||||
|
- NS_SWIFT_NAME
|
||||||
|
- PP_STRINGIZE
|
||||||
|
- STRINGIZE
|
||||||
|
WrapNamespaceBodyWithEmptyLines: Leave
|
||||||
|
...
|
||||||
|
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.o
|
||||||
|
*.out
|
29
Makefile
Normal file
29
Makefile
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
CC=gcc
|
||||||
|
ECHO=echo -e
|
||||||
|
RM=rm
|
||||||
|
|
||||||
|
CFLAGS=-Wall -Werror -std=gnu99 -O0 -g
|
||||||
|
LIBS=
|
||||||
|
|
||||||
|
FILES=build/main.o build/utils/vector.o build/utils/buffer.o
|
||||||
|
OUT=bin/pinky.out
|
||||||
|
|
||||||
|
all: $(FILES)
|
||||||
|
@$(ECHO) "LD\t\t"$(FILES)
|
||||||
|
@$(CC) $(CFLAGS) $(FILES) -o $(OUT) $(LIBS)
|
||||||
|
|
||||||
|
build/main.o: src/main.c
|
||||||
|
@$(ECHO) "CC\t\t"$<
|
||||||
|
@$(CC) $(CFLAGS) $< -c -o $@ $(LIBS)
|
||||||
|
|
||||||
|
build/utils/vector.o: src/utils/vector.c
|
||||||
|
@$(ECHO) "CC\t\t"$<
|
||||||
|
@$(CC) $(CFLAGS) $< -c -o $@ $(LIBS)
|
||||||
|
|
||||||
|
build/utils/buffer.o: src/utils/buffer.c
|
||||||
|
@$(ECHO) "CC\t\t"$<
|
||||||
|
@$(CC) $(CFLAGS) $< -c -o $@ $(LIBS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@$(ECHO) "Cleaning..."
|
||||||
|
@$(RM) -f $(FILES) $(OUT)
|
0
bin/.gitkeep
Normal file
0
bin/.gitkeep
Normal file
0
build/.gitkeep
Normal file
0
build/.gitkeep
Normal file
0
build/utils/.gitkeep
Normal file
0
build/utils/.gitkeep
Normal file
14
src/main.c
Normal file
14
src/main.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
if (argc < 2)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "usage: %s [filename]\n", argv[0]);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
88
src/utils/buffer.c
Normal file
88
src/utils/buffer.c
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
buffer_resize (size_t s_len, struct buffer *b)
|
||||||
|
{
|
||||||
|
if (!b)
|
||||||
|
return;
|
||||||
|
|
||||||
|
b->capacity += s_len;
|
||||||
|
b->buf = realloc (b->buf, sizeof (char) * b->capacity);
|
||||||
|
if (!b->buf)
|
||||||
|
fputs ("buffer_resize: couldn't resize memory for buffer.", stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct buffer
|
||||||
|
buffer_create ()
|
||||||
|
{
|
||||||
|
struct buffer b = { 0 };
|
||||||
|
|
||||||
|
b.capacity = 16;
|
||||||
|
b.buf = calloc (b.capacity, sizeof (char));
|
||||||
|
if (!b.buf)
|
||||||
|
{
|
||||||
|
fputs ("buffer_create: cannot allocate memory.", stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
buffer_append (const char *s, struct buffer *b)
|
||||||
|
{
|
||||||
|
if (!s || !b)
|
||||||
|
return;
|
||||||
|
|
||||||
|
size_t s_len = strlen (s);
|
||||||
|
if (((b->len + s_len) + 1) >= b->capacity)
|
||||||
|
buffer_resize (s_len + 1, b);
|
||||||
|
|
||||||
|
char *pos = (char *)(b->buf + b->len);
|
||||||
|
memcpy (pos, s, s_len);
|
||||||
|
b->len += s_len;
|
||||||
|
b->buf[b->len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
buffer_printf (struct buffer *b, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list list1, list2;
|
||||||
|
|
||||||
|
va_start (list1, fmt);
|
||||||
|
va_copy (list2, list1);
|
||||||
|
|
||||||
|
int size = vsnprintf (NULL, 0, fmt, list1);
|
||||||
|
|
||||||
|
va_end (list1);
|
||||||
|
|
||||||
|
char *buf = malloc (sizeof (char) * size + 1);
|
||||||
|
vsnprintf (buf, size + 1, fmt, list2);
|
||||||
|
va_end (list2);
|
||||||
|
|
||||||
|
buffer_append (buf, b);
|
||||||
|
free (buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
buffer_get (struct buffer *b)
|
||||||
|
{
|
||||||
|
if (!b)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return b->buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
buffer_free (struct buffer *b)
|
||||||
|
{
|
||||||
|
if (!b)
|
||||||
|
return;
|
||||||
|
|
||||||
|
free (b->buf);
|
||||||
|
memset (b, 0, sizeof (struct buffer));
|
||||||
|
}
|
19
src/utils/buffer.h
Normal file
19
src/utils/buffer.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef __BUFFER_H
|
||||||
|
#define __BUFFER_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
struct buffer
|
||||||
|
{
|
||||||
|
size_t capacity;
|
||||||
|
size_t len;
|
||||||
|
char *buf;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct buffer buffer_create ();
|
||||||
|
void buffer_append (const char *s, struct buffer *b);
|
||||||
|
void buffer_printf (struct buffer *b, const char *fmt, ...);
|
||||||
|
char *buffer_get (struct buffer *b);
|
||||||
|
void buffer_free (struct buffer *b);
|
||||||
|
|
||||||
|
#endif
|
72
src/utils/vector.c
Normal file
72
src/utils/vector.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "vector.h"
|
||||||
|
|
||||||
|
static _Bool
|
||||||
|
vector_realloc (struct vector *v)
|
||||||
|
{
|
||||||
|
if (!v)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
v->capacity *= 2;
|
||||||
|
v->elements = realloc (v->elements, sizeof (void *) * v->capacity);
|
||||||
|
return (_Bool)v->elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct vector
|
||||||
|
vector_create ()
|
||||||
|
{
|
||||||
|
struct vector v = { 0 };
|
||||||
|
|
||||||
|
v.capacity = VECTOR_INIT_CAPACITY;
|
||||||
|
v.elements = calloc (v.capacity, sizeof (void *));
|
||||||
|
if (!v.elements)
|
||||||
|
fputs ("vector_create: cannot allocate memory.", stderr);
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
_Bool
|
||||||
|
vector_push_back (void *elm, struct vector *v)
|
||||||
|
{
|
||||||
|
if (!elm || !v)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ((v->length + 1) >= v->capacity)
|
||||||
|
if (!vector_realloc (v))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
v->elements[v->length] = elm;
|
||||||
|
v->length++;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
vector_at (size_t i, struct vector *v)
|
||||||
|
{
|
||||||
|
if (!v)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (i >= v->length)
|
||||||
|
{
|
||||||
|
fprintf (stderr,
|
||||||
|
"vector_at: cannot access index '%lu' in an array of '%lu' "
|
||||||
|
"elements.\n",
|
||||||
|
i, v->length + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return v->elements[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
vector_free (struct vector *v)
|
||||||
|
{
|
||||||
|
if (!v)
|
||||||
|
return;
|
||||||
|
|
||||||
|
free (v->elements);
|
||||||
|
memset (v, 0, sizeof (struct vector));
|
||||||
|
}
|
20
src/utils/vector.h
Normal file
20
src/utils/vector.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef __VECTOR_H
|
||||||
|
#define __VECTOR_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#define VECTOR_INIT_CAPACITY 20
|
||||||
|
|
||||||
|
struct vector
|
||||||
|
{
|
||||||
|
size_t length;
|
||||||
|
size_t capacity;
|
||||||
|
void **elements;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct vector vector_create ();
|
||||||
|
_Bool vector_push_back (void *elm, struct vector *v);
|
||||||
|
void *vector_at (size_t i, struct vector *v);
|
||||||
|
void vector_free (struct vector *v);
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user