Chameleon

Chameleon Svn Source Tree

Root/branches/blackosx/package/Resources.source/ConvertResourcesTextFile.pl

  • Property svn:executable set to *
1#!/usr/bin/perl
2
3# This script converts a human readable file for all the
4# language 'Resources' for the Chameleon package installer
5# in to a simple format ready for merging with pre-defined
6# templates during compilation.
7#
8# The human readable file is hosted on Google Docs at:
9# www.......
10# The file should be saved from Google Docs by using:
11# File -> Download As -> Text (current sheet)
12#
13# This saves a UTF-8, tabbed delimited text file which
14# should be placed in the same folder as this script.
15#
16
17if ($#ARGV < 0) {
18 print stderr "A destination file is needed\n";
19} else {
20 $destination_file=$ARGV[0];
21}
22
23sub set_indent {
24# Set indent to 4 spaces X the number of fields deep currently at.
25# $_[0] = Headed field number (not including blanks) currently being processed.
26 $new_indent=" ";
27 for ($l = 0; $l < $_[0]; $l++) {
28 $new_indent=$new_indent." ";
29 }
30 return $new_indent;
31}
32
33sub adjust_indent {
34# Pull back indent if Headed fields previous to current one haven't yet been populated.
35# $_[0] = Current indent being used which would have come from function set_indent().
36# $_[1] = Headed field number (not including blanks) currently being processed.
37 $new_indent= $_[0];
38 for ($p = 0; $p < $_[1]; $p++) {
39 if ( $fieldsWithHeadersSet[$p] eq 0 ) {
40 $new_indent = substr($new_indent, 0, -4);
41 }
42 }
43 return $new_indent;
44}
45
46sub calculateIndent {
47# Find number of indents required by matching name of fieldsWithoutLanguage to position in fieldsWithHeaders.
48 for($i = 0; $i < scalar(@fieldsWithHeaders); $i++) {
49 if ( $fieldsWithHeaders[$i] eq $fieldsWithoutLanguage[$loop] ) {
50 $indent=set_indent($i);
51 last;
52 }
53 }
54 $indent=adjust_indent($indent,$i); # Are there any empty 'headed' fields preceding this one? if so, adjust.
55}
56
57#--------------------------------------------------------------------------
58$sourceFileToRead="Package%20Installer%20Resource%20Text%20-%20Sheet1.tsv";
59#--------------------------------------------------------------------------
60
61open (FILE, "$sourceFileToRead");
62open (OUTFILE, ">$destination_file");
63
64print OUTFILE "\n"; # Output blank line.
65 # This is needed so after converting to rtf using textutil in later bash script
66 # the rtf description header appears on it's own line. For example: \f0\fs24 \cf0..
67while (<FILE>) {
68 $indent = " ";
69 chomp;
70 @fieldsReadIn = split("\t");
71 $startFirstField=substr($fieldsReadIn[0],0,1); # First charatcer of first field
72$startSecondField=substr($fieldsReadIn[1],0,1); # First charatcer of second field
73
74 if ($startFirstField ne "#" ) { # Ignore lines beginning with a hash
75 if ($startFirstField ne "") { # Check first field for language identifier.
76 print OUTFILE "language: $fieldsReadIn[0]\n"; # Output first field - LANGUAGE.
77 }
78 $headedFieldCount=0;
79 if ($startSecondField ne "") { # Check second field for language identifier.
80 print OUTFILE " file: $fieldsReadIn[1]\n"; # Output second field - FILE.
81 @fieldsWithHeaders = (); # Clear array which stores only field names with titles and NOT blanks.
82 for($i = 1; $i <= scalar(@fieldsReadIn); $i++) { # Loop through each field - ignoring first field [0].
83 @fieldsWithoutLanguage[$i]=$fieldsReadIn[$i]; # copy each field in to 'fieldsWithoutLanguage' array.
84 if ( $fieldsWithoutLanguage[$i] ne "" ) { # Check for NON-Blank fields headers
85 push(@fieldsWithHeaders, $fieldsWithoutLanguage[$i]); # Store in to 'fieldsWithHeaders' array.
86 }
87 }
88 }
89
90 for ($loop = 1; $loop < scalar(@fieldsReadIn); $loop++) {
91 if ( $fieldsReadIn[$loop] ne "" && $fieldsWithoutLanguage[$loop] ne "" ) {
92 if ( $fieldsReadIn[$loop] ne $fieldsWithoutLanguage[$loop]) {
93 $headedFieldCount++;
94 $indent=calculateIndent;
95 print OUTFILE $indent."$fieldsWithoutLanguage[$loop]: $fieldsReadIn[$loop]\n";
96 $fieldsWithHeadersSet[$headedFieldCount]=1; # Set value in this array to mark that we've written to it.
97 }
98 }
99 }
100 }
101}
102close (FILE);
103close (OUTFILE);
104exit;

Archive Download this file

Revision: 1831