input output

This commit is contained in:
Andrew Kelley 2015-08-05 15:46:40 -07:00
parent 50f0ed918c
commit 1d554f3161
5 changed files with 58 additions and 2 deletions

View File

@ -6,7 +6,7 @@ set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
project(zig C)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
set(ZIG_VERSION_MAJOR 1)
set(ZIG_VERSION_MAJOR 0)
set(ZIG_VERSION_MINOR 0)
set(ZIG_VERSION_PATCH 0)
set(ZIG_VERSION "${ZIG_VERSION_MAJOR}.${ZIG_VERSION_MINOR}.${ZIG_VERSION_PATCH}")
@ -15,6 +15,11 @@ message("Configuring zig version ${ZIG_VERSION}")
find_package(llvm)
include_directories(${LLVM_INCLUDE_DIR})
include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
)
set(ZIG_SOURCES
"${CMAKE_SOURCE_DIR}/src/main.c"
)

View File

@ -1,5 +1,46 @@
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static int usage(char *arg0) {
fprintf(stderr, "Usage: %s --output outfile code.zig\n"
"Other options:\n"
"--version print version number and exit\n"
, arg0);
return EXIT_FAILURE;
}
int main(int argc, char **argv) {
return 0;
char *arg0 = argv[0];
char *in_file = NULL;
char *out_file = NULL;
for (int i = 1; i < argc; i += 1) {
char *arg = argv[i];
if (arg[0] == '-' && arg[1] == '-') {
if (strcmp(arg, "--version") == 0) {
printf("%s\n", ZIG_VERSION_STRING);
return EXIT_SUCCESS;
} else if (i + 1 >= argc) {
return usage(arg0);
} else {
i += 1;
if (strcmp(arg, "--output") == 0) {
out_file = argv[i];
} else {
return usage(arg0);
}
}
} else if (!in_file) {
in_file = arg;
} else {
return usage(arg0);
}
}
if (!in_file || !out_file)
return usage(arg0);
fprintf(stderr, "in: %s out: %s\n", in_file, out_file);
return EXIT_SUCCESS;
}

1
test/add.h Normal file
View File

@ -0,0 +1 @@
int add(int a, int b);

3
test/add.zig Normal file
View File

@ -0,0 +1,3 @@
int add(int a, int b) {
return a + b;
}

6
test/hello.zig Normal file
View File

@ -0,0 +1,6 @@
#include <stdio.h>
#include "add.h"
int main(int argc, char **argv) {
fprintf(stderr, "hello: %d", add(1, 2));
}