-
Notifications
You must be signed in to change notification settings - Fork 8
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
13 changed files
with
278 additions
and
35 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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: [ main ] | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
check_build: | ||
|
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: [ main ] | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- "**.nix" | ||
- "**.lock" | ||
|
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
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 |
---|---|---|
|
@@ -90,3 +90,4 @@ result | |
# config | ||
.cache | ||
compile_commands.json | ||
.pre-commit-config.yaml |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,96 @@ | ||
#include "./getopt.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
char *optarg = NULL; | ||
int optind = 1, opterr = 0, optopt = '\0'; | ||
|
||
static void getopt_printerr(const char *msg) { | ||
if (opterr) { | ||
fprintf(stderr, "%s", msg); | ||
} | ||
} | ||
|
||
static int getopt_in(char d, const char *str) { | ||
int i = 0; | ||
while (str[i] != '\0') { | ||
if (d == str[i] && str[i] != ':') { | ||
return i; | ||
} | ||
i++; | ||
} | ||
return 0; | ||
} | ||
|
||
static void getopt_exchange(char *argv[], int i, int j) { | ||
char *tmp = argv[i]; | ||
argv[i] = argv[j]; | ||
argv[j] = tmp; | ||
} | ||
|
||
int getopt(int argc, char **argv, const char *optstring) { | ||
int c; | ||
static char *nextchar = NULL; | ||
static int coropt = 1; | ||
if (!coropt) { | ||
coropt = 1; | ||
} | ||
|
||
if (coropt >= argc || argv[coropt] == NULL) { | ||
return -1; | ||
} | ||
|
||
while (argv[coropt] && argv[coropt][0] != '-') { | ||
coropt++; | ||
} | ||
|
||
if (nextchar == NULL || *nextchar == '\0') { | ||
if (coropt >= argc) { | ||
return -1; | ||
} | ||
nextchar = &argv[coropt][1]; | ||
} | ||
|
||
int idx; | ||
if (!((idx = getopt_in(*nextchar, optstring)) >= 0)) { | ||
getopt_printerr("invalid option\n"); | ||
optopt = *nextchar; | ||
return '?'; | ||
} | ||
|
||
c = *nextchar++; | ||
if (*nextchar == '\0') { | ||
coropt++; | ||
nextchar = NULL; | ||
} | ||
|
||
if (optstring[idx + 1] != ':') { | ||
coropt--; | ||
optind++; | ||
goto exit; | ||
} | ||
|
||
if (nextchar != NULL && *nextchar != '\0') { | ||
coropt++; | ||
} | ||
|
||
if (coropt >= argc || argv[coropt][0] == '-') { | ||
getopt_printerr("option requires an argument\n"); | ||
optopt = *nextchar; | ||
return '?'; | ||
} | ||
|
||
optarg = argv[coropt]; | ||
|
||
exit: { | ||
int i = coropt; | ||
int j = coropt - 1; | ||
while (j >= 0 && argv[j][0] != '-') { | ||
getopt_exchange(argv, i, j); | ||
i--; | ||
j--; | ||
} | ||
} | ||
optind++; | ||
return 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,23 @@ | ||
// Reimplementation of GNU getopt | ||
#ifndef _GETOPT_H_ | ||
#define _GETOPT_H_ | ||
|
||
struct option { | ||
const char *name; | ||
int has_arg; | ||
int *flag; | ||
int val; | ||
}; | ||
|
||
extern char *optarg; | ||
extern int optind, opterr, optopt; | ||
|
||
int getopt(int argc, char **argv, const char *optstring); | ||
|
||
int getopt_long(int argc, char *const argv[], const char *optstring, | ||
const struct option *longopts, int *longindex); | ||
|
||
int getopt_long_only(int argc, char *const argv[], const char *optstring, | ||
const struct option *longopts, int *longindex); | ||
|
||
#endif // _GETOPT_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
Oops, something went wrong.