Esempio n. 1
0
File: dfu.c Progetto: rroart/freevms
void clean_ctrlc()
/* Cleanup CTRLC channel */

{
    struct
    {
        short status, count;
        int extra ;
    } iosb;
    unsigned int t_mask[2];
#if 0

    status = SYS$QIOW(0,tchan, IO$_SETMODE,0,0,0,&orgttchar,12,0,0,0,0);
    if (!smg$enable)
        status = SYS$QIOW(0,tchan,(IO$_SETMODE+IO$M_OUTBAND),&iosb,
                          0,0,0,0,0,0,0,0);
    else
    {
        t_mask[0] = 0;
        t_mask[1] = 1 << 23;
        status = SYS$QIOW(0,tchan,(IO$_SETMODE+IO$M_OUTBAND),&iosb,
                          0,0,refresh,&t_mask,0,0,0,0);
    }
#endif
    status = 1;
}
Esempio n. 2
0
File: spawn.c Progetto: ytoto/uemacs
/*
 * Run a command. The "cmd" is a pointer to a command string, or NULL if you
 * want to run a copy of DCL in the subjob (this is how the standard routine
 * LIB$SPAWN works. You have to do wierd stuff with the terminal on the way in
 * and the way out, because DCL does not want the channel to be in raw mode.
 */
int sys(char *cmd)
{
	struct dsc$descriptor cdsc;
	struct dsc$descriptor *cdscp;
	long status;
	long substatus;
	long iosb[2];

	status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
			  oldmode, sizeof(oldmode), 0, 0, 0, 0);
	if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
		return FALSE;
	cdscp = NULL;		/* Assume DCL.          */
	if (cmd != NULL) {	/* Build descriptor.    */
		cdsc.dsc$a_pointer = cmd;
		cdsc.dsc$w_length = strlen(cmd);
		cdsc.dsc$b_dtype = DSC$K_DTYPE_T;
		cdsc.dsc$b_class = DSC$K_CLASS_S;
		cdscp = &cdsc;
	}
	status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
	if (status != SS$_NORMAL)
		substatus = status;
	status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
			  newmode, sizeof(newmode), 0, 0, 0, 0);
	if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
		return FALSE;
	if ((substatus & STS$M_SUCCESS) == 0)	/* Command failed.      */
		return FALSE;
	return TRUE;
}
Esempio n. 3
0
static int put ( io_channel chan, char *buffer, int length )
{
    int status;
    struct io_status iosb;
    status = SYS$QIOW ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0,
	buffer, length, 0, 0, 0, 0 );
    if ( (status&1) == 1 ) status = iosb.status;
    return status;
}
Esempio n. 4
0
/* Decnet I/O routines.
 */
static int get ( io_channel chan, char *buffer, int maxlen, int *length )
{
    int status;
    struct io_status iosb;
    status = SYS$QIOW ( 0, chan, IO$_READVBLK, &iosb, 0, 0,
	buffer, maxlen, 0, 0, 0, 0 );
    if ( (status&1) == 1 ) status = iosb.status;
    if ( (status&1) == 1 ) *length = iosb.count;
    return status;
}
Esempio n. 5
0
File: dfu.c Progetto: rroart/freevms
        /* Get next line */
        cip = 0;
#if 1
        if (smg$enable)
        {
            SMG$ERASE_LINE(&disp2_id, &i1, &i1);
            SMG$SET_CURSOR_ABS(&disp2_id,&i1,&i1);
            status = SMG$READ_COMPOSED_LINE(&keyb_id,&key_tab,&input_line,
                                            &prompt,&out_len,&disp2_id,0,0,0,0,0); /*Get next command */
            cip = 1;
        }
        else
            status = SMG$READ_COMPOSED_LINE(&keyb_id,0,&input_line,
                                            &prompt,&out_len,0,0,0,0,0,0); /*Get next command */
#else
        printf("%s",prompt.dsc$a_pointer);
        out_len = read(0,command_line,254);
        out_len--;
        command_line[out_len]=0;
        if (strncmp(command_line,"exit",4)==0)
            return 0;
#endif
    }
}  /* END of MAIN */
int help_command(int mask)
/*	HELP

	Purpose : call on-line help
	Output  : contents of DFUHLP helplib.
*/
{
    unsigned int x,flag=1,tmp=0;
#if 0
    static char help[80];
    $DESCRIPTOR(help_key ,help);
    $DESCRIPTOR(help_item, "helpkey");
    $DESCRIPTOR(help_lib,"dfuhlp");
    $DESCRIPTOR(item,"DFU ");
    $DESCRIPTOR(hlp_txt,"< DFU Help Screen >");

    /* Check if a help item was entered */
    if (cli$present(&help_item) == CLI$_PRESENT)
        cli$get_value(&help_item,&help_key,&help_key);
    else
        help_key.dsc$w_length=0;

    /* Add 'DFU ' to the help key */
    help_key.dsc$w_length +=4;
    str$concat(&help_key,&item,&help_key);
    x = rows - 4;
    /* Reenable line editing... */
    status = SYS$QIOW(0,tchan, IO$_SETMODE,0,0,0,&orgttchar,12,0,0,0,0);
    if (smg$enable)
    {
        SMG$CREATE_VIRTUAL_DISPLAY(&x, &colls, &help_id, 0 , 0, 0);
        SMG$LABEL_BORDER(&help_id, &hlp_txt, 0, 0,&SMG$M_BOLD);
        SMG$PASTE_VIRTUAL_DISPLAY(&help_id, &paste_id, &i2,&i2,0);
        status = SMG$PUT_HELP_TEXT(&help_id, &keyb_id, &help_key, &help_lib,0,0);
        SMG$UNPASTE_VIRTUAL_DISPLAY(&help_id, &paste_id);
        SMG$DELETE_VIRTUAL_DISPLAY(&help_id);
    }
    else
        status = lbr$output_help(lib$put_output,0,&help_key,
                                 &help_lib,&flag,lib$get_input);
    if (status != SS$_NORMAL)
    {
        sprintf(outbuf,"%%DFU-E-HELPERR, Error opening help library,");
        put_disp();
        singlemsg(0,status);
    }
#endif
    return(1);
} /*END help_command */
Esempio n. 6
0
File: dfu.c Progetto: rroart/freevms
void reset_ctrl(void)
/* Reset CTRLC/Y on the terminal channel */

{
#if 0
    int stat, func;
    struct
    {
        short status, count;
        int extra ;
    } iosb;
    unsigned int t_mask[2];

    /* Disable the F6 key */
    status = SYS$QIOW(0,tchan, IO$_SETMODE,0,0,0,&ttchar,12,0,0,0,0);
    ctrlc = 0;
    /* Enable CTRLC/Y trapping by setting CTRL C and Y as out-of-band chars*/
    t_mask[0] = 0;
    t_mask[1] = 1 << 3;
    t_mask[1] += (1 << 25);
    status = SYS$QIOW(0,tchan,(IO$_SETMODE+IO$M_OUTBAND),&iosb,
                      0,0,astrtn,&t_mask,0,0,0,0);
#endif
}
Esempio n. 7
0
PUBLIC BYTE GetAKey()
{
   BYTE c;

#ifdef SUN
   if ( TermMode == ORG_MODE )
      {
	 CurMode.c_iflag &= ~ICRNL;
	 CurMode.c_lflag &= ~(ICANON | ECHO);
	 CurMode.c_cc[VTIME] = 0;
	 CurMode.c_cc[VMIN] = 1;
	 ioctl( 0, TCSETS, &CurMode );
	 TermMode = GET_MODE;
      }
   else
      if ( TermMode == POLL_MODE )
	 {
	 CurMode.c_cc[VTIME] = 0;
	 CurMode.c_cc[VMIN] = 1;
	 ioctl( 0, TCSETS, &CurMode );
	 TermMode = GET_MODE;
	 }
   (void)read(0, &c, 1);
#endif
#ifdef MSC
   c = getch();
#endif
#ifdef HELIOS
   if ( TermMode == ORG_MODE )
      {
	 RemoveAttribute(&CurAttributes,ConsoleEcho);
	 AddAttribute(&CurAttributes,ConsoleRawInput);
	 SetAttributes(InputStream,&CurAttributes);
	 TermMode = GET_MODE;
      }
   (void)Read(InputStream, &c, 1, -1);
#endif
#ifdef VMS
    (void)SYS$QIOW(0, InputChan, (IO$_READVBLK | IO$M_NOECHO | IO$M_NOFILTR ), &iosb_desc, 0, 0, &c, 1, 0, 0L, 0, 0);
#endif

   return(c);
}
Esempio n. 8
0
int rlSerial::writeChar(unsigned char uchar)
{
#ifdef RLUNIX
  int ret;
  if(fd == -1) return -1;
  if(trace == 1) printf("writeChar %d\n",(int)uchar);
  ret = write(fd,&uchar,1);
  if(ret < 0) return -1;
  //tcflush(fd, TCIOFLUSH);
  return ret;
#endif

#ifdef __VMS
  int  status;
  IOSB iosb;

  status = SYS$QIOW(0,vms_channel,IO$_WRITEVBLK | IO$M_CANCTRLO | IO$M_NOFORMAT,
                    &iosb,0,0,&uchar,1,0,0,0,0);
  if(status != SS$_NORMAL) return -1;
  return 1;
#endif

#ifdef RLWIN32
  BOOL ret;
  unsigned long len;

  if(trace == 1) printf("writeChar %d\n",(int)uchar);
  ret = WriteFile(
                  hdl,    // handle to file to write to
                  &uchar, // pointer to data to write to file
                  1,      // number of bytes to write
                  &len,   // pointer to number of bytes written
                  NULL    // pointer to structure for overlapped I/O
                 );

  if(ret) return (int) len;
  return -1;
#endif

#ifdef RM3
  return writeBlock(&uchar, 1);
#endif
}
Esempio n. 9
0
int XEEnableCtrlY(void (*rtn)(int))
{
#ifndef vms
    signal(SIGQUIT,rtn); /* CTRL-backslash */
    return(1);
#else /* vms */
    int status;

    status = SYS$QIOW ( 0,                      /* Set characteristics */
                        comm_chan,              /* Channel */
                        IO$_SETMODE|IO$M_CTRLYAST, /* Set ctrl_y */
                        comm_iosb,              /* iosb address */
                        0, 0,                   /* */
                        rtn, 0,                 /* AST routine and param */
                        CTRL_USER_MODE, 0, 0, 0 );
    $CheckStatus(status);

    return (SS$_NORMAL);
#endif /* vms */
}
Esempio n. 10
0
/*
 * This function gets called just before we go back home to the command
 * interpreter. On VMS it puts the terminal back in a reasonable state.
 * Another no-operation on CPM.
 */
