1828317 Members
3598 Online
109976 Solutions
New Discussion

Re: CLI$ROUTINES.H

 
ram_47
Frequent Advisor

CLI$ROUTINES.H

I am trying to add the ability to read command line arguments in my program. Is there an example which I can refer to for doing this. I came across a header file which has routines for doing that but not sure how to do it.
39 REPLIES 39
David B Sneddon
Honored Contributor

Re: CLI$ROUTINES.H

ram,

if you do

$ SEARCH SYS$EXAMPLES:*.C CLI$

you will see there are three sample programs that
use the CLI routines. These may help.

Dave
Willem Grooters
Honored Contributor

Re: CLI$ROUTINES.H

In SYS$EXAMPLES: you will find a number of C programs you can use as a reference:

ACMEUTIL.C
GCU$BALANCER.C

(Besides HELP and the online documentation, SYS$EXAMPLES is a perfect source for examples (hence the name ;-)). Great part: All are buildable and run when compiled and linked according the documentation)

Willem
Willem Grooters
OpenVMS Developer & System Manager
Brian Reiter
Valued Contributor

Re: CLI$ROUTINES.H

Ram

Have a look at the CLI$PRESENT function. These coupled with a .CLD definition allow very easy to implement CLI.

I've attached a Pascal snipped which may help.


cheers

Brian
ram_47
Frequent Advisor

Re: CLI$ROUTINES.H

RE5::[VMSUSER] >search sys$examples:*.c cli$

******************************
SYS$COMMON:[SYSHLP.EXAMPLES]DISKMOUNT.C;1

unsigned int spawn_flag = CLI$M_NOWAIT;
RE5::[VMSUSER] >


Not sure what it means.
Brian Reiter
Valued Contributor

Re: CLI$ROUTINES.H


unsigned int spawn_flag = CLI$M_NOWAIT

is a flag for LIB$SPAWN to allow the subprocess to run in parallel rather than wait for it to complete.
David B Sneddon
Honored Contributor

Re: CLI$ROUTINES.H

ram,

Is that the entire output of the search command?
What version of VMS do you have?

Dave
Antoniov.
Honored Contributor

Re: CLI$ROUTINES.H

Hi Ram,
$ HELP CLI is your friend.

Antonio Vigliotti
Antonio Maria Vigliotti
ram_47
Frequent Advisor

Re: CLI$ROUTINES.H

Dave,

yes, that was all i got after the search command.

version - DEC C V5.6-003 on OpenVMS VAX V6.2
ram_47
Frequent Advisor

Re: CLI$ROUTINES.H

Antonio-

>HELP CLI
sorry no documentation on CLI.

Could you pl give me complete path.
Martin Vorlaender
Honored Contributor

Re: CLI$ROUTINES.H

Kris Clippeleyr
Honored Contributor

Re: CLI$ROUTINES.H

Ram,

VAX/VMS V6.2 & DEC C V5.7 (the versions you have) do not bring SYS$SHARE:SYS$STARLET_C.TLB (at least AFAIK).
I suggest upgrading the VAX to VMS version 7.3 and DEC C V6.4 (the latest for VAX/VMS), then you'll have all the declarations of the VMS specific routines like CLI$, LIB$, etc. siting in SYS$SHARE:SYS$STARLET_C.TLB.

I attach the CLI$ROUTINES.H file for you.

Regards,
Kris (aka Qkcl)

I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
ram_47
Frequent Advisor

Re: CLI$ROUTINES.H

Kris,

Does it imply that if i try to run an example for CLI it would fail since my version does not support CLI library?
Kris Clippeleyr
Honored Contributor

Re: CLI$ROUTINES.H

Ram,


Does it imply that if i try to run an example for CLI it would fail since my version does not support CLI library?


Not at all. The CLI$ routines are present in the OS. What I meant was that the text library SYS$SHARE:SYS$STARLET_C.TLB is probably not present on your system.
Older versions of the C compiler did not bring that file along. DEC C V6.4 does.

Regards,
Kris (aka Qkcl)
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
ram_47
Frequent Advisor

Re: CLI$ROUTINES.H


int status = 0;
const char* label = "input";
struct dsc$descriptor_s* entity;



entity->dsc$b_class = DSC$K_CLASS_S;
entity->dsc$b_dtype = DSC$K_DTYPE_T;
entity->dsc$w_length = strlen(label);
entity->dsc$a_pointer = label ;
status = CLI$PRESENT(entity);



what would be the value of 'status' after the CLI$PRESENT(entity) command is executed?
Brian Reiter
Valued Contributor

Re: CLI$ROUTINES.H

Depends if it was there or not.

Could get

CLI$_PRESENT = 261401

if 'input' was present,or

CLI$_ABSENT = 229872

