Skip to content

Commit

Permalink
v0.1.1 documentation changes and C util program renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
mofosyne committed Jan 19, 2025
1 parent 4eb781f commit 59b447d
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ sexp_formatter
*.o

temp/
sexp_prettify_cli
sexp_prettify
sexp_prettify_cpp_cli
sexp_prettify_kicad_cli
sexp_prettify_kicad_original_cli
45 changes: 36 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# sexp_formatter

![CI/CD Status Badge](https://github.com/mofosyne/sexp_formatter/actions/workflows/ci.yml/badge.svg)
<versionBadge>![Version 0.1.1](https://img.shields.io/badge/version-0.1.1-blue.svg)</versionBadge>
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![C](https://img.shields.io/badge/Language-C-blue.svg)](https://en.wikipedia.org/wiki/C_(programming_language))
[![CI/CD Status Badge](https://github.com/mofosyne/sexp_formatter/actions/workflows/ci.yml/badge.svg)](https://github.com/mofosyne/sexp_prettify/actions)

Prettifies KiCad-like S-expressions according to a KiCADv8-style formatting Via Python.
This is both a cli program as well as a C/CPP/Python implementation library.

This is primarily targeted at C but there is multiple implementations in
C/CPP/Python as well that you can use for integration with your code.

```bash
# Build sexp_prettify_cli
# Build sexp_prettify
make

# Install sexp_prettify_cli as sexp_prettify system wide
# Install sexp_prettify as sexp_prettify system wide
make install

# Remove sexp_prettify cli system wide
Expand All @@ -19,13 +24,13 @@ make uninstall
make cicd
```

Expected Help Message when running `sexp_prettify_cli`
Expected Help Message when running `sexp_prettify`

```
S-Expression Formatter (Brian Khuu 2024)
Usage:
./sexp_prettify_cli [OPTION]... SOURCE [DESTINATION]
./sexp_prettify [OPTION]... SOURCE [DESTINATION]
SOURCE Source file path. If '-' then use standard stream input
DESTINATION Destination file path. If omitted or '-' then use standard stream output
Expand All @@ -39,7 +44,7 @@ Options:
Example:
- Use standard input and standard output. Also use KiCAD's standard compact list and shortform setting.
./sexp_prettify_cli -l pts -s font -s stroke -s fill -s offset -s rotate -s scale - -
./sexp_prettify -l pts -s font -s stroke -s fill -s offset -s rotate -s scale - -
```

When integrating into your project, copy over `sexp_prettify.c` and `sexp_prettify.h` and use these functions:
Expand All @@ -55,6 +60,28 @@ typedef void (*PrettifySExprPutcFunc)(char c, void *context);
void sexp_prettify(struct PrettifySExprState *state, const char c, PrettifySExprPutcFunc output_func, void *output_func_context);
```
An example of how to use this C library in your project:
First make a callback function
```c
void putc_handler(char c, void *context_putc) { fputc(c, (FILE *)context_putc); }
```

Then implement this in your main program as a loop of this form

```c
struct PrettifySExprState state = {0};
sexp_prettify_init(&state, PRETTIFY_SEXPR_KICAD_DEFAULT_INDENT_CHAR, PRETTIFY_SEXPR_KICAD_DEFAULT_INDENT_SIZE, PRETTIFY_SEXPR_KICAD_DEFAULT_CONSECUTIVE_TOKEN_WRAP_THRESHOLD);

int ch;
FILE *dst_file = stdout;
while ((ch = getc(message)) != EOF)
{
sexp_prettify(&state, ch, &putc_handler, dst_file);
}
```
## Developer
* Run `make` to build all the c and cpp binaries shown above.
Expand All @@ -63,11 +90,11 @@ void sexp_prettify(struct PrettifySExprState *state, const char c, PrettifySExpr
### About Files
* sexp_prettify_cli.py : This is a python implementation
* sexp_prettify.py : This is a python implementation
* sexp_prettify_kicad_original_cli : This is a cpp original logic from the KiCAD repository as of 2024-12-03
* sexp_prettify_kicad_cli : This is the new cpp logic from the KiCAD repository being proposed for KiCAD
* sexp_prettify_cpp_cli : This is a cpp cli wrapper around the c function `sexp_prettify()` in `sexp_prettify.c/h`
* sexp_prettify_cli : This is a c cli wrapper around the c function `sexp_prettify()` in `sexp_prettify.c/h`
* sexp_prettify : This is a c cli wrapper around the c function `sexp_prettify()` in `sexp_prettify.c/h`
## History
Expand Down
4 changes: 2 additions & 2 deletions clib.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "S-Expressions Prettify",
"version": "0.1.0",
"version": "0.1.1",
"repo": "mofosyne/sexp_prettify",
"description": "Prettifies S-expressions (Based On KiCAD formatting)",
"keywords": ["no heap", "malloc free", "formatter", "kicad", "sexp", "s-expressions", "no malloc"],
"license": "GPL-3.0-or-later",
"src": ["sexp_prettify.c", "sexp_prettify.h"],
"src": ["src/sexp_prettify.c", "src/sexp_prettify.h"],
"install": "make install",
"uninstall": "make uninstall"
}
29 changes: 18 additions & 11 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@

CFLAGS = -std=c99 -Wall -pedantic
CFLAGS = -std=c99 -Wall -pedantic -Isrc
PREFIX ?= /usr/local

main: sexp_prettify_cli
main: sexp_prettify readme_update

all: sexp_prettify_cli sexp_prettify_cpp_cli sexp_prettify_kicad_cli sexp_prettify_kicad_original_cli
all: sexp_prettify sexp_prettify_cpp_cli sexp_prettify_kicad_cli sexp_prettify_kicad_original_cli

sexp_prettify_cli.o: sexp_prettify.c
$(CC) -c -o $@ $^
src/sexp_prettify.o: src/sexp_prettify.c
$(CC) $(CFLAGS) -c -o $@ $^

sexp_prettify_cli: sexp_prettify_cli.c sexp_prettify.o sexp_prettify.h
$(CC) -o $@ $^
sexp_prettify: sexp_prettify_cli.c src/sexp_prettify.o
$(CC) $(CFLAGS) -o $@ $^

sexp_prettify_cpp_cli: sexp_prettify_cpp_cli.cpp sexp_prettify.o sexp_prettify.h
$(CXX) -o $@ $^
sexp_prettify_cpp_cli: sexp_prettify_cpp_cli.cpp src/sexp_prettify.o src/sexp_prettify.h
$(CXX) $(CFLAGS) -o $@ $^

sexp_prettify_kicad_cli: sexp_prettify_kicad_cli.cpp
$(CXX) -o $@ $^
$(CXX) $(CFLAGS) -o $@ $^

sexp_prettify_kicad_original_cli: sexp_prettify_kicad_original_cli.cpp
$(CXX) -o $@ $^
$(CXX) $(CFLAGS) -o $@ $^

# Dev Note: $ is used by both make and AWK. Must escape $ for use in AWK within makefile.
.PHONY: readme_update
readme_update:
# Library Version (From clib package metadata)
jq -r '.version' clib.json | xargs -I{} sed -i 's|<version>.*</version>|<version>{}</version>|' README.md
jq -r '.version' clib.json | xargs -I{} sed -i 's|<versionBadge>.*</versionBadge>|<versionBadge>![Version {}](https://img.shields.io/badge/version-{}-blue.svg)</versionBadge>|' README.md

.PHONY: install
install: sexp_prettify_cli
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ echo "========================================================================"
# ./test_standard_single.sh <EXECUTABLE> <SKIP ZERO STYLE>
./test_standard_single.sh ./sexp_prettify_kicad_cli true
./test_standard_single.sh ./sexp_prettify_cpp_cli false
./test_standard_single.sh ./sexp_prettify_cli false
./test_standard_single.sh ./sexp_prettify_cli.py true
./test_standard_single.sh ./sexp_prettify false

echo "All tests passed in all executables!"
exit 0
2 changes: 1 addition & 1 deletion time_test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ executables=(
"./sexp_prettify_kicad_original_cli"
"./sexp_prettify_kicad_cli"
"./sexp_prettify_cpp_cli"
"./sexp_prettify_cli"
"./sexp_prettify"
)


Expand Down

0 comments on commit 59b447d

Please sign in to comment.