Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorial/xaf2cat
blob: e50abd75cc331c50d9c8bb8f6f6cefb8a1790107 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
if [ $# != 1 ]; then
    echo "xaf2cat converts .xaf to .cat file format and reconstructs .xaf"
    echo "Usage: xaf2cat [ filename.xaf | -h ]"
    exit 1
    fi

if [ "$1" = "-h" ]; then
 echo "This tool helps you create language independent .xaf files."
 echo "The texts from the .xaf file will be copied into all .cat files."
 echo "All texts in the .xaf file will be pointered to the .cat files."
 echo "You have to write your own descriptions for the .xaf tutorial file"
 echo "into the .cat files for each language."
 echo ""
 echo "The usage of this tool is quite straightforward, but unfortunately"
 echo "it has a serious bug: it cannot handle multiline texts correctly."
 echo "Keep this bug in mind or write a better script which will solve"
 echo "this problem."
 exit 1
 fi    

test -r $1 || {
    echo "$1 is missing"
    exit 1
    }
export BASENAME=`basename $1 .xaf`
cp $1 $1.orig
echo "$1.orig file as backup was created."
OUTPUTFILE=$BASENAME.cat

echo "
##############################################
#for file $1
" > $OUTPUTFILE

cat $1 | grep "text " | sed s/"(text "/""/g | sed s/"\")"/"\""/g |\
 sed s/" \"$"/"\""/g | awk '{x++; print ENVIRON["BASENAME"] x " " $0}' \
 >> $OUTPUTFILE
 
cat $OUTPUTFILE
echo -n "^- This is the output. Do you want to append it to ../catalogs/*.cat? [Y/n] "
read A
if [ "$A" != "n" ]; then
 for i in ../catalogs/*.cat; do
  cat $OUTPUTFILE >> $i
  echo -n "$i, "
  done
 echo "done."
 fi

echo -n "Shall I create 'message' commands instead of 'text's in $1? [Y/n] "
read A
if [ "$A" != "n" ]; then
 cat $1 | sed s/"(text "/"(message "/g |\
  sed s/" \"$"/"\""/g | awk '
  {
   if (index($0,"(message ")==1)
    {
     x++
     l=length($0)
     print "(message ~" ENVIRON["BASENAME"] x "~)"
    }
   else print $0
  }' | sed s/"~"/"\""/g \
  > $1.work
 
 cat $1.work
 echo -n "^- This is the new $1 file. Do you want to save it? [Y/n] "
 read A
 if [ "$A" != "n" ]; then
  cp $1.work $1
  echo "Done."
  fi
 fi

echo -n "Cleanup? [Y/n] "
read A
if [ "$A" != "n" ]; then
 rm -f $1.work $1.orig $OUTPUTFILE
 echo "Cleanup done."
 fi

echo "Exiting."