Skip to content

Commit

Permalink
remove submodule, add source files (#134)
Browse files Browse the repository at this point in the history
* remove submodule

* add alex-c-collections, remove submodule
  • Loading branch information
alex-courtis committed Sep 4, 2023
1 parent 9170e30 commit 2f946a8
Show file tree
Hide file tree
Showing 19 changed files with 1,360 additions and 27 deletions.
1 change: 1 addition & 0 deletions .cppcheck.supp
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
unusedFunction:lib/col/*c
unusedFunction:tst/wrap-log.c
unusedFunction:tst/util.c
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: deps
run: |
sudo add-apt-repository universe
Expand Down
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

6 changes: 0 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ Most will be available if you are running a wlroots based compositor like sway.

yaml-cpp will need to be installed via your distribution's package manager.

## Library Submodules

Following clone the libraries must be fetched.

`git submodule update --init`

## Development

gcc is the default for packaging reasons, however clang is preferred.
Expand Down
15 changes: 5 additions & 10 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
include config.mk

INC_H = $(wildcard inc/*.h)
INC_H = $(wildcard inc/*.h) $(wildcard lib/col/inc/*.h)

SRC_C = $(wildcard src/*.c)
SRC_C = $(wildcard src/*.c) $(wildcard lib/col/src/*.c)
SRC_CXX = $(wildcard src/*.cpp)
SRC_O = $(SRC_C:.c=.o) $(SRC_CXX:.cpp=.o)

LIB_H = $(wildcard lib/alex-c-collections/inc/*.h)
LIB_C = $(wildcard lib/alex-c-collections/src/*.c)
LIB_O = $(LIB_C:.c=.o)

EXAMPLE_C = $(wildcard examples/*.c)
EXAMPLE_O = $(EXAMPLE_C:.c=.o)
EXAMPLE_E = $(EXAMPLE_C:.c=)
Expand All @@ -28,11 +24,10 @@ TST_T = $(patsubst tst%,test%,$(TST_E))
all: way-displays

$(SRC_O): $(INC_H) $(PRO_H) config.mk GNUmakefile
$(LIB_O): $(LIB_H) $(LIB_C) config.mk GNUmakefile
$(PRO_O): $(PRO_H) config.mk GNUmakefile
$(EXAMPLE_O): $(INC_H) $(PRO_H) config.mk GNUmakefile

way-displays: $(SRC_O) $(PRO_O) $(LIB_O)
way-displays: $(SRC_O) $(PRO_O)
$(CXX) -o $(@) $(^) $(LDFLAGS) $(LDLIBS)

$(PRO_H): $(PRO_X)
Expand All @@ -42,7 +37,7 @@ $(PRO_C): $(PRO_X)
wayland-scanner private-code $(@:.c=.xml) $@

clean:
rm -f way-displays $(SRC_O) $(PRO_O) $(PRO_H) $(PRO_C) $(LIB_O) $(TST_O) $(TST_E) $(EXAMPLE_E) $(EXAMPLE_O)
rm -f way-displays $(SRC_O) $(PRO_O) $(PRO_H) $(PRO_C) $(TST_O) $(TST_E) $(EXAMPLE_E) $(EXAMPLE_O)

install: way-displays way-displays.1 cfg.yaml
mkdir -p $(DESTDIR)$(PREFIX)/bin
Expand Down Expand Up @@ -84,7 +79,7 @@ $(TST_T): all
$(VALGRIND) ./$(EXE)

examples: $(EXAMPLE_E)
examples/%: examples/%.o $(filter-out src/main.o,$(SRC_O)) $(PRO_O) $(LIB_O)
examples/%: examples/%.o $(filter-out src/main.o,$(SRC_O)) $(PRO_O)
$(CXX) -o $(@) $(^) $(LDFLAGS) $(LDLIBS)

.PHONY: all clean install uninstall man cppcheck iwyu test test-vg $(TST_T)
Expand Down
2 changes: 1 addition & 1 deletion config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PREFIX ?= /usr/local
PREFIX_ETC ?= /usr/local
ROOT_ETC ?= /etc

INCS = -Iinc -Ipro -Ilib/alex-c-collections/inc
INCS = -Iinc -Ipro -Ilib/col/inc

CPPFLAGS += $(INCS) -D_GNU_SOURCE -DVERSION=\"$(VERSION)\" -DROOT_ETC=\"$(ROOT_ETC)\"

Expand Down
1 change: 0 additions & 1 deletion lib/alex-c-collections
Submodule alex-c-collections deleted from 4c3f2b
1 change: 1 addition & 0 deletions lib/col/.source
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[email protected]:alex-courtis/alex-c-collections.git v1.1.1
67 changes: 67 additions & 0 deletions lib/col/inc/itable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef ITABLE_H
#define ITABLE_H

#include <stddef.h>
#include <stdint.h>

/*
* Array backed integer indexed table.
* Entries preserve insertion order.
* Operations linearly traverse keys.
* NULL values permitted.
* Not thread safe.
*/
struct ITable;

/*
* Entry iterator.
*/
struct ITableIter {
const uint64_t key;
const void* const val;
};

/*
* Lifecycle
*/

// construct a table with initial size, growing as necessary, NULL on zero param
const struct ITable *itable_init(const size_t initial, const size_t grow);

// free table
void itable_free(const void* const tab);

// free table and vals, null free_val uses free()
void itable_free_vals(const struct ITable* const tab, void (*free_val)(const void* const val));

// free iter
void itable_iter_free(const struct ITableIter* const iter);

/*
* Access
*/

// return val, NULL not present
const void *itable_get(const struct ITable* const tab, const uint64_t key);

// create an iterator, caller must itable_iter_free or invoke itable_next until NULL
const struct ITableIter *itable_iter(const struct ITable* const tab);

// next iterator value, NULL at end of list
const struct ITableIter *itable_next(const struct ITableIter* const iter);

// number of entries with val
size_t itable_size(const struct ITable* const tab);

/*
* Mutate
*/

// set key/val, return old val if overwritten
const void *itable_put(const struct ITable* const tab, const uint64_t key, const void* const val);

// remove key, return old val if present
const void *itable_remove(const struct ITable* const tab, const uint64_t key);

#endif // ITABLE_H

65 changes: 65 additions & 0 deletions lib/col/inc/oset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#ifndef OSET_H
#define OSET_H

#include <stdbool.h>
#include <stddef.h>

/*
* Array backed ordered set.
* Operations linearly traverse values.
* NULL not permitted.
* Not thread safe.
*/
struct OSet;

/*
* Entry iterator.
*/
struct OSetIter {
const void* const val;
};

/*
* Lifecycle
*/

// construct a set with initial size, grow as needed, NULL on zero param
const struct OSet *oset_init(const size_t initial, const size_t grow);

// free set
void oset_free(const void* const set);

// free map and vals, NULL free_val uses free()
void oset_free_vals(const struct OSet* const set, void (*free_val)(const void* const val));

// free iter
void oset_iter_free(const struct OSetIter* const iter);

/*
* Access
*/

// true if this set contains the specified element
bool oset_contains(const struct OSet* const set, const void* const val);

// number of values
size_t oset_size(const struct OSet* const set);

// create an iterator, caller must oset_iter_free or invoke oset_next until NULL
const struct OSetIter *oset_iter(const struct OSet* const set);

// next iterator value, NULL at end of set
const struct OSetIter *oset_next(const struct OSetIter* const iter);

/*
* Mutate
*/

// true if this set did not already contain the specified element
bool oset_add(const struct OSet* const set, const void* const val);

// true if this set contained the element
bool oset_remove(const struct OSet* const set, const void* const val);

#endif // OSET_H

59 changes: 59 additions & 0 deletions lib/col/inc/ptable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef PTABLE_H
#define PTABLE_H

#include <stddef.h>

/*
* ITable convenience wrapper with pointer key.
*/
struct PTable;

/*
* Entry iterator.
*/
struct PTableIter {
const void *key;
const void *val;
};

/*
* Lifecycle
*/

// construct a table with initial size, growing as necessary, NULL on zero param
const struct PTable *ptable_init(const size_t initial, const size_t grow);

// free table
void ptable_free(const void* const tab);

// free table and vals, null free_val uses free()
void ptable_free_vals(const struct PTable* const tab, void (*free_val)(const void* const val));

// free iter
void ptable_iter_free(const struct PTableIter* const iter);

/*
* Access
*/

// return val, NULL not present
const void *ptable_get(const struct PTable* const tab, const void* const key);

// create an iterator, caller must ptable_iter_free or invoke ptable_next until NULL
const struct PTableIter *ptable_iter(const struct PTable* const tab);

// next iterator value, NULL at end of list
const struct PTableIter *ptable_next(const struct PTableIter* const iter);

// number of entries with val
size_t ptable_size(const struct PTable* const tab);

/*
* Mutate
*/

// set key/val, return old val if overwritten, NULL val to remove
const void *ptable_put(const struct PTable* const tab, const void* const key, const void* const val);

#endif // PTABLE_H

84 changes: 84 additions & 0 deletions lib/col/inc/slist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#ifndef SLIST_H
#define SLIST_H

#include <stdbool.h>
#include <stddef.h>

struct SList {
void *val;
struct SList *nex;
};

/*
* Lifecycle
*/

// clone the list, setting val pointers
struct SList *slist_shallow_clone(struct SList *head);

// free list
void slist_free(struct SList **head);

// free list and vals, NULL free_val uses free()
void slist_free_vals(struct SList **head, void (*free_val)(void *val));

/*
* Mutate
*/

// append val to a list
struct SList *slist_append(struct SList **head, void *val);

// remove an item, returning the val
void *slist_remove(struct SList **head, struct SList **item);

// remove items, NULL predicate is val pointer comparison
size_t slist_remove_all(struct SList **head, bool (*predicate)(const void *val, const void *data), const void *data);

// remove items and free vals, NULL predicate is val pointer comparison, NULL free_val calls free()
size_t slist_remove_all_free(struct SList **head, bool (*predicate)(const void *val, const void *data), const void *data, void (*free_val)(void *val));

/*
* Access
*/

// val at position
void *slist_at(struct SList *head, size_t index);

// find
struct SList *slist_find(struct SList *head, bool (*test)(const void *val));

// find a val
void *slist_find_val(struct SList *head, bool (*test)(const void *val));

// find, NULL predicate is val pointer comparison
struct SList *slist_find_equal(struct SList *head, bool (*predicate)(const void *val, const void *data), const void *data);

// find a val, NULL predicate is val pointer comparison
void *slist_find_equal_val(struct SList *head, bool (*predicate)(const void *val, const void *data), const void *data);

// same length and every item passes test in order, NULL equal compares pointers
bool slist_equal(struct SList *a, struct SList *b, bool (*equal)(const void *a, const void *b));

/*
* Utility
*/

// length
size_t slist_length(struct SList *head);

// sort into a new list
struct SList *slist_sort(struct SList *head, bool (*before)(const void *a, const void *b));

// move items between lists with predicate, NULL predicate does nothing
void slist_move(struct SList **to, struct SList **from, bool (*predicate)(const void *val, const void *data), const void *data);

/*
* Predicate
*/

// test val for equality using strcmp
bool slist_predicate_strcmp(const void *val, const void *data);

#endif // SLIST_H

Loading

0 comments on commit 2f946a8

Please sign in to comment.