ttclose()
{
#if     AMIGA
        Close(terminal);
#endif
#if     VMS
        int     status;
        int     iosb[1];

        ttflush();
        status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
                 oldmode, sizeof(oldmode), 0, 0, 0, 0);
        if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
                exit(status);
        status = SYS$DASSGN(iochan);
        if (status != SS$_NORMAL)
                exit(status);
#endif
#if     CPM
#endif
#if     MSDOS && !__OS2__
        int_restore(0x23);      /* de-install control-break handler     */
#endif
#if     BSDUNIX
        stty(1, &ostate);
#if NONBLOCK
        fcntl(0,F_SETFL,oldstatus);
#endif
#endif

#if     linux || __OpenBSD__ || __APPLE__
        tcsetattr(1, TCSADRAIN, &ostate);	// return to original mode
#endif

#if NCURSES
	endwin();
#endif
}
Esempio n. 11
0
int
__gnat_expect_poll (int *fd, int num_fd, int timeout, int *is_set)
{
  int i, num, ready = 0;
  unsigned int status;
  int mbxchans [num_fd];
  struct dsc$descriptor_s mbxname;
  struct io_status_block {
    short int condition;
    short int count;
    int dev;
  } iosb;
  char buf [256];

  for (i = 0; i < num_fd; i++)
    is_set[i] = 0;

  for (i = 0; i < num_fd; i++)
    {

      /* Get name of the mailbox used in the pipe */
      getname (fd [i], buf);

      /* Assign a channel to the mailbox */
      if (strlen (buf) > 0)
	{
	  mbxname.dsc$w_length = strlen (buf);
	  mbxname.dsc$b_dtype = DSC$K_DTYPE_T;
	  mbxname.dsc$b_class = DSC$K_CLASS_S;
	  mbxname.dsc$a_pointer = buf;

	  status = SYS$ASSIGN (&mbxname, &mbxchans[i], 0, 0, 0);

	  if ((status & 1) != 1)
	    {
	      ready = -1;
	      return ready;
	    }
	}
    }

  num = timeout / 100;

  while (1)
    {
      for (i = 0; i < num_fd; i++)
	{
	  if (mbxchans[i] > 0)
	    {

	      /* Peek in the mailbox to see if there's data */
	      status = SYS$QIOW
		(0, mbxchans[i], IO$_SENSEMODE|IO$M_READERCHECK,
		 &iosb, 0, 0, 0, 0, 0, 0, 0, 0);

	      if ((status & 1) != 1)
		{
		  ready = -1;
		  goto deassign;
		}

	      if (iosb.count > 0)
		{
		  is_set[i] = 1;
		  ready = 1;
		  goto deassign;
		}
	    }
	}

      if (timeout > 0 && num == 0)
	{
	  ready = 0;
	  goto deassign;
	}

      usleep (100000);
      num--;
    }

 deassign:

  /* Deassign channels assigned above */
  for (i = 0; i < num_fd; i++)
    {
      if (mbxchans[i] > 0)
	status = SYS$DASSGN (mbxchans[i]);
    }

  return ready;
}
Esempio n. 12
0
PUBLIC VOID SpPollkey()
{
   BUFFER_DECLARATIONS;
   char c;
#ifdef VMS
   struct CHARACTERISTICS {
			     short  Count;
			     char   ch;
			     char   res1;
			     long   res2;
			   } Chars;
#endif

   DEBUG(( "SP.POLLKEY" ));
   INIT_BUFFERS;

#ifdef MSC
   if ( kbhit() )
      {
	 c = getch();
	 PUT_BYTE( SP_SUCCESS );
	 PUT_BYTE( c );  
      }
   else
      {
	 PUT_BYTE( SP_ERROR );
      }
#endif
#ifdef SUN
   if ( TermMode == ORG_MODE )
      {
	 CurMode.c_iflag &= ~ICRNL;
	 CurMode.c_lflag &= ~(ICANON | ECHO);
	 CurMode.c_cc[VTIME] = 1;
	 CurMode.c_cc[VMIN] = 0;
	 ioctl( 0, TCSETS, &CurMode );
	 TermMode = POLL_MODE;
      }
   else
      if ( TermMode == GET_MODE )
	 {
	    CurMode.c_cc[VTIME] = 1;
	    CurMode.c_cc[VMIN] = 0;
	    ioctl( 0, TCSETS, &CurMode );
	    TermMode = POLL_MODE;
	 }

   if ( read(0, &c, 1) == 0 )
      {
	 PUT_BYTE( SP_ERROR );
      }
   else
      {
	 PUT_BYTE( SP_SUCCESS );
	 PUT_BYTE( c );  
      }
#endif

#ifdef VMS
   (void)SYS$QIOW( 0, InputChan, (IO$_SENSEMODE | IO$M_TYPEAHDCNT ), &iosb_desc, 0, 0, &Chars, sizeof(struct CHARACTERISTICS), 0, 0, 0, 0 ) ;
   if ( Chars.Count > 0 )
      {
	 (void)SYS$QIOW( 0, InputChan, (IO$_READVBLK | IO$M_NOECHO | IO$M_NOFILTR ), &iosb_desc, 0, 0, &c, 1, 0, 0L, 0, 0 );
	 PUT_BYTE( SP_SUCCESS );
	 PUT_BYTE( c );  
      }
   else
      {
	 PUT_BYTE( SP_ERROR );
      }
#endif
#ifdef HELIOS
   if ( TermMode == ORG_MODE )
      {
	 RemoveAttribute(&CurAttributes,ConsoleEcho);
	 AddAttribute(&CurAttributes,ConsoleRawInput);
	 AddAttribute(&CurAttributes,ConsoleBreakInterrupt);
	 SetAttributes(InputStream,&CurAttributes);
	 TermMode = POLL_MODE;
      }
   if ( Read( InputStream, &c, 1, OneSec/10 ) == 1 )
      {
	 PUT_BYTE( SP_SUCCESS );
	 PUT_BYTE( c );  
      }
   else
      {
	 PUT_BYTE( SP_ERROR );
      }
#endif
   REPLY;

}
Esempio n. 13
0
PUBLIC VOID SpGetkey()
{
#if (BOARD_ID == UDP)
/* the udp version of iserver requires that the link is kept active,
   if it is inactive for X seconds the transputer will reset itself.
   Therefore this function polls the keyboard & sends an ACTIVE frame
   every X seconds to keep the transputer alive. */
   BUFFER_DECLARATIONS;
   BYTE c;
   int timeval1,timeval2,finished;

#ifdef VMS
   struct CHARACTERISTICS {
			     short  Count;
			     char   ch;
			     char   res1;
			     long   res2;
			   } Chars;
#endif

   DEBUG(( "SP.GETKEY {udp}" ));
   INIT_BUFFERS;           
   finished = FALSE;  
   time (&timeval1);

   while (!finished) {
     time (&timeval2);
     /* if 10 seconds elapsed, check link still active */
     if ((timeval2-timeval1) >= QUIETTIMEOUT) {
       if (TestLink(TheLink) != SUCCEEDED) {
	 finished = TRUE;
	 PUT_BYTE( SP_ERROR );
	 break;
       } else {
	 time (&timeval1);
       };
     };

#ifdef MSC
     if (kbhit()) {
       c = getch();
       PUT_BYTE( SP_SUCCESS );
       PUT_BYTE( c );    
       finished = TRUE;
     };
#endif

#ifdef SUN          
     if ( TermMode == ORG_MODE ) {
       CurMode.c_iflag &= ~ICRNL;
       CurMode.c_lflag &= ~(ICANON | ECHO);
       CurMode.c_cc[VTIME] = 1;
       CurMode.c_cc[VMIN] = 0;
       ioctl( 0, TCSETS, &CurMode );
       TermMode = POLL_MODE;
      } else {
	if ( TermMode == GET_MODE ) {
	  CurMode.c_cc[VTIME] = 1;
	  CurMode.c_cc[VMIN] = 0;
	  ioctl( 0, TCSETS, &CurMode );
	  TermMode = POLL_MODE;
	};
      };
      if (read(0, &c, 1) != 0) {
	PUT_BYTE( SP_SUCCESS );
	PUT_BYTE( c );   
	finished = TRUE;
      };
#endif

#ifdef VMS
     (void)SYS$QIOW( 0, InputChan, (IO$_SENSEMODE | IO$M_TYPEAHDCNT ), &iosb_desc, 0, 0, &Chars, sizeof(struct CHARACTERISTICS), 0, 0, 0, 0 ) ;
     if (Chars.Count > 0) {
       (void)SYS$QIOW( 0, InputChan, (IO$_READVBLK | IO$M_NOECHO | IO$M_NOFILTR ), &iosb_desc, 0, 0, &c, 1, 0, 0L, 0, 0 );
       PUT_BYTE( SP_SUCCESS );
       PUT_BYTE( c );   
       finished = TRUE;
     };
#endif

#ifdef HELIOS
    if ( TermMode == ORG_MODE ) {
      RemoveAttribute(&CurAttributes,ConsoleEcho);
      AddAttribute(&CurAttributes,ConsoleRawInput);
      AddAttribute(&CurAttributes,ConsoleBreakInterrupt);
      SetAttributes(InputStream,&CurAttributes);
      TermMode = POLL_MODE;
     }
     if ( Read( InputStream, &c, 1, OneSec/10 ) == 1 ) {
       PUT_BYTE( SP_SUCCESS );
       PUT_BYTE( c );  
       finished = TRUE;
     };
#endif 
   };   /* end of while */
 
   DEBUG(("key was %c",c));
   REPLY;
#else
   BUFFER_DECLARATIONS;
   BYTE c;

   DEBUG(( "SP.GETKEY {non-udp}" ));
   INIT_BUFFERS;

   c = GetAKey();

   DEBUG(("key was %c",c));
   PUT_BYTE( SP_SUCCESS );
   PUT_BYTE( c );  
   REPLY;
#endif
}
Esempio n. 14
0
int rlSerial::writeBlock(const unsigned char *buf, int len)
{
#ifdef RLUNIX
  int ret;

  if(fd == -1) return -1;
  if(trace == 1)
  {
    printf("writeBlock:");
    for(int i=0; i<len; i++) printf(" %d",(int) buf[i]);
    printf("\n");
  }
  ret = write(fd,buf,len);
  //tcflush(fd, TCIOFLUSH);
  return ret;
#endif

#ifdef __VMS
  int  status;
  IOSB iosb;


  status = SYS$QIOW(0,vms_channel,IO$_WRITEVBLK | IO$M_CANCTRLO | IO$M_NOFORMAT,
                    &iosb,0,0,buf,len,0,0,0,0);
  if(status != SS$_NORMAL) return -1;
  return len;
#endif

#ifdef RLWIN32
  BOOL ret;
  unsigned long retlen;

  if(trace == 1)
  {
    printf("writeBlock:");
    for(int i=0; i<len; i++) printf(" %d",(int) buf[i]);
    printf("\n");
  }
  retlen = len;
  ret = WriteFile(
                  hdl,     // handle to file to write to
                  buf,     // pointer to data to write to file
                  len,     // number of bytes to write
                  &retlen, // pointer to number of bytes written
                  NULL     // pointer to structure for overlapped I/O
                 );

  if(ret) return (int) retlen;
  return -1;
#endif

#ifdef RM3
  RmBytParmStruct  PBlock;    /* Parameterstruktur fr RmIO - Funktion          */
  RmIOStatusStruct DrvSts;    /* Struktur der Rckgabewerte fr RmIO - Funktion  */
  unsigned char    cByte;     /* Rckgabewert von ibyte - Funktion              */
  int              iStatus;   /* Rckgabewert                                   */
  int              i;         /* Schleifenz�ler                                */
                              /**************************************************/

  /*
   * Schreibparameter setzen
   */
  PBlock.string = (char*)buf;
  PBlock.strlen = len;
  PBlock.buffer = 0;
  PBlock.timlen = 0;
  PBlock.status = 0;

  /******************************************************
   *                                                    *
   * Toggle mode wird emuliert indem an dieser Stelle   *
   * RTS-Signal gesetzt und sp�er wieder gel�cht wird   *
   *                                                    *
   ******************************************************/

  cByte = inbyte( com + 0x04u );
  outbyte( com + 0x04, (unsigned char)(cByte | 0x02u) );

  /*
   * Schreibvorgang einleiten
   */
  iStatus = RmIO( BYT_WRITE_WAIT, (unsigned)device, (unsigned)unit, 0u, 0u, &DrvSts, &PBlock );

  /******************************************************************
   *                                                                *
   * 8ms warten.Bei der Aenderung der Uebertragungsgeschwindigkeit, *
   * sollte dieser Wert angepasst werden. Hier fuer 9600            *
   *                                                                *
   ******************************************************************/
  RmPauseTask((RTS_TIME_WAIT*9600)/baudrate);

  /*
   * RTS-Signal l�chen
   */
  outbyte( com + 0x04, (unsigned char)(cByte & 0xFDu) );

  if( iStatus ) printf( "BYT_WRITE_WAIT (write block): Error status = %X\n", iStatus );

  if( !iStatus ) return len;
  return -1;
#endif
}
Esempio n. 15
0
int
SOCKconnect(char *hostname, int port)
{
#if !defined(CMUIP) && !defined(NETLIB)
     struct sockaddr_in Server;
     struct hostent *HostPtr;
     int sockfd = 0;
     unsigned int ERRinet = -1;

#ifdef _CRAY
     ERRinet = 0xFFFFFFFF;  /* -1 doesn't sign extend on 64 bit machines */
#endif

     /*** Find the hostname address ***/
     
     if (hostname == NULL || *hostname == '\0')
	  return(ErrSocketNullHost);

#ifdef DGUX
     Server.sin_addr = inet_addr(hostname);
     if (Server.sin_addr.s_addr == ERRinet)
#else
     if ((Server.sin_addr.s_addr = inet_addr(hostname)) == ERRinet)
#endif
     {
	  if ((HostPtr = gethostbyname(hostname)) != NULL) {
	       bzero((char *) &Server, sizeof(Server));
	       bcopy(HostPtr->h_addr, (char *) &Server.sin_addr, HostPtr->h_length);
	       Server.sin_family = HostPtr->h_addrtype;
	  } else
	       return (ErrSocketGetHost);
     } else
	  Server.sin_family = AF_INET;

     Server.sin_port = (unsigned short) htons(port);

     /*** Open the socket ***/

     if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
	  return (ErrSocketCall);

#ifndef UCX
     setsockopt(sockfd, SOL_SOCKET, ~SO_LINGER, 0, 0);
#endif

     setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, 0, 0);
     setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, 0, 0);

     /*** Connect ***/
     if (ControlCpressed) { /* Already interrupted */
	  return(ErrSocketInterrupted);
     }
     if (signal(SIGINT, controlcJmp) == SIG_ERR)
	  perror("signal died:\n"), exit(-1);

     if (setjmp(Jmpenv)) {
	  /* Note controlcJmp will reprime controlc and set flag*/
	  Debug("interruptable_connect triggered\r\n",NULL)
	       return(ErrSocketInterrupted);
     }

     if (connect(sockfd, (struct sockaddr *) &Server, sizeof(Server)) < 0) {
	  closenet(sockfd);
	  reprimeControlc();
	  return (ErrSocketConnect);
     }
     reprimeControlc();

     return(sockfd);

