-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: CI/CD Pipeline | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up C | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y build-essential | ||
- name: Run make test | ||
run: | | ||
make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,5 @@ modules.order | |
Module.symvers | ||
Mkfile.old | ||
dkms.conf | ||
|
||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "linux-gcc-x64", | ||
"includePath": [ | ||
"${workspaceFolder}/**" | ||
], | ||
"compilerPath": "/usr/bin/gcc", | ||
"cStandard": "${default}", | ||
"cppStandard": "${default}", | ||
"intelliSenseMode": "linux-gcc-x64", | ||
"compilerArgs": [ | ||
"" | ||
] | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "C/C++ Runner: Debug Session", | ||
"type": "cppdbg", | ||
"request": "launch", | ||
"args": [], | ||
"stopAtEntry": false, | ||
"externalConsole": false, | ||
"cwd": "/home/mofosyne/git/C/filenameExtractPathAndExtension.c", | ||
"program": "/home/mofosyne/git/C/filenameExtractPathAndExtension.c/build/Debug/outDebug", | ||
"MIMode": "gdb", | ||
"miDebuggerPath": "gdb", | ||
"setupCommands": [ | ||
{ | ||
"description": "Enable pretty-printing for gdb", | ||
"text": "-enable-pretty-printing", | ||
"ignoreFailures": true | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"C_Cpp_Runner.cCompilerPath": "gcc", | ||
"C_Cpp_Runner.cppCompilerPath": "g++", | ||
"C_Cpp_Runner.debuggerPath": "gdb", | ||
"C_Cpp_Runner.cStandard": "", | ||
"C_Cpp_Runner.cppStandard": "", | ||
"C_Cpp_Runner.msvcBatchPath": "", | ||
"C_Cpp_Runner.useMsvc": false, | ||
"C_Cpp_Runner.warnings": [ | ||
"-Wall", | ||
"-Wextra", | ||
"-Wpedantic", | ||
"-Wshadow", | ||
"-Wformat=2", | ||
"-Wcast-align", | ||
"-Wconversion", | ||
"-Wsign-conversion", | ||
"-Wnull-dereference" | ||
], | ||
"C_Cpp_Runner.msvcWarnings": [ | ||
"/W4", | ||
"/permissive-", | ||
"/w14242", | ||
"/w14287", | ||
"/w14296", | ||
"/w14311", | ||
"/w14826", | ||
"/w44062", | ||
"/w44242", | ||
"/w14905", | ||
"/w14906", | ||
"/w14263", | ||
"/w44265", | ||
"/w14928" | ||
], | ||
"C_Cpp_Runner.enableWarnings": true, | ||
"C_Cpp_Runner.warningsAsError": false, | ||
"C_Cpp_Runner.compilerArgs": [], | ||
"C_Cpp_Runner.linkerArgs": [], | ||
"C_Cpp_Runner.includePaths": [], | ||
"C_Cpp_Runner.includeSearch": [ | ||
"*", | ||
"**/*" | ||
], | ||
"C_Cpp_Runner.excludeSearch": [ | ||
"**/build", | ||
"**/build/**", | ||
"**/.*", | ||
"**/.*/**", | ||
"**/.vscode", | ||
"**/.vscode/**" | ||
], | ||
"C_Cpp_Runner.useAddressSanitizer": false, | ||
"C_Cpp_Runner.useUndefinedSanitizer": false, | ||
"C_Cpp_Runner.useLeakSanitizer": false, | ||
"C_Cpp_Runner.showCompilationTime": false, | ||
"C_Cpp_Runner.useLinkTimeOptimization": false, | ||
"C_Cpp_Runner.msvcSecureNoWarnings": false, | ||
"files.associations": { | ||
"filenameextractpathandextension.h": "c", | ||
"assert.h": "c", | ||
"stdio.h": "c", | ||
"stdbool.h": "c" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "filenameExtractPathAndExtension", | ||
"version": "0.1.0", | ||
"repo": "mofosyne/filenameExtractPathAndExtension.c", | ||
"description": "Minimal Filename Extraction Of Path And Extention", | ||
"keywords": ["no heap", "malloc free", "no malloc", "filename", "extension"], | ||
"license": "GPL-3.0-or-later", | ||
"src": ["filenameExtractPathAndExtension.c", "filenameExtractPathAndExtension.h"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
void filenameExtractPathAndExtension(const char *fname, | ||
char *pathBuff, int pathSize, | ||
char *extBuff, int extSize) | ||
{ | ||
// Minimal Filename Extraction Of Path And Extention | ||
// Brian Khuu 2021 | ||
// https://gist.github.com/mofosyne/21587a9b68ea212ab976150ca3525664/edit | ||
int i = 0; | ||
int end = 0; | ||
int exti = 0; | ||
for (end = 0; fname[end] != '\0' ; end++) | ||
{ | ||
if ((fname[end] == '/')||(fname[end] == '\\')) | ||
exti = 0; | ||
else if (fname[end] == '.') | ||
exti = end; | ||
} | ||
if (exti == 0) | ||
exti = end; | ||
|
||
// Copy PathName | ||
if (pathBuff) | ||
{ | ||
for (i = 0; i < (pathSize-1) ; i++) | ||
{ | ||
if (!(i < exti)) | ||
break; | ||
pathBuff[i] = fname[i]; | ||
} | ||
pathBuff[i] = '\0'; | ||
} | ||
|
||
// Copy Extention | ||
if (extBuff) | ||
{ | ||
for (i = 0; i < (extSize-1) ; i++) | ||
{ | ||
if (!(i < (end-exti-1))) | ||
break; | ||
extBuff[i] = fname[exti + i + 1]; | ||
} | ||
extBuff[i] = '\0'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef __STRTOK_ESCAPED_H | ||
#define __STRTOK_ESCAPED_H | ||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
void filenameExtractPathAndExtension(const char *fname, | ||
char *pathBuff, int pathSize, | ||
char *extBuff, int extSize); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
all: clean test | ||
|
||
test: $(OBJS) | ||
$(CC) filenameExtractPathAndExtension.c test.c -std=c99 -Wall -Werror -o test | ||
./test | ||
|
||
clean: | ||
rm -f test | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
#include <assert.h> | ||
|
||
#include "filenameExtractPathAndExtension.h" | ||
|
||
bool test (char *fname, char *exp_path, char *exp_ext) | ||
{ | ||
char path[200] = {0}; | ||
char ext[200] = {0}; | ||
filenameExtractPathAndExtension(fname, path, sizeof(path), ext, sizeof(ext)); | ||
printf("%s, %s, %s\r\n", fname, path, ext); | ||
|
||
//printf("assert(test(\"%s\", \"%s\", \"%s\"));\r\n", fname, path, ext); | ||
|
||
if (strcmp(path, exp_path) != 0) | ||
{ | ||
return false; | ||
} | ||
if (strcmp(ext, exp_ext) != 0) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
int main (void) | ||
{ | ||
assert(test("test", "test", "")); | ||
assert(test("test.", "test", "")); | ||
assert(test("test.exp", "test", "exp")); | ||
assert(test("./hello/test.exp", "./hello/test", "exp")); | ||
|
||
printf("\r\nfilenameExtractPathAndExtension OK\r\n"); | ||
return 0; | ||
} |