home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / whoami.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-19  |  2.1 KB  |  89 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: whoami.c,v 1.6 1995/10/19 10:39:40 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    whoami.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    29 Nov 1984
  9.  * Last update:
  10.  *        19 Oct 1995, DEC-C clean-compile.
  11.  *        18 Mar 1995, prototypes
  12.  *        30 Sep 1985, use SYS$GETJPIw in VMS 4.x
  13.  *        09 May 1985, return nonzero code if from system
  14.  *        01 Dec 1984
  15.  *
  16.  * Function:    Return to the caller all-or-part of the pathname by which
  17.  *        the main program was called.
  18.  *
  19.  * Arguments:    name    => buffer into which to return result (a null-ended
  20.  *              string, maximum length of 128).
  21.  *        opt    = option controlling use of $PARSE after the $GETJPI
  22.  *              which determines the image name:
  23.  *
  24.  *              0 - return full pathname.
  25.  *              1 - return name, less version
  26.  *              2 - return name, less type.
  27.  *              3 - return only the filename (for error reporting).
  28.  *              4 - return only the device+directory name
  29.  *
  30.  * Returns:    TRUE iff the image is run from a system directory
  31.  */
  32.  
  33. #include    <starlet.h>
  34. #include    <rms.h>
  35. #include    <jpidef.h>
  36. #include    <string.h>
  37.  
  38. #include    "rmsinit.h"
  39. #include    "whoami.h"
  40.  
  41. int    whoami (char *name, int opt)
  42. {
  43.     int    len;
  44.     char    buffer[NAM$C_MAXRSS];
  45.     /* Safe: $GETJPI returns at most 128 bytes */
  46.  
  47.     struct    {
  48.         short    buf_len,
  49.             code;
  50.         char    *buf_adr;
  51.         unsigned end_flag;
  52.         } itmlst;
  53.     struct    FAB    fab;
  54.     struct    NAM    nam;
  55.     char    esa[NAM$C_MAXRSS], *lo_, *hi_;
  56.  
  57.     memset (buffer, 0, sizeof(buffer));    /* clear buffer    */
  58.  
  59.     itmlst.buf_len = sizeof(buffer) - 1;
  60.     itmlst.code    = JPI$_IMAGNAME;
  61.     itmlst.buf_adr = buffer;
  62.     itmlst.end_flag = 0;
  63.  
  64.     sys$getjpiw (0,0,0, &itmlst, 0,0,0);
  65.  
  66.     rmsinit_fab (&fab, &nam, 0, buffer);
  67.     rmsinit_nam (&nam, 0, esa);
  68.     sys$parse (&fab);
  69.     lo_ = nam.nam$l_node;
  70.     if (opt == 1)
  71.         hi_ = nam.nam$l_ver;
  72.     else if (opt == 2)
  73.         hi_ = nam.nam$l_type;
  74.     else if (opt == 3)
  75.     {
  76.         lo_ = nam.nam$l_name;
  77.         hi_ = nam.nam$l_type;
  78.     }
  79.     else if (opt == 4)
  80.         hi_ = nam.nam$l_name;
  81.     else
  82.         hi_ = lo_ + nam.nam$b_esl;
  83.     strncpy (name, lo_, len = (hi_ - lo_));
  84.     name[len] = '\0';
  85.  
  86.     return (   (strncmp (nam.nam$l_dir, "[SYS", 4) == 0)    /* VMS 4.x */
  87.         || (strncmp (nam.nam$l_dev, "SYS$", 4) == 0));    /* VMS 3.x */
  88. }
  89.