Showing posts with label $ldirlist. Show all posts
Showing posts with label $ldirlist. Show all posts

Saturday, 16 June 2012

Undocumented feature - interrupt - part eight


Continuing from part seven where we looked at "989", I will now do a full summary of the known functionality that we've looked at in this series of posts...


Code Description Example Alternative
0File information
interrupt(0,"test.txt")
if ( $status < 0 )
  ;file doesn't exist
else
  list = $result
  name = $item("Name",list) ;"test"
  type = $item("Type",list) ;"txt"
  vers = $item("Version",list) ;""
  attr = $item("Attrib",list) ;"UUU"
endif
This doesn't seem to return any useful information now.


Could use:
$fileproperties or
$lfileproperties


These return lots more file information, but not the same.
2Extract filenameinterrupt(2,"C:\temp\test.txt")
filename = $result ;"test.txt"
Use string manipulation
(although interrupt takes 60% of the time)
3Extract file pathinterrupt(3,"C:\temp\test.txt")
filename = $result ;"C:\temp\"
Use string manipulation
(although interrupt takes 60% of the time)
5Working directoryinterrupt(5,"")
working = $result ;"C:\temp\"
Use:
$ldir
5Uniface "usys" directoryinterrupt(5,"USYS")
uniface = $result ;"C:\uniface\"
Use:
$fileproperties of "usys:"
6Concatenate file path$result "C:\temp"
interrupt(6,"test")
filepath = $result ;"C:\temp\test\"
Use string manipulation
(although interrupt takes 70% of the time)
7Parent directoryinterrupt(7,"C:\temp\test\")
parent = $result ;"C:\temp\"
Use string manipulation
(although interrupt takes 33% of the time)
10Directory listing (files)interrupt(10,"C:\temp")
list = $result ;"test.txt·;test2.txt"
count = $status ;2
Use:
$dirlist or
$ldirlist (with "FILE" topic)
11Directory listing (folders)interrupt(11,"C:\temp")
list = $result ;"test·;test2"
count = $status ;2
Use:
$dirlist or
$ldirlist (with "DIR" topic)
989Application focusinterrupt(989,"APPLFOCUS") No alternative
(doesn't seem to work anyway)
989Format string
$result "RPL"
interrupt(989,"FORMAT")
string = $result
Use string manipulation
(doesn't seem to work anyway)
989Undo gold characters$result "R·;P·!L"
interrupt(989,"UNDOGOLD")
string = $result ;"R;P!L"
Use:
$replace



It seems that the interrupt command isn't really very useful anymore.  The functionality has either been replaced by new Uniface functions, or can be achieved by string manipulation.  Given the performance improvements, it may be worth considering using interrupt if you are heavily handling file paths, but given the number of iterations needed to see the difference, I'd be surprised if this was ever worthwhile.


Given the numeric nature of the code, I'm sure that the unknowns (1, 4, 8 and 9) must do something too - I'd love to know what!  Probably some of 12-988 do something as well, so I'm sure there are some hidden gems within the interrupt command.  If you know of any, please let me know in the comments.

Friday, 15 June 2012

Undocumented feature - interrupt - part six



Continuing from part five where we looked at "7", "8" and "9"...



10 - Directory listing (files)


This sets $result to be a Uniface list of all the files in the specified directory.  It also sets $status to be the count of files returned, like this...


  interrupt(10,"C:\temp")
  list = $result
  count = $status


In my test case it sets $result to be "test.txt·;test2.txt" and $status to be 2.  At last, there's a nice Uniface function to replace this one; $ldirlist or $dirlist can be used.  These actually return folders and files by default, but you can specify the "FILE" topic to limit it.  Both of these methods allow you to use wildcards.  The functions do not return the number of files found, but as they do return the list, we can easily use $itemcount if you want this as well, like this...

  list = $ldirlist("C:\temp","FILE")
  count = $itemcount(list)


This is much cleaner code, very concise and readable.  So how does it perform, I hear you cry! I tested over 200,000 iterations...

  • interrupt = 00:17.10, 00:16.89, 00:16.96 (around 17 seconds)
  • $ldirlist = 00:14.68, 00:14.72, 00:14.67 (almost 15 seconds)

So there's not a lot in it, but it does performs better.  I think the alternative is definitely the way to go in this case.


11 - Directory listing (folders)


This sets $result to be a Uniface list of all the folders in the specified directory, similar to "10".  It also sets $status to be the count of folders returned, like this...


  interrupt(11,"C:\temp")
  list = $result
  count = $status

In my test case it sets $result to be "test·;test2" and $status to be 2.  Similarly $ldirlist or $dirlist can be used, but specifying the "DIR" topic this time, like this...

  list = $ldirlist("C:\temp","DIR")
  count = $itemcount(list)


Let's test the performance over 200,000 iterations again...

  • interrupt = 00:15.31, 00:15.30, 00:15.24 (over 15 seconds)
  • $ldirlist = 00:13.33, 00:13.37, 00:13.45 (over 13 seconds)

Again there's not a lot in it, but it does performs better.  I think the alternative is definitely the way to go in this case as well.


More unknowns


Having no indication of what they did, I ran some basic tests on the codes "12" to "988" (see the next post for why I stopped there).  Mostly it was pretty uninteresting, generally speaking they set $status to -1 and leave $result unaffected.  There were some that left $status unaffected as well, and most interestingly "18" sets $result to a blank string.  Unfortunately I couldn't work out anything more for any of them, but I'd like to investigate this further.


Summary: Numeric codes "10" and "11" are useful but have been replaced by $ldirlist and $dirlist which do the same thing, but better.  All the codes beyond that, seem to be useless.  Except "989" which we will tackle in the next post.