示例#1
0
文件: stat.c 项目: Theldus/nanvix
/*
 * Displays file status.
 */
int main(int argc, char *const argv[])
{
	struct stat st;
	
	readargs(argc, argv);
	
	/* Get file status. */
	if (stat(filename, &st) < 0)
	{
		printf("stat: cannot stat()\n");
		return (errno);
	}
	
	/* Print file status. */
	printf("    Name: %s\n", filename);
	printf("    Type: %s\n", filetype(st.st_mode));
	printf("    Size: %d bytes\n", (signed)st.st_size);
	printf("   Inode: %u\n", (unsigned)st.st_ino);
	printf("  Device: %xh\n", (unsigned)st.st_dev);
	printf("   Links: %d\n", (signed)st.st_nlink);
	printf("  Access: %s\n",  fileacc(st.st_mode));
	printf(" User ID: %d\n", st.st_uid);
	printf("Group ID: %d\n", st.st_gid);
	
	return (EXIT_SUCCESS);
}
示例#2
0
int main(int argc, char **argv)
{
	FILE *swp;
	struct cache *c;
	struct matrix *m;	
	FILE *matrix_shared;

	readargs(argc, argv);

	if ((swp = fopen(swapfile, "w+")) == NULL)
		error("cannot open swap file");

	c = cache_create(&access_info, swp, CACHE_SIZE);

	/* Read traces. */
	for (int i = 0; i < ntraces; i++)
	{
		FILE *trace;
		
		if ((trace = fopen(tracefiles[i], "r")) == NULL)
			error("cannot open trace file");
		
		trace_read(c, trace, i);
		fclose(trace);
		
		fprintf(stderr, "\nFechado arquivo de trace da thread %d\n\n", i);
		
	}
	
	/* Flushe traces on swap file. */
	cache_flush(c);
	
	/* Create communication matrix. */
	fseek(swp, 0, SEEK_SET); 
	m  = matrix_create(QTD_THREADS, QTD_THREADS);
	
	fprintf(stderr, "\nMatriz criada\n");
	
	matrix_generate(swp, m);
	
	
	if ((matrix_shared = fopen(outfile, "w")) == NULL)
		error("cannot open output file");
	
	fprintf(stderr, "\nGravar matriz no arquivo\n");
	
	for (int i = 0; i < ntraces; i++)
	{
		for(int j = 0; j < ntraces; j++)
			fprintf(matrix_shared, "%d;%d;%d\n", i, j, (int) matrix_get(m, i, j));	
	}

	/* House keeping. */
	fclose(matrix_shared);
	fclose(swp);
	
	fprintf(stderr, "\n\n FIM!\n");
		
	return (EXIT_SUCCESS);
}
示例#3
0
文件: main.c 项目: Denis2222/ft_ls
int	main(int ac, char **av)
{
	t_ls	*ls;

	ls = newls();
	setupls(ls, av, ac);
	if (ls->sort_alpha)
		sortargs(ls->args, ls->sort_alpha);
	readfiles(ls);
	readargs(ls->args, ls);
	return (0);
}
示例#4
0
文件: main.c 项目: jre/upart
int
main(int argc, char *argv[])
{
	struct disk_params params;
	struct opts newopts;
	char *name;
	struct disk *disk;
	int ret;

	if (up_savename(argv[0]) < 0 ||
	    up_getendian() < 0)
		return (EXIT_FAILURE);
	up_mbr_register();
	up_bsdlabel_register();
	up_apm_register();
	up_sunlabel_sparc_register();
	up_sunlabel_x86_register();
	up_gpt_register();
	up_softraid_register();

	name = readargs(argc, argv, &newopts, &params);
	if (name == NULL)
		return (EXIT_FAILURE);
	set_options(&newopts);

	disk = up_disk_open(name);
	if (!disk)
		return (EXIT_FAILURE);
	if (up_disk_setup(disk, &params) < 0 ||
	    up_map_loadall(disk) < 0) {
		up_disk_close(disk);
		return (EXIT_FAILURE);
	}

	ret = EXIT_SUCCESS;
	if (opts->serialize) {
		if (serialize(disk) < 0)
			ret = (EXIT_FAILURE);
	} else {
		up_disk_print(disk, stdout);
		up_map_printall(disk, stdout);
		if (UP_NOISY(SPAM))
			up_disk_dump(disk, stdout);
	}

	up_disk_close(disk);

	return (ret);
}
示例#5
0
/*
 * Runs benchmark.
 */
