Internationalization: Translation Tables Update.
[openemr.git] / contrib / util / language_translations / sortCleanList.pl
blob8757e65989a1d754d6776bb1441fc2655d3b138c
1 #!/usr/bin/perl
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # author Brady Miller
9 # email brady@sparmy.com
10 # date 05/21/09
12 # This is a perl script that will simply sort and remove redundant entries
13 # from a list to maintain the manuallyAddedConstants.txt and the
14 # manuallyRemovedConstants.txt files.
16 # Example command:
18 # -Below command will simply sort and remove redundant entries from a list:
19 # ./sortCleanList.pl manuallyAddedConstants.txt
23 use strict;
25 my $inputFile;
26 my $logFile = "log.txt";
27 my $filenameOut = "list.txt";
29 # check parameter
30 if (@ARGV > 1) {
31 die "\nERROR: Too many parameters. Follow instructions found in sortCleanList.pl file.\n\n";
33 elsif (@ARGV < 1) {
34 die "\nERROR: Not enough parameters. Follow instructions found in sortCleanList.pl file.\n\n";
36 elsif (@ARGV == 1) {
37 $inputFile = $ARGV[0];
39 else {
40 die "\nERROR: Problem with parameters. Follow instructions found in sortCleanList.pl file.\n\n";
43 # open log file and output file
44 open(LOGFILE, ">$logFile") or die "unable to open log file";
45 open(OUTPUTFILE, ">$filenameOut") or die "unable to open output file";
47 # if comparing, then open input file and store in array
48 open(MYINPUTFILE, "<$inputFile") or die "unable to open file";
49 my @inputList = <MYINPUTFILE>;
50 close(MYINPUTFILE);
52 # remove blankl lines, windows characters, and chomp it
53 my @processInputList1;
54 foreach my $var (@inputList) {
55 chomp($var);
56 # remove ^M characters (windows line feeds)
57 $var =~ s/\r//g;
58 # skip blank lines
59 if ($var eq "") {
60 next;
62 # push into new array
63 push(@processInputList1,$var);
66 # remove redundancies
67 my @processInputList2;
68 foreach my $var (@processInputList1) {
69 if (withinArray($var,@processInputList2)) {
70 print LOGFILE "Redundant variable removed: " . $var . "\n";
72 else {
73 push (@processInputList2, $var);
77 # sort list
78 my @sortedInputList = sortConstants(@processInputList2);
80 # output to file
81 foreach my $var (@sortedInputList) {
82 print OUTPUTFILE $var . "\n";
85 # close files
86 close(LOGFILE);
87 close(OUTPUTFILE);
91 # FUNCTIONS
94 # function to sort constant list
95 # param - @arr
96 # return - @arr
98 sub sortConstants {
99 my(@arr) = @_;
100 my @first;
101 my @last;
103 foreach my $var (@arr) {
104 if ($var =~ /^[a-z]/i) {
105 push (@first,$var);
107 else {
108 push (@last,$var);
112 my @sortFirst = sort { lc($a) cmp lc($b) } @first;
113 my @sortLast = sort { lc($a) cmp lc($b) } @last;
115 push (@sortFirst, @sortLast);
116 my @sorted_arr = @sortFirst;
118 return @sorted_arr;
123 # function to return whether a variable is in an array
124 # param - $variable @arr
125 # return - 1(true) or 0(false) integer
127 sub withinArray {
128 my($variable,@arr) = @_;
129 my $isMatch = 0;
130 foreach my $tempVar (@arr) {
131 if ($tempVar eq $variable) {
132 $isMatch = 1;
133 last;
136 return $isMatch;