コード例 #1
0
ファイル: client.c プロジェクト: IvanMalison/grid
void add_job_std_in(char *host, int port) {
    int num_args, num_jobs, connection, i, flags[MAX_ARGUMENTS];
    job *jobs;
    char job_names[MAX_JOBS][MAX_ARGUMENT_LEN], files[MAX_ARGUMENTS][BUFFER_SIZE];
    char temp[BUFFER_SIZE];
    jobs = malloc(sizeof(job)*num_jobs);


    printf("How many jobs would you like to enqueue?\n");
    fgets(temp, BUFFER_SIZE, stdin);
    sscanf(temp, "%d", &num_jobs);



    for(i = 0; i < num_jobs; i++) {
        printfl("Give the name of job %d", i);
        fgets(temp, MAX_ARGUMENT_LEN, stdin);
        lowercase(temp);
        strcpy(job_names[i], temp);
    }


    for(i = 0; i < num_jobs; i++) {
        do {
            printfl("Enter the names of the jobs that %s depends on separated by commas(only immediate dependence)",
                    job_names[i]);
            fgets(temp, BUFFER_SIZE-1, stdin);
        }  while(parse_dependencies(temp, job_names, &jobs[i]));
    }

}
コード例 #2
0
ファイル: base64.c プロジェクト: klesun/Progmeistars_tasks
int main(){
	// Файл, который мы будем криптовать, а потом раскриптовывать
	printf("Введите, пожалуйста, название файла:\n");
	char s[255];
	scanf("%s", &(s[0]));
	// выводим содержимое файла
	printfl(s);
	decript(s, 8, 6, "result.dat");
	printfl("result.dat");
	print64("result.dat");
	decript("result.dat", 6, 8, "rezrez.txt");
	printfl("rezrez.txt");
	return 0;
}
コード例 #3
0
ファイル: functions.cpp プロジェクト: vehagn/LCDCD
void printTime(hd44780 &lcd){
	time_t now;
	struct tm timeinfo;
	char buf [64];
	
	time(&now);
	timeinfo = *localtime(&now);
	strftime(buf,64,"%a %d %b %H:%M:%S \nWeek %V Year %G",&timeinfo);
	
	lcd.clear();
	lcd.move(0,1);
	printfl("Timestamp:", lcd);
	lcd.move(0,2);
	printfl(buf, lcd);	
}
コード例 #4
0
ファイル: ex_1_22.c プロジェクト: zhujun1980/K-R-C-Exercise
void fold(char line[], int col) {
	int len, i, pos;
	
	if(col <= 0) {
		printf("%s", line);
		return;
	}

	for(len = 0; line[len] != '\n'; ++len);
	if(line[len] == '\n')
		++len;

	if(col >= len) {
		printf("%s", line);
		return;
	}

	pos = col;
	if(line[pos] == ' ' || line[pos] == '\t') {
		while(pos >= 0 && (line[pos] == ' ' || line[pos] == '\t'))
			--pos;
		if(pos >= 0) {
			printfl(line, 0, pos);
			printfl(line, pos+1, len);
		}
		else {
			printf("%s", line);
		}
	}
	else {
		while(pos >= 0 && (line[pos] != ' ' && line[pos] != '\t'))
			--pos;
		if(pos >= 0) {
			while(pos >= 0 && (line[pos] == ' ' || line[pos] == '\t'))
				--pos;
			if(pos >= 0) {
				printfl(line, 0, pos);
				printfl(line, pos+1, len);
			}
			else {
				printf("%s", line);
			}
		}
		else {
			printf("%s", line);
		}
	}
}
コード例 #5
0
ファイル: ga.c プロジェクト: Nazgolze/image-approximator
void _mutation(struct ia_circles **generation)
{
	if(ia_cfg.quit) {
		return;
	}
	int idx;
	printfi("mutation round\n");
	for(idx = 0; idx < GEN_SIZE; idx++) {
		printfl(IA_INFO, "mutating %d\n", idx);
		_mutate(generation[idx]);
		sort_circles(generation[idx]);
		refresh_circles(generation[idx]);
	}
	/*
	_mutate(ia_cfg.seed1);
	_mutate(ia_cfg.seed2);
	_mutate(ia_cfg.seed3);
	sort_circles(ia_cfg.seed1);
	sort_circles(ia_cfg.seed2);
	sort_circles(ia_cfg.seed3);
	refresh_circles(ia_cfg.seed1);
	refresh_circles(ia_cfg.seed2);
	refresh_circles(ia_cfg.seed3);
	*/
}
コード例 #6
0
ファイル: ga.c プロジェクト: Nazgolze/image-approximator
void init_ga(int num_circles)
{
	char *end_time_str;
	struct timespec tp1, tp2;
	int idx;
	if(_is_initialized)
		return;

	printfl(IA_INFO,
	    "initializing for genetic algorithm, this may take some time....");
	_is_initialized = true;
	circle_pool = calloc(GEN_SIZE, sizeof(struct ia_circles *));
	start_time(&tp1);

	for(idx = 0; idx < GEN_SIZE; idx++) {
		circle_pool[idx] = calloc(1, sizeof(struct ia_circles));
		init_circles(circle_pool[idx], num_circles);
	}

	for(idx = 0; idx < GEN_SIZE; idx++) {
		//for(jdx = 0; jdx < 2; jdx++) {
		//	_seed_mutate(&circle_pool[idx]);
		//}
		refresh_circles(circle_pool[idx]);
		sort_circles(circle_pool[idx]);
	}

	end_time_str = end_time(&tp1, &tp2, "time");
	printfi("%s\nsee, that didn't take too long, did it?\n", end_time_str);
	free(end_time_str);
}
コード例 #7
0
ファイル: client.c プロジェクト: IvanMalison/grid
int parse_dependencies(char *str, char job_names[MAX_JOBS][MAX_ARGUMENT_LEN], job *j) {
    char temp[BUFFER_SIZE];
    char *point;
    while(point = strchr(str, (int)',')) {
        strncpy(temp, str, str-point);
        printfl("%s", temp);
        str = point;
        str++;
    }
    return 0;
}
コード例 #8
0
ファイル: client.c プロジェクト: IvanMalison/grid
void simple_add(char *host, int port) {
    int num_files, i, num_times_to_add, job_num;
    char buffer[BUFFER_SIZE], filename[MAX_ARGUMENT_LEN];
    job ajob;
    data_size *data;

    //Get the name of our job
    printfl("Enter the name of your job");
    fgets(ajob.name, MAX_ARGUMENT_LEN, stdin);
    ajob.name[strlen(ajob.name)-1] = '\0';

    //Get the requisite files
    printf("How many files?\n");
    fgets(buffer, BUFFER_SIZE, stdin);
    sscanf(buffer, "%d", &num_files);
    data = malloc(sizeof(data_size)*num_files);
    for(i = 0; i < num_files; i++) {
        do {
            printf("Enter the name of file %d\n", i + 1);
            fgets(filename, MAX_ARGUMENT_LEN, stdin);
            filename[strlen(filename)-1] = '\0';
        } while(get_file_into_memory(filename, &data[i]));
    }

    //Enter the number of arguments
    printf("Enter the number of arguments: \n");
    fgets(buffer, BUFFER_SIZE, stdin);
    sscanf(buffer, "%d", &(ajob.argc));
    for(i = 0; i < ajob.argc; i++) {
        printf("Enter the name of argument %d\n", i);
        fgets(ajob.argv[i], MAX_ARGUMENT_LEN, stdin);
        ajob.argv[i][strlen(ajob.argv[i])-1] = '\0';
    }

    printf("How many times would you like to add the job?\n");
    scanf("%d", &num_times_to_add);
    for(i = 0; i < num_times_to_add; i++) {
        job_num = submit_job_to_server(host, port, &ajob, data, num_files);
        printf("Your job id is %d\n", job_num);
    }
}
コード例 #9
0
ファイル: conflicting_writes.c プロジェクト: IvanMalison/grid
int main(int argc, char **argv) {
  int connection, err;
  pthread_t thread;
  host_port host;
  struct timespec req;
  if(argc < 3) {
    host.port = atoi(argv[1]);
    pthread_create(&thread, NULL, (void *(*)(void *))listen_for_connection, &host);
    pthread_join(thread, NULL);
  } else {
    strcpy(host.ip, argv[1]);
    host.port = atoi(argv[2]);
    make_connection_with(host.ip, host.port, &connection);
    printfl("Made connection in main thread, file descriptor is %d", connection);
    err = LISTEN;
    safe_send(connection, &err, sizeof(int));
    pthread_create(&thread, NULL, (void *(*)(void *))conflicting_writes, &host);
    req.tv_sec = 2;
    pthread_join(thread, NULL);
  }
}
コード例 #10
0
ファイル: functions.cpp プロジェクト: vehagn/LCDCD
int printTimeLeft(hd44780 &lcd, time_t targetTime){
	time_t now;
    int timeLeft;
	char buf [64];
	
    // Calculate time remaining, set to 0 is time is passed.
	time(&now);
    timeLeft = (int)difftime(targetTime, now);
    timeLeft = (timeLeft>0)?(timeLeft):(0);
    
    // Create output
	sprintf(buf,"%5i%5i%5i%5i",timeLeft/86400, (timeLeft%86400)/3600, (timeLeft%3600)/60, timeLeft%60);
    
    // Print to LCD and terminal
	lcd.move(0,2);
	printfl(buf, lcd);
    
    // Print moving block to LCD
    lcd.write(19-(timeLeft+1)%20,3," ");
    lcd.move(19-timeLeft%20,3);
    lcd.write(hd44780::CCHAR0);
    
    return timeLeft;
}
コード例 #11
0
ファイル: DeltaPi.cpp プロジェクト: vehagn/DeltaPi
int main(int argc, char* argv[]){

	hd44780 lcd(14, 15, 24, 25, 8, 7);
   	lcd.init(20, 4);
	lcd.setAutoscroll(hd44780::HSCROLL_LINE | hd44780::VSCROLL);
	
	rpihw::gpio &io = rpihw::gpio::get();
	io.setup(23, rpihw::OUTPUT);
	io.write(23, rpihw::HIGH); bool *backlight = new bool(true);

	uint8_t blank[8]		= {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
	lcd.defChar(hd44780::CCHAR2, blank);
	
	getDatabaseDetails(&DBHOST, &USER, &PASSWORD, &DATABASE);
	retrieveSQL(entries, lcd);
	entries.erase(0);
	
	int card = 0;
	
	lcd.move(0,2);
	printfl("DeltaPi ver. 0.9.0",lcd);
	
	do{
		moveAndClearLine(0,0,lcd);
		lcd.write("Retrieving database");
		retrieveSQL(entries, lcd);
		scanCard(entries, card, lcd);
		if (!(*backlight))
			changeBacklight(io, backlight, lcd);
		if (card > 10){
			moveAndClearLine(0,1,lcd);
			lcd.write("Retrieving database");
			retrieveSQL(entries, lcd);
			printInfo(entries, card, lcd);
			transaction(entries, card, lcd);
		}
		else if (card == 0){
			printHelp(lcd);
		}else if (card == 1){
			lcd.write("Retrieving database");
			retrieveSQL(entries, lcd);
			printSummary(entries, lcd);
		} else if (card == 3){
			lcd.clear();
			lcd.move(0,1);
			printfl("Retrieving database", lcd);
			retrieveSQL(entries, lcd);	
		} else if (card == 4){
			printTime(lcd);
		} else if (card == 6){
			printLastCoffee(lcd);
		} else if (card == 9){
			changeBacklight(io, backlight, lcd);
		}
	}while (card != -1);
	lcd.clear();
	
	printfl("  Closing DeltaPi", lcd);
	lcd.move(6,2);
	lcd.write("Goodbye!    .",128);
	io.write(23, rpihw::LOW);
	
	delete backlight;
	return 0;
}