[Info-vax] A SYS$ version of F$EDIT
Arne Vajhøj
arne at vajhoej.dk
Sun Jun 2 11:29:08 EDT 2019
On 6/1/2019 8:55 PM, Arne Vajhøj wrote:
> On 5/31/2019 10:11 PM, John Reagan wrote:
>> Many people used to call BAS$EDIT from non BASIC code on VAX. It is
>> now called DBAS$EDIT in Alpha going forward. We use to document all
>> those language RTL entry points.
>
> So like:
>
> $ type edit.pas
> program edit(input,output);
>
> const
> COLLAPSE = 2;
> TRIM = 8 + 128;
> COMPRESS = 16;
> UPCASE = 32;
> QUOTE = 256;
>
> type
> varstr = varying[255] of char;
>
> [external]
> function dbasic$edit(%DESCR newstr : varstr;
> %DESCR oldstr : varstr;
> %IMMED editlist : integer) : integer; external;
>
> procedure test(s : varstr; editlist : integer);
>
> var
> res : varstr;
>
> begin
> dbasic$edit(res, s, editlist);
> writeln('|' + s + '| -> |' + res + '|');
> end;
>
> begin
> test('Test', UPCASE);
> test(' X ', TRIM);
> test('X X', COMPRESS);
> test('X X X', COLLAPSE);
> test(' x x x ', COMPRESS + TRIM + UPCASE);
> test('x x " x x " x x', COLLAPSE + UPCASE);
> test('x x " x x " x x', COLLAPSE + UPCASE + QUOTE);
> end.
> $ pas edit
> $ lin edit + sys$input/opt
> sys$share:dec$basrtl/share
> $
> run edit
> |Test| -> |TEST|
> | X | -> |X|
> |X X| -> |X X|
> |X X X| -> |XXX|
> | x x x | -> |X X X|
> |x x " x x " x x| -> |XX"XX"XX|
> |x x " x x " x x| -> |XX" x x "XX|
And in C:
$ type edit.c
#include <stdio.h>
#include <string.h>
#include <descrip.h>
const int COLLAPSE = 2;
const int TRIM = 8 + 128;
const int COMPRESS = 16;
const int UPCASE = 32;
const int QUOTE = 256;
struct varstr
{
short length;
char body[256];
};
int dbasic$edit(struct dsc$descriptor_vs *newstr,
struct dsc$descriptor_vs *oldstr,
int editlist);
void test(char *s, int editlist)
{
struct varstr res, temp;
struct dsc$descriptor_vs newdesc;
struct dsc$descriptor_vs olddesc;
strcpy(temp.body, s);
temp.length = strlen(s);
newdesc.dsc$w_maxstrlen = sizeof(res.body) - 1;
newdesc.dsc$b_dtype = DSC$K_DTYPE_VT;
newdesc.dsc$b_class = DSC$K_CLASS_VS;
newdesc.dsc$a_pointer = (char *)&res;
olddesc.dsc$w_maxstrlen = sizeof(temp.body) - 1;
olddesc.dsc$b_dtype = DSC$K_DTYPE_VT;
olddesc.dsc$b_class = DSC$K_CLASS_VS;
olddesc.dsc$a_pointer = (char *)&temp;
dbasic$edit(&newdesc, &olddesc, editlist);
res.body[res.length] = '\0';
printf("|%s| -> |%s|\n", s, res.body);
}
int main(int argc, char *argv[])
{
test("Test", UPCASE);
test(" X ", TRIM);
test("X X", COMPRESS);
test("X X X", COLLAPSE);
test(" x x x ", COMPRESS + TRIM + UPCASE);
test("x x \" x x \" x x", COLLAPSE + UPCASE);
test("x x \" x x \" x x", COLLAPSE + UPCASE + QUOTE);
return 0;
}
$ cc edit
$ lin edit + sys$input/opt
sys$share:dec$basrtl/share
$
$ run edit
|Test| -> |TEST|
| X | -> |X|
|X X| -> |X X|
|X X X| -> |XXX|
| x x x | -> |X X X|
|x x " x x " x x| -> |XX"XX"XX|
|x x " x x " x x| -> |XX" x x "XX|
Arne
More information about the Info-vax
mailing list