Created filereader

This commit is contained in:
=
2026-04-27 08:50:15 +00:00
parent 6053cbf1dc
commit acd272ee08
12 changed files with 111 additions and 11 deletions
+3 -10
View File
@@ -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",
"linker-flags": [ "use-stdlib": false,
"-L/home/coder/bin/avr-toolchain/lib", "output": "build/blinky.o"
"-Tdata=0x800100",
"-mmcu=atmega328p"
],
"c-include-dirs": [
"/home/coder/bin/avr-toolchain/include"
]
} }
}, },
// Global settings. // Global settings.
+2
View File
@@ -0,0 +1,2 @@
build/
out/
View File
View File
View File
View File
+45
View File
@@ -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.
}
View File
View File
View File
+60
View File
@@ -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;
}
View File