Add perl emoji generation as option instead of python

v1
Tony Olagbaiye 7 years ago
parent 3e0cd6e8d5
commit c1e7e096d0
No known key found for this signature in database
GPG Key ID: 7420820577A31D11

@ -7,7 +7,7 @@ endif
RM=rm -f
CFLAGS+=$(DBGCFLAGS) -fno-omit-frame-pointer -fPIC -std=gnu99 -g -Wall -Wextra -Werror-implicit-function-declaration -Wno-missing-field-initializers -Ilibwebsockets/include -Ijson-c
LDFLAGS+=-shared -g $(DBGCFLAGS) $(DBGLDFLAGS)
LDLIBS=-Wl,--push-state,--as-needed -lgnutls
LDLIBS=-lgnutls
PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib
@ -47,8 +47,15 @@ all: libwebsockets/lib/libwebsockets.a json-c/libjson-c.a weechat-slack
weechat-slack: $(OBJS)
$(CXX) $(LDFLAGS) -o slack.so $(OBJS) $(LDLIBS)
ifeq ($(shell which python),)
slack-emoji.inc: slack-emoji.pl
cpan LWP::Simple
cpan JSON
perl slack-emoji.pl > slack-emoji.inc
else
slack-emoji.inc: slack-emoji.py
env python3 slack-emoji.py > slack-emoji.inc
endif
libwebsockets/lib/libwebsockets.a:
cd libwebsockets && env CFLAGS= LDFLAGS= cmake -DLWS_STATIC_PIC=ON -DLWS_WITH_SHARED=OFF -DLWS_WITHOUT_TESTAPPS=ON -DLWS_WITH_LIBEV=OFF -DLWS_WITH_LIBUV=OFF -DLWS_WITH_LIBEVENT=OFF -DCMAKE_BUILD_TYPE=DEBUG .

3
debian/control vendored

@ -6,7 +6,8 @@ Build-Depends:
cmake, pkg-config,
debhelper (>= 11),
libssl-dev,
libgnutls28-dev
libgnutls28-dev,
perl
Standards-Version: 4.0.0
Homepage: https://weechat.org/
Vcs-Git: https://github.com/bqv/weechat-slack.git

@ -0,0 +1,80 @@
#!/usr/bin/perl -l
use strict;
use warnings;
use LWP::Simple;
use Data::Dumper;
use JSON qw (decode_json);
use List::Util qw (max);
our ($json, @array);
$json = get('https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json');
@array = @{ decode_json($json) };
my $maxtexts = max (map { 1 + @{$_} } (grep defined, map { $_->{'texts'} } @array));
my $maxnames = max (map { 1 + @{$_} } (grep defined, map { $_->{'short_names'} } @array));
print "
#include <stdlib.h>
#define MAX_TEXTS $maxtexts
#define MAX_NAMES $maxnames
struct t_slack_emoji_by_name {
const char *name;
const char *unicode;
const char *text_to;
const char *text_from[MAX_TEXTS];
};
struct t_slack_emoji_by_text {
const char *text;
const char *unicode;
const char *name_to;
const char *name_from[MAX_NAMES];
};
";
print "static struct t_slack_emoji_by_name slack_emoji_by_name[] =";
my $c = '{';
my %byname = map { my $o = $_; map {($_, $o)} @{$o->{'short_names'}} } @array;
my @sortedbyname = sort { $a cmp $b } keys %byname;
foreach my $name (@sortedbyname)
{
my $_0 = "\"$name\"";
my @_1 = split /-/, $byname{$name}->{'unified'};
my $_1 = "\"";
foreach my $codepoint (@_1) { $_1 .= "\\u$codepoint" };
$_1 .= "\"";
my $_2 = $byname{$name}->{'text'};
if (defined $_2) { $_2 = "\"$_2\"" } else { $_2 = "NULL" };
my $_3 = "{";
foreach my $text (@{$byname{$name}->{'texts'}}) { if (defined $text) { $_3 .= "\"$text\", " } };
$_3 .= "NULL}";
print "$c { $_0, $_1, $_2, $_3 }";
$c = ',';
}
print "};";
print "";
print "static struct t_slack_emoji_by_text slack_emoji_by_text[] =";
$c = '{';
my %bytext = map { my $o = $_; map {($_, $o)} @{$o->{'texts'}} } @array;
my @sortedbytext = sort { $a cmp $b } keys %bytext;
foreach my $text (@sortedbytext)
{
my $_0 = "\"$text\"";
my @_1 = split /-/, $bytext{$text}->{'unified'};
my $_1 = "\"";
foreach my $codepoint (@_1) { $_1 .= "\\u$codepoint" };
$_1 .= "\"";
my $_2 = $bytext{$text}->{'short_name'};
if (defined $_2) { $_2 = "\"$_2\"" } else { $_2 = "NULL" };
my $_3 = "{";
foreach my $name (@{$bytext{$text}->{'short_names'}}) { if (defined $name) { $_3 .= "\"$name\", " } };
$_3 .= "NULL}";
print "$c { $_0, $_1, $_2, $_3 }";
$c = ',';
}
print "};";

@ -1,4 +1,5 @@
#!/usr/bin/env python3
#!/usr/bin/python
# Compatible with python v2 and v3
import requests
import json

Loading…
Cancel
Save