Skip to content

Commit

Permalink
add main logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mofosyne committed Dec 7, 2024
1 parent 2990d1d commit 2b036f2
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf

test
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
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
}
24 changes: 24 additions & 0 deletions .vscode/launch.json
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
}
]
}
]
}
65 changes: 65 additions & 0 deletions .vscode/settings.json
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"
}
}
9 changes: 9 additions & 0 deletions clib.json
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"]
}
44 changes: 44 additions & 0 deletions filenameExtractPathAndExtension.c
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';
}
}
13 changes: 13 additions & 0 deletions filenameExtractPathAndExtension.h
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
10 changes: 10 additions & 0 deletions makefile
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
37 changes: 37 additions & 0 deletions test.c
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;
}

0 comments on commit 2b036f2

Please sign in to comment.