Created filereader
This commit is contained in:
+4
-11
@@ -36,17 +36,10 @@
|
|||||||
// and overrides of global settings here.
|
// and overrides of global settings here.
|
||||||
},
|
},
|
||||||
"atmega328p": {
|
"atmega328p": {
|
||||||
"type": "executable",
|
"type": "object-files",
|
||||||
"triple": "avr-atmel-none",
|
"cpu": "atmega328p",
|
||||||
"cpu": "atmega328p",
|
"use-stdlib": false,
|
||||||
"linker-flags": [
|
"output": "build/blinky.o"
|
||||||
"-L/home/coder/bin/avr-toolchain/lib",
|
|
||||||
"-Tdata=0x800100",
|
|
||||||
"-mmcu=atmega328p"
|
|
||||||
],
|
|
||||||
"c-include-dirs": [
|
|
||||||
"/home/coder/bin/avr-toolchain/include"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Global settings.
|
// Global settings.
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
build/
|
||||||
|
out/
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
// Language version of C3.
|
||||||
|
"langrev": "1",
|
||||||
|
// Warnings used for all targets.
|
||||||
|
"warnings": [ "no-unused" ],
|
||||||
|
// Directories where C3 library files may be found.
|
||||||
|
"dependency-search-paths": [ "lib" ],
|
||||||
|
// Libraries to use for all targets.
|
||||||
|
"dependencies": [ ],
|
||||||
|
// Authors, optionally with email.
|
||||||
|
"authors": [ "Khwezi Mngoma <khwezi@mngoma.africa>" ],
|
||||||
|
// Version using semantic versioning.
|
||||||
|
"version": "0.1.0",
|
||||||
|
// Sources compiled for all targets.
|
||||||
|
"sources": [ "src/**" ],
|
||||||
|
// Test sources compiled for all targets.
|
||||||
|
"test-sources": [ "test/**" ],
|
||||||
|
// C sources if the project also compiles C sources
|
||||||
|
// relative to the project file.
|
||||||
|
// "c-sources": [ "csource/**" ],
|
||||||
|
// Include directories for C sources relative to the project file.
|
||||||
|
// "c-include-dirs": [ "csource/include" ],
|
||||||
|
// Build location, relative to project file.
|
||||||
|
"build-dir": "build",
|
||||||
|
// Output location, relative to project file.
|
||||||
|
"output": "build",
|
||||||
|
// Architecture and OS target.
|
||||||
|
// You can use 'c3c --list-targets' to list all valid targets.
|
||||||
|
// "target": "windows-x64",
|
||||||
|
// Targets.
|
||||||
|
"targets": {
|
||||||
|
"textfilereader": {
|
||||||
|
// Executable or library.
|
||||||
|
"type": "executable",
|
||||||
|
// Additional libraries, sources
|
||||||
|
// and overrides of global settings here.
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Global settings.
|
||||||
|
// CPU name, used for optimizations in the LLVM backend.
|
||||||
|
"cpu": "generic",
|
||||||
|
// Optimization: "O0", "O1", "O2", "O3", "O4", "O5", "Os", "Oz".
|
||||||
|
"opt": "O0"
|
||||||
|
// See resources/examples/project_all_settings.json and 'c3c --list-project-properties' to see more properties.
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
module textfilereader;
|
||||||
|
|
||||||
|
import std::io;
|
||||||
|
|
||||||
|
fn String? read_file(String filename)
|
||||||
|
{
|
||||||
|
ulong? size = io::file::get_size(filename);
|
||||||
|
if (catch err = size) return err~;
|
||||||
|
|
||||||
|
char[] buffer = mem::new_array(char, size);
|
||||||
|
|
||||||
|
File? handle = io::file::open(filename, "r");
|
||||||
|
|
||||||
|
if (catch err = handle)
|
||||||
|
{
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
|
return err~;
|
||||||
|
}
|
||||||
|
|
||||||
|
defer (void)handle.close();
|
||||||
|
|
||||||
|
(void)handle.read(buffer);
|
||||||
|
|
||||||
|
return (String)buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn int main(String[] args)
|
||||||
|
{
|
||||||
|
if (args.len < 2)
|
||||||
|
{
|
||||||
|
io::printn("Please specify file");
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
String filename = args[1];
|
||||||
|
|
||||||
|
String? data = read_file(filename);
|
||||||
|
|
||||||
|
if (catch excuse = data)
|
||||||
|
{
|
||||||
|
if(excuse == io::FILE_NOT_FOUND)
|
||||||
|
{
|
||||||
|
io::printfn("File not found: %s", filename);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
io::printfn("Could not read file: %s", excuse);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
io::printfn("%s", data);
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user