1# *************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20# *************************************************************
21package ConvwatchHelper;
22
23use English;
24use warnings;
25use strict;
26use Cwd;
27use Cwd 'chdir';
28
29use CallExternals;
30use stringhelper;
31use filehelper;
32use oshelper;
33use loghelper;
34
35BEGIN {
36    use Exporter   ();
37    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
38
39    $VERSION     = 1.00;
40    # if using RCS/CVS, this may be preferred
41    $VERSION = do { my @r = (q$Revision: 1.39 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
42    @ISA         = qw(Exporter);
43    @EXPORT      = qw(&getQADEVToolsPath &setProjectRoot &getProjectRoot &checkForStop &getSofficeExe &setINPATH);
44    %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
45    # your exported package globals go here,
46    # as well as any optionally exported functions
47    @EXPORT_OK   = ( ); # qw($Var1 %Hashit &func3);
48}
49
50# ------------------------------------------------------------------------------
51our $tempprefix;
52
53# sub getTempDir()
54# {
55#     my $sTempDir;
56#     if (! $tempprefix)
57#     {
58#         if ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
59#         {
60#             # $tempdir = "C:/gfxcmp/temp";
61#             $tempprefix = "//so-gfxcmp-lin/gfxcmp-data/wntmsci/temp";
62#         }
63#         elsif ($OSNAME eq "linux")
64#         {
65#             $tempprefix = "/net/so-gfxcmp-lin/export/gfxcmp/data/unxlngi/temp";
66#         }
67#         elsif ($OSNAME eq "solaris")
68#         {
69#             # $tempdir = "/space/gfxcmp/temp";
70#             $tempprefix = "/net/so-gfxcmp-lin/export/gfxcmp/data/unxsoli/temp";
71#         }
72#         else
73#         {
74#             print "Error: This environment isn't supported yet.\n";
75#             exit(1);
76#         }
77#     }
78#     $sTempDir = $tempprefix;
79#     return $sTempDir;
80# }
81# ------------------------------------------------------------------------------
82# in filehelper
83# our $programprefix;
84#
85# sub getProgramPrefix($)
86# {
87#     my $sDBDistinct = shift;
88#
89#     my $sProgramPrefix;
90#     if (! $programprefix)
91#     {
92#         if ($OSNAME eq "MSWin32")
93#         {
94#             # $programprefix = "C:/gfxcmp/programs";
95#             $programprefix = "C:/gp";
96#         }
97#         elsif ($OSNAME eq "linux")
98#         {
99#             $programprefix = "/space/gfxcmp/programs";
100#         }
101#         elsif ($OSNAME eq "solaris")
102#         {
103#             $programprefix = "/space/gfxcmp/programs";
104#         }
105#         else
106#         {
107#             print "Error: This environment isn't supported yet.\n";
108#             exit(1);
109#         }
110#     }
111#     $sProgramPrefix = appendPath($programprefix, substr($sDBDistinct, 0, 19));
112#     return $sProgramPrefix;
113# }
114# ------------------------------------------------------------------------------
115sub getQADEVToolsPath()
116{
117    my $sNewPath = appendPath(getToolsPrefix(), "qadev");
118    $sNewPath = appendPath($sNewPath, "scripts");
119    $sNewPath = appendPath($sNewPath, "gfxcmp_ui");
120    return $sNewPath;
121}
122
123# in filehelper
124# our $toolsprefix;
125#
126# sub getToolsPrefix()
127# {
128#     my $sToolsPrefix;
129#     if (! $toolsprefix)
130#     {
131#         if ($OSNAME eq "MSWin32")
132#         {
133#             $toolsprefix = "C:/gfxcmp/tools";
134#         }
135#         elsif ($OSNAME eq "linux")
136#         {
137#             $toolsprefix = "/space/gfxcmp/tools";
138#         }
139#         elsif ($OSNAME eq "solaris")
140#         {
141#             $toolsprefix = "/space/gfxcmp/tools";
142#         }
143#         else
144#         {
145#             print "Error: This environment isn't supported yet.\n";
146#             exit(1);
147#         }
148#     }
149#     $sToolsPrefix = $toolsprefix;
150#     return $sToolsPrefix;
151# }
152# ------------------------------------------------------------------------------
153our $sProjectRoot;
154sub setProjectRoot($)
155{
156    $sProjectRoot = shift;
157    log_print "\$sProjectRoot := $sProjectRoot\n";
158}
159sub getProjectRoot()
160{
161    if ($sProjectRoot)
162    {
163        return $sProjectRoot;
164    }
165    die "setProjectRoot(PATH) not set.\n";
166}
167
168our $sINPATH;
169sub setINPATH($)
170{
171    $sINPATH = shift;
172}
173sub getINPATH()
174{
175    if ($sINPATH)
176    {
177        return $sINPATH;
178    }
179    die "setINPATH(PATH) not set.\n";
180}
181our $dataprefix;
182
183# sub getDataPrefix()
184# {
185#     my $sDataPrefix;
186#     if (! $dataprefix)
187#     {
188#         if ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
189#         {
190#             # $dataprefix = "C:/gfxcmp/data";
191#             # $dataprefix = "//so-gfxcmp-lin/gfxcmp-data/wntmsci";
192#             $dataprefix = getProjectRoot();
193#         }
194#         elsif ($OSNAME eq "linux")
195#         {
196#             # $dataprefix = "/space/gfxcmp/data";
197#             # $dataprefix = "/net/so-gfxcmp-lin/export/gfxcmp/data/unxlngi";
198#             $dataprefix = getProjectRoot();
199#         }
200#         elsif ($OSNAME eq "solaris")
201#         {
202#             # $dataprefix = "/space/gfxcmp/data";
203#             # $dataprefix = "/net/so-gfxcmp-lin/export/gfxcmp/data/unxsoli";
204#             $dataprefix = getProjectRoot();
205#         }
206#         else
207#         {
208#             print "Error: This environment isn't supported yet.\n";
209#             exit(1);
210#         }
211#         $dataprefix = appendPath(getProjectRoot(), getINPATH());
212#         $dataprefix = appendPath($dataprefix, "data");
213#     }
214#     $sDataPrefix = $dataprefix;
215#     return $sDataPrefix;
216# }
217
218# ------------------------------------------------------------------------------
219
220# sub _shortsleep($)
221# {
222# #    sleep 1;
223#     select(undef, undef, undef, 0.333);
224# }
225#
226# sub _waitInSeconds($)
227# {
228#     my $nLength = shift;
229#     my $i;
230#     my $j;
231#
232#     for ($j=0;$j<$nLength;$j++)
233#     {
234#         for ($i=0;$i<$j;$i++)
235#         {
236#             print ".";
237#         }
238#         for ($i=$j;$i<$nLength;$i++)
239#         {
240#             print " ";
241#         }
242#         _shortsleep( 1 );
243#         print "\r";
244#     }
245#
246#     for ($j=0;$j<=$nLength;$j++)
247#     {
248#         for ($i=0;$i<$j;$i++)
249#         {
250#             print " ";
251#         }
252#         for ($i=$j;$i<$nLength;$i++)
253#         {
254#             print ".";
255#         }
256#         _shortsleep( 1 );
257#         print "\r";
258#     }
259# }
260#
261# sub wait30seconds()
262# {
263#     _waitInSeconds(20);
264#     _waitInSeconds(20);
265# }
266
267sub checkForStop($)
268{
269    my $sStopFilename = shift;
270    my $sStopFilePath;
271    if ($OSNAME eq "MSWin32")
272    {
273        $sStopFilePath = "C:/temp/";
274    }
275    else
276    {
277        $sStopFilePath = "/tmp/";
278    }
279    my $sStopFile = $sStopFilePath . $sStopFilename;
280    if ( -e "$sStopFile" )
281    {
282        print "Stop of Convwatch tool forced!\n";
283        unlink($sStopFile);
284        exit(2);
285    }
286}
287
288# ----------------------------------------------------------------------------------------
289sub readdirectory($$$);
290
291sub readdirectory($$$)
292{
293    my $startdir = shift;
294    my $sUserParameter  = shift;
295    my $hook     = shift;
296
297    my $myfile;
298
299    local *DIR;
300    chdir $startdir;
301    cwd();
302
303    my $nCountFiles = 0;
304    if (opendir (DIR, $startdir))           # Directory oeffnen
305    {
306        while ($myfile = readdir(DIR))
307        {                                  # ein filename holen
308            #if (! -l $myfile)              # not a link
309            #{
310            if (-d $myfile ) # is a directory
311            {
312                if ( -l $myfile)
313                {
314                    next;
315                }
316                # if ( $myfile eq "help" ||
317                #      $myfile eq "presets" ||
318                #      $myfile eq "registry" ||
319                #      $myfile eq "uno_packages" ||
320                #      $myfile eq "lib" ||
321                #      $myfile eq "user_tree" )
322                # {
323                #     next;
324                # }
325
326                if ($myfile ne "." && $myfile ne "..")
327                {
328                    my $sNewStartDir = appendPath($startdir, $myfile);    # neuen Directorystring erstellen
329                    # if ($sNewStartDir =~ "^\/proc" ||
330                    #     $sNewStartDir =~ "^\/dev" ||
331                    #     $sNewStartDir =~ "^\/udev" ||
332                    #     $sNewStartDir =~ "lost+found" )
333                    # {
334                    #     next;
335                    # }
336                    # my $sNewSUserParameter  = $sUserParameter . $myfile ."/";
337                    # do a recursive call
338                    # $nCountFiles++;
339                    my $nFileCount = readdirectory($sNewStartDir, $sUserParameter, $hook);
340                    # workOnDir($sNewDir, $nFileCount);
341                    $nCountFiles += $nFileCount;
342
343                    chdir ($startdir);                      # zurueckwechseln.
344                    cwd();
345                }
346            }
347            else
348            {
349                # File must exist, be a regular file and must not be the $onlyOnFile
350                if (-f $myfile)
351                {
352                    # print STDERR " $startdir" . "$myfile\n";
353                    $nCountFiles++;
354                    # workOnFile($startdir, $myfile, $destdir);
355                    $hook->($startdir, $myfile, $sUserParameter);
356                }
357            }
358            #}
359            #else
360            #{
361            #    print STDERR "linked file: $dir/$myfile\n";
362            #}
363        }
364        closedir(DIR);
365    }
366    else
367    {
368        print STDERR "could not open $startdir\n";
369    }
370    return $nCountFiles;
371}
372
373our $lcl_sSofficeBinPath;
374our $lcl_sSofficeBinName;
375
376sub searchSofficeBin($$$)
377{
378    my $currentDir = shift;
379    my $currentFile = shift;
380    my $sUserParameter = shift;
381
382    if ($currentFile eq $sUserParameter)
383    {
384        my $sSourceFilename;
385        $sSourceFilename = appendPath($currentDir, $currentFile);
386
387        if ( -e "$sSourceFilename" )
388        {
389            $lcl_sSofficeBinPath = $currentDir;
390            $lcl_sSofficeBinName = $currentFile;
391        }
392    }
393}
394
395# our $lcl_sUnoPkgPath;
396#
397# sub searchUnoPkgBin($$$)
398# {
399#     my $currentDir = shift;
400#     my $currentFile = shift;
401#     my $sUserParameter = shift;
402#
403#     if ($currentFile eq $sUserParameter)
404#     {
405#         my $sSourceFilename;
406#         $sSourceFilename = appendPath($currentDir, $currentFile);
407#         if ( -e "$sSourceFilename" )
408#         {
409#             $lcl_sUnoPkgPath = $currentDir;
410#         }
411#     }
412# }
413
414# our $lcl_sJARPath;
415
416# sub searchJARFile($$$)
417# {
418#     my $currentDir = shift;
419#     my $currentFile = shift;
420#     my $sUserParameter = shift;
421#
422#     if ($currentFile eq $sUserParameter)
423#     {
424#         my $sSourceFilename;
425#         $sSourceFilename = appendPath($currentDir, $currentFile);
426#         if ( -e "$sSourceFilename" )
427#         {
428#             $lcl_sJARPath = $currentDir;
429#         }
430#     }
431# }
432
433# return the PATH, where the file was found
434# sub searchForJAR($$)
435# {
436#     my $sPathToInstallOffice = shift;
437#     my $sJARFileName = shift;
438#
439#     my $sCurrentPath = cwd();
440#
441#     $lcl_sJARPath = "";
442#     readdirectory(${sPathToInstallOffice}, ${sJARFileName}, \&searchJARFile);
443#
444#     chdir $sCurrentPath;
445#     cwd();
446#
447#     return $lcl_sJARPath;
448# }
449
450# sub getUnoPkg($)
451# {
452#     my $sPathToInstallOffice = shift;
453#
454#     my $sUnoPkgName = "unopkg.bin";
455#     if (isWindowsEnvironment())
456#     {
457#         $sUnoPkgName = "unopkg.exe";
458#     }
459#
460#     my $sCurrentPath = cwd();
461#
462#     $lcl_sUnoPkgPath = "";
463#     readdirectory(${sPathToInstallOffice}, ${sUnoPkgName}, \&searchUnoPkgBin);
464#
465#     chdir $sCurrentPath;
466#     cwd();
467#
468#     return ($lcl_sUnoPkgPath, $sUnoPkgName);
469# }
470
471sub getSofficeExe($)
472{
473    my $sPathToOffice = shift;
474
475    my $sSofficeExeName = "soffice";
476    if (isWindowsEnvironment())
477    {
478        $sSofficeExeName = "soffice.exe";
479    }
480
481    my $sCurrentPath = cwd();
482
483    $lcl_sSofficeBinPath = "";
484    $lcl_sSofficeBinName = "";
485    readdirectory(${sPathToOffice}, ${sSofficeExeName}, \&searchSofficeBin);
486
487    chdir $sCurrentPath;
488    cwd();
489
490    return ($lcl_sSofficeBinPath, $lcl_sSofficeBinName);
491}
492
493# sub checkOfficeAlreadyInstalled($)
494# {
495#     my $sOfficePath = shift;
496#
497#     my $sCurrentPath = cwd();
498#
499#     $lcl_sSofficeBinPath = "";
500#     my $sOldOfficePath = appendPath($sOfficePath, "program");
501#     if ( -d "$sOldOfficePath" )
502#     {
503#         $sOldOfficePath = appendPath($sOldOfficePath, "soffice.bin");
504#         if ( -e $sOldOfficePath )
505#         {
506#             return 1;
507#         }
508#     }
509#     else
510#     {
511#         if (isWindowsEnvironment())
512#         {
513#             my $sThreeLayerOffice = appendPath($sOfficePath, "Sun");
514#             $sThreeLayerOffice = appendPath($sThreeLayerOffice, "StarOffice 9");
515#             $sThreeLayerOffice = appendPath($sThreeLayerOffice, "program");
516#             $sThreeLayerOffice = appendPath($sThreeLayerOffice, "soffice.bin");
517#
518#             if ( -e "$sThreeLayerOffice" )
519#             {
520#                 return 1;
521#             }
522#         }
523#         else
524#         {
525#             my $sThreeLayerOffice = appendPath($sOfficePath, "staroffice9");
526#             $sThreeLayerOffice = appendPath($sThreeLayerOffice, "program");
527#             $sThreeLayerOffice = appendPath($sThreeLayerOffice, "soffice.bin");
528#             if ( -e "$sThreeLayerOffice" )
529#             {
530#                 return 1;
531#             }
532#         }
533#     }
534#
535#     # soffice.bin not found in fast path
536#     readdirectory($sOfficePath, "soffice.bin", \&searchSofficeBin);
537#     chdir $sCurrentPath;
538#     cwd();
539#
540#     if ( $lcl_sSofficeBinPath ne "" )
541#     {
542#         return 1;
543#     }
544#     return 0;
545#     # this is the old check
546#     # my $sOfficePathCheck = appendPath(${sPathToInstallOffice}, "program");
547#     # $sOfficePathCheck = appendPath($sOfficePathCheck, "soffice.bin");
548#     # if ( -e $sOfficePathCheck )
549#     # {
550#     #     return 1;
551#     # }
552#     #
553#     # # check path system of tree layer office
554#     # if ( isWindowsEnvironment() )
555#     # {
556#     #     $sOfficePathCheck = appendPath(${sPathToInstallOffice}, "Sun");
557#     #     if ( ! -e $sOfficePathCheck)
558#     #     {
559#     #         # could be an OpenOffice.org
560#     #         return 0;
561#     #     }
562#     #     else
563#     #     {
564#     #
565#     #         $sOfficePathCheck = appendPath($sOfficePathCheck, "StarOffice 9");
566#     #         $sOfficePathCheck = appendPath($sOfficePathCheck, "program");
567#     #         $sOfficePathCheck = appendPath($sOfficePathCheck, "soffice.bin");
568#     #         if ( -e $sOfficePathCheck )
569#     #         {
570#     #             return 1;
571#     #         }
572#     #         print "Error: There exist no Office, maybe an unsupported version?\n";
573#     #     }
574#     # }
575#     # elsif ( isUnixEnvironment() )
576#     # {
577#     #     $sOfficePathCheck = appendPath(${sPathToInstallOffice}, "staroffice9");
578#     #     $sOfficePathCheck = appendPath($sOfficePathCheck, "staroffice9");
579#     #     $sOfficePathCheck = appendPath($sOfficePathCheck, "program");
580#     #     $sOfficePathCheck = appendPath($sOfficePathCheck, "soffice.bin");
581#     #     if ( -e $sOfficePathCheck )
582#     #     {
583#     #         return 1;
584#     #     }
585#     #     print "Error: There exist no Office, maybe an unsupported version?\n";
586#     # }
587#     # else
588#     # {
589#     #     print "Error: There exist no Office, maybe an unsupported version?\n";
590#     # }
591#     # return 0;
592# }
593
5941;
595