1cdf0e10cSrcweir#!/usr/bin/perl
2cdf0e10cSrcweir#########################################################################
3cdf0e10cSrcweir
49780544fSAndrew Rist #**************************************************************
59780544fSAndrew Rist#
69780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
79780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
89780544fSAndrew Rist#  distributed with this work for additional information
99780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
109780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
119780544fSAndrew Rist#  "License"); you may not use this file except in compliance
129780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
139780544fSAndrew Rist#
149780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
159780544fSAndrew Rist#
169780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
179780544fSAndrew Rist#  software distributed under the License is distributed on an
189780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
199780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
209780544fSAndrew Rist#  specific language governing permissions and limitations
219780544fSAndrew Rist#  under the License.
229780544fSAndrew Rist#
239780544fSAndrew Rist#**************************************************************
249780544fSAndrew Rist
259780544fSAndrew Rist
26cdf0e10cSrcweir
27cdf0e10cSrcweir####################################################################
28cdf0e10cSrcweir# File Name: converterlib.pm
29cdf0e10cSrcweir# Version  : 1.0
30cdf0e10cSrcweir# Project  : XMerge
31cdf0e10cSrcweir# Author   : Brian Cameron
32cdf0e10cSrcweir# Date     : 5th Sept. 2001
33cdf0e10cSrcweir#
34cdf0e10cSrcweir# This script enters text at position x,y on screen.
35cdf0e10cSrcweir#
36cdf0e10cSrcweir# Parameter
37cdf0e10cSrcweir#  x-coordinate
38cdf0e10cSrcweir#  y-coordinate
39cdf0e10cSrcweir#  Text to enter
40cdf0e10cSrcweir#
41cdf0e10cSrcweir##########################################################################
42cdf0e10cSrcweir
43cdf0e10cSrcweiruse EmRPC;  # EmRPC::OpenConnection, CloseConnection
44cdf0e10cSrcweiruse EmFunctions;
45cdf0e10cSrcweiruse EmUtils;
46cdf0e10cSrcweir
47cdf0e10cSrcweir# Set global_debug flag
48cdf0e10cSrcweir#
49cdf0e10cSrcweir$global_debug   = $ENV{'ZENDEBUG'};
50cdf0e10cSrcweir#$em_script_home = "/export/home/test/qadir/bin";
51cdf0e10cSrcweir$em_script_home = $ENV{'EM_SCRIPT_HOME'};
52cdf0e10cSrcweir#$qa_script_home = "/export/home/test/qadir/qa-new/bin";
53cdf0e10cSrcweir    $qa_script_home = $ENV{'QA_SCRIPT_HOME'};
54cdf0e10cSrcweir#
55cdf0e10cSrcweir# CONVERT FUNCTIONS
56cdf0e10cSrcweir#
57cdf0e10cSrcweir
58cdf0e10cSrcweir# convert_to_pdb
59cdf0e10cSrcweir# directory  - directory containing the xml-orig and pdb-orig
60cdf0e10cSrcweir#              subdirectories.
61cdf0e10cSrcweir# file       - file to convert
62cdf0e10cSrcweir# extension  - extension of file to convert (sxw or sxc)
63cdf0e10cSrcweir# convert_to - what PDB format to convert into.
64cdf0e10cSrcweir#
65cdf0e10cSrcweir# Returns 0 if success, -1 otherwise.
66cdf0e10cSrcweir#
67cdf0e10cSrcweir# Converts file from XML to PDB
68cdf0e10cSrcweir#
69cdf0e10cSrcweirsub convert_to_pdb
70cdf0e10cSrcweir{
71cdf0e10cSrcweir  my $directory     = $_[0];
72cdf0e10cSrcweir  my $file          = $_[1];
73cdf0e10cSrcweir  my $extension     = $_[2];
74cdf0e10cSrcweir  my $convert_to    = $_[3];
75cdf0e10cSrcweir  my $pdb_directory = $_[4];
76cdf0e10cSrcweir  my $rc            = 0;
77cdf0e10cSrcweir  my $xmlfile       = "$directory/$file.$extension";
78cdf0e10cSrcweir  my $pdbdir        = "$pdb_directory";
79cdf0e10cSrcweir
80cdf0e10cSrcweir  &enter_func("convert_to_pdb");
81cdf0e10cSrcweir
82cdf0e10cSrcweir  if (! -f "$xmlfile")
83cdf0e10cSrcweir  {
84cdf0e10cSrcweir    print "\nERROR, file $xmlfile does not exist\n";
85cdf0e10cSrcweir    $rc = -1;
86cdf0e10cSrcweir  }
87cdf0e10cSrcweir  if (! -d "$pdbdir")
88cdf0e10cSrcweir  {
89cdf0e10cSrcweir    print "\nERROR, directory $directory/pdb-orig does not exist\n";
90cdf0e10cSrcweir    $rc = -1;
91cdf0e10cSrcweir  }
92cdf0e10cSrcweir
93cdf0e10cSrcweir  if ($rc != -1)
94cdf0e10cSrcweir  {
95cdf0e10cSrcweir    if ("$convert_to" eq "application/x-minicalc")
96cdf0e10cSrcweir    {
97cdf0e10cSrcweir      # Move all files over.
98cdf0e10cSrcweir      #
99cdf0e10cSrcweir      my $i = 1;
100cdf0e10cSrcweir
101cdf0e10cSrcweir      while (-f "$pdbdir/$file-Sheet$i.pdb")
102cdf0e10cSrcweir      {
103cdf0e10cSrcweir        my $pdbfile = "$pdbdir/$file-Sheet$i.pdb";
104cdf0e10cSrcweir
105cdf0e10cSrcweir        print "\n";
106cdf0e10cSrcweir
107cdf0e10cSrcweir        if (-f "$pdbfile.old")
108cdf0e10cSrcweir        {
109cdf0e10cSrcweir          print "Removing $pdbfile.old\n";
110cdf0e10cSrcweir          `/bin/rm -f $pdbfile.old`;
111cdf0e10cSrcweir        }
112cdf0e10cSrcweir
113cdf0e10cSrcweir        print "Moving $pdbfile file to $pdbfile.old\n";
114cdf0e10cSrcweir        `mv "$pdbfile" "$pdbfile.old"`;
115cdf0e10cSrcweir
116cdf0e10cSrcweir        $i++;
117cdf0e10cSrcweir      }
118cdf0e10cSrcweir    }
119cdf0e10cSrcweir    else
120cdf0e10cSrcweir    {
121cdf0e10cSrcweir      if (-f "$pdbdir/$file.pdb")
122cdf0e10cSrcweir      {
123cdf0e10cSrcweir        print "\n";
124cdf0e10cSrcweir
125cdf0e10cSrcweir        if (-f "$pdbdir/$file.pdb.old")
126cdf0e10cSrcweir        {
127cdf0e10cSrcweir          print "Removing $pdbdir/$file.pdb.old\n";
128cdf0e10cSrcweir          `/bin/rm -f $pdbdir/$file.pdb.old`;
129cdf0e10cSrcweir        }
130cdf0e10cSrcweir
131cdf0e10cSrcweir        print "Moving $pdbdir/$file.pdb file to $pdbdir/$file.pdb.old\n";
132cdf0e10cSrcweir        `mv "$pdbdir/$file.pdb" "$pdbdir/$file.pdb.old"`
133cdf0e10cSrcweir      }
134cdf0e10cSrcweir    }
135cdf0e10cSrcweir
136cdf0e10cSrcweir    &start_rd($extension, $convert_to, $xmlfile, "");
137cdf0e10cSrcweir
138cdf0e10cSrcweir    if ("$convert_to" eq "application/x-minicalc")
139cdf0e10cSrcweir    {
140cdf0e10cSrcweir      # Must handle minicalc separately since it can
141cdf0e10cSrcweir      # convert to multiple files with this file name
142cdf0e10cSrcweir      # convention.
143cdf0e10cSrcweir      #
144cdf0e10cSrcweir      print "Moving $file-Sheet*.pdb files to $pdbdir\n";
145cdf0e10cSrcweir      `mv $file-Sheet*.pdb $pdbdir`;
146cdf0e10cSrcweir      `chmod 666 $pdbdir/$file-*.pdb`;
147cdf0e10cSrcweir    }
148cdf0e10cSrcweir    else
149cdf0e10cSrcweir    {
150cdf0e10cSrcweir      print "Moving $file.pdb file to $pdbdir\n";
151cdf0e10cSrcweir      `mv $file.pdb $pdbdir`;
152cdf0e10cSrcweir      `chmod 666 $pdbdir/$file.pdb`;
153cdf0e10cSrcweir    }
154cdf0e10cSrcweir  }
155cdf0e10cSrcweir
156cdf0e10cSrcweir  &leave_func("convert_to_pdb");
157cdf0e10cSrcweir
158cdf0e10cSrcweir  return $rc;
159cdf0e10cSrcweir}
160cdf0e10cSrcweir
161cdf0e10cSrcweir# convert_to_xml
162cdf0e10cSrcweir# xmldir       - directory to contain the xml output.
163cdf0e10cSrcweir# xmlorigdir   - directory to contain the xml input (used for merge)
164cdf0e10cSrcweir# pdbfile      - file to convert
165cdf0e10cSrcweir# convert_from - what PDB format to convert from.
166cdf0e10cSrcweir# extension    - extension of file to convert (sxw or sxc)
167cdf0e10cSrcweir# output       - output filename to create
168cdf0e10cSrcweir# merge_opt    - 1 if convert and merge, 0 if convert only
169cdf0e10cSrcweir#
170cdf0e10cSrcweir# Returns 0 if success, -1 otherwise.
171cdf0e10cSrcweir#
172cdf0e10cSrcweir# Converts file from PDB to XML
173cdf0e10cSrcweir#
174cdf0e10cSrcweirsub convert_to_xml
175cdf0e10cSrcweir{
176cdf0e10cSrcweir  my $xmldir        = $_[0];
177cdf0e10cSrcweir  my $xmlorigdir    = $_[1];
178cdf0e10cSrcweir  my $pdbfile       = $_[2];
179cdf0e10cSrcweir  my $convert_from  = $_[3];
180cdf0e10cSrcweir  my $extension     = $_[4];
181cdf0e10cSrcweir  my $output        = $_[5];
182cdf0e10cSrcweir  my $merge_opt     = $_[6];
183cdf0e10cSrcweir  my $rc            = 0;
184cdf0e10cSrcweir
185cdf0e10cSrcweir  &enter_func("convert_to_xml");
186cdf0e10cSrcweir
187cdf0e10cSrcweir  my @args = split(/ /,$pdbfile);
188cdf0e10cSrcweir
189cdf0e10cSrcweir  for ($i=0;$i <= $#args; $i++)
190cdf0e10cSrcweir  {
191cdf0e10cSrcweir    if (! -f "@args[$i]")
192cdf0e10cSrcweir    {
193cdf0e10cSrcweir      print "\nERROR, file $pdbfile does not exist\n";
194cdf0e10cSrcweir      $rc = -1;
195cdf0e10cSrcweir    }
196cdf0e10cSrcweir  }
197cdf0e10cSrcweir
198cdf0e10cSrcweir  if (! -f "$xmlorigdir/$output.$extension")
199cdf0e10cSrcweir  {
200cdf0e10cSrcweir    print "\nERROR, file $xmlorigdir/$output.$extension does not exist\n";
201cdf0e10cSrcweir    $rc = -1;
202cdf0e10cSrcweir  }
203cdf0e10cSrcweir  if (! -d "$xmldir")
204cdf0e10cSrcweir  {
205cdf0e10cSrcweir    print "\nERROR, directory $xmlorigdir does not exist\n";
206cdf0e10cSrcweir    $rc = -1;
207cdf0e10cSrcweir  }
208cdf0e10cSrcweir  if (! -d "$xmlorigdir")
209cdf0e10cSrcweir  {
210cdf0e10cSrcweir    print "\nERROR, directory $xmldir does not exist\n";
211cdf0e10cSrcweir    $rc = -1;
212cdf0e10cSrcweir  }
213cdf0e10cSrcweir
214cdf0e10cSrcweir  if ($rc != -1)
215cdf0e10cSrcweir  {
216cdf0e10cSrcweir    if ($merge_opt == 1)
217cdf0e10cSrcweir    {
218cdf0e10cSrcweir      print "Copying <$xmlorigdir/$output.$extension> to <$xmldir>\n";
219cdf0e10cSrcweir      `cp $xmlorigdir/$output.$extension $xmldir/`;
220cdf0e10cSrcweir
221cdf0e10cSrcweir      my $check_stamp = (stat("$xmldir/$output.$extension"))[9];
222cdf0e10cSrcweir
223cdf0e10cSrcweir      &start_rd($convert_from, $extension, $pdbfile,
224cdf0e10cSrcweir        "$xmldir/$output.$extension");
225cdf0e10cSrcweir
226cdf0e10cSrcweir
227cdf0e10cSrcweir      # No need to move the file to the $xmldir since the merge
228cdf0e10cSrcweir      # argument specifies the output file.
229cdf0e10cSrcweir
230cdf0e10cSrcweir      my $check_stamp_update = (stat("$xmldir/$output.$extension"))[9];
231cdf0e10cSrcweir      if ($check_stamp eq $check_stamp_update)
232cdf0e10cSrcweir      {
233cdf0e10cSrcweir        print "\nERROR, Problem while merging <$xmldir/$output.$extension>\n";
234cdf0e10cSrcweir        `mv $xmldir/$output.$extension $xmldir/$output.$extension.err`;
235cdf0e10cSrcweir      }
236cdf0e10cSrcweir    }
237cdf0e10cSrcweir    else
238cdf0e10cSrcweir    {
239cdf0e10cSrcweir      &start_rd($convert_from, $extension, $pdbfile, "");
240cdf0e10cSrcweir
241cdf0e10cSrcweir      print "Moving $output.$extension to $xmldir\n";
242cdf0e10cSrcweir      `mv $output.$extension $xmldir`;
243cdf0e10cSrcweir      `chmod 666 $xmldir/$output.$extension`;
244cdf0e10cSrcweir    }
245cdf0e10cSrcweir  }
246cdf0e10cSrcweir
247cdf0e10cSrcweir  &leave_func("convert_to_xml");
248cdf0e10cSrcweir
249cdf0e10cSrcweir  return $rc;
250cdf0e10cSrcweir}
251cdf0e10cSrcweir
252cdf0e10cSrcweir# start_rd
253cdf0e10cSrcweir# from  - format to convert from
254cdf0e10cSrcweir# to    - format to convert to
255cdf0e10cSrcweir# file  - file to convert
256cdf0e10cSrcweir# merge - merge filename ("" indicates convert-only with no merge)
257cdf0e10cSrcweir#
258cdf0e10cSrcweir# converts file from/to the specified formats.
259cdf0e10cSrcweir#
260cdf0e10cSrcweirsub start_rd
261cdf0e10cSrcweir{
262cdf0e10cSrcweir    my $from       = $_[0];
263cdf0e10cSrcweir    my $to         = $_[1];
264cdf0e10cSrcweir    my $file       = $_[2];
265cdf0e10cSrcweir    my $merge      = $_[3];
266cdf0e10cSrcweir
267cdf0e10cSrcweir    print "\nConverting from $from to $to.\n";
268cdf0e10cSrcweir    if ($global_debug)
269cdf0e10cSrcweir    {
270cdf0e10cSrcweir      &print_debug ("rd command is:\n");
271cdf0e10cSrcweir    }
272cdf0e10cSrcweir
273cdf0e10cSrcweir    if ($merge eq "")
274cdf0e10cSrcweir    {
275cdf0e10cSrcweir       &print_debug ("  $em_script_home/rd -from $from -to $to $file\n");
276cdf0e10cSrcweir       print "\nConverting from $from to $to with no merge.\n";
277cdf0e10cSrcweir      `$em_script_home/rd -from $from -to $to $file`;
278cdf0e10cSrcweir    }
279cdf0e10cSrcweir    else
280cdf0e10cSrcweir    {
281cdf0e10cSrcweir       &print_debug ("  $em_script_home/rd -from $from -to $to -merge $merge $file\n");
282cdf0e10cSrcweir       print "\nConverting from $from to $to with merge.\n";
283cdf0e10cSrcweir      `$em_script_home/rd -from $from -to $to -merge $merge $file`;
284cdf0e10cSrcweir    }
285cdf0e10cSrcweir
286cdf0e10cSrcweir    print "Done converting.\n\n";
287cdf0e10cSrcweir}
288cdf0e10cSrcweir
289cdf0e10cSrcweir#
290cdf0e10cSrcweir# POSE INTERACTION FUNCTIONS
291cdf0e10cSrcweir#
292cdf0e10cSrcweir
293cdf0e10cSrcweir# open_connection
294cdf0e10cSrcweir# display_debug - debug will be displayed if not 0
295cdf0e10cSrcweir#
296cdf0e10cSrcweir# Opens the connection to pose.
297cdf0e10cSrcweir#
298cdf0e10cSrcweirsub open_connection
299cdf0e10cSrcweir{
300cdf0e10cSrcweir  my $display_debug = $_[0];
301cdf0e10cSrcweir  my $rc;
302cdf0e10cSrcweir
303cdf0e10cSrcweir  EmRPC::OpenConnection(6415, "localhost");
304cdf0e10cSrcweir
305cdf0e10cSrcweir  if ($display_debug && $global_debug)
306cdf0e10cSrcweir  {
307cdf0e10cSrcweir    print "\nPose Connection Opened\n";
308cdf0e10cSrcweir  }
309cdf0e10cSrcweir}
310cdf0e10cSrcweir
311cdf0e10cSrcweir# close_connection
312cdf0e10cSrcweir# display_debug - debug will be displayed if not 0
313cdf0e10cSrcweir#
314cdf0e10cSrcweir# Closes the connection to pose.
315cdf0e10cSrcweir#
316cdf0e10cSrcweirsub close_connection
317cdf0e10cSrcweir{
318cdf0e10cSrcweir  my $display_debug = $_[0];
319cdf0e10cSrcweir
320cdf0e10cSrcweir  EmRPC::CloseConnection();
321cdf0e10cSrcweir
322cdf0e10cSrcweir  if ($display_debug && $global_debug)
323cdf0e10cSrcweir  {
324cdf0e10cSrcweir    print "\nPose Connection Closed\n";
325cdf0e10cSrcweir  }
326cdf0e10cSrcweir}
327cdf0e10cSrcweir
328cdf0e10cSrcweir# start_pose
329cdf0e10cSrcweir# pose_exe  - name of pose executable.
330cdf0e10cSrcweir# apps_load - The PRC files to load into pose, can be a comma
331cdf0e10cSrcweir#             separated list.
332cdf0e10cSrcweir# run_prog  - Program to run at startup.
333cdf0e10cSrcweir# timeout   - Timeout value to use when starting pose.
334cdf0e10cSrcweir#
335cdf0e10cSrcweir# Starts the Palm OS Emulator, loads PRC files, and starts
336cdf0e10cSrcweir# a program.
337cdf0e10cSrcweir#
338cdf0e10cSrcweirsub start_pose
339cdf0e10cSrcweir{
340cdf0e10cSrcweir  my $pose_exe     = $_[0];
341cdf0e10cSrcweir  my $sessionfile  = $ENV{'EM_SESSION_FILE'};
342cdf0e10cSrcweir  my $romfile      = $ENV{'EM_ROM_FILE'};
343cdf0e10cSrcweir  my $apps_load    = $_[1];
344cdf0e10cSrcweir  my $run_prog     = $_[2];
345cdf0e10cSrcweir  my $timeout      = $_[3];
346cdf0e10cSrcweir  my $stay_in_loop = 1;
347cdf0e10cSrcweir  my $address;
348cdf0e10cSrcweir  my $title;
349cdf0e10cSrcweir  my $form;
350cdf0e10cSrcweir  my $label_id;
351cdf0e10cSrcweir  my $num_objects;
352cdf0e10cSrcweir  my $i;
353cdf0e10cSrcweir  my $ii;
354cdf0e10cSrcweir  my $rc = 1;
355cdf0e10cSrcweir
356cdf0e10cSrcweir  my $pose_cmd  = "$pose_exe ";
357cdf0e10cSrcweir  $pose_cmd    .= " -psf $sessionfile ";
358cdf0e10cSrcweir  $pose_cmd    .= "-load_apps $apps_load ";
359cdf0e10cSrcweir  $pose_cmd    .= "-run_app $run_prog";
360cdf0e10cSrcweir
361cdf0e10cSrcweir# It is more effective to use the -psf argument to
362cdf0e10cSrcweir# set these values.
363cdf0e10cSrcweir#
364cdf0e10cSrcweir#  $pose_cmd    .= -rom $romfile ";
365cdf0e10cSrcweir#  $pose_cmd    .= "-ram_size 8192 ";
366cdf0e10cSrcweir#  $pose_cmd    .= "-device PalmVx ";
367cdf0e10cSrcweir
368cdf0e10cSrcweir  &enter_func("start_pose");
369cdf0e10cSrcweir
370cdf0e10cSrcweir  if ($global_debug)
371cdf0e10cSrcweir  {
372cdf0e10cSrcweir    &print_debug("\n");
373cdf0e10cSrcweir    &print_debug("pose command is:\n");
374cdf0e10cSrcweir    &print_debug("  $pose_cmd\n");
375cdf0e10cSrcweir  }
376cdf0e10cSrcweir
377cdf0e10cSrcweir  print "\nLaunching pose...\n";
378cdf0e10cSrcweir  system ("$pose_cmd &");
379cdf0e10cSrcweir
380cdf0e10cSrcweir  # Give time for pose to get started...
381cdf0e10cSrcweir  #
382cdf0e10cSrcweir  for ($i=0; $i < $timeout; $i++)
383cdf0e10cSrcweir  {
384cdf0e10cSrcweir    $tmp = $i + 1;
385cdf0e10cSrcweir    print "$tmp\n";
386cdf0e10cSrcweir
387cdf0e10cSrcweir    # Do not use pose_sleep here
388cdf0e10cSrcweir    #
389cdf0e10cSrcweir    sleep(1);
390cdf0e10cSrcweir  }
391cdf0e10cSrcweir
392cdf0e10cSrcweir  # Verify pose started successfully, and fail otherwise...
393cdf0e10cSrcweir  #
394cdf0e10cSrcweir  $rc = &verify_pose(5);
395cdf0e10cSrcweir  if ($rc != 0)
396cdf0e10cSrcweir  {
397cdf0e10cSrcweir     $stay_in_loop = 0;
398cdf0e10cSrcweir  }
399cdf0e10cSrcweir  else
400cdf0e10cSrcweir  {
401cdf0e10cSrcweir     # Sleep before opening the connection again, after testing in
402cdf0e10cSrcweir     # the verify_pose function.
403cdf0e10cSrcweir     #
404cdf0e10cSrcweir     pose_sleep(2);
405cdf0e10cSrcweir     &open_connection(1);
406cdf0e10cSrcweir     print "\nChecking if the appropriate window is on screen...\n";
407cdf0e10cSrcweir  }
408cdf0e10cSrcweir
409cdf0e10cSrcweir  # Stop looping when the specified window has started.
410cdf0e10cSrcweir  #
411cdf0e10cSrcweir  for ($i=0; $i < $timeout && $stay_in_loop == 1; $i++)
412cdf0e10cSrcweir  {
413cdf0e10cSrcweir    $form = FrmGetActiveForm();
414cdf0e10cSrcweir    $num_objects = FrmGetNumberOfObjects($form);
415cdf0e10cSrcweir
416cdf0e10cSrcweir    for $ii (0..$num_objects - 1)
417cdf0e10cSrcweir    {
418cdf0e10cSrcweir      my ($object_type) = FrmGetObjectType($form, $ii);
419cdf0e10cSrcweir
420cdf0e10cSrcweir      if ("$run_prog" eq "Quickword")
421cdf0e10cSrcweir      {
422cdf0e10cSrcweir        if ($object_type == frmTitleObj)
423cdf0e10cSrcweir        {
424cdf0e10cSrcweir          ($address, $title) = FrmGetTitle($form,);
425cdf0e10cSrcweir
426cdf0e10cSrcweir          # Display count and title.
427cdf0e10cSrcweir          #
428cdf0e10cSrcweir          $tmp = $i + 1;
429cdf0e10cSrcweir          print "$tmp - title is $title\n";
430cdf0e10cSrcweir
431cdf0e10cSrcweir          if ("$title" eq "Quickword")
432cdf0e10cSrcweir          {
433cdf0e10cSrcweir            $stay_in_loop = 0;
434cdf0e10cSrcweir            $rc = 0;
435cdf0e10cSrcweir            last;
436cdf0e10cSrcweir          }
437cdf0e10cSrcweir        }
438cdf0e10cSrcweir      }
439cdf0e10cSrcweir      elsif ("$run_prog" eq "MiniCalc")
440cdf0e10cSrcweir      {
441cdf0e10cSrcweir        if ($object_type == frmLabelObj)
442cdf0e10cSrcweir        {
443cdf0e10cSrcweir          $label_id = FrmGetObjectId ($form, $ii);
444cdf0e10cSrcweir          ($address, $label) = FrmGetLabel($form, $label_id);
445cdf0e10cSrcweir
446cdf0e10cSrcweir          # Display count and label.
447cdf0e10cSrcweir          #
448cdf0e10cSrcweir          $tmp = $i + 1;
449cdf0e10cSrcweir          print "$tmp - label is $label\n";
450cdf0e10cSrcweir          if ("$label" =~ "Solutions In Hand")
451cdf0e10cSrcweir          {
452cdf0e10cSrcweir            $stay_in_loop = 0;
453cdf0e10cSrcweir            $rc = 0;
454cdf0e10cSrcweir            last;
455cdf0e10cSrcweir          }
456cdf0e10cSrcweir        }
457cdf0e10cSrcweir      }
458cdf0e10cSrcweir    }
459cdf0e10cSrcweir
460cdf0e10cSrcweir    # Do not use pose_sleep here
461cdf0e10cSrcweir    #
462cdf0e10cSrcweir    sleep(1);
463cdf0e10cSrcweir  }
464cdf0e10cSrcweir
465cdf0e10cSrcweir  # Do not use pose_sleep here
466cdf0e10cSrcweir  #
467cdf0e10cSrcweir  sleep(1);
468cdf0e10cSrcweir
469cdf0e10cSrcweir  &leave_func("start_pose");
470cdf0e10cSrcweir  return($rc);
471cdf0e10cSrcweir}
472cdf0e10cSrcweir
473cdf0e10cSrcweir# kill_pose
474cdf0e10cSrcweir#
475cdf0e10cSrcweir# Kills all pose processes
476cdf0e10cSrcweir#
477cdf0e10cSrcweirsub kill_pose
478cdf0e10cSrcweir{
479cdf0e10cSrcweir  if ($global_debug)
480cdf0e10cSrcweir  {
481cdf0e10cSrcweir     print "Stopping pose process...\n";
482cdf0e10cSrcweir  }
483cdf0e10cSrcweir
484cdf0e10cSrcweir  `pkill pose`;
485cdf0e10cSrcweir}
486cdf0e10cSrcweir
487cdf0e10cSrcweir# verify_pose
488cdf0e10cSrcweir# timeout - timeout to wait for pose
489cdf0e10cSrcweir#
490cdf0e10cSrcweir#  Tries to do a connect/close to Pose to see if
491cdf0e10cSrcweir#  it is working okay.
492cdf0e10cSrcweir#
493cdf0e10cSrcweirsub verify_pose
494cdf0e10cSrcweir{
495cdf0e10cSrcweir  my $timeout = $_[0];
496cdf0e10cSrcweir  my $rc = 0;
497cdf0e10cSrcweir
498cdf0e10cSrcweir  $rc = system("$em_script_home/verify_sane.pl $timeout");
499cdf0e10cSrcweir  return $rc;
500cdf0e10cSrcweir}
501cdf0e10cSrcweir
502cdf0e10cSrcweir# db_export
503cdf0e10cSrcweir# dbname - Name of database to export
504cdf0e10cSrcweir#
505cdf0e10cSrcweir#  Exports a palmdb file to /tmp
506cdf0e10cSrcweir#
507cdf0e10cSrcweirsub db_export
508cdf0e10cSrcweir{
509cdf0e10cSrcweir  my $dbname = $_[0];
510cdf0e10cSrcweir
511cdf0e10cSrcweir  &enter_func("db_export");
512cdf0e10cSrcweir  print "\nExporting PDB file <$dbname> from pose\n";
513cdf0e10cSrcweir  &pose_tap_pen(22, 20, 2);
514cdf0e10cSrcweir  &pose_tap_pen (15, 85, 2);
515cdf0e10cSrcweir  &enter_string($dbname, 1);
516cdf0e10cSrcweir  &pose_tap_pen (15, 126, 1);
517cdf0e10cSrcweir  &enter_string("/tmp/", 1);
518cdf0e10cSrcweir  &pose_tap_button("OK", 4);
519cdf0e10cSrcweir  &tap_applications(3);
520cdf0e10cSrcweir  print "Export of PDB file <$dbname> completed.\n";
521cdf0e10cSrcweir  &leave_func("db_export");
522cdf0e10cSrcweir}
523cdf0e10cSrcweir
524cdf0e10cSrcweir#
525cdf0e10cSrcweir# QUICKWORD SPECIFIC
526cdf0e10cSrcweir#
527cdf0e10cSrcweir
528cdf0e10cSrcweir# start_quickword
529cdf0e10cSrcweir#
530cdf0e10cSrcweir# Assuming pose was launched with the -run_app flag to launch
531cdf0e10cSrcweir# QuickWord on startup, this starts up QuickWord with the first
532cdf0e10cSrcweir# file in the list and turns off write-protect.
533cdf0e10cSrcweir#
534cdf0e10cSrcweirsub start_quickword
535cdf0e10cSrcweir{
536cdf0e10cSrcweir  &enter_func("start_quickword");
537cdf0e10cSrcweir
538cdf0e10cSrcweir  # This will open the first file in the list.
539cdf0e10cSrcweir  # Assuming this will always be the case.
540cdf0e10cSrcweir  #
541cdf0e10cSrcweir  &pose_tap_pen(20, 18, 1);
542cdf0e10cSrcweir  &quickword_press_write_protect();
543cdf0e10cSrcweir
544cdf0e10cSrcweir  &leave_func("start_quickword");
545cdf0e10cSrcweir}
546cdf0e10cSrcweir
547cdf0e10cSrcweir# quickword_press_write_protect
548cdf0e10cSrcweir#
549cdf0e10cSrcweir# Useful function for pressing the write protect button
550cdf0e10cSrcweir# to allow changes to be made.
551cdf0e10cSrcweir#
552cdf0e10cSrcweirsub quickword_press_write_protect
553cdf0e10cSrcweir{
554cdf0e10cSrcweir  &enter_func("quickword_press_write_protect");
555cdf0e10cSrcweir
556cdf0e10cSrcweir  my ($form) = FrmGetActiveForm();
557cdf0e10cSrcweir  my ($num_objects) = FrmGetNumberOfObjects($form);
558cdf0e10cSrcweir
559cdf0e10cSrcweir  for $ii (0..$num_objects - 1)
560cdf0e10cSrcweir  {
561cdf0e10cSrcweir    my ($object_type) = FrmGetObjectType($form, $ii);
562cdf0e10cSrcweir
563cdf0e10cSrcweir    # The write protect button is the only frmGadgetObj
564cdf0e10cSrcweir    # on the QuickWord screen.
565cdf0e10cSrcweir    #
566cdf0e10cSrcweir    if ($object_type == frmGadgetObj)
567cdf0e10cSrcweir    {
568cdf0e10cSrcweir       my (%bounds) = FrmGetObjectBounds($form, $ii);
569cdf0e10cSrcweir
570cdf0e10cSrcweir       if ($global_debug)
571cdf0e10cSrcweir       {
572cdf0e10cSrcweir          &print_debug("  Found QuickWord WriteProtect button\n");
573cdf0e10cSrcweir          &print_debug("    left   = $bounds{left}\n");
574cdf0e10cSrcweir          &print_debug("    right  = $bounds{right}\n");
575cdf0e10cSrcweir          &print_debug("    top    = $bounds{top}\n");
576cdf0e10cSrcweir          &print_debug("    bottom = $bounds{bottom}\n");
577cdf0e10cSrcweir       }
578cdf0e10cSrcweir
579cdf0e10cSrcweir       # For some reason, the tapping of the write-protect button
580cdf0e10cSrcweir       # doesn't work unless you tap somewhere else first.
581cdf0e10cSrcweir       #
582cdf0e10cSrcweir       &pose_sleep(1);
583cdf0e10cSrcweir       &pose_tap_pen($bounds{left} + 2, $bounds{top} + 2, 1);
584cdf0e10cSrcweir       last;
585cdf0e10cSrcweir    }
586cdf0e10cSrcweir  }
587cdf0e10cSrcweir
588cdf0e10cSrcweir  &leave_func("quickword_press_write_protect");
589cdf0e10cSrcweir}
590cdf0e10cSrcweir
591cdf0e10cSrcweir# quickword_find_replace
592cdf0e10cSrcweir# from_string - string to replace
593cdf0e10cSrcweir# to_string - string to replace with
594cdf0e10cSrcweir#
595cdf0e10cSrcweir# Uses QuickWord's find/replace utility to replace
596cdf0e10cSrcweir# one string with another.
597cdf0e10cSrcweir#
598cdf0e10cSrcweirsub quickword_find_replace
599cdf0e10cSrcweir{
600cdf0e10cSrcweir  my $from_string = $_[0];
601cdf0e10cSrcweir  my $to_string   = $_[1];
602cdf0e10cSrcweir
603cdf0e10cSrcweir  &enter_func("quickword_find_replace");
604cdf0e10cSrcweir
605cdf0e10cSrcweir  # Move cursor to beginning...
606cdf0e10cSrcweir  #
607cdf0e10cSrcweir  &quickword_tap_at_top(1);
608cdf0e10cSrcweir
609cdf0e10cSrcweir  # Move to "Find" field:
610cdf0e10cSrcweir  # Triple-click to highlight all the text in the field,
611cdf0e10cSrcweir  # so it is removed when the string is entered...
612cdf0e10cSrcweir  #
613cdf0e10cSrcweir  &pose_tap_button("Find", 2);
614cdf0e10cSrcweir  &pose_tap_pen(50, 100, 0);
615cdf0e10cSrcweir  &pose_tap_pen(50, 100, 0);
616cdf0e10cSrcweir  &pose_tap_pen(50, 100, 1);
617cdf0e10cSrcweir
618cdf0e10cSrcweir  # sleep for 2 seconds to avoid double click after moving
619cdf0e10cSrcweir  # to replace field
620cdf0e10cSrcweir  #
621cdf0e10cSrcweir  &enter_string("$from_string", 2);
622cdf0e10cSrcweir
623cdf0e10cSrcweir  # Move to "Replace" field:
624cdf0e10cSrcweir  # Triple-click to highlight all the text in the field,
625cdf0e10cSrcweir  # so it is removed when the string is entered...
626cdf0e10cSrcweir  #
627cdf0e10cSrcweir  &pose_tap_pen(50, 120, 0);
628cdf0e10cSrcweir  &pose_tap_pen(50, 120, 0);
629cdf0e10cSrcweir  &pose_tap_pen(50, 120, 1);
630cdf0e10cSrcweir  &enter_string("$to_string", 1);
631cdf0e10cSrcweir
632cdf0e10cSrcweir  # Do find, then replace...
633cdf0e10cSrcweir  #
634cdf0e10cSrcweir  &pose_tap_button("Find", 1);
635cdf0e10cSrcweir  &pose_tap_button("Replace", 1);
636cdf0e10cSrcweir  &pose_tap_button("Cancel", 1);
637cdf0e10cSrcweir
638cdf0e10cSrcweir  &leave_func("quickword_find_replace");
639cdf0e10cSrcweir}
640cdf0e10cSrcweir
641cdf0e10cSrcweir# quickword_tap_at_top
642cdf0e10cSrcweir# secs - seconds to sleep after the tap
643cdf0e10cSrcweir#
644cdf0e10cSrcweir# Tap's at the top of the QuickWord document.
645cdf0e10cSrcweir#
646cdf0e10cSrcweirsub quickword_tap_at_top
647cdf0e10cSrcweir{
648cdf0e10cSrcweir  my $secs = $_[0];
649cdf0e10cSrcweir
650cdf0e10cSrcweir  &enter_func("quickword_tap_at_top");
651cdf0e10cSrcweir
652cdf0e10cSrcweir  # Sleep for a second to avoid any double-clicks
653cdf0e10cSrcweir  # from happening.
654cdf0e10cSrcweir  #
655cdf0e10cSrcweir  &pose_sleep(1);
656cdf0e10cSrcweir
657cdf0e10cSrcweir  &pose_tap_pen(0, 15, $secs);
658cdf0e10cSrcweir  &leave_func("quickword_tap_at_top");
659cdf0e10cSrcweir}
660cdf0e10cSrcweir
661cdf0e10cSrcweir# Saves file and returns to the Application list.
662cdf0e10cSrcweir#
663cdf0e10cSrcweirsub close_quickword
664cdf0e10cSrcweir{
665cdf0e10cSrcweir  &enter_func("close_quickword");
666cdf0e10cSrcweir
667cdf0e10cSrcweir  &pose_tap_button("Done", 2);
668cdf0e10cSrcweir  &tap_applications(2);
669cdf0e10cSrcweir
670cdf0e10cSrcweir  &leave_func("close_quickword");
671cdf0e10cSrcweir}
672cdf0e10cSrcweir
673cdf0e10cSrcweir#
674cdf0e10cSrcweir# MINICALC SPECIFIC
675cdf0e10cSrcweir#
676cdf0e10cSrcweir
677cdf0e10cSrcweir# start_minicalc
678cdf0e10cSrcweir#
679cdf0e10cSrcweir# Assuming pose was launched with the -run_app flag to launch
680cdf0e10cSrcweir# Minicalc on startup, this starts up Minicalc with the first
681cdf0e10cSrcweir# file in the list.
682cdf0e10cSrcweir#
683cdf0e10cSrcweirsub start_minicalc
684cdf0e10cSrcweir{
685cdf0e10cSrcweir  &enter_func("start_minicalc");
686cdf0e10cSrcweir  &pose_tap_button("OK", 1);
687cdf0e10cSrcweir
688cdf0e10cSrcweir  # For now just tap on the first spreadsheet.  Add support
689cdf0e10cSrcweir  # for multiple sheets later.
690cdf0e10cSrcweir  #
691cdf0e10cSrcweir  &pose_tap_pen(10, 40, 5);
692cdf0e10cSrcweir
693cdf0e10cSrcweir  &leave_func("start_minicalc");
694cdf0e10cSrcweir}
695cdf0e10cSrcweir
696cdf0e10cSrcweir# close_minicalc
697cdf0e10cSrcweir#
698cdf0e10cSrcweir# Returns to the Application list (no need to save).
699cdf0e10cSrcweir#
700cdf0e10cSrcweirsub close_minicalc
701cdf0e10cSrcweir{
702cdf0e10cSrcweir  &enter_func("close_minicalc");
703cdf0e10cSrcweir  &tap_applications(3);
704cdf0e10cSrcweir  &leave_func("close_minicalc");
705cdf0e10cSrcweir}
706cdf0e10cSrcweir
707cdf0e10cSrcweir# minicalc_enter_cell
708cdf0e10cSrcweir# row - row to enter value, starting with 1
709cdf0e10cSrcweir# col - column to enter value, starting with 1
710cdf0e10cSrcweir# val - value to enter
711cdf0e10cSrcweir#
712cdf0e10cSrcweir# Only valid for minicalc.
713cdf0e10cSrcweir#
714cdf0e10cSrcweir# This only works if the val passed in has a '\n' at the
715cdf0e10cSrcweir# end.
716cdf0e10cSrcweir#
717cdf0e10cSrcweirsub minicalc_enter_cell
718cdf0e10cSrcweir{
719cdf0e10cSrcweir  my $row = $_[0];
720cdf0e10cSrcweir  my $col = $_[1];
721cdf0e10cSrcweir  my $val = $_[2];
722cdf0e10cSrcweir  my $i;
723cdf0e10cSrcweir  my $j;
724cdf0e10cSrcweir
725cdf0e10cSrcweir  &enter_func("minicalc_enter_cell");
726cdf0e10cSrcweir
727cdf0e10cSrcweir  if ($global_debug)
728cdf0e10cSrcweir  {
729cdf0e10cSrcweir    &print_debug ("  tapping to cell row=<$row> col=<$col>\n");
730cdf0e10cSrcweir  }
731cdf0e10cSrcweir
732cdf0e10cSrcweir  # Tap pen on home button to start with row=1, col=A
733cdf0e10cSrcweir  # at top left.
734cdf0e10cSrcweir  #
735cdf0e10cSrcweir  pose_tap_pen(1, 1, 3);
736cdf0e10cSrcweir
737cdf0e10cSrcweir  # Now the cell should be in the top-left corner,
738cdf0e10cSrcweir  # so click there.  However we must first click
739cdf0e10cSrcweir  # in another cell or pose doesn't acknowledge the
740cdf0e10cSrcweir  # click.
741cdf0e10cSrcweir  #
742cdf0e10cSrcweir  # pose_tap_pen(120, 95, 1);
743cdf0e10cSrcweir  # pose_tap_pen(21, 9, 1);
744cdf0e10cSrcweir
745cdf0e10cSrcweir  # Click the down button once for each row.
746cdf0e10cSrcweir  # Must pause 3 seconds each time, otherwise MiniCalc
747cdf0e10cSrcweir  # will not keep up.
748cdf0e10cSrcweir  #
749cdf0e10cSrcweir  for ($i=0; $i < $row; $i++)
750cdf0e10cSrcweir  {
751cdf0e10cSrcweir    if ($global_debug)
752cdf0e10cSrcweir    {
753cdf0e10cSrcweir      &print_debug ("  Typing carrage return to go down\n");
754cdf0e10cSrcweir    }
755cdf0e10cSrcweir    enter_string("\n", 1);
756cdf0e10cSrcweir  }
757cdf0e10cSrcweir
758cdf0e10cSrcweir  # Click the right button once for each col.
759cdf0e10cSrcweir  # Must pause 3 seconds each time, otherwise MiniCalc
760cdf0e10cSrcweir  # will not keep up.
761cdf0e10cSrcweir  #
762cdf0e10cSrcweir  for ($i=0; $i < $col; $i++)
763cdf0e10cSrcweir  {
764cdf0e10cSrcweir    if ($global_debug)
765cdf0e10cSrcweir    {
766cdf0e10cSrcweir      &print_debug ("  Typing tab to go right\n");
767cdf0e10cSrcweir    }
768cdf0e10cSrcweir
769cdf0e10cSrcweir    enter_string("\t", 1);
770cdf0e10cSrcweir  }
771cdf0e10cSrcweir
772cdf0e10cSrcweir  # enter string
773cdf0e10cSrcweir  #
774cdf0e10cSrcweir  &enter_string($val, 1);
775cdf0e10cSrcweir
776cdf0e10cSrcweir  &leave_func("minicalc_enter_cell");
777cdf0e10cSrcweir}
778cdf0e10cSrcweir
779cdf0e10cSrcweir#
780cdf0e10cSrcweir# GENERIC UTILIIES (pose)
781cdf0e10cSrcweir#
782cdf0e10cSrcweir
783cdf0e10cSrcweir# tap_applications
784cdf0e10cSrcweir# secs - seconds to sleep after the tap
785cdf0e10cSrcweir#
786cdf0e10cSrcweir# taps pen on the Applications button.
787cdf0e10cSrcweir#
788cdf0e10cSrcweirsub tap_applications
789cdf0e10cSrcweir{
790cdf0e10cSrcweir  my $secs = $_[0];
791cdf0e10cSrcweir
792cdf0e10cSrcweir  &enter_func("tap_applications");
793cdf0e10cSrcweir
794cdf0e10cSrcweir  &pose_tap_pen(15, 170, 1);
795cdf0e10cSrcweir  &pose_tap_pen(155, 10, 1);
796cdf0e10cSrcweir  &pose_tap_pen(155, 10, $secs);
797cdf0e10cSrcweir
798cdf0e10cSrcweir  &leave_func("tap_applications");
799cdf0e10cSrcweir}
800cdf0e10cSrcweir
801cdf0e10cSrcweir# enter_string_at_location
802cdf0e10cSrcweir# x           - x-location to enter string
803cdf0e10cSrcweir# y           - y-location to enter string
804cdf0e10cSrcweir# in_string   - string to enter
805*07df5c71SJohn Bampton# application - application (QUICKWORD or MINICALC)
806cdf0e10cSrcweir#
807cdf0e10cSrcweir# Enters a string at the specified x,y position.
808cdf0e10cSrcweir#
809cdf0e10cSrcweirsub enter_string_at_location
810cdf0e10cSrcweir{
811cdf0e10cSrcweir  my $x_val       = $_[0];
812cdf0e10cSrcweir  my $y_val       = $_[1];
813cdf0e10cSrcweir  my $in_string   = $_[2];
814cdf0e10cSrcweir  my $application = $_[3];
815cdf0e10cSrcweir  my $x;
816cdf0e10cSrcweir  my $y;
817cdf0e10cSrcweir
818cdf0e10cSrcweir  &enter_func("enter_string_at_location");
819cdf0e10cSrcweir
820cdf0e10cSrcweir  $x = $x_val;
821cdf0e10cSrcweir  $y = $y_val;
822cdf0e10cSrcweir
823cdf0e10cSrcweir  if ($application eq "QUICKWORD")
824cdf0e10cSrcweir  {
825cdf0e10cSrcweir     # Allow users to specify TOP/BOTTOM/LEFT/RIGHT
826cdf0e10cSrcweir     # for QuickWord.
827cdf0e10cSrcweir     #
828cdf0e10cSrcweir     if ($y_val eq "TOP")
829cdf0e10cSrcweir     {
830cdf0e10cSrcweir        if ($global_debug)
831cdf0e10cSrcweir        {
832cdf0e10cSrcweir           &print_debug("  Converting TOP to 15\n");
833cdf0e10cSrcweir        }
834cdf0e10cSrcweir
835cdf0e10cSrcweir        $y = 15;
836cdf0e10cSrcweir     }
837cdf0e10cSrcweir     if ($y_val eq "BOTTOM")
838cdf0e10cSrcweir     {
839cdf0e10cSrcweir        if ($global_debug)
840cdf0e10cSrcweir        {
841cdf0e10cSrcweir           &print_debug("  Converting BOTTOM to 144\n");
842cdf0e10cSrcweir        }
843cdf0e10cSrcweir
844cdf0e10cSrcweir        $y = 144;
845cdf0e10cSrcweir     }
846cdf0e10cSrcweir     if ($x_val eq "LEFT")
847cdf0e10cSrcweir     {
848cdf0e10cSrcweir        if ($global_debug)
849cdf0e10cSrcweir        {
850cdf0e10cSrcweir           &print_debug("  Converting LEFT to 0\n");
851cdf0e10cSrcweir        }
852cdf0e10cSrcweir
853cdf0e10cSrcweir        $x = 0;
854cdf0e10cSrcweir     }
855cdf0e10cSrcweir     if ($x_val eq "RIGHT")
856cdf0e10cSrcweir     {
857cdf0e10cSrcweir        if ($global_debug)
858cdf0e10cSrcweir        {
859cdf0e10cSrcweir           &print_debug("  Converting RIGHT to 152\n");
860cdf0e10cSrcweir        }
861cdf0e10cSrcweir
862cdf0e10cSrcweir        $x = 152;
863cdf0e10cSrcweir     }
864cdf0e10cSrcweir  }
865cdf0e10cSrcweir
866cdf0e10cSrcweir  # Just to make sure the offset isn't outside the
867cdf0e10cSrcweir  # proper area.
868cdf0e10cSrcweir  #
869cdf0e10cSrcweir  if ($x >= 100)
870cdf0e10cSrcweir  {
871cdf0e10cSrcweir    $offset = -2;
872cdf0e10cSrcweir  }
873cdf0e10cSrcweir  else
874cdf0e10cSrcweir  {
875cdf0e10cSrcweir    $offset = 2;
876cdf0e10cSrcweir  }
877cdf0e10cSrcweir
878cdf0e10cSrcweir  &off_tap_pen($x, $y, $offset);
879cdf0e10cSrcweir  &enter_string($in_string, 1);
880cdf0e10cSrcweir
881cdf0e10cSrcweir  &leave_func("enter_string_at_location");
882cdf0e10cSrcweir}
883cdf0e10cSrcweir
884cdf0e10cSrcweir# off_tap_pen
885cdf0e10cSrcweir# x      - x-location to tap
886cdf0e10cSrcweir# y      - y-location to tap
887cdf0e10cSrcweir# offset - x-offset to use for first tap.
888cdf0e10cSrcweir#
889cdf0e10cSrcweir# For some reason, pose does not register a single
890cdf0e10cSrcweir# pen tap if the last single pen tap was also
891cdf0e10cSrcweir# at the same x,y coordinate (even if the last tap
892cdf0e10cSrcweir# was a while ago).  So this function does two
893cdf0e10cSrcweir# slightly different pen taps to ensure then pen
894cdf0e10cSrcweir# tap happens.
895cdf0e10cSrcweir#
896cdf0e10cSrcweirsub off_tap_pen
897cdf0e10cSrcweir{
898cdf0e10cSrcweir  my $x      = $_[0];
899cdf0e10cSrcweir  my $y      = $_[1];
900cdf0e10cSrcweir  my $offset = $_[2];
901cdf0e10cSrcweir
902cdf0e10cSrcweir  &enter_func("off_tap_pen");
903cdf0e10cSrcweir
904cdf0e10cSrcweir  # sleep for 2 seconds to avoid double-click.
905cdf0e10cSrcweir  #
906cdf0e10cSrcweir  &pose_tap_pen_hard($x + $offset, $y, 2);
907cdf0e10cSrcweir  &pose_tap_pen_hard($x, $y, 1);
908cdf0e10cSrcweir
909cdf0e10cSrcweir  &leave_func("off_tap_pen");
910cdf0e10cSrcweir}
911cdf0e10cSrcweir
912cdf0e10cSrcweir# enter_string
913cdf0e10cSrcweir# in_string - string to enter
914cdf0e10cSrcweir# secs - seconds to sleep after entering the string
915cdf0e10cSrcweir#
916cdf0e10cSrcweir# Enters a string
917cdf0e10cSrcweir#
918cdf0e10cSrcweirsub enter_string
919cdf0e10cSrcweir{
920cdf0e10cSrcweir  my $in_string = $_[0];
921cdf0e10cSrcweir  my $secs = $_[1];
922cdf0e10cSrcweir  my $j;
923cdf0e10cSrcweir
924cdf0e10cSrcweir  &enter_func("enter_string");
925cdf0e10cSrcweir
926cdf0e10cSrcweir  if ($global_debug)
927cdf0e10cSrcweir  {
928cdf0e10cSrcweir     # Display in_string so \n and \t values
929cdf0e10cSrcweir     # show up as normal ASCII.
930cdf0e10cSrcweir     #
931cdf0e10cSrcweir     if ($in_string eq "\n")
932cdf0e10cSrcweir     {
933cdf0e10cSrcweir        &print_debug("  Entering string     : <\\n>\n");
934cdf0e10cSrcweir     }
935cdf0e10cSrcweir     elsif ($in_string eq "\t")
936cdf0e10cSrcweir     {
937cdf0e10cSrcweir        &print_debug("  Entering string     : <\\t>\n");
938cdf0e10cSrcweir     }
939cdf0e10cSrcweir     else
940cdf0e10cSrcweir     {
941cdf0e10cSrcweir        &print_debug("  Entering string     : <$in_string>\n");
942cdf0e10cSrcweir     }
943cdf0e10cSrcweir  }
944cdf0e10cSrcweir
945cdf0e10cSrcweir  # Replace "\n" with real carrage returns.
946cdf0e10cSrcweir  #
947cdf0e10cSrcweir  my $string_val = $in_string;
948cdf0e10cSrcweir  $string_val =~ s#\\n#\n#g;
949cdf0e10cSrcweir
950cdf0e10cSrcweir  # Replace "\t" with a real tab.
951cdf0e10cSrcweir  #
952cdf0e10cSrcweir  $string_val =~ s#\\t#\t#g;
953cdf0e10cSrcweir
954cdf0e10cSrcweir  # Convert string to ASCII numeric values
955cdf0e10cSrcweir  #
956cdf0e10cSrcweir  my @array = unpack("C*", $string_val);
957cdf0e10cSrcweir
958cdf0e10cSrcweir  # Enter string one key at a time.
959cdf0e10cSrcweir  #
960cdf0e10cSrcweir  for ($j=0; $j <= $#array; $j++)
961cdf0e10cSrcweir  {
962cdf0e10cSrcweir     $queue_size = EnterKey($array[$j], 0, 0);
963cdf0e10cSrcweir  }
964cdf0e10cSrcweir
965cdf0e10cSrcweir  if ($secs > 0)
966cdf0e10cSrcweir  {
967cdf0e10cSrcweir     pose_sleep($secs);
968cdf0e10cSrcweir  }
969cdf0e10cSrcweir
970cdf0e10cSrcweir  &leave_func("enter_string");
971cdf0e10cSrcweir}
972cdf0e10cSrcweir
973cdf0e10cSrcweir#
974cdf0e10cSrcweir# GENERIC UTILIIES (non pose)
975cdf0e10cSrcweir#
976cdf0e10cSrcweir
977cdf0e10cSrcweir# get_date_string
978cdf0e10cSrcweir#
979cdf0e10cSrcweir# Returns a timestampe string in yyyymmddHHMM format, where:
980cdf0e10cSrcweir#   yyyy = year
981cdf0e10cSrcweir#   mm   = month
982cdf0e10cSrcweir#   dd   = day
983cdf0e10cSrcweir#   HH   = hour
984cdf0e10cSrcweir#   MM   = minute
985cdf0e10cSrcweir#
986cdf0e10cSrcweir# This sort of datestamp is used to create the output directory
987cdf0e10cSrcweir# names, so it used in various places.
988cdf0e10cSrcweir#
989cdf0e10cSrcweirsub get_date_string
990cdf0e10cSrcweir{
991cdf0e10cSrcweir    my $cur_secs  = time;
992cdf0e10cSrcweir    my @lu = localtime $cur_secs;
993cdf0e10cSrcweir    my $lu_secs  = $lu[1];
994cdf0e10cSrcweir    my $lu_hours = $lu[2];
995cdf0e10cSrcweir    my $lu_day   = $lu[3];
996cdf0e10cSrcweir    my $lu_mon   = $lu[4] + 1;
997cdf0e10cSrcweir    my $lu_year  = $lu[5] + 1900;
998cdf0e10cSrcweir    my $lu_str   = $lu_year;
999cdf0e10cSrcweir
1000cdf0e10cSrcweir    if ($lu_mon < 10)
1001cdf0e10cSrcweir    {
1002cdf0e10cSrcweir       $lu_str .= "0";
1003cdf0e10cSrcweir    }
1004cdf0e10cSrcweir    $lu_str .= $lu_mon;
1005cdf0e10cSrcweir
1006cdf0e10cSrcweir    if ($lu_day < 10)
1007cdf0e10cSrcweir    {
1008cdf0e10cSrcweir       $lu_str .= "0";
1009cdf0e10cSrcweir    }
1010cdf0e10cSrcweir    $lu_str .= $lu_day;
1011cdf0e10cSrcweir
1012cdf0e10cSrcweir    if ($lu_hours < 10)
1013cdf0e10cSrcweir    {
1014cdf0e10cSrcweir       $lu_str .= "0";
1015cdf0e10cSrcweir    }
1016cdf0e10cSrcweir    $lu_str .= $lu_hours;
1017cdf0e10cSrcweir
1018cdf0e10cSrcweir    if ($lu_secs < 10)
1019cdf0e10cSrcweir    {
1020cdf0e10cSrcweir       $lu_str .= "0";
1021cdf0e10cSrcweir    }
1022cdf0e10cSrcweir    $lu_str .= $lu_secs;
1023cdf0e10cSrcweir
1024cdf0e10cSrcweir    return $lu_str;
1025cdf0e10cSrcweir}
1026cdf0e10cSrcweir
1027cdf0e10cSrcweir#
1028cdf0e10cSrcweir# DEBUG FUNCTIONS - Wrapper functions
1029cdf0e10cSrcweir#
1030cdf0e10cSrcweir
1031cdf0e10cSrcweir# pose_tap_pen
1032cdf0e10cSrcweir# x    - x-position of pen tap
1033cdf0e10cSrcweir# y    - y-position of pen tap
1034cdf0e10cSrcweir# secs - seconds to sleep after the tap
1035cdf0e10cSrcweir#
1036cdf0e10cSrcweir# Taps pen at specified position and displays debug info
1037cdf0e10cSrcweir#
1038cdf0e10cSrcweirsub pose_tap_pen
1039cdf0e10cSrcweir{
1040cdf0e10cSrcweir  my $x           = $_[0];
1041cdf0e10cSrcweir  my $y           = $_[1];
1042cdf0e10cSrcweir  my $secs        = $_[2];
1043cdf0e10cSrcweir
1044cdf0e10cSrcweir  if ($global_debug)
1045cdf0e10cSrcweir  {
1046cdf0e10cSrcweir    &print_debug("  Tapping pen at      : $x,$y\n");
1047cdf0e10cSrcweir  }
1048cdf0e10cSrcweir
1049cdf0e10cSrcweir  TapPen($x, $y);
1050cdf0e10cSrcweir
1051cdf0e10cSrcweir  if ($secs > 0)
1052cdf0e10cSrcweir  {
1053cdf0e10cSrcweir     pose_sleep($secs);
1054cdf0e10cSrcweir  }
1055cdf0e10cSrcweir}
1056cdf0e10cSrcweir
1057cdf0e10cSrcweir# pose_tap_pen_hard
1058cdf0e10cSrcweir# x    - x-position of pen tap
1059cdf0e10cSrcweir# y    - y-position of pen tap
1060cdf0e10cSrcweir# secs - seconds to sleep after the tap
1061cdf0e10cSrcweir#
1062cdf0e10cSrcweir# Taps pen at specified position and displays debug info
1063cdf0e10cSrcweir# This function works more effectively in situations where
1064cdf0e10cSrcweir# pose_tap_pen is flakey.  This function is not good for
1065cdf0e10cSrcweir# double/triple click situations since it is slow.
1066cdf0e10cSrcweir#
1067cdf0e10cSrcweirsub pose_tap_pen_hard
1068cdf0e10cSrcweir{
1069cdf0e10cSrcweir  my $x           = $_[0];
1070cdf0e10cSrcweir  my $y           = $_[1];
1071cdf0e10cSrcweir  my $secs        = $_[2];
1072cdf0e10cSrcweir
1073cdf0e10cSrcweir  if ($global_debug)
1074cdf0e10cSrcweir  {
1075cdf0e10cSrcweir    &print_debug("  Tapping pen hard at : $x,$y\n");
1076cdf0e10cSrcweir  }
1077cdf0e10cSrcweir
1078cdf0e10cSrcweir  `$qa_script_home/tappen.pl $x $y`;
1079cdf0e10cSrcweir
1080cdf0e10cSrcweir  if ($secs > 0)
1081cdf0e10cSrcweir  {
1082cdf0e10cSrcweir     pose_sleep($secs);
1083cdf0e10cSrcweir  }
1084cdf0e10cSrcweir}
1085cdf0e10cSrcweir
1086cdf0e10cSrcweir# pose_tap_button
1087cdf0e10cSrcweir# button - button to press
1088cdf0e10cSrcweir# secs - seconds to sleep after the button press
1089cdf0e10cSrcweir#
1090cdf0e10cSrcweir# Presses specified button and displays debug info
1091cdf0e10cSrcweir#
1092cdf0e10cSrcweirsub pose_tap_button
1093cdf0e10cSrcweir{
1094cdf0e10cSrcweir  my $button = $_[0];
1095cdf0e10cSrcweir  my $secs = $_[1];
1096cdf0e10cSrcweir
1097cdf0e10cSrcweir  if ($global_debug)
1098cdf0e10cSrcweir  {
1099cdf0e10cSrcweir    &print_debug("  Tapping button      : $button\n");
1100cdf0e10cSrcweir  }
1101cdf0e10cSrcweir
1102cdf0e10cSrcweir  TapButton($button);
1103cdf0e10cSrcweir
1104cdf0e10cSrcweir  if ($secs > 0)
1105cdf0e10cSrcweir  {
1106cdf0e10cSrcweir     pose_sleep($secs);
1107cdf0e10cSrcweir  }
1108cdf0e10cSrcweir}
1109cdf0e10cSrcweir
1110cdf0e10cSrcweir# pose_sleep
1111cdf0e10cSrcweir# secs - seconds to sleep
1112cdf0e10cSrcweir#
1113cdf0e10cSrcweir# Sleeps the specified amount of time and displays debug info
1114cdf0e10cSrcweir#
1115cdf0e10cSrcweirsub pose_sleep
1116cdf0e10cSrcweir{
1117cdf0e10cSrcweir  my $secs = $_[0];
1118cdf0e10cSrcweir
1119cdf0e10cSrcweir  if ($global_debug)
1120cdf0e10cSrcweir  {
1121cdf0e10cSrcweir    &print_debug("  Sleeping            : $secs seconds\n");
1122cdf0e10cSrcweir  }
1123cdf0e10cSrcweir
1124cdf0e10cSrcweir  sleep($secs);
1125cdf0e10cSrcweir}
1126cdf0e10cSrcweir
1127cdf0e10cSrcweir# enter_func
1128cdf0e10cSrcweir# func - function name
1129cdf0e10cSrcweir#
1130cdf0e10cSrcweir# Displays debug info about entering specified function.
1131cdf0e10cSrcweir#
1132cdf0e10cSrcweirsub enter_func
1133cdf0e10cSrcweir{
1134cdf0e10cSrcweir  my $func = $_[0];
1135cdf0e10cSrcweir
1136cdf0e10cSrcweir  if ($global_debug)
1137cdf0e10cSrcweir  {
1138cdf0e10cSrcweir    &print_debug("Function enter        : $func\n");
1139cdf0e10cSrcweir  }
1140cdf0e10cSrcweir}
1141cdf0e10cSrcweir
1142cdf0e10cSrcweir# leave_func
1143cdf0e10cSrcweir# func - function name
1144cdf0e10cSrcweir#
1145cdf0e10cSrcweir# Displays debug info about leaving specified function.
1146cdf0e10cSrcweir#
1147cdf0e10cSrcweirsub leave_func
1148cdf0e10cSrcweir{
1149cdf0e10cSrcweir  my $func = $_[0];
1150cdf0e10cSrcweir
1151cdf0e10cSrcweir  if ($global_debug)
1152cdf0e10cSrcweir  {
1153cdf0e10cSrcweir    &print_debug("Function exit         : $func\n");
1154cdf0e10cSrcweir  }
1155cdf0e10cSrcweir}
1156cdf0e10cSrcweir
1157cdf0e10cSrcweir# print_debug
1158cdf0e10cSrcweir# string - string to print
1159cdf0e10cSrcweir#
1160cdf0e10cSrcweir# Displays debug message with a # at the beginning of the line.
1161cdf0e10cSrcweir#
1162cdf0e10cSrcweirsub print_debug
1163cdf0e10cSrcweir{
1164cdf0e10cSrcweir   my $string = $_[0];
1165cdf0e10cSrcweir
1166cdf0e10cSrcweir   print "# $string";
1167cdf0e10cSrcweir}
1168cdf0e10cSrcweir
1169cdf0e10cSrcweir1;
1170cdf0e10cSrcweir
1171