int main(int argc, char **argv)
{
	int i;              /* Loop index. */
	double *mask;       /* Mask.       */
	uint64_t end;       /* End time.   */
	uint64_t start;     /* Start time. */
	unsigned char *img; /* Image.      */
	
	readargs(argc, argv);
	
	timer_init();
	srandnum(seed);
	
	/* Benchmark initialization. */
	if (verbose)
		printf("initializing...\n");
	start = timer_get();
	img = smalloc(p->imgsize*p->imgsize*sizeof(char));
	for (i = 0; i < p->imgsize*p->imgsize; i++)
		img[i] = randnum() & 0xff;
	mask = smalloc(p->masksize*p->masksize*sizeof(double));
	generate_mask(mask);
	end = timer_get();
	if (verbose)
		printf("  time spent: %f\n", timer_diff(start, end)*MICROSEC);
		
	/* Apply filter. */
	if (verbose)
		printf("applying filter...\n");
	start = timer_get();
	gauss_filter(img, p->imgsize, mask, p->masksize);
	end = timer_get();
	
	total = timer_diff(start, end);

	/* Print timing statistics. */
	printf("timing statistics:\n");
	printf("  master:        %f\n", master*MICROSEC);
	for (i = 0; i < nclusters; i++)
		printf("  slave %d:      %f\n", i, slave[i]*MICROSEC);
	printf("  communication: %f\n", communication*MICROSEC);
	printf("  total time:    %f\n", total*MICROSEC);
	
	/* House keeping. */
	free(mask);
	free(img);
	
	return (0);
}
示例#6
0
/**
 * @brief Converts a NAS trace file to a Topaz input file.
 */
int main(int argc, char **argv)
{
	FILE *nasfilep;
	
	readargs(argc, argv);
	
	/* Open NAS trace file. */
	nasfilep = fopen(nasfile, "r");
	if (nasfilep == NULL)
		error("cannot open NAS trace file");
		
	nas2tpz(nasfilep);

	fclose(nasfilep);
	
	return (EXIT_SUCCESS);
}
示例#7
0
/*
 * Runs benchmark.
 */
int main(int argc, char **argv)
{
	int i;          /* Loop index.         */
	int *a;         /* Array to be sorted. */
	uint64_t end;   /* End time.           */
	uint64_t start; /* Start time.         */
	
	readargs(argc, argv);
	
	timer_init();
	srandnum(seed);
	
	/* Benchmark initialization. */
	if (verbose)
		printf("initializing...\n");
	start = timer_get();
	a = smalloc(p->n*sizeof(int));
	for (i = 0; i < p->n; i++)
		a[i] = randnum() & 0xfffff;
	end = timer_get();
	if (verbose)
		printf("  time spent: %f\n", timer_diff(start, end)*MICROSEC);
	
	/* Cluster data. */
	if (verbose)
		printf("sorting...\n");
	start = timer_get();
	bucketsort(a, p->n);
	end = timer_get();

	total = timer_diff(start, end);

	/* Print timing statistics. */
	printf("timing statistics:\n");
	printf("  master:        %f\n", master*MICROSEC);
	for (i = 0; i < nclusters; i++)
		printf("  slave %d:      %f\n", i, slave[i]*MICROSEC);
	printf("  communication: %f\n", communication*MICROSEC);
	printf("  total time:    %f\n", total*MICROSEC);
	
	/* House keeping. */
	free(a);
	
	return (0);
}
示例#8
0
/*
 * Runs benchmark.
 */
