Skip to content

Commit 93f7bb1

Browse files
committed
init
0 parents  commit 93f7bb1

12 files changed

Lines changed: 341 additions & 0 deletions

File tree

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*.c]
4+
indent_style = tab
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.DS_STORE
2+
*.o
3+
*.log
4+
*.gcov
5+
*.gcda
6+
*.gcno
7+
binary
8+
test
9+
example
10+
coverage

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: c
2+
compiler:
3+
- clang
4+
- gcc
5+
script: make run-test
6+
notifications:
7+
email: false

Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
PREFIX ?= /usr/local
2+
3+
SRC = cli.c deps/os.c/os.c
4+
5+
OBJ_SRC = $(SRC:.c=.o)
6+
7+
CFLAGS = -D_GNU_SOURCE -std=c99 -I deps/os.c/
8+
9+
LFLAGS = -Wall -Wno-format-y2k -W -Wstrict-prototypes \
10+
-Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch \
11+
-Wshadow -Wcast-align -Wbad-function-cast -Wchar-subscripts -Winline \
12+
-Wnested-externs -Wredundant-decls
13+
14+
os: $(OBJ_SRC)
15+
$(CC) $(OBJ_SRC) -o $@
16+
17+
.SUFFIXES: .c .o
18+
.c.o:
19+
$(CC) $< $(CFLAGS) $(LFLAGS) -c -o $@
20+
21+
install: os
22+
cp -f os $(PREFIX)/bin/os
23+
24+
uninstall:
25+
rm -f $(PREFIX)/bin/os
26+
27+
run-test: os
28+
bash ./test.sh
29+
30+
clean:
31+
rm -f os *.o deps/**/*.o *.gc{ov,da,no}
32+
33+
.PHONY: clean run-test install uninstall

cli.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// cli.c
3+
//
4+
// MIT licensed.
5+
// Copyright (c) Abraham Hernandez <abraham@abranhe.com>
6+
//
7+
8+
#include <stdio.h>
9+
#include <string.h>
10+
#include "os.h"
11+
12+
const char*
13+
show_help() {
14+
return "\n\
15+
Wanna know your operating system? - I know right :)\n\n\
16+
Usage:\n\n\
17+
$ os <flag> \n\n\
18+
Options:\n\n\
19+
-v, --version output version number\n\
20+
-h, --help output usage information\n\n\
21+
Example:\n\n\
22+
$ os\n\
23+
macOS\n\n";
24+
}
25+
26+
/* CLI. */
27+
int
28+
main(int argc, char **argv) {
29+
char *a = argv[1];
30+
31+
if (argc == 2) {
32+
if (!strcmp(a, "-v") || !strcmp(a, "--version")) {
33+
printf("%s", "1.0.0\n");
34+
return 0;
35+
}
36+
37+
if (!strcmp(a, "-h") || !strcmp(a, "--help")) {
38+
printf("%s", show_help());
39+
return 0;
40+
}
41+
}
42+
43+
if (argc > 1) {
44+
fprintf(stderr, "\033[31mSee `--help` for details.\033[0m\n");
45+
return 1;
46+
}
47+
48+
printf("%s\n", operating_system());
49+
return 0;
50+
}

deps/os.c/os.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// os.c
3+
// Get to know your operating system
4+
//
5+
// MIT licensed.
6+
// Copyright (c) Abraham Hernandez <abraham@abranhe.com>
7+
//
8+
9+
const char * operating_system()
10+
{
11+
#ifdef _WIN32
12+
return "win32";
13+
#elif _WIN64
14+
return "win64";
15+
#elif __unix || __unix__
16+
return "unix";
17+
#elif __APPLE__ || __MACH__
18+
return "macOS";
19+
#elif __linux__
20+
return "linux";
21+
#elif __FreeBSD__
22+
return "freeBSD";
23+
#else
24+
return "other";
25+
#endif
26+
}

deps/os.c/os.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef OS_H
2+
#define OS_H
3+
4+
//
5+
// os.h
6+
//
7+
// MIT licensed.
8+
// Copyright (c) Abraham Hernandez <abraham@abranhe.com>
9+
//
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
const char * operating_system(void);
16+
17+
#ifdef __cplusplus
18+
}
19+
#endif
20+
21+
#endif // OS_H

deps/os.c/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "os.c",
3+
"version": "1.0.2",
4+
"description": "Small C library to know your operating system",
5+
"license": "MIT",
6+
"keywords": [
7+
"os",
8+
"macos",
9+
"linux",
10+
"windows",
11+
"win32",
12+
"win64",
13+
"operating-system",
14+
"tool"
15+
],
16+
"repo": "abranhe/os.c",
17+
"src": [
18+
"os.h",
19+
"os.c"
20+
]
21+
}

license

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Abraham Hernandez <abraham@abranhe.com> (abranhe.com)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "os",
3+
"version": "1.0.0",
4+
"description": "Wanna know your operating system? - I know right :)",
5+
"license": "MIT",
6+
"keywords": [
7+
"operating-system",
8+
"os",
9+
"macos",
10+
"linux",
11+
"windows",
12+
"win32",
13+
"win64",
14+
"bin",
15+
"cli"
16+
],
17+
"repo": "abranhe/os",
18+
"dependencies": {
19+
"abranhe/os.c": "1.0.2"
20+
},
21+
"install": "make install"
22+
}

0 commit comments

Comments
 (0)