Ejemplo n.º 1
0
void getdatfile ( char fildat[] )

/*
*+
*  Name:
*     getdatfile
*
*  Purpose:
*     Get DAT file Name
*
*  Invocation:
*     getdatfile( fildat )
*
*  Description:
*     Build compiled version of Device Configuration Table file name
*
*  Arguments:
*     fildct = char[]
*        File name
*
*  Authors:
*     SANTIN: P. Santin (Trieste Astronomical Observatory)
*     NE: Nick Eaton (Durham University)
*     DLT: David Terrett (Starlink, RAL)
*
*  History:
*     26-OCT-1988 (SANTIN):
*        Orignal version
*     21-FEB-1991 (NE):
*        Replaced call to getenv with call to getdev for device name
*     23-MAY-1991 (NE):
*        Removed definition of getenv
*     22-JAN-1992 (DLT):
*        Add default path if IDI_DIR not set
*     14-OCT-1993 (DLT):
*        Cast strlen to int to suppress warning message on Solaris
*     27-JUL-1995 (DLT):
*        Seach for DCT file relative to PATH
*/

{

/* Local Variables */
char *ext = ".dat";
char *device;
char fil[256];
int i;

device = getdev();

strncpy (fil , device , strlen(device));
for (i = 0; i < (int)strlen(ext); i++)
   fil[i+strlen(device)] = ext[i];
fil[strlen(device)+strlen(ext)] = '\0';

getfile( fil, fildat);

return;
}
Ejemplo n.º 2
0
char *read_subchannels(char *path) {
	char *tmp, *ret;
	int n, x;
	struct dirent **cdevs;
		
	if ((n = scandir(path, &cdevs, is_cdev, alphasort)) <= 0)
		return NULL;
		
	ret = getdev(path,cdevs[0]->d_name);
	for (x = 1 ; x < n ; x++ ) { 
		if (asprintf(&tmp, "%s,%s", ret, getdev(path, cdevs[x]->d_name)) == -1) 
			return NULL;
		free(ret);
		ret = tmp;
	}
	return ret;
}
Ejemplo n.º 3
0
/*
 * Copy from to in 10K units.
 * Intended for use in system
 * installation.
 */
main()
{
	int from, to;
	char fbuf[50], tbuf[50];
	char buffer[10240];
	register int record;
	extern int errno;

	from = getdev("From", fbuf, 0);
	to = getdev("To", tbuf, 1);
	for (record = 0; ; record++) {
		int rcc, wcc;

		rcc = read(from, buffer, sizeof (buffer));
		if (rcc == 0)
			break;
		if (rcc < 0) {
			printf("Record %d: read error, errno=%d\n",
				record, errno);
			break;
		}
		if (rcc < sizeof (buffer))
			printf("Record %d: read short; expected %d, got %d\n",
				record, sizeof (buffer), rcc);
		/*
		 * For bug in ht driver.
		 */
		if (rcc > sizeof (buffer))
			rcc = sizeof (buffer);
		wcc = write(to, buffer, rcc);
		if (wcc < 0) {
			printf("Record %d: write error: errno=%d\n",
				record, errno);
			break;
		}
		if (wcc < rcc) {
			printf("Record %d: write short; expected %d, got %d\n",
				record, rcc, wcc);
			break;
		}
	}
	printf("Copy completed: %d records copied\n", record);
	/* can't call exit here */
}
Ejemplo n.º 4
0
blkno_t blk_alloc(uint16_t devno)
{
    fsptr dev;
    blkno_t newno;
    blkno_t *buf;
    uint8_t *mbuf;
    int j;

    if(baddev(dev = getdev(devno)))
        goto corrupt2;

    if(dev->s_nfree <= 0 || dev->s_nfree > FILESYS_TABSIZE)
        goto corrupt;

    newno = dev->s_free[--dev->s_nfree];
    if(!newno)
    {
        if(dev->s_tfree != 0)
            goto corrupt;
        udata.u_error = ENOSPC;
        ++dev->s_nfree;
        return(0);
    }

    /* See if we must refill the s_free array */

    if(!dev->s_nfree)
    {
        buf =(blkno_t *)bread(devno, newno, 0);
        dev->s_nfree = buf[0];
        for(j=0; j < FILESYS_TABSIZE; j++)
        {
            dev->s_free[j] = buf[j+1];
        }
        brelse((char *)buf);
    }

    validblk(devno, newno);

    if(!dev->s_tfree)
        goto corrupt;
    --dev->s_tfree;

    /* Zero out the new block */
    mbuf = bread(devno, newno, 2);
    memset(mbuf, 0, 512);
    bawrite(mbuf);
    return newno;

corrupt:
    kputs("blk_alloc: corrupt\n");
    dev->s_mounted = 1;
corrupt2:
    udata.u_error = ENOSPC;
    return 0;
}
Ejemplo n.º 5
0
uint16_t i_alloc(uint16_t devno)
{
    staticfast fsptr dev;
    staticfast blkno_t blk;
    struct dinode *buf;
    staticfast uint16_t j;
    uint16_t k;
    unsigned ino;

    if(baddev(dev = getdev(devno)))
        goto corrupt;

tryagain:
    if(dev->s_ninode) {
        if(!(dev->s_tinode))
            goto corrupt;
        ino = dev->s_inode[--dev->s_ninode];
        if(ino < 2 || ino >=(dev->s_isize-2)*8)
            goto corrupt;
        --dev->s_tinode;
        return(ino);
    }
    /* We must scan the inodes, and fill up the table */

    _sync();           /* Make on-disk inodes consistent */
    k = 0;
    for(blk = 2; blk < dev->s_isize; blk++) {
        buf = (struct dinode *)bread(devno, blk, 0);
        for(j=0; j < 8; j++) {
            if(!(buf[j].i_mode || buf[j].i_nlink))
                dev->s_inode[k++] = 8*(blk-2) + j;
            if(k==FILESYS_TABSIZE) {
                brelse(buf);
                goto done;
            }
        }
        brelse(buf);
    }

done:
    if(!k) {
        if(dev->s_tinode)
            goto corrupt;
        udata.u_error = ENOSPC;
        return(0);
    }
    dev->s_ninode = k;
    goto tryagain;

corrupt:
    kputs("i_alloc: corrupt superblock\n");
    dev->s_mounted = 1;
    udata.u_error = ENOSPC;
    return(0);
}
Ejemplo n.º 6
0
void i_free(uint16_t devno, uint16_t ino)
{
    fsptr dev;

    if(baddev(dev = getdev(devno)))
        return;

    if(ino < 2 || ino >=(dev->s_isize-2)*8)
        panic("i_free: bad ino");

    ++dev->s_tinode;
    if(dev->s_ninode < FILESYS_TABSIZE)
        dev->s_inode[dev->s_ninode++] = ino;
}
Ejemplo n.º 7
0
void test2()
 {
  Variable v{1,2,3};
  
  Printf(Con,"len = #;\n",SaveLen(v).value);
  
  uint8 buf[100];
  
  BufPutDev putdev(buf);
  
  putdev(v,v,v);
  
  Variable v1;
  
  BufGetDev getdev(buf);
  
  getdev(v1);
  
  Printf(Con,"#;\n",v1);
 
  getdev(v1);
  
  Printf(Con,"#;\n",v1);
  
  getdev(v1);
  
  Printf(Con,"#;\n",v1);
  
  RangeGetDev rget(Range_const(buf));
  
  Variable v2[3];
  
  LoadRange(v2,3,rget);
  
  Printf(Con,"#; #; #;\n",v2[0],v2[1],v2[2]);
 } 
Ejemplo n.º 8
0
void test1()
 {
  Fixed f{1,2,3,4};
  
  Printf(Con,"len = #;\n",SaveLen(f).value);
  
  uint8 buf[100];
  
  BufPutDev putdev(buf);
  
  putdev(f,f,f);
  
  Fixed f1;
  
  BufGetDev getdev(buf);
  
  getdev(f1);
  
  Printf(Con,"#;\n",f1);
 
  getdev(f1);
  
  Printf(Con,"#;\n",f1);
  
  getdev(f1);
  
  Printf(Con,"#;\n",f1);
  
  RangeGetDev rget(Range_const(buf));
  
  Fixed f2[3];
  
  rget(f2[0],f2[1],f2[2]);
  
  Printf(Con,"#; #; #;\n",f2[0],f2[1],f2[2]);
 } 
Ejemplo n.º 9
0
int
requested(char *argv[], struct acct *acp)
{
	const char *p;

	do {
		p = user_from_uid(acp->ac_uid, 0);
		if (!strcmp(p, *argv))
			return (1);
		if ((p = getdev(acp->ac_tty)) && !strcmp(p, *argv))
			return (1);
		if (!strncmp(acp->ac_comm, *argv, AC_COMM_LEN))
			return (1);
	} while (*++argv);
	return (0);
}
Ejemplo n.º 10
0
void vrpn_SGIBox::reset() {  /* Button/Dial box setup */
  int i;
  
  for (i=0; i<NUM_DIALS; i++) devs[i] = DIAL0+i;
  for (i=0; i<NUM_BUTTONS; i++) devs[i+NUM_DIALS] = SW0+i;
  btstat = 0;  /* Set all on/off buttons to off */
  //fprintf(stderr, "vrpn_SGIBox::reset %d\n", __LINE__);
  setdblights(btstat); /* Make the lights reflect this */
  //fprintf(stderr, "vrpn_SGIBox::reset %d\n", __LINE__);
  getdev(NUMDEVS, devs, vals1);  /* Get initial values */

  for (i=0; i<NUM_BUTTONS; i++)
    lastbuttons[i] = vals1[NUM_DIALS+i];

  for (i=0; i<NUM_DIALS; i++) mid_values[i] = vals1[i], last[i] = 0;
}
Ejemplo n.º 11
0
/**
 * Shell command (netdown) to stop a network interface.
 * @param nargs  number of arguments in args array
 * @param args   array of arguments
 * @return OK for success, SYSERR for syntax error
 */
shellcmd xsh_netdown(int nargs, char *args[])
{
    int descrp;

    /* Enable interrupts */
    enable();

    /* Help */
    if ((2 == nargs) && (0 == strncmp(args[1], "--help", 7)))
    {
        printf("Usage:\n");
        printf("\t%s <DEVICE>\n", args[0]);
        printf("Description:\n");
        printf
            ("\tStops a network interface on the specified underlying\n");
        printf("\tdevice.\n");
        printf("Options:\n");
        printf("\t<DEVICE>\tunderlying device (ex. ETH0)\n");
        printf("\t--help\t\tdisplay this help and exit\n");
        return SHELL_OK;
    }

    /* Verify number of arguments */
    if (nargs != 2)
    {
        fprintf(stderr, "Invalid number of arguments\n");
        return SHELL_ERROR;
    }

    /* Parse device */
    descrp = getdev(args[1]);
    if (SYSERR == descrp)
    {
        fprintf(stderr, "%s is not a valid device.\n", args[1]);
        return SHELL_ERROR;
    }

    if (SYSERR == netDown(descrp))
    {
        fprintf(stderr, "Failed to stop network interface on %s\n",
                args[1]);
        return SHELL_ERROR;
    }

    return SHELL_OK;
}
Ejemplo n.º 12
0
static int osf_cdfs_mount(char * dirname, struct cdfs_args * args, int flags)
{
	int retval;
	struct inode * inode;
	struct cdfs_args tmp;

	retval = verify_area(VERIFY_READ, args, sizeof(*args));
	if (retval)
		return retval;
	memcpy_fromfs(&tmp, args, sizeof(tmp));
	retval = getdev(tmp.devname, 1, &inode);
	if (retval)
		return retval;
	retval = do_mount(inode->i_rdev, tmp.devname, dirname, "iso9660", flags, NULL);
	if (retval)
		putdev(inode);
	iput(inode);
	return retval;
}
Ejemplo n.º 13
0
void vrpn_SGIBox::get_report() {
  int i;
  getdev(NUMDEVS, devs, vals1); /* read button/dial boxes */
  //fprintf(stderr, "Button=");
  for (i=0; i< NUM_BUTTONS; i++) {
    buttons[i] = vals1[NUM_DIALS+i];
  }
  for (i=0; i< NUM_DIALS; i++) {
    int temp = vals1[i] -mid_values[i];
    if (temp > 200) channel[i] = 0.5, mid_values[i] = vals1[i] - 200; 
    else if (temp < -200) channel[i] = -0.5, mid_values[i] = vals1[i]
			    + 200;
    else 
        channel[i] = temp/400.0;
      //fprintf(stderr, " %d", vals1[i]);
  }
  //fprintf(stderr, "\n");

  vrpn_Analog::report_changes();
  vrpn_Button_Filter::report_changes();
}
Ejemplo n.º 14
0
void blk_free(uint16_t devno, blkno_t blk)
{
    fsptr dev;
    uint8_t *buf;

    if(!blk)
        return;

    if(baddev(dev = getdev(devno)))
        return;

    validblk(devno, blk);

    if(dev->s_nfree == FILESYS_TABSIZE) {
        buf = bread(devno, blk, 1);
        memcpy(buf, (char *)&(dev->s_nfree), 51*sizeof(int));
        bawrite(buf);
        dev->s_nfree = 0;
    }

    ++dev->s_tfree;
    dev->s_free[(dev->s_nfree)++] = blk;
}
Ejemplo n.º 15
0
int testlfl(void){


//  lfsInit(0);
  int f;
  //  printf("getdev %d\n", getdev("EXTROOTFS"));
  f = lfsOpen(getdev("EXTROOTFS"), "./test" , 0);
  printf( "File0: %d\n", getdev("LFILE0"));

  printf( "Char %c\n", lflGetc( &devtab[getdev("LFILE0")] ));

  char testing[14];

  lflRead( &devtab[getdev("LFILE0")], (void*)testing, 20);
  printf("String %s\n", testing);

  lflPutc( &devtab[getdev("LFILE0")], '!');

  printf( "Char %c\n", lflGetc( &devtab[getdev("LFILE0")] ));

  lfltab[0].lfpos=0;

  char reading[30];
  lflRead( &devtab[getdev("LFILE0")], (void*)reading, 20);
  printf("NS: %s\n", reading);

  char lolface[40] = "HELLLLLOOO";;
  lflWrite( &devtab[getdev("LFILE0")], (void*)lolface, 20);

  lfltab[0].lfpos=0;
  lflRead( &devtab[getdev("LFILE0")], (void*)reading, 30);
  printf("NS: %s\n", reading);

  lflClose( &devtab[getdev("LFILE0")]);

  lfsOpen(getdev("EXTROOTFS"), "./test", 0);
  lflRead( &devtab[getdev("LFILE0")], (void*)reading, 30);
  printf("NS: %s\n", reading);

  return 0;
}
Ejemplo n.º 16
0
/**
 * The Xinu shell.  Provides an interface to execute commands.
 * @param descrp descriptor of device on which the shell is open
 * @return OK for successful exit, SYSERR for unrecoverable error
 */
thread shell(int indescrp, int outdescrp, int errdescrp)
{
  char buf[SHELL_BUFLEN];     /* line input buffer        */
  short buflen;               /* length of line input     */
  char tokbuf[SHELL_BUFLEN + SHELL_MAXTOK];   /* token value buffer       */
  short ntok;                 /* number of tokens         */
  char *tok[SHELL_MAXTOK];    /* pointers to token values */
  char *outname;              /* name of output file      */
  char *inname;               /* name of input file       */
  bool background;            /* is background proccess?  */
  syscall child;              /* pid of child thread      */
  ushort i, j;                /* temp variables           */
  irqmask im;                 /* interrupt mask state     */

  /* hostname variables */
  char hostnm[NET_HOSTNM_MAXLEN + 1]; /* hostname of backend      */
  char *hostptr;              /* pointer to hostname      */
  int hostname_strsz;         /* nvram hostname name size */
  device *devptr;             /* device pointer           */

  printf( "Welcome to the shell!\n" );

  /* Enable interrupts */
  enable();

  hostptr = NULL;
  devptr = NULL;
  hostname_strsz = 0;
  bzero(hostnm, NET_HOSTNM_MAXLEN + 1);

  /* Setup buffer for string for nvramGet call for hostname */
#ifdef ETH0
  if (!isbaddev(ETH0))
  {
    /* Determine the hostname of the main network device */
    devptr = (device *)&devtab[ETH0];
    hostname_strsz = strnlen(NET_HOSTNAME, NVRAM_STRMAX) + 1;
    hostname_strsz += DEVMAXNAME;
    char nvramget_hostname_str[hostname_strsz];
    sprintf(nvramget_hostname_str, "%s_%s", devptr->name,
        NET_HOSTNAME);

    /* Acquire the backend's hostname */
#if NVRAM
    hostptr = nvramGet(nvramget_hostname_str);
#endif                          /* NVRAM */
    if (hostptr != NULL)
    {
      memcpy(hostnm, hostptr, NET_HOSTNM_MAXLEN);
      hostptr = hostnm;
    }
  }
#endif

  /* Set command devices for input, output, and error */
  stdin = indescrp;
  stdout = outdescrp;
  stderr = errdescrp;

  /* Print shell banner */
  printf(SHELL_BANNER);
  /* Print shell welcome message */
  printf(SHELL_START);

  /* Continually receive and handle commands */
  while (TRUE)
  {
    /* Display prompt */
    printf(SHELL_PROMPT);

    if (NULL != hostptr)
    {
      printf("@%s$ ", hostptr);
    }
    else
    {
      printf("$ ");
    }

    /* Setup proper tty modes for input and output */
    control(stdin, TTY_CTRL_CLR_IFLAG, TTY_IRAW, NULL);
    control(stdin, TTY_CTRL_SET_IFLAG, TTY_ECHO, NULL);

    /* Null out the buf and read command */
    memset(buf, '\0', SHELL_BUFLEN);
    buflen = shellRead(stdin, buf, SHELL_BUFLEN);

    if(buf[0] != '!') {
      addHistoryItem(buf, buflen);
    }

    /* Check for EOF and exit gracefully if seen */
    if (EOF == buflen)
    {
      break;
    }

    // Check for indicator of history command
    if (buf[0] == '!')
    {
      int index;

      // handler for !! (just execute most recent command)
      if(buf[1] == '!') {
        index = 0;
      } else {
        // extract the number string
        char indexString[buflen];
        strncpy(indexString, &buf[1], buflen - 1);
        indexString[buflen] = '\0';

        // convert number string into a valid index
        // calculation is done because the index numbers
        // are reverse of their numbers printed using 'history'
        index = numHistoryItems - atoi(indexString);
      }

      //replace buf and buflen with the last command
      strncpy(buf, history[index].command, SHELL_BUFLEN);
      buflen = history[index].commandLength + 1;
    }

    /* Parse line input into tokens */
    if (SYSERR == (ntok = lexan(buf, buflen, &tokbuf[0], &tok[0])))
    {
      fprintf(stderr, SHELL_SYNTAXERR);
      continue;
    }

    /* Ensure parse generated tokens */
    if (0 == ntok)
    {
      continue;
    }

    /* Initialize command options */
    inname = NULL;
    outname = NULL;
    background = FALSE;

    /* Mark as background thread, if last token is '&' */
    if ('&' == *tok[ntok - 1])
    {
      ntok--;
      background = TRUE;
    }

    /* Check each token and perform special handling of '>' and '<' */
    for (i = 0; i < ntok; i++)
    {
      /* Background '&' should have already been handled; Syntax error */
      if ('&' == *tok[i])
      {
        ntok = -1;
        break;
      }

      /* Setup for output redirection if token is '>'  */
      if ('>' == *tok[i])
      {
        /* Syntax error */
        if (outname != NULL || i >= ntok - 1)
        {
          ntok = -1;
          break;
        }

        outname = tok[i + 1];
        ntok -= 2;

        /* shift tokens (not to be passed to command */
        for (j = i; j < ntok; j++)
        {
          tok[j] = tok[j + 2];
        }
        continue;
      }

      /* Setup for input redirection if token is '<' */
      if ('<' == *tok[i])
      {
        /* Syntax error */
        if (inname != NULL || i >= ntok - 1)
        {
          ntok = -1;
          break;
        }
        inname = tok[i + 1];
        ntok -= 2;

        /* shift tokens (not to be passed to command */
        for (j = i; j < ntok; j++)
        {
          tok[j] = tok[j + 2];
        }

        continue;
      }
    }

    /* Handle syntax error */
    if (ntok <= 0)
    {
      fprintf(stderr, SHELL_SYNTAXERR);
      continue;
    }

    /* Lookup first token in the command table */
    for (i = 0; i < ncommand; i++)
    {
      if (0 == strncmp(commandtab[i].name, tok[0], SHELL_BUFLEN))
      {
        break;
      }
    }

    /* Handle command not found */
    if (i >= ncommand)
    {
      fprintf(stderr, "%s: command not found\n", tok[0]);
      continue;
    }

    /* Handle command if it is built-in */
    if (commandtab[i].builtin)
    {
      if (inname != NULL || outname != NULL || background)
      {
        fprintf(stderr, SHELL_SYNTAXERR);
      }
      else
      {
        (*commandtab[i].procedure) (ntok, tok);
      }
      continue;
    }

    /* Spawn child thread for non-built-in commands */
    child =
      create(commandtab[i].procedure,
          SHELL_CMDSTK, SHELL_CMDPRIO,
          commandtab[i].name, 2, ntok, tok);



    /* Ensure child command thread was created successfully */
    if (SYSERR == child)
    {
      fprintf(stderr, SHELL_CHILDERR);
      continue;
    }

    /* Set file descriptors for newly created thread */
    if (NULL == inname)
    {
      thrtab[child].fdesc[0] = stdin;
    }
    else
    {
      thrtab[child].fdesc[0] = getdev(inname);
    }
    if (NULL == outname)
    {
      thrtab[child].fdesc[1] = stdout;
    }
    else
    {
      thrtab[child].fdesc[1] = getdev(outname);
    }
    thrtab[child].fdesc[2] = stderr;

    if (background)
    {
      /* Make background thread ready, but don't reschedule */
      im = disable();
      ready(child, RESCHED_NO);
      restore(im);
    }
    else
    {
      /* Clear waiting message; Reschedule; */
      while (recvclr() != NOMSG);
      im = disable();
      ready(child, RESCHED_YES);
      restore(im);

      /* Wait for command thread to finish */
      while (receive() != child);
      sleep(10);
    }
  }

  /* Close shell */
  fprintf(stdout, SHELL_EXIT);
  sleep(10);
  return OK;
}
Ejemplo n.º 17
0
/**
 * @ingroup shell
 *
 * Shell command (timeserver).
 * @param nargs number of arguments in args array
 * @param args  array of arguments
 * @return 0 for success, 1 for error
 */
