Skip to content

Instantly share code, notes, and snippets.

@wincentbalin
Last active May 13, 2018 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wincentbalin/9cd38a993c1a7582b49db3781ba94e80 to your computer and use it in GitHub Desktop.
Save wincentbalin/9cd38a993c1a7582b49db3781ba94e80 to your computer and use it in GitHub Desktop.
How to compile gcrtraining tools for win32
# Install pre-requisites (pango is needed for xheights)
sudo apt install build-essential libpango1.0-dev
# Clone gcrtraining repository
git clone https://ancientgreekocr.org/grctraining.git
# Compile LibUTF
cd grctraining/tools/libutf
make CFLAGS="-ansi -pedantic -O2 -Wall -Wextra"
cd ..
# Compile tools
for f in *.c
do
gcc -ansi -pedantic -O2 -Wall -Wextra -s -o `basename $f .c` $f -L libutf -lutf $(pkg-config --cflags --libs pangocairo)
done
/* See LICENSE file for copyright and license details. */
#define usage "utf8only\n\n" \
"Outputs only the lines from stdin which contain exclusively\n" \
"UTF-8 encoded Cuneiform characters (see the ranges[] array\n" \
"for the characters this refers to).\n"
#include <stdio.h>
#include "libutf/utf.h"
#define LENGTH(X) (sizeof X / sizeof X[0])
typedef struct {
unsigned int start;
unsigned int end;
} Range;
static const Range ranges[] = {
{ 0x12000, 0x123FF }, /* Cuneiform */
{ 0x12400, 0x1247F }, /* Cuneiform Numbers and Punctuation */
{ 0x12480, 0x1254F }, /* Early Dynastic Cuneiform */
};
int main(int argc, char *argv[]) {
unsigned int b, i, n;
unsigned int inrange, print, runenum;
char buf[BUFSIZ];
Rune rune;
if(argc != 1) {
fputs("usage: " usage, stdout);
return 1;
}
while(fgets(buf, BUFSIZ, stdin)) {
runenum = utflen(buf);
print = 1;
for(i = 0, b = 0; i < runenum; i++) {
b += chartorune(&rune, buf + b);
if(rune == '\n' || rune == ' ') {
break;
}
inrange = 0;
for(n = 0; n < LENGTH(ranges); n++) {
if(rune >= ranges[n].start && rune <= ranges[n].end) {
inrange = 1;
}
}
if(!inrange) {
print = 0;
}
}
if(print) {
fputs(buf, stdout);
}
}
return 0;
}
@wincentbalin
Copy link
Author

wincentbalin commented May 13, 2018

If you should need the gcrtraining tools under win32, you might compile them using MXE. On condition that MXE is installed in /opt/mxe, you will compile libutf first with

make CC=/opt/mxe/usr/bin/i686-w64-mingw32.static-gcc CFLAGS="-ansi -pedantic -O2 -Wall -Wextra"

and then compile all the tools with

for f in *.c
do
    /opt/mxe/usr/bin/i686-w64-mingw32.static-gcc -ansi -pedantic -O2 -Wall -Wextra -s -o `basename $f .c`.exe $f -L libutf -lutf -Drandom=rand -mms-bitfields -DPCRE_STATIC -I/opt/mxe/usr/i686-w64-mingw32.static/include/pango-1.0 -I/opt/mxe/usr/i686-w64-mingw32.static/include/harfbuzz -I/opt/mxe/usr/i686-w64-mingw32.static/include/pango-1.0 -I/opt/mxe/usr/i686-w64-mingw32.static/include/cairo -I/opt/mxe/usr/i686-w64-mingw32.static/include/glib-2.0 -I/opt/mxe/usr/i686-w64-mingw32.static/lib/glib-2.0/include -I/opt/mxe/usr/i686-w64-mingw32.static/include -I/opt/mxe/usr/i686-w64-mingw32.static/include/pixman-1 -I/opt/mxe/usr/i686-w64-mingw32.static/include -I/opt/mxe/usr/i686-w64-mingw32.static/include/freetype2 -I/opt/mxe/usr/i686-w64-mingw32.static/include/libpng16 -I/opt/mxe/usr/i686-w64-mingw32.static/include -L/opt/mxe/usr/i686-w64-mingw32.static/lib -lpangocairo-1.0 -lpango-1.0 -lpangoft2-1.0 -lpangowin32-1.0 -lgobject-2.0 -lglib-2.0 -lintl -liconv -lcairo -lfontconfig -lfreetype -lharfbuzz -lpng -lexpat -lbz2 -lz -lmsimg32 -lgdi32 -lpixman-1 -lws2_32 -lpcre -lffi -lole32 -loleaut32 -lwinmm -lusp10
done

@wincentbalin
Copy link
Author

The file utf8cuneiformonly.c is a quick amendment of utf8greekonly.c to the Cuneiform Unicode ranges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment