ArborX


defstr

Longname: def ine str ing   Open the Documentation Legend
Released: not available 
Created: not available 
See also: addstr

Summary
Defines a new 3B2 string, or copies the contents of one string into a new string
Example extract

The example below shows a simple use of the ^wdb variable, along with ? macros, in a stripped down version of the script used in stuk.3ad to define the search/replace dialogue box.

 "ts", "320" 1
 $defstr 349,"@/ @|Search / Replace\n"<> 2
 $addstr 349,"--\n"<> 3
 $addstr 349,"Search for:\n"<> 4
 $addstr 349," ^_sr_s_str%1..40sn!?7,@\\\\%d\\\\!\n"<> 5
 $addstr 349,"Replace with (blank for Search only):\n"<> 6
 $addstr 349," ^_sr_r_str%0..40sn!?7,@\\\\%d\\\\!\n"<> 7
 $addstr 349,"Options: ^_sr_o_str%0..20snx!348!\n"<> 8
 $addstr 349,"--\n"<> 9
 $addstr 349,"|Keep above settings: ^_sr_k_keep%0..1B[Yes] [No]\n"<> 10
 $addstr 349,"--\n"<> 11
 $addstr 349,"|%2..1e [OK] [Cancel]"<> 12
 $defstr 348,"Search/Replace Options:\n"<> 13
 $addstr 348," t -- start from Top|@t\n"<> 14
 . . . . 15
 $addstr 348," num repeat num times\n"<> 16
 #if REGEXPS 17
 $addstr 348,"Standard search:\n"<> 18
 #endif 19
 $addstr 348," ? -- wildcard ? on|@?\n"<> 20
 $addstr 348," [ -- search/insert|@[\n"<> 21
 $addstr 348," ] -- search/append|@]\n"<> 22
 #if REGEXPS 23
 $addstr 348,"Regular expressions:\n"<> 24
 $addstr 348," r -- normal|@r\n"<> 25
 $addstr 348," x -- eXtended . matching|@x\n"<> 26
 #endif 27
 $wdb 349<> 28
 $^wdb----<> 29
 $?0^wdb trun 0<> 30
 $^blank=<> 31
 $?=^_sr_r_str,^blank /^_sr_s_str/^_sr_o_str^<> 32
 $?+^_sr_r_str,^blank /^_sr_s_str/^_sr_r_str/^_sr_o_str^<> 33

Syntax (SVNNA)
string:s The new string number to be defined or replaced by the contents of string2. There are cirtain string numbers available to users please refer to the stuk.3ad and Scripts chapter_en and the information below for more detail.
first_line:s The characters to be included in the first line of the string, if any.
extract:n
Ø|0  3B2 processes characters within extra_data. That is, \n is converted to a newline, \\ is a single backslash.
The characters within extra_data are not processed.
string:s The (new) string to be defined or replaced by the contents of string2.
old_string:s The (old) string being copied.

Most readers will be aware of the existence of the 3B2 strings file (stuk.3ad on normal UK systems). This contains all of 3B2's language-dependent strings and other user configurable strings. These strings define such things as 3B2's menus and dialogue boxes. By using defstr and addstr to define your own strings, you can either overwrite existing strings or define new strings, usually in order to describe menus and dialogue boxes from within a script.

Each string is known to 3B2 by a number. Certain ranges of numbers have been allocated as follows, and you will normally be interested in the range 350..399 (see last section of stuk.3ad for additional user definable string numbers). You can define your own new strings within this range without any danger of clashing with current or future versions of 3B2.

If you have used a user strings file (usually suser.3ad) to create new strings within the range 350. . .399 you must take care not to overwrite them from scripts within your documents. We suggest that scripts in a user file use strings 350..379 and scripts internal to a document use strings 380. . .389. Strings 390..399 are best reserved for 'temporary' user strings, i.e. those defined within a particular script which can be over-written by other scripts which are run on different occasions.

You can check if a string is non-empty by using getvar with a code of 31nnn, where nnn is the string number. This will get up to 80 characters from a string into a variable. If the string is empty the variable returned using getvar will be emptied of any contents that it had before getvar was run.

Example

This example copies the content of string number 1007 to string number 390.

 addstr 390,1007
Example

The simple example below uses getvar to determine the current operating mode and, depending on what it is, defines string no.390 with a macro that could appropriately be assigned to the keystroke +.

  1
 "ts", "389" 2
 $getvar 01505 "Mode"<> 3
 $defstr 390,""<> 4
 $?=^Mode addstr 390,"tdpctrl\n" }end<> 5
 $^Mode- -<> 6
 $?=^Mode addstr 390,"tfbgc\n" }end<> 7
 $^Mode- -<> 8
 $?=^Mode addstr 390,"tic\n" }end<> 9
 $^Mode- -<> 10
 $?=^Mode addstr 390,"tgfcol\n" }end<> 11
 $:end<> 12
 $trun 390<> 13
4
String header. (In this illustration the script is shown as if it was set in an suser.3ad file).
6
Use getvar to obtain a numeric code, from 0..3, for the current operating mode.
8
Define an empty string no.390.
10
If the ^Mode variable has a value of 0, then assign macro to be accessed from Document Mode, and jump to the label on line 11.
12
Decrease the value of the ^Mode variable by 1. If getvar had returned a value of 1, the new value will be 0, allowing the next line to be run, and so on. Decreasing the value of a variable in this way is efficient and allows simpler tests than for a specific value.
11
The target label for lines 4, 6, 8 and 10.
12
Run the script that has just been define.

Document created on 2-Apr-2003 (revision 001)