authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-08-05 15:46:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-08-05 15:46:40-07:00
log1d554f3161e7bcf76a180c9280a53cd0f5927591
treef89aa7adadee316aab00a2018040cee3dc1c418b
parent50f0ed918c4f5c70685752188b6a3853fc7205b9

input output


5 files changed, 58 insertions(+), 2 deletions(-)

CMakeLists.txt+6-1
......@@ -6,7 +6,7 @@ set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
66project(zig C)
77set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
88
9set(ZIG_VERSION_MAJOR 1)
9set(ZIG_VERSION_MAJOR 0)
1010set(ZIG_VERSION_MINOR 0)
1111set(ZIG_VERSION_PATCH 0)
1212set(ZIG_VERSION "${ZIG_VERSION_MAJOR}.${ZIG_VERSION_MINOR}.${ZIG_VERSION_PATCH}")
......@@ -15,6 +15,11 @@ message("Configuring zig version ${ZIG_VERSION}")
1515find_package(llvm)
1616include_directories(${LLVM_INCLUDE_DIR})
1717
18include_directories(
19 ${CMAKE_SOURCE_DIR}
20 ${CMAKE_BINARY_DIR}
21)
22
1823set(ZIG_SOURCES
1924 "${CMAKE_SOURCE_DIR}/src/main.c"
2025)
src/main.c+42-1
......@@ -1,5 +1,46 @@
1#include "config.h"
12#include <stdio.h>
3#include <string.h>
4#include <stdlib.h>
5
6static int usage(char *arg0) {
7 fprintf(stderr, "Usage: %s --output outfile code.zig\n"
8 "Other options:\n"
9 "--version print version number and exit\n"
10 , arg0);
11 return EXIT_FAILURE;
12}
213
314int main(int argc, char **argv) {
4 return 0;
15 char *arg0 = argv[0];
16 char *in_file = NULL;
17 char *out_file = NULL;
18 for (int i = 1; i < argc; i += 1) {
19 char *arg = argv[i];
20 if (arg[0] == '-' && arg[1] == '-') {
21 if (strcmp(arg, "--version") == 0) {
22 printf("%s\n", ZIG_VERSION_STRING);
23 return EXIT_SUCCESS;
24 } else if (i + 1 >= argc) {
25 return usage(arg0);
26 } else {
27 i += 1;
28 if (strcmp(arg, "--output") == 0) {
29 out_file = argv[i];
30 } else {
31 return usage(arg0);
32 }
33 }
34 } else if (!in_file) {
35 in_file = arg;
36 } else {
37 return usage(arg0);
38 }
39 }
40
41 if (!in_file || !out_file)
42 return usage(arg0);
43
44 fprintf(stderr, "in: %s out: %s\n", in_file, out_file);
45 return EXIT_SUCCESS;
546}
test/add.h created+1
......@@ -0,0 +1 @@
1int add(int a, int b);
test/add.zig created+3
......@@ -0,0 +1,3 @@
1int add(int a, int b) {
2 return a + b;
3}
test/hello.zig created+6
......@@ -0,0 +1,6 @@
1#include <stdio.h>
2#include "add.h"
3
4int main(int argc, char **argv) {
5 fprintf(stderr, "hello: %d", add(1, 2));
6}