#else /* !NETLIB && !CMUIP */
#ifdef NETLIB
     int status;
     static int iSock = 0;
     struct {
          long len;
          char *adr;
     } host_desc;

#define NET_K_TCP 1
     status = NET_ASSIGN (&iSock);
     if ((status & 1) == 0)
          return (ErrSocketCall);
     status = NET_BIND (&iSock, NET_K_TCP);
     if ((status & 1) == 0)
          return (ErrSocketCall);
     host_desc.adr = hostname;
     host_desc.len = strlen (host_desc.adr);
     status = TCP_CONNECT (&iSock, &host_desc, port);
     if ((status & 1) == 0) {
          NET_DEASSIGN (&iSock);
          if (status == SS$_REJECT || status == SS$_TIMEOUT) {
	       if (status == SS$_REJECT)
		    errno = ECONNREFUSED;
	       else
		    errno = ETIMEDOUT;
	       
	       return (ErrSocketConnect);
	  }
	  if (status == SS$_ENDOFFILE)
	       return (ErrSocketGetHost);
          return (ErrSocketGetService);
     }
     return (iSock);
#else /* ifdef NETLIB:  assume CMUIP */
     short channel;
     int status;
     struct {
          short status;
          short size;
          long xxx;
     } cmu_iosb;
     static struct {long l; char *a;} ip_dev = {12, "INET$DEVICE:"};
     globalvalue NET$_CREF;           /* Connection refused */
     globalvalue NET$_FTO;            /* Function timedout */
     globalvalue NET$_DSNAMERR;       /* Domain server name error */
     status = SYS$ASSIGN (&ip_dev, &channel, 0, 0);
     if ((status & 1) == 0)
          return (ErrSocketCall);
     status = SYS$QIOW (0, channel, IO$_CREATE, &cmu_iosb, 0, 0,
          hostname, port, 0, 1, 0, 0);
     if ((status & 1) == 0 || (cmu_iosb.status & 1) == 0) {
          SYS$DASSGN (channel);
          if (cmu_iosb.status == SS$_ABORT || cmu_iosb.xxx == NET$_FTO) {
               if (cmu_iosb.xxx == NET$_CREF)
		    errno = ECONNREFUSED;
	       else
		    errno = ETIMEDOUT;

	       return(ErrSocketConnect);
	  }
	  if (cmu_iosb.xxx == NET$_DSNAMERR)
	       return (ErrSocketGetHost);
     }
     return (channel);
