Example #1
0
/* processor:
 *  Processes the first packet in the buffer, if any, returning the number
 *  of bytes eaten.
 */
static int processor (unsigned char *buf, int buf_size)
{
   struct input_event *event;

   if (buf_size < (int)sizeof(struct input_event))
      return 0; /* not enough data */

   event = (struct input_event*)buf;
   switch (event->type) {
      case EV_KEY:
         process_key(event);
         break;
      case EV_REL:
         process_rel(event);
         break;
      case EV_ABS:
         process_abs(event);
         break;
   }

   if (current_tool!=no_tool) {
      x_axis.out_abs = CLAMP(x_axis.out_min, x_axis.out_abs, x_axis.out_max);
      y_axis.out_abs = CLAMP(y_axis.out_min, y_axis.out_abs, y_axis.out_max);
      /* There's no range for z */

      _mouse_x = x_axis.out_abs;
      _mouse_y = y_axis.out_abs;
      _mouse_z = z_axis.out_abs;
      _mouse_b = button_left + (button_right<<1) + (button_middle<<2);
      _handle_mouse_input();
   }
   /* Returns the size of the data used */
   return sizeof(struct input_event);
}
Example #2
0
int processOperator(Drawing d, char *op) {
	int res = 0;

	// Look for which operator it is and then process it
	for (int i = 0; i < N_OPS_AVAILABLE; i++) {
		if (strlen(op) == strlen(OPS_AVAILABLE[i]) && strcmp(op, OPS_AVAILABLE[i]) == 0) {
			switch (i) {
				case 0:
					res = process_sum(d->stack);
					break;
				case 1:
					res = process_subtraction(d->stack);
					break;
				case 2:
					res = process_multiplication(d->stack);
					break;
				case 3:
					res = process_division(d->stack);
					break;
				case 4:
					res = process_pi(d->stack);
					break;
				case 5:
					res = process_sin(d->stack);
					break;
				case 6:
					res = process_cos(d->stack);
					break;
				case 7:
					res = process_deg(d->stack);
					break;
				case 8:
					res = process_cm(d->stack);
					break;
				case 9:
					res = process_mm(d->stack);
					break;
				case 10:
					res = process_pt(d->stack);
					break;
				case 11:
					res = process_copy(d->stack);
					break;
				case 12:
					res = process_translate(d->stack);
					break;
				case 13:
					res = process_mtranslate(d->stack);
					break;
				case 14:
					res = process_rotate(d->stack);
					break;
				case 15:
					res = process_mrotate(d->stack);
					break;
				case 16:
					res = process_line(d);
					break;
				case 17:
					res = process_circle(d);
					break;
				case 18:
					res = process_fillcircle(d);
					break;
				case 19:
					res = process_show(d->stack);
					break;
				case 20:
					res = process_tan(d->stack);
					break;
				case 21:
					res = process_arcsin(d->stack);
					break;
				case 22:
					res = process_arccos(d->stack);
					break;
				case 23:
					res = process_arctan(d->stack);
					break;
				case 24:
					res = process_eraseline(d);
					break;
				case 25:
					res = process_e(d->stack);
					break;
				case 26:
					res = process_lg(d->stack);
					break;
				case 27:
					res = process_ln(d->stack);
					break;
				case 28:
					res = process_log(d->stack);
					break;
				case 29:
					res = process_abs(d->stack);
					break;
				default:
					res = throw_error(op, PROCESSOR_ERROR_ILEGAL_OP);
					break;
			}

			break;
		}
	}

	return res;
}