toxcore/other/make_single_file
iphydf de4af4c270
feat: Add async event handling (callbacks) code.
Instead of synchronously handling events as they happen in
`tox_iterate`, this first collects all events in a structure and then
lets the client process them. This allows clients to process events in
parallel, since the data structure returned is mostly immutable.

This also makes toxcore compatible with languages that don't (easily)
support callbacks from C into the non-C language.

If we remove the callbacks, this allows us to add fields to the events
without breaking the API.
2022-02-06 17:28:28 +00:00

57 lines
1.2 KiB
Perl
Executable File

#!/usr/bin/env perl
#
# This script can be used to create a single .c file with all of toxcore in it
# as well as your code or test file. It does not depend on any header files
# anymore, as those are emitted directly into the .c file.
#
# Example:
#
# other/make_single_file testing/misc_tools.c auto_tests/send_message_test.c | \
# tcc -o send_message_test - $(pkg-config --cflags --libs libsodium opus vpx)
use strict;
use warnings;
use Cwd 'abs_path';
sub relative_to {
my ($rel, $fn) = @_;
my @path = split "/", $rel;
pop @path;
abs_path(join "/", @path, $fn)
}
my %seen;
sub emit {
my ($fn) = @_;
return if $seen{$fn};
$seen{$fn} = 1;
open my $fh, "<", $fn or die "$fn: $!";
my $line = 1;
print "#line $line \"$fn\"\n";
while (<$fh>) {
if (/^#include "([^"]*)"/) {
emit(relative_to($fn, $1), $1);
++$line;
print "#line $line \"$fn\"\n";
} else {
print;
++$line;
}
}
}
if (@ARGV and $ARGV[0] eq "-core") {
shift @ARGV;
for my $fn (<toxcore/*.c>) {
emit(abs_path $fn);
}
} else {
for my $fn (<toxav/*.c>, <toxcore/*.c>, <toxcore/*/*.c>, <toxencryptsave/*.c>) {
emit(abs_path $fn);
}
}
emit(abs_path $_) for @ARGV;