Ejemplo n.º 1
0
/********************************************//**
 *
 * This is the main method which will start the compiler.
 * 1) Check if the file name contains .ps, if not it will exit.
 * 2) Do the first Transition.
 * 3) Do the second transition.
 * 4) Check for errors, if errors exist it will print them and exit the program
 *    before writing the files.
 * 5) Generate the required files.
 *
 ***********************************************/
int main(int argc, char *argv[]) {
	Compiler *compiler = NULL;
	int curFileIdx = 1;

	if (argc == 1) {
		printf("No input files to compile!\n");
		exit(0);
	} else {
		while (--argc) {

			if (is_valid_filename(argv[curFileIdx]) == FALSE)
				exit(0);

			init_compiler(&compiler, BASE_OFFSET, argv[curFileIdx]);
			first_transition(compiler);
			second_transition(compiler);

			if (check_errors(compiler)) {
				//printf("errors\n");
				print_errors(compiler);
				exit(0);
			} else
				generate_files(compiler);

			free(compiler);
			curFileIdx++;
		}
	}

	printf("Compilation finished successfully.\n");
	return 0;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
  cerr << "SLICC v0.3" << endl;

  if (argc < 4) {
    cerr << "  Usage: generator.exec <code path> <html path> <ident> files ... " << endl;
    exit(1);
  }

  // The path we should place the generated code
  string code_path(argv[1]);
  code_path += "/";

  // The path we should place the generated html
  string html_path(argv[2]);
  html_path += "/";

  string ident(argv[3]);

  Vector<DeclListAST*> decl_list_vec;

  // Parse
  cerr << "Parsing..." << endl;
  for(int i=4; i<argc; i++) {
    cerr << "  " << argv[i] << endl;
    DeclListAST* decl_list_ptr = parse(argv[i]);
    decl_list_vec.insertAtBottom(decl_list_ptr);
  }

  // Find machines
  cerr << "Generator pass 1..." << endl;
  int size = decl_list_vec.size();
  for(int i=0; i<size; i++) {
    DeclListAST* decl_list_ptr = decl_list_vec[i];
    decl_list_ptr->findMachines();    
  }

  // Generate Code
  cerr << "Generator pass 2..." << endl;
  for(int i=0; i<size; i++) {
    DeclListAST* decl_list_ptr = decl_list_vec[i];
    decl_list_ptr->generate();    
    delete decl_list_ptr;
  }
  
  generate_files(code_path, html_path, ident);
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	define_config_defaults();
	int c, i;
	int set_rand_seed=0;
	if (argc==1)
	{
		help();
		return 0;
	}

	while (1)
                {
                int option_index=0;
                static struct option long_options[] =
                        {
                         { "user",1,NULL,'u' },
			 { "port",1,NULL,'P' },
			 { "host",1,NULL,'H' },
                         { "workgroup",1,NULL,'w' },
                         { "password",1,NULL,'p'},
                         { "help",0,NULL,'h' },
			 { "share1",1,NULL,'1'},
			 { "share2",1,NULL,'2'},
			 { "copy",1,NULL,'c'},
			 { "record",1,NULL,'r'},
			 { "size",1,NULL,'s'},
			 { "time",1,NULL,'t'},
			 { "number",1,NULL,'n'},
			 { "verbose",0,NULL,'v'},
			 { "replay",1,NULL,'e'},
                         { 0,0,0,0 }
                        };

                c=getopt_long(argc,argv,
                        "e:u:w:p:h1:2:c:r:s:t:n:vH:P:",
                        long_options,&option_index);
                if (c==-1) break;
                switch(c)
                	{
                	case 'u':
				if (config.user!=NULL) free(config.user);
                        	config.user=(char *) malloc(sizeof(char)*
					strlen(optarg));
				strcpy(config.user,optarg);
                        	break;
			case 'w':
				if (config.workgroup!=NULL) 
					free(config.workgroup);
				config.workgroup=(char *) malloc(sizeof(char)*
					strlen(optarg));
				strcpy(config.workgroup,optarg);
				break;
			case 'p':
				if (config.password!=NULL) 
					free(config.password);
				config.password=(char *) malloc(sizeof(char)*
					strlen(optarg));
				strcpy(config.password,optarg);
				break;
			case 'P':
				config.port=atoi(optarg);
				break;
			case 'H':
				config.host=(char *) malloc(sizeof(char)*
					strlen(optarg));
				strcpy(config.host,optarg);
				break;
			case 'h':
				help();
				return 0;
			case '1':
				if (config.share1!=NULL) free(config.share1);
				config.share1=(char*) malloc(sizeof(char)*
					strlen(optarg));
				strcpy(config.share1,optarg);
				break;
			case '2':
				if (config.share2!=NULL) free(config.share2);
				config.share2=(char*) malloc(sizeof(char)*
					strlen(optarg));
				strcpy(config.share2,optarg);
				break;
			case 'c':
				config.copy = (int) common_myatoi(optarg);
				break;
			case 'r':
				if (config.record!=NULL) free(config.record);
				config.record=(char*) malloc(sizeof(char)*
					strlen(optarg));
				strcpy(config.record,optarg);
				break;
			case 's':
				if(strstr(optarg, "M")!=NULL) 
				{
					config.size=(int) common_myatoi(optarg)*1024*1024;
				}
				else if(strstr(optarg, "G")!=NULL)
				{
					config.size=(int) common_myatoi(optarg)*1024*1024*1024;
				}
				else if(strstr(optarg, "K")!=NULL)
				{
					config.size=(int) common_myatoi(optarg)*1024;
				}
				else
				 	config.size=(int) common_myatoi(optarg);

				break;
			case 't':
				config.time = (int) common_myatoi(optarg);
				break;
			case 'n':
				config.number = (int) common_myatoi(optarg);
				break;
			case 'v':
				config.verbose = 1;
				break;
			case 'e':
				if (config.replay!=NULL) free(config.replay);
				config.replay=(char *) malloc(sizeof(char)*
					strlen(optarg));
				strcpy(config.replay,optarg);
				break;
			default :
				printf("Error: unkown option.\n\n");
				help();
				return 0;
		}
		}


	/* check the mode */
	if (config.replay!=NULL && config.record!=NULL) {
		printf("ERROR: please either record or playback!\n");
		return 0;
	}

	if (config.replay!=NULL && config.port!=0) {
		printf("FYI: 	Since we replay a torture run, we will not\n");
		printf("	connect to a smbtatorturesrv process.\n");
		config.port = 0;
	}

	if (config.record!=NULL && config.copy==0) {
		printf("ERROR: recording can't be infinite.\n");
		return 0;
	}

	/* open the file according to the mode */
	if (config.replay!=NULL) {
		config.player=fopen(config.replay,"r");
		if (config.player==NULL) {
			printf("ERROR: playback file cannot be opened.\n");
			return 0;
		}
	}
	if (config.record!=NULL) {
		config.recorder=fopen(config.record,"w");
		if (config.recorder==NULL) {
			printf("ERROR: recorder file cannot be"
				" opened for writing.\n");
		return 0;
		}
	}
	if (config.port != 0) {
		// connect to smbtatorturesrv
		if (config.host==NULL) {
			printf("ERROR: please specify a host to connect to.\n");
			return 0;
		}
		config.sockfd=
			connect_smbtatorturesrv(config.port, config.host);
	}
        /* init fnamelist */
        fnamelist = (char **) malloc(sizeof(char *) * (config.number + 1));
	generate_files();
	if (config.replay!=NULL) {
		/* when playing back, get the number of copies first */
		fscanf(config.player,"copy = %i\n",&config.copy);
		/* when playing back, get the number of files that have been
		   created. */
		fscanf(config.player,"number = %i\n",&config.number);
	}

	/* initialize rand */
	time_t rand_time;
	time(&rand_time);
	srandom( (unsigned int) rand_time);

	/* endless copying until we are stopped */
	if(config.copy==0)
	{
		for(;;)
		{
			copy();
			set_rand_seed++;
			//srand(time(NULL)+set_rand_seed);
	                if (set_rand_seed==100) {
        	                //srand(time(NULL));
                	        set_rand_seed=0;
                	}

		}
	}

	if (config.record!=NULL) {
		// when recording, save the number of copies as the first
		// parameter
		fprintf(config.recorder,"copy = %i\n",config.copy);

		// then the number of files that have been created
		fprintf(config.recorder,"number = %i\n",config.number);
	}
	static clock_t start_time;
	static clock_t end_time;
	static struct tms start_cpu;
	static struct tms end_cpu;
	unsigned long int clockticks = sysconf(_SC_CLK_TCK);
	start_time=times(&start_cpu);
	for(i=0;i<config.copy;i++)
	{
		copy();
		set_rand_seed++;
		//srand(time(NULL)+set_rand_seed);
		if (set_rand_seed==100) {
			//srand(time(NULL));
			set_rand_seed=0;
		}
	}
	end_time=times(&end_cpu);
	double timet = (double) (end_time - start_time) / (double) clockticks;	
	printf("Time required : %f seconds.\n", timet);
	// free allocated memory
	free(config.user);
	free(config.workgroup);
	free(config.password);
	free(config.share1);
	free(config.share2);
	if (config.host != NULL) free(config.host);

	if (config.record!=NULL) {
		free(config.record);
		fclose(config.recorder);
	}
	if (config.replay!=NULL) {
		free(config.replay);
		fclose(config.player);
	}
	if (config.port!=0) close(config.sockfd);		

	return 0;

}
Ejemplo n.º 4
0
Archivo: main.c Proyecto: OPSF/uClinux
static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
{
	int pid;
	int status = 0;
	int error_pipe[2];

	/* The receiving side mustn't obey this, or an existing symlink that
	 * points to an identical file won't be replaced by the referent. */
	copy_links = 0;

	if (preserve_hard_links)
		init_hard_links();

	if (fd_pair(error_pipe) < 0) {
		rsyserr(FERROR, errno, "pipe failed in do_recv");
		exit_cleanup(RERR_IPC);
	}

	io_flush(NORMAL_FLUSH);

	if ((pid = do_fork()) == -1) {
		rsyserr(FERROR, errno, "fork failed in do_recv");
		exit_cleanup(RERR_IPC);
	}

	if (pid == 0) {
		close(error_pipe[0]);
		if (f_in != f_out)
			close(f_out);

		/* we can't let two processes write to the socket at one time */
		close_multiplexing_out();

		/* set place to send errors */
		set_msg_fd_out(error_pipe[1]);

		recv_files(f_in, flist, local_name);
		io_flush(FULL_FLUSH);
		handle_stats(f_in);

		send_msg(MSG_DONE, "", 0);
		io_flush(FULL_FLUSH);

		/* Handle any keep-alive packets from the post-processing work
		 * that the generator does. */
		if (protocol_version >= 29) {
			kluge_around_eof = -1;

			/* This should only get stopped via a USR2 signal. */
			while (read_int(f_in) == flist->count
			    && read_shortint(f_in) == ITEM_IS_NEW) {}

			rprintf(FERROR, "Invalid packet at end of run [%s]\n",
				who_am_i());
			exit_cleanup(RERR_PROTOCOL);
		}

		/* Finally, we go to sleep until our parent kills us with a
		 * USR2 signal.  We sleep for a short time, as on some OSes
		 * a signal won't interrupt a sleep! */
		while (1)
			msleep(20);
	}

	am_generator = 1;
	close_multiplexing_in();
	if (write_batch && !am_server)
		stop_write_batch();

	close(error_pipe[1]);
	if (f_in != f_out)
		close(f_in);

	io_start_buffering_out();

	set_msg_fd_in(error_pipe[0]);

	generate_files(f_out, flist, local_name);

	handle_stats(-1);
	io_flush(FULL_FLUSH);
	if (protocol_version >= 24) {
		/* send a final goodbye message */
		write_int(f_out, -1);
	}
	io_flush(FULL_FLUSH);

	set_msg_fd_in(-1);
	kill(pid, SIGUSR2);
	wait_process(pid, &status);
	return status;
}