
| The Following User Says Thank You to ctennenh For This Useful Post: | ||
#!/bin/sh
# Converts cedict to English -> Chinese babylon file
# using cedict_1_0_ts_utf8_mdbg. Use stardict-tools
# to convert $OUTFILE to stardict format.
CEDICT_FILE=$1
OUTFILE=$2
COUNTER=35
ENDLINE=`cat $CEDICT_FILE | wc -l`
touch $OUTFILE
while [ $COUNTER -le $ENDLINE ]
do
WLINE=`sed -n ${COUNTER}p $CEDICT_FILE`
echo $WLINE | sed 's/.* \///' | sed 's/\/.$//' | tr "/" "|" >> $OUTFILE
echo $WLINE | awk -F / '{print $1 "\n"}' >> $OUTFILE
((COUNTER++))
done
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 300
int parser(char string[])
{
int c, i;
for (i=0; i < MAX && (c=getchar()) != EOF && c != '\n'; ++i)
string[i] = c;
if (c == '\n') {
string[i] = c;
++i;
}
string[i] = '\0';
return i;
}
int split(const char src[], char prt[], int del, int idx)
{
int i = 0, j = 0;
if (!idx) {
while ((prt[j++] = src[i++]) != '\0' && src[i] != '\n' && src[i] != del && i < MAX);
prt[i] = '\0';
}
else {
int n = 0;
while (src[i++] != '\0' && src[i] != '\n' && i < MAX) {
if (src[i] == del) {
if (++n == idx) {
i++;
while ((prt[j++]=src[i++]) != '\0' && src[i] != '\n' && src[i] != del && i < MAX);
prt[j] = '\0';
}
}
}
}
return j;
}
int get_range(const char *str, int del) {
int i=0, j = 0;
while (*str++ != '\0' && i++ < MAX) {
if (*str == del)
j++;
}
return j;
}
int main()
{
char prt[300], def[300], line[300];
int i, j, len, range;
while ((len = parser(line)) > 0) {
range = get_range(line, '/');
j = split(line, def, '/', 0);
for (i=1; i < range; i++) {
j = split(line, prt, '/', i);
printf("%s\t%s\n", prt, def);
}
}
return 0;
}
cc ce2ec.c cat cedict_ts.u8 | ./a.out > ecdict.tab sudo apt-get install stardict-tools /usr/lib/stardict-tools/tabfile ecdict.tab sudo mkdir /usr/share/stardict/dic/ecdict sudo mv ecdict.* /usr/share/stardict/dic/ecdict sudo -hr root:root /usr/share/stardict/dic/ecdict stardict echo 'Everything should be just ok xD';
| The Following User Says Thank You to s331234 For This Useful Post: | ||