Example #1
0
/*
** Writes the hostname of the current system in string "hostname".
**
** NOTE: This function used to be called "GetHostName" but that resulted in a 
** linking conflict on VMS with the standard gethostname function, because
** VMS links case-insensitively.
*/
const char
*GetNameOfHost(void)
{
    static char hostname[MAXNODENAMELEN+1];
    static int  hostnameFound = False;
    
    if (!hostnameFound) {
#ifdef VMS
        /* This should be simple, but uname is not supported in the DEC C RTL and
           gethostname on VMS depends either on Multinet or UCX.  So use uname 
           on Unix, and use LIB$GETSYI on VMS. Note the VMS hostname will
           be in DECNET format with trailing double colons, e.g. "FNALV1::".    */
        int syi_status;
        struct dsc$descriptor_s *hostnameDesc;
        unsigned long int syiItemCode = SYI$_NODENAME;	/* get Nodename */
        unsigned long int unused = 0;
        unsigned short int hostnameLen = MAXNODENAMELEN+1;

        hostnameDesc = NulStrWrtDesc(hostname, MAXNODENAMELEN+1);
        syi_status = lib$getsyi(&syiItemCode, &unused, hostnameDesc, &hostnameLen,
    			        0, 0);
        if (syi_status != SS$_NORMAL) {
	    fprintf(stderr, "nedit: Error return from lib$getsyi: %d", syi_status);
	    strcpy(hostname, "VMS");
        } else
    	    hostname[hostnameLen] = '\0';
        FreeStrDesc(hostnameDesc);
#else
        struct utsname nameStruct;
        int rc = uname(&nameStruct);
        if (rc<0) {
            /* Shouldn't ever happen, so we better exit() here */
           perror("nedit: uname() failed ");
           exit(EXIT_FAILURE);
        }
        strcpy(hostname, nameStruct.nodename);
#endif /* VMS */
        hostnameFound = True;
    }
    return hostname;
}
Example #2
0
/*
** Re-read the command line and convert it from VMS style to unix style.
** Replaces argv and argc with Unix-correct versions.  This is
** a poor solution to parsing VMS command lines because some information
** is lost and some elements of the syntax are not checked.  Users also
** can't abbreviate qualifiers as is customary under VMS.
*/
void ConvertVMSCommandLine(int *argc, char **argv[])
{
    int i;
    short cmdLineLen;
    char *c, cmdLine[MAX_CMD_LENGTH], *oldArg0;
    struct dsc$descriptor_s *cmdLineDesc;

    /* get the command line (don't use the old argv and argc because VMS
       has removed the quotes and altered the line somewhat */
    cmdLineDesc = NulStrWrtDesc(cmdLine, MAX_CMD_LENGTH);
    lib$get_foreign(cmdLineDesc, 0, &cmdLineLen, 0);
    FreeStrDesc(cmdLineDesc);
    
    /* begin a new argv and argc, but preserve the original argv[0]
       which is not returned by lib$get_foreign */
    oldArg0 = (*argv)[0];
    *argv = (char **)malloc(sizeof(char *) * MAX_ARGS);
    (*argv)[0] = oldArg0;
    *argc = 1;

    /* scan all of the text on the command line, reconstructing the arg list */
    for (i=0, c=cmdLine; i<cmdLineLen; c++, i++) {
	if (*c == '\t') {
	    addArgChar(argc, *argv, ' ');
	} else if (*c == '/') {
	    addArgChar(argc, *argv, ' ');
	    addArgChar(argc, *argv, '-');
	} else if (*c == '=') {
	    addArgChar(argc, *argv, ' ');
	} else if (*c == ',') {
	    addArgChar(argc, *argv, ' ');
	} else {
	    addArgChar(argc, *argv, *c);
	}
    }
    addArgChar(argc, *argv, ' ');
}