#endif
#endif

}
Esempio n. 16
0
File: dfu.c Progetto: rroart/freevms
main(int argc, char *argv[])

/*	MAIN

	Purpose : 1 Get privilege mask
		  2 Setup SMG environment unless no VT or DFU$NOSMG is set
		  3 Get and Parse command (syntax only)
		  4 Dispatch to correct subroutine

	Inputs  : Command line (if specified through foreign command)

	Outputs : returns last status code to DCL in  case
		  of single command processing. In interactive mode
		  always returns SS$_NORMAL.
*/
{
    const rms_eof=98938,smg$_eof=1213442;
    struct
    {
        short status, count;
        int extra ;
    } iosb;
    static char command_line[255], *e;
    unsigned int out_len,ret_len,prvmask;
    void reset_ctrl(), clean_ctrlc(),
         prev_screen(), next_screen(), dump_screen(), toggle_width() ;
    int smg_flag, x, y, i, ttype;
    int cursor_on = SMG$M_CURSOR_ON;
    $DESCRIPTOR(input_line , command_line);
    $DESCRIPTOR(prompt,"DFU> ");
    $DESCRIPTOR(terminal,"SYS$COMMAND");
    $DESCRIPTOR(top_txt,"< DFU V2.2 (Freeware) >");
    $DESCRIPTOR(status_txt,"Statistics");
    $DESCRIPTOR(do_key,"DO");
    $DESCRIPTOR(pf2,"PF2");
    $DESCRIPTOR(pf4,"PF4");
    $DESCRIPTOR(prev,"PREV_SCREEN");
    $DESCRIPTOR(next,"NEXT_SCREEN");
    $DESCRIPTOR(select,"SELECT");
    $DESCRIPTOR(help,"HELP");

    /* First find out how we got called ( by RUN, or a foreign command */
    ret_len = 0;
#if 0
    status = lib$get_foreign(&input_line,0,&ret_len,0);
#else
    status = 1;
#if 0
    strcpy(command_line,argv[1]);
#endif
#endif
    out_len = ret_len;

    smg$enable = TRUE;
    key_tab = 0;
    disp2_id = 0;
    cip = 0;

    setvbuf(stdout, NULL, _IONBF, 0);      // need this to see i/o at all
#if 0
    smg$enable = FALSE;
    vms_mm = check_vms_mm();
#else
    /* Now create the SMG environment */

    colls=80;
    rows=24;
    SMG$CREATE_PASTEBOARD(&paste_id, 0, &rows,
                          &colls,&SMG$M_KEEP_CONTENTS,&ttype,0);
    if ((e = (char *) getenv("DFU$NOSMG")) && *e) smg$enable = FALSE;
    else
    {
        if (ttype != SMG$K_VTTERMTABLE) smg$enable = FALSE;
        if (ttype != SMG$K_VTTERMTABLE) SMG$DELETE_PASTEBOARD(&paste_id,&i0);
    }

    SMG$CREATE_VIRTUAL_KEYBOARD(&keyb_id,0,0,0,0);
    if (smg$enable)
        /* Setup key table */
    {
        SMG$ERASE_PASTEBOARD(&paste_id, 0, 0, 0, 0, 0, 0);
        SMG$CREATE_KEY_TABLE(&key_tab);
        colls -=2;
        orig_colls = colls;
        smg_flag = SMG$M_KEY_NOECHO + SMG$M_KEY_TERMINATE;
        SMG$ADD_KEY_DEF(&key_tab,&do_key,0, &smg_flag, &do_key,0);
        SMG$ADD_KEY_DEF(&key_tab,&pf4,0, &smg_flag,&pf4,0);
        SMG$ADD_KEY_DEF(&key_tab,&prev,0, &smg_flag, &prev,0);
        SMG$ADD_KEY_DEF(&key_tab,&next,0, &smg_flag, &next,0);
        SMG$ADD_KEY_DEF(&key_tab,&pf2,0, &smg_flag, &help,0);
        SMG$ADD_KEY_DEF(&key_tab,&help,0, &smg_flag, &help,0);
        SMG$ADD_KEY_DEF(&key_tab,&select,0, &smg_flag, &select,0);
        SMG$CREATE_VIRTUAL_DISPLAY(&i500, &colls , &disp1_id, &SMG$M_BORDER,
                                   0, 0);
        x = 508 - rows;
        y = rows - 7;
        SMG$CREATE_VIEWPORT(&disp1_id,&x,&i1,&y,&colls);
        SMG$CREATE_VIRTUAL_DISPLAY(&i2, &colls, &status_id, 0 , 0, 0);
        SMG$CREATE_VIRTUAL_DISPLAY(&i2, &colls, &disp2_id, 0 , 0, 0);
        SMG$SET_BROADCAST_TRAPPING(&paste_id,brdcst_ast,0);
        SMG$LABEL_BORDER(&disp1_id, &top_txt, 0, 0,&SMG$M_BOLD, 0, 0);
        SMG$LABEL_BORDER(&status_id, &status_txt, 0, 0,&SMG$M_BOLD, 0, 0);
        SMG$PASTE_VIRTUAL_DISPLAY(&disp1_id, &paste_id, &i2,&i2,0);
        x = rows - 4;
        SMG$PASTE_VIRTUAL_DISPLAY(&status_id, &paste_id, &x,&i2,0);
        x = rows - 1;
        SMG$PASTE_VIRTUAL_DISPLAY(&disp2_id, &paste_id, &x,&i2,0);
        x = 508 - rows;
        SMG$SET_CURSOR_ABS(&disp1_id,&x,&i1);
        SMG$SET_CURSOR_ABS(&disp2_id,&i1,&i1);
        SMG$BEGIN_PASTEBOARD_UPDATE(&paste_id);
    }
#endif

    sprintf(outbuf,"\n     Disk and File Utilities for OpenVMS DFU V2.2");
    put_disp();
    sprintf(outbuf,"     Freeware version");
    put_disp();
    sprintf(outbuf,"     Copyright © 1995 Digital Equipment Corporation\n");
    put_disp();

    if (smg$enable)
    {
        /* Enter additional info */
        sprintf(outbuf,"     DFU functions are : \n");
        put_disp();
        sprintf(outbuf,"     DEFRAGMENT : Defragment files");
        put_disp();
        sprintf(outbuf,"     DELETE     : Delete files by File-ID; delete directory (trees)");
        put_disp();
        sprintf(outbuf,"     DIRECTORY  : Manipulate directories");
        put_disp();
        sprintf(outbuf,"     REPORT     : Generate a complete disk report");
        put_disp();
        sprintf(outbuf,"     SEARCH     : Fast file search");
        put_disp();
        sprintf(outbuf,"     SET        : Modify file attributes");
        put_disp();
        sprintf(outbuf,"     UNDELETE   : Recover deleted files");
        put_disp();
        sprintf(outbuf,"     VERIFY     : Check and repair disk structure");
        put_disp();
        SMG$END_PASTEBOARD_UPDATE(&paste_id);
    }

    prvmask = 0;
    status = dfu_check_access(&prvmask);  /*Get the privilege mask */

    /* Setup terminal channel for control purposes; get the terminal chars */
    status = SYS$ASSIGN(&terminal, &tchan, 0,0);
    status = SYS$QIOW(0,tchan, IO$_SENSEMODE,0,0,0,&orgttchar,12,0,0,0,0);
    for (i = 0; i < 3; i++) ttchar[i] = orgttchar[i];
    ttchar[2] &= ~TT2$M_EDITING; /* Clear line edit bit */
    clean_ctrlc(); /* Enable CTRL/W if needed */

    if (ret_len==0)
    {
        if (smg$enable)
            status = SMG$READ_COMPOSED_LINE(&keyb_id,&key_tab,&input_line,&prompt,
                                            &out_len,&disp2_id,0,0,0,0,0);
        else
            status = SMG$READ_COMPOSED_LINE(&keyb_id,0,&input_line,&prompt,
                                            &out_len,0,0,0,0,0,0);
    }

    memcpy (command_line, input_line.dsc$a_pointer, input_line.dsc$w_length);
    cip = 1;

    /* Main loop starts here. Get a command and pasre it*/
    for (;;)
    {
        /* loop forever until EXIT is entered */
        if(status==smg$_eof) status = exit_command(prvmask);
        if ((status&1) != 1) goto endfor;
        if (out_len == 0) goto endfor;

        /* First catch special screen commands */
        if (smg$enable)
        {
            status = strncmp(command_line, "PREV_SCREEN", 11);
            if (status == 0)
            {
                prev_screen();
                goto endfor;
            }
            status = strncmp(command_line, "DO",2);
            if (status == 0)
            {
                status = spawn_command(prvmask);
                goto endfor;
            }
            status = strncmp(command_line, "PF4",3);
            if (status == 0)
            {
                dump_screen();
                goto endfor;
            }
            status = strncmp(command_line, "NEXT_SCREEN", 11);
            if (status == 0)
            {
                next_screen();
                goto endfor;
            }
            status = strncmp(command_line, "SELECT", 6);
            if (status == 0)
            {
                toggle_width();
                goto endfor;
            }

            SMG$ERASE_DISPLAY(&disp1_id, 0, 0, 0, 0);
            SMG$ERASE_DISPLAY(&status_id, 0, 0, 0, 0);
            SMG$CHANGE_VIEWPORT(&disp1_id,&x,&i1,&y,&colls);
            SMG$SET_CURSOR_ABS(&disp1_id,&x,&i1);
        }

        /* Catch the CLI errors do avoid disrupting the SMG screen... */
#if 0
        VAXC$ESTABLISH(prim_hand);
#endif
        status = CLI$DCL_PARSE(&input_line,&dfu_tables,0 /* not yet lib$get_input*/,0,&prompt); // check added & before dfu_tables
#if 0
        VAXC$ESTABLISH(NULL);
#endif
        if (status == CLI$_NOCOMD) singlemsg(0,status);
        if ((status & 1 ) != 1) goto endfor;
        else
            /* Now dispatch if no errors */
        {
            reset_ctrl();
            CLI$DISPATCH(prvmask);
            clean_ctrlc();
            cip = 0;
            status = brdcst_ast();
            if (smg$enable) SMG$SET_CURSOR_MODE(&paste_id, &cursor_on);
        }
endfor:
        if (ret_len !=0)
        {
            /* Single command processing , so exit here */
            status += 0x10000000; /* Do not echo the error on DCL level */
            if (smg$enable)
            {
                if (colls != orig_colls) toggle_width();
                SMG$SET_CURSOR_ABS(&disp2_id,&i2,&i1);
            }
            exit(status);
        }
        /* Get next line */
        cip = 0;
#if 1
        if (smg$enable)
        {
            SMG$ERASE_LINE(&disp2_id, &i1, &i1);
            SMG$SET_CURSOR_ABS(&disp2_id,&i1,&i1);
            status = SMG$READ_COMPOSED_LINE(&keyb_id,&key_tab,&input_line,
                                            &prompt,&out_len,&disp2_id,0,0,0,0,0); /*Get next command */
            cip = 1;
        }
        else
            status = SMG$READ_COMPOSED_LINE(&keyb_id,0,&input_line,
                                            &prompt,&out_len,0,0,0,0,0,0); /*Get next command */
#else
        printf("%s",prompt.dsc$a_pointer);
        out_len = read(0,command_line,254);
        out_len--;
        command_line[out_len]=0;
        if (strncmp(command_line,"exit",4)==0)
            return 0;
#endif
    }
}  /* END of MAIN */
Esempio n. 17
0
int
vms_file_stats_name (const char *filename,
		     long long *cdt,
		     long *siz,
		     char *rfo,
		     int *ver)
{
#ifdef VMS
  struct FAB fab;
  struct NAM nam;

  unsigned long long create;
  FAT recattr;
  char ascnamebuff [256];

  ATRDEF atrlst[]
    = {
      { ATR$S_CREDATE,  ATR$C_CREDATE,  &create },
      { ATR$S_RECATTR,  ATR$C_RECATTR,  &recattr },
      { ATR$S_ASCNAME,  ATR$C_ASCNAME,  &ascnamebuff },
      { 0, 0, 0}
    };

  FIBDEF fib;
  struct dsc$descriptor_fib fibdsc = {sizeof (fib), (void *) &fib};

  struct IOSB iosb;

  long status;
  unsigned short chan;

  struct vstring file;
  struct dsc$descriptor_s filedsc
    = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) file.string};
  struct vstring device;
  struct dsc$descriptor_s devicedsc
    = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) device.string};
  struct vstring result;
  struct dsc$descriptor_s resultdsc
    = {NAM$C_MAXRSS, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, (void *) result.string};

  if (strcmp (filename, "<internal>") == 0
      || strcmp (filename, "<built-in>") == 0)
    {
      if (cdt)
	*cdt = 0;

      if (siz)
	*siz = 0;

      if (rfo)
	*rfo = 0;

      if (ver)
        *ver = 0;

      return 0;
    }

  tryfile = to_vms_file_spec ((char *) filename);

  /* Allocate and initialize a FAB and NAM structures.  */
  fab = cc$rms_fab;
  nam = cc$rms_nam;

  nam.nam$l_esa = file.string;
  nam.nam$b_ess = NAM$C_MAXRSS;
  nam.nam$l_rsa = result.string;
  nam.nam$b_rss = NAM$C_MAXRSS;
  fab.fab$l_fna = tryfile;
  fab.fab$b_fns = strlen (tryfile);
  fab.fab$l_nam = &nam;

  /* Validate filespec syntax and device existence.  */
  status = SYS$PARSE (&fab, 0, 0);
  if ((status & 1) != 1)
    return 1;

  file.string[nam.nam$b_esl] = 0;

  /* Find matching filespec.  */
  status = SYS$SEARCH (&fab, 0, 0);
  if ((status & 1) != 1)
    return 1;

  file.string[nam.nam$b_esl] = 0;
  result.string[result.length=nam.nam$b_rsl] = 0;

  /* Get the device name and assign an IO channel.  */
  strncpy (device.string, nam.nam$l_dev, nam.nam$b_dev);
  devicedsc.dsc$w_length  = nam.nam$b_dev;
  chan = 0;
  status = SYS$ASSIGN (&devicedsc, &chan, 0, 0, 0);
  if ((status & 1) != 1)
    return 1;

  /* Initialize the FIB and fill in the directory id field.  */
  memset (&fib, 0, sizeof (fib));
  fib.fib$w_did[0]  = nam.nam$w_did[0];
  fib.fib$w_did[1]  = nam.nam$w_did[1];
  fib.fib$w_did[2]  = nam.nam$w_did[2];
  fib.fib$l_acctl = 0;
  fib.fib$l_wcc = 0;
  strcpy (file.string, (strrchr (result.string, ']') + 1));
  filedsc.dsc$w_length = strlen (file.string);
  result.string[result.length = 0] = 0;

  /* Open and close the file to fill in the attributes.  */
  status
    = SYS$QIOW (0, chan, IO$_ACCESS|IO$M_ACCESS, &iosb, 0, 0,
		&fibdsc, &filedsc, &result.length, &resultdsc, &atrlst, 0);
  if ((status & 1) != 1)
    return 1;
  if ((iosb.status & 1) != 1)
    return 1;

  result.string[result.length] = 0;
  status = SYS$QIOW (0, chan, IO$_DEACCESS, &iosb, 0, 0, &fibdsc, 0, 0, 0,
		     &atrlst, 0);
  if ((status & 1) != 1)
    return 1;
  if ((iosb.status & 1) != 1)
    return 1;

  /* Deassign the channel and exit.  */
  status = SYS$DASSGN (chan);
  if ((status & 1) != 1)
    return 1;

  if (cdt) *cdt = create;
  if (siz) *siz = (512 * 65536 * recattr.fat$w_efblkh) +
                  (512 * (recattr.fat$w_efblkl - 1)) +
                  recattr.fat$w_ffbyte;
  if (rfo) *rfo = recattr.fat$v_rtype;
  if (ver) *ver = strtol (strrchr (ascnamebuff, ';')+1, 0, 10);

  return 0;
