xref: /AOO42X/main/helpcontent2/helpers/checkuno.pl (revision 52b78ea2f0e0d1f4ec7f128eae59989e7fe366e3)
1*c667dd47SPedro Giffuni#!/usr/bin/env perl
2bb113e63SAndrew Rist# *************************************************************
3bb113e63SAndrew Rist#
4bb113e63SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
5bb113e63SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
6bb113e63SAndrew Rist#  distributed with this work for additional information
7bb113e63SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
8bb113e63SAndrew Rist#  to you under the Apache License, Version 2.0 (the
9bb113e63SAndrew Rist#  "License"); you may not use this file except in compliance
10bb113e63SAndrew Rist#  with the License.  You may obtain a copy of the License at
11bb113e63SAndrew Rist#
12bb113e63SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
13bb113e63SAndrew Rist#
14bb113e63SAndrew Rist#  Unless required by applicable law or agreed to in writing,
15bb113e63SAndrew Rist#  software distributed under the License is distributed on an
16bb113e63SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17bb113e63SAndrew Rist#  KIND, either express or implied.  See the License for the
18bb113e63SAndrew Rist#  specific language governing permissions and limitations
19bb113e63SAndrew Rist#  under the License.
20bb113e63SAndrew Rist#
21bb113e63SAndrew Rist# *************************************************************
22cdf0e10cSrcweir
23cdf0e10cSrcweir$uno_hid = "/handbuch/WORKBENCH/helpcontent2/helpers/uno_hid.lst";
24cdf0e10cSrcweir$uno_cmd = "/handbuch/WORKBENCH/helpcontent2/helpers/unocmds.txt";
25cdf0e10cSrcweir$startdir = "/handbuch/WORKBENCH/helpcontent2/source/text/";
26cdf0e10cSrcweir
27cdf0e10cSrcweirif (open HID, $uno_hid) {
28cdf0e10cSrcweir    while (<HID>) {
29cdf0e10cSrcweir        chomp;
30cdf0e10cSrcweir        ($shid,$nhid,$uno) = split ",";
31cdf0e10cSrcweir        $hid{lc($uno)} = $shid;
32cdf0e10cSrcweir    }
33cdf0e10cSrcweir    close HID;
34cdf0e10cSrcweir} else {
35cdf0e10cSrcweir    die "Cannot open $uno_hid: $!\n";
36cdf0e10cSrcweir}
37cdf0e10cSrcweirprint scalar keys(%hid) . " entries read\n";
38cdf0e10cSrcweir
39cdf0e10cSrcweirif (open UNO, $uno_cmd) {
40cdf0e10cSrcweir    while (<UNO>) {
41cdf0e10cSrcweir        chomp;
42cdf0e10cSrcweir        ($uno,$file) = split ";";
43cdf0e10cSrcweir        #print "$file\n";
44cdf0e10cSrcweir        if (defined $hid{lc($uno)}) {
45cdf0e10cSrcweir            if (open XML, "$startdir$file") {
46cdf0e10cSrcweir                undef $/;
47cdf0e10cSrcweir                $xml = <XML>;
48cdf0e10cSrcweir                $/ = "\n";
49cdf0e10cSrcweir                close XML;
50cdf0e10cSrcweir                if ($xml =~ /hid\/$hid{lc($uno)}/ig) {
51cdf0e10cSrcweir                    print "OK    $startdir$file\n";
52cdf0e10cSrcweir                } else {
53cdf0e10cSrcweir                    print "MISS  $startdir$file\n";
54cdf0e10cSrcweir                    open XML, ">$startdir$file.org";
55cdf0e10cSrcweir                    print XML $xml;
56cdf0e10cSrcweir                    close XML;
57cdf0e10cSrcweir                    open XML, ">$startdir$file";
58cdf0e10cSrcweir                    $id = "bm_id" . int(rand(10000000));
59cdf0e10cSrcweir                    $xml =~ s/(<bookmark[^>]*branch=\"hid\/$uno\"[^>]*>)/<bookmark xml-lang=\"en-US\" branch=\"hid\/$hid{lc($uno)}\" id=\"$id\" localize=\"false\"\/><!-- HID added by script -->\n$1/ig;
60cdf0e10cSrcweir                    print XML $xml;
61cdf0e10cSrcweir                    close XML;
62cdf0e10cSrcweir                }
63cdf0e10cSrcweir            } else {
64cdf0e10cSrcweir                print "Cannot open $startdir$file: $!\n";
65cdf0e10cSrcweir            }
66cdf0e10cSrcweir        }
67cdf0e10cSrcweir    }
68cdf0e10cSrcweir} else {
69cdf0e10cSrcweir    die "Cannot open $uno_cmd: $!\n";
70cdf0e10cSrcweir}
71