aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAiden Woodruff <aiden.woodruff@gmail.com>2019-09-18 22:51:25 -0500
committerAiden Woodruff <aiden.woodruff@gmail.com>2019-09-18 22:51:25 -0500
commitf64ebb50da3a74b9060f1616d05b1e25e0503798 (patch)
tree7c2a843291308ea3466ae4e970d01b6817e5ce23 /src
parent176647fc5eb719953aa3961f39b3311e3368ce6a (diff)
downloadlife-f64ebb50da3a74b9060f1616d05b1e25e0503798.tar.gz
life-f64ebb50da3a74b9060f1616d05b1e25e0503798.tar.bz2
life-f64ebb50da3a74b9060f1616d05b1e25e0503798.zip
Use CMake instead of other stuff
Add stuff to develop in Visual Studio (i.e. to gitignore) Add correct_curses.h Add MSVC fixes to foreach.h macros Add Windows getopt.c and getopt.h (for now).
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt6
-rw-r--r--src/correct_curses.h24
-rw-r--r--src/foreach.h37
-rw-r--r--src/getopt.c51
-rw-r--r--src/getopt.h85
5 files changed, 195 insertions, 8 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..3b216bf
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,6 @@
1# Makefile stuff
2include_directories(.)
3add_executable(life life.c life.h updatemap.c updatemap.h menus.c menus.h)
4target_compile_features(life PUBLIC c_function_prototypes c_variadic_macros)
5target_include_directories(life PRIVATE "${CURSES_INCLUDE_DIRS}")
6target_link_libraries(life "${CURSES_LIBRARIES}")
diff --git a/src/correct_curses.h b/src/correct_curses.h
new file mode 100644
index 0000000..60bc2ba
--- /dev/null
+++ b/src/correct_curses.h
@@ -0,0 +1,24 @@
1#ifndef GRAPH_CORRECT_CURSES_H
2#define GRAPH_CORRECT_CURSES_H
3#if defined(HAVE_CMAKECONFIG_H)
4#include <cmakeconfig.h>
5
6#if defined HAVE_NCURSESW_CURSES_H
7# include <ncursesw/curses.h>
8#elif defined HAVE_NCURSESW_H
9# include <ncursesw.h>
10#elif defined HAVE_NCURSES_CURSES_H
11# include <ncurses/curses.h>
12#elif defined HAVE_NCURSES_H
13# include <ncurses.h>
14#elif defined HAVE_CURSES_H
15# include <curses.h>
16#else
17# error "SysV or X/Open-compatible Curses header file required"
18#endif
19#else
20
21// Fingers-crossed
22#include <curses.h>
23#endif
24#endif // GRAPH_CORRECT_CURSES_H \ No newline at end of file
diff --git a/src/foreach.h b/src/foreach.h
index e684b93..9b20953 100644
--- a/src/foreach.h
+++ b/src/foreach.h
@@ -1,11 +1,35 @@
1#ifndef NARG 1#ifndef NARG
2#define NARG(...) NARG_(__VA_ARGS__, RSEQ_N)
3#define NARG_(...) NARG_N(__VA_ARGS__)
4#define RSEQ_N 8, 7, 6, 5, 4, 3, 2, 1, 0
5#define NARG_N(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N 2#define NARG_N(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N
3#define RSEQ_N 8, 7, 6, 5, 4, 3, 2, 1, 0
4#if _MSC_VER && !__INTEL_COMPILER
5#define EXPAND(...) __VA_ARGS__
6#define NARG_(...) EXPAND(EXPAND(NARG_N) (__VA_ARGS__))
7#else
8#define NARG_(...) NARG_N(__VA_ARGS__)
9#endif
10#define NARG(...) NARG_(__VA_ARGS__, RSEQ_N)
6#endif 11#endif
7 12
8#ifndef foreach 13#ifndef foreach
14
15#define CONCAT2(x, y) x##y
16#define CONCAT1(x, y) CONCAT2(x,y)
17#define CONCATENATE(x, y) CONCAT1(x, y)
18
19#if _MSC_VER && !__INTEL_COMPILER
20#undef EXPAND
21#define EXPAND(...) __VA_ARGS__
22#define FOREACH_0(func) } while (0)
23#define FOREACH_1(func, first) func(first); FOREACH_0(func)
24#define FOREACH_2(func, first,...) func(first); EXPAND(EXPAND(FOREACH_1)(func, __VA_ARGS__))
25#define FOREACH_3(func, first,...) func(first); EXPAND(EXPAND(FOREACH_2)(func, __VA_ARGS__))
26#define FOREACH_4(func, first,...) func(first); EXPAND(EXPAND(FOREACH_3)(func, __VA_ARGS__))
27#define FOREACH_5(func, first,...) func(first); EXPAND(EXPAND(FOREACH_4)(func, __VA_ARGS__))
28#define FOREACH_6(func, first,...) func(first); EXPAND(EXPAND(FOREACH_5)(func, __VA_ARGS__))
29#define FOREACH_7(func, first,...) func(first); EXPAND(EXPAND(FOREACH_6)(func, __VA_ARGS__))
30#define FOREACH_8(func, first,...) func(first); EXPAND(EXPAND(FOREACH_7)(func, __VA_ARGS__))
31#define foreach(func, ...) do { EXPAND(CONCATENATE(FOREACH_, NARG(__VA_ARGS__))(func, __VA_ARGS__))
32#else
9#define FOREACH_0(func) } while (0) 33#define FOREACH_0(func) } while (0)
10#define FOREACH_1(func, first) func(first); FOREACH_0(func) 34#define FOREACH_1(func, first) func(first); FOREACH_0(func)
11#define FOREACH_2(func, first,...) func(first); FOREACH_1(func, __VA_ARGS__) 35#define FOREACH_2(func, first,...) func(first); FOREACH_1(func, __VA_ARGS__)
@@ -15,10 +39,7 @@
15#define FOREACH_6(func, first,...) func(first); FOREACH_5(func, __VA_ARGS__) 39#define FOREACH_6(func, first,...) func(first); FOREACH_5(func, __VA_ARGS__)
16#define FOREACH_7(func, first,...) func(first); FOREACH_6(func, __VA_ARGS__) 40#define FOREACH_7(func, first,...) func(first); FOREACH_6(func, __VA_ARGS__)
17#define FOREACH_8(func, first,...) func(first); FOREACH_7(func, __VA_ARGS__) 41#define FOREACH_8(func, first,...) func(first); FOREACH_7(func, __VA_ARGS__)
18 42#define foreach(func, ...) do { CONCATENATE(FOREACH_, NARG(__VA_ARGS__))(func, __VA_ARGS__)
19#define CONCAT1(x, y) x##y 43#endif
20#define CONCATENATE(x, y) CONCAT1(x, y)
21
22#define foreach(func, ...) do { CONCATENATE(FOREACH_,NARG(__VA_ARGS__))(func, __VA_ARGS__)
23#endif 44#endif
24 45
diff --git a/src/getopt.c b/src/getopt.c
new file mode 100644
index 0000000..cb4f192
--- /dev/null
+++ b/src/getopt.c
@@ -0,0 +1,51 @@
1/* *****************************************************************
2*
3* Copyright 2016 Microsoft
4*
5*
6* Licensed under the Apache License, Version 2.0 (the "License");
7* you may not use this file except in compliance with the License.
8* You may obtain a copy of the License at
9*
10* http://www.apache.org/licenses/LICENSE-2.0
11*
12* Unless required by applicable law or agreed to in writing, software
13* distributed under the License is distributed on an "AS IS" BASIS,
14* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15* See the License for the specific language governing permissions and
16* limitations under the License.
17*
18******************************************************************/
19
20#include "getopt.h"
21#include <string.h>
22
23char* optarg = NULL;
24int optind = 1;
25
26int getopt(int argc, char* const argv[], const char* optstring)
27{
28 if ((optind >= argc) || (argv[optind][0] != '-') || (argv[optind][0] == 0))
29 {
30 return -1;
31 }
32
33 int opt = argv[optind][1];
34 const char* p = strchr(optstring, opt);
35
36 if (p == NULL)
37 {
38 return '?';
39 }
40 if (p[1] == ':')
41 {
42 optind++;
43 if (optind >= argc)
44 {
45 return '?';
46 }
47 optarg = argv[optind];
48 optind++;
49 }
50 return opt;
51}
diff --git a/src/getopt.h b/src/getopt.h
new file mode 100644
index 0000000..b9a1e72
--- /dev/null
+++ b/src/getopt.h
@@ -0,0 +1,85 @@
1/* *****************************************************************
2*
3* Copyright 2016 Microsoft
4*
5*
6* Licensed under the Apache License, Version 2.0 (the "License");
7* you may not use this file except in compliance with the License.
8* You may obtain a copy of the License at
9*
10* http://www.apache.org/licenses/LICENSE-2.0
11*
12* Unless required by applicable law or agreed to in writing, software
13* distributed under the License is distributed on an "AS IS" BASIS,
14* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15* See the License for the specific language governing permissions and
16* limitations under the License.
17*
18******************************************************************/
19
20#include <string.h>
21
22#ifndef GETOPT_H__
23#define GETOPT_H__
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29 int getopt(int argc, char* const argv[], const char* optstring);
30
31
32 /* *****************************************************************
33*
34* Copyright 2016 Microsoft
35*
36*
37* Licensed under the Apache License, Version 2.0 (the "License");
38* you may not use this file except in compliance with the License.
39* You may obtain a copy of the License at
40*
41* http://www.apache.org/licenses/LICENSE-2.0
42*
43* Unless required by applicable law or agreed to in writing, software
44* distributed under the License is distributed on an "AS IS" BASIS,
45* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46* See the License for the specific language governing permissions and
47* limitations under the License.
48*
49******************************************************************/
50
51 char* optarg = NULL;
52 int optind = 1;
53
54 int getopt(int argc, char* const argv[], const char* optstring)
55 {
56 if ((optind >= argc) || (argv[optind][0] != '-') || (argv[optind][0] == 0))
57 {
58 return -1;
59 }
60
61 int opt = argv[optind][1];
62 const char* p = strchr(optstring, opt);
63
64 if (p == NULL)
65 {
66 return '?';
67 }
68 if (p[1] == ':')
69 {
70 optind++;
71 if (optind >= argc)
72 {
73 return '?';
74 }
75 optarg = argv[optind];
76 optind++;
77 }
78 return opt;
79 }
80
81#ifdef __cplusplus
82}
83#endif
84
85#endif