#else
  struct stat buff;
  struct tm *ts;

  if ((stat (filename, &buff)) != 0)
     return 1;

  if (cdt)
    {
      ts = localtime (&buff.st_mtime);
      *cdt = (long long) ((buff.st_mtim.tv_sec * VMS_GRANULARITY_FACTOR)
                          + (buff.st_mtim.tv_nsec / 100))
                         + VMS_EPOCH_OFFSET;
    }

  if (siz)
    *siz = buff.st_size;

  if (rfo)
    *rfo = 2; /* Stream LF format.  */

  if (ver)
    *ver = 0;

  return 0;
#endif
}
Esempio n. 18
0
$Id: vmstime.c,v 1.6 91/07/06 12:20:26 dhesi Exp $";
#endif
/*
This file was graciously supplied by Randal Barnes to support preservation
of file timestamps under VAX/VMS.  I claim no copyright on the contents of
this file.  I assume that neither do its authors.  However, if you adapt
this code for your own use, I recommend preserving author attributions.

                                -- Rahul Dhesi  1991/07/04
*/

/*
*  This module sets a VAX/VMS file's creation and revision date/time to a
*  specified date/time.
*
*  Inputs       Type            Description
*  ------       ----            -----------
*  path         char *          Name of file to be modified
*  date         int             Binary formatted date to be applied to the file
*  time         int             Binary formatted time to be applied to the file
*
*  Outputs      Type            Description
*  -------      ----            -----------
*  Modified file
*
*  Randy Magnuson - (612) 542-5052
*  Randal Barnes  - (612) 542-5021
*  Honeywell Inc. - Military Avionics Division
*  April 12, 1990
*/

