Add all files.
parent
d5a6567aec
commit
13dff67a36
|
@ -0,0 +1,5 @@
|
|||
all:
|
||||
@clang -g -lncurses -I include src/*.c main.c -o gen-flake
|
||||
|
||||
bear:
|
||||
@bear -- clang -g -lncurses -I include src/*.c main.c -o gen-flake
|
|
@ -14,8 +14,7 @@
|
|||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
codelldb = pkgs.writeShellScriptBin "codelldb" ''
|
||||
#!/usr/bin/env bash
|
||||
exec ${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb "$@"
|
||||
exec ${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb "$@"
|
||||
'';
|
||||
in
|
||||
{
|
||||
|
@ -31,6 +30,9 @@
|
|||
buildInputs = with pkgs; [
|
||||
ncurses
|
||||
];
|
||||
shellHook = ''
|
||||
export GEN_FLAKE_SPEC_PATH="${./specs}"
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef GEN_FLAKE_DYN_ARRAY_H
|
||||
#define GEN_FLAKE_DYN_ARRAY_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
struct DynArray;
|
||||
|
||||
struct DynArray *dyn_array_new(size_t capacity);
|
||||
|
||||
size_t dyn_array_size(struct DynArray *a);
|
||||
|
||||
void dyn_array_push(struct DynArray *a, void *item);
|
||||
|
||||
void dyn_array_free(struct DynArray *a);
|
||||
|
||||
#endif /* GEN_FLAKE_DYN_ARRAY_H */
|
64
main.c
64
main.c
|
@ -1,7 +1,67 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <curses.h>
|
||||
#include <glob.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "dyn_array.h"
|
||||
|
||||
static int glob_specs(char *name, struct DynArray *entries) {
|
||||
assert(name);
|
||||
assert(entries);
|
||||
|
||||
int name_length = strlen(name);
|
||||
char *pattern = malloc(name_length + 3);
|
||||
if (!pattern) {
|
||||
goto cleanup;
|
||||
}
|
||||
memcpy(pattern, name, name_length);
|
||||
memcpy(pattern + name_length + 1, "/*", 3);
|
||||
|
||||
glob_t *pglob = 0;
|
||||
|
||||
int retval = 0;
|
||||
if ((retval = glob(pattern, GLOB_ONLYDIR | GLOB_MARK, 0, pglob))) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// GLOB_ONLYDIR is just a hint. We still need to actually verify the only
|
||||
// results we are reading in are directories.
|
||||
// TODO:
|
||||
|
||||
globfree(pglob);
|
||||
|
||||
cleanup:
|
||||
if (pattern) {
|
||||
free(pattern);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void cleanup(int sig) {
|
||||
endwin();
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int num = 0;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: gen-flake <spec>\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Allow interrupting the program cleanly.
|
||||
// TODO: How does this cleanup spec correctly?
|
||||
signal(SIGINT, cleanup);
|
||||
|
||||
initscr();
|
||||
keypad(stdscr, TRUE); // Enable keyboard mapping.
|
||||
nonl(); // Disables NL to CR/NL conversion on output.
|
||||
|
||||
cleanup(0);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
description = ''
|
||||
An opinionated clang flake.
|
||||
'';
|
||||
|
||||
inputs = {
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
codelldb = pkgs.writeShellScriptBin "codelldb" ''
|
||||
#!/usr/bin/env bash
|
||||
exec ${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb "$@"
|
||||
'';
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell.override {
|
||||
# https://nixos.wiki/wiki/Using_Clang_instead_of_GCC
|
||||
stdenv = pkgs.clangStdenv;
|
||||
} {
|
||||
packages = with pkgs; [
|
||||
bear
|
||||
clang-tools
|
||||
codelldb
|
||||
];
|
||||
buildInputs = with pkgs; [
|
||||
ncurses
|
||||
];
|
||||
};
|
||||
});
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [ -z "$VERSION" ]; then
|
||||
VERSION="default"
|
||||
fi
|
||||
|
||||
cp "$VERSION/flake.nix" "$OUT"
|
|
@ -0,0 +1,44 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include "dyn_array.h"
|
||||
|
||||
struct DynArray {
|
||||
void **buf;
|
||||
// The size of @buf excluding `NUL`.
|
||||
size_t size;
|
||||
// The allocated size of @buf including `NUL`.
|
||||
size_t _capacity;
|
||||
};
|
||||
|
||||
struct DynArray *dyn_array_new(size_t capacity) {
|
||||
struct DynArray *a = malloc(sizeof(struct DynArray));
|
||||
a->buf = calloc(capacity, sizeof(void *));
|
||||
a->size = 0;
|
||||
a->_capacity = capacity;
|
||||
return a;
|
||||
}
|
||||
|
||||
size_t dyn_array_size(struct DynArray *a) {
|
||||
assert(a);
|
||||
|
||||
return a->size;
|
||||
}
|
||||
|
||||
void dyn_array_push(struct DynArray *a, void *item) {
|
||||
assert(a);
|
||||
|
||||
if (a->size == a->_capacity) {
|
||||
// We assume reallocation will work.
|
||||
a->_capacity *= 2;
|
||||
a = realloc(a, sizeof(void *) * a->_capacity);
|
||||
}
|
||||
a->size += 1;
|
||||
a->buf[a->size] = item;
|
||||
}
|
||||
|
||||
void dyn_array_free(struct DynArray *a) {
|
||||
assert(a);
|
||||
|
||||
free(a->buf);
|
||||
free(a);
|
||||
}
|
Loading…
Reference in New Issue