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