Example #1
0
double* extract_coulmn_double(char *str, int col_min, int col_max)	{
	/*
	 return pointer to array of size [(col_max-col_min)+1]
	 array contains floating point numbers range from from col_min to col_max of the given line/string.
	 For example;
	 ---------------------------------------
	 	double *out;
	 	char *line = "    24 U-A       0.07      0.02      0.49     -2.48     -7.63     -0.38";
	 	char *input=NULL;
	 	input = strdup(line);
		out = extract_coulmn_double(input, 3, 5);
		printf("%15.3f%15.3f%15.3f\n",out[0], out[1], out[2]);
	-----------------------------------------
		OUTPUT $          0.070          0.020          0.490
	 */

	double *data=NULL;
	char *buffer=NULL, **str_data=NULL;
	int size = (col_max-col_min)+1;
	int i=0,n=0;

	buffer = strdup(str);
	remove_leading_white_space(buffer);
	str_data = split_by_space(buffer, NULL);

	data = (double *) malloc (sizeof(double)*size);
	for(i=(col_min-1);i<col_max;i++){
		data[n] = strtof(str_data[i],NULL);
		n++;
	}
	free(buffer);
	free(str_data);
	return data;
}
Example #2
0
double get_AtomWCAEnergy(char *line)	{
	double energy;
	char **split_data=NULL;
	int nwords, i;

	remove_leading_white_space(line);
	split_data = split_by_space(line, &nwords);
	energy = strtod(split_data[5], NULL);

	free(split_data);
	return energy;
}
Example #3
0
int* extract_coulmn_integer(char *str, int col_min, int col_max)	{
	/*
	 Similar to extract_coulmn_double but extract integer data.
	 */

	int *data=NULL;
	char *buffer=NULL, **str_data=NULL;
	int size = (col_max-col_min)+1;
	int i=0,n=0;

	buffer = strdup(str);
	remove_leading_white_space(buffer);
	str_data = split_by_space(buffer, NULL);

	data = (int *) malloc (sizeof(int)*size);
	for(i=(col_min-1);i<col_max;i++){
		data[n] = atoi(str_data[i]);
		n++;
	}
	return data;
}
Example #4
0
File: main.c Project: mengpq/os
void process_command(char* cmd){
	char* CMD[10];
	memset(CMD,0,10);
	int i,pid,total,status;
	total=0;
	split_by_space(CMD,cmd,&total);
	if (total==0) return;
	if (strcmp(CMD[0],"clear")==0){
		clear_screen();
	} else if (strcmp(CMD[0],"run")==0){
		if (total<2 || (pid=run(CMD[1]))==-1){
			display_string("this program is not exists or already running!\n");
		} else{
			display_string("run successful ");
			display_string("pid = "); display_int(pid); 
			display_string(" name = "); display_string(CMD[1]);
			display_string("\n");
		}
	} else if (strcmp(CMD[0],"sleep")==0){
		if (total<2 || sleep(CMD[1])==-1){
		} else{
			display_string("Process "); 
			display_string(CMD[1]);
			display_string(" is sleeping now!\n");
		}
	} else if (strcmp(CMD[0],"kill")==0){
		if (total<2 || !is_number(CMD[1])){
			display_string("Usage: kill <pid>\n");
		} else 
		if (kill(CMD[1])==-1){
			display_string("No such process\n");
		} else{
			display_string("The process with pid=");
			display_string(CMD[1]);
			display_string(" was stopped\n");
		}
	} else if (strcmp(CMD[0],"killall")==0){
		if (total<2){
			display_string("Usage: killall <name>");
		} else{
			if (killall(CMD[1])==-1){
				display_string("No such process\n");
			} else{
				display_string("the process with name=");
				display_string(CMD[1]);
				display_string(" was stopped\n");
			}
		}
	} else if (strcmp(CMD[0],"setp")==0){
		if (total<3 || !is_number(CMD[2])){
			display_string("Usage: setp <name> <num>\n");
		} else if (setp(CMD[1],atoi(CMD[2]))==-1){
			display_string("i can't set the priority of ");
			display_string(CMD[1]);
			display_string("\n");
		} else {
			display_string("set priority successful\n");
		}
	} else if (strcmp(CMD[0],"ps")==0){
		if (show_tasks(CMD[1])==-1){
			display_string("I can't recognize the parameter\n");
		}
	} else if (strcmp(CMD[0],"ls")==0){
		ls();
	} else if (strcmp(CMD[0],"rm")==0){
		if (total<2){
			display_string("Usage: rm <filename>\n");
		} else{
			if (rm(CMD[1])==-1){
				display_string(CMD[1]); 
				display_string(" no exist!\n");
			}
		}
	} else if (strcmp(CMD[0],"help")==0){
		show_help();
	} else if (strcmp(CMD[0],"edit")==0){
		if (total==1){
			display_string("Usage: edit <filename>\n");
		} else start_editor(CMD[1]);
	} else if (strcmp(CMD[0],"dump")==0){
		if (dump_mem(CMD[1],CMD[2])==-1){
			display_string("I can't recognize the parameter\n");
		}
	} else{
		display_string(cmd); display_string(": ");
		display_string("no such command\n");
	}
}