int main(int argc, char **argv)
{
	int i;          /* Loop index.      */
	int *map;       /* Map of clusters. */
	uint64_t end;   /* End time.        */
	uint64_t start; /* Start time.      */
	vector_t *data; /* Data points.     */
	
	readargs(argc, argv);
	printf("CAPBench - KM kernel\n");
	printf("  # of threads: %d \n", nthreads);
	
	timer_init();
	srandnum(seed);
	omp_set_num_threads(nthreads);
	
	/* Benchmark initialization. */
	start = timer_get();
	data = smalloc(p->npoints*sizeof(vector_t));
	for (i = 0; i < p->npoints; i++)
	{
		data[i] = vector_create(p->dimension);
		vector_random(data[i]);
	}
	end = timer_get();
	
	/* Cluster data. */
	printf("Entering in KM ROI - Clustering data...\n");
	start = timer_get();
	m5_reset_stats(0,0);
	map = kmeans(data, p->npoints, p->ncentroids, p->mindistance);
	end = timer_get();
	m5_dump_stats(0,0);
		
	printf("KM total time:    %f\n", timer_diff(start, end)*MICROSEC);
	
	/* House keeping. */
	free(map);
	for (i = 0; i < p->npoints; i++)
		vector_destroy(data[i]);
	free(data);
	
	return (0);
}
示例#9
0
int xmain(int argc, char *argv[])
{
    strcpy( progverstr, "ECOMPILE" );
    progver = 1;

#ifdef _WIN32
    MiniDumper::Initialize();
#endif

    read_config_file( argc,argv );

    int res = readargs(argc, argv);
    if (res)
        return res;

    if (!quiet)
    {
		// vX.YY
		double vernum = (double)progver + (double)(ESCRIPT_FILE_VER_CURRENT / 100.0f);
		cerr << "EScript Compiler v" << vernum << endl;
        cerr << "Copyright (C) 1993-2013 Eric N. Swanson" << endl;
        cerr << endl;
    }

    if (opt_generate_wordlist)
    {
        generate_wordlist();
        return 0;
    }
    
    bool didanything = run( argc, argv );
    
    if (!didanything)
    {
        usage();
        return 1;
    }
    else
    {
        return 0;
    }
}
示例#10
0
int
main(int argc, char *argv[])
{
  char infile[120], outfile[120], tmpname[120];
  int dirlen;
  char format[20], ext[3];
  static int isBooked = 0;
  int i = 0;
  begin();

  /*  srand(getpid()*2 - 1); */
  srand(time(NULL));

  for (i = readargs(argc, argv); i < argc; i++) {
    nBuffer = 0;
    dirlen = strlen(dir_name);
    sprintf(format, "%s%d%s", "%", dirlen,"s%s");
    printf("%s\n", format);
    
    printf("input = %s\n", argv[i]);
    sscanf(argv[i], format, dir_name, tmpname);
    printf("%s %s\n", dir_name, tmpname);

    sprintf(format, "%s%d%s", "%", strlen(tmpname)-4,"s%4s");
    sscanf(tmpname, format, infile, ext);
    printf("%s %s\n", infile, ext);

    sprintf(outfile, "%s%s", "./", infile);
    printf("Histogram file: %s\n", outfile);
    procfile(argv[i]); 
    if (!isBooked) {
      hsbook();
      isBooked = 1;
    }
    hsfill();
    write_hist(outfile);
    hist1d_resetall();
  }  
  end();
  return 0;
}
示例#11
0
int
main(int argc, char **argv)
{
    int errcount = 0;
    applyby = applybypointer;
    readargs(argc,argv);

    if( runstandardtests) {
        errcount += standard_tests();
    }
    {
        if(filetest1) {
            errcount += applyby(filetest1,filetest1name,
                g_hideactions,0,g_showallactions);
        }
        if(filetest2) {
            errcount += applyby(filetest2,filetest2name,
                g_hideactions,0,g_showallactions);
        }
        if(filetest3) {
            errcount += applyby(filetest3,filetest3name,
                g_hideactions,0,g_showallactions);
        }
        if(filetest4) {
            errcount += applyby(filetest4,filetest4name,
                g_hideactions,0,g_showallactions);
        }
    }
    free(filetest1);
    free(filetest2);
    free(filetest3);
    free(filetest4);

    if(errcount) {
        printf("FAIL tsearch test.\n");
        exit(1);
    }
    printf("PASS tsearch test.\n");
    exit(0);
}
示例#12
0
文件: ex17.c 项目: lingyq/tcpl2
/*	sort input lines  */
int main(int argc, char *argv[])
{
	char *lineptr[LINES];
	int nlines;
	int rc = 0;

	readargs(argc,argv);
	if((nlines = readlines(lineptr, LINES)) > 0)
	{
		if(option & NUMERIC)
		qsort((void **)lineptr, 0, nlines-1, 
			 (int (*)(void *, void *))numcmp);
		else
		qsort((void **)lineptr, 0, nlines-1, 
			 (int (*)(void *, void *))charcmp);
		writelines(lineptr, nlines, option & DECR);
	}
	else
	{
		printf("input too big to sort \n");
		rc = -1;
	}
	return rc;
}
示例#13
0
文件: mirror.c 项目: kreeze/mirror
int main(int argc, char *argv[]) {
  char proto, mode;
  unsigned int addr;
  unsigned short port;

  //read arguments (options)
  readargs(argc, argv, &proto, &mode, &addr, &port, "10001");

  if(mode == 's') {
    if(proto == 'u') {
      udp_server(port);
    } else {
      tcp_server(port);
    }
  } else {
    if(proto == 'u') {
      udp_client(addr, port, 0);
    } else {
      tcp_client(addr, port, 0);
    }
  }

  return 0;
}
示例#14
0
文件: main.c 项目: ftnapps/smapinntpd
int main(int argc, char **argv) 
{ 
   SOCKET sock;
   int error,res; 
   struct sockaddr_in local;
   fd_set fds;
   struct timeval tv;
   FILE *fp;
   struct _minf m;
   
   if(argc == 2 && (stricmp(argv[1],"?")==0 || stricmp(argv[1],"-h")==0 || stricmp(argv[1],"--help")==0))
   {

           /*          1         2         3         4         5         6         7         8 */
           /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */     
      printf("\n"
             "Usage: smapinntpd [<options>]\n"
             "\n"
             " General options:\n"
             "\n"
             " -p[ort] <port>         Port number for SmapiNNTPd (default: 5000)\n"
             " -m[ax] <maxconn>       Maximum number of simultaneous connections (default: 5)\n"
             " -g[roups] <groupsfile> Read this file instead of " CFG_GROUPSFILE "\n"
             " -a[llow] <allowfile>   Read this file instead of " CFG_ALLOWFILE "\n"
             " -u[sers] <usersfile>   Read this file instead of " CFG_USERSFILE "\n"
             " -x[lat] <xlatfile>     Read this file instead of " CFG_XLATFILE "\n"
             " -l[ogfile] <logfile>   Log to this file instead of " CFG_LOGFILE "\n"
             " -noecholog             Do not write log messages to console\n" 
             " -debug                 Write all network communication to console\n"
             "\n"
             " Options for displaying messages:\n"
             "\n"
             " -readorigin           Get addresses from the origin line instead of JAM header\n"
             " -noencode             Do not MIME encode headers with 8-bit characters\n"
             " -strictnetmail        Use strict article counters in netmail areas\n"
             " -def_flowed on/off    Default setting for format=flowed (RFC 2646)\n"
             " -def_showto on/off    Default setting for the display of recipient on from line\n"
             "\n"
             " Options for posting messages:\n"
             "\n"
             " -nostripre            Do not remove \"Re:\" from subject line\n"
             " -notearline           Do not put X-Newsreader/User-Agent string on tearline\n"
             " -noreplyaddr          Do not create REPLYADDR kludges\n"
             " -notzutc              Do not create TZUTC kludges\n"
             " -nocancel             Do not allow cancelling of messages\n"
             " -smartquote           Reformat quoted text to fidonet style\n"
             " -origin <origin>      Origin to use instead of contents of Organization line\n"
             " -guestsuffix <suffix> Suffix added to from name of unauthenticated users\n"
             " -echomailjam <file>   Create echomail.jam file for CrashMail and other tossers\n"
             "\n"
             " Options for configuration files:\n"
             "\n"
             " -config <file>        Read options from this file\n"
             " -create <file>        Create a configuration file with the default options\n"
             "\n"
             "If no options are specified on the commandline, SmapiNNTPd will attempt to read\n"
             "options from " CONFIGFILE " (if it exists).\n"
             "\n");
      
      return(FALSE);
   }

   if(argc == 1)
   {
      if((fp=fopen(CONFIGFILE,"r")))
      {
         fclose(fp);
     
         if(!readargs(CONFIGFILE))
         {
            freeargs();
            exit(0);
         }
      }
   }
   else
   {
      if(!parseargs(argc-1,&argv[1],NULL,0))
      { 
         freeargs();
         exit(0);
      }
   }

   if(!os_init())
   {
       freeargs();
       exit(10);
   }
	
   m.req_version = 0;
   m.def_zone = 0;

   if(MsgOpenApi(&m) != 0)
   {
      os_showerror("Failed to initialize SMAPI");
      freeargs();
      os_free();
      exit(10);
   }

   sock = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);

   if(sock == INVALID_SOCKET)
   {
      uchar err[200];

      os_showerror("Failed to create socket: %s",os_strerr(os_errno(),err,200));
      MsgCloseApi();
      os_free();
      freeargs();
      exit(10);
   }

   memset(&local, 0, sizeof(local) );

   local.sin_family = AF_INET;
   local.sin_addr.s_addr = INADDR_ANY;
   local.sin_port = htons(cfg_port);

   error = bind(sock,(struct sockaddr *)&local,sizeof(local));

   if(error == SOCKET_ERROR)
   {
      uchar err[200];

      os_showerror("Could not bind to port (server already running?): %s",os_strerr(os_errno(),err,200));
      close(sock);
      MsgCloseApi();
      os_free();
      freeargs();
      exit(10);
   }

   error = listen(sock,5);

   if(error == SOCKET_ERROR)
   {
      uchar err[200];

      os_showerror("Could not listen to socket: %s",os_strerr(os_errno(),err,200));
      close(sock);
      MsgCloseApi();
      os_free();
      freeargs();
      exit(10);
   }

   os_logwrite(SERVER_NAME " " SERVER_VERSION " is running on port %d",cfg_port);

   if(cfg_debug)
      os_logwrite("Compiled " __DATE__ " " __TIME__);

   while(!get_server_quit())
   {
      FD_ZERO(&fds);
      FD_SET(sock,&fds);
	
      tv.tv_sec=1;
      tv.tv_usec=0;
	
      res=select(sock+1,&fds,NULL,NULL,&tv);

      if(res != 0 && res != -1)
      {
          SOCKET active_sock; 
          struct sockaddr_in from; 
          int fromlen = sizeof(from);               

          active_sock = accept(sock,(struct sockaddr *)&from,&fromlen);

          if(active_sock == SOCKET_ERROR)
          {
              uchar err[200];
              os_showerror("Failed to accept incoming connection: %s",os_strerr(os_errno(),err,200));
              break;
          }

          os_startserver(server,active_sock);
      }
   }

   if(get_server_openconnections())
   {
      os_logwrite("Exiting. %ld connection(s) are active, waiting for them to quit",
			get_server_openconnections());

      while(get_server_openconnections())
         os_sleep(1);
   }

   close(sock);

   os_logwrite(SERVER_NAME " exited");
   MsgCloseApi();
   os_free();
   freeargs();
   exit(0);
}
示例#15
0
文件: main.c 项目: ftnapps/smapinntpd
bool parseargs(int argc, char **argv,uchar *filename,ulong line)
{   
   uchar *arg,src[100],tmp[200];
   uchar *token;
   int c;
   
   src[0]=0;

   if(filename)
      sprintf(src," (%.95s line %ld)",filename,line);
   
   for(c=0;c<argc;c++)
   {
      arg=argv[c];
      
      if(arg[0] == '-' && arg[1] == '-')
         arg=&arg[1]; /* --option should be equivalent to -option */
         
      if(filename && arg[0] && arg[0] != '-')
      {
         /* Add dash if missing */
         strcpy(tmp,"-");
         mystrncpy(&tmp[1],arg,199);
         arg=tmp;
      }
      
      if(stricmp(arg,"-debug")==0)
      {
         cfg_debug=TRUE;
      }
      else if(stricmp(arg,"-noecholog")==0)
      {
         cfg_noecholog=TRUE;
      }
      else if(stricmp(arg,"-nostripre")==0)
      {
         cfg_nostripre=TRUE;
      }
      else if(stricmp(arg,"-notearline")==0)
      {
         cfg_notearline=TRUE;
      }
      else if(stricmp(arg,"-nocancel")==0)
      {
         cfg_nocancel=TRUE;
      }
      else if(stricmp(arg,"-strictnetmail")==0)
      {
         cfg_strictnetmail=TRUE;
      }
      else if(stricmp(arg,"-readorigin")==0)
      {
         cfg_readorigin=TRUE;
      }
      else if(stricmp(arg,"-noreplyaddr")==0)
      {
         cfg_noreplyaddr=TRUE;
      }
      else if(stricmp(arg,"-smartquote")==0)
      {
         cfg_smartquote=TRUE;
      }
      else if(stricmp(arg,"-noencode")==0)
      {
         cfg_noencode=TRUE;
      }
      else if(stricmp(arg,"-notzutc")==0)
      {
         cfg_notzutc=TRUE;
      }
      else if(stricmp(arg,"-p")==0 || stricmp(arg,"-port")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         cfg_port=atoi(argv[++c]);
      }
      else if(stricmp(arg,"-m")==0 || stricmp(arg,"-max")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         cfg_maxconn=atoi(argv[++c]);
      }
      else if(stricmp(arg,"-def_flowed")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         if(!(setboolonoff(argv[c+1],&cfg_def_flowed)))
         {
            printf("Invalid setting %s for %s, must be on or off%s\n",argv[c+1],argv[c],src);
            return(FALSE);
         }

         c++;
      }
      else if(stricmp(arg,"-def_showto")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         if(!(setboolonoff(argv[c+1],&cfg_def_showto)))
         {
            printf("Invalid setting %s for %s, must be on or off%s\n",argv[c+1],argv[c],src);
            return(FALSE);
         }

         c++;
      }
      else if(stricmp(arg,"-origin")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }
         token = strtok(argv[c++],"|"); //jump over ORIGIN
         token = strtok(argv[c++],"|");
         while (token  != NULL) 
         {
            num_origins++;
            cfg_origin[num_origins] = malloc(strlen(token) +1);
            strcpy(cfg_origin[num_origins],trim(token));
            token = strtok(argv[c++],"|");
          }  
      }
      else if(stricmp(arg,"-exitflag")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         cfg_exitflag=argv[++c];
      }
      else if(stricmp(arg,"-guestsuffix")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         cfg_guestsuffix=argv[++c];
      }
      else if(stricmp(arg,"-echomailjam")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         cfg_echomailjam=argv[++c];
      }
      else if(stricmp(arg,"-g")==0 || stricmp(arg,"-groups")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         cfg_groupsfile=argv[++c];
      }
      else if(stricmp(arg,"-a")==0 || stricmp(arg,"-allow")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         cfg_allowfile=argv[++c];
      }
      else if(stricmp(arg,"-u")==0 || stricmp(arg,"-users")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         cfg_usersfile=argv[++c];
      }
      else if(stricmp(arg,"-x")==0 || stricmp(arg,"-xlat")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         cfg_xlatfile=argv[++c];
      }
      else if(stricmp(arg,"-l")==0 || stricmp(arg,"-logfile")==0)
      {
         if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         cfg_logfile=argv[++c];
      }
      else if(stricmp(arg,"-config")==0)
      {
         if(filename)
         {
            printf("%s may only be used on commandline%s\n",argv[c],src);
            return(FALSE);
         }
         else if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         if(!readargs(argv[++c]))
            return(FALSE);
      }
      else if(stricmp(arg,"-create")==0)
      {
         if(filename)
         {
            printf("%s may only be used on commandline%s\n",argv[c],src);
            return(FALSE);
         }
         
         else if(c+1 == argc)
         {
            printf("Missing argument for %s%s\n",argv[c],src);
            return(FALSE);
         }

         createconfig(argv[++c]);
         return(FALSE);
      }
      else
      {
         printf("Unknown switch %s%s\n",argv[c],src);
         return(FALSE);
      }
   }

   return(TRUE);
}
示例#16
0
int main(int argc, char **argv) {
  auto_handle * ses = NULL;
  char *config_file = NULL;
  char *logfile = NULL;
  char *pidfile = NULL;
  char *xmlfile = NULL;
  char erbuf[100];
  NODE *current = NULL;
  uint32_t count = 0;
  uint8_t first_run = 1;
  uint8_t once = 0;
  uint8_t verbose = AM_DEFAULT_VERBOSE;
  uint8_t append_log = 0;
  uint8_t match_only = 0;

  /* this sets the log level to the default before anything else is done.
  ** This way, if any outputting happens in readargs(), it'll be printed
  ** to stderr.
  */
  log_init(NULL, verbose, 0);

  readargs(argc, argv, &config_file, &logfile, &pidfile, &xmlfile, &nofork, &verbose, &once, &append_log, &match_only);

  /* reinitialize the logging with the values from the command line */
  log_init(logfile, verbose, append_log);

  dbg_printf(P_MSG, "Automatic version: %s", LONG_VERSION_STRING);

  if(!config_file) {
    config_file = am_strdup(AM_DEFAULT_CONFIGFILE);
  }

  strncpy(AutoConfigFile, config_file, strlen(config_file));

  ses = session_init();
  ses->match_only = match_only;

  if(parse_config_file(ses, AutoConfigFile) != 0) {
     if(errno == ENOENT) {
        snprintf(erbuf, sizeof(erbuf), "Cannot find file '%s'", config_file);
     } else {
        snprintf(erbuf, sizeof(erbuf), "Unknown error");
     }

     fprintf(stderr, "Error parsing config file: %s\n", erbuf);
     shutdown_daemon(ses);
  }

  if(!setupSession(ses)) {
     shutdown_daemon(ses);
  }

  setup_signals();

  if(!nofork) {
    /* start daemon */
    if(daemonize(pidfile) != 0) {
      dbg_printf(P_ERROR, "Error: Daemonize failed. Aborting...");
      shutdown_daemon(mySession);
    }
    dbg_printft( P_MSG, "Daemon started");
  }

  dbg_printf(P_INFO, "verbose level: %d", verbose);
  dbg_printf(P_INFO, "foreground mode: %s", nofork == true ? "yes" : "no");

  while(!closing) {
    isRunning = true;
    dbg_printft( P_INFO, "------ Checking for new episodes ------");
    if(xmlfile && *xmlfile) {
      processFile(mySession, xmlfile);
      once = 1;
    } else {
      current = mySession->feeds;
      count = 0;
      while(current && current->data) {
        ++count;
        processFeed(mySession, current->data, first_run);
        current = current->next;
      }
      if(first_run) {
        dbg_printf(P_INFO2, "New bucket size: %d", mySession->max_bucket_items);
      }
      first_run = 0;
    }

    /* leave loop when program is only supposed to run once */
    if(once) {
      break;
    }

    isRunning = false;

    if(seenHUP) {
      signal_handler(SIGHUP);
    }

    sleep(mySession->check_interval * 60);
  }

  shutdown_daemon(mySession);
  return 0;
}
示例#17
0
/*
 * Runs benchmark.
 */
int main(int argc, char **argv)
{
	int i;              /* Loop index.            */
	int *mask;       	/* Mask.                  */
	uint64_t end;       /* End time.              */
	uint64_t start;     /* Start time.            */
	char *img; 			/* Image.                 */
	int numcorners=0;	/* Total corners detected */
	
#ifdef _XEON_PHI_
	double power;
#endif	
	
	readargs(argc, argv);
	
	timer_init();
	srandnum(seed);
	omp_set_num_threads(nthreads);
	
	/* Benchmark initialization. */
	if (verbose)
		printf("initializing...\n");
	start = timer_get();
	img = smalloc(p->imgsize*p->imgsize*sizeof(char));
	for (i = 0; i < p->imgsize*p->imgsize; i++){
		char val = randnum() & 0xff;
		img[i] = (val>0) ? val : val*(-1);
	}	
	mask = smalloc(p->maskrows*p->maskcolumns*sizeof(int));
	generate_mask(mask);
	end = timer_get();
	if (verbose)
		printf("  time spent: %f\n", timer_diff(start, end)*MICROSEC);
	
#ifdef _XEON_PHI_
	power_init();
#endif		
		
	/* Detect corners. */
	if (verbose)
		printf("detecting corners...\n");
	start = timer_get();
	numcorners = fast(img, p->imgsize, mask);
	end = timer_get();
	
#ifdef _XEON_PHI_
	power = power_end();
#endif

	printf("timing statistics:\n");
	printf("  total time:       %f\n", timer_diff(start, end)*MICROSEC);

#ifdef _XEON_PHI_
	printf("  average power: %f\n", power*0.000001);
#endif

	printf("  corners detected: %d\n", numcorners);
	
	/* House keeping. */
	free(mask);
	free(img);
	
	return (0);
}
示例#18
0
/*
 * RT kernel.
 */
int main(int argc, char **argv)
{
    /* Number of spheres. */
#define NR_SPHERES 6

    int i;                        /* Loop index. */
    image_t img;                  /* Image.      */
    sphere_t spheres[NR_SPHERES]; /* Spheres.    */
    uint64_t end;                 /* End time.   */
    uint64_t start;               /* Start time. */

#ifdef _XEON_PHI_
    double power;
#endif

    readargs(argc, argv);

    timer_init();
    omp_set_num_threads(nthreads);

    /* Benchmark initialization. */
    if (verbose)
        printf("initializing...\n");
    start = timer_get();
    /* Ground sphere. */
    spheres[0] = sphere_create(
                     VECTOR(0, -10004, -20), /* Center         */
                     10000,                  /* Radius         */
                     VECTOR(0.2, 0.2, 0.2),  /* Surface Color  */
                     0,                      /* Reflection     */
                     0,                      /* Transparency   */
                     VECTOR(0, 0, 0));       /* Emission Color */

    /* Red sphere. */
    spheres[1] = sphere_create(
                     VECTOR(0, 0, -20),        /* Center         */
                     4,                        /* Radius         */
                     VECTOR(1.00, 0.32, 0.36), /* Surface Color  */
                     1,                        /* Reflection     */
                     0.5,                      /* Transparency   */
                     VECTOR(0, 0, 0));         /* Emission Color */

    /* Yellow sphere. */
    spheres[2] = sphere_create(
                     VECTOR(5, -1, -15),
                     2,
                     VECTOR(0.90, 0.76, 0.46),
                     1,
                     0.0,
                     VECTOR(0, 0, 0));

    /* Blue sphere. */
    spheres[3] = sphere_create(
                     VECTOR(5, 0, -25),
                     3,
                     VECTOR(0.65, 0.77, 0.97),
                     1,
                     0.0,
                     VECTOR(0, 0, 0));

    /* Gray sphere. */
    spheres[4] = sphere_create(
                     VECTOR(-5.5, 0, -15),
                     3,
                     VECTOR(0.90, 0.90, 0.90),
                     1,
                     0.0,
                     VECTOR(0, 0, 0));

    /* Light source. */
    spheres[5] = sphere_create(
                     VECTOR(0, 30, -30),
                     3,
                     VECTOR(0, 0, 0),
                     0,
                     0,
                     VECTOR(3, 3, 3));
    end = timer_get();
    if (verbose)
        printf("  time spent: %f\n", timer_diff(start, end)*MICROSEC);

#ifdef _XEON_PHI_
    power_init();
#endif

    /* Ray tracing. */
    if (verbose)
        printf("rendering scene...\n");
    start = timer_get();
    img = render(spheres, NR_SPHERES, p->height, p->width, p->depth);
    end = timer_get();

#ifdef _XEON_PHI_
    power = power_end();
#endif

    if (verbose)
        image_export("out.ppm", img, IMAGE_PPM);

    printf("timing statistics:\n");
    printf("  total time:    %f\n", timer_diff(start, end)*MICROSEC);

#ifdef _XEON_PHI_
    printf("  average power: %f\n", power*0.000001);
#endif

    /* Hous keeping. */
    for (i = 0; i < NR_SPHERES; i++)
        sphere_destroy(spheres[i]);
    image_destroy(img);

    return (EXIT_SUCCESS);
}
示例#19
0
int main(int argc, char **argv) {
  auto_handle *session = NULL;
  char *config_file = NULL;
  char *logfile = NULL;
  char *xmlfile = NULL;
  char erbuf[100];
  NODE *current = NULL;
  uint32_t count = 0;
  uint8_t first_run = 1;
  uint8_t once = 0;
  uint8_t verbose = AM_DEFAULT_VERBOSE;
  uint8_t append_log = 0;
  uint8_t match_only = 0;

  /* this sets the log level to the default before anything else is done.
  ** This way, if any outputting happens in readargs(), it'll be printed
  ** to stderr.
  */
  log_init(NULL, verbose, 0);

  readargs(argc, argv, &config_file, &logfile, &xmlfile, &nofork, &verbose, &once, &append_log, &match_only);

  /* reinitialize the logging with the values from the command line */
  log_init(logfile, verbose, append_log);

  if(!config_file) {
    config_file = am_strdup(AM_DEFAULT_CONFIGFILE);
  }
  strncpy(AutoConfigFile, config_file, strlen(config_file));

  session = session_init();
  session->match_only = match_only;

  if(parse_config_file(session, AutoConfigFile) != 0) {
    if(errno == ENOENT) {
      snprintf(erbuf, sizeof(erbuf), "Cannot find file '%s'", config_file);
    } else {
      snprintf(erbuf, sizeof(erbuf), "Unknown error");
    }
    fprintf(stderr, "Error parsing config file: %s\n", erbuf);
    shutdown_daemon(session);
  }

  setup_signals();

  if(!nofork) {

    /* start daemon */
    if(daemonize() != 0) {
      dbg_printf(P_ERROR, "Error: Daemonize failed. Aborting...");
      shutdown_daemon(session);
    }

    dbg_printft( P_MSG, "Daemon started");
  }

  filter_printList(session->filters);

  dbg_printf(P_MSG, "Trailermatic version: %s", LONG_VERSION_STRING);
  dbg_printf(P_INFO, "verbose level: %d", verbose);
  dbg_printf(P_INFO, "foreground mode: %s", nofork == 1 ? "yes" : "no");
  dbg_printf(P_INFO, "config file: %s", AutoConfigFile);
  dbg_printf(P_INFO, "check interval: %d min", session->check_interval);
  dbg_printf(P_INFO, "download folder: %s", session->download_folder);
  dbg_printf(P_INFO, "state file: %s", session->statefile);
  dbg_printf(P_MSG,  "%d feed URLs", listCount(session->feeds));
  dbg_printf(P_MSG,  "Read %d filters from config file", listCount(session->filters));

  if(session->prowl_key) {
    dbg_printf(P_INFO, "Prowl API key: %s", session->prowl_key);
  }

  if(listCount(session->feeds) == 0) {
    dbg_printf(P_ERROR, "No feed URL specified in trailermatic.conf!\n");
    shutdown_daemon(session);
  }

  if(listCount(session->filters) == 0) {
    dbg_printf(P_ERROR, "No filters specified in trailermatic.conf!\n");
    shutdown_daemon(session);
  }

  /* check if Prowl API key is given, and if it is valid */
  if(session->prowl_key && verifyProwlAPIKey(session->prowl_key) ) {
    session->prowl_key_valid = 1;
  }

  load_state(session->statefile, &session->downloads);
  while(!closing) {
    dbg_printft( P_INFO, "------ Checking for new trailers ------");
     if(xmlfile && *xmlfile) {
       processFile(session, xmlfile);
       once = 1;
    } else {
      current = session->feeds;
      count = 0;
      while(current && current->data) {
        ++count;
        dbg_printf(P_INFO2, "Checking feed %d ...", count);
        processFeed(session, current->data, first_run);
        current = current->next;
      }
      if(first_run) {
        dbg_printf(P_INFO2, "New bucket size: %d", session->max_bucket_items);
      }
      first_run = 0;
    }
    /* leave loop when program is only supposed to run once */
    if(once) {
      break;
    }
    sleep(session->check_interval * 60);
  }
  shutdown_daemon(session);
  return 0;
}