diff --git a/examples/2024-01-15-zig-build-explained/all.sh b/examples/2024-01-15-zig-build-explained/all.sh new file mode 100755 index 0000000..bdc979e --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/all.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +echo "Run Entry..." +DIR="$(dirname "$(realpath "$0")")" +for ex in `ls -d */`;do + echo "Run ${ex}..." + cd ${DIR}/${ex} + if [ -f part.sh ]; then + ./part.sh + fi +done \ No newline at end of file diff --git a/examples/2024-01-15-zig-build-explained/build.zig b/examples/2024-01-15-zig-build-explained/build.zig new file mode 100644 index 0000000..c10063c --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/build.zig @@ -0,0 +1,27 @@ +const std = @import("std"); +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "test", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + // b.installArtifact(exe); + const cmd = b.addSystemCommand(&.{ + "./all.sh", + // "-outfile=lines.c", + // "lines.l", + }); + + exe.step.dependOn(&cmd.step); + b.installArtifact(exe); + // const run_cmd = b.addRunArtifact(exe); + // run_cmd.step.dependOn(b.getInstallStep()); + // if (b.args) |args| { + // run_cmd.addArgs(args); + // } + // const run_step = b.step("run", "Run the app"); + // run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/main.zig b/examples/2024-01-15-zig-build-explained/main.zig new file mode 100644 index 0000000..c9038b3 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/main.zig @@ -0,0 +1,5 @@ +const std = @import("std"); + +pub fn main() !void { + std.debug.print("{s}\n", .{""}); +} diff --git a/examples/2024-01-15-zig-build-explained/part1/1.1/build.zig b/examples/2024-01-15-zig-build-explained/part1/1.1/build.zig new file mode 100644 index 0000000..6e97e3e --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.1/build.zig @@ -0,0 +1,28 @@ + const std = @import("std"); + pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "test", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); + const unit_tests = b.addTest(.{ + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + + const run_unit_tests = b.addRunArtifact(unit_tests); + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&run_unit_tests.step); + } \ No newline at end of file diff --git a/examples/2024-01-15-zig-build-explained/part1/1.1/src/main.zig b/examples/2024-01-15-zig-build-explained/part1/1.1/src/main.zig new file mode 100644 index 0000000..1269bcc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.1/src/main.zig @@ -0,0 +1,10 @@ +const std = @import("std"); + +pub fn main() !void { + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + try bw.flush(); // don't forget to flush! +} diff --git a/examples/2024-01-15-zig-build-explained/part1/1.2/build.zig b/examples/2024-01-15-zig-build-explained/part1/1.2/build.zig new file mode 100644 index 0000000..24ff89d --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.2/build.zig @@ -0,0 +1,5 @@ +const std = @import("std"); +pub fn build(b: *std.build.Builder) void { + const named_step = b.step("step-name", "This is what is shown in help"); + _ = named_step; +} diff --git a/examples/2024-01-15-zig-build-explained/part1/1.3/build.zig b/examples/2024-01-15-zig-build-explained/part1/1.3/build.zig new file mode 100644 index 0000000..a581773 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.3/build.zig @@ -0,0 +1,14 @@ +const std = @import("std"); +pub fn build(b: *std.build.Builder) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "test", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + + const compile_step = b.step("compile", "Compiles src/main.zig"); + compile_step.dependOn(&exe.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part1/1.3/src/main.zig b/examples/2024-01-15-zig-build-explained/part1/1.3/src/main.zig new file mode 100644 index 0000000..1269bcc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.3/src/main.zig @@ -0,0 +1,10 @@ +const std = @import("std"); + +pub fn main() !void { + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + try bw.flush(); // don't forget to flush! +} diff --git a/examples/2024-01-15-zig-build-explained/part1/1.4/build.zig b/examples/2024-01-15-zig-build-explained/part1/1.4/build.zig new file mode 100644 index 0000000..53064dc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.4/build.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +pub fn build(b: *std.build.Builder) void { + const exe = b.addExecutable(.{ + .name = "fresh", + .root_source_file = .{ .path = "src/main.zig" }, + .optimize = .ReleaseSafe, + }); + const compile_step = b.step("compile", "Compiles src/main.zig"); + compile_step.dependOn(&exe.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part1/1.4/src/main.zig b/examples/2024-01-15-zig-build-explained/part1/1.4/src/main.zig new file mode 100644 index 0000000..1269bcc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.4/src/main.zig @@ -0,0 +1,10 @@ +const std = @import("std"); + +pub fn main() !void { + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + try bw.flush(); // don't forget to flush! +} diff --git a/examples/2024-01-15-zig-build-explained/part1/1.6/build.zig b/examples/2024-01-15-zig-build-explained/part1/1.6/build.zig new file mode 100644 index 0000000..f8203a1 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.6/build.zig @@ -0,0 +1,13 @@ +const std = @import("std"); + +pub fn build(b: *std.build.Builder) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "fresh", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + b.installArtifact(exe); +} diff --git a/examples/2024-01-15-zig-build-explained/part1/1.6/src/main.zig b/examples/2024-01-15-zig-build-explained/part1/1.6/src/main.zig new file mode 100644 index 0000000..1269bcc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.6/src/main.zig @@ -0,0 +1,10 @@ +const std = @import("std"); + +pub fn main() !void { + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + try bw.flush(); // don't forget to flush! +} diff --git a/examples/2024-01-15-zig-build-explained/part1/1.7/build.zig b/examples/2024-01-15-zig-build-explained/part1/1.7/build.zig new file mode 100644 index 0000000..3321812 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.7/build.zig @@ -0,0 +1,15 @@ +const std = @import("std"); +pub fn build(b: *std.build.Builder) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "fresh", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part1/1.7/src/main.zig b/examples/2024-01-15-zig-build-explained/part1/1.7/src/main.zig new file mode 100644 index 0000000..1269bcc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.7/src/main.zig @@ -0,0 +1,10 @@ +const std = @import("std"); + +pub fn main() !void { + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + try bw.flush(); // don't forget to flush! +} diff --git a/examples/2024-01-15-zig-build-explained/part1/1.8/build.zig b/examples/2024-01-15-zig-build-explained/part1/1.8/build.zig new file mode 100644 index 0000000..e8343e8 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.8/build.zig @@ -0,0 +1,18 @@ +const std = @import("std"); +pub fn build(b: *std.build.Builder) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "fresh", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part1/1.8/src/main.zig b/examples/2024-01-15-zig-build-explained/part1/1.8/src/main.zig new file mode 100644 index 0000000..29f9f38 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/1.8/src/main.zig @@ -0,0 +1,15 @@ +const std = @import("std"); + +pub fn main() !void { + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + std.debug.print("args from builds:", .{}); + for (std.os.argv) |arg| { + std.debug.print("{s},", .{arg}); + } + std.debug.print("\n", .{}); + try bw.flush(); // don't forget to flush! +} diff --git a/examples/2024-01-15-zig-build-explained/part1/part.sh b/examples/2024-01-15-zig-build-explained/part1/part.sh new file mode 100755 index 0000000..c7df642 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part1/part.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +echo "Run Part..." +DIR="$(dirname "$(realpath "$0")")" +for ex in `ls -d */`;do + echo "Run example ${ex}..." + cd ${DIR}/${ex} + zig build --summary none +done diff --git a/examples/2024-01-15-zig-build-explained/part2/2.1/buffer.c b/examples/2024-01-15-zig-build-explained/part2/2.1/buffer.c new file mode 100644 index 0000000..5dce924 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.1/buffer.c @@ -0,0 +1,28 @@ +#include +#include + +void * buffer_create(size_t len) +{ + return malloc(len); +} + +void buffer_destroy(void * ptr) +{ + free(ptr); +} + +void buffer_write(void * buf, size_t offset, void * data, size_t len) +{ + memcpy( + (char*)buf + offset, + data, + len); +} + +void buffer_read(void * buf, size_t offset, void * data, size_t len) +{ + memcpy( + data, + (char*)buf + offset, + len); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.1/build.zig b/examples/2024-01-15-zig-build-explained/part2/2.1/build.zig new file mode 100644 index 0000000..b10dbbc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.1/build.zig @@ -0,0 +1,24 @@ +const std = @import("std"); +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "example", + // 这块调试了很久。最后的结论是根本不要写 + // .root_source_file = .{ .path = undefined }, + .target = target, + .optimize = optimize, + }); + // 这块调试了很久。API变了不会写,着了很久的文档和看了很久的代码 + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("main.c"), .flags = &.{} }); + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("buffer.c"), .flags = &.{} }); + //exe.linkLibC(); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); // + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.1/main.c b/examples/2024-01-15-zig-build-explained/part2/2.1/main.c new file mode 100644 index 0000000..59828bc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.1/main.c @@ -0,0 +1,22 @@ +#include + +void * buffer_create(size_t len); +void buffer_destroy(void * ptr); +void buffer_write(void * buf, size_t offset, void * data, size_t len); +void buffer_read(void * buf, size_t offset, void * data, size_t len); + +int main() +{ + void * buf = buffer_create(8); + buffer_write(buf, 0, "World", 6); + + { + char str[8]; + buffer_read(buf, 0, str, 6); + printf("Hello, %s!\n", str); + } + + buffer_destroy(buf); + + return 0; +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.10/build.zig b/examples/2024-01-15-zig-build-explained/part2/2.10/build.zig new file mode 100644 index 0000000..858fdd6 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.10/build.zig @@ -0,0 +1,24 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "example", + .target = target, + .optimize = optimize, + }); + exe.addCSourceFile(.{ + .file = std.build.LazyPath.relative("main.m"), + .flags = &.{}, + }); + exe.linkFramework("Foundation"); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.10/main.m b/examples/2024-01-15-zig-build-explained/part2/2.10/main.m new file mode 100644 index 0000000..bbe17af --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.10/main.m @@ -0,0 +1,15 @@ +#import "Foundation/Foundation.h" + +@interface SampleClass : NSObject +- (void)sampleMethod; +@end +@implementation SampleClass +- (void)sampleMethod { + NSLog(@"Hello World in Objective-C!\n"); +} +@end +int main() { + SampleClass *sampleClass = [[SampleClass alloc]init]; + [sampleClass sampleMethod]; + return 0; +} \ No newline at end of file diff --git a/examples/2024-01-15-zig-build-explained/part2/2.11/buffer.c b/examples/2024-01-15-zig-build-explained/part2/2.11/buffer.c new file mode 100644 index 0000000..5dce924 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.11/buffer.c @@ -0,0 +1,28 @@ +#include +#include + +void * buffer_create(size_t len) +{ + return malloc(len); +} + +void buffer_destroy(void * ptr) +{ + free(ptr); +} + +void buffer_write(void * buf, size_t offset, void * data, size_t len) +{ + memcpy( + (char*)buf + offset, + data, + len); +} + +void buffer_read(void * buf, size_t offset, void * data, size_t len) +{ + memcpy( + data, + (char*)buf + offset, + len); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.11/build.zig b/examples/2024-01-15-zig-build-explained/part2/2.11/build.zig new file mode 100644 index 0000000..d0fab38 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.11/build.zig @@ -0,0 +1,25 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "example", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + exe.addCSourceFile(.{ + .file = std.build.LazyPath.relative("buffer.c"), + .flags = &.{}, + }); + exe.linkLibC(); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.11/main.zig b/examples/2024-01-15-zig-build-explained/part2/2.11/main.zig new file mode 100644 index 0000000..d51d3ac --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.11/main.zig @@ -0,0 +1,19 @@ +const std = @import("std"); + +pub extern fn buffer_create(len: usize) ?*anyopaque; +pub extern fn buffer_destroy(ptr: ?*anyopaque) void; +pub extern fn buffer_write(buf: ?*anyopaque, offset: usize, data: ?*const anyopaque, len: usize) void; +pub extern fn buffer_read(buf: ?*anyopaque, offset: usize, data: ?*anyopaque, len: usize) void; + +pub fn main() void { + const buf = buffer_create(8); + defer buffer_destroy(buf); + + buffer_write(buf, 0, "World", 6); + + { + var str: [8]u8 = undefined; + buffer_read(buf, 0, &str, 6); + std.log.info("Hello, {s}!", .{str[0..6]}); + } +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.2/build.zig b/examples/2024-01-15-zig-build-explained/part2/2.2/build.zig new file mode 100644 index 0000000..b3cca51 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.2/build.zig @@ -0,0 +1,17 @@ +const std = @import("std"); +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "downloader", + .target = target, + .optimize = optimize, + }); + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("download.c"), .flags = &.{} }); + exe.linkSystemLibrary("curl"); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.2/download.c b/examples/2024-01-15-zig-build-explained/part2/2.2/download.c new file mode 100644 index 0000000..af994d2 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.2/download.c @@ -0,0 +1,30 @@ +#include +#include + +static size_t writeData(void *ptr, size_t size, size_t nmemb, FILE *stream) { + size_t written; + written = fwrite(ptr, size, nmemb, stream); + return written; +} + +int main(int argc, char ** argv) +{ + if(argc != 2) + return 1; + + char const * url = argv[1]; + CURL * curl = curl_easy_init(); + if (curl == NULL) + return 1; + + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout); + CURLcode res = curl_easy_perform(curl); + curl_easy_cleanup(curl); + + if(res != CURLE_OK) + return 1; + + return 0; +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.3/bass-player.c b/examples/2024-01-15-zig-build-explained/part2/2.3/bass-player.c new file mode 100644 index 0000000..5957fcb --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.3/bass-player.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +int main() +{ + if (BASS_Init(-1, 44100, 0, NULL, NULL) == 0) { + return 1; + } + + // Track by Incompetech: + // "Island Meet and Greet" Kevin MacLeod (incompetech.com) + // Licensed under Creative Commons: By Attribution 4.0 License + // http://creativecommons.org/licenses/by/4.0/ + int chan = BASS_StreamCreateURL("https://mq32.de/public/island-meet-and-greet.mp3", 0, BASS_STREAM_BLOCK | BASS_STREAM_AUTOFREE, NULL, NULL); + + BASS_ChannelPlay(chan, FALSE); + + printf("Press ENTER to stop!\n"); + getchar(); + + BASS_Free(); + + return 0; +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.3/bass/linux/bass.h b/examples/2024-01-15-zig-build-explained/part2/2.3/bass/linux/bass.h new file mode 100644 index 0000000..1e3a86f --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.3/bass/linux/bass.h @@ -0,0 +1,1149 @@ +/* + BASS 2.4 C/C++ header file + Copyright (c) 1999-2022 Un4seen Developments Ltd. + + See the BASS.CHM file for more detailed documentation +*/ + +#ifndef BASS_H +#define BASS_H + +#ifdef _WIN32 +#ifdef WINAPI_FAMILY +#include +#endif +#include +typedef unsigned __int64 QWORD; +#else +#include +#define WINAPI +#define CALLBACK +typedef uint8_t BYTE; +typedef uint16_t WORD; +typedef uint32_t DWORD; +typedef uint64_t QWORD; +#ifdef __OBJC__ +typedef int BOOL32; +#define BOOL BOOL32 // override objc's BOOL +#else +typedef int BOOL; +#endif +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif +#define LOBYTE(a) (BYTE)(a) +#define HIBYTE(a) (BYTE)((a)>>8) +#define LOWORD(a) (WORD)(a) +#define HIWORD(a) (WORD)((a)>>16) +#define MAKEWORD(a,b) (WORD)(((a)&0xff)|((b)<<8)) +#define MAKELONG(a,b) (DWORD)(((a)&0xffff)|((b)<<16)) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define BASSVERSION 0x204 // API version +#define BASSVERSIONTEXT "2.4" + +#ifndef BASSDEF +#define BASSDEF(f) WINAPI f +#else +#define NOBASSOVERLOADS +#endif + +typedef DWORD HMUSIC; // MOD music handle +typedef DWORD HSAMPLE; // sample handle +typedef DWORD HCHANNEL; // sample playback handle +typedef DWORD HSTREAM; // sample stream handle +typedef DWORD HRECORD; // recording handle +typedef DWORD HSYNC; // synchronizer handle +typedef DWORD HDSP; // DSP handle +typedef DWORD HFX; // effect handle +typedef DWORD HPLUGIN; // plugin handle + +// Error codes returned by BASS_ErrorGetCode +#define BASS_OK 0 // all is OK +#define BASS_ERROR_MEM 1 // memory error +#define BASS_ERROR_FILEOPEN 2 // can't open the file +#define BASS_ERROR_DRIVER 3 // can't find a free/valid driver +#define BASS_ERROR_BUFLOST 4 // the sample buffer was lost +#define BASS_ERROR_HANDLE 5 // invalid handle +#define BASS_ERROR_FORMAT 6 // unsupported sample format +#define BASS_ERROR_POSITION 7 // invalid position +#define BASS_ERROR_INIT 8 // BASS_Init has not been successfully called +#define BASS_ERROR_START 9 // BASS_Start has not been successfully called +#define BASS_ERROR_SSL 10 // SSL/HTTPS support isn't available +#define BASS_ERROR_REINIT 11 // device needs to be reinitialized +#define BASS_ERROR_ALREADY 14 // already initialized/paused/whatever +#define BASS_ERROR_NOTAUDIO 17 // file does not contain audio +#define BASS_ERROR_NOCHAN 18 // can't get a free channel +#define BASS_ERROR_ILLTYPE 19 // an illegal type was specified +#define BASS_ERROR_ILLPARAM 20 // an illegal parameter was specified +#define BASS_ERROR_NO3D 21 // no 3D support +#define BASS_ERROR_NOEAX 22 // no EAX support +#define BASS_ERROR_DEVICE 23 // illegal device number +#define BASS_ERROR_NOPLAY 24 // not playing +#define BASS_ERROR_FREQ 25 // illegal sample rate +#define BASS_ERROR_NOTFILE 27 // the stream is not a file stream +#define BASS_ERROR_NOHW 29 // no hardware voices available +#define BASS_ERROR_EMPTY 31 // the file has no sample data +#define BASS_ERROR_NONET 32 // no internet connection could be opened +#define BASS_ERROR_CREATE 33 // couldn't create the file +#define BASS_ERROR_NOFX 34 // effects are not available +#define BASS_ERROR_NOTAVAIL 37 // requested data/action is not available +#define BASS_ERROR_DECODE 38 // the channel is/isn't a "decoding channel" +#define BASS_ERROR_DX 39 // a sufficient DirectX version is not installed +#define BASS_ERROR_TIMEOUT 40 // connection timedout +#define BASS_ERROR_FILEFORM 41 // unsupported file format +#define BASS_ERROR_SPEAKER 42 // unavailable speaker +#define BASS_ERROR_VERSION 43 // invalid BASS version (used by add-ons) +#define BASS_ERROR_CODEC 44 // codec is not available/supported +#define BASS_ERROR_ENDED 45 // the channel/file has ended +#define BASS_ERROR_BUSY 46 // the device is busy +#define BASS_ERROR_UNSTREAMABLE 47 // unstreamable file +#define BASS_ERROR_PROTOCOL 48 // unsupported protocol +#define BASS_ERROR_DENIED 49 // access denied +#define BASS_ERROR_UNKNOWN -1 // some other mystery problem + +// BASS_SetConfig options +#define BASS_CONFIG_BUFFER 0 +#define BASS_CONFIG_UPDATEPERIOD 1 +#define BASS_CONFIG_GVOL_SAMPLE 4 +#define BASS_CONFIG_GVOL_STREAM 5 +#define BASS_CONFIG_GVOL_MUSIC 6 +#define BASS_CONFIG_CURVE_VOL 7 +#define BASS_CONFIG_CURVE_PAN 8 +#define BASS_CONFIG_FLOATDSP 9 +#define BASS_CONFIG_3DALGORITHM 10 +#define BASS_CONFIG_NET_TIMEOUT 11 +#define BASS_CONFIG_NET_BUFFER 12 +#define BASS_CONFIG_PAUSE_NOPLAY 13 +#define BASS_CONFIG_NET_PREBUF 15 +#define BASS_CONFIG_NET_PASSIVE 18 +#define BASS_CONFIG_REC_BUFFER 19 +#define BASS_CONFIG_NET_PLAYLIST 21 +#define BASS_CONFIG_MUSIC_VIRTUAL 22 +#define BASS_CONFIG_VERIFY 23 +#define BASS_CONFIG_UPDATETHREADS 24 +#define BASS_CONFIG_DEV_BUFFER 27 +#define BASS_CONFIG_REC_LOOPBACK 28 +#define BASS_CONFIG_VISTA_TRUEPOS 30 +#define BASS_CONFIG_IOS_SESSION 34 +#define BASS_CONFIG_IOS_MIXAUDIO 34 +#define BASS_CONFIG_DEV_DEFAULT 36 +#define BASS_CONFIG_NET_READTIMEOUT 37 +#define BASS_CONFIG_VISTA_SPEAKERS 38 +#define BASS_CONFIG_IOS_SPEAKER 39 +#define BASS_CONFIG_MF_DISABLE 40 +#define BASS_CONFIG_HANDLES 41 +#define BASS_CONFIG_UNICODE 42 +#define BASS_CONFIG_SRC 43 +#define BASS_CONFIG_SRC_SAMPLE 44 +#define BASS_CONFIG_ASYNCFILE_BUFFER 45 +#define BASS_CONFIG_OGG_PRESCAN 47 +#define BASS_CONFIG_MF_VIDEO 48 +#define BASS_CONFIG_AIRPLAY 49 +#define BASS_CONFIG_DEV_NONSTOP 50 +#define BASS_CONFIG_IOS_NOCATEGORY 51 +#define BASS_CONFIG_VERIFY_NET 52 +#define BASS_CONFIG_DEV_PERIOD 53 +#define BASS_CONFIG_FLOAT 54 +#define BASS_CONFIG_NET_SEEK 56 +#define BASS_CONFIG_AM_DISABLE 58 +#define BASS_CONFIG_NET_PLAYLIST_DEPTH 59 +#define BASS_CONFIG_NET_PREBUF_WAIT 60 +#define BASS_CONFIG_ANDROID_SESSIONID 62 +#define BASS_CONFIG_WASAPI_PERSIST 65 +#define BASS_CONFIG_REC_WASAPI 66 +#define BASS_CONFIG_ANDROID_AAUDIO 67 +#define BASS_CONFIG_SAMPLE_ONEHANDLE 69 +#define BASS_CONFIG_NET_META 71 +#define BASS_CONFIG_NET_RESTRATE 72 +#define BASS_CONFIG_REC_DEFAULT 73 +#define BASS_CONFIG_NORAMP 74 + +// BASS_SetConfigPtr options +#define BASS_CONFIG_NET_AGENT 16 +#define BASS_CONFIG_NET_PROXY 17 +#define BASS_CONFIG_IOS_NOTIFY 46 +#define BASS_CONFIG_ANDROID_JAVAVM 63 +#define BASS_CONFIG_LIBSSL 64 +#define BASS_CONFIG_FILENAME 75 + +#define BASS_CONFIG_THREAD 0x40000000 // flag: thread-specific setting + +// BASS_CONFIG_IOS_SESSION flags +#define BASS_IOS_SESSION_MIX 1 +#define BASS_IOS_SESSION_DUCK 2 +#define BASS_IOS_SESSION_AMBIENT 4 +#define BASS_IOS_SESSION_SPEAKER 8 +#define BASS_IOS_SESSION_DISABLE 16 +#define BASS_IOS_SESSION_DEACTIVATE 32 +#define BASS_IOS_SESSION_AIRPLAY 64 +#define BASS_IOS_SESSION_BTHFP 128 +#define BASS_IOS_SESSION_BTA2DP 0x100 + +// BASS_Init flags +#define BASS_DEVICE_8BITS 1 // unused +#define BASS_DEVICE_MONO 2 // mono +#define BASS_DEVICE_3D 4 // unused +#define BASS_DEVICE_16BITS 8 // limit output to 16-bit +#define BASS_DEVICE_REINIT 128 // reinitialize +#define BASS_DEVICE_LATENCY 0x100 // unused +#define BASS_DEVICE_CPSPEAKERS 0x400 // unused +#define BASS_DEVICE_SPEAKERS 0x800 // force enabling of speaker assignment +#define BASS_DEVICE_NOSPEAKER 0x1000 // ignore speaker arrangement +#define BASS_DEVICE_DMIX 0x2000 // use ALSA "dmix" plugin +#define BASS_DEVICE_FREQ 0x4000 // set device sample rate +#define BASS_DEVICE_STEREO 0x8000 // limit output to stereo +#define BASS_DEVICE_HOG 0x10000 // hog/exclusive mode +#define BASS_DEVICE_AUDIOTRACK 0x20000 // use AudioTrack output +#define BASS_DEVICE_DSOUND 0x40000 // use DirectSound output +#define BASS_DEVICE_SOFTWARE 0x80000 // disable hardware/fastpath output + +// DirectSound interfaces (for use with BASS_GetDSoundObject) +#define BASS_OBJECT_DS 1 // IDirectSound +#define BASS_OBJECT_DS3DL 2 // IDirectSound3DListener + +// Device info structure +typedef struct { +#if defined(_WIN32_WCE) || (defined(WINAPI_FAMILY) && WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP) + const wchar_t *name; // description + const wchar_t *driver; // driver +#else + const char *name; // description + const char *driver; // driver +#endif + DWORD flags; +} BASS_DEVICEINFO; + +// BASS_DEVICEINFO flags +#define BASS_DEVICE_ENABLED 1 +#define BASS_DEVICE_DEFAULT 2 +#define BASS_DEVICE_INIT 4 +#define BASS_DEVICE_LOOPBACK 8 +#define BASS_DEVICE_DEFAULTCOM 128 + +#define BASS_DEVICE_TYPE_MASK 0xff000000 +#define BASS_DEVICE_TYPE_NETWORK 0x01000000 +#define BASS_DEVICE_TYPE_SPEAKERS 0x02000000 +#define BASS_DEVICE_TYPE_LINE 0x03000000 +#define BASS_DEVICE_TYPE_HEADPHONES 0x04000000 +#define BASS_DEVICE_TYPE_MICROPHONE 0x05000000 +#define BASS_DEVICE_TYPE_HEADSET 0x06000000 +#define BASS_DEVICE_TYPE_HANDSET 0x07000000 +#define BASS_DEVICE_TYPE_DIGITAL 0x08000000 +#define BASS_DEVICE_TYPE_SPDIF 0x09000000 +#define BASS_DEVICE_TYPE_HDMI 0x0a000000 +#define BASS_DEVICE_TYPE_DISPLAYPORT 0x40000000 + +// BASS_GetDeviceInfo flags +#define BASS_DEVICES_AIRPLAY 0x1000000 + +typedef struct { + DWORD flags; // device capabilities (DSCAPS_xxx flags) + DWORD hwsize; // unused + DWORD hwfree; // unused + DWORD freesam; // unused + DWORD free3d; // unused + DWORD minrate; // unused + DWORD maxrate; // unused + BOOL eax; // unused + DWORD minbuf; // recommended minimum buffer length in ms + DWORD dsver; // DirectSound version + DWORD latency; // average delay (in ms) before start of playback + DWORD initflags; // BASS_Init "flags" parameter + DWORD speakers; // number of speakers available + DWORD freq; // current output rate +} BASS_INFO; + +// BASS_INFO flags (from DSOUND.H) +#define DSCAPS_EMULDRIVER 0x00000020 // device does not have hardware DirectSound support +#define DSCAPS_CERTIFIED 0x00000040 // device driver has been certified by Microsoft + +#define DSCAPS_HARDWARE 0x80000000 // hardware mixed + +// Recording device info structure +typedef struct { + DWORD flags; // device capabilities (DSCCAPS_xxx flags) + DWORD formats; // supported standard formats (WAVE_FORMAT_xxx flags) + DWORD inputs; // number of inputs + BOOL singlein; // TRUE = only 1 input can be set at a time + DWORD freq; // current input rate +} BASS_RECORDINFO; + +// BASS_RECORDINFO flags (from DSOUND.H) +#define DSCCAPS_EMULDRIVER DSCAPS_EMULDRIVER // device does not have hardware DirectSound recording support +#define DSCCAPS_CERTIFIED DSCAPS_CERTIFIED // device driver has been certified by Microsoft + +// defines for formats field of BASS_RECORDINFO (from MMSYSTEM.H) +#ifndef WAVE_FORMAT_1M08 +#define WAVE_FORMAT_1M08 0x00000001 /* 11.025 kHz, Mono, 8-bit */ +#define WAVE_FORMAT_1S08 0x00000002 /* 11.025 kHz, Stereo, 8-bit */ +#define WAVE_FORMAT_1M16 0x00000004 /* 11.025 kHz, Mono, 16-bit */ +#define WAVE_FORMAT_1S16 0x00000008 /* 11.025 kHz, Stereo, 16-bit */ +#define WAVE_FORMAT_2M08 0x00000010 /* 22.05 kHz, Mono, 8-bit */ +#define WAVE_FORMAT_2S08 0x00000020 /* 22.05 kHz, Stereo, 8-bit */ +#define WAVE_FORMAT_2M16 0x00000040 /* 22.05 kHz, Mono, 16-bit */ +#define WAVE_FORMAT_2S16 0x00000080 /* 22.05 kHz, Stereo, 16-bit */ +#define WAVE_FORMAT_4M08 0x00000100 /* 44.1 kHz, Mono, 8-bit */ +#define WAVE_FORMAT_4S08 0x00000200 /* 44.1 kHz, Stereo, 8-bit */ +#define WAVE_FORMAT_4M16 0x00000400 /* 44.1 kHz, Mono, 16-bit */ +#define WAVE_FORMAT_4S16 0x00000800 /* 44.1 kHz, Stereo, 16-bit */ +#endif + +// Sample info structure +typedef struct { + DWORD freq; // default playback rate + float volume; // default volume (0-1) + float pan; // default pan (-1=left, 0=middle, 1=right) + DWORD flags; // BASS_SAMPLE_xxx flags + DWORD length; // length (in bytes) + DWORD max; // maximum simultaneous playbacks + DWORD origres; // original resolution + DWORD chans; // number of channels + DWORD mingap; // minimum gap (ms) between creating channels + DWORD mode3d; // BASS_3DMODE_xxx mode + float mindist; // minimum distance + float maxdist; // maximum distance + DWORD iangle; // angle of inside projection cone + DWORD oangle; // angle of outside projection cone + float outvol; // delta-volume outside the projection cone + DWORD vam; // unused + DWORD priority; // unused +} BASS_SAMPLE; + +#define BASS_SAMPLE_8BITS 1 // 8 bit +#define BASS_SAMPLE_FLOAT 256 // 32 bit floating-point +#define BASS_SAMPLE_MONO 2 // mono +#define BASS_SAMPLE_LOOP 4 // looped +#define BASS_SAMPLE_3D 8 // 3D functionality +#define BASS_SAMPLE_SOFTWARE 16 // unused +#define BASS_SAMPLE_MUTEMAX 32 // mute at max distance (3D only) +#define BASS_SAMPLE_VAM 64 // unused +#define BASS_SAMPLE_FX 128 // unused +#define BASS_SAMPLE_OVER_VOL 0x10000 // override lowest volume +#define BASS_SAMPLE_OVER_POS 0x20000 // override longest playing +#define BASS_SAMPLE_OVER_DIST 0x30000 // override furthest from listener (3D only) + +#define BASS_STREAM_PRESCAN 0x20000 // scan file for accurate seeking and length +#define BASS_STREAM_AUTOFREE 0x40000 // automatically free the stream when it stops/ends +#define BASS_STREAM_RESTRATE 0x80000 // restrict the download rate of internet file stream +#define BASS_STREAM_BLOCK 0x100000 // download internet file stream in small blocks +#define BASS_STREAM_DECODE 0x200000 // don't play the stream, only decode +#define BASS_STREAM_STATUS 0x800000 // give server status info (HTTP/ICY tags) in DOWNLOADPROC + +#define BASS_MP3_IGNOREDELAY 0x200 // ignore LAME/Xing/VBRI/iTunes delay & padding info +#define BASS_MP3_SETPOS BASS_STREAM_PRESCAN + +#define BASS_MUSIC_FLOAT BASS_SAMPLE_FLOAT +#define BASS_MUSIC_MONO BASS_SAMPLE_MONO +#define BASS_MUSIC_LOOP BASS_SAMPLE_LOOP +#define BASS_MUSIC_3D BASS_SAMPLE_3D +#define BASS_MUSIC_FX BASS_SAMPLE_FX +#define BASS_MUSIC_AUTOFREE BASS_STREAM_AUTOFREE +#define BASS_MUSIC_DECODE BASS_STREAM_DECODE +#define BASS_MUSIC_PRESCAN BASS_STREAM_PRESCAN // calculate playback length +#define BASS_MUSIC_CALCLEN BASS_MUSIC_PRESCAN +#define BASS_MUSIC_RAMP 0x200 // normal ramping +#define BASS_MUSIC_RAMPS 0x400 // sensitive ramping +#define BASS_MUSIC_SURROUND 0x800 // surround sound +#define BASS_MUSIC_SURROUND2 0x1000 // surround sound (mode 2) +#define BASS_MUSIC_FT2PAN 0x2000 // apply FastTracker 2 panning to XM files +#define BASS_MUSIC_FT2MOD 0x2000 // play .MOD as FastTracker 2 does +#define BASS_MUSIC_PT1MOD 0x4000 // play .MOD as ProTracker 1 does +#define BASS_MUSIC_NONINTER 0x10000 // non-interpolated sample mixing +#define BASS_MUSIC_SINCINTER 0x800000 // sinc interpolated sample mixing +#define BASS_MUSIC_POSRESET 0x8000 // stop all notes when moving position +#define BASS_MUSIC_POSRESETEX 0x400000 // stop all notes and reset bmp/etc when moving position +#define BASS_MUSIC_STOPBACK 0x80000 // stop the music on a backwards jump effect +#define BASS_MUSIC_NOSAMPLE 0x100000 // don't load the samples + +// Speaker assignment flags +#define BASS_SPEAKER_FRONT 0x1000000 // front speakers +#define BASS_SPEAKER_REAR 0x2000000 // rear speakers +#define BASS_SPEAKER_CENLFE 0x3000000 // center & LFE speakers (5.1) +#define BASS_SPEAKER_SIDE 0x4000000 // side speakers (7.1) +#define BASS_SPEAKER_N(n) ((n)<<24) // n'th pair of speakers (max 15) +#define BASS_SPEAKER_LEFT 0x10000000 // modifier: left +#define BASS_SPEAKER_RIGHT 0x20000000 // modifier: right +#define BASS_SPEAKER_FRONTLEFT BASS_SPEAKER_FRONT | BASS_SPEAKER_LEFT +#define BASS_SPEAKER_FRONTRIGHT BASS_SPEAKER_FRONT | BASS_SPEAKER_RIGHT +#define BASS_SPEAKER_REARLEFT BASS_SPEAKER_REAR | BASS_SPEAKER_LEFT +#define BASS_SPEAKER_REARRIGHT BASS_SPEAKER_REAR | BASS_SPEAKER_RIGHT +#define BASS_SPEAKER_CENTER BASS_SPEAKER_CENLFE | BASS_SPEAKER_LEFT +#define BASS_SPEAKER_LFE BASS_SPEAKER_CENLFE | BASS_SPEAKER_RIGHT +#define BASS_SPEAKER_SIDELEFT BASS_SPEAKER_SIDE | BASS_SPEAKER_LEFT +#define BASS_SPEAKER_SIDERIGHT BASS_SPEAKER_SIDE | BASS_SPEAKER_RIGHT +#define BASS_SPEAKER_REAR2 BASS_SPEAKER_SIDE +#define BASS_SPEAKER_REAR2LEFT BASS_SPEAKER_SIDELEFT +#define BASS_SPEAKER_REAR2RIGHT BASS_SPEAKER_SIDERIGHT + +#define BASS_ASYNCFILE 0x40000000 // read file asynchronously +#define BASS_UNICODE 0x80000000 // UTF-16 + +#define BASS_RECORD_ECHOCANCEL 0x2000 +#define BASS_RECORD_AGC 0x4000 +#define BASS_RECORD_PAUSE 0x8000 // start recording paused + +// DX7 voice allocation & management flags +#define BASS_VAM_HARDWARE 1 +#define BASS_VAM_SOFTWARE 2 +#define BASS_VAM_TERM_TIME 4 +#define BASS_VAM_TERM_DIST 8 +#define BASS_VAM_TERM_PRIO 16 + +// Channel info structure +typedef struct { + DWORD freq; // default playback rate + DWORD chans; // channels + DWORD flags; + DWORD ctype; // type of channel + DWORD origres; // original resolution + HPLUGIN plugin; + HSAMPLE sample; + const char *filename; +} BASS_CHANNELINFO; + +#define BASS_ORIGRES_FLOAT 0x10000 + +// BASS_CHANNELINFO types +#define BASS_CTYPE_SAMPLE 1 +#define BASS_CTYPE_RECORD 2 +#define BASS_CTYPE_STREAM 0x10000 +#define BASS_CTYPE_STREAM_VORBIS 0x10002 +#define BASS_CTYPE_STREAM_OGG 0x10002 +#define BASS_CTYPE_STREAM_MP1 0x10003 +#define BASS_CTYPE_STREAM_MP2 0x10004 +#define BASS_CTYPE_STREAM_MP3 0x10005 +#define BASS_CTYPE_STREAM_AIFF 0x10006 +#define BASS_CTYPE_STREAM_CA 0x10007 +#define BASS_CTYPE_STREAM_MF 0x10008 +#define BASS_CTYPE_STREAM_AM 0x10009 +#define BASS_CTYPE_STREAM_SAMPLE 0x1000a +#define BASS_CTYPE_STREAM_DUMMY 0x18000 +#define BASS_CTYPE_STREAM_DEVICE 0x18001 +#define BASS_CTYPE_STREAM_WAV 0x40000 // WAVE flag (LOWORD=codec) +#define BASS_CTYPE_STREAM_WAV_PCM 0x50001 +#define BASS_CTYPE_STREAM_WAV_FLOAT 0x50003 +#define BASS_CTYPE_MUSIC_MOD 0x20000 +#define BASS_CTYPE_MUSIC_MTM 0x20001 +#define BASS_CTYPE_MUSIC_S3M 0x20002 +#define BASS_CTYPE_MUSIC_XM 0x20003 +#define BASS_CTYPE_MUSIC_IT 0x20004 +#define BASS_CTYPE_MUSIC_MO3 0x00100 // MO3 flag + +// BASS_PluginLoad flags +#define BASS_PLUGIN_PROC 1 + +typedef struct { + DWORD ctype; // channel type +#if defined(_WIN32_WCE) || (defined(WINAPI_FAMILY) && WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP) + const wchar_t *name; // format description + const wchar_t *exts; // file extension filter (*.ext1;*.ext2;etc...) +#else + const char *name; // format description + const char *exts; // file extension filter (*.ext1;*.ext2;etc...) +#endif +} BASS_PLUGINFORM; + +typedef struct { + DWORD version; // version (same form as BASS_GetVersion) + DWORD formatc; // number of formats + const BASS_PLUGINFORM *formats; // the array of formats +} BASS_PLUGININFO; + +// 3D vector (for 3D positions/velocities/orientations) +typedef struct BASS_3DVECTOR { +#ifdef __cplusplus + BASS_3DVECTOR() {} + BASS_3DVECTOR(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {} +#endif + float x; // +=right, -=left + float y; // +=up, -=down + float z; // +=front, -=behind +} BASS_3DVECTOR; + +// 3D channel modes +#define BASS_3DMODE_NORMAL 0 // normal 3D processing +#define BASS_3DMODE_RELATIVE 1 // position is relative to the listener +#define BASS_3DMODE_OFF 2 // no 3D processing + +// software 3D mixing algorithms (used with BASS_CONFIG_3DALGORITHM) +#define BASS_3DALG_DEFAULT 0 +#define BASS_3DALG_OFF 1 +#define BASS_3DALG_FULL 2 +#define BASS_3DALG_LIGHT 3 + +// BASS_SampleGetChannel flags +#define BASS_SAMCHAN_NEW 1 // get a new playback channel +#define BASS_SAMCHAN_STREAM 2 // create a stream + +typedef DWORD (CALLBACK STREAMPROC)(HSTREAM handle, void *buffer, DWORD length, void *user); +/* User stream callback function. +handle : The stream that needs writing +buffer : Buffer to write the samples in +length : Number of bytes to write +user : The 'user' parameter value given when calling BASS_StreamCreate +RETURN : Number of bytes written. Set the BASS_STREAMPROC_END flag to end the stream. */ + +#define BASS_STREAMPROC_END 0x80000000 // end of user stream flag + +// Special STREAMPROCs +#define STREAMPROC_DUMMY (STREAMPROC*)0 // "dummy" stream +#define STREAMPROC_PUSH (STREAMPROC*)-1 // push stream +#define STREAMPROC_DEVICE (STREAMPROC*)-2 // device mix stream +#define STREAMPROC_DEVICE_3D (STREAMPROC*)-3 // device 3D mix stream + +// BASS_StreamCreateFileUser file systems +#define STREAMFILE_NOBUFFER 0 +#define STREAMFILE_BUFFER 1 +#define STREAMFILE_BUFFERPUSH 2 + +// User file stream callback functions +typedef void (CALLBACK FILECLOSEPROC)(void *user); +typedef QWORD (CALLBACK FILELENPROC)(void *user); +typedef DWORD (CALLBACK FILEREADPROC)(void *buffer, DWORD length, void *user); +typedef BOOL (CALLBACK FILESEEKPROC)(QWORD offset, void *user); + +typedef struct { + FILECLOSEPROC *close; + FILELENPROC *length; + FILEREADPROC *read; + FILESEEKPROC *seek; +} BASS_FILEPROCS; + +// BASS_StreamPutFileData options +#define BASS_FILEDATA_END 0 // end & close the file + +// BASS_StreamGetFilePosition modes +#define BASS_FILEPOS_CURRENT 0 +#define BASS_FILEPOS_DECODE BASS_FILEPOS_CURRENT +#define BASS_FILEPOS_DOWNLOAD 1 +#define BASS_FILEPOS_END 2 +#define BASS_FILEPOS_START 3 +#define BASS_FILEPOS_CONNECTED 4 +#define BASS_FILEPOS_BUFFER 5 +#define BASS_FILEPOS_SOCKET 6 +#define BASS_FILEPOS_ASYNCBUF 7 +#define BASS_FILEPOS_SIZE 8 +#define BASS_FILEPOS_BUFFERING 9 +#define BASS_FILEPOS_AVAILABLE 10 + +typedef void (CALLBACK DOWNLOADPROC)(const void *buffer, DWORD length, void *user); +/* Internet stream download callback function. +buffer : Buffer containing the downloaded data... NULL=end of download +length : Number of bytes in the buffer +user : The 'user' parameter value given when calling BASS_StreamCreateURL */ + +// BASS_ChannelSetSync types +#define BASS_SYNC_POS 0 +#define BASS_SYNC_END 2 +#define BASS_SYNC_META 4 +#define BASS_SYNC_SLIDE 5 +#define BASS_SYNC_STALL 6 +#define BASS_SYNC_DOWNLOAD 7 +#define BASS_SYNC_FREE 8 +#define BASS_SYNC_SETPOS 11 +#define BASS_SYNC_MUSICPOS 10 +#define BASS_SYNC_MUSICINST 1 +#define BASS_SYNC_MUSICFX 3 +#define BASS_SYNC_OGG_CHANGE 12 +#define BASS_SYNC_DEV_FAIL 14 +#define BASS_SYNC_DEV_FORMAT 15 +#define BASS_SYNC_THREAD 0x20000000 // flag: call sync in other thread +#define BASS_SYNC_MIXTIME 0x40000000 // flag: sync at mixtime, else at playtime +#define BASS_SYNC_ONETIME 0x80000000 // flag: sync only once, else continuously + +typedef void (CALLBACK SYNCPROC)(HSYNC handle, DWORD channel, DWORD data, void *user); +/* Sync callback function. +handle : The sync that has occured +channel: Channel that the sync occured in +data : Additional data associated with the sync's occurance +user : The 'user' parameter given when calling BASS_ChannelSetSync */ + +typedef void (CALLBACK DSPPROC)(HDSP handle, DWORD channel, void *buffer, DWORD length, void *user); +/* DSP callback function. +handle : The DSP handle +channel: Channel that the DSP is being applied to +buffer : Buffer to apply the DSP to +length : Number of bytes in the buffer +user : The 'user' parameter given when calling BASS_ChannelSetDSP */ + +typedef BOOL (CALLBACK RECORDPROC)(HRECORD handle, const void *buffer, DWORD length, void *user); +/* Recording callback function. +handle : The recording handle +buffer : Buffer containing the recorded sample data +length : Number of bytes +user : The 'user' parameter value given when calling BASS_RecordStart +RETURN : TRUE = continue recording, FALSE = stop */ + +// BASS_ChannelIsActive return values +#define BASS_ACTIVE_STOPPED 0 +#define BASS_ACTIVE_PLAYING 1 +#define BASS_ACTIVE_STALLED 2 +#define BASS_ACTIVE_PAUSED 3 +#define BASS_ACTIVE_PAUSED_DEVICE 4 + +// Channel attributes +#define BASS_ATTRIB_FREQ 1 +#define BASS_ATTRIB_VOL 2 +#define BASS_ATTRIB_PAN 3 +#define BASS_ATTRIB_EAXMIX 4 +#define BASS_ATTRIB_NOBUFFER 5 +#define BASS_ATTRIB_VBR 6 +#define BASS_ATTRIB_CPU 7 +#define BASS_ATTRIB_SRC 8 +#define BASS_ATTRIB_NET_RESUME 9 +#define BASS_ATTRIB_SCANINFO 10 +#define BASS_ATTRIB_NORAMP 11 +#define BASS_ATTRIB_BITRATE 12 +#define BASS_ATTRIB_BUFFER 13 +#define BASS_ATTRIB_GRANULE 14 +#define BASS_ATTRIB_USER 15 +#define BASS_ATTRIB_TAIL 16 +#define BASS_ATTRIB_PUSH_LIMIT 17 +#define BASS_ATTRIB_DOWNLOADPROC 18 +#define BASS_ATTRIB_VOLDSP 19 +#define BASS_ATTRIB_VOLDSP_PRIORITY 20 +#define BASS_ATTRIB_MUSIC_AMPLIFY 0x100 +#define BASS_ATTRIB_MUSIC_PANSEP 0x101 +#define BASS_ATTRIB_MUSIC_PSCALER 0x102 +#define BASS_ATTRIB_MUSIC_BPM 0x103 +#define BASS_ATTRIB_MUSIC_SPEED 0x104 +#define BASS_ATTRIB_MUSIC_VOL_GLOBAL 0x105 +#define BASS_ATTRIB_MUSIC_ACTIVE 0x106 +#define BASS_ATTRIB_MUSIC_VOL_CHAN 0x200 // + channel # +#define BASS_ATTRIB_MUSIC_VOL_INST 0x300 // + instrument # + +// BASS_ChannelSlideAttribute flags +#define BASS_SLIDE_LOG 0x1000000 + +// BASS_ChannelGetData flags +#define BASS_DATA_AVAILABLE 0 // query how much data is buffered +#define BASS_DATA_NOREMOVE 0x10000000 // flag: don't remove data from recording buffer +#define BASS_DATA_FIXED 0x20000000 // unused +#define BASS_DATA_FLOAT 0x40000000 // flag: return floating-point sample data +#define BASS_DATA_FFT256 0x80000000 // 256 sample FFT +#define BASS_DATA_FFT512 0x80000001 // 512 FFT +#define BASS_DATA_FFT1024 0x80000002 // 1024 FFT +#define BASS_DATA_FFT2048 0x80000003 // 2048 FFT +#define BASS_DATA_FFT4096 0x80000004 // 4096 FFT +#define BASS_DATA_FFT8192 0x80000005 // 8192 FFT +#define BASS_DATA_FFT16384 0x80000006 // 16384 FFT +#define BASS_DATA_FFT32768 0x80000007 // 32768 FFT +#define BASS_DATA_FFT_INDIVIDUAL 0x10 // FFT flag: FFT for each channel, else all combined +#define BASS_DATA_FFT_NOWINDOW 0x20 // FFT flag: no Hanning window +#define BASS_DATA_FFT_REMOVEDC 0x40 // FFT flag: pre-remove DC bias +#define BASS_DATA_FFT_COMPLEX 0x80 // FFT flag: return complex data +#define BASS_DATA_FFT_NYQUIST 0x100 // FFT flag: return extra Nyquist value + +// BASS_ChannelGetLevelEx flags +#define BASS_LEVEL_MONO 1 // get mono level +#define BASS_LEVEL_STEREO 2 // get stereo level +#define BASS_LEVEL_RMS 4 // get RMS levels +#define BASS_LEVEL_VOLPAN 8 // apply VOL/PAN attributes to the levels +#define BASS_LEVEL_NOREMOVE 16 // don't remove data from recording buffer + +// BASS_ChannelGetTags types : what's returned +#define BASS_TAG_ID3 0 // ID3v1 tags : TAG_ID3 structure +#define BASS_TAG_ID3V2 1 // ID3v2 tags : variable length block +#define BASS_TAG_OGG 2 // OGG comments : series of null-terminated UTF-8 strings +#define BASS_TAG_HTTP 3 // HTTP headers : series of null-terminated ASCII strings +#define BASS_TAG_ICY 4 // ICY headers : series of null-terminated ANSI strings +#define BASS_TAG_META 5 // ICY metadata : ANSI string +#define BASS_TAG_APE 6 // APE tags : series of null-terminated UTF-8 strings +#define BASS_TAG_MP4 7 // MP4/iTunes metadata : series of null-terminated UTF-8 strings +#define BASS_TAG_WMA 8 // WMA tags : series of null-terminated UTF-8 strings +#define BASS_TAG_VENDOR 9 // OGG encoder : UTF-8 string +#define BASS_TAG_LYRICS3 10 // Lyric3v2 tag : ASCII string +#define BASS_TAG_CA_CODEC 11 // CoreAudio codec info : TAG_CA_CODEC structure +#define BASS_TAG_MF 13 // Media Foundation tags : series of null-terminated UTF-8 strings +#define BASS_TAG_WAVEFORMAT 14 // WAVE format : WAVEFORMATEEX structure +#define BASS_TAG_AM_NAME 16 // Android Media codec name : ASCII string +#define BASS_TAG_ID3V2_2 17 // ID3v2 tags (2nd block) : variable length block +#define BASS_TAG_AM_MIME 18 // Android Media MIME type : ASCII string +#define BASS_TAG_LOCATION 19 // redirected URL : ASCII string +#define BASS_TAG_RIFF_INFO 0x100 // RIFF "INFO" tags : series of null-terminated ANSI strings +#define BASS_TAG_RIFF_BEXT 0x101 // RIFF/BWF "bext" tags : TAG_BEXT structure +#define BASS_TAG_RIFF_CART 0x102 // RIFF/BWF "cart" tags : TAG_CART structure +#define BASS_TAG_RIFF_DISP 0x103 // RIFF "DISP" text tag : ANSI string +#define BASS_TAG_RIFF_CUE 0x104 // RIFF "cue " chunk : TAG_CUE structure +#define BASS_TAG_RIFF_SMPL 0x105 // RIFF "smpl" chunk : TAG_SMPL structure +#define BASS_TAG_APE_BINARY 0x1000 // + index #, binary APE tag : TAG_APE_BINARY structure +#define BASS_TAG_MUSIC_NAME 0x10000 // MOD music name : ANSI string +#define BASS_TAG_MUSIC_MESSAGE 0x10001 // MOD message : ANSI string +#define BASS_TAG_MUSIC_ORDERS 0x10002 // MOD order list : BYTE array of pattern numbers +#define BASS_TAG_MUSIC_AUTH 0x10003 // MOD author : UTF-8 string +#define BASS_TAG_MUSIC_INST 0x10100 // + instrument #, MOD instrument name : ANSI string +#define BASS_TAG_MUSIC_CHAN 0x10200 // + channel #, MOD channel name : ANSI string +#define BASS_TAG_MUSIC_SAMPLE 0x10300 // + sample #, MOD sample name : ANSI string + +// ID3v1 tag structure +typedef struct { + char id[3]; + char title[30]; + char artist[30]; + char album[30]; + char year[4]; + char comment[30]; + BYTE genre; +} TAG_ID3; + +// Binary APE tag structure +typedef struct { + const char *key; + const void *data; + DWORD length; +} TAG_APE_BINARY; + +// BWF "bext" tag structure +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4200) +#endif +#pragma pack(push,1) +typedef struct { + char Description[256]; // description + char Originator[32]; // name of the originator + char OriginatorReference[32]; // reference of the originator + char OriginationDate[10]; // date of creation (yyyy-mm-dd) + char OriginationTime[8]; // time of creation (hh-mm-ss) + QWORD TimeReference; // first sample count since midnight (little-endian) + WORD Version; // BWF version (little-endian) + BYTE UMID[64]; // SMPTE UMID + BYTE Reserved[190]; +#if defined(__GNUC__) && __GNUC__<3 + char CodingHistory[0]; // history +#elif 1 // change to 0 if compiler fails the following line + char CodingHistory[]; // history +#else + char CodingHistory[1]; // history +#endif +} TAG_BEXT; +#pragma pack(pop) + +// BWF "cart" tag structures +typedef struct +{ + DWORD dwUsage; // FOURCC timer usage ID + DWORD dwValue; // timer value in samples from head +} TAG_CART_TIMER; + +typedef struct +{ + char Version[4]; // version of the data structure + char Title[64]; // title of cart audio sequence + char Artist[64]; // artist or creator name + char CutID[64]; // cut number identification + char ClientID[64]; // client identification + char Category[64]; // category ID, PSA, NEWS, etc + char Classification[64]; // classification or auxiliary key + char OutCue[64]; // out cue text + char StartDate[10]; // yyyy-mm-dd + char StartTime[8]; // hh:mm:ss + char EndDate[10]; // yyyy-mm-dd + char EndTime[8]; // hh:mm:ss + char ProducerAppID[64]; // name of vendor or application + char ProducerAppVersion[64]; // version of producer application + char UserDef[64]; // user defined text + DWORD dwLevelReference; // sample value for 0 dB reference + TAG_CART_TIMER PostTimer[8]; // 8 time markers after head + char Reserved[276]; + char URL[1024]; // uniform resource locator +#if defined(__GNUC__) && __GNUC__<3 + char TagText[0]; // free form text for scripts or tags +#elif 1 // change to 0 if compiler fails the following line + char TagText[]; // free form text for scripts or tags +#else + char TagText[1]; // free form text for scripts or tags +#endif +} TAG_CART; + +// RIFF "cue " tag structures +typedef struct +{ + DWORD dwName; + DWORD dwPosition; + DWORD fccChunk; + DWORD dwChunkStart; + DWORD dwBlockStart; + DWORD dwSampleOffset; +} TAG_CUE_POINT; + +typedef struct +{ + DWORD dwCuePoints; +#if defined(__GNUC__) && __GNUC__<3 + TAG_CUE_POINT CuePoints[0]; +#elif 1 // change to 0 if compiler fails the following line + TAG_CUE_POINT CuePoints[]; +#else + TAG_CUE_POINT CuePoints[1]; +#endif +} TAG_CUE; + +// RIFF "smpl" tag structures +typedef struct +{ + DWORD dwIdentifier; + DWORD dwType; + DWORD dwStart; + DWORD dwEnd; + DWORD dwFraction; + DWORD dwPlayCount; +} TAG_SMPL_LOOP; + +typedef struct +{ + DWORD dwManufacturer; + DWORD dwProduct; + DWORD dwSamplePeriod; + DWORD dwMIDIUnityNote; + DWORD dwMIDIPitchFraction; + DWORD dwSMPTEFormat; + DWORD dwSMPTEOffset; + DWORD cSampleLoops; + DWORD cbSamplerData; +#if defined(__GNUC__) && __GNUC__<3 + TAG_SMPL_LOOP SampleLoops[0]; +#elif 1 // change to 0 if compiler fails the following line + TAG_SMPL_LOOP SampleLoops[]; +#else + TAG_SMPL_LOOP SampleLoops[1]; +#endif +} TAG_SMPL; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +// CoreAudio codec info structure +typedef struct { + DWORD ftype; // file format + DWORD atype; // audio format + const char *name; // description +} TAG_CA_CODEC; + +#ifndef _WAVEFORMATEX_ +#define _WAVEFORMATEX_ +#pragma pack(push,1) +typedef struct tWAVEFORMATEX +{ + WORD wFormatTag; + WORD nChannels; + DWORD nSamplesPerSec; + DWORD nAvgBytesPerSec; + WORD nBlockAlign; + WORD wBitsPerSample; + WORD cbSize; +} WAVEFORMATEX, *PWAVEFORMATEX, *LPWAVEFORMATEX; +typedef const WAVEFORMATEX *LPCWAVEFORMATEX; +#pragma pack(pop) +#endif + +// BASS_ChannelGetLength/GetPosition/SetPosition modes +#define BASS_POS_BYTE 0 // byte position +#define BASS_POS_MUSIC_ORDER 1 // order.row position, MAKELONG(order,row) +#define BASS_POS_OGG 3 // OGG bitstream number +#define BASS_POS_END 0x10 // trimmed end position +#define BASS_POS_LOOP 0x11 // loop start positiom +#define BASS_POS_FLUSH 0x1000000 // flag: flush decoder/FX buffers +#define BASS_POS_RESET 0x2000000 // flag: reset user file buffers +#define BASS_POS_RELATIVE 0x4000000 // flag: seek relative to the current position +#define BASS_POS_INEXACT 0x8000000 // flag: allow seeking to inexact position +#define BASS_POS_DECODE 0x10000000 // flag: get the decoding (not playing) position +#define BASS_POS_DECODETO 0x20000000 // flag: decode to the position instead of seeking +#define BASS_POS_SCAN 0x40000000 // flag: scan to the position + +// BASS_ChannelSetDevice/GetDevice option +#define BASS_NODEVICE 0x20000 + +// BASS_RecordSetInput flags +#define BASS_INPUT_OFF 0x10000 +#define BASS_INPUT_ON 0x20000 + +#define BASS_INPUT_TYPE_MASK 0xff000000 +#define BASS_INPUT_TYPE_UNDEF 0x00000000 +#define BASS_INPUT_TYPE_DIGITAL 0x01000000 +#define BASS_INPUT_TYPE_LINE 0x02000000 +#define BASS_INPUT_TYPE_MIC 0x03000000 +#define BASS_INPUT_TYPE_SYNTH 0x04000000 +#define BASS_INPUT_TYPE_CD 0x05000000 +#define BASS_INPUT_TYPE_PHONE 0x06000000 +#define BASS_INPUT_TYPE_SPEAKER 0x07000000 +#define BASS_INPUT_TYPE_WAVE 0x08000000 +#define BASS_INPUT_TYPE_AUX 0x09000000 +#define BASS_INPUT_TYPE_ANALOG 0x0a000000 + +// BASS_ChannelSetFX effect types +#define BASS_FX_DX8_CHORUS 0 +#define BASS_FX_DX8_COMPRESSOR 1 +#define BASS_FX_DX8_DISTORTION 2 +#define BASS_FX_DX8_ECHO 3 +#define BASS_FX_DX8_FLANGER 4 +#define BASS_FX_DX8_GARGLE 5 +#define BASS_FX_DX8_I3DL2REVERB 6 +#define BASS_FX_DX8_PARAMEQ 7 +#define BASS_FX_DX8_REVERB 8 +#define BASS_FX_VOLUME 9 + +typedef struct { + float fWetDryMix; + float fDepth; + float fFeedback; + float fFrequency; + DWORD lWaveform; // 0=triangle, 1=sine + float fDelay; + DWORD lPhase; // BASS_DX8_PHASE_xxx +} BASS_DX8_CHORUS; + +typedef struct { + float fGain; + float fAttack; + float fRelease; + float fThreshold; + float fRatio; + float fPredelay; +} BASS_DX8_COMPRESSOR; + +typedef struct { + float fGain; + float fEdge; + float fPostEQCenterFrequency; + float fPostEQBandwidth; + float fPreLowpassCutoff; +} BASS_DX8_DISTORTION; + +typedef struct { + float fWetDryMix; + float fFeedback; + float fLeftDelay; + float fRightDelay; + BOOL lPanDelay; +} BASS_DX8_ECHO; + +typedef struct { + float fWetDryMix; + float fDepth; + float fFeedback; + float fFrequency; + DWORD lWaveform; // 0=triangle, 1=sine + float fDelay; + DWORD lPhase; // BASS_DX8_PHASE_xxx +} BASS_DX8_FLANGER; + +typedef struct { + DWORD dwRateHz; // Rate of modulation in hz + DWORD dwWaveShape; // 0=triangle, 1=square +} BASS_DX8_GARGLE; + +typedef struct { + int lRoom; // [-10000, 0] default: -1000 mB + int lRoomHF; // [-10000, 0] default: 0 mB + float flRoomRolloffFactor; // [0.0, 10.0] default: 0.0 + float flDecayTime; // [0.1, 20.0] default: 1.49s + float flDecayHFRatio; // [0.1, 2.0] default: 0.83 + int lReflections; // [-10000, 1000] default: -2602 mB + float flReflectionsDelay; // [0.0, 0.3] default: 0.007 s + int lReverb; // [-10000, 2000] default: 200 mB + float flReverbDelay; // [0.0, 0.1] default: 0.011 s + float flDiffusion; // [0.0, 100.0] default: 100.0 % + float flDensity; // [0.0, 100.0] default: 100.0 % + float flHFReference; // [20.0, 20000.0] default: 5000.0 Hz +} BASS_DX8_I3DL2REVERB; + +typedef struct { + float fCenter; + float fBandwidth; + float fGain; +} BASS_DX8_PARAMEQ; + +typedef struct { + float fInGain; // [-96.0,0.0] default: 0.0 dB + float fReverbMix; // [-96.0,0.0] default: 0.0 db + float fReverbTime; // [0.001,3000.0] default: 1000.0 ms + float fHighFreqRTRatio; // [0.001,0.999] default: 0.001 +} BASS_DX8_REVERB; + +#define BASS_DX8_PHASE_NEG_180 0 +#define BASS_DX8_PHASE_NEG_90 1 +#define BASS_DX8_PHASE_ZERO 2 +#define BASS_DX8_PHASE_90 3 +#define BASS_DX8_PHASE_180 4 + +typedef struct { + float fTarget; + float fCurrent; + float fTime; + DWORD lCurve; +} BASS_FX_VOLUME_PARAM; + +typedef void (CALLBACK IOSNOTIFYPROC)(DWORD status); +/* iOS notification callback function. +status : The notification (BASS_IOSNOTIFY_xxx) */ + +#define BASS_IOSNOTIFY_INTERRUPT 1 // interruption started +#define BASS_IOSNOTIFY_INTERRUPT_END 2 // interruption ended + +BOOL BASSDEF(BASS_SetConfig)(DWORD option, DWORD value); +DWORD BASSDEF(BASS_GetConfig)(DWORD option); +BOOL BASSDEF(BASS_SetConfigPtr)(DWORD option, const void *value); +const void *BASSDEF(BASS_GetConfigPtr)(DWORD option); +DWORD BASSDEF(BASS_GetVersion)(void); +int BASSDEF(BASS_ErrorGetCode)(void); + +BOOL BASSDEF(BASS_GetDeviceInfo)(DWORD device, BASS_DEVICEINFO *info); +#if defined(_WIN32) && !defined(_WIN32_WCE) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP) +BOOL BASSDEF(BASS_Init)(int device, DWORD freq, DWORD flags, HWND win, const void *dsguid); +#else +BOOL BASSDEF(BASS_Init)(int device, DWORD freq, DWORD flags, void *win, const void *dsguid); +#endif +BOOL BASSDEF(BASS_Free)(void); +BOOL BASSDEF(BASS_SetDevice)(DWORD device); +DWORD BASSDEF(BASS_GetDevice)(void); +BOOL BASSDEF(BASS_GetInfo)(BASS_INFO *info); +BOOL BASSDEF(BASS_Start)(void); +BOOL BASSDEF(BASS_Stop)(void); +BOOL BASSDEF(BASS_Pause)(void); +DWORD BASSDEF(BASS_IsStarted)(void); +BOOL BASSDEF(BASS_Update)(DWORD length); +float BASSDEF(BASS_GetCPU)(void); +BOOL BASSDEF(BASS_SetVolume)(float volume); +float BASSDEF(BASS_GetVolume)(void); +#if defined(_WIN32) && !defined(_WIN32_WCE) && !(defined(WINAPI_FAMILY) && WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP) +void *BASSDEF(BASS_GetDSoundObject)(DWORD object); +#endif + +BOOL BASSDEF(BASS_Set3DFactors)(float distf, float rollf, float doppf); +BOOL BASSDEF(BASS_Get3DFactors)(float *distf, float *rollf, float *doppf); +BOOL BASSDEF(BASS_Set3DPosition)(const BASS_3DVECTOR *pos, const BASS_3DVECTOR *vel, const BASS_3DVECTOR *front, const BASS_3DVECTOR *top); +BOOL BASSDEF(BASS_Get3DPosition)(BASS_3DVECTOR *pos, BASS_3DVECTOR *vel, BASS_3DVECTOR *front, BASS_3DVECTOR *top); +void BASSDEF(BASS_Apply3D)(void); + +HPLUGIN BASSDEF(BASS_PluginLoad)(const char *file, DWORD flags); +BOOL BASSDEF(BASS_PluginFree)(HPLUGIN handle); +BOOL BASSDEF(BASS_PluginEnable)(HPLUGIN handle, BOOL enable); +const BASS_PLUGININFO *BASSDEF(BASS_PluginGetInfo)(HPLUGIN handle); + +HSAMPLE BASSDEF(BASS_SampleLoad)(BOOL mem, const void *file, QWORD offset, DWORD length, DWORD max, DWORD flags); +HSAMPLE BASSDEF(BASS_SampleCreate)(DWORD length, DWORD freq, DWORD chans, DWORD max, DWORD flags); +BOOL BASSDEF(BASS_SampleFree)(HSAMPLE handle); +BOOL BASSDEF(BASS_SampleSetData)(HSAMPLE handle, const void *buffer); +BOOL BASSDEF(BASS_SampleGetData)(HSAMPLE handle, void *buffer); +BOOL BASSDEF(BASS_SampleGetInfo)(HSAMPLE handle, BASS_SAMPLE *info); +BOOL BASSDEF(BASS_SampleSetInfo)(HSAMPLE handle, const BASS_SAMPLE *info); +DWORD BASSDEF(BASS_SampleGetChannel)(HSAMPLE handle, DWORD flags); +DWORD BASSDEF(BASS_SampleGetChannels)(HSAMPLE handle, HCHANNEL *channels); +BOOL BASSDEF(BASS_SampleStop)(HSAMPLE handle); + +HSTREAM BASSDEF(BASS_StreamCreate)(DWORD freq, DWORD chans, DWORD flags, STREAMPROC *proc, void *user); +HSTREAM BASSDEF(BASS_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags); +HSTREAM BASSDEF(BASS_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user); +HSTREAM BASSDEF(BASS_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *proc, void *user); +BOOL BASSDEF(BASS_StreamFree)(HSTREAM handle); +QWORD BASSDEF(BASS_StreamGetFilePosition)(HSTREAM handle, DWORD mode); +DWORD BASSDEF(BASS_StreamPutData)(HSTREAM handle, const void *buffer, DWORD length); +DWORD BASSDEF(BASS_StreamPutFileData)(HSTREAM handle, const void *buffer, DWORD length); + +HMUSIC BASSDEF(BASS_MusicLoad)(BOOL mem, const void *file, QWORD offset, DWORD length, DWORD flags, DWORD freq); +BOOL BASSDEF(BASS_MusicFree)(HMUSIC handle); + +BOOL BASSDEF(BASS_RecordGetDeviceInfo)(DWORD device, BASS_DEVICEINFO *info); +BOOL BASSDEF(BASS_RecordInit)(int device); +BOOL BASSDEF(BASS_RecordFree)(void); +BOOL BASSDEF(BASS_RecordSetDevice)(DWORD device); +DWORD BASSDEF(BASS_RecordGetDevice)(void); +BOOL BASSDEF(BASS_RecordGetInfo)(BASS_RECORDINFO *info); +const char *BASSDEF(BASS_RecordGetInputName)(int input); +BOOL BASSDEF(BASS_RecordSetInput)(int input, DWORD flags, float volume); +DWORD BASSDEF(BASS_RecordGetInput)(int input, float *volume); +HRECORD BASSDEF(BASS_RecordStart)(DWORD freq, DWORD chans, DWORD flags, RECORDPROC *proc, void *user); + +double BASSDEF(BASS_ChannelBytes2Seconds)(DWORD handle, QWORD pos); +QWORD BASSDEF(BASS_ChannelSeconds2Bytes)(DWORD handle, double pos); +DWORD BASSDEF(BASS_ChannelGetDevice)(DWORD handle); +BOOL BASSDEF(BASS_ChannelSetDevice)(DWORD handle, DWORD device); +DWORD BASSDEF(BASS_ChannelIsActive)(DWORD handle); +BOOL BASSDEF(BASS_ChannelGetInfo)(DWORD handle, BASS_CHANNELINFO *info); +const char *BASSDEF(BASS_ChannelGetTags)(DWORD handle, DWORD tags); +DWORD BASSDEF(BASS_ChannelFlags)(DWORD handle, DWORD flags, DWORD mask); +BOOL BASSDEF(BASS_ChannelLock)(DWORD handle, BOOL lock); +BOOL BASSDEF(BASS_ChannelFree)(DWORD handle); +BOOL BASSDEF(BASS_ChannelPlay)(DWORD handle, BOOL restart); +BOOL BASSDEF(BASS_ChannelStart)(DWORD handle); +BOOL BASSDEF(BASS_ChannelStop)(DWORD handle); +BOOL BASSDEF(BASS_ChannelPause)(DWORD handle); +BOOL BASSDEF(BASS_ChannelUpdate)(DWORD handle, DWORD length); +BOOL BASSDEF(BASS_ChannelSetAttribute)(DWORD handle, DWORD attrib, float value); +BOOL BASSDEF(BASS_ChannelGetAttribute)(DWORD handle, DWORD attrib, float *value); +BOOL BASSDEF(BASS_ChannelSlideAttribute)(DWORD handle, DWORD attrib, float value, DWORD time); +BOOL BASSDEF(BASS_ChannelIsSliding)(DWORD handle, DWORD attrib); +BOOL BASSDEF(BASS_ChannelSetAttributeEx)(DWORD handle, DWORD attrib, void *value, DWORD size); +DWORD BASSDEF(BASS_ChannelGetAttributeEx)(DWORD handle, DWORD attrib, void *value, DWORD size); +BOOL BASSDEF(BASS_ChannelSet3DAttributes)(DWORD handle, int mode, float min, float max, int iangle, int oangle, float outvol); +BOOL BASSDEF(BASS_ChannelGet3DAttributes)(DWORD handle, DWORD *mode, float *min, float *max, DWORD *iangle, DWORD *oangle, float *outvol); +BOOL BASSDEF(BASS_ChannelSet3DPosition)(DWORD handle, const BASS_3DVECTOR *pos, const BASS_3DVECTOR *orient, const BASS_3DVECTOR *vel); +BOOL BASSDEF(BASS_ChannelGet3DPosition)(DWORD handle, BASS_3DVECTOR *pos, BASS_3DVECTOR *orient, BASS_3DVECTOR *vel); +QWORD BASSDEF(BASS_ChannelGetLength)(DWORD handle, DWORD mode); +BOOL BASSDEF(BASS_ChannelSetPosition)(DWORD handle, QWORD pos, DWORD mode); +QWORD BASSDEF(BASS_ChannelGetPosition)(DWORD handle, DWORD mode); +DWORD BASSDEF(BASS_ChannelGetLevel)(DWORD handle); +BOOL BASSDEF(BASS_ChannelGetLevelEx)(DWORD handle, float *levels, float length, DWORD flags); +DWORD BASSDEF(BASS_ChannelGetData)(DWORD handle, void *buffer, DWORD length); +HSYNC BASSDEF(BASS_ChannelSetSync)(DWORD handle, DWORD type, QWORD param, SYNCPROC *proc, void *user); +BOOL BASSDEF(BASS_ChannelRemoveSync)(DWORD handle, HSYNC sync); +BOOL BASSDEF(BASS_ChannelSetLink)(DWORD handle, DWORD chan); +BOOL BASSDEF(BASS_ChannelRemoveLink)(DWORD handle, DWORD chan); +HDSP BASSDEF(BASS_ChannelSetDSP)(DWORD handle, DSPPROC *proc, void *user, int priority); +BOOL BASSDEF(BASS_ChannelRemoveDSP)(DWORD handle, HDSP dsp); +HFX BASSDEF(BASS_ChannelSetFX)(DWORD handle, DWORD type, int priority); +BOOL BASSDEF(BASS_ChannelRemoveFX)(DWORD handle, HFX fx); + +BOOL BASSDEF(BASS_FXSetParameters)(HFX handle, const void *params); +BOOL BASSDEF(BASS_FXGetParameters)(HFX handle, void *params); +BOOL BASSDEF(BASS_FXSetPriority)(HFX handle, int priority); +BOOL BASSDEF(BASS_FXReset)(DWORD handle); + +#ifdef __cplusplus +} + +#if defined(_WIN32) && !defined(NOBASSOVERLOADS) +static inline HPLUGIN BASS_PluginLoad(const WCHAR *file, DWORD flags) +{ + return BASS_PluginLoad((const char*)file, flags | BASS_UNICODE); +} + +static inline HMUSIC BASS_MusicLoad(BOOL mem, const WCHAR *file, QWORD offset, DWORD length, DWORD flags, DWORD freq) +{ + return BASS_MusicLoad(mem, (const void*)file, offset, length, flags | BASS_UNICODE, freq); +} + +static inline HSAMPLE BASS_SampleLoad(BOOL mem, const WCHAR *file, QWORD offset, DWORD length, DWORD max, DWORD flags) +{ + return BASS_SampleLoad(mem, (const void*)file, offset, length, max, flags | BASS_UNICODE); +} + +static inline HSTREAM BASS_StreamCreateFile(BOOL mem, const WCHAR *file, QWORD offset, QWORD length, DWORD flags) +{ + return BASS_StreamCreateFile(mem, (const void*)file, offset, length, flags | BASS_UNICODE); +} + +static inline HSTREAM BASS_StreamCreateURL(const WCHAR *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user) +{ + return BASS_StreamCreateURL((const char*)url, offset, flags | BASS_UNICODE, proc, user); +} + +static inline BOOL BASS_SetConfigPtr(DWORD option, const WCHAR *value) +{ + return BASS_SetConfigPtr(option | BASS_UNICODE, (const void*)value); +} +#endif +#endif + +#ifdef __OBJC__ +#undef BOOL +#endif + +#endif diff --git a/examples/2024-01-15-zig-build-explained/part2/2.3/bass/linux/x64/libbass.dylib b/examples/2024-01-15-zig-build-explained/part2/2.3/bass/linux/x64/libbass.dylib new file mode 100644 index 0000000..5a76f93 Binary files /dev/null and b/examples/2024-01-15-zig-build-explained/part2/2.3/bass/linux/x64/libbass.dylib differ diff --git a/examples/2024-01-15-zig-build-explained/part2/2.3/build.zig b/examples/2024-01-15-zig-build-explained/part2/2.3/build.zig new file mode 100644 index 0000000..b33be1a --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.3/build.zig @@ -0,0 +1,22 @@ +const std = @import("std"); +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "example", + .target = target, + .optimize = optimize, + }); + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("bass-player.c"), .flags = &.{} }); + exe.addIncludePath(std.build.LazyPath.relative("bass/linux")); + exe.addLibraryPath(std.build.LazyPath.relative("bass/linux/x64")); + exe.linkSystemLibraryName("bass"); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.4/build.zig b/examples/2024-01-15-zig-build-explained/part2/2.4/build.zig new file mode 100644 index 0000000..79785c2 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.4/build.zig @@ -0,0 +1,21 @@ +const std = @import("std"); +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "example", + .target = target, + .optimize = optimize, + }); + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("multi-main.c"), .flags = &.{} }); + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("multi.c"), .flags = &.{ "-I", "inc1" } }); + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("multi.c"), .flags = &.{ "-I", "inc2" } }); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.4/inc1/api.h b/examples/2024-01-15-zig-build-explained/part2/2.4/inc1/api.h new file mode 100644 index 0000000..c40d6a9 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.4/inc1/api.h @@ -0,0 +1 @@ +#define API_NAME foo diff --git a/examples/2024-01-15-zig-build-explained/part2/2.4/inc2/api.h b/examples/2024-01-15-zig-build-explained/part2/2.4/inc2/api.h new file mode 100644 index 0000000..711a4e9 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.4/inc2/api.h @@ -0,0 +1 @@ +#define API_NAME bar diff --git a/examples/2024-01-15-zig-build-explained/part2/2.4/multi-main.c b/examples/2024-01-15-zig-build-explained/part2/2.4/multi-main.c new file mode 100644 index 0000000..ee0fe12 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.4/multi-main.c @@ -0,0 +1,10 @@ +#include +void foo(); +void bar(); + +int main() +{ + foo(); + bar(); + return 0; +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.4/multi.c b/examples/2024-01-15-zig-build-explained/part2/2.4/multi.c new file mode 100644 index 0000000..a7b8bbb --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.4/multi.c @@ -0,0 +1,10 @@ +#include +#include + +#define S(X) #X +#define SS(X) S(X) + +void API_NAME() +{ + printf(SS(API_NAME) "\n"); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.5/buffer.cc b/examples/2024-01-15-zig-build-explained/part2/2.5/buffer.cc new file mode 100644 index 0000000..a722a37 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.5/buffer.cc @@ -0,0 +1,29 @@ +#include +#include +#include + +extern "C" void * buffer_create(size_t len) +{ + return new char[len]; +} + +extern "C" void buffer_destroy(void * ptr) +{ + delete[] (char*)ptr; +} + +extern "C" void buffer_write(void * buf, size_t offset, void * data, size_t len) +{ + std::copy( + static_cast(data), + static_cast(data) + len, + static_cast(buf) + offset); +} + +extern "C" void buffer_read(void * buf, size_t offset, void * data, size_t len) +{ + std::copy( + static_cast(buf) + offset, + static_cast(buf) + offset + len, + static_cast(data)); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.5/build.zig b/examples/2024-01-15-zig-build-explained/part2/2.5/build.zig new file mode 100644 index 0000000..4aff5bb --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.5/build.zig @@ -0,0 +1,23 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "example", + .target = target, + .optimize = optimize, + }); + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("main.c"), .flags = &.{} }); + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("buffer.cc"), .flags = &.{} }); + exe.linkLibC(); + exe.linkLibCpp(); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.5/main.c b/examples/2024-01-15-zig-build-explained/part2/2.5/main.c new file mode 100644 index 0000000..59828bc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.5/main.c @@ -0,0 +1,22 @@ +#include + +void * buffer_create(size_t len); +void buffer_destroy(void * ptr); +void buffer_write(void * buf, size_t offset, void * data, size_t len); +void buffer_read(void * buf, size_t offset, void * data, size_t len); + +int main() +{ + void * buf = buffer_create(8); + buffer_write(buf, 0, "World", 6); + + { + char str[8]; + buffer_read(buf, 0, str, 6); + printf("Hello, %s!\n", str); + } + + buffer_destroy(buf); + + return 0; +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.6/buffer.cc b/examples/2024-01-15-zig-build-explained/part2/2.6/buffer.cc new file mode 100644 index 0000000..a722a37 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.6/buffer.cc @@ -0,0 +1,29 @@ +#include +#include +#include + +extern "C" void * buffer_create(size_t len) +{ + return new char[len]; +} + +extern "C" void buffer_destroy(void * ptr) +{ + delete[] (char*)ptr; +} + +extern "C" void buffer_write(void * buf, size_t offset, void * data, size_t len) +{ + std::copy( + static_cast(data), + static_cast(data) + len, + static_cast(buf) + offset); +} + +extern "C" void buffer_read(void * buf, size_t offset, void * data, size_t len) +{ + std::copy( + static_cast(buf) + offset, + static_cast(buf) + offset + len, + static_cast(data)); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.6/build.zig b/examples/2024-01-15-zig-build-explained/part2/2.6/build.zig new file mode 100644 index 0000000..afd4ab6 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.6/build.zig @@ -0,0 +1,23 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "example", + .target = target, + .optimize = optimize, + }); + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("main.c"), .flags = &.{"-std=c90"} }); + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("buffer.cc"), .flags = &.{"-std=c++17"} }); + exe.linkLibC(); + exe.linkLibCpp(); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.6/main.c b/examples/2024-01-15-zig-build-explained/part2/2.6/main.c new file mode 100644 index 0000000..59828bc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.6/main.c @@ -0,0 +1,22 @@ +#include + +void * buffer_create(size_t len); +void buffer_destroy(void * ptr); +void buffer_write(void * buf, size_t offset, void * data, size_t len); +void buffer_read(void * buf, size_t offset, void * data, size_t len); + +int main() +{ + void * buf = buffer_create(8); + buffer_write(buf, 0, "World", 6); + + { + char str[8]; + buffer_read(buf, 0, str, 6); + printf("Hello, %s!\n", str); + } + + buffer_destroy(buf); + + return 0; +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.7/build.zig b/examples/2024-01-15-zig-build-explained/part2/2.7/build.zig new file mode 100644 index 0000000..be8469e --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.7/build.zig @@ -0,0 +1,30 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const use_platform_io = b.option(bool, "platform-io", "Uses the native api instead of the C wrapper") orelse true; + const exe = b.addExecutable(.{ + .name = "example", + .target = target, + .optimize = optimize, + }); + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("print-main.c"), .flags = &.{} }); + if (use_platform_io) { + exe.defineCMacro("USE_PLATFORM_IO", null); + if (exe.target.isWindows()) { + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("print-windows.c"), .flags = &.{} }); + } else { + exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("print-unix.c"), .flags = &.{} }); + } + } + exe.linkLibC(); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.7/print-main.c b/examples/2024-01-15-zig-build-explained/part2/2.7/print-main.c new file mode 100644 index 0000000..52bd504 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.7/print-main.c @@ -0,0 +1,16 @@ +#include + +#ifdef USE_PLATFORM_IO +extern void printText(char const * str); +#else +void printText(char const * str) +{ + fputs(str, stdout); +} +#endif + +int main() +{ + printText("Hello, cross platform code!\n"); + return 0; +} \ No newline at end of file diff --git a/examples/2024-01-15-zig-build-explained/part2/2.7/print-unix.c b/examples/2024-01-15-zig-build-explained/part2/2.7/print-unix.c new file mode 100644 index 0000000..05a65fc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.7/print-unix.c @@ -0,0 +1,7 @@ +#include +#include + +void printText(char const * str) +{ + write(STDOUT_FILENO, str, strlen(str)); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.7/print-windows.c b/examples/2024-01-15-zig-build-explained/part2/2.7/print-windows.c new file mode 100644 index 0000000..3049ca7 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.7/print-windows.c @@ -0,0 +1,10 @@ +#include +#include + +void printText(char const * str) +{ + HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); + + DWORD bytes_written; + WriteFile(h, str, strlen(str), &bytes_written, NULL); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.8/buffer.cc b/examples/2024-01-15-zig-build-explained/part2/2.8/buffer.cc new file mode 100644 index 0000000..a722a37 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.8/buffer.cc @@ -0,0 +1,29 @@ +#include +#include +#include + +extern "C" void * buffer_create(size_t len) +{ + return new char[len]; +} + +extern "C" void buffer_destroy(void * ptr) +{ + delete[] (char*)ptr; +} + +extern "C" void buffer_write(void * buf, size_t offset, void * data, size_t len) +{ + std::copy( + static_cast(data), + static_cast(data) + len, + static_cast(buf) + offset); +} + +extern "C" void buffer_read(void * buf, size_t offset, void * data, size_t len) +{ + std::copy( + static_cast(buf) + offset, + static_cast(buf) + offset + len, + static_cast(data)); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.8/build.zig b/examples/2024-01-15-zig-build-explained/part2/2.8/build.zig new file mode 100644 index 0000000..6d7096b --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.8/build.zig @@ -0,0 +1,40 @@ +//demo2.8 +const std = @import("std"); +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "example", + .target = target, + .optimize = optimize, + }); + const flags = .{ + "-Wall", + "-Wextra", + "-Werror=return-type", + }; + const cflags = flags ++ .{"-std=c99"}; + const cppflags = cflags ++ .{ + "-std=c++17", + "-stdlib=libc++", + "-fno-exceptions", + }; + exe.addCSourceFile(.{ + .file = std.build.LazyPath.relative("main.c"), + .flags = &cflags, + }); + exe.addCSourceFile(.{ + .file = std.build.LazyPath.relative("buffer.cc"), + .flags = &cppflags, + }); + exe.linkLibC(); + exe.linkLibCpp(); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.8/main.c b/examples/2024-01-15-zig-build-explained/part2/2.8/main.c new file mode 100644 index 0000000..59828bc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.8/main.c @@ -0,0 +1,22 @@ +#include + +void * buffer_create(size_t len); +void buffer_destroy(void * ptr); +void buffer_write(void * buf, size_t offset, void * data, size_t len); +void buffer_read(void * buf, size_t offset, void * data, size_t len); + +int main() +{ + void * buf = buffer_create(8); + buffer_write(buf, 0, "World", 6); + + { + char str[8]; + buffer_read(buf, 0, str, 6); + printf("Hello, %s!\n", str); + } + + buffer_destroy(buf); + + return 0; +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.9/buffer.cc b/examples/2024-01-15-zig-build-explained/part2/2.9/buffer.cc new file mode 100644 index 0000000..a722a37 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.9/buffer.cc @@ -0,0 +1,29 @@ +#include +#include +#include + +extern "C" void * buffer_create(size_t len) +{ + return new char[len]; +} + +extern "C" void buffer_destroy(void * ptr) +{ + delete[] (char*)ptr; +} + +extern "C" void buffer_write(void * buf, size_t offset, void * data, size_t len) +{ + std::copy( + static_cast(data), + static_cast(data) + len, + static_cast(buf) + offset); +} + +extern "C" void buffer_read(void * buf, size_t offset, void * data, size_t len) +{ + std::copy( + static_cast(buf) + offset, + static_cast(buf) + offset + len, + static_cast(data)); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.9/build.zig b/examples/2024-01-15-zig-build-explained/part2/2.9/build.zig new file mode 100644 index 0000000..f60ae42 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.9/build.zig @@ -0,0 +1,43 @@ +//demo2.9 +const std = @import("std"); +pub fn build(b: *std.build.Builder) !void { + var sources = std.ArrayList([]const u8).init(b.allocator); + // Search for all C/C++ files in `src` and add them + { + var dir = try std.fs.cwd().openIterableDir(".", .{ .access_sub_paths = true }); + + var walker = try dir.walk(b.allocator); + defer walker.deinit(); + + const allowed_exts = [_][]const u8{ ".c", ".cpp", ".cxx", ".c++", ".cc" }; + while (try walker.next()) |entry| { + const ext = std.fs.path.extension(entry.basename); + const include_file = for (allowed_exts) |e| { + if (std.mem.eql(u8, ext, e)) + break true; + } else false; + if (include_file) { + // we have to clone the path as walker.next() or walker.deinit() will override/kill it + try sources.append(b.dupe(entry.path)); + } + } + } + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "example", + .target = target, + .optimize = optimize, + }); + exe.addCSourceFiles(sources.items, &.{}); + exe.linkLibC(); + exe.linkLibCpp(); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part2/2.9/main.c b/examples/2024-01-15-zig-build-explained/part2/2.9/main.c new file mode 100644 index 0000000..59828bc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/2.9/main.c @@ -0,0 +1,22 @@ +#include + +void * buffer_create(size_t len); +void buffer_destroy(void * ptr); +void buffer_write(void * buf, size_t offset, void * data, size_t len); +void buffer_read(void * buf, size_t offset, void * data, size_t len); + +int main() +{ + void * buf = buffer_create(8); + buffer_write(buf, 0, "World", 6); + + { + char str[8]; + buffer_read(buf, 0, str, 6); + printf("Hello, %s!\n", str); + } + + buffer_destroy(buf); + + return 0; +} diff --git a/examples/2024-01-15-zig-build-explained/part2/part.sh b/examples/2024-01-15-zig-build-explained/part2/part.sh new file mode 100755 index 0000000..c7df642 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part2/part.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +echo "Run Part..." +DIR="$(dirname "$(realpath "$0")")" +for ex in `ls -d */`;do + echo "Run example ${ex}..." + cd ${DIR}/${ex} + zig build --summary none +done diff --git a/examples/2024-01-15-zig-build-explained/part3/3.1/foo.ihex b/examples/2024-01-15-zig-build-explained/part3/3.1/foo.ihex new file mode 100644 index 0000000..e69de29 diff --git a/examples/2024-01-15-zig-build-explained/part3/3.1/ihex.zig b/examples/2024-01-15-zig-build-explained/part3/3.1/ihex.zig new file mode 100644 index 0000000..ffabca0 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.1/ihex.zig @@ -0,0 +1,3 @@ +pub fn loadFile(str: []const u8) ![]const u8 { + return str; +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.1/main.zig b/examples/2024-01-15-zig-build-explained/part3/3.1/main.zig new file mode 100644 index 0000000..ff0f841 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.1/main.zig @@ -0,0 +1,9 @@ +const std = @import("std"); // imports the "std" package +const ihex = @import("ihex"); // imports the "ihex" package +const tools = @import("tools.zig"); // imports the file "tools.zig" + +pub fn main() !void { + const data = try tools.loadFile("foo.ihex"); + const hex_file = try ihex.parse(data); + std.debug.print("foo.ihex = {}\n", .{hex_file}); +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.1/tools.zig b/examples/2024-01-15-zig-build-explained/part3/3.1/tools.zig new file mode 100644 index 0000000..ffabca0 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.1/tools.zig @@ -0,0 +1,3 @@ +pub fn loadFile(str: []const u8) ![]const u8 { + return str; +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.2/build.zig b/examples/2024-01-15-zig-build-explained/part3/3.2/build.zig new file mode 100644 index 0000000..7e05107 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.2/build.zig @@ -0,0 +1,22 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "example", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + exe.linkLibC(); + exe.linkSystemLibrary("curl"); + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.2/main.zig b/examples/2024-01-15-zig-build-explained/part3/3.2/main.zig new file mode 100644 index 0000000..f331310 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.2/main.zig @@ -0,0 +1,5 @@ +const std = @import("std"); // imports the "std" package + +pub fn main() !void { + std.debug.print("hi\n", .{}); +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.3/build.zig b/examples/2024-01-15-zig-build-explained/part3/3.3/build.zig new file mode 100644 index 0000000..fd8c2a3 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.3/build.zig @@ -0,0 +1,16 @@ +const std = @import("std"); +pub fn build(b: *std.build.Builder) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "test", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + b.installArtifact(exe); + exe.linkLibC(); + exe.addIncludePath(.{ .path = "vendor/libcurl/include" }); + exe.addLibraryPath(.{ .path = "vendor/libcurl/lib" }); + exe.linkSystemLibraryName("curl"); +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.3/main.zig b/examples/2024-01-15-zig-build-explained/part3/3.3/main.zig new file mode 100644 index 0000000..f331310 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.3/main.zig @@ -0,0 +1,5 @@ +const std = @import("std"); // imports the "std" package + +pub fn main() !void { + std.debug.print("hi\n", .{}); +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.4/build.zig b/examples/2024-01-15-zig-build-explained/part3/3.4/build.zig new file mode 100644 index 0000000..64cd758 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.4/build.zig @@ -0,0 +1,16 @@ +const std = @import("std"); +pub fn build(b: *std.build.Builder) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "test", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + b.installArtifact(exe); + exe.linkLibC(); + exe.addIncludePath(.{ .path = "/usr/local/Cellar/curl/8.5.0/include" }); + exe.addLibraryPath(.{ .path = "/usr/local/Cellar/curl/8.5.0/lib" }); + exe.addObjectFile(.{ .path = "/usr/local/Cellar/curl/8.5.0/lib/libcurl.a" }); +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.4/main.zig b/examples/2024-01-15-zig-build-explained/part3/3.4/main.zig new file mode 100644 index 0000000..f331310 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.4/main.zig @@ -0,0 +1,5 @@ +const std = @import("std"); // imports the "std" package + +pub fn main() !void { + std.debug.print("hi\n", .{}); +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.5/build.zig b/examples/2024-01-15-zig-build-explained/part3/3.5/build.zig new file mode 100644 index 0000000..90b2976 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.5/build.zig @@ -0,0 +1,18 @@ +const std = @import("std"); +pub fn build(b: *std.build.Builder) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "test", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + // const cmd = b.addSystemCommand(&.{ + // "flex", + // "-outfile=lines.c", + // "lines.l", + // }); + b.installArtifact(exe); + // exe.step.dependOn(&cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.5/src/main.zig b/examples/2024-01-15-zig-build-explained/part3/3.5/src/main.zig new file mode 100644 index 0000000..1269bcc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.5/src/main.zig @@ -0,0 +1,10 @@ +const std = @import("std"); + +pub fn main() !void { + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + try bw.flush(); // don't forget to flush! +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.6/build.zig b/examples/2024-01-15-zig-build-explained/part3/3.6/build.zig new file mode 100644 index 0000000..02ce654 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.6/build.zig @@ -0,0 +1,15 @@ +const std = @import("std"); +pub fn build(b: *std.build.Builder) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "test", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + b.installArtifact(exe); + const cmd = b.addSystemCommand(&.{"size"}); + cmd.addArtifactArg(exe); + b.getInstallStep().dependOn(&cmd.step); +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.6/main.zig b/examples/2024-01-15-zig-build-explained/part3/3.6/main.zig new file mode 100644 index 0000000..1269bcc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.6/main.zig @@ -0,0 +1,10 @@ +const std = @import("std"); + +pub fn main() !void { + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + try bw.flush(); // don't forget to flush! +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.7/build.zig b/examples/2024-01-15-zig-build-explained/part3/3.7/build.zig new file mode 100644 index 0000000..f1ec6e8 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.7/build.zig @@ -0,0 +1,90 @@ +const std = @import("std"); + +pub fn build(b: *std.build.Builder) void { + const mode = b.standardOptimizeOption(.{}); + // const mode = b.standardReleaseOptions(); + + const target = b.standardTargetOptions(.{}); + + // Generates the lex-based parser + const parser_gen = b.addSystemCommand(&[_][]const u8{ + "flex", + "--outfile=review-parser.c", + "review-parser.l", + }); + + // Our application + const exe = b.addExecutable(.{ + .name = "upload-review", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = mode, + }); + + { + exe.step.dependOn(&parser_gen.step); + // todo 作为译者我太难了。这个原作者没有提供各种依赖文件,我自己拼太难了,可以build通过但是无法执行通过 + // exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("review-parser.c"), .flags = &.{} }); + // todo 作为译者我太难了。这个原作者没有提供各种依赖文件,我自己拼太难了,可以build通过但是无法执行通过 + // add zig-args to parse arguments + + // const ap = b.createModule(.{ + // .source_file = .{ .path = "vendor/zig-args/args.zig" }, + // .dependencies = &.{}, + // }); + // exe.addModule("args-parser", ap); + + // add libcurl for uploading + exe.addIncludePath(std.build.LazyPath.relative("vendor/libcurl/include")); + // todo 作为译者我太难了。这个原作者没有提供各种依赖文件,我自己拼太难了,可以build通过但是无法执行通过 + // exe.addObjectFile(std.build.LazyPath.relative("vendor/libcurl/lib/libcurl.a")); + + exe.linkLibC(); + b.installArtifact(exe); + // exe.install(); + } + + // Our test suite + const test_step = b.step("test", "Runs the test suite"); + const test_suite = b.addTest(.{ + .root_source_file = .{ .path = "src/tests.zig" }, + }); + + test_suite.step.dependOn(&parser_gen.step); + // todo 作为译者我太难了。这个原作者没有提供各种依赖文件,我自己拼太难了,可以build通过但是无法执行通过 + // exe.addCSourceFile(.{ .file = std.build.LazyPath.relative("review-parser.c"), .flags = &.{} }); + + // add libcurl for uploading + exe.addIncludePath(std.build.LazyPath.relative("vendor/libcurl/include")); + // todo 作为译者我太难了。这个原作者没有提供各种依赖文件,我自己拼太难了,可以build通过但是无法执行通过 + // exe.addObjectFile(std.build.LazyPath.relative("vendor/libcurl/lib/libcurl.a")); + + test_suite.linkLibC(); + + test_step.dependOn(&test_suite.step); + + { + const deploy_step = b.step("deploy", "Creates an application bundle"); + + // compile the app bundler + const deploy_tool = b.addExecutable(.{ + .name = "deploy", + .root_source_file = .{ .path = "tools/deploy.zig" }, + .target = target, + .optimize = mode, + }); + + { + deploy_tool.linkLibC(); + deploy_tool.linkSystemLibrary("libzip"); + } + + const bundle_app = b.addRunArtifact(deploy_tool); + bundle_app.addArg("app-bundle.zip"); + bundle_app.addArtifactArg(exe); + bundle_app.addArg("resources/index.htm"); + bundle_app.addArg("resources/style.css"); + + deploy_step.dependOn(&bundle_app.step); + } +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.7/review-parser.c b/examples/2024-01-15-zig-build-explained/part3/3.7/review-parser.c new file mode 100644 index 0000000..b8df2cb --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.7/review-parser.c @@ -0,0 +1,1780 @@ +#line 1 "review-parser.c" + +#line 3 "review-parser.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 4 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +typedef uint64_t flex_uint64_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +/* begin standard C++ headers. */ + +/* TODO: this is always defined, so inline it */ +#define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) +#else +#define yynoreturn +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an + * integer in range [0..255] for use as an array index. + */ +#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern yy_size_t yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + yy_size_t yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ +yy_size_t yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = NULL; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart ( FILE *input_file ); +void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); +void yy_delete_buffer ( YY_BUFFER_STATE b ); +void yy_flush_buffer ( YY_BUFFER_STATE b ); +void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state ( void ); + +static void yyensure_buffer_stack ( void ); +static void yy_load_buffer_state ( void ); +static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); +#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, yy_size_t len ); + +void *yyalloc ( yy_size_t ); +void *yyrealloc ( void *, yy_size_t ); +void yyfree ( void * ); + +#define yy_new_buffer yy_create_buffer +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ +typedef flex_uint8_t YY_CHAR; + +FILE *yyin = NULL, *yyout = NULL; + +typedef int yy_state_type; + +extern int yylineno; +int yylineno = 1; + +extern char *yytext; +#ifdef yytext_ptr +#undef yytext_ptr +#endif +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state ( void ); +static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); +static int yy_get_next_buffer ( void ); +static void yynoreturn yy_fatal_error ( const char* msg ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (yy_size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; +#define YY_NUM_RULES 4 +#define YY_END_OF_BUFFER 5 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static const flex_int16_t yy_accept[19] = + { 0, + 0, 0, 5, 3, 4, 3, 3, 3, 3, 0, + 0, 0, 0, 1, 0, 2, 0, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 3, 4, 5, 1, + + 6, 1, 1, 7, 8, 1, 1, 1, 1, 1, + 9, 1, 1, 1, 1, 10, 11, 1, 1, 1, + 12, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static const YY_CHAR yy_meta[13] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1 + } ; + +static const flex_int16_t yy_base[19] = + { 0, + 0, 0, 23, 24, 24, 10, 13, 12, 14, 12, + 15, 9, 13, 24, 11, 24, 2, 24 + } ; + +static const flex_int16_t yy_def[19] = + { 0, + 18, 1, 18, 18, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 0 + } ; + +static const flex_int16_t yy_nxt[37] = + { 0, + 4, 5, 4, 6, 4, 4, 7, 4, 8, 9, + 4, 4, 13, 17, 16, 15, 14, 13, 12, 11, + 11, 10, 18, 3, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18 + } ; + +static const flex_int16_t yy_chk[37] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 17, 15, 13, 12, 11, 10, 9, 8, + 7, 6, 3, 18, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "review-parser.l" +#line 2 "review-parser.l" + + #include + #include "y.tab.h" + +#line 457 "review-parser.c" +#line 458 "review-parser.c" + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals ( void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy ( void ); + +int yyget_debug ( void ); + +void yyset_debug ( int debug_flag ); + +YY_EXTRA_TYPE yyget_extra ( void ); + +void yyset_extra ( YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in ( void ); + +void yyset_in ( FILE * _in_str ); + +FILE *yyget_out ( void ); + +void yyset_out ( FILE * _out_str ); + + yy_size_t yyget_leng ( void ); + +char *yyget_text ( void ); + +int yyget_lineno ( void ); + +void yyset_lineno ( int _line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap ( void ); +#else +extern int yywrap ( void ); +#endif +#endif + +#ifndef YY_NO_UNPUT + + static void yyunput ( int c, char *buf_ptr ); + +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy ( char *, const char *, int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen ( const char * ); +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus +static int yyinput ( void ); +#else +static int input ( void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + yy_size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK /*LINTED*/break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + { +#line 8 "review-parser.l" + + +#line 678 "review-parser.c" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 19 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 24 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +/* rule 1 can match eol */ +YY_RULE_SETUP +#line 10 "review-parser.l" +{return HI; } + YY_BREAK +case 2: +/* rule 2 can match eol */ +YY_RULE_SETUP +#line 11 "review-parser.l" +{return BYE;} + YY_BREAK +case 3: +YY_RULE_SETUP +#line 12 "review-parser.l" +{yyerror(); } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 14 "review-parser.l" +ECHO; + YY_BREAK +#line 757 "review-parser.c" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + yy_size_t num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + yy_size_t new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc( (void *) b->yy_ch_buf, + (yy_size_t) (b->yy_buf_size + 2) ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = NULL; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + /* "- 2" to take care of EOB's */ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + yy_state_type yy_current_state; + char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 19 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); + + YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 19 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 18); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_UNPUT + + static void yyunput (int c, char * yy_bp ) +{ + char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + yy_size_t number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return 0; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_init_buffer( YY_CURRENT_BUFFER, input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree( (void *) b->yy_ch_buf ); + + yyfree( (void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + yy_size_t num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return NULL; + + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = NULL; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer( b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (const char * yystr ) +{ + + return yy_scan_bytes( yystr, (int) strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, yy_size_t _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + yy_size_t i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = (yy_size_t) (_yybytes_len + 2); + buf = (char *) yyalloc( n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer( buf, n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yynoreturn yy_fatal_error (const char* msg ) +{ + fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + yy_size_t yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +yy_size_t yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param _line_number line number + * + */ +void yyset_lineno (int _line_number ) +{ + + yylineno = _line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param _in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * _in_str ) +{ + yyin = _in_str ; +} + +void yyset_out (FILE * _out_str ) +{ + yyout = _out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int _bdebug ) +{ + yy_flex_debug = _bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = NULL; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = NULL; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = NULL; + yyout = NULL; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer( YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, const char * s2, int n ) +{ + + int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (const char * s ) +{ + int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return malloc(size); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return realloc(ptr, size); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 14 "review-parser.l" + + +int main(void) +{ + yyparse(); + return 0; +} + +int yywrap(void) +{ + return 0; +} + +int yyerror(void) +{ + printf("Error\n"); + exit(1); +} diff --git a/examples/2024-01-15-zig-build-explained/part3/3.7/review-parser.l b/examples/2024-01-15-zig-build-explained/part3/3.7/review-parser.l new file mode 100644 index 0000000..aad41b1 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.7/review-parser.l @@ -0,0 +1,31 @@ +%{ + + #include + #include "y.tab.h" + +%} + +%% + +("hi"|"oi")"\n" {return HI; } +("tchau"|"bye")"\n" {return BYE;} +. {yyerror(); } + +%% + +int main(void) +{ + yyparse(); + return 0; +} + +int yywrap(void) +{ + return 0; +} + +int yyerror(void) +{ + printf("Error\n"); + exit(1); +} \ No newline at end of file diff --git a/examples/2024-01-15-zig-build-explained/part3/3.7/src/main.zig b/examples/2024-01-15-zig-build-explained/part3/3.7/src/main.zig new file mode 100644 index 0000000..1269bcc --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/3.7/src/main.zig @@ -0,0 +1,10 @@ +const std = @import("std"); + +pub fn main() !void { + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + try bw.flush(); // don't forget to flush! +} diff --git a/examples/2024-01-15-zig-build-explained/part3/part.sh b/examples/2024-01-15-zig-build-explained/part3/part.sh new file mode 100755 index 0000000..83ee481 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/part3/part.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +echo "Run Part..." +DIR="$(dirname "$(realpath "$0")")" +for ex in `ls -d */`;do + echo "Run example ${ex}..." + cd ${DIR}/${ex} + if [ -f build.zig ]; then + zig build --summary none + fi +done diff --git a/examples/2024-01-15-zig-build-explained/readme.md b/examples/2024-01-15-zig-build-explained/readme.md new file mode 100644 index 0000000..4d31ad7 --- /dev/null +++ b/examples/2024-01-15-zig-build-explained/readme.md @@ -0,0 +1,7 @@ +# 代码说明 + +1. 本目录内代码为`Zig构建系统解析`系列文章的配套代码,这些配套代码都是可以通过`$zig build`以及`zig build run`来构建和运行的 +2. `Zig构建系统解析`共三个部分,配套代码分别在三个子目录内,分别为`part1`,`part2`,`part3`内 +3. 文章发内的代码段都有编号,编号在代码块的第一行的标注内,此编号对应代码工程文件的目录,比如代码编号为1.1的,对于的代码在`part1/1.1` +4. 每一个代码块的对应工程目录内都有一个`build.zig`文件,当你看到此文件,就意味着可以使用`$zig build run`命令来构建并运行 +5. 此`build.zig`依赖的zig文件,c文件,m文件等都在对应目录之内,可以查看`build.zig`了解工程依赖的文件清单