shellcmd xsh_timeserver(int nargs, char *args[])
{
    int descrp, port, i;

    /* parse arguments to find port number */
    if ((2 == nargs) && (strcmp(args[1], "--help") == 0))
    {
        printf("Usage: %s [-d device] [-p port]\n\n", args[0]);
        printf("Description:\n");
        printf("\tSpawns a time server, providing remote system time\n");
        printf("Options:\n");
        printf
            ("\t-d device\tdevice to listen for traffic. (default: ETH0)\n");
        printf
            ("\t-p port\t\tport on which the server listens. (default: %d)\n",
             UDP_PORT_RDATE);
        printf("\t--help\t\tdisplay this help information and exit\n");
        return 0;
    }

    if (nargs > 4)
    {
        fprintf(stderr, "%s: too many arguments\n", args[0]);
        fprintf(stderr, "Try %s --help for usage\n", args[0]);
        return SHELL_ERROR;
    }

    /* assume default device and port */
    descrp = (ethertab[0].dev)->num;
    port = UDP_PORT_RDATE;

    /* set user options if specified */
    for (i = 1; i < nargs; i++)
    {
        if (strcmp(args[i], "-d") == 0)
        {
            i++;
            if (i >= nargs)
                return argErr(args[0], "");
            descrp = getdev(args[i]);
        }
        else if (strcmp(args[i], "-p") == 0)
        {
            i++;
            if (i >= nargs)
                return argErr(args[0], "");
            port = atoi(args[i]);
        }
        else
        {
            return argErr(args[0], args[i]);
        }
    }

    /* verify the device is valid */
    if (isbaddev(descrp))
    {
        fprintf(stderr, "%s: invalid device.\n", args[0]);
        fprintf(stderr, "Try %s --help for usage\n", args[0]);
        return SHELL_ERROR;
    }

    /* verify the provided port is a valid number */
    if (port <= 0)
    {
        fprintf(stderr, "%s: invalid port\n", args[0]);
        fprintf(stderr, "Try %s --help for usage\n", args[0]);
        return SHELL_ERROR;
    }

    ready(create((void *)timeServer, INITSTK, INITPRIO, "TimeServer",
                 2, descrp, port), RESCHED_YES);

    return SHELL_OK;
}
Ejemplo n.º 18
0
/**
 * Shell command (netup) to start a network interface.
 * @param nargs  number of arguments in args array
 * @param args   array of arguments
 * @return OK for success, SYSERR for syntax error
 */
shellcmd xsh_netup(int nargs, char *args[])
{
    int descrp;
    struct netaddr ip;
    struct netaddr mask;
    struct netaddr gateway;
    char *str_ip, *str_mask, *str_gateway;
    char nvramLookup[DEVMAXNAME + NVRAM_STRMAX];

    /* Enable interrupts */
    enable();

    /* Help */
    if ((2 == nargs) && (0 == strncmp(args[1], "--help", 7)))
    {
        usage(args[0]);
        return SHELL_OK;
    }

    /* Parse device */
    if (nargs > 1)
    {
        descrp = getdev(args[1]);
        if (SYSERR == descrp)
        {
            fprintf(stderr, "%s is not a valid device.\n", args[1]);
            return SHELL_ERROR;
        }
    }
    else
    {
        /* assume first ethernet interface */
        descrp = (ethertab[0].dev)->num;
    }

    if (5 == nargs)
    {
        /* grab string data */
        str_ip = args[2];
        str_mask = args[3];
        str_gateway = args[4];
    }
    else if (nargs < 3)
    {
        /* lookup information in nvram */
        bzero(nvramLookup, DEVMAXNAME + NVRAM_STRMAX);
        sprintf(nvramLookup, "%s_%s", (ethertab[0].dev)->name,
                NET_LAN_IPADDR);
#if NVRAM
        str_ip = nvramGet(nvramLookup);
        if (NULL == str_ip)
        {
            str_ip = nvramGet("lan_ipaddr");
        }
#else
        str_ip = NULL;
#endif                          /* NVRAM */

        bzero(nvramLookup, DEVMAXNAME + NVRAM_STRMAX);
        sprintf(nvramLookup, "%s_%s", (ethertab[0].dev)->name,
                NET_SUBNET_MASK);
#if NVRAM
        str_mask = nvramGet(nvramLookup);
        if (NULL == str_mask)
        {
            str_mask = nvramGet("lan_netmask");
        }
#else
        str_mask = NULL;
#endif                          /* NVRAM */

#if NVRAM
        str_gateway = nvramGet(NET_GATEWAY);
        if (NULL == str_gateway)
        {
            str_gateway = nvramGet("lan_gateway");
        }
#else
        str_gateway = NULL;
#endif                          /* NVRAM */
    }
    else
    {
        fprintf(stderr, "Invalid number of arguments\n");
        return SHELL_ERROR;
    }

    /* Make sure we have valid IPv4 style parameters */
    if (NULL == str_ip)
    {
        str_ip = "0.0.0.0";
    }

    if (NULL == str_mask)
    {
        str_mask = "0.0.0.0";
    }

    if (NULL == str_gateway)
    {
        str_gateway = "0.0.0.0";
    }

    /* Parse IP */
    if (SYSERR == dot2ipv4(str_ip, &ip))
    {
        fprintf(stderr, "%s is not a valid IPv4 address.\n", str_ip);
        return SHELL_ERROR;
    }

    /* Parse Mask */
    if (SYSERR == dot2ipv4(str_mask, &mask))
    {
        fprintf(stderr, "%s is not a valid IPv4 address mask.\n",
                str_mask);
        return SHELL_ERROR;
    }

    /* Parse Gateway */
    if (SYSERR == dot2ipv4(str_gateway, &gateway))
    {
        fprintf(stderr, "%s is not a valid IPv4 address.\n", str_gateway);
        return SHELL_ERROR;
    }

    if (SYSERR == netUp(descrp, &ip, &mask, &gateway))
    {
        fprintf(stderr, "Failed to start network interface on %s\n",
                args[1]);
        return SHELL_ERROR;
    }

    printf("%s is %s with netmask %s (gateway: %s)\n",
           devtab[descrp].name, str_ip, str_mask, str_gateway);

    return SHELL_OK;
}
Ejemplo n.º 19
0
main()
{
    float ship[XY];
    long org[XY];
    long size[XY];
    Device dev;
    short val;
    Device mdev[XY];
    short mval[XY];
    long nhits;
    short buffer[BUFSIZE];
    Boolean run;

    prefsize(400, 400);
    winopen("select1");
    getorigin(&org[X], &org[Y]);
    getsize(&size[X], &size[Y]);
    mmode(MVIEWING);
    ortho2(-0.5, size[X] - 0.5, -0.5, size[Y] - 0.5);
    qdevice(LEFTMOUSE);
    qdevice(ESCKEY);
    color(BLACK);
    clear();
    mdev[X] = MOUSEX;
    mdev[Y] = MOUSEY;

    drawplanet();
    run = TRUE;
    while (run) {
	dev = qread(&val);
	if (val == 0) {				/* on upstroke */
	    switch (dev) {
	    case LEFTMOUSE:
		getdev(XY, mdev, mval);
		ship[X] = mval[X] - org[X];
		ship[Y] = mval[Y] - org[Y];
		color(BLUE);
		sbox(ship[X], ship[Y], 
		     ship[X] + SHIPWIDTH, ship[Y] + SHIPHEIGHT);

		/*
		 * specify the selecting region to be a box surrounding the
		 * rocket ship 
		 */
		ortho2(ship[X], ship[X] + SHIPWIDTH, 
		       ship[Y], ship[Y] + SHIPHEIGHT);

		initnames();
		gselect(buffer, BUFSIZE);
		    loadname(PLANET);
		    /* no actual drawing takes place */
		    drawplanet();
		nhits = endselect(buffer);

		/*
		 * restore the Projection matrix; NB. can't use push/popmatrix 
		 * since they only work for the ModelView matrix stack 
		 * when in MVIEWING mode
		 */
		ortho2(-0.5, size[X] - 0.5, -0.5, size[Y] - 0.5);

		/* 
		 * check to see if PLANET was selected; NB. nhits is NOT the
		 * number of buffer elements written
		 */
		if (nhits < 0) {
		    fprintf(stderr, "gselect buffer overflow\n");
		    run = FALSE;
		} 
		else if (nhits >= 1 && buffer[0] == 1 && buffer[1] == PLANET)
		    ringbell();
		break;
	    case ESCKEY:
		run = FALSE;
		break;
	    }
	}
    }
    gexit();
    return 0;
}
Ejemplo n.º 20
0
/**
 * @ingroup shell
 *
 * Kernel execute- Transfer control to a new kernel.
 */
