예제 #1
0
int main(int argc, const char * argv[])
{
	ClientInit();
	ClientRun();
	RunClientExit();
	return 0;
}
예제 #2
0
파일: Spool.c 프로젝트: z-neil/308-310
/** entry point
 @param argc the number of arguments starting with the programme name
 @param argv the arguments
 @return     either EXIT_SUCCESS or EXIT_FAILURE */
int main(int argc, char **argv) {
	int i;
	int jobs = 3, clients = 4, printers = 2; /* defualt */
	int is_wtf = 0;
	char c;
	extern char *optarg;
	extern int optind;

	/* parse command line */
	while((c = getopt(argc, argv, "c:p:b:h")) != -1) {
		switch(c) {
			case 'c':
				clients = atoi(optarg);
				break;
			case 'p':
				printers = atoi(optarg);
				break;
			case 'b':
				jobs = atoi(optarg);
				break;
			case 'h':
				usage();
				return EXIT_SUCCESS;
			case '?':
				is_wtf = -1;
				break;
		}
	}
	if(is_wtf || optind != argc || jobs < 1 || clients < 1 || printers < 1) {
		usage();
		return EXIT_FAILURE;
	}

	/* seed the random */
	srand(clock());

	/* semaphores */
	if(!semaphores(jobs)) return EXIT_FAILURE;
	atexit(&semaphores_);

	/* print stuff with multiple threads */
	if(!(the_spool = Spool(jobs, printers, clients))) return EXIT_FAILURE;
	for(i = 0; i < printers; i++) PrinterRun(the_spool->printer[i]);
	/* fixme: the printers have to be started first, I think */
	for(i = 0; i < clients;  i++) ClientRun(the_spool->client[i]);
	Spool_(&the_spool);

	printf("Shutting down.\n");

	return EXIT_SUCCESS;
}