[Info-vax] C... the only winning move is not to play...

JohnF john at please.see.sig.for.email.com
Mon Feb 10 10:12:29 EST 2014


VAXman- wrote:
JohnF <john at please.see.sig.for.email.com> writes:
>>VAXman- wrote:
>>> I've encountered a VMS library call prototype that is incorrect.
>>> How can I override/overwrite the prototype in my source
>>> to make it correct?
>>> 
>>> OK.  The function is STR$CONCAT.
>>> somewhere VMS pre-V8.*, where it's WRONG, WRONG, WRONG...
>>> #define  str$concat  STR$CONCAT
>>> #ifdef __NEW_STARLET
>>> unsigned int str$concat(
>>>        void *destination_string,
>>>        void *source_string);
>>> 
>>> and later VMS versions, where it's workable,...
>>> #define  str$concat  STR$CONCAT
>>> #ifdef __NEW_STARLET
>>> unsigned int str$concat(
>>>        void *destination_string,
>>>        void *source_string_1,
>>>        __optional_params);
>>> Now, if you can include <str$routines.h> and make this go away,
>>> I'm wanting.
>>
>>Is that actual entry point uppercase?
>>You might (or might not) be able to get away with
>>something like
>>#define STR$CONCAT dummy
>>#include <str$routines.h>
>>whereby the prototype refers to a dummy() func.
>>Then
>>#undef STR$CONCAT
>>#redefine str$concat STR$CONCAT
>>and prototype the actual func any way you like.
> 
> Thanks John.  Here's the KLUDGE written in KLUDGE, errr... C.
> #define STR$CONCAT STR$CONCAT_badly_prototyped_in_STR$ROUTINES_header
> #include <str$routines.h>   // OpenVMS STR$ RTL prototype definitions
> #undef STR$CONCAT
> #define str$concat STR$CONCAT
> unsigned int str$concat(struct dsc$descriptor_s*,
> struct dsc$descriptor_s*, __optional_params);

Glad it worked for you. Sometimes you've
just got to out-stupid the machine:).

>>But I've got to ask: why would you/anybody use vms-specific
>>library stuff for ansi-standard functionality?
> 
> ANSI standard?  ANSI-C standard?  confusion? 

Not sure if that's a question or a comment.
  If the former, I kind of mean conforming to K&R, 2nd edition
of "The C Programming Language". There are later standards,
e.g., cc/standard=ansi89, but for maintaining old code it's
probably easier/safer to just stick with that unless you can't
for one reason or another.

>>Besides job security, that is?
>>I recall some code I became responsible for, where after
>>reading through several pages of rms stuff, it dawned on
>>me the guy could just have done an fopen()/fprintf()'s.
>>It was ridiculous to write it the way he did.
> 
> Maybe he wanted files that weren't streams?  Index files?

No, no, nothing vms-specific. I read the code,
including open and fab. No rabs.

> Perhaps, wanted
> to avoid the wrapper overhead to the real services below?
> I don't know nor do I care.
> I an writing VERY OpenVMS specific code.
> I don't want nor do I need the *IXisms.

Nothing I said, not strcat nor fopen/fprintf, is an x-ism.
All ansi standard, as above.
Works identically on vms, unix, windows, etc.
If not, the compiler can't call itself "C".

>>   I'm too lazy to look up what those optional args
>>might be doing for you, but the "real solution" here
>>is to replace str$concat() with ansi-standard strcat() 
>>wherever possible. Modulo job security, that is.
> 
> This has ABSOLUTELY NOTHING to do with JOB SECURITY.

I was just kidding around about all that.