shellcmd xsh_kexec(int nargs, char *args[])
{
    int dev;

    /* Output help, if '--help' argument was supplied */
    if (2 == nargs && 0 == strcmp(args[1], "--help"))
    {
        usage(args[0]);
        return SHELL_OK;
    }

    if (3 != nargs && 4 != nargs)
    {
        fprintf(stderr, "ERROR: Wrong number of arguments.\n");
        usage(args[0]);
        return SHELL_ERROR;
    }

    if (0 == strcmp(args[1], "-n"))
    {
        dev = getdev(args[2]);
        if (SYSERR == dev)
        {
            fprintf(stderr, "ERROR: device \"%s\" not found.\n", args[2]);
            return SHELL_ERROR;
        }
    #if NETHER
        if (dev < ETH0 || dev >= ETH0 + NETHER)
    #endif
        {
            fprintf(stderr, "ERROR: \"%s\" is not a valid network device.\n",
                    args[2]);
            return SHELL_ERROR;
        }
		  if (4 == nargs) // For specific .boot files on tftpboot server
		  		kexec_from_network(dev, args[3]);
        else // For DHCP defined .boot files on tftpboot server
				kexec_from_network(dev, NULL);
    }
    else if (0 == strcmp(args[1], "-u"))
    {
        dev = getdev(args[2]);
        if (SYSERR == dev)
        {
            fprintf(stderr, "ERROR: device \"%s\" not found.\n", args[2]);
            return SHELL_ERROR;
        }
    #if NUART
        if (dev < SERIAL0 || dev >= SERIAL0 + NUART)
    #endif
        {
            fprintf(stderr, "ERROR: \"%s\" is not a valid UART device.\n",
                    args[2]);
            return SHELL_ERROR;
        }
        kexec_from_uart(dev);
    }
    else
    {
        usage(args[0]);
    }

    return SHELL_ERROR;
}
Ejemplo n.º 21
0
/*
 half OK w95
 */
