Pages

Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Monday, November 23, 2009

AutoIt script to execute on key combination event

     For the Programming section of SecurityOverride, you are required to make a script to resolve a task, given a random input, in a short time, 10-15 seconds.  The method I've used for all the challenges:  I've written an AutoIt  script that:
  • stays active when run
  • after a keyboard combination is pressed:
    • copies the selected text into clipboard
    • gets it, and executes a function on it
    • puts the result in the clipboard
Example for challenge1:


         In order to complete Programming Challenge 1, you must code a script that will reverse the string below, while maintaining the first letter at the beginning.
         Example: chicken -> cnekcih


#comments-start
#comments-start
 ;---------------------------------------
 Autorun program on Ctrl+C event (for SecurityOverride programming)
 ;---------------------------------------
#comments-end 

HotKeySet("^{F1}", "Solve")
Global $input

While 1
 Sleep(10000)
WEnd


Func Solve()
 GetInput()
 ParseInput()
 Exit(0)
EndFunc

Func GetInput()
 Send("^{c}")
 $input = ClipGet()
EndFunc

Func ParseInput()  
 Local $a = StringToASCIIArray($input)
 Local $len = StringLen($input)
 Local $i, $j = 1
 Dim $rez[$len]
 
 $rez[0] = $a[0]
 For $i = $len-1 to 1 Step -1
   $rez[$j] = $a[$i]
   $j = $j + 1
 Next
 
 ClipPut(StringFromASCIIArray($rez))
EndFunc

; cnekcih


References: 

  1. AutoIt official site
  2. Scite IDE for AutoIt3
  3. Great site: SecurityOverride

Tuesday, September 29, 2009

Script to find diff between labels in ClearCase

     A simple bash script, using cleartool,  to show files that have the new label, but not the old one. Supposedly modified files are label correctly with new label, the script will show the files modified between two labels, in ClearCase. It will also show the creator of the new version. There is also a grep with regular expression filter on the output, to show only the files with .c, .cpp, .h, ... extensions.

#! /bin/bash
# Script to show diffs between 2 ClearCase labels

#cleartool location
export CT=/usr/atria/bin/cleartool

function usage() {
 echo "Usage: cc_dif.sh <new_label> <old_label>"
 exit
}

if [ $# -ne 2 ] ; then
 usage
 exit
else
 echo -e "\t-- New label: $1 --"
 echo -e "\t-- Old label: $2 --\n"
fi

${CT} find . -version "{(lbtype($1) && ! lbtype($2))}" -exec 'cleartool describe -fmt "%Xn \t\tBy: %Fu (%Lu) \n" $CLEARCASE_PN' | grep -E '.*\.(c|cpp|h|hpp|xml)@' 


References:
  • cleartool find man page (cand also be accessed with cleartool man find )
  • cleartool describe man page
  • format to apply to describecommand:  fmt_ccase  
  • Useful regexp filters, this post
Hope it will be useful for others too. If you used other methods to do this, leave a comment:)