Beispiel #1
0
int scan_main(SSL *ssl)
{
	int order;
	system("clear");
	order = Mlist();	
	switch(order)
	{
		case CSCL:	scan_local_files();break;	
		case CSCS:	scan_serv_files(ssl,order);break;
		case CSCLS: scan_all(ssl);break;	
		default: fprintf(stderr,"No such option!\n");
				 return -1;
	}
	return 0;
}
Beispiel #2
0
int MyCalculateDiversity(vector<vector<vector<int> > > AlleleList, vector<int> ActiveMaxAllelesList, std::string Standardize, double& RandomActiveDiversity, double& AltRandomActiveDiversity)
{
	/*AlleleList structure:
		  Pop1..r
			  locusarray1..n		*/
	int CoreSize = AlleleList.size();
	int NumLoci = AlleleList[0].size();
	int i, j, M;
	unsigned int k;
	vector<int> CurrLoc;
	vector<int> Mlist(NumLoci);
	set<int> AlleleSet;

	if (NumLoci == 0)
	{
		RandomActiveDiversity = -1; 
		AltRandomActiveDiversity = -1;
	}
	else
	{
		//use set to eliminate redundancies
		for (i=0;i<NumLoci;i++)
		{

			//3. pass alleles from the same locus into a single set, for all populations in core, to remove redundancies
			AlleleSet.clear(); //clear AlleleSet
			for (j=0;j<CoreSize;j++)
			{
				CurrLoc = AlleleList[j][i];
				for (k=0;k<CurrLoc.size();++k)
				{
					AlleleSet.insert(CurrLoc[k]); //locus i for all population j
				}
			}
			
			if (AlleleSet.size() == 0) M=0;
			else M=AlleleSet.size();
			
			Mlist[i] = M;
		}
		
		//5. standardize the M values to the maximum possible number of alleles at that locus, 
		//and add them up to get final estimate of standardized allelic diversity in the core.
		//Then divide by the number of loci to get a number that is comparable across data sets.
		
		//calculate the standardized allelic diversity
		double SAD;
		double SADtemp = 0; //SADtemp is the summed value of standardized M across all loci for a single subcore
		for (i=0;i<NumLoci;i++)
		{
			SADtemp = SADtemp + ( (double) Mlist[i] / (double) ActiveMaxAllelesList[i] );
		}
		SAD = SADtemp / NumLoci;
		
		//calculate M by simply adding up the Mlist
		M = 0;
		for (k=0;k<Mlist.size();++k)
		{
			M = M + Mlist[k];
		}
		
		//6. Determine the way variables are updated so that the value for the desired optimality 
		//criterion is RandomActiveDiversity, while the other is AltRandomActiveDiversity.  
		//This way, the output can contain information on both M+ and M criteria, 
		//although only one will be used for optimization.
		if (Standardize == "yes")
		{
			RandomActiveDiversity = SAD;
			AltRandomActiveDiversity = M;
		}
		else if (Standardize == "no")
		{
			RandomActiveDiversity = M;
			AltRandomActiveDiversity = SAD;
		}
	}
	return 0;
}
Beispiel #3
0
/* void Ucommand (void) -------------------------
 * 
 * OS/0 command processor.
 * 
 *   Before spawning/calling this process, set the 
 *   external variable CurrentTerm to the number
 *   of the terminal you want the command processor to
 *   run on.  Note that CurrentTerm is incremented by
 *   the command processor after it "uses" the value.
 *   This allows Ucommand to be spawned in a loop.
 *
 *   This command interpreter was designed to be both
 *   spawned and called.  It is suggested that terms
 *   1-3 be spawned, then term 1 be called directly.
 *   This way when the "bye" command is issued at a terminal
 *   greater than 0 the system will not shut down.
*/
void Ucommand (void)
{
  int TermNum = (CurrentTerm++) ;
  ARG Args ;
  char *Cmd ;
  char *user ;
  char *prompt ;
  char *buf ;
  int NumChars, CmdNum, i ;
  short bLoggedIn = FALSE ;

  Cmd = (char*) malloc (sizeof(char)*256) ;
  user = (char*) malloc (sizeof(char)*256) ;
  prompt = (char*) malloc (sizeof(char)*256) ;
  buf = (char*) malloc (sizeof(char)*256) ;

  tprint ("   Command processor %d active\n", TermNum) ;
  sprintf (buf, "\aOS/0 Mail - Copyright (c) 1990, Charles Kindel and Sandy Smith.\n") ;
  Writeterm (buf, strlen (buf), TermNum) ;
  sprintf (buf, "\tCommand processor %d active\n", TermNum) ;
  Writeterm (buf, strlen (buf), TermNum) ;
  sprintf (buf, "Available commands:\n") ;
  Writeterm (buf, strlen(buf), TermNum) ;
  for (i = 0 ; i < NCMDS ; i++)
    {
      sprintf (buf, "\t%s\n", cmdnames[i]) ;
      Writeterm (buf, strlen(buf), TermNum) ;
    }  
  
  strcpy (user, "OS/0") ;
  while (TRUE)
    {
      if (!bLoggedIn && TermNum)
	sprintf (prompt, "\x1b[1mType \"login <username>\" to get started:\x1b[0m ") ;
      else
	sprintf (prompt, "\x1b[1m[%s]\x1b[0m ", user) ;
      Writeterm (prompt, strlen(prompt), TermNum) ;
      NumChars = Readterm (Cmd, CMDSIZE, TermNum) ;

      CmdNum = CmdToNum (Cmd, &Args) ; 

      if (bEcho)
	{
	  /* echo cmd to terminal */
	  for (i = 0 ; i <= Args.num ; i++)
	    {
	      sprintf (buf, "%s ", Args.arg[i]) ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	    }
	  Writeterm ("\n", 1, TermNum) ;
	}

      switch (CmdNum)
	{
	case CECHO :
	  if (TermNum)
	    {
	      sprintf (buf, "\aYou must be logged in to use that command!\n") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	      break ;
	    }
	  if (Args.num)
	    {
	      if (!strcmp (Args.arg[1], "on"))
		bEcho = TRUE ;
	      else
		if (!strcmp (Args.arg[1], "off"))
		  bEcho = FALSE ;
		else
		  {
		    sprintf (buf, "The usage for the echo command is : \"echo [on|off]\"\n") ;
		    Writeterm (buf, strlen(buf), TermNum) ;
		    break ;
		  }
	    }
	  else
	    {
	      sprintf (buf, "\techo is %s\n", bEcho ? "on"  : "off") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	    }
	  break ;

	case CHELP :
	  sprintf (buf, "Available commands:\n") ;
	  Writeterm (buf, strlen(buf), TermNum) ;
	  for (i = 0 ; i < NCMDS ; i++)
	    {
	      sprintf (buf, "\t%s\n", cmdnames[i]) ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	    }
	  break ;

	case CLIST :
	  if (bLoggedIn || !TermNum)
	    Mlist (TermNum) ;
	  else
	    {
	      sprintf (buf, "\aYou must be logged in to use that command!\n") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	      break ;
	    }
	  break ;

	case CADDUSER:
	  Madduser (TermNum, &Args) ;
	  break ;

	case CLOGIN :
	  if (bLoggedIn)
	    {
	      Mlogout (TermNum, user, &Args) ;
	      strcpy (user, "OS/0") ;
	    }

	  if (Mlogin (TermNum, user, &Args))
	    bLoggedIn = TRUE ;
	  break ;

	case CLOGOUT :
	  if (!bLoggedIn)
	    {
	      sprintf (buf, "\aNo one is logged in!\n") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	      break ;
	    }

	  bLoggedIn = !Mlogout (TermNum, user, &Args) ;
	  strcpy (user, "OS/0") ;
	  break ;

	case CMAIL :
	  if (!bLoggedIn)
	    {
	      sprintf (buf, "\aYou must be logged in to use that command!\n") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	      break ;
	    }
	  MMail (TermNum, user, &Args) ;
	  break ;

	case CCMD :
	  if (!bLoggedIn && TermNum)
	    {
	      sprintf (buf, "\aYou must be logged in to use that command!\n") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	      break ;
	    }

	  if (Args.num != 1)
	    {
	      sprintf (buf, "\aThe usage for \"cmd\" is: cmd <time>\n") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	      break ;
	    }
	  sprintf (buf, "Executing a psuedo-command...\n") ;
          Writeterm (buf, strlen(buf), TermNum) ;
	  Delay (atoi(Args.arg[1]) / 10) ;
	  break ;

	case CDIR :
	  if (bLoggedIn || !TermNum)
	    Udir (TermNum) ;
	  else
	    {
	      sprintf (buf, "\aYou must be logged in to use that command!\n") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	    }
	  break ;

	case CTIME:
	  if (bLoggedIn || !TermNum)
	    {
	      sprintf (buf, "The current time is %d\n", Get_Time_of_Day()) ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	    }
	  else
	    {
	      sprintf (buf, "\aYou must be logged in to use that command!\n") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	    }
	  break ;

	case CDEL:
	  if (TermNum)       /* check to see if were on term 0 */
	    {
	      sprintf (buf, "\aFiles can be deleted from Terminal 0 only.\n") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	      break ;
	    }
	  for (i = 1 ; i <= Args.num ; i++)
	    {
 	      if (!(strcmp (Args.arg[i], ".")) || (-1 == Uremove (Args.arg[i])))
		{
		  sprintf (buf, "\t%s does not exist.\n", Args.arg[i]) ;
		  Writeterm (buf, strlen(buf), TermNum) ;
		}
	      sprintf (buf, "\t%s deleted.\n", Args.arg[i]) ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	    }
	  break ;

	case CFORMAT :
	  if (TermNum)       /* check to see if were on term 0 */
	    {
	      sprintf (buf, "\aThe disk can be formatted from Terminal 0 only.\n") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	      break ;
	    }
	  Uformat (INODESPACE) ;
	  break ;

	case CTYPE :
	  if (TermNum && !bLoggedIn)
	    {
	      sprintf (buf, "\aYou must be logged in to use this command!\n") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	      break ;
	    }
	  Ctype (TermNum, &Args) ;
	  break ;

	case CBYE :
	  if (TermNum)       /* check to see if were on term 0 */
	    {
	      sprintf (buf, "\aThe system can only be shut down from Terminal 0.\n") ;
	      Writeterm (buf, strlen(buf), TermNum) ;
	      break ;
	    }
	  sprintf (buf, "Shutting down the OS/0 file system!\n") ;
	  Writeterm (buf, strlen(buf), TermNum) ;
	  for (i = 1 ; i < 4 ; i++)
	    {
	      sprintf (buf, "\n\a\a\aNotice! The OS/0 file system is going down in 10 seconds!\n") ;
	      Writeterm (buf, strlen(buf), i) ;
	    }
	  Delay (10) ;

	  free (Cmd) ;
	  free (user) ;
	  free (prompt) ;
	  free (buf) ;
	  Terminate () ;
	  break ;

	  default :
	    if (strlen(Cmd))
	      {
		sprintf (buf, "\a\"%s\" is an invalid command!\n", Cmd) ;
		Writeterm (buf, strlen(buf), TermNum) ;
	      }
	    break ;
	}

    } 
} /* Ucommand */