Ejemplo n.º 1
0
void exec_command(char cmd, char *param)
{
  switch(cmd){
  case'Q':cmd_quit();  break;
  case'C':cmd_check(); break;
  case'P':cmd_print(atoi(param)); break;
  case'R':cmd_read(param);  break;
  case'W':cmd_write(param); break;
  case'F':cmd_find(param);  break;
  case'S':cmd_sort(atoi(param));  break;
  case'E':cmd_edit(); break;
  case'H':cmd_help(); break;
  default:fprintf(stderr,"error\n\n");
  }
  printf(":");
}
Ejemplo n.º 2
0
Archivo: net_pro.c Proyecto: kota395/np
void exec_command(char cmd, char *param)
{
  switch (cmd) {
  case 'Q': cmd_quit();              break;
  case 'C': cmd_check();             break;
  case 'P': cmd_print(atoi(param));  break;
  case 'R': cmd_read(param);         break;
  case 'W': cmd_write(param);        break;
  case 'F': cmd_find(param);         break;
  case 'S': cmd_sort(atoi(param));   break;
  case 'D': cmd_delete(param);       break;
  case 'r': cmd_random();            break;
  case 'T': test(atoi(param));       break;
  default:
    fprintf(stderr, "Invalid command %c: ignored.\n", cmd);
    break;
  }
}
Ejemplo n.º 3
0
int main(void) {
	int isRunning = 1;
	char buffer[MAX_LINE_LENGTH];
	char command[MAX_LINE_LENGTH];
	while(isRunning){	
		//int i;
		printf("> ");
		fgets(buffer, MAX_LINE_LENGTH, stdin);
		/*for( i = 0; i < MAX_LINE_LENGTH; i++ ){
		  buffer[i] = tolower(buffer[i]);
		}*/
		sscanf(buffer, " %s ", (char*)&command);
		//Switch for commands
		if(strcmp(command, "BYE") == 0){					/*BYE*/
			deleteAllEntry(entry_head);
			deleteAllSnapshot(snapshot_head);
			printf("bye");
			isRunning = 0;
		}else if(strcmp(command, "HELP") == 0){				/*HELP*/
			cmd_help();
		}else if(strcmp(command, "LIST") == 0){
			sscanf(buffer + strlen(command), "%s", (char*)&command);
			if(strcmp(command, "KEYS") == 0){				/*LIST KEYS*/
				cmd_list_keys();
			}else if(strcmp(command, "ENTRIES") == 0){		/*LIST ENTRIES*/
				cmd_list_entries();
			}else if(strcmp(command, "SNAPSHOTS") == 0){	/*LIST SNAPSHOTS*/
				cmd_list_snapshots();
			}
		}else if(strcmp(command, "GET") == 0){				/*GET*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_get(key);
		}else if(strcmp(command, "DEL") == 0){				/*DEL*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_del(key);
		}else if(strcmp(command, "PURGE") == 0){			/*PURGE*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_purge(key);
		}else if(strcmp(command, "SET") == 0){				/*SET*/
			int i = 0;
			char key[MAX_KEY_LENGTH];
			char *endptr;
			int *values = (int*)malloc(MAX_LINE_LENGTH/2*sizeof(int));
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			endptr = buffer + strlen(command) + strlen(key) + 2;
			while(1){
				values[i] = strtol(endptr, &endptr, 10);
				if(*endptr == '\n'){
					cmd_set(key, values, i+1);
					break;
				}
				i++;
			}
			free(values);
		}else if(strcmp(command, "PUSH") == 0){				/*PUSH*/
			int i = 0;
			char key[MAX_KEY_LENGTH];
			char *endptr;
			int *values = (int*)malloc(MAX_LINE_LENGTH/2*sizeof(int));
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			endptr = buffer + strlen(command) + strlen(key) + 2;
			while(1){
				values[i] = strtol(endptr, &endptr, 10);
				if(*endptr == '\n'){
					cmd_push(key, values, i+1);
					break;
				}
				i++;
			}
			free(values);
		}else if(strcmp(command, "APPEND") == 0){			/*APPEND*/ 
			int i = 0;
			char key[MAX_KEY_LENGTH];
			char *endptr;
			int *values = (int*)malloc(MAX_LINE_LENGTH/2*sizeof(int));
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			endptr = buffer + strlen(command) + strlen(key) + 2;
			while(1){
				values[i] = strtol(endptr, &endptr, 10);
				if(*endptr == '\n'){
					cmd_append(key, values, i+1);
					break;
				}
				i++;
			}
			free(values);
		}else if(strcmp(command, "PICK") == 0){				/*PICK*/
			char key[MAX_KEY_LENGTH];
			int index;
			sscanf(buffer + strlen(command)+1, "%s", (char*)&key);
			index = strtol(buffer + strlen(command) + strlen(key)+2, (char**)&command, 0);
			cmd_pick(key, index);
		}else if(strcmp(command, "PLUCK") == 0){			/*PLUCK*/
			char key[MAX_KEY_LENGTH];
			int index;
			sscanf(buffer + strlen(command)+1, "%s", (char*)&key);
			index = strtol(buffer + strlen(command) + strlen(key)+2, (char**)&command, 0);
			cmd_pluck(key, index);
		}else if(strcmp(command, "POP") == 0){				/*POP*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_pop(key);
		}else if(strcmp(command, "DROP") == 0){				/*DROP*/
			int id = strtol(buffer + strlen(command) +1 , (char**)&command, 10);
			cmd_drop(id);
		}else if(strcmp(command, "ROLLBACK") == 0){			/*ROLLBACK*/
			int id = strtol(buffer + strlen(command) +1 , (char**)&command, 10);
			cmd_rollback(id);
		}else if(strcmp(command, "CHECKOUT") == 0){			/*CHECKOUT*/
			int id = strtol(buffer + strlen(command) +1 , (char**)&command, 10);
			cmd_checkout(id);
		}else if(strcmp(command, "SNAPSHOT") == 0){			/*SNAPSHOT*/
			cmd_snapshot();
		}else if(strcmp(command, "MIN") == 0){				/*MIN*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_min(key);
		}else if(strcmp(command, "MAX") == 0){				/*MAX*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_max(key);
		}else if(strcmp(command, "SUM") == 0){				/*SUM*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_sum(key);
		}else if(strcmp(command, "LEN") == 0){				/*LEN*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_len(key);
		}else if(strcmp(command, "REV") == 0){				/*REV*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_rev(key);
		}else if(strcmp(command, "UNIQ") == 0){				/*UNIQ*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_uniq(key);
		}else if(strcmp(command, "SORT") == 0){				/*SORT*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_sort(key);
		}else{
			printf("\n");
		}
	}
	return 0;
}
Ejemplo n.º 4
0
static void
cb_dialog_ok_clicked (SortFlowState *state)
{
	GnmSortData *data, *data_copy;
	GnmSortClause *array, *this_array_item;
	int item = 0;
	GtkTreeIter iter;
	gboolean descending, case_sensitive, sort_by_value, move_format;
	gint number;
	gint base;
	char const *text;

	array = g_new (GnmSortClause, state->sort_items);
	this_array_item = array;
	base = (state->is_cols ? state->sel->v_range.cell.a.col : state->sel->v_range.cell.a.row);

	while (gtk_tree_model_iter_nth_child  (GTK_TREE_MODEL (state->model),
					       &iter, NULL, item)) {
		gtk_tree_model_get (GTK_TREE_MODEL (state->model), &iter,
				    ITEM_DESCENDING,&descending,
				    ITEM_CASE_SENSITIVE, &case_sensitive,
				    ITEM_SORT_BY_VALUE, &sort_by_value,
				    ITEM_MOVE_FORMAT, &move_format,
				    ITEM_NUMBER, &number,
				    -1);
		item++;
		this_array_item->offset = number - base;
		this_array_item->asc = !!descending;
		this_array_item->cs = case_sensitive;
		this_array_item->val = sort_by_value;
		this_array_item++;
	}


	data = g_new (GnmSortData, 1);
	data->sheet = state->sel->v_range.cell.a.sheet;
	data->range = g_new (GnmRange, 1);
	data->range = range_init (data->range, state->sel->v_range.cell.a.col
				  + ((state->header && !state->is_cols) ? 1 : 0),
				  state->sel->v_range.cell.a.row
				  + ((state->header && state->is_cols) ? 1 : 0),
				  state->sel->v_range.cell.b.col,
				  state->sel->v_range.cell.b.row);
	data->num_clause = state->sort_items;
	data->clauses = array;
	data->top = state->is_cols;
	data->retain_formats = gtk_toggle_button_get_active (
		GTK_TOGGLE_BUTTON (state->retain_format_check));
	data->locale = go_locale_sel_get_locale (state->locale_selector);

	data_copy = gnm_sort_data_copy (data);
	text = gnm_expr_entry_get_text (state->range_entry);
	gnm_sheet_add_sort_setup
		(data->sheet,
		 g_strdup((text != NULL && text[0] != '\0') ? text : "Other"),
		 data_copy);

	cmd_sort (WORKBOOK_CONTROL (state->wbcg), data);

	gtk_widget_destroy (state->dialog);
	return;
}