#include <stdio.h>
#include <rms.h>
#include <fibdef.h>
#include <atrdef.h>
#include <descrip.h>
#include <iodef.h>
#include <libdtdef.h>

int setutime (char *path, unsigned int date, unsigned int time)
{
   char EName [NAM$C_MAXRSS],   /*  Expanded String Area                */
        RName [NAM$C_MAXRSS],   /*  Resultant String Area               */
        date_str [50];          /*  Holds intermediate ASCII date/time  */

   short iosb [4];              /*  I/O status block for sys calls      */

   int  status,                 /*  Condition code for sys calls, etc.  */
        i,                      /*  Temp index for looping thru arrays  */
        chan,                   /*  Channel to device containing file   */
        Cdate [2],              /*  VMS binary time - creation date     */
        Rdate [2],              /*  VMS binary time - revision date     */
        datetimecontext = 0,    /*  Context for time conv. lib calls    */
        intime = LIB$K_INPUT_FORMAT,  /*  Constant for time lib calls   */
        intdate [2];            /*  VMS binary time - temp              */

   struct FAB Fab;              /*  RMS File Access Block               */
   struct NAM Nam;              /*  RMS Name Block                      */
   static struct fibdef Fib;    /*  RMS File Information Block          */
   struct atrdef Atr [] =       /*  File attribute struct               */
      {
         { sizeof (Cdate), ATR$C_CREDATE, &Cdate [0] }, /*  Creation date  */
         { sizeof (Rdate), ATR$C_REVDATE, &Rdate [0] }, /*  Revision date  */
         {              0,             0,         0 }
      };
   struct dsc$descriptor devnam =       /*  Device name descriptor      */
      { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, &Nam.nam$t_dvi [1] };
   struct dsc$descriptor FibDesc =      /*  File ID descriptor          */
      { sizeof (Fib), 0, 0, &Fib };
   struct dsc$descriptor_s FileName =   /*  File name descriptor        */
      { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };

   /*  Time conversion format specification  */
   $DESCRIPTOR (datetimeformat, "|!Y4!MN0!D0|!H04!M0!S0!C2|");

   /*  String descriptor for intermediate date/time string  */
   $DESCRIPTOR (date_desc, date_str);


/*
*  Fill out our File Access Block, Name Block, and Extended Attribute Block so
*  we can parse the file name.
*/
   Fab = cc$rms_fab;
   Nam = cc$rms_nam;

   Fab.fab$l_fna = path;
   Fab.fab$b_fns = strlen (path);
   Fab.fab$l_nam = &Nam;

   Nam.nam$l_esa = &EName;
   Nam.nam$b_ess = sizeof (EName);
   Nam.nam$l_rsa = &RName;
   Nam.nam$b_rss = sizeof (RName);


/*
*  Do a parse and search to fill out the NAM block.
*/
   status = sys$parse(&Fab);
   if (!(status & 1))
      return 0;
   status = sys$search(&Fab);
   if (!(status & 1))
      return 0;


/*
*  Open a channel to the device that the file resides on.
*/
   devnam.dsc$w_length = Nam.nam$t_dvi [0];
   status = SYS$ASSIGN (&devnam, &chan, 0, 0);
   if (!(status & 1))
      return 0;


/*
*  Initialize the FIB
*/
   Fib.fib$r_acctl_overlay.fib$l_acctl = FIB$M_NORECORD;
   for (i = 0; i < 3; i++)
   {
      Fib.fib$r_fid_overlay.fib$w_fid [i] = Nam.nam$w_fid [i];
      Fib.fib$r_did_overlay.fib$w_did [i] = Nam.nam$w_did [i];
   }


/*
*  Set up the file name descriptor for the QIO
*/
   FileName.dsc$a_pointer = Nam.nam$l_name;
   FileName.dsc$w_length = Nam.nam$b_name + Nam.nam$b_type + Nam.nam$b_ver;


/*
*  Use the IO$_ACCESS function to return info about the file.
*/
   status = SYS$QIOW (0, chan, IO$_ACCESS, &iosb, 0, 0,
                      &FibDesc, &FileName, 0, 0, 0, 0);
   if (!(status & 1))
      return 0;
   status = iosb [0];
   if (!(status & 1))
      return 0;


/*
*  Set up a date/time format that we can easily convert to - "YYMMDD HHMMSS"
*/
   status = LIB$INIT_DATE_TIME_CONTEXT (&datetimecontext, &intime,
                                        &datetimeformat);
   if (!(status & 1))
      return 0;


/*
*  Convert the MS-DOS time ints to our ASCII format.
*/
   date_desc.dsc$w_length = sprintf (date_str, "%04d%02d%02d %02d%02d%02d00",
                                      ((date >> 9) & 0x7f) + 1980, /* year */
                                      (date >> 5) & 0x0f,          /* month */
                                      date & 0x1f,                 /* day */
                                      (time >> 11)& 0x1f,          /* hour */
                                      (time >> 5) & 0x3f,          /* min */
                                      (time & 0x1f) * 2);          /* sec */


/*
*  Convert our ASCII formatted date/time to VMS internal time format
*/
   status = LIB$CONVERT_DATE_STRING (&date_desc, &intdate, &datetimecontext);
   if (!(status & 1))
      return 0;


/*
*  Fill in the creation date and revision date fields in the Extended Attribute
*  Block with the date and time from the zoo file.
*/
   Cdate [0] = Rdate [0] = intdate [0];
   Cdate [1] = Rdate [1] = intdate [1];

/*
*  Modify the file
*/
   status = SYS$QIOW (0, chan, IO$_MODIFY, &iosb, 0, 0,
                      &FibDesc, &FileName, 0, 0, &Atr, 0);
   if (!(status & 1))
      return 0;
   status = iosb [0];
   if (!(status & 1))
      return 0;


/*
*  Okee dokee.
*/
   return 1;
}
Esempio n. 19
0
static int
vms_file_stats_name (const char *dirname,
                     const char *filename,
		     long long *cdt,
		     long *siz,
		     char *rfo,
		     int *ver)
{
  char fullname[strlen (dirname) + strlen (filename) + 1];
#ifdef VMS
  struct FAB fab;
  struct NAM nam;

  unsigned long long create;
  FAT recattr;
  char ascnamebuff [256];

  ATRDEF atrlst[]
    = {
      { ATR$S_CREDATE,  ATR$C_CREDATE,  &create },
      { ATR$S_RECATTR,  ATR$C_RECATTR,  &recattr },
      { ATR$S_ASCNAME,  ATR$C_ASCNAME,  &ascnamebuff },
      { 0, 0, 0}
    };

  FIBDEF fib;
  struct dsc$descriptor_fib fibdsc = {sizeof (fib), (void *) &fib};

  struct IOSB iosb;

  long status;
  unsigned short chan;

  struct vstring file;
  struct dsc$descriptor_s filedsc
    = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) file.string};
  struct vstring device;
  struct dsc$descriptor_s devicedsc
    = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) device.string};
  struct vstring result;
  struct dsc$descriptor_s resultdsc
    = {NAM$C_MAXRSS, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, (void *) result.string};

  if (strcmp (filename, "<internal>") == 0
      || strcmp (filename, "<built-in>") == 0)
    {
      if (cdt)
	*cdt = 0;

      if (siz)
	*siz = 0;

      if (rfo)
	*rfo = 0;

      if (ver)
        *ver = 0;

      return 0;
    }

  strcpy (fullname, dirname);
  strcat (fullname, filename);

  tryfile = to_vms_file_spec (fullname);

  /* Allocate and initialize a FAB and NAM structures.  */
  fab = cc$rms_fab;
  nam = cc$rms_nam;

  nam.nam$l_esa = file.string;
  nam.nam$b_ess = NAM$C_MAXRSS;
  nam.nam$l_rsa = result.string;
  nam.nam$b_rss = NAM$C_MAXRSS;
  fab.fab$l_fna = tryfile;
  fab.fab$b_fns = strlen (tryfile);
  fab.fab$l_nam = &nam;

  /* Validate filespec syntax and device existence.  */
  status = SYS$PARSE (&fab, 0, 0);
  if ((status & 1) != 1)
    return 1;

  file.string[nam.nam$b_esl] = 0;

  /* Find matching filespec.  */
  status = SYS$SEARCH (&fab, 0, 0);
  if ((status & 1) != 1)
    return 1;

  file.string[nam.nam$b_esl] = 0;
  result.string[result.length=nam.nam$b_rsl] = 0;

  /* Get the device name and assign an IO channel.  */
  strncpy (device.string, nam.nam$l_dev, nam.nam$b_dev);
  devicedsc.dsc$w_length  = nam.nam$b_dev;
  chan = 0;
  status = SYS$ASSIGN (&devicedsc, &chan, 0, 0, 0);
  if ((status & 1) != 1)
    return 1;

  /* Initialize the FIB and fill in the directory id field.  */
  memset (&fib, 0, sizeof (fib));
  fib.fib$w_did[0]  = nam.nam$w_did[0];
  fib.fib$w_did[1]  = nam.nam$w_did[1];
  fib.fib$w_did[2]  = nam.nam$w_did[2];
  fib.fib$l_acctl = 0;
  fib.fib$l_wcc = 0;
  strcpy (file.string, (strrchr (result.string, ']') + 1));
  filedsc.dsc$w_length = strlen (file.string);
  result.string[result.length = 0] = 0;

  /* Open and close the file to fill in the attributes.  */
  status
    = SYS$QIOW (0, chan, IO$_ACCESS|IO$M_ACCESS, &iosb, 0, 0,
		&fibdsc, &filedsc, &result.length, &resultdsc, &atrlst, 0);
  if ((status & 1) != 1)
    return 1;
  if ((iosb.status & 1) != 1)
    return 1;

  result.string[result.length] = 0;
  status = SYS$QIOW (0, chan, IO$_DEACCESS, &iosb, 0, 0, &fibdsc, 0, 0, 0,
		     &atrlst, 0);
  if ((status & 1) != 1)
    return 1;
  if ((iosb.status & 1) != 1)
    return 1;

  /* Deassign the channel and exit.  */
  status = SYS$DASSGN (chan);
  if ((status & 1) != 1)
    return 1;

  if (cdt) *cdt = create;
  if (siz) *siz = (512 * 65536 * recattr.fat$w_efblkh) +
                  (512 * (recattr.fat$w_efblkl - 1)) +
                  recattr.fat$w_ffbyte;
  if (rfo) *rfo = recattr.fat$v_rtype;
  if (ver) *ver = strtol (strrchr (ascnamebuff, ';') + 1, 0, 10);
#else /* not VMS */

  struct stat buff;
  struct tm *ts;
  long long gmtoff, secs, nsecs;

  strcpy (fullname, dirname);
  strcat (fullname, filename);

  if ((stat (fullname, &buff)) != 0)
     return 1;

  if (cdt)
    {
      ts = localtime (& buff.st_mtime);

#ifdef HAVE_TM_GMTOFF
	gmtoff = ts->tm_gmtoff;
#else
	{
	  extern long timezone;

	  if (ts->tm_isdst == 1)
	    gmtoff = - (timezone - 3600);
	  else
	    gmtoff = - timezone;
	}
#endif

#ifdef HAVE_ST_MTIM_TV_SEC
      secs = buff.st_mtim.tv_sec;
#else
      secs = buff.st_mtime;
#endif

#ifdef HAVE_ST_MTIM_TV_NSEC
      nsecs = buff.st_mtim.tv_nsec;
#else
      nsecs = 0;
#endif

      /* VMS timestamps are stored in local time to 100 nsec accuracy, but by
	 experiment I found timestamps truncated to (at least) microseconds
	 on an NFS mounted filesystem, hence the adjustment below. DBR. */
      *cdt = ((secs + gmtoff) * VMS_GRANULARITY_FACTOR)
	+ (nsecs / 1000 * 10) + VMS_EPOCH_OFFSET;
    }

  if (siz)
    *siz = buff.st_size;

  if (rfo)
    *rfo = 2; /* Stream LF format.  */

  /* Returning a file version of 0 is never correct for debug info, version 1
     will be correct if file editing is done only on the Unix side.  If editing
     is done on the VMS side, then its TBD.  */
  if (ver)
    *ver = 1;
#endif /* VMS */

  return 0;
}
Esempio n. 20
0
/*
 * This function is called once to set up the terminal device streams.
 * On VMS, it translates SYS$INPUT until it finds the terminal, then assigns
 * a channel to it and sets it raw. On CPM it is a no-op.
 */
ttopen()
{
#if     AMIGA
        terminal = Open("RAW:1/1/639/199/MicroEmacs", NEW);
#endif
#if     VMS
        struct  dsc$descriptor  idsc;
        struct  dsc$descriptor  odsc;
        char    oname[40];
        int     iosb[2];
        int     status;

        odsc.dsc$a_pointer = "SYS$INPUT";
        odsc.dsc$w_length  = strlen(odsc.dsc$a_pointer);
        odsc.dsc$b_dtype   = DSC$K_DTYPE_T;
        odsc.dsc$b_class   = DSC$K_CLASS_S;
        idsc.dsc$b_dtype   = DSC$K_DTYPE_T;
        idsc.dsc$b_class   = DSC$K_CLASS_S;
        do {
                idsc.dsc$a_pointer = odsc.dsc$a_pointer;
                idsc.dsc$w_length  = odsc.dsc$w_length;
                odsc.dsc$a_pointer = &oname[0];
                odsc.dsc$w_length  = sizeof(oname);
                status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc);
                if (status!=SS$_NORMAL && status!=SS$_NOTRAN)
                        exit(status);
                if (oname[0] == 0x1B) {
                        odsc.dsc$a_pointer += 4;
                        odsc.dsc$w_length  -= 4;
                }
        } while (status == SS$_NORMAL);
        status = SYS$ASSIGN(&odsc, &iochan, 0, 0);
        if (status != SS$_NORMAL)
                exit(status);
        status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0,
                          oldmode, sizeof(oldmode), 0, 0, 0, 0);
        if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
                exit(status);
        newmode[0] = oldmode[0];
        newmode[1] = oldmode[1] | TT$M_PASSALL | TT$M_NOECHO;
        status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
                          newmode, sizeof(newmode), 0, 0, 0, 0);
        if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
                exit(status);
#endif
#if     CPM
#endif
#if     MSDOS && !__OS2__
        /* Set control-break handler    */
        int_intercept(0x23,kbd_inthandler,128);
#endif
#if     BSDUNIX
        /* Adjust output channel        */
        gtty(1, &ostate);                       /* save old state */
        gtty(1, &nstate);                       /* get base of new state */
        nstate.sg_flags |= RAW;
        nstate.sg_flags &= ~(ECHO|CRMOD);       /* no echo for now... */
        stty(1, &nstate);                       /* set mode */

#if NONBLOCK
        /* Set input to non-blocking    */
        oldstatus = fcntl(0,F_GETFL);
        fcntl(0,F_SETFL,oldstatus | FNDELAY);   /* don't block on input */
#endif
#endif

#if     linux || __OpenBSD__ || __APPLE__
        /* Adjust output channel        */
        tcgetattr(1, &ostate);                       /* save old state */
        tcgetattr(1, &nstate);                       /* get base of new state */
	cfmakeraw(&nstate);
        tcsetattr(1, TCSADRAIN, &nstate);      /* set mode */
#endif

#if NCURSES
	initscr();
	cbreak();
	noecho();

	nonl();
	intrflush(stdscr, FALSE);
	keypad(stdscr, TRUE);
#endif
}
Esempio n. 21
0
int rlSerial::readBlock(unsigned char *buf, int len, int timeout)
{
#ifdef RLUNIX
  int c, retlen;

  retlen = 0;
  for(int i=0; i<len; i++)
  {
    if(timeout >= 0)
    {
      if(select(timeout) == 0) break; // timeout
    }
    c = readChar();
    if(c < 0) return c;
    buf[i] = (unsigned char) c;
    retlen = i+1;
  }
  if(retlen <= 0) return -1;
  return retlen;
#endif

#ifdef __VMS
  int   status;
  int   _timeout = 1; // second
  short iosb[4];

  status = SYS$QIOW(0,vms_channel,
                    IO$_READVBLK | IO$M_NOFILTR | IO$M_NOECHO | IO$M_TIMED,
                    iosb,0,0,buf,len,_timeout,0,0,0);
  if(status != SS$_NORMAL) return -1;
  len=iosb[1];
  if(iosb[2] != 0)
  {
    len++;
    buf[len] = iosb[2];
  }
  return len;
#endif

#ifdef RLWIN32
  BOOL ret;
  unsigned long retlen;

  if(timeout >= 0) select(timeout);
  ret = ReadFile(
                 hdl,     // handle of file to read
                 buf,     // pointer to buffer that receives data
                 len,     // number of bytes to read
                 &retlen, // pointer to number of bytes read
                 NULL     // pointer to structure for data
                );
  if(retlen > 0)
  {
    if(trace == 1) printf("readBlock retlen=%d\n",(int)retlen);
    return (int) retlen;
  }
  return -1;
#endif

#ifdef RM3
  RmBytParmStruct  PBlock;    /* Parameterstruktur fr RmIO - Funktion          */
  RmIOStatusStruct DrvSts;    /* Struktur der Rckgabewerte fr RmIO - Funktion */
  int              iStatus;   /* Rckgabewert                                   */
  int              i;         /* Schleifenz�ler                                */
                              /**************************************************/

  /*
   * Schreibparameter setzen
   */
  PBlock.string = 0;
  PBlock.strlen = 0;
  PBlock.buffer = (char*)buf;
  PBlock.timlen = len;
  PBlock.status = 0;

  /*
   * Lesevorgang einleiten
   */
  iStatus = RmIO( BYT_POLL_XBUF_WAIT, (unsigned)device, (unsigned)unit, 0u, 0u, &DrvSts, &PBlock );

  if( iStatus ) printf( "BYT_POLL_XBUF_WAIT (set ucb): Error status = %X\n", iStatus );

  if( !iStatus ) return len;
  return -1;
#endif
}
Esempio n. 22
0
char *
readpassphrase(const char *prompt, char *pbuf, size_t buflen, int flags)
{

	static unsigned long keyboard_id, keytable_id = 0;
	unsigned long ctrl_mask, saved_ctrl_mask = 0;
	int timeout_secs = 0;
	int *timeout_ptr = NULL;
	unsigned long status = 0;
	unsigned short iosb[4];
	unsigned short ttchan, result_len = 0, stdin_is_tty;

	$DESCRIPTOR(ttdsc, "");
	$DESCRIPTOR(pbuf_dsc, "");
	$DESCRIPTOR(prompt_dsc, "");
	char *retval = NULL;
	char *myprompt = NULL;
	char input_fspec[MY_PASSWORD_LEN + 1];

	if (pbuf == NULL || buflen == 0) {
		errno = EINVAL;
		return NULL;
	}
	bzero(pbuf, buflen);
	pbuf_dsc.dsc$a_pointer = pbuf;
	pbuf_dsc.dsc$w_length = buflen - 1;


	/*
	 * If stdin is not a terminal and only reading from a terminal is allowed, we
	 * stop here.  
	 */
	stdin_is_tty = isatty(fileno(stdin));
	if (stdin_is_tty != 1 && (flags & RPP_REQUIRE_TTY)) {
		errno = ENOTTY;
		return NULL;
	}

	/*
	 * We need the file or device associated with stdin in VMS format.
	 */
	if (fgetname(stdin, input_fspec, 1)) {
		ttdsc.dsc$a_pointer = (char *)&input_fspec;
		ttdsc.dsc$w_length = strlen(input_fspec);
	} else {
		errno = EMFILE;
		return NULL;
	}

	/* 
	 * The prompt is expected to provide its own leading newline.
	 */
	myprompt = malloc(strlen(prompt) + 1);
	if (myprompt == NULL) {
		errno = ENOMEM;
		return NULL;
	}
	sprintf(myprompt, "\n%s", prompt);
	prompt_dsc.dsc$a_pointer = myprompt;
	prompt_dsc.dsc$w_length = strlen(myprompt);

	if (!(flags & RPP_ECHO_ON) && (stdin_is_tty)) {
		/* Disable Ctrl-T and Ctrl-Y */
		ctrl_mask = LIB$M_CLI_CTRLT | LIB$M_CLI_CTRLY;
		status = LIB$DISABLE_CTRL(&ctrl_mask, &saved_ctrl_mask);
		if (!$VMS_STATUS_SUCCESS(status)) {
			errno = EVMSERR;
			vaxc$errno = status;
			free(myprompt);
			return NULL;
		}
	}

	/* 
	 * Unless timeouts are disabled, find out how long should we wait for input
	 * before giving up.
	 */
	if (!(flags & RPP_TIMEOUT_OFF)) {
		unsigned long tmo_item = SYI$_LGI_PWD_TMO;

		status = LIB$GETSYI(&tmo_item, &timeout_secs);
		if (!$VMS_STATUS_SUCCESS(status))
			timeout_secs = DEFAULT_TIMEOUT;
		timeout_ptr = &timeout_secs;
	}

	if (!(flags & RPP_ECHO_ON) && (stdin_is_tty)) {
		/* 
		 * If we are suppressing echoing, get a line of input with $QIOW.  
		 * Non-echoed lines are not stored for recall.  (The same thing
		 * could be done with SMG but would require maintenance of a virtual 
		 * display and pasteboard.)
		 */
		status = SYS$ASSIGN(&ttdsc, &ttchan, 0, 0, 0);
		if ($VMS_STATUS_SUCCESS(status)) {

			unsigned long qio_func = IO$_READPROMPT | IO$M_NOECHO | IO$M_PURGE;

			if (!(flags & RPP_TIMEOUT_OFF))
				qio_func |= IO$M_TIMED;
			bzero(iosb, sizeof(iosb));

			status = SYS$QIOW(0,
					  (unsigned long) ttchan,
					  qio_func, &iosb, 0, 0, pbuf, buflen - 1, timeout_secs, 0, myprompt, strlen(myprompt));

			if ($VMS_STATUS_SUCCESS(status)) {
				status = iosb[0];
				result_len = iosb[1];	/* bytes actually read */
			}
			(void) SYS$DASSGN(ttchan);
		}
	} else {
		/* 
		 * We are not suppressing echoing because echoing has been explicitly 
		 * enabled and/or we are not reading from a terminal.  In this case we 
		 * use SMG, which will store commands for recall.  The virtual keyboard 
		 * and key table are static and will only be created if we haven't been 
		 * here before.
		 */
		status = SS$_NORMAL;
		if (keyboard_id == 0) {
			unsigned char recall_size = RECALL_SIZE;

			status = SMG$CREATE_VIRTUAL_KEYBOARD(&keyboard_id, &ttdsc, 0, 0, &recall_size);
		}
		if ($VMS_STATUS_SUCCESS(status) && keytable_id == 0) {
			status = SMG$CREATE_KEY_TABLE(&keytable_id);
		}

		if ($VMS_STATUS_SUCCESS(status)) {
			status = SMG$READ_COMPOSED_LINE(&keyboard_id,
							&keytable_id, &pbuf_dsc, &prompt_dsc, &result_len, 0, 0, 0, timeout_ptr);
		}
	}

	/* 
	 * Process return value from SYS$QIOW or SMG$READ_COMPOSED_LINE.
	 */
	switch (status) {
	case SS$_TIMEOUT:
		errno = ETIMEDOUT;
		break;
	case SMG$_EOF:
		if (result_len != 0) {
			status = SS$_NORMAL;
		}
		/* fall through */
	default:
		if ($VMS_STATUS_SUCCESS(status)) {
			int i;

			if (flags & RPP_FORCELOWER) {
				for (i = 0; i < result_len; i++)
					pbuf[i] = tolower(pbuf[i]);
			}
			if (flags & RPP_FORCEUPPER) {
				for (i = 0; i < result_len; i++)
					pbuf[i] = toupper(pbuf[i]);
			}
			if (flags & RPP_SEVENBIT) {
				for (i = 0; i < result_len; i++)
					pbuf[i] &= 0x7f;
			}
			pbuf[result_len] = '\0';
			retval = pbuf;
		} else {
			errno = EVMSERR;
			vaxc$errno = status;
		}
	}			/* end switch */

	free(myprompt);

	if (!(flags & RPP_ECHO_ON) && (stdin_is_tty)) {
		/*
		 * Reenable previous control processing.
		 */
		status = LIB$ENABLE_CTRL(&saved_ctrl_mask);

		if (!$VMS_STATUS_SUCCESS(status)) {
			errno = EVMSERR;
			vaxc$errno = status;
			return NULL;
		}
	}

	return retval;

}				/* getpassphrase */