> What's so difficult
> to fathom about OpenVMS STR$CONCAT that you'd have to resort to strcat()?
> And, FWIW, your beloved strcat() is really only STR$APPEND.  STR$CONCAT is
> capable of concatenating a number of strings into on string which is what
> the poorly prototyped STR$CONCAT definition is causing your beloved "C" to
> vomit.
> 
> When KLUDGE, errr... C, supports *dynamic* string descriptors and or the
> whole of the OpenVMS infrastructure used null terminated strings a la *IX,
> then, maybe, I'll use #include <strings.h>.  OpenVMS code should/must use
> OpenVMS interfaces.  I don't need wrappers of KLUDGE, errr... C making the
> code look *IX to appease the mindset that all the worlds the plain vanilla
> of *IX.
> 
> 
> The John way:

Nope...
  char *words[] = { "a", "is", ..., "\000" },
       *word, string[999]="\000";
  int length = 0;
  for ( word=words[0]; *word != '\000'; word++ ) {
    int len=strlen(word);
    if ( length+len >= 999 ) break; /* or realloc and cat */
    strcat(string,word); length+=len; }
Or you could alloc/realloc string if you don't like
that 999.
  But you already knew all that, right? You're just
intentionally making it look harder that necessary,
and maybe a little more vulgar than necessary, too
(note: gratuitous vulgarity can sometimes be a
giveaway as to what's going on).
  Maybe this is still harder than the str$concat way,
maybe not. But you're right that in this particular
case, I wouldn't personally have chosen to use
vms library stuff. Try an fao example instead
(note: f=formatted). I'd probably use it for some
of the more complicated stuff of that sort.
  
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> 
> main()
>  {
>    char *a = {"a"};
>    char *is = {"is"};
>    char *space = {" "};
>    char *f_bomb = {"fucking"};
>    char *C = {"kludge"};
>    char *kludge = {"C"};
>    char *exclamations = {"!!!"};
> 
>    char *dynstr;
> 
>    int length = strlen(kludge);
>    length += strlen(space);
>    length += strlen(is);
>    length += strlen(space);
>    length += strlen(a);
>    length += strlen(space);
>    length += strlen(f_bomb);
>    length += strlen(space);
>    length += strlen(C);
>    length += strlen(exclamations);
> 
>    dynstr = malloc (++length);
> 
>    strcat(dynstr,kludge);
>    strcat(dynstr,space);
>    strcat(dynstr,is);
>    strcat(dynstr,space);
>    strcat(dynstr,a);
>    strcat(dynstr,space);
>    strcat(dynstr,f_bomb);
>    strcat(dynstr,space);
>    strcat(dynstr,C);
>    strcat(dynstr,exclamations);
> 
>    printf("%s\n",dynstr);
>  }
> 
> The OpenVMS and VAXman way:
> 
> #define __NEW_STARLET new_and_improved_aint_that_much_better
> 
> #include <descrip.h>
> #include <lib$routines.h>
> #define STR$CONCAT STR$CONCAT_is_badly_prototyped_in_STR$ROUTINES_header
> #include <str$routines.h>       // OpenVMS STR$ RTL prototype definitions
> #undef STR$CONCAT
> #define str$concat STR$CONCAT
> unsigned int str$concat(struct dsc$descriptor_s*, struct dsc$descriptor_s*, __optional_params);
> 
> main()
>  {
>    $DESCRIPTOR(a,"a");
>    $DESCRIPTOR(is,"is");
>    $DESCRIPTOR(space," ");
>    $DESCRIPTOR(f_bomb,"fucking");
>    $DESCRIPTOR(C,"kludge");
>    $DESCRIPTOR(kludge,"C");
>    $DESCRIPTOR(exclamations,"!!!");
> 
>    struct dsc$descriptor_s dynstr = { 0, DSC$K_DTYPE_T, DSC$K_CLASS_D, 0 };
> 
>    STR$CONCAT(&dynstr,&kludge,&space,&is,&space,&a,&space,&f_bomb,&space,&C,&exclamations);
>    LIB$PUT_OUTPUT(&dynstr);
>  }

-- 
John Forkosh  ( mailto:  j at f.com  where j=john and f=forkosh )



More information about the Info-vax mailing list