if it wasn't there. Standard VMS error checks apply :) Gets more complex when looking for negated qualifiers though.
ram_47
Frequent Advisor

Re: CLI$ROUTINES.H

Even though the 'input' is present it returns a value that is different from
CLI$_PRESENT and CLI$_DEFAULTED. What could be the reason for this?
David B Sneddon
Honored Contributor

Re: CLI$ROUTINES.H

try const char* label = "INPUT";
i.e. in uppercase
Brian Reiter
Valued Contributor

Re: CLI$ROUTINES.H

Ram

Have you tried (from DCL) just entering

$exit

and see what comes out? This may prove helpful.

Antoniov.
Honored Contributor

Re: CLI$ROUTINES.H

/* Include status definition */
#include
/* I guess this is already declared *
#include

/* Set initial status */
int status = SS$_NORNAL;

/* Declare & allocate descripted var */
$DESCRIPTOR (entity, "input");



const char* label = "input";
struct dsc$descriptor_s* entity;

status = CLI$PRESENT(entity);
if (status == CLI$_PRESENT)
{
printf ("Entity present in command\n");
}
else if (status == CLI$_NEGATED)
{
printf ("Entity negated like /NOENTITY\n");
}
else if (status == CLI$_LOCPRES)
{
printf ("Entity present as local qual.\n");
}
else if (status == CLI$_LOCNEG)
{
printf ("Entity negated in loc.qualf.\n");
}
else if (status == CLI$_DEFAULTED)
{
printf ("Default value for entity\n");
}
else if (status == CLI$_ABSENT)
{
printf ("Entity not presenet\n");
}
else
{
printf ("Uhu, wrong software :-?\n");
}


Antonio Vigliotti
Antonio Maria Vigliotti
John Gillings
Honored Contributor

Re: CLI$ROUTINES.H

ram,

I'd recommend for C programs you use the standard argv & argc mechanisms, rather than the CLI routines. CLI is for implementing DCL style commands. They're very good for building a complex command syntax, but if all you want to do is read a few arguments, they're major overkill.

argv and argc work exactly the same way they do on any other Unix implementation.

A crucible of informative mistakes
ram_47
Frequent Advisor

Re: CLI$ROUTINES.H


#include
#include
#include /* Starlet (SYS$...) */
#include /* CLI function definitions */
#include /* CLI status codes */
#include /* CLI message definitions */
#include /* Lib routines (LIB$...) */

/* Set initial status */
int status = 1;

/* Declare & allocate descripted var */
const char* label = "input";
struct dsc$descriptor_s* entity;

void main(int argc, char *argv[])
{

$DESCRIPTOR (entity, "input");

status = CLI$PRESENT(entity);

if (status == CLI$_PRESENT){
printf ("Entity present in command\n");
}
else if (status == CLI$_NEGATED){
printf ("Entity negated like /NOENTITY\n");
}
else if (status == CLI$_LOCPRES){
printf ("Entity present as local qual.\n");
}
else if (status == CLI$_LOCNEG){
printf ("Entity negated in loc.qualf.\n");
}
else if (status == CLI$_DEFAULTED){
printf ("Default value for entity\n");
}
else if (status == CLI$_ABSENT){
printf ("Entity not presenet\n");
}
else{
printf ("Uhu, wrong software :-?\n");
}
}



I get an error -
%SYSTEM-F-ACCVIO, access violation, reason mask=01, virtual address=010E0009,
PC=0001B78D, PSL=03C00020
break on unhandled exception at SHARE$LIBRTL+106893
Volker Halle
Honored Contributor

Re: CLI$ROUTINES.H

Ram,

you need to pass the argument to CLI$PRESENT by descriptor, e.g.

status = CLI$PRESENT(&entity);

works for me...

Volker.
Antoniov.
Honored Contributor

Re: CLI$ROUTINES.H

Sorry Ram,
using $DESCRIPTOR macro, cc compiler is not able to recognize entity as structure so you must explicit declare by reference.

$DESCRIPTOR (entity, "input");
/* Look at & symbol */
status = CLI$PRESENT(&entity);

Reading HELP CLI documentation I found a new condition:
else if (status == CLI$_INVREQTYP)
{
printf ("Entity not presenet\n");
}

HTH
Antonio Vigliotti
Antonio Maria Vigliotti
ram_47
Frequent Advisor

Re: CLI$ROUTINES.H

I changed the call to 'CLI$PRESENT(&entity);' (included ampersand).

Here are 2 observations -

1 - Using 'else if (status == CLI$_INVREQTYP)' i get a message 'Uhu, wrong software :-?'
2 - Using 'else if (status == CLI$_ABSENT)' i get a message 'Entity not presenet'

what is the output you ppl get?