Index: uspace/lib/usbhid/src/hidparser.c
===================================================================
--- uspace/lib/usbhid/src/hidparser.c	(revision b72efe87f3e33beaa3b0d0cf7c8b598a58f6a6de)
+++ uspace/lib/usbhid/src/hidparser.c	(revision 22a8a9bf03a2a9e9757a181a62a427d71aae2fa5)
@@ -52,12 +52,9 @@
 	int32_t value);
 
-int usb_pow(int a, int b);
-
-/*---------------------------------------------------------------------------*/
-
-// TODO: tohle ma bejt asi jinde
-int usb_pow(int a, int b)
-{
-	switch(b) {
+/*---------------------------------------------------------------------------*/
+
+static int usb_pow(int a, int b)
+{
+	switch (b) {
 	case 0:
 		return 1;
@@ -67,5 +64,5 @@
 		break;
 	default:
-		return a * usb_pow(a, b-1);
+		return a * usb_pow(a, b - 1);
 		break;
 	}
@@ -81,17 +78,16 @@
  */
 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id, 
-                           usb_hid_report_type_t type)
+    usb_hid_report_type_t type)
 {
 	usb_hid_report_description_t *report_des;
 
-	if(report == NULL) {
+	if (report == NULL) {
 		return 0;
 	}
 
-	report_des = usb_hid_report_find_description (report, report_id, type);
-	if(report_des == NULL){
+	report_des = usb_hid_report_find_description(report, report_id, type);
+	if (report_des == NULL) {
 		return 0;
-	}
-	else {
+	} else {
 		return report_des->item_length;
 	}
@@ -106,17 +102,16 @@
  */
 size_t usb_hid_report_byte_size(usb_hid_report_t *report, uint8_t report_id, 
-                           usb_hid_report_type_t type)
+    usb_hid_report_type_t type)
 {
 	usb_hid_report_description_t *report_des;
 
-	if(report == NULL) {
+	if (report == NULL) {
 		return 0;
 	}
 
-	report_des = usb_hid_report_find_description (report, report_id, type);
-	if(report_des == NULL){
+	report_des = usb_hid_report_find_description(report, report_id, type);
+	if (report_des == NULL) {
 		return 0;
-	}
-	else {
+	} else {
 		return ((report_des->bit_length + 7) / 8) ;
 	}
@@ -133,5 +128,5 @@
  */ 
 int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, 
-	size_t size, uint8_t *report_id)
+    size_t size, uint8_t *report_id)
 {
 	usb_hid_report_field_t *item;
@@ -140,20 +135,18 @@
 	usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
 	
-	if(report == NULL) {
+	if (report == NULL) {
 		return EINVAL;
 	}
 
-	if(report->use_report_ids != 0) {
+	if (report->use_report_ids != 0) {
 		*report_id = data[0];
-	}	
-	else {
+	} else {
 		*report_id = 0;
 	}
 
-
 	report_des = usb_hid_report_find_description(report, *report_id, 
-		type);
-
-	if(report_des == NULL) {
+	    type);
+
+	if (report_des == NULL) {
 		return EINVAL;
 	}
@@ -162,35 +155,32 @@
 	list_foreach(report_des->report_items, list_item) {
 		item = list_get_instance(list_item, usb_hid_report_field_t, 
-				ritems_link);
-
-		if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
+		    ritems_link);
+
+		if (USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
 			
-			if(USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0){
-
-				// array
+			if (USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) {
+				/* array */
 				item->value = 
 					usb_hid_translate_data(item, data);
 		
 				item->usage = USB_HID_EXTENDED_USAGE(
-				    item->usages[
-				    item->value - item->physical_minimum]);
+				    item->usages[item->value -
+				    item->physical_minimum]);
 
 				item->usage_page = 
 				    USB_HID_EXTENDED_USAGE_PAGE(
-				    item->usages[
-				    item->value - item->physical_minimum]);
-
-				usb_hid_report_set_last_item (
+				    item->usages[item->value -
+				    item->physical_minimum]);
+
+				usb_hid_report_set_last_item(
 				    item->collection_path, 
 				    USB_HID_TAG_CLASS_GLOBAL, 
 				    item->usage_page);
 
-				usb_hid_report_set_last_item (
+				usb_hid_report_set_last_item(
 				    item->collection_path, 
 				    USB_HID_TAG_CLASS_LOCAL, item->usage);
-				
-			}
-			else {
-				// variable item
+			} else {
+				/* variable item */
 				item->value = usb_hid_translate_data(item, 
 				    data);				
@@ -200,5 +190,4 @@
 	
 	return EOK;
-	
 }
 
@@ -217,14 +206,14 @@
 	int part_size;
 	
-	int32_t value=0;
-	int32_t mask=0;
-	const uint8_t *foo=0;
-
-	// now only shot tags are allowed
-	if(item->size > 32) {
+	int32_t value = 0;
+	int32_t mask = 0;
+	const uint8_t *foo = 0;
+
+	/* now only short tags are allowed */
+	if (item->size > 32) {
 		return 0;
 	}
 
-	if((item->physical_minimum == 0) && (item->physical_maximum == 0)){
+	if ((item->physical_minimum == 0) && (item->physical_maximum == 0)) {
 		item->physical_minimum = item->logical_minimum;
 		item->physical_maximum = item->logical_maximum;			
@@ -232,57 +221,55 @@
 	
 
-	if(item->physical_maximum == item->physical_minimum){
+	if (item->physical_maximum == item->physical_minimum) {
 	    resolution = 1;
-	}
-	else {
+	} else {
 	    resolution = (item->logical_maximum - item->logical_minimum) / 
 		((item->physical_maximum - item->physical_minimum) * 
-		(usb_pow(10,(item->unit_exponent))));
+		(usb_pow(10, (item->unit_exponent))));
 	}
 
 	offset = item->offset;
 	// FIXME
-	if((size_t)(offset/8) != (size_t)((offset+item->size-1)/8)) {
+	if ((size_t) (offset / 8) != (size_t) ((offset+item->size - 1) / 8)) {
 		
 		part_size = 0;
 
-		size_t i=0;
-		for(i=(size_t)(offset/8); i<=(size_t)(offset+item->size-1)/8; i++){
-			if(i == (size_t)(offset/8)) {
-				// the higher one
+		size_t i = 0;
+		for (i = (size_t) (offset / 8);
+		    i <= (size_t) (offset + item->size - 1) / 8; i++) {
+			if (i == (size_t) (offset / 8)) {
+				/* the higher one */
 				part_size = 8 - (offset % 8);
 				foo = data + i;
-				mask =  ((1 << (item->size-part_size))-1);
+				mask =  ((1 << (item->size - part_size)) - 1);
 				value = (*foo & mask);
-			}
-			else if(i == ((offset+item->size-1)/8)){
-				// the lower one
+			} else if (i == ((offset + item->size - 1) / 8)) {
+				/* the lower one */
 				foo = data + i;
-				mask = ((1 << (item->size - part_size)) - 1) 
-					<< (8 - (item->size - part_size));
+				mask = ((1 << (item->size - part_size)) - 1) <<
+				    (8 - (item->size - part_size));
 
 				value = (((*foo & mask) >> (8 - 
-				    (item->size - part_size))) << part_size ) 
-				    + value;
-			}
-			else {
-				value = (*(data + 1) << (part_size + 8)) + value;
+				    (item->size - part_size))) << part_size) + 
+				    value;
+			} else {
+				value = (*(data + 1) << (part_size + 8)) +
+				    value;
 				part_size += 8;
 			}
 		}
-	}
-	else {		
-		foo = data+(offset/8);
-		mask =  ((1 << item->size)-1) << (8-((offset%8)+item->size));
-		value = (*foo & mask) >> (8-((offset%8)+item->size));
-	}
-
-	if((item->logical_minimum < 0) || (item->logical_maximum < 0)){
+	} else {		
+		foo = data + (offset / 8);
+		mask = ((1 << item->size) - 1) <<
+		    (8 - ((offset % 8) + item->size));
+		value = (*foo & mask) >> (8 - ((offset % 8) + item->size));
+	}
+
+	if ((item->logical_minimum < 0) || (item->logical_maximum < 0)) {
 		value = USB_HID_UINT32_TO_INT32(value, item->size);
 	}
 
-	return (int)(((value - item->logical_minimum) / resolution) + 
-		item->physical_minimum);
-	
+	return (int) (((value - item->logical_minimum) / resolution) + 
+	    item->physical_minimum);
 }
 
@@ -299,7 +286,7 @@
  */
 uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, 
-	uint8_t report_id)
-{
-	if(report == NULL) {
+    uint8_t report_id)
+{
+	if (report == NULL) {
 		*size = 0;
 		return NULL;
@@ -310,18 +297,17 @@
 	list_foreach(report->reports, report_it) {
 		report_des = list_get_instance(report_it,
-			usb_hid_report_description_t, reports_link);
+		    usb_hid_report_description_t, reports_link);
 		
-		if((report_des->report_id == report_id) &&
-			(report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){
+		if ((report_des->report_id == report_id) &&
+		    (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)) {
 			break;
 		}
 	}
 
-	if(report_des == NULL){
+	if (report_des == NULL) {
 		*size = 0;
 		return NULL;
-	}
-	else {
-		*size = (report_des->bit_length + (8 - 1))/8;
+	} else {
+		*size = (report_des->bit_length + (8 - 1)) / 8;
 		uint8_t *ret = malloc((*size) * sizeof(uint8_t));
 		memset(ret, 0, (*size) * sizeof(uint8_t));
@@ -337,8 +323,7 @@
  */
 void usb_hid_report_output_free(uint8_t *output)
-
-{
-	if(output != NULL) {
-		free (output);
+{
+	if (output != NULL) {
+		free(output);
 	}
 }
@@ -354,24 +339,24 @@
  */
 int usb_hid_report_output_translate(usb_hid_report_t *report, 
-	uint8_t report_id, uint8_t *buffer, size_t size)
-{
-	int32_t value=0;
+    uint8_t report_id, uint8_t *buffer, size_t size)
+{
+	int32_t value = 0;
 	int offset;
 	int length;
 	int32_t tmp_value;
 	
-	if(report == NULL) {
+	if (report == NULL) {
 		return EINVAL;
 	}
 
-	if(report->use_report_ids != 0) {
+	if (report->use_report_ids != 0) {
 		buffer[0] = report_id;		
 	}
 
 	usb_hid_report_description_t *report_des;
-	report_des = usb_hid_report_find_description (report, report_id, 
-		USB_HID_REPORT_TYPE_OUTPUT);
-	
-	if(report_des == NULL){
+	report_des = usb_hid_report_find_description(report, report_id, 
+	    USB_HID_REPORT_TYPE_OUTPUT);
+	
+	if (report_des == NULL) {
 		return EINVAL;
 	}
@@ -384,5 +369,5 @@
 
 		value = usb_hid_translate_data_reverse(report_item, 
-			report_item->value);
+		    report_item->value);
 
 		offset = report_des->bit_length - report_item->offset - 1;
@@ -391,55 +376,53 @@
 		usb_log_debug("\ttranslated value: %x\n", value);
 
-		if((offset/8) == ((offset+length-1)/8)) {
-			// je to v jednom bytu
-			if(((size_t)(offset/8) >= size) || 
-				((size_t)(offset+length-1)/8) >= size) {
+		if ((offset / 8) == ((offset + length - 1) / 8)) {
+			if (((size_t) (offset / 8) >= size) || 
+			    ((size_t) (offset + length - 1) / 8) >= size) {
 				break; // TODO ErrorCode
 			}
-			size_t shift = 8 - offset%8 - length;
+			size_t shift = 8 - offset % 8 - length;
 			value = value << shift;							
-			value = value & (((1 << length)-1) << shift);
+			value = value & (((1 << length) - 1) << shift);
 				
 			uint8_t mask = 0;
 			mask = 0xff - (((1 << length) - 1) << shift);
-			buffer[offset/8] = (buffer[offset/8] & mask) | value;
-		}
-		else {
+			buffer[offset / 8] = (buffer[offset / 8] & mask) |
+			    value;
+		} else {
 			int i = 0;
 			uint8_t mask = 0;
-			for(i = (offset/8); i <= ((offset+length-1)/8); i++) {
-				if(i == (offset/8)) {
+			for (i = (offset / 8);
+			    i <= ((offset + length - 1) / 8); i++) {
+				if (i == (offset / 8)) {
 					tmp_value = value;
 					tmp_value = tmp_value & 
-						((1 << (8-(offset%8)))-1);
-
-					tmp_value = tmp_value << (offset%8);
-	
-					mask = ~(((1 << (8-(offset%8)))-1) << 
-							(offset%8));
+					    ((1 << (8 - (offset % 8))) - 1);
+
+					tmp_value = tmp_value << (offset % 8);
+	
+					mask = ~(((1 << (8 - (offset % 8))) - 1)
+					    << (offset % 8));
 
 					buffer[i] = (buffer[i] & mask) | 
-						tmp_value;
-				}
-				else if (i == ((offset + length -1)/8)) {
+					    tmp_value;
+				} else if (i == ((offset + length - 1) / 8)) {
 					
 					value = value >> (length - 
-						((offset + length) % 8));
+					    ((offset + length) % 8));
 
 					value = value & ((1 << (length - 
-						((offset + length) % 8))) - 1);
+					    ((offset + length) % 8))) - 1);
 				
 					mask = (1 << (length - 
-						((offset + length) % 8))) - 1;
+					    ((offset + length) % 8))) - 1;
 
 					buffer[i] = (buffer[i] & mask) | value;
-				}
-				else {
-					buffer[i] = value & (0xFF << i);
+				} else {
+					buffer[i] = value & (0xff << i);
 				}
 			}
 		}
 
-		// reset value
+		/* reset value */
 		report_item->value = 0;
 	}
@@ -456,39 +439,39 @@
  */
 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, 
-	int value)
-{
-	int ret=0;
+    int value)
+{
+	int ret = 0;
 	int resolution;
 
-	if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags)) {
+	if (USB_HID_ITEM_FLAG_CONSTANT(item->item_flags)) {
 		ret = item->logical_minimum;
 	}
 
-	if((item->physical_minimum == 0) && (item->physical_maximum == 0)){
+	if ((item->physical_minimum == 0) && (item->physical_maximum == 0)) {
 		item->physical_minimum = item->logical_minimum;
 		item->physical_maximum = item->logical_maximum;			
 	}
 	
-	// variable item
-	if(item->physical_maximum == item->physical_minimum){
+	/* variable item */
+	if (item->physical_maximum == item->physical_minimum) {
 	    resolution = 1;
-	}
-	else {
+	} else {
 	    resolution = (item->logical_maximum - item->logical_minimum) /
 		((item->physical_maximum - item->physical_minimum) *
-		(usb_pow(10,(item->unit_exponent))));
+		(usb_pow(10, (item->unit_exponent))));
 	}
 
 	ret = ((value - item->physical_minimum) * resolution) + 
-		item->logical_minimum;
-
-	usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), \
-		ret(%x)\n", value, resolution, item->physical_minimum, 
-		item->logical_minimum, ret);
-	
-	if((item->logical_minimum < 0) || (item->logical_maximum < 0)){
+	    item->logical_minimum;
+
+	usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), "
+	    "ret(%x)\n", value, resolution, item->physical_minimum, 
+	    item->logical_minimum, ret);
+	
+	if ((item->logical_minimum < 0) || (item->logical_maximum < 0)) {
 		return USB_HID_INT32_TO_UINT32(ret, item->size);
 	}
-	return (int32_t)0 + ret;
+
+	return (int32_t) 0 + ret;
 }
 
@@ -501,9 +484,9 @@
  */
 usb_hid_report_item_t *usb_hid_report_item_clone(
-	const usb_hid_report_item_t *item)
+    const usb_hid_report_item_t *item)
 {
 	usb_hid_report_item_t *new_report_item;
 	
-	if(!(new_report_item = malloc(sizeof(usb_hid_report_item_t)))) {
+	if (!(new_report_item = malloc(sizeof(usb_hid_report_item_t)))) {
 		return NULL;
 	}					
@@ -529,42 +512,37 @@
  */
 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, 
-	usb_hid_report_field_t *field, usb_hid_report_path_t *path, int flags, 
-	usb_hid_report_type_t type)
+    usb_hid_report_field_t *field, usb_hid_report_path_t *path, int flags, 
+    usb_hid_report_type_t type)
 {
 	usb_hid_report_description_t *report_des = 
-		usb_hid_report_find_description(report, path->report_id, type);
+	    usb_hid_report_find_description(report, path->report_id, type);
 
 	link_t *field_it;
 	
-	if(report_des == NULL){
+	if (report_des == NULL) {
 		return NULL;
 	}
 
-	if(field == NULL){
+	if (field == NULL) {
 		field_it = report_des->report_items.head.next;
-	}
-	else {
+	} else {
 		field_it = field->ritems_link.next;
 	}
 
-	while(field_it != &report_des->report_items.head) {
+	while (field_it != &report_des->report_items.head) {
 		field = list_get_instance(field_it, usb_hid_report_field_t, 
-			ritems_link);
-
-		if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
-			usb_hid_report_path_append_item (
-				field->collection_path, field->usage_page, 
-				field->usage);
-
-			if(usb_hid_report_compare_usage_path(
-				field->collection_path, path, flags) == EOK){
-
+		    ritems_link);
+
+		if (USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
+			usb_hid_report_path_append_item(field->collection_path,
+			    field->usage_page, field->usage);
+
+			if (usb_hid_report_compare_usage_path(
+			    field->collection_path, path, flags) == EOK) {
 				usb_hid_report_remove_last_item(
-					field->collection_path);
-
+				    field->collection_path);
 				return field;
 			}
-			usb_hid_report_remove_last_item (
-				field->collection_path);
+			usb_hid_report_remove_last_item(field->collection_path);
 		}
 		field_it = field_it->next;
@@ -586,8 +564,8 @@
  * @retval report_id otherwise
  */
-uint8_t usb_hid_get_next_report_id(usb_hid_report_t *report, 
-	uint8_t report_id, usb_hid_report_type_t type)
-{
-	if(report == NULL){
+uint8_t usb_hid_get_next_report_id(usb_hid_report_t *report, uint8_t report_id,
+    usb_hid_report_type_t type)
+{
+	if (report == NULL) {
 		return 0;
 	}
@@ -596,23 +574,21 @@
 	link_t *report_it;
 	
-	if(report_id > 0) {
+	if (report_id > 0) {
 		report_des = usb_hid_report_find_description(report, report_id, 
-			type);
-		if(report_des == NULL) {
+		    type);
+		if (report_des == NULL) {
 			return 0;
-		}
-		else {
+		} else {
 			report_it = report_des->reports_link.next;
 		}	
-	}
-	else {
+	} else {
 		report_it = report->reports.head.next;
 	}
 
-	while(report_it != &report->reports.head) {
+	while (report_it != &report->reports.head) {
 		report_des = list_get_instance(report_it, 
-			usb_hid_report_description_t, reports_link);
-
-		if(report_des->type == type){
+		    usb_hid_report_description_t, reports_link);
+
+		if (report_des->type == type) {
 			return report_des->report_id;
 		}
@@ -635,5 +611,5 @@
 void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item)
 {
-	if(report_item == NULL)	{
+	if (report_item == NULL) {
 		return;
 	}
@@ -651,7 +627,6 @@
 	report_item->string_minimum = 0;
 	report_item->string_maximum = 0;
-
-	return;
-}
+}
+
 /**
  * @}