void subEventLoop() 
{
   short     sVal, sXCurrent, sYCurrent;
   long      lDevice;
	float tmp;

   nCurrentDir = DIR_NONE;
   czclear(0x404040, getgdesc(GD_ZMAX));

   strcpy(Message, ReadyMesg);
   vDrawScene();
   qreset();
   while (TRUE) {

      if (qtest()) {
         lDevice = qread(&sVal);

         switch (lDevice)
			{

			case INPUTCHANGE:
				#ifdef DOFF
					printf(" %d, %d, %d\n", Win_ids[0], Win_ids[1], sVal);
				#endif
				if ( sVal != 0 )
					Input_win = sVal;
				else
					Input_win = -1;
				break;

            case REDRAW:
				if ( sVal == Win_ids[1] && Win_ids[1] != -1 )
					vDrawHelpScene();
				else if ( sVal == Win_ids[0] )
				{
					winset(Win_ids[0]);
               		reshapeviewport();
               		getsize(&nWinWidth, &nWinHeight);
               		getorigin(&nXWinOrigin, &nYWinOrigin);
					tmp = Speed;
					Speed = 0.0;
               		vDrawScene();
					Speed = tmp;
				}
            break;

         case RIGHTMOUSE:
               dopup(mainmenu);
               break;
  
			case SPACEKEY:
				if ( EMode == FALSE )
				{
					p1EventLoop();
					strcpy(Message, "");
				}
				if ( EMode == TRUE )    /* game over */
				{
					vDrawOverScene();
				}
				break;

			case RKEY:
				if ( Last_Actions[FIRE] == TRUE )
					vEventLoop((&vDrawScene));
				break;

         case QKEY:
				if ( Input_win == Win_ids[1] ) 
				{
					winclose(Input_win);
					Win_ids[1] != -1;
				}
				else if ( Input_win == Win_ids[0] )
				{
					winclose(Win_ids[0]);
					if ( Win_ids[1] != -1 )
						winclose(Win_ids[1]);
	               exit(0);
				}
				break;

             default:
               break;
         }
      }
	  else
		getdev(DR_NUM_BUT, Devs, Last_Actions);

   }
}
Ejemplo n.º 22
0
/*---------------------------------------------------------------------------
main play loop
---------------------------------------------------------------------------*/
void p1EventLoop() {

   short     sVal;
   long      lDevice;
   Matrix    mNewMat;
   int		 reset = TRUE, i;
	static OKMode = FALSE;

	PMode = TRUE;

    strcpy(Message, "");
    while (TRUE) 
	{

		if (qtest()) 
		{
    		lDevice = qread(&sVal);

        	switch (lDevice) 
			{

			case INPUTCHANGE:
				#ifdef DOFF
					printf(" %d, %d, %d\n", Win_ids[0], Win_ids[1], sVal);
				#endif
				if ( sVal != 0 )
					Input_win = sVal;
				else
					Input_win = -1;
				break;

            case REDRAW:
				if ( sVal == Win_ids[1] && Win_ids[1] != -1 )
					vDrawHelpScene();
				else if ( sVal == Win_ids[0] )
				{
					winset(Win_ids[0]);
               		reshapeviewport();
               		getsize(&nWinWidth, &nWinHeight);
               		getorigin(&nXWinOrigin, &nYWinOrigin);
/*
               		vDrawScene();
*/
				}
               break;

				case ESCKEY:
					if ( OKMode != TRUE)
						return;
					break;

            case QKEY:
				if ( Input_win == Win_ids[1] ) 
				{
					winclose(Input_win);
					Win_ids[1] != -1;
				}
				else if ( Input_win == Win_ids[0] )
				{
					winclose(Win_ids[0]);
					if ( Win_ids[1] != -1 )
						winclose(Win_ids[1]);
	               exit(0);
				}
                	break;
        	}
		}

		getdev(DR_NUM_BUT, Devs, Last_Actions);

		if ( Time == Time/REDRAW_RATE*REDRAW_RATE )
		{
			if ( Energy <= 0 )
			{
				EMode = TRUE;
				return;
			}
			else if ( Time >= END_TIME )
			{
				OKMode = TRUE;
				last_mesg();
			}
			else
				vDrawScene();
		}

		for ( i=0; i<DR_NUM_BUT; i++)
		{
			Last_Actions[i] = FALSE;
		}
		Time++;

	}
}
Ejemplo n.º 23
0
int
main(int argc, char **argv)
{

	/* 
	 *  Automatic data
	 */

	char	      **arglist;	/* List of arguments */
	char	      **criterialist;	/* List of criteria */
	char	      **devicelist;	/* List of devices to search/ignore */
	char	      **fitdevlist;	/* List of devices that fit criteria */
	char	       *cmdname;	/* Simple command name */
	char	       *device;		/* Device name in the list */
	char	       *devtab;		/* The device table name */
	int		exitcode;	/* Value to return to the caller */
	int		sev;		/* Message severity */
	int		optchar;	/* Option character (from getopt()) */
	int		andflag;	/* TRUE if criteria are to be anded */
	int		excludeflag;	/* TRUE if exclude "devices" lists */
	int		options;	/* Options to pass to getdev() */
	int		usageerr;	/* TRUE if syntax error */


	/* Build the message label from the (simple) command name */
	if ((cmdname = strrchr(argv[0], '/')) != (char *) NULL) cmdname++;
	else cmdname = argv[0];
	(void) strlcat(strcpy(lbl, "UX:"), cmdname, sizeof(lbl));

	/* Write text-component of messages only (goes away in SVR4.1) */
	(void) putenv("MSGVERB=text");

	/* 
	 *  Parse the command line:
	 *	- Options
	 *	- Selection criteria
	 *	- Devices to include or exclude
	 */

	/* 
	 *  Extract options from the command line 
	 */

	/* Initializations */
	andflag = FALSE;	/* No -a -- Or criteria data */
	excludeflag = FALSE;	/* No -e -- Include only mentioned devices */
	usageerr = FALSE;	/* No errors on the command line (yet) */

	/* 
	 *  Loop until all of the command line options have been parced 
	 */
	opterr = FALSE;			/* Don't let getopt() write messages */
	while ((optchar = getopt(argc, argv, "ae")) != EOF) switch (optchar) {

	/* -a  List devices that fit all of the criteria listed */
	case 'a': 
	    if (andflag) usageerr = TRUE;
	    else andflag = TRUE;
	    break;

	/* -e  Exclude those devices mentioned on the command line */
	case 'e':
	    if (excludeflag) usageerr = TRUE;
	    else excludeflag = TRUE;
	    break;

	/* Default case -- command usage error */
	case '?':
	default:
	    usageerr = TRUE;
	    break;
	}

	/* If there is a usage error, write an appropriate message and exit */
	if (usageerr) {
	    stdmsg(MM_NRECOV, lbl, MM_ERROR, M_USAGE);
	    exit(EX_ERROR);
	}

	/* Open the device file (if there's one to be opened) */
	if (!_opendevtab("r")) {
	    if (devtab = _devtabpath()) {
		(void) snprintf(txt, sizeof(txt), M_DEVTAB, devtab);
		sev = MM_ERROR;
		exitcode = EX_DEVTAB;
	    } else {
		(void) sprintf(txt, M_ERROR, errno);
		sev = MM_HALT;
		exitcode = EX_ERROR;
	    }
	    stdmsg(MM_NRECOV, lbl, sev, txt);
	    exit(exitcode);
	}

	/* Build the list of criteria and devices */
	arglist = argv + optind;
	criterialist = buildcriterialist(arglist);
	devicelist = builddevlist(arglist);
	options = (excludeflag?DTAB_EXCLUDEFLAG:0)|(andflag?DTAB_ANDCRITERIA:0);

	/* 
	 *  Get the list of devices that meets the criteria requested.  If we 
	 *  got a list (that might be empty), write that list to the standard 
	 *  output file (stdout).
	 */

	exitcode = 0;
	if (!(fitdevlist = getdev(devicelist, criterialist, options))) {
	    exitcode = 1;
	}
	else for (device = *fitdevlist++ ; device ; device = *fitdevlist++)
		(void) puts(device);

	/* Finished */
	return(exitcode);
}
Ejemplo n.º 24
0
int
main(int argc, char *argv[])
{
	char *p;
	struct acct ab;
	struct stat sb;
	FILE *fp;
	off_t size = 0;
	time_t t;
	int ch;
	const char *acctfile;
	int flags = 0;

	acctfile = _PATH_ACCT;
	while ((ch = getopt(argc, argv, "f:usecSE")) != -1)
		switch((char)ch) {
		case 'f':
			acctfile = optarg;
			break;

		case 'u': 
			flags |= AC_UTIME; /* user time */
			break;
		case 's':
			flags |= AC_STIME; /* system time */
			break;
		case 'e':
			flags |= AC_ETIME; /* elapsed time */
			break;
		case 'c':
                        flags |= AC_CTIME; /* user + system time */
			break;

		case 'S':
                        flags |= AC_BTIME; /* starting time */
			break;
		case 'E':
			/* exit time (starting time + elapsed time )*/
                        flags |= AC_FTIME; 
			break;

		case '?':
		default:
			usage();
		}

	/* default user + system time and starting time */
	if (!flags) {
	    flags = AC_CTIME | AC_BTIME;
	}

	argc -= optind;
	argv += optind;

	if (strcmp(acctfile, "-") == 0)
		fp = stdin;
	else {
		/* Open the file. */
		if ((fp = fopen(acctfile, "r")) == NULL ||
		    fstat(fileno(fp), &sb))
			err(1, "could not open %s", acctfile);

		/*
		 * Round off to integral number of accounting records,
		 * probably not necessary, but it doesn't hurt.
		 */
		size = sb.st_size - sb.st_size % sizeof(struct acct);

		/* Check if any records to display. */
		if ((unsigned)size < sizeof(struct acct))
			exit(0);
	}

	do {
		int rv;

		if (fp != stdin) {
			size -= sizeof(struct acct);
			if (fseeko(fp, size, SEEK_SET) == -1)
				err(1, "seek %s failed", acctfile);
		}

		if ((rv = fread(&ab, sizeof(struct acct), 1, fp)) != 1) {
			if (feof(fp))
				break;
			else
				err(1, "read %s returned %d", acctfile, rv);
		}

		if (ab.ac_comm[0] == '\0') {
			ab.ac_comm[0] = '?';
			ab.ac_comm[1] = '\0';
		} else
			for (p = &ab.ac_comm[0];
			    p < &ab.ac_comm[AC_COMM_LEN] && *p; ++p)
				if (!isprint(*p))
					*p = '?';
		if (*argv && !requested(argv, &ab))
			continue;

		(void)printf("%-*.*s %-7s %-*s %-*s",
			     AC_COMM_LEN, AC_COMM_LEN, ab.ac_comm,
			     flagbits(ab.ac_flag),
			     UT_NAMESIZE, user_from_uid(ab.ac_uid, 0),
			     UT_LINESIZE, getdev(ab.ac_tty));
		
		
		/* user + system time */
		if (flags & AC_CTIME) {
			(void)printf(" %6.2f secs", 
				     (expand(ab.ac_utime) + 
				      expand(ab.ac_stime))/AC_HZ);
		}
		
		/* usr time */
		if (flags & AC_UTIME) {
			(void)printf(" %6.2f us", expand(ab.ac_utime)/AC_HZ);
		}
		
		/* system time */
		if (flags & AC_STIME) {
			(void)printf(" %6.2f sy", expand(ab.ac_stime)/AC_HZ);
		}
		
		/* elapsed time */
		if (flags & AC_ETIME) {
			(void)printf(" %8.2f es", expand(ab.ac_etime)/AC_HZ);
		}
		
		/* starting time */
		if (flags & AC_BTIME) {
			(void)printf(" %.16s", ctime(&ab.ac_btime));
		}
		
		/* exit time (starting time + elapsed time )*/
		if (flags & AC_FTIME) {
			t = ab.ac_btime;
			t += (time_t)(expand(ab.ac_etime)/AC_HZ);
			(void)printf(" %.16s", ctime(&t));
		}
		printf("\n");

	} while (size > 0);
	exit(0);
}
Ejemplo n.º 25
0
Archivo: shell.c Proyecto: osa1/osdev
/**
 * @ingroup shell
 *
 * The Xinu shell.  Provides an interface to execute commands.
 * @param descrp descriptor of device on which the shell is open
 * @return OK for successful exit, SYSERR for unrecoverable error
 */
