Esempio n. 1
0
char *test_read_input()
{
        FILE *f;

        /* open, read and parse some invalid xml */
        f = fopen("test.invalid.xml", "r");
        mu_assert("read invalid xml", read_input(f) == 0);
        fclose(f);
        mu_assert("parse invalid xml", xml_parse(buf) == XML_STATUS_INVALID);

        /* open, read and parse some valid xml */
        f = fopen("test.xml", "r");
        mu_assert("read valid xml", read_input(f) == 0);
        fclose(f);
        mu_assert("buffer contains request", strncmp(buf,"<request>", 9) == 0);
        mu_assert("parse some valid xml", xml_parse(buf) == XML_STATUS_OK);

        /* fetch value of an element */
        char *value = xml_element("//username");
        mu_assert("perform xpath search for element", value != NULL);
        mu_assert("get value of xml element", strcmp(value, "iamauser") == 0);
        xml_free(value);

        xml_cleanup();

        return 0;
}
Esempio n. 2
0
int main(int argc, char **path, char ** envp) {
	struct stat st = { 0 };
	char *home = getenv("HOME");
	char *conf_path = (char *) malloc(sizeof(char) * (strlen(home)));
	strcpy(conf_path, home);
	strcat(conf_path, "/.shell");
	if (stat(conf_path, &st) == -1) {
		mkdir(conf_path, 0700);
	}
	history_path = (char *) malloc(sizeof(char) * (strlen(conf_path) + 7));
	log_path = (char *) malloc(sizeof(char) * (strlen(conf_path) + 4));
	strcpy(history_path, conf_path);
	strcat(history_path, "/history");
	strcpy(log_path, conf_path);
	strcat(log_path, "/log");
	signal(SIGCHLD, handle_signal);
	fill_env_var(envp);
	fill_bin_paths();
	if (argc == 1) {
		read_input(INTERACTIVE, "");
	} else if (argc == 2) {
		read_input(BATCH, path[1]);
	} else {
		fprintf(stderr, "too much arguments\n");
	}
	free_args();
	free(line);
	printf("\n");
	return 0;
}
Esempio n. 3
0
static void event_play_profile(char* infile) {
  FILE* in, * datain;
  char filename[4096], buffer[4096];
  unsigned limit, data_read, amt;

  limit = 16*1024*1024;
  if (getenv("CHISTKA_PREREAD"))
    limit = atoi(getenv("CHISTKA_PREREAD"))*1024*1024;

  data_read = 0;

  if (in = fopen(infile, "r")) {
    while (data_read < limit && fgets(filename, sizeof(filename), in)) {
      read_input();
      if (!filename[0]) continue;
      /* Remove trailing newline */
      filename[strlen(filename)-1] = 0;
      dbgprintf(stderr, "daemon: replaying profile event: %s\n", filename);

      if (datain = fopen(filename, "r")) {
        do {
          read_input();
          amt = fread(buffer, 1, sizeof(buffer), datain);
          data_read += amt;
        } while (amt == sizeof(buffer) && data_read < limit);
        fclose(datain);
      }
    }
    fclose(in);
  }

  /* Done reading those files, now open the profile output. */
  profile_output = fopen(infile, "w");
}
Esempio n. 4
0
/**
* Tworzy żądanie, prosząc o odpowienie wpisy użytkownika.
* Zwraca -1 jeśli nastąpił błąd lub 0 - jeśli proces przebiegł pomyślnie.
*/
int make_request(int *auth){
  if(!*auth){  // autoryzuje do skutku
    char name[60], password[30];
    printf("Imię: ");
    read_input(61,name);
    strcpy(tmp.message, name);
    strcat(tmp.message,"_");
    printf("Nazwisko: ");
    read_input(60,name);
    strcat(tmp.message,name);
    printf("Hasło(jeśli puste wpisz \"\")[max. 30 zn]: ");
    read_input(30, password);
    if(strcmp(password,"\"\"") == 0)
      strcpy(password,"");
    strcat(tmp.message, ";");
    strcat(tmp.message, password);
	printf("%s\n",tmp.message);
    tmp.command_type = 1;
    return 0;
  }
  printf("Command: ");
  int cmd = -1;
  char tab[40];
  read_input(40,tab);
  cmd = parse_comand(tab);
  request_details(&cmd,auth);  // tworzymy żądanie
  if(cmd < 0 || cmd > 14){
    return -1;
  }
    tmp.command_type = cmd;
  return 0;
}
Esempio n. 5
0
int login_auth()
{
    char user_name[16]={0};
    char password[16]={0};
    int ret;

    printf_to_fd(fd_pty_slave, "login:"******"password:"******"admin")==0 &&
        strcmp(user_name, "admin")==0)
    {
        printf_to_fd(fd_pty_slave, "login success\n");
        return 0;
    }

          printf_to_fd(fd_pty_slave, "username or password wrong\n");
        return 1;
}
	int main(int argc, char* argv[]){
		printf("Welcome to Title Case! Please enter your exceptions within square brackets, each word in single quotes, then enter your desired sentence, again in square brackets and single quotes\n"); 
		struct value* exceptions = read_input(stdin);
		struct value* sentence = read_input(stdin);
		
		title_case(sentence, exceptions);
		return 0;
	}
bool DataFlashFileReader::update(char type[5])
{
    uint8_t hdr[3];
    if (read_input(hdr, 3) != 3) {
        return false;
    }
    if (hdr[0] != HEAD_BYTE1 || hdr[1] != HEAD_BYTE2) {
        printf("bad log header\n");
        return false;
    }

    if (hdr[2] == LOG_FORMAT_MSG) {
        struct log_Format f;
        memcpy(&f, hdr, 3);
        if (read_input(&f.type, sizeof(f)-3) != sizeof(f)-3) {
            return false;
        }
        memcpy(&formats[f.type], &f, sizeof(formats[f.type]));
        strncpy(type, "FMT", 3);
        type[3] = 0;

        message_count++;
        return handle_log_format_msg(f);
    }

    if (!done_format_msgs) {
        done_format_msgs = true;
        end_format_msgs();
    }

    const struct log_Format &f = formats[hdr[2]];
    if (f.length == 0) {
        // can't just throw these away as the format specifies the
        // number of bytes in the message
        ::printf("No format defined for type (%d)\n", hdr[2]);
        exit(1);
    }

    uint8_t msg[f.length];

    memcpy(msg, hdr, 3);
    if (read_input(&msg[3], f.length-3) != f.length-3) {
        return false;
    }

    strncpy(type, f.name, 4);
    type[4] = 0;

    message_count++;
    return handle_msg(f,msg);
}
Esempio n. 8
0
static u8 handle_lasikbd_event(unsigned long hpa)
{
        u8 status_keyb,status_mouse,scancode,id;
        extern void handle_at_scancode(int); /* in drivers/char/keyb_at.c */
        
        /* Mask to get the base address of the PS/2 controller */
        id = gsc_readb(hpa+LASI_ID) & 0x0f;
        
        if (id==1) 
		hpa -= LASI_PSAUX_OFFSET; 
	
        status_keyb = read_status(hpa);
        status_mouse = read_status(hpa+LASI_PSAUX_OFFSET);

        while ((status_keyb|status_mouse) & LASI_STAT_RBNE){
           
		while (status_keyb & LASI_STAT_RBNE) {
	      
		scancode = read_input(hpa);

	        /* XXX don't know if this is a valid fix, but filtering
	         * 0xfa avoids 'unknown scancode' errors on, eg, capslock
	         * on some keyboards.
	         */
	      	      
		if (scancode == AUX_REPLY_ACK) 
			cmd_status=0;
			
		else if (scancode == AUX_RESEND)
			cmd_status=1;
		else 
			handle_at_scancode(scancode); 
	      
		status_keyb =read_status(hpa);
		}
	   
#ifdef CONFIG_PSMOUSE
		while (status_mouse & LASI_STAT_RBNE) {
			scancode = read_input(hpa+LASI_PSAUX_OFFSET);
			handle_mouse_scancode(scancode);
			status_mouse = read_status(hpa+LASI_PSAUX_OFFSET);
		}
		status_mouse = read_status(hpa+LASI_PSAUX_OFFSET);
#endif /* CONFIG_PSMOUSE */
		status_keyb = read_status(hpa);
        }

        tasklet_schedule(&keyboard_tasklet);
        return (status_keyb|status_mouse);
}
Esempio n. 9
0
//read input
int line_input(char *line_str)
{

	if (get_buffer(line_str)) {
		return 1;

	} else if (check_input()) {

		read_input();

		if (get_buffer(line_str)) {
			return 1;

		} else if (read_end == LINE_INPUT_MAX_CHAR) {

			memcpy(line_str, buffer, LINE_INPUT_MAX_CHAR - 1);
			line_str[LINE_INPUT_MAX_CHAR - 1] = '\0';
			buffer[0] = buffer[LINE_INPUT_MAX_CHAR - 1];

			read_end = 1;
			return 1;

		} else {
			return 0;
		}

	} else {
		return 0;
	}
}
Esempio n. 10
0
File: 2.c Progetto: el-tillias/mdh
int main(void) {

    time_t t;
    int val, ans[7], sumof, ret;
    srand((int) time(&t));

    while (1) {    
        for (val=0; val<6; val++) {
            ans[val] = (rand() % 6 + 1);
            write(ans[val]);
        }

        count_pairs(ans); 
        sumof = count(ans);
        printf("Sum of all dices: %i\n", sumof);
        ret = read_input();
    
        if (ret == 1) {
            continue;
        }
        else {
            break;
        }
    }
    return 0;
}
Esempio n. 11
0
// INTERACT WITH USER AND SERVER IN ORDER TO CHOOSE ACTION
void interact(int socket) {
	printf("---MENU---\n1: SHELL\n2: SCREENSHOT\n3: UPDATE\n---FIN---\n");
	
	char *input;
	int choix = 0; 
	int i;
	// GET INPUT FROM USER AND TRANSFORM IT TO AN INT
	while(choix == 0) {
		input = read_input();
		for(i = 0; i < 4; i++)
			if(strchr(input, i + '0') != NULL)
				choix = i;
	}
	// TELL TO SERVER OUR CHOICE			
	write(socket, input, BUF_SIZE); 
	free(input); 
	
	switch(choix) {
		case 1 : 
			handle_shell(socket);
		break;
		case 2: 
			get_screenshot(socket);
		break;
		case 3:
			send_update(socket);
		break;
	}
	// WE'RE DONE, BYE
	close(socket);
}
Esempio n. 12
0
void part2(){
  int r[4] = {0, 0, 1, 0};
  Vector v = read_input();
  run(v, r);
  printf("%d\n", r['a' - 'a']);
  Vector_free(v);
}
Esempio n. 13
0
int main(int argc, char *argv[])
{
	const char *outfilename = "tinyL.out";
	char *input;
	FILE *infile;

	printf("------------------------------------------------\n");
	printf("CS314 compiler for tinyL\n      Spring 2014\n");
	printf("------------------------------------------------\n");
	if (argc != 2) {
		ERROR("Use of command:\n  compile <tinyL file>\n");
		exit(EXIT_FAILURE);
	}
	infile = fopen(argv[1], "r");
	if (!infile) {
		ERROR("Cannot open input file \"%s\"\n", argv[1]);
		exit(EXIT_FAILURE);
	}
	outfile = fopen(outfilename, "w");
	if (!outfile) {
		ERROR("Cannot open output file \"%s\"\n", outfilename);
		exit(EXIT_FAILURE);
	}
	input = read_input(infile);
	buffer = input;
	program();
	printf("\nCode written to file \"%s\".\n\n", outfilename);
	free(input);
	fclose(infile);
	fclose(outfile);
	return EXIT_SUCCESS;
}
Esempio n. 14
0
void read_username_password (char *pword, int flag)
{
	int i = 0;
	int ch;
	while ((ch = read_input()) != '\n') {

		if (IS_BACK_SPACE(ch))  {
			if(pword[0] == '\0')
				continue;
			if (i > 0) {
				i--;
				pword[i] = '\0';
				if (flag)
					write_string ("\b \b");
			}
		}
		else {
			pword[i++] = (char)ch;
			if (flag)
				write_input_on_screen (ch);

		}
	}

	pword[i] = '\0';

	return;
}
Esempio n. 15
0
int main(int argc, char * argv[])
{	
	char current_path[] = "0:/";
	
	printf(SHELL_BANNER",%s,v%d。\n", __DATE__, SHELL_VERSION);
	printf("输入help获取帮助.\n");
	
	/* Loop to get char */
	while(1)
	{
		int ch;

		/* 获取当前路径 */

		/* 打印提示符 */
		printf("[%s]#", current_path);
		ch = read_input(line_buffer, MAX_LINE_SIZE);
		printf("\n");
 
		/* 回车键则执行命令 */
		if (ch == SHELL_KEY_ENTER)
		{
			execute_cmd(line_buffer);	
		}		
	}

	return 0;
}
Esempio n. 16
0
static void irc_input_cb_ssl(gpointer data, PurpleSslConnection *gsc,
		PurpleInputCondition cond)
{

	PurpleConnection *gc = data;
	struct irc_conn *irc = gc->proto_data;
	int len;

	if(!g_list_find(purple_connections_get_all(), gc)) {
		purple_ssl_close(gsc);
		return;
	}

	if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) {
		irc->inbuflen += IRC_INITIAL_BUFSIZE;
		irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen);
	}

	len = purple_ssl_read(gsc, irc->inbuf + irc->inbufused, IRC_INITIAL_BUFSIZE - 1);

	if (len < 0 && errno == EAGAIN) {
		/* Try again later */
		return;
	} else if (len < 0) {
		purple_connection_error(gc, _("Read error"));
		return;
	} else if (len == 0) {
		purple_connection_error(gc, _("Server has disconnected"));
		return;
	}

	read_input(irc, len);
}
Esempio n. 17
0
static int decipher(struct sc_pkcs15_object *obj)
{
	u8 buf[1024], out[1024];
	int r, c, len;

	if (opt_input == NULL) {
		fprintf(stderr, "No input file specified.\n");
		return 2;
	}
	c = read_input(buf, sizeof(buf));
	if (c < 0)
		return 2;

	len = sizeof(out);
	if (!((struct sc_pkcs15_prkey_info *) obj->data)->native) {
                fprintf(stderr, "Deprecated non-native key detected! Upgrade your smart cards.\n");
		return SC_ERROR_NOT_SUPPORTED;
	}

	r = sc_pkcs15_decipher(p15card, obj, opt_crypt_flags & SC_ALGORITHM_RSA_PAD_PKCS1, buf, c, out, len);
	if (r < 0) {
		fprintf(stderr, "Decrypt failed: %s\n", sc_strerror(r));
		return 1;
	}
	r = write_output(out, r);

	return 0;
}
Esempio n. 18
0
static void run(tool_options_t &opts)
{
	netlist_tool_t nt;
	osd_ticks_t t = osd_ticks();

	nt.m_opts = &opts;
	nt.init();
	nt.read_netlist(filetobuf(opts.opt_file()), opts.opt_name());

	plist_t<input_t> *inps = read_input(&nt, opts.opt_inp());

	double ttr = opts.opt_ttr();

	printf("startup time ==> %5.3f\n", (double) (osd_ticks() - t) / (double) osd_ticks_per_second() );
	printf("runnning ...\n");
	t = osd_ticks();

	unsigned pos = 0;
	netlist::netlist_time nlt = netlist::netlist_time::zero;

	while (pos < inps->size() && (*inps)[pos].m_time < netlist::netlist_time::from_double(ttr))
	{
		nt.process_queue((*inps)[pos].m_time - nlt);
		(*inps)[pos].setparam();
		nlt = (*inps)[pos].m_time;
		pos++;
	}
	nt.process_queue(netlist::netlist_time::from_double(ttr) - nlt);
	nt.stop();
	pfree(inps);

	double emutime = (double) (osd_ticks() - t) / (double) osd_ticks_per_second();
	printf("%f seconds emulation took %f real time ==> %5.2f%%\n", ttr, emutime, ttr/emutime*100.0);
}
Esempio n. 19
0
int main(int argc, char *argv[])
{
    FILE *input = NULL;
    FILE *output = NULL;
    Edges edges = {0, NULL} ;
    double *shapley = NULL;
    long kernel_time = 0;
    long summary_time = 0;
    int n;
    Adjacency *adjacency;

    input = safeFopen(argv[1], "r");
    output = safeFopen(argv[2], "w");

    read_input(input, &edges);

    n = number_of_vertices(&edges);
    shapley = (double *) safeMalloc(n * sizeof(double));

    adjacency = createAdjacency(n, &edges, n);
    compute_shapley(adjacency, n, shapley, function, &kernel_time, &summary_time);
    
    write_output(n, shapley, output);

    print_time("kernel", kernel_time);
    print_time("summary", summary_time);

    releaseAdjacency(adjacency);
    free(shapley);
    free(edges.list);
    fclose(input);
    fclose(output);

    return 0;
}
Esempio n. 20
0
int main(int argc, char ** argv) {
	//create_dummy_vol_file(); exit(0);
	holger_time_start(0, "Main");	
	holger_time(0, "OpenCL initialization");
	read_input(
		"C:\\Master Holger\\Franks thumb drive\\UL\\Nevro_Spine\\SpineData\\ultrasoundSample5.mhd",
		"C:\\Master Holger\\Franks thumb drive\\UL\\Nevro_Spine\\SpineData\\ultrasoundSample5.pos",
		"C:\\Master Holger\\Franks thumb drive\\UL\\Nevro_Spine\\SpineData\\ultrasoundSample5.tim",
		"C:\\Master Holger\\Franks thumb drive\\UL\\Nevro_Spine\\SpineData\\ultrasoundSample5.msk",
		//"C:\\Master Holger\\Simple test input\\Lines\\lines.vol",
		"C:\\Master Holger\\Franks thumb drive\\UL\\Nevro_Spine\\SpineData\\ultrasoundSample5.vol",
		"C:\\Master Holger\\Franks thumb drive\\UL\\Nevro_Spine\\calibration_files\\M12L.cal"
	);
	holger_time(0, "Read input files");
	#pragma omp parallel num_threads(2)
	{
		int thread_idx = omp_get_thread_num();
		if (thread_idx == 0) {
			printf("Reconstruct thread\n");
			reconstruct();
		} else if (thread_idx == 1) {
			printf("GUI thread\n");
			gui(argc, argv);
		}
	}

	gui(argc, argv);
	holger_time(0, "Reconstruction");
	holger_time_print(0);
	exit(0);
}
Esempio n. 21
0
int main(int argc, char *argv[])
{
 	PetscErrorCode ierr;
	params params;

	Mat H; 

	SlepcInitialize(&argc,&argv,(char*)0,help);

	ierr = PetscPrintf(PETSC_COMM_WORLD,"--------------------------------------------------------------------------------------\n");CHKERRQ(ierr);
	ierr = PetscPrintf(PETSC_COMM_WORLD,"               _______ __  __  _______          _______ ______ _______                \n");CHKERRQ(ierr);
        ierr = PetscPrintf(PETSC_COMM_WORLD,"              |__   __|  \\/  |/ ____\\ \\        / /_   _|  ____|__   __|               \n");CHKERRQ(ierr);
        ierr = PetscPrintf(PETSC_COMM_WORLD,"                 | |  | \\  / | (___  \\ \\  /\\  / /  | | | |__     | |                  \n");CHKERRQ(ierr);
        ierr = PetscPrintf(PETSC_COMM_WORLD,"                 | |  | |\\/| |\\___ \\  \\ \\/  \\/ /   | | |  __|    | |                  \n");CHKERRQ(ierr);
        ierr = PetscPrintf(PETSC_COMM_WORLD,"                 | |  | |  | |____) |  \\  /\\  /   _| |_| |       | |                  \n");CHKERRQ(ierr);
        ierr = PetscPrintf(PETSC_COMM_WORLD,"                 |_|  |_|  |_|_____/    \\/  \\/   |_____|_|       |_|                  \n");CHKERRQ(ierr);
        ierr = PetscPrintf(PETSC_COMM_WORLD,"               True Muonium Solver with Iterative Front-Form Techniques               \n");CHKERRQ(ierr);
        ierr = PetscPrintf(PETSC_COMM_WORLD,"                                                                                      \n");CHKERRQ(ierr);
        ierr = PetscPrintf(PETSC_COMM_WORLD,"--------------------------------------------------------------------------------------\n");CHKERRQ(ierr);


	read_input(ierr,argv,&params);
	print_input(ierr,&params);
	
	if(check_file(params.hfile))
	{
		PetscViewer    viewer_H;
		PetscViewerBinaryOpen(PETSC_COMM_WORLD,params.hfile.c_str(),FILE_MODE_READ,&viewer_H);
		MatCreate(PETSC_COMM_WORLD,&H);
		MatSetFromOptions(H);
		MatLoad(H,viewer_H);
		PetscViewerDestroy(&viewer_H);		

	}else
	{
        	discretize(ierr,&params);
//  	    	ierr = VecView(params.mu,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
//        	ierr = VecView(params.theta,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);

		write_output(ierr,&params);	

        	coulomb_trick(ierr,&params);	
//		ierr = VecView(params.CT,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);

		ct_discrete(ierr,&params);
//		ierr = VecView(params.CT,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);

		hamiltonian(ierr,&params,H);
// 		ierr = PetscViewerSetFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_DENSE);//DENSE<-->COMMON
//	      	MatView(H,PETSC_VIEWER_STDOUT_WORLD);
	}

	cleanup(ierr,&params);	
	eigensolver(ierr,&params,H,argc,argv);

	ierr = MatDestroy(&H);CHKERRQ(ierr);

	ierr = SlepcFinalize();
	return 0;
}
Esempio n. 22
0
int main(int argc, char *argv[])
{
	const char *outfilename = "tinyL.out";
	char *input;
	FILE *infile;

	printf("------------------------------------------------\n");
	printf("      Compiler for tinyL\n          Fall 2015\n");
	printf("------------------------------------------------\n");
	if (argc != 2) {
		ERROR("Use of command:\n  compile <tinyL file>\n");
		exit(EXIT_FAILURE);
	}
	infile = fopen(argv[1], "r");
	if (!infile) {
		ERROR("Cannot open input file \"%s\"\n", argv[1]);
		exit(EXIT_FAILURE);
	}
	outfile = fopen(outfilename, "w");
	if (!outfile) {
		ERROR("Cannot open output file \"%s\"\n", outfilename);
		exit(EXIT_FAILURE);
	}
	input = read_input(infile);
	buffer = input;

	CodeGen(LOADI, 1024, 0, EMPTY_FIELD); /* set base register to 1024 */
	program();
	printf("\nCode written to file \"%s\".\n\n", outfilename);
	free(input);
	fclose(infile);
	fclose(outfile);
	return EXIT_SUCCESS;
}
Esempio n. 23
0
int main(int argc, char *argv[])
{
    // Get the amount of change from user
    float amount;
    
    int cents_amount;
    int coins_total = 0;
        
    amount = read_input("O hai! How much change is owed?");
    
    // Convert the amount of money to integer value of total cents
    cents_amount = round(amount * 100);
    
    // Now check how much quarters, dimes and nickels are needed
    coins_total = coins_total + get_quotient(&cents_amount, 25);
    coins_total = coins_total + get_quotient(&cents_amount, 10);
    coins_total = coins_total + get_quotient(&cents_amount, 5);
    
    coins_total = coins_total + cents_amount;   // Only pennies are left
    
    // Now print the result
    printf("%d\n", coins_total);
    
    return 0;
}
Esempio n. 24
0
//begin public methods
unsigned int Random::calibrate(){
  unsigned int* bins = (unsigned int*)malloc(BINS_SIZE * sizeof(unsigned int));
  
  //set all value counts to zero  
  for(int i = 0; i < BINS_SIZE; i++)
  {
    bins[i] = 0;
  }
  
  //loop until i equals the calibration sample size 
  for(unsigned int i = 0; i < CALIBRATION_SIZE; i++)
  {
    //get a sample
    byte adc_byte = read_input();
    //add one count to the bin of the sample value
    bins[adc_byte]++;
  }
  
  //find the threshold
  _threshold = find_threshold(bins);
  
  free(bins);
  
  return _threshold;
}
Esempio n. 25
0
void	run(t_params const* params)
{
  int	fd;
  pid_t	master;
  pid_t	ptyfk;
  struct termios	term;

  fd = open(params->file, O_WRONLY | O_CREAT |
      (params->append == 1 ? O_APPEND : O_TRUNC), 0644);
  if (fd == -1)
      xperror();
  ptyfk = my_forkpty(&master, NULL);
  if (ptyfk == -1)
    xperror();
  if (ptyfk == 0)
  {
    dup2_fd(master);
    execl(params->shell, params->shell, NULL);
    exit(0);
  }
  update_win_size(master);
  signal(SIGWINCH, handle_resize);
  remove_block(master, 0);
  init_term(&term);
  printf("Script started, file is %s\n", params->file);
  read_input(ptyfk, master, fd);
  restore_term(&term);
  close(fd);
  printf("Script done, file is %s\n", params->file);
}
Esempio n. 26
0
int main(void) {

  // Read input file and get number of particles
  read_input();
  read_nparts();

  // Read list of files in ./output/part-*.*.cgns
  read_time();
  // strrep part- and .cgns, save remainder to tName array
  
  // pare down tName array to ts < tName < te
  // pare down tName array to multiples of dt, or thereabouts

  // read first file, find nparts
  // construct part_struct[nparts].vec[length(tName)]

  // read part-*.** to part_struct array

  // loop over all r0 TODO: list r0, tol in input file
  //   loop over all particles and find tetrad apirs
  //    create *T struct with first tetrad pair
  //    double n[0], n[1], n[2], n[3]
  //    *prev = NULL
  //    *next = 
  //    create a *T, loop over *prev, check if unique or not
  //    if unique, change *T.next = *currT
  //    *T = *currT
  //    fill out V, R^2, etc. to *T
  // continue loops


  return EXIT_SUCCESS;
}
Esempio n. 27
0
parsed_line* input_process(input_state* input) {
	parsed_line* line;

	/* set term into unbuffered mode */
	reset_term(input, false);

	/* terminal i/o */
	if (!read_input(input, input->history_current->buffer)) {
		return NULL;
	}
	/* back to buffered */
	reset_term(input, true);
	putc('\n', stdout);

	if (strlen(input->history_current->buffer) == 0) {
		print_prompt();
		return NULL;
	}

	/* parse line */
	line = parse_input(input->history_current);

	history_add(input);
	input->cursor = 0;

	return line;
}
Esempio n. 28
0
int main() {

  char* token;
  int num_paths = 0;
  int first = 1;
  char* input;

  input = read_input();

  int paths_size = getPathsCount(input);

  paths   = malloc(sizeof(char *) * paths_size);
  weights = malloc(sizeof(char *) * paths_size);

  token = strtok(input, TOK_DELIM);
  while (token != NULL) {
    if(first) {             // getting first token from line, always weight
      weights[num_paths] = token;
      first = 0;
    } else {
      paths[num_paths] = token;
      first = 1;
      num_paths++;
    }

    token = strtok(NULL, TOK_DELIM);
  }

  orderPaths(num_paths);

  int i;
  for (i = 0; paths[i] != NULL; i++) {
    printf("%s, %s\n", weights[pathsOrdered[i]], paths[pathsOrdered[i]]);
  }
}
__u16 capture_key( struct INPUT* input, int *x, int *y, int num_key, __u16 *keys )
{
	struct input_event *event;

	int got_x = 0;
	int got_y = 0;
	int got_key = 0;
	__u16 key;
	int key_index;

	do {
		event = read_input( input );

		// DEBUG printf(
		// DEBUG 	"Event: time %ld.%06ld, type %d, code %d, value %d\n",
		// DEBUG 	event->time.tv_sec,
		// DEBUG 	event->time.tv_usec,
		// DEBUG 	event->type,
		// DEBUG 	event->code,
		// DEBUG 	event->value
		// DEBUG );

		if( event->type == EV_ABS ) {

			// remember position
			switch( event->code ) {

				case ABS_X:
				case ABS_Z:	/* Some tablets send ABS_Z instead of ABS_X */
					got_x = 1;
					*x = event->value;
				break;

				case ABS_Y:
				case ABS_RX:	/* Some tablets send ABS_RX instead of ABS_Y */
					got_y = 1;
					*y = event->value;
				break;
			}
		}

		if(
			event->type == EV_KEY && ( !event->value ) &&
			got_x && got_y
		) {	// some key released at some position

			key = event->code;

			for( key_index = 0; key_index < num_key; key_index++ ) {
				if( key == keys[key_index] ) {
					got_key = 1;
					break;
				}
			}
		}

	} while( !got_key );

	return key; /* key code */
}
Esempio n. 30
0
int main(int argc, char *argv[])
{
  if (argc != 4)
    invocation_error(argv[0], "[input file 1] [input file 2] [output file]"); 

  char *output_filename = argv[3];
  struct stat file1_stat, file2_stat;
  FileInfo larger, smaller;
  off_t record_size = (off_t)get_part_record_size();

  validate_input_file(argv[1], &file1_stat, record_size);
  validate_input_file(argv[2], &file2_stat, record_size);

  sort_input_files(argv[1], &file1_stat, argv[2], &file2_stat, &larger, &smaller, record_size);

  Part out_buffer = (Part)malloc(larger.size + smaller.size);
  if (!out_buffer)
    memory_error(__FILE__, __LINE__, __func__);

  if (read_input(&larger, out_buffer, record_size) != 0) {
    free(out_buffer);
    exit(EXIT_FAILURE);
  }

  Part in_buffer = malloc(smaller.size);
  if (!in_buffer) {
    free(out_buffer);
    memory_error(__FILE__, __LINE__, __func__);
  }

  if (read_input(&smaller, in_buffer, record_size) != 0) {
    free(in_buffer);
    free(out_buffer);
    exit(EXIT_FAILURE);
  }

  size_t out_count = merge_buffers(in_buffer, smaller.count, out_buffer, larger.count);
  free(in_buffer);

  if (write_output(output_filename, out_buffer, out_count, record_size) != 0) {
    free(out_buffer);
    exit(EXIT_FAILURE);
  }

  free(out_buffer);
  return 0;
}