+static char * shortened_hierarchy(char * box) {
+ int dots = 0;
+ char * last_dot;
+ int i,j;
+ char * new_box;
+ for (i=0;i<strlen(box);++i)
+ if (box[i] == '.') ++dots;
+ last_dot = strrchr(box,'.');
+ if (last_dot) {
+ ++last_dot;
+ new_box = safe_malloc(strlen(last_dot)+2*dots+1);
+ new_box[0] = box[0];
+ for (i=1,j=1;i<strlen(box);++i) {
+ if (box[i] == '.') {
+ new_box[j++] = '.';
+ new_box[j] = 0;
+ if (&box[i+1] != last_dot) {
+ new_box[j++] = box[i+1];
+ new_box[j] = 0;
+ } else {
+ strcat(&new_box[j],last_dot);
+ break;
+ }
+ }
+ }
+ return new_box;
+ }
+ return safe_strdup(box);
+}
+