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