From: SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 7-FEB-1994 09:05:31.19 To: EVERHART CC: Subj: Re: F$EDIT lexical From: bruce@ais.com (Bruce C. Wright) X-Newsgroups: comp.os.vms Subject: Re: F$EDIT lexical Message-Id: <1994Feb6.103453.6491@ais.com> Date: 6 Feb 94 10:34:53 GMT Organization: Applied Information Systems, Chapel Hill, NC Lines: 55 To: Info-VAX@CRVAX.SRI.COM X-Gateway-Source-Info: USENET In article <2j2bc9$4sr@gap.cco.caltech.edu>, eychaner@SUNCUB.BBSO.CALTECH.EDU ("Channel Energy") writes: > fairfield@slacvx.slac.stanford.edu writes: >>eychaner@SUNCUB.BBSO.CALTECH.EDU ("Channel Energy") writes: >>> Is there a system service/RTL routine that contains the function >>>of the F$EDIT lexical? >>[...] >>The following was posted by Tom Wade in August of last year >>[...] >>TW>Well, the BASIC intrinsic function EDIT$ does this and a lot more besides. >>TW>Here is a FORTRAN subroutine that removes all spaces/tabs from a string. > [...] >>TW>Character *(*) string >>TW>Call Bas$Edit (string, string, %Val (2)) > > (Yeah, LOTS of deletions.) > Simple question: I'm calling BAS$EDIT from C. I can get it to work > passing it fixed-length string descriptors (K_CLASS_S). Unfortunately, > the w_length part of the descriptor isn't updated, and the string is > padded with spaces (necessitating a call to STR$TRIM). When I pass it > a dynamic string descriptor (K_CLASS_D), it crashes with the message > "fatal internal error". What class of string descriptor should I be > passing it? (I don't have a BASIC or FORTRAN manual handy.) How are you using the string descriptor? If you are setting up the address portion of the dynamic string descriptor to point to a buffer explicitly allocated in your program, you will almost certainly crash unless you understand how the STR$ routines manage their memory. What you should do is to set the address portion of the descriptor to NULL and set the type to DSC$K_DTYPE_T and the class to DSC$K_CLASS_D and the length to 0 and then use routines like STR$COPY_DX or STR$COPY_R or others as appropriate to copy your data into the dynamic string. When you do it that way you don't have to be aware of how the string storage is allocated, and you won't crash when the STR$ routines try to free and reallocate storage that's allocated in your static data area or on your stack frame. Another technique that would probably work would be to set the string type to DSC$K_DTYPE_VT and allocate an extra length word in the string buffer area like a PL/I VARYING length string. Most of the user-level string manipulation routines will accept this type of string as well, although it's possible that BAS$EDIT won't because it expects to be called only from BASIC with compiler-generated strings. But if it uses the STR$ routines to extract and assign the string, it will work properly. (Note: the system services by and large don't accept DSC$K_DTYPE_VT strings, because the area pointed to by the address portion of the descriptor is the current length word followed by the string data, and most of the system services don't bother to analyze the string descriptor completely. But most of the RTL will accept DTYPE_VT strings). Using a DTYPE_VT string would allow the data to be allocated in your static area or on the stack and avoid the extra overhead of the dynamic string management (extra allocs/frees) if that happens to be important to your application (doing enough of this to take up too much time). Bruce C. Wright