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
17use LWP::Simple;
18
19if ($#ARGV < 0) {
20 print stderr "A destination file is needed\n";
21} else {
22 $destination_file=$ARGV[0];
23}
24
25sub set_indent {
26# Set indent to 4 spaces X the number of fields deep currently at.
27# $_[0] = Headed field number (not including blanks) currently being processed.
28 $new_indent=" ";
29 for ($l = 0; $l < $_[0]; $l++) {
30 $new_indent=$new_indent." ";
31 }
32 return $new_indent;
33}
34
35sub adjust_indent {
36# Pull back indent if Headed fields previous to current one haven't yet been populated.
37# $_[0] = Current indent being used which would have come from function set_indent().
38# $_[1] = Headed field number (not including blanks) currently being processed.
39 $new_indent= $_[0];
40 for ($p = 0; $p < $_[1]; $p++) {
41 if ( $fieldsWithHeadersSet[$p] eq 0 ) {
42 $new_indent = substr($new_indent, 0, -4);
43 }
44 }
45 return $new_indent;
46}
47
48sub calculateIndent {
49# Find number of indents required by matching name of fieldsWithoutLanguage to position in fieldsWithHeaders.
50 for($i = 0; $i < scalar(@fieldsWithHeaders); $i++) {
51 if ( $fieldsWithHeaders[$i] eq $fieldsWithoutLanguage[$loop] ) {
52 $indent=set_indent($i);
53 last;
54 }
55 }
56 $indent=adjust_indent($indent,$i); # Are there any empty 'headed' fields preceding this one? if so, adjust.
57}
58
59#--------------------------------------------------------------------------
60$googlePublishedDoc = 'https://docs.google.com/spreadsheet/pub?key=0Aj0jJ2rdmK_sdFdNbm45NlpNYU1PcjRmOHVXX0FNa3c&single=true&gid=0&output=txt';
61$sourceFileToRead="PackageInstallerResourceText.tsv";
62getstore ($googlePublishedDoc, $sourceFileToRead) or die "Couldn't get master file";
63#--------------------------------------------------------------------------
64
65open (FILE, "$sourceFileToRead");
66open (OUTFILE, ">$destination_file");
67
68print OUTFILE "\n"; # Output blank line.
69 # This is needed so after converting to rtf using textutil in later bash script
70 # the rtf description header appears on it's own line. For example: \f0\fs24 \cf0..
71while (<FILE>) {
72 $indent = " ";
73 chomp;
74 @fieldsReadIn = split("\t");
75 $startFirstField=substr($fieldsReadIn[0],0,1); # First charatcer of first field
76$startSecondField=substr($fieldsReadIn[1],0,1); # First charatcer of second field
77
78 if ($startFirstField ne "#" ) { # Ignore lines beginning with a hash
79 if ($startFirstField ne "") { # Check first field for language identifier.
80 print OUTFILE "language: $fieldsReadIn[0]\n"; # Output first field - LANGUAGE.
81 }
82 $headedFieldCount=0;
83 if ($startSecondField ne "") { # Check second field for language identifier.
84 print OUTFILE " file: $fieldsReadIn[1]\n"; # Output second field - FILE.
85 @fieldsWithHeaders = (); # Clear array which stores only field names with titles and NOT blanks.
86 for($i = 1; $i <= scalar(@fieldsReadIn); $i++) { # Loop through each field - ignoring first field [0].
87 @fieldsWithoutLanguage[$i]=$fieldsReadIn[$i]; # copy each field in to 'fieldsWithoutLanguage' array.
88 if ( $fieldsWithoutLanguage[$i] ne "" ) { # Check for NON-Blank fields headers
89 push(@fieldsWithHeaders, $fieldsWithoutLanguage[$i]); # Store in to 'fieldsWithHeaders' array.
90 }
91 }
92 }
93
94 for ($loop = 1; $loop < scalar(@fieldsReadIn); $loop++) {
95 if ( $fieldsReadIn[$loop] ne "" && $fieldsWithoutLanguage[$loop] ne "" ) {
96 if ( $fieldsReadIn[$loop] ne $fieldsWithoutLanguage[$loop]) {
97 $headedFieldCount++;
98 $indent=calculateIndent;
99 print OUTFILE $indent."$fieldsWithoutLanguage[$loop]: $fieldsReadIn[$loop]\n";
100 $fieldsWithHeadersSet[$headedFieldCount]=1; # Set value in this array to mark that we've written to it.
101 }
102 }
103 }
104 }
105}
106close (FILE);
107close (OUTFILE);
108exit;

Archive Download this file

Revision: 1833