thread shell(int indescrp, int outdescrp, int errdescrp)
{
    char buf[SHELL_BUFLEN];     /* line input buffer        */
    short buflen;               /* length of line input     */
    char tokbuf[SHELL_BUFLEN + SHELL_MAXTOK];   /* token value buffer       */
    short ntok;                 /* number of tokens         */
    char *tok[SHELL_MAXTOK];    /* pointers to token values */
    char *outname;              /* name of output file      */
    char *inname;               /* name of input file       */
    bool background;            /* is background proccess?  */
    syscall child;              /* pid of child thread      */
    ushort i, j;                /* temp variables           */
    irqmask im;                 /* interrupt mask state     */
    char *hostptr = NULL;       /* pointer to hostname      */

    /* Setup buffer for string for nvramGet call for hostname */
#if defined(ETH0) && NVRAM
    char hostnm[NET_HOSTNM_MAXLEN + 1]; /* hostname of backend      */
    if (!isbaddev(ETH0))
    {
        size_t hostname_strsz;          /* nvram hostname name size */

        bzero(hostnm, NET_HOSTNM_MAXLEN + 1);

        /* Determine the hostname of the main network device */
        hostname_strsz = strlen(NET_HOSTNAME);
        hostname_strsz += 1;
        hostname_strsz += DEVMAXNAME;
        hostname_strsz += 1;
        char nvramget_hostname_str[hostname_strsz];
        sprintf(nvramget_hostname_str, "%s_%s", devtab[ETH0].name,
                NET_HOSTNAME);

        /* Acquire the backend's hostname */
        hostptr = nvramGet(nvramget_hostname_str);
        if (hostptr != NULL)
        {
            strncpy(hostnm, hostptr, NET_HOSTNM_MAXLEN);
            hostptr = hostnm;
        }
    }
#endif

    /* Set command devices for input, output, and error */
    stdin = indescrp;
    stdout = outdescrp;
    stderr = errdescrp;

    /* Print shell banner to framebuffer, if exists */
#if defined(FRAMEBUF)
    if (indescrp == FRAMEBUF)
    {
        foreground = RASPBERRY;
        printf(SHELL_BANNER_NONVT100);
        foreground = LEAFGREEN;
        printf(SHELL_START);
        foreground = GREEN;
    }
    else
#endif
    {
        printf(SHELL_BANNER);
        printf(SHELL_START);
    }

    /* Continually receive and handle commands */
    while (TRUE)
    {
        /* Display prompt */
        printf(SHELL_PROMPT);

        if (NULL != hostptr)
        {
            printf("@%s$ ", hostptr);
        }
        else
        {
            printf("$ ");
        }

        /* Setup proper tty modes for input and output */
        control(stdin, TTY_CTRL_CLR_IFLAG, TTY_IRAW, NULL);
        control(stdin, TTY_CTRL_SET_IFLAG, TTY_ECHO, NULL);

        /* Read command */
        buflen = read(stdin, buf, SHELL_BUFLEN - 1);

        /* Check for EOF and exit gracefully if seen */
        if (EOF == buflen)
        {
            break;
        }

        /* Parse line input into tokens */
        if (SYSERR == (ntok = lexan(buf, buflen, &tokbuf[0], &tok[0])))
        {
            fprintf(stderr, SHELL_SYNTAXERR);
            continue;
        }

        /* Ensure parse generated tokens */
        if (0 == ntok)
        {
            continue;
        }

        /* Initialize command options */
        inname = NULL;
        outname = NULL;
        background = FALSE;

        /* Mark as background thread, if last token is '&' */
        if ('&' == *tok[ntok - 1])
        {
            ntok--;
            background = TRUE;
        }

        /* Check each token and perform special handling of '>' and '<' */
        for (i = 0; i < ntok; i++)
        {
            /* Background '&' should have already been handled; Syntax error */
            if ('&' == *tok[i])
            {
                ntok = -1;
                break;
            }

            /* Setup for output redirection if token is '>'  */
            if ('>' == *tok[i])
            {
                /* Syntax error */
                if (outname != NULL || i >= ntok - 1)
                {
                    ntok = -1;
                    break;
                }

                outname = tok[i + 1];
                ntok -= 2;

                /* shift tokens (not to be passed to command */
                for (j = i; j < ntok; j++)
                {
                    tok[j] = tok[j + 2];
                }
                continue;
            }

            /* Setup for input redirection if token is '<' */
            if ('<' == *tok[i])
            {
                /* Syntax error */
                if (inname != NULL || i >= ntok - 1)
                {
                    ntok = -1;
                    break;
                }
                inname = tok[i + 1];
                ntok -= 2;

                /* shift tokens (not to be passed to command */
                for (j = i; j < ntok; j++)
                {
                    tok[j] = tok[j + 2];
                }

                continue;
            }
        }

        /* Handle syntax error */
        if (ntok <= 0)
        {
            fprintf(stderr, SHELL_SYNTAXERR);
            continue;
        }

        /* Lookup first token in the command table */
        for (i = 0; i < ncommand; i++)
        {
            if (0 == strcmp(commandtab[i].name, tok[0]))
            {
                break;
            }
        }

        /* Handle command not found */
        if (i >= ncommand)
        {
            fprintf(stderr, "%s: command not found\n", tok[0]);
            continue;
        }

        /* Handle command if it is built-in */
        if (commandtab[i].builtin)
        {
            if (inname != NULL || outname != NULL || background)
            {
                fprintf(stderr, SHELL_SYNTAXERR);
            }
            else
            {
                (*commandtab[i].procedure) (ntok, tok);
            }
            continue;
        }

        /* Spawn child thread for non-built-in commands */
        child =
            create(commandtab[i].procedure,
                   SHELL_CMDSTK, SHELL_CMDPRIO,
                   commandtab[i].name, 2, ntok, tok);

        /* Ensure child command thread was created successfully */
        if (SYSERR == child)
        {
            fprintf(stderr, SHELL_CHILDERR);
            continue;
        }

        /* Set file descriptors for newly created thread */
        if (NULL == inname)
        {
            thrtab[child].fdesc[0] = stdin;
        }
        else
        {
            thrtab[child].fdesc[0] = getdev(inname);
        }
        if (NULL == outname)
        {
            thrtab[child].fdesc[1] = stdout;
        }
        else
        {
            thrtab[child].fdesc[1] = getdev(outname);
        }
        thrtab[child].fdesc[2] = stderr;

        if (background)
        {
            /* Make background thread ready, but don't reschedule */
            im = disable();
            ready(child, RESCHED_NO);
            restore(im);
        }
        else
        {
            /* Clear waiting message; Reschedule; */
            while (recvclr() != NOMSG);
            im = disable();
            ready(child, RESCHED_YES);
            restore(im);

            /* Wait for command thread to finish */
            while (receive() != child);
            sleep(10);
        }
    }

    /* Close shell */
    fprintf(stdout, SHELL_EXIT);
    sleep(10);
    return OK;
}
Ejemplo n.º 26
0
/*
OK w95
 */
void mainEventLoop() {

   short     sVal, sXCurrent, sYCurrent;
   long      lDevice;
	int		i=0;
	int 	state = FALSE;
    short attached = 1;
    short value;
    int dev;
    int pupval;

  // make_all();
	//init_menu();

   nCurrentDir = DIR_NONE;

   czclear(0x404040, getgdesc(GD_ZMAX));

   while (TRUE) {

      if (qtest()) {
         lDevice = qread(&sVal);

         switch (lDevice) {

			case INPUTCHANGE:
				#ifdef DOFF
					printf(" %d, %d, %d\n", Win_ids[0], Win_ids[1], sVal);
				#endif
				if ( sVal != 0 )
					Input_win = sVal;
				else
					Input_win = -1;
				break;

            case REDRAW:
				if ( sVal == Win_ids[1] && Win_ids[1] != -1 )
					vDrawHelpScene();
				else if ( sVal == Win_ids[0] )
				{
               		reshapeviewport();
               		getsize(&nWinWidth, &nWinHeight);
               		getorigin(&nXWinOrigin, &nYWinOrigin);
				}
               break;

            case RIGHTMOUSE:
               pupval = dopup(mainmenu);
               break;
  
			case SPACEKEY:
				state = TRUE;
				i++;
				if ( i == 4 )
					subEventLoop();
				break;

			case RKEY:
				if ( Last_Actions[FIRE] == TRUE )
					vEventLoop(&vDrawTitle);
				break;

         case QKEY:
				if ( Input_win == Win_ids[1] ) 
				{
					winclose(Input_win);
					Win_ids[1] != -1;
				}
				else if ( Input_win == Win_ids[0] )
				{
					winclose(Win_ids[0]);
					if ( Win_ids[1] != -1 )
						winclose(Win_ids[1]);
	               exit(0);
				}
               break;

            default:
               break;
         }
      }
		getdev(DR_NUM_BUT, Devs, Last_Actions);

	  	vDrawTitle(state);
   }
}
Ejemplo n.º 27
0
/**
 * @ingroup snoop
 *
 * Opens a capture from a network device.
 * @param cap pointer to capture structure
 * @param name of underlying device, ALL for all network devices
 * @return OK if open was successful, otherwise SYSERR
 * @pre-condition filter settings should already be setup in cap
 */
int snoopOpen(struct snoop *cap, char *devname)
{
    int i;
    int count = 0;
    int devnum;
    irqmask im;

    /* Error check pointers */
    if ((NULL == cap) || (NULL == devname))
    {
        return SYSERR;
    }

    SNOOP_TRACE("Opening capture on %s", devname);

    /* Reset statistics */
    cap->ncap = 0;
    cap->nmatch = 0;
    cap->novrn = 0;

    /* Allocated mailbox for queue packets */
    cap->queue = mailboxAlloc(SNOOP_QLEN);
    if (SYSERR == (int)cap->queue)
    {
        SNOOP_TRACE("Failed to allocate mailbox");
        return SYSERR;
    }

    /* Attach capture to all running network interfaces for devname "ALL" */
    if (0 == strcmp(devname, "ALL"))
    {
        im = disable();
#if NNETIF
        for (i = 0; i < NNETIF; i++)
        {
            if (NET_ALLOC == netiftab[i].state)
            {
                netiftab[i].capture = cap;
                count++;
                SNOOP_TRACE("Attached capture to interface %d", i);
            }
        }
#endif
        restore(im);
        if (0 == count)
        {
            SNOOP_TRACE("Capture not attached to any interface");
            mailboxFree(cap->queue);
            return SYSERR;
        }
        return OK;
    }

    /* Determine network interface to attach capture to */
    devnum = getdev(devname);
    if (SYSERR == devnum)
    {
        SNOOP_TRACE("Invalid device");
        mailboxFree(cap->queue);
        return SYSERR;
    }
    im = disable();
#if NNETIF
    for (i = 0; i < NNETIF; i++)
    {
        if ((NET_ALLOC == netiftab[i].state)
            && (netiftab[i].dev == devnum))
        {
            netiftab[i].capture = cap;
            restore(im);
            SNOOP_TRACE("Attached capture to interface %d", i);
            return OK;
        }
    }
#endif

    /* No network interface found */
    restore(im);
    SNOOP_TRACE("No network interface found");
    mailboxFree(cap->queue);
    return SYSERR;
}
Ejemplo n.º 28
0
void
main(int argc, char *argv[])
{
	char buf[32];
	Dev *d, *ed;
	Ep *e;
	int i;

	ARGBEGIN {
	case 'D':
		chatty9p++;
		break;
	case 'd':
		usbdebug++;
		break;
	} ARGEND;

	if(argc == 0)
		usage();

	if((d = getdev(*argv)) == nil)
		sysfatal("getdev: %r");
	audiodev = d;

	/* parse descriptors, mark valid altc */
	for(i = 0; i < nelem(d->usb->ddesc); i++)
		parsedescr(d->usb->ddesc[i]);
	for(i = 0; i < nelem(d->usb->ep); i++){
		e = d->usb->ep[i];
		if(e != nil && e->type == Eiso && e->iface != nil && e->iface->csp == CSP(Claudio, 2, 0)){
			switch(e->dir){
			case Ein:
				if(audioepin != nil)
					continue;
				audioepin = e;
				break;
			case Eout:
				if(audioepout != nil)
					continue;
				audioepout = e;
				break;
			case Eboth:
				if(audioepin != nil && audioepout != nil)
					continue;
				if(audioepin == nil)
					audioepin = e;
				if(audioepout == nil)
					audioepout = e;
				break;
			}
			if((ed = setupep(audiodev, e, audiofreq)) == nil){
				fprint(2, "setupep: %r\n");

				if(e == audioepin)
					audioepin = nil;
				if(e == audioepout)
					audioepout = nil;
				continue;
			}
			closedev(ed);
		}
	}
	if(audioepout == nil)
		sysfatal("no endpoints found");

	fs.tree = alloctree(user, "usb", DMDIR|0555, nil);
	createfile(fs.tree->root, "volume", user, 0666, nil);

	snprint(buf, sizeof buf, "%d.audio", audiodev->id);
	postsharesrv(&fs, nil, "usb", buf);

	exits(0);
}