int sort_contents(object one,object two)
{
	return strcmp(one->query("name"),two->query("name"));
}
int filter_cansee(object what)
{
	return can_see(what,viewingOb);
}
 
// Process inventory of the room/object being examined
	contents = all_inventory (room) - ({ viewingOb });
	contents = filter_array(contents,"filter_cansee",this_object());
    if (!i = sizeof (contents)) return long;
	contents = sort_array(contents,"sort_contents",this_object());

	lastname = ( userp(contents[i-1]) ? 
					contents[i-1]->query("title") :
					contents[i-1]->query("short") );
	obj = contents[i-1];
    count = 0;

    while (i--) {
//	name = contents[i]->query("name");
	name = ( userp(contents[i]) ? 
					contents[i]->query("title") :
					contents[i]->query("short") );
	if ( name == lastname ) {
		count ++ ;
		continue ; 
	} else 
		lastname = name ;

	if (count > 1) {
		long = sprintf("%s  %s%s%s(%s).\n",long,convert_c_number(count),
						(obj->query("unit") ? obj->query("unit") :"个"),
				      	obj->query(SHORT_DESCRIPTION),
        			    capitalize((string)obj->query("name")));
     } else {
	    long = sprintf("%s  %s(%s).\n",long,
		      	obj->query(SHORT_DESCRIPTION),
        	    capitalize((string)obj->query("name")));
	}
	count = 1;
	obj = contents[i];
	}
		if (count > 1) {
		long = sprintf("%s  %s%s%s(%s).\n",long,convert_c_number(count),
						(obj->query("unit") ? obj->query("unit"):"个"),
				      	obj->query(SHORT_DESCRIPTION),
        			    capitalize((string)obj->query("name")));
     } else {
	    long = sprintf("%s  %s(%s).\n",long,
		      	obj->query(SHORT_DESCRIPTION),
        	    capitalize((string)obj->query("name")));
	}	
	
  return long;
}

