I agree, it's an ommission from the STR$ rtl if you ask me (I
know you didn't, but there it's done :-).
There is a solution, however, BAS$EDIT. I've included an old
post from Tom Wade (I think, there may have been other contributors
to that thread, Bart Z. Lederman being among them) discussing
BAS$EDIT, but I'll add that I've used it to good effect in some of
my code. It won't do a LOWERCASE and it won't do an UNCOMMMENT
which F$Edit can do, but it does COLLAPSE, COMPRESS, TRIM, and
UPCASE, as well as being able to separately TRIM_LEADING and
TRIM_TRAILING (to do TRIM, you'd combine TRIM_LEADING with
TRIM_TRAILING), and a few more esoteric functions.
As an example, here's a snippet that does a TRIM_LEADING with a
COMPRESS (the following call to STR$TRIM is used simply to return
the non-blank length of the string, which is why I omitted
TRIM_TRAIING from the BAS$EDIT call):
----------------------------------------------------------------------------
!+
! Use BAS$EDIT to delete leading white-space (8), compress embedded
! white-space (16). [Other options: (32) upcases all text; (128)
! trims trailing white-space.]
!-
CALL BAS$EDIT (THIS_SRC(1:LSRC), THIS_SRC(1:LSRC),
> %VAL(8+16))
CALL STR$TRIM (THIS_SRC, THIS_SRC(1:LSRC), LSRC)
----------------------------------------------------------------------------
Thanks Tom!
-Ken
--
Kenneth H. Fairfield | Internet: Fair...@Slac.Stanford.Edu
SLAC, P.O.Box 4349, MS 46 | DECnet: 45537::FAIRFIELD (45537=SLACVX)
Stanford, CA 94309 | Voice: 415-926-2924 FAX: 415-926-3515
-------------------------------------------------------------------------
These opinions are mine, not SLAC's, Stanford's, nor the DOE's...
===============================================================================
>So does fortran have a function (of VMS a library routine) that eliminates all
>embedded spaces in a string?
Well, the BASIC intrinsic function EDIT$ does this and a lot more besides.
The BASIC RTL routines are, like all HLL RTLs bundled with VMS, so you don't
need a BASIC license to use them. Here is a FORTRAN subroutine that removes
all spaces/tabs from a given string.
Subroutine ZAP_WHITESPACE (string)
Implicit None ! always always always .....
Character *(*) string
Call Bas$Edit (string, string, %Val (2))
End
You can therefore catenate your strings into one big one, and then zap the
spaces. Make sure you declare your target string length to be the sum of the
lengths of the source strings, as the removal of spaces takes place after
catenation (if not, then you will lose some string from the right).
The complete codes for BAS$EDIT are:
1 Trim parity bits.
2 Discard all spaces and tabs.
4 Discard CR, LF, FF, ESC, DEL, NUL.
8 Discard leading space/tab characters.
16 Reduce spaces and tabs to one space.
32 Convert lowercase to uppercase.
64 Convert [ to ( and ] to )
128 Discard trailing spaces and tabs.
256 Do not alter characters inside quotes.
Since they are bit positions, you can sum the values for cumulative effect
(e.g. 34 (=32+2) discards white space and converts lowercase to uppercase).
-------------------------------------------------------------------------------
Greetings,
I have received several messages in response to my last posting about calling
the BASIC EDIT$ function from other languages, asking where such things are
documented.
The documentation for the routine itself, and the arguments it requires,
are normally part of the language specific documentation set. I no longer
have a BASIC manual, as I don't use it anymore, but within BASIC, a HELP
EDIT$ gives information on this, and help is available on other routines
as well. The actual mapping of a BASIC EDIT$ call to BAS$EDIT is not
documented. What I did was to write the following program:
10 A$ = "A B C"
20 A$ = EDIT$ (A$, 2%)
30 End
and compile it using $ BASIC FILE /list /machine . This causes assembler
output to go into the listing file. From that listing, it is straightforward
to find the call to BAS$EDIT and what arguments are being passed, and in
what manner. In the above, it passed the address of the string descriptor
twice (one as input, one as output), and the integer argument by value.
Knowing this, one can call the routine from any language. The same should
apply to FORTRAN and PASCAL RTL routines as well, though I never had the need
to call PASCAL ones, and I tend to write in FORTRAN anyway.
Of course, there should really be an STR$EDIT just as there is an STR$LEFT
and STR$RIGHT, but in the meantime, this is a useful technique.
Regards
------------------------------------------------------------------------------
Tom Wade | Internet: T.W...@cc.ucd.ie (all domain mailers).
Speaker To VAXes | Bitnet: T_WADE@CCVAX
EuroKom | PSI-Mail: PSI%27243154000712::T.WADE
University College | DEC EASYnet: DECWRL::"t.w...@cc.ucd.ie" (VMS Mail)
Belfield | JANET: t.wade%ie.u...@UK.AC.EARN-RELAY
Dublin 4 | X400: [Address Exceeds 65536 byte buffer]
Ireland | Telex: (0500) 91178 UCD EI ("TO: WADE" at start)
--------------------+----------------------------------------------------------
Voice:+353-1-2697890| Official Disclaimer: "This is not a disclaimer"
Fax: +353-1-2838605| Unix .... Just say No !
-------------------------------------------------------------------------------
Don't think there is one (STR$EDIT would be real nice). Of course, the BASIC
runtime library has the EDIT$ function to do this, and you can call this from
a non-BASIC program as BAS$EDIT (language runtime libraries are included in
VMS, you only need a compiler license to compile source code). The following
Fortran code demonstrates:
------------------------------------------------
Program TEST
Implicit None
Character *20 text
Call Lib$Get_Input (text, 'Input string:')
Call Bas$Edit (text, text, %Val (80))
Call Lib$Put_Output (text)
End
-------------------------------------------------
The above is fine for VAX, but not for Alpha. It looks like the BASIC RTL is
non-native (even at V6.2), and you get an error message (even if linked with
/NONATIVE - perhaps someone can shed some light ?). Alternatively, pick up a
copy of STR-EDIT.FOR from ftp://kirk.eurokom.ie/str-edit.for which is a rewrite
of the Basic EDIT$ function (mail me if you don't have anonymous FTP).
------------------------------------------------------------------------------
Tom Wade | Internet: T.W...@vms.eurokom.ie (all domain mailers).
Network Manager | X400: g=tom;s=wade;o=eurokom;p=eurokom;a=eirmail400;c=ie
EuroKom | Tel: +353 (1) 283-0555
UCD Belfield | Fax: +353 (1) 283-8605
Dublin 4 | Disclaimer: This is not a disclaimer
Ireland | "Friends don't let friends do Unix !"
------------------------------------------------------------------------------
The language-specific RTL routines have not been documented since VMS V3.
--
Steve Lionel lio...@quark.enet.dec.com
Fortran Development http://www.digital.com/info/slionel.html
Digital Equipment Corporation http://ourworld.compuserve.com/homepages/
110 Spit Brook Road, ZKO2-3/N30 Steve_Lionel/
Nashua, NH 03062-2698 "Free advice is worth every cent"
For information on Digital Fortran 90, see http://www.digital.com/info/hpc/f90/
>Of course, the BASIC
>runtime library has the EDIT$ function to do this, and you can call
this from
>a non-BASIC program as BAS$EDIT (language runtime libraries are
included in
>VMS, you only need a compiler license to compile source code).
[snip]
>
>----------------------------------------------------------------------
-------
>Tom Wade | Internet: T.W...@vms.eurokom.ie (all domain
mailers).
>Network Manager | X400:
g=tom;s=wade;o=eurokom;p=eurokom;a=eirmail400;c=ie
>EuroKom | Tel: +353 (1) 283-0555
>UCD Belfield | Fax: +353 (1) 283-8605
>Dublin 4 | Disclaimer: This is not a disclaimer
>Ireland | "Friends don't let friends do Unix !"
>----------------------------------------------------------------------
-------
Since this is the case, why do we not get RTL manuals for all
languages? Or am I just missing some?
Dom
I've always used BAS$EDIT for that purpose. On Alpha/VMS, BASRTL is replaced by
DBASIC$RTL. The following C program shows how to call EDIT on both platforms.
(Tested with DECC 5.0 on Vax/VMS 6.1, Alpha/VMS 6.1).
-----------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <descrip.h>
#include <stsdef.h>
#pragma nostandard
#define STR_LENGTH 250
typedef struct dsc$descriptor_vs vs_descr;
#define VS_STRING(name,len) struct {\
short length;\
char body[len];\
vs_descr descr;\
} name = {0,"",{len,DSC$K_DTYPE_VT,DSC$K_CLASS_VS,(char*)&name.length}}
#define STRING(name) VS_STRING(name,STR_LENGTH)
#ifdef __alpha
#define EDIT DBASIC$EDIT
#else
#define EDIT BAS$EDIT
#endif
extern int EDIT (vs_descr *tgt, vs_descr *src, int flags);
#define EDIT_DISCARD_PARITY 1 /* Discards bit 7 */
#define EDIT_COLLAPSE 2 /* Discards spaces and tabs */
#define EDIT_DISCARD_FORMS 4 /* Discards cr, lf, ff, del, esc and nul */
#define EDIT_TRIM 8 /* Discards leading and trailing spaces and tabs */
#define EDIT_COMPRESS 16 /* Compresses multiple spaces and tabs to single spaces */
#define EDIT_UPCASE 32 /* Converts lowercase to uppercase */
#define EDIT_UNBRACKET 64 /* Converts [ and ] to ( and ) */
#define EDIT_TRAIL 128 /* Discards trailing spaces and tabs */
#define EDIT_QUOTE 256 /* Preserves characters within quotes */
main() {
int sts;
STRING(st1);
STRING(st2);
(void) printf("Str1> ");
(void) gets(st1.body);
st1.length = strlen(st1.body);
sts = EDIT(&st2.descr,&st1.descr,
EDIT_COMPRESS | EDIT_TRIM | EDIT_UPCASE | EDIT_QUOTE);
if (!$VMS_STATUS_SUCCESS(sts)) {
lib$signal(sts);
exit(EXIT_FAILURE);
}
st2.length = strlen(st2.body);
(void) printf("st2= '%s'\n",st2.body);
}
#pragma standard
-----------------------------------------------------
A sample run:
$ cc testedit
$ link testedit
$ run testedit
Str1> This is a "Test !"
st2= 'THIS IS A "Test !"'
$
--
!++
! Lennart Börjeson
! Front Capital Systems AB
! World Trade Centre, Kungsbron 1, box 70351
! S-107 24 Stockholm
! tel: +46-8-454 00 00, fax: +46-8-454 00 10
! email: lenn...@front.se
! PSImail: PSI%24037104026::LENNARTB
!--
> Since this is the case, why do we not get RTL manuals for all
> languages? Or am I just missing some?
Support ! There are hundreds and hundreds of language RTL routines.
Apperently DIGITAL does not want to document and support them. Many
of them are simple, but some of them are extremely context
dependent and could be generating a lot of faulty error-reports.
So using language RTL directly is undocumented and unsupported, but
work fine.
The unsupported is emphasized by that VAX and AXP compilers generate
different calls.
Arne
Arne Vajhøj local DECNET: KOPC::ARNE
Computer Department PSI: PSI%23831001354030::ARNE
Southern Denmark Business School Internet: AR...@KO.HHS.DK
WWW URL: http://www.hhs.dk/~arne/arne.html
Then how do we find out about them if they are not documented?
This BAS$EDIT was, I'm sure, just one good example.
Fred W. Bach , Operations Group | Internet: mu...@triumf.ca
TRIUMF (TRI-University Meson Facility) | Voice: 604-222-1047 loc 6327/6278
4004 WESBROOK MALL, UBC CAMPUS | FAX: 604-222-1074
University of British Columbia, Vancouver, B.C., CANADA V6T 2A3
Damien says " If you don't STAND for SOMETHING, you'll FALL for ANYTHING "
These are my opinions, which should ONLY make you read, think, and question.
They do NOT necessarily reflect the views of my employer or fellow workers.
We don't, unless we go browsing through compilation listings or stepping
through executables.
--------------------------------------------------------------------------------
Carl J Lydick | INTERnet: CA...@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL
Disclaimer: Hey, I understand VAXen and VMS. That's what I get paid for. My
understanding of astronomy is purely at the amateur level (or below). So
unless what I'm saying is directly related to VAX/VMS, don't hold me or my
organization responsible for it. If it IS related to VAX/VMS, you can try to
hold me responsible for it, but my organization had nothing to do with it.
I should have posted this originally, but I could have sworn my VMS
manuals once had BAS routines and even FOR routines. Now I have
neither. Anyone else?
Dom
They were listed and documented in the Version 3 era RTL doccos...
you all saved a set, right?
Lee K. Gleason N5ZMR
Control-G Consultants
gle...@mwk.com
You are remembering things from a previous life. VMS Version 3.x to
be just a little less than precise.
"VAX-11 Run-Time Library Language Support Reference Manual", order number
AA-J107B-TE, September 1982.
DEC ceased to document these routines as of VMS 4.0. Their use is no
longer supported.
--
*************************************************************************
* Here, there be dragons! *
* DRA...@CIS.CompuServe.Com *
* *
* Richard B. Gilbert *
*************************************************************************
: I should have posted this originally, but I could have sworn my VMS
: manuals once had BAS routines and even FOR routines. Now I have
: neither. Anyone else?
: Dom
You'll still find a few in the "OpenVMS Obsolete Features Manual". Some
formerly documented FOR$ routines were made obsolete in favor of OTS$ routines,
and are documented as such. They still exist so that code compiled way-back-
when will still run.
For those not obsolete, the documentation was intenionally pulled back at 3.0
or 4.0 or so, I can't recall for sure which.
------------------------------------------------------------------------------
Bob Koehler | CSC/SSD/MITG
rkoe...@csc.com |