Differences between revisions 17 and 35 (spanning 18 versions)
Revision 17 as of 2011-08-04 19:58:22
Size: 3740
Editor: KaiJaeger
Comment:
Revision 35 as of 2017-06-01 17:15:55
Size: 1385
Editor: KaiJaeger
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
<<TableOfContents>> = User Commands Int2Hex and Hex2Int =
Line 3: Line 3:
= User Command ADOC (Dyalog) =
Line 5: Line 4:
[[ADOC]] is a utility useful to generate documentation (semi-) automatically from class scripts as well as namespace scripts.
Line 7: Line 5:
Obviously it makes sense to make ADOC's services available as a User Command. Although Dyalog comes from two built-in user commands for converting a hex number into an integer and vice versa (`]ToHex` and `]FromHex`), `fromHex` is too limited to be really useful.
Line 9: Line 7:
This page offers a small class script `ADOC_UC.dyalog` which is designed to do exactly that.

== Assumptions ==
In order to make `ADOC` available as a user command the script `ADOC_UC.dyalog` ("UC" for User Command) attached to this page must go somewhere where Dyalog is able to find it. There are to options:

 * Move it into `Salt\Spice` inside the Dyalog installation folder. That's where the Dyalog User Commands are located.
 * Create a particular folder for your own User Commands.

Although the first option is certainly easier, it's actually the second one which is recommended. There are a couple of reasons:

 * Messing Dyalog scripts with your scripts is not a good idea.
 * When a new version of Dyalog arrives you are in trouble.
 * Having a separate folder for your own User Commands allows you to overwrite a Dyalog User Command with an improved version you are not going to loose in case of an update or a new version.

To make your own User Command folder work you have to do a couple of things:

 1. Add the folder to the SALT search path.
 1. Create another folder which is going to host the "real thing". A recommended name is "!UserCommandCode".
 1. Copy the script `ADOC.dyalog` from the [[ADOC]] page into that folder.
 1. Create a registry entry pointing to that new folder with the name `HKEY_CURRENT_USER\Software\Dyalog\Dyalog APL/W 12.1 Unicode\SALT\CodeFolder`

Note that the script attached to this page only deals with two issues:

 * Figure out what command the user wants to invoke, "Browse" or "List".
 * Find the real work horse and call it, see below.

In order to achieve that the script `ADOC_UC.dyalog` reads the `HKEY_CURRENT_USER\Software\Dyalog\Dyalog APL/W 12.1 Unicode\SALT\CodeFolder` from the Windows registry. It then tries to load the "real" ADOC script from that folder.

Note that not only our examples given on this page but also the code in `ADOC_UC.dyalog` all refer to version 12.1 Unicode of Dyalog. If your are using a different version of Dyalog of course you must change the script, otherwise it's not going to work.

== Samples ==
Given that the two different ADOC scripts went into the right folders, this would be a sample session:
For example, is one wishes to convert an error code returned by the Windows Task Scheduler:
Line 43: Line 10:
      ]?ADOC
"??" for general help, "?CMD" for more specific info on command CMD
      ]tohex 2147942667
* Command Execution Failed: must be 32 bits signed integer
}}}
Line 46: Line 14:
 Group Name Description
 ===== ==== ===========
 ADOC ADOC.Browse Creates full documentation and displayes it in the default browser.
        ADOC.HELP Displays help regarding ADOC.
        ADOC.List Prints syntax of all public stuff to the session.
With the excellent function `Hex` written and contributed by PhilLast - which is the internal engine of the two user commands - this can be avoided:
Line 52: Line 16:
      ]?ADOC.Browse
Command "ADOC.Browse". Syntax: 1 arguments; accepts switches -b=
Script location: ........\....\....\ADOC
{{{
      ]Int2hex 2147942667
8007010b
      ]Hex2Int 8007010b
2147942667
}}}
Line 56: Line 23:
Gathers information from a class script, compiles
an HTML page with these pieces of information
and displays it in your default browser.
This is Phil's underlying code:
Line 60: Line 25:
      ]?ADOC.List
Command "ADOC.List".
Script location: ........\...\...\ADOC

Prints a list with all sorts of information to the session
about all public stuff given in the script specified in the right argument

]ADOC.Help
Watch your browser

Shows extensive information about ADOC. It's basically doing `ADOC.Browse ADOC`.
{{{
      Hex←{
          ⎕IO←0 ⋄ ⎕ML←1
          t←0∊⊃⍬⍴0⍴⊂⍵
          a←⎕D,'abcdef',⎕D,6⍴⎕A
          t:a⌷⍨⊂⍉16⊥⍣¯1⊢⍵
          16⊥⍉16|a⍳⍵
    ⍝ ⍵ dec-number or hex-string
    ⍝ ← hex-string or dec-number
    ⍝ accepts hex as CAPS or small
    ⍝ returns hex as small
    ⍝ dec to hex is rank increasing
    ⍝ hex to dec is rank decreasing
      }
Line 75: Line 43:
[[attachment:ADOC_UC.zip | Download]] the script. [[attachment:Hex.dyalog | Download]] the script.
Line 77: Line 45:
== Version ==
The script is version 1.2.0 from 2011-08-04

Author: KaiJaeger

-- KaiJaeger <<DateTime(2011-08-04T19:54:50Z)>>
Authors: Logic=PhilLast, user command=KaiJaeger

User Commands Int2Hex and Hex2Int

Overview

Although Dyalog comes from two built-in user commands for converting a hex number into an integer and vice versa (]ToHex and ]FromHex), fromHex is too limited to be really useful.

For example, is one wishes to convert an error code returned by the Windows Task Scheduler:

      ]tohex 2147942667                              
* Command Execution Failed: must be 32 bits signed integer

With the excellent function Hex written and contributed by PhilLast - which is the internal engine of the two user commands - this can be avoided:

      ]Int2hex 2147942667                              
8007010b
      ]Hex2Int 8007010b
2147942667

This is Phil's underlying code:

      Hex←{
          ⎕IO←0 ⋄ ⎕ML←1
          t←0∊⊃⍬⍴0⍴⊂⍵
          a←⎕D,'abcdef',⎕D,6⍴⎕A
          t:a⌷⍨⊂⍉16⊥⍣¯1⊢⍵
          16⊥⍉16|a⍳⍵
    ⍝ ⍵ dec-number or hex-string
    ⍝ ← hex-string or dec-number
    ⍝   accepts hex as CAPS or small
    ⍝   returns hex as small
    ⍝   dec to hex is rank increasing
    ⍝   hex to dec is rank decreasing
      }

Download

Download the script.

Authors: Logic=PhilLast, user command=KaiJaeger


CategoryDyalogUserCommands

UserCommands/Hex (last edited 2019-05-30 07:48:57 by KaiJaeger)