diff options
author | nalin <nalin> | 2001-04-02 15:03:55 +0000 |
---|---|---|
committer | nalin <nalin> | 2001-04-02 15:03:55 +0000 |
commit | 95f9b90d2d81c897a99a13336dbdaf6354ee2c6b (patch) | |
tree | d47ad9cd1cc4606e50dc9230a3ca957bfc0fb5fb | |
download | pomatic-95f9b90d2d81c897a99a13336dbdaf6354ee2c6b.tar.gz pomatic-95f9b90d2d81c897a99a13336dbdaf6354ee2c6b.tar.xz pomatic-95f9b90d2d81c897a99a13336dbdaf6354ee2c6b.zip |
pomatic initial check-in
-rw-r--r-- | Makefile | 24 | ||||
-rwxr-xr-x | convert-locale | 61 | ||||
-rw-r--r-- | pomatic.1 | 25 | ||||
-rw-r--r-- | pomatic.spec | 35 | ||||
-rw-r--r-- | pomatic.x | 127 |
5 files changed, 272 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bd28d0d --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +.SUFFIXES: .x .c .o +bindir=/usr/bin +libdir=/usr/lib +mandir=/usr/share/man + +all: pomatic + +CFLAGS=-ggdb -Wall +LDFLAGS=-lfl + +.o: + $(CC) -o $@ $^ $(LDFLAGS) + +.c.o: + $(CC) -o $@ $(CFLAGS) -c $^ + +.x.c: + flex -o$@ $^ + +install: all + mkdir -p $(DESTDIR)$(bindir) + mkdir -p $(DESTDIR)$(mandir)/man1 + install -m755 pomatic convert-locale $(DESTDIR)$(bindir)/ + install -m644 pomatic.1 $(DESTDIR)$(mandir)/man1 diff --git a/convert-locale b/convert-locale new file mode 100755 index 0000000..39dc3a2 --- /dev/null +++ b/convert-locale @@ -0,0 +1,61 @@ +#!/bin/bash + +SOURCELOCALEDIR=/usr/share/locale +DESTLOCALEDIR=$DESTDIR/usr/share/locale +LIBLOCALEDIR=$DESTDIR/usr/lib/locale + +SOURCELOCALE=de +DESTLOCALES= + +while [ $# -gt 0 ] ; do + case $1 in + --source) + shift + SOURCELOCALE=$1 + shift + ;; + *) + DESTLOCALES="$DESTLOCALES $1" + shift + ;; + esac +done + +if [ -z "$DESTLOCALES" ] ; then + echo Usage: `basename $0` '[--source sourcelocale]' 'destlocale [...]' +fi + +messagedir=$SOURCELOCALEDIR/$SOURCELOCALE/LC_MESSAGES + +for DESTLOCALE in $DESTLOCALES ; do + aliasfile=/usr/X11R6/lib/X11/locale/locale.alias + alias=`basename $DESTLOCALE` + + echo Converting strings from $SOURCELOCALE using $alias. + + test -d $LIBLOCALEDIR || mkdir -p $LIBLOCALEDIR + test -d $DESTLOCALEDIR/$alias/LC_MESSAGES || \ + mkdir -p $DESTLOCALEDIR/$alias/LC_MESSAGES + + test -d $LIBLOCALEDIR/$alias/LC_MESSAGES || \ + ln -s /usr/lib/locale/en_US $LIBLOCALEDIR/$alias + + sources=`find $messagedir -type f -name "*.mo" | sort` + + for source in $sources ; do + domain=`basename $source .mo` + echo " $domain" + target=$DESTLOCALEDIR/$alias/LC_MESSAGES/$domain.mo + TMP1=`mktemp /tmp/convert${domain}XXXXXX` + TMP2=`mktemp /tmp/convert${domain}XXXXXX` + msgunfmt $source > $TMP1 + pomatic $TMP1 $DESTLOCALE > $TMP2 + msgfmt -o $target $TMP2 + rm $TMP1 $TMP2 + done + echo + + if ! grep -q ^$alias: $aliasfile ; then + echo $alias: en_US.ISO8859-1 >> $aliasfile + fi +done diff --git a/pomatic.1 b/pomatic.1 new file mode 100644 index 0000000..70ec5e4 --- /dev/null +++ b/pomatic.1 @@ -0,0 +1,25 @@ +.TH POMATIC 1 +.SH NAME +pomatic \- convert a .pot file to a fake locale +.SH SYNOPSIS +.B pomatic +.RB [ \-s ] +.RB [ path ] +.RB [ filter ] +.SH DESCRIPTION +.I pomatic +runs strings from a POT file through an arbitrary filter, outputting a +modified POT file on standard out. +.SH "OPTIONS" +.TP +.BI \-s +Generate new strings using the \fBmsgstr\fP entries. The default is to +pipe the \fBmsgid\fP strings through the filter. +.SH "EXAMPLES" +The simplest example: +.IP +\fCpomatic program.po /bin/cat\fP +.LP +creates a mostly-identical copy of program.po. +.SH "SEE ALSO" +cat(1) diff --git a/pomatic.spec b/pomatic.spec new file mode 100644 index 0000000..24aef1f --- /dev/null +++ b/pomatic.spec @@ -0,0 +1,35 @@ +Name: pomatic +Version: 1.0 +Release: 1 +Source: %{name}-%{version}.tar.gz +Summary: pomatic +Group: Applications/Text +License: GPL +BuildRoot: %{_tmppath}/%{name}-root +BuildPrereq: talkfilters +Requires: talkfilters + +%description +pomatic + +%prep +%setup -q + +%build +make + +%install +rm -fr $RPM_BUILD_ROOT +make install DESTDIR=$RPM_BUILD_ROOT + +%clean +rm -fr $RPM_BUILD_ROOT + +%files +%defattr(-,root,root) +%{_bindir}/* +%{_mandir}/*/* + +%changelog +* Mon Apr 2 2001 Nalin Dahyabhai <nalin@redhat.com> +- initial CVS checkin diff --git a/pomatic.x b/pomatic.x new file mode 100644 index 0000000..96c3e3e --- /dev/null +++ b/pomatic.x @@ -0,0 +1,127 @@ +%{ + +#include <stdio.h> +#include <unistd.h> +#include <errno.h> +#include <string.h> + +char message[32768]; +enum {id, str} string = id, mode = id; +char *msgid = NULL, *msgstr = NULL; +char *filter = "cat"; + +%} + +%% + +[ \t]+ {}; +^#.* {}; +^msgid { + if(string == str) { + if(msgid) { + printf("msgid %s", msgid); + } else { + printf("msgid \"\"\n"); + } + if ( ((mode == id) && msgid) || ((mode == str) && msgstr) ) { + int i, ipipe[2], opipe[2]; + pid_t childpid; + FILE *msgpipe; + char *text = (mode == id) ? msgid : msgstr; + + pipe(ipipe); + pipe(opipe); + childpid = fork(); + + if(childpid == 0) { + /* child */ + dup2(ipipe[0], STDIN_FILENO); + close(ipipe[1]); + close(opipe[0]); + dup2(opipe[1], STDOUT_FILENO); + exit(execlp(filter, filter, NULL)); + } + + close(ipipe[0]); + close(opipe[1]); + + write(ipipe[1], text, strlen(text)); + close(ipipe[1]); + msgpipe = fdopen(opipe[0], "r"); + + printf("msgstr \"\"\n"); + while(fgets(message, sizeof(message), msgpipe)) { + for(i = 0; message[i]; i++) { + if(i > 0) + if(message[i] == '"') + if(message[i - 1] != '\\') + if(message[i - 1] != '\n') + if(message[i + 1] != '\n') + fputc('\\', stdout); + fputc(message[i], stdout); + } + } + waitpid(childpid, NULL, 0); + fclose(msgpipe); + } + + if(msgid) + free(msgid); + msgid = NULL; + + if(msgstr) + free(msgstr); + msgstr = NULL; + } + string = id; +}; +^msgstr { + string = str; +}; +\".*\"\n { + char *tmp; + char **target = NULL; + if(string == str) { + target = &msgstr; + } else { + target = &msgid; + } + tmp = malloc((*target ? strlen(*target) : 0) + strlen(yytext) + 1); + strcpy(tmp, *target ? *target : ""); + strcat(tmp, yytext); + free(*target); + *target = tmp; +}; + +%% + +int +main(int argc, char **argv) +{ + int base = 0; + yyin = stdin; + if(argc == 1) { + printf("Usage: %s [-s] [potfile] [filter]\n", + strrchr(argv[0], '/') ? + strrchr(argv[0], '/') + 1 : + argv[0]); + return 1; + } + if(argc > 1) { + if(strcmp(argv[1], "-s") == 0) { + mode = str; + base++; + } + } + if(argc > base + 1) { + yyin = fopen(argv[base + 1], "r"); + } + if(argc > base + 2) { + filter = argv[base + 2]; + } + + while(yyin && !feof(yyin)) + yylex(); + + return 0; +} |