patch
Michal Vitecek (M.Vitecek@sh.cvut.cz)
Fri, 21 Aug 1998 15:43:33 +0200
--yrj/dFKFPuw6o+aM
Content-Type: text/plain; charset=us-ascii
hello, i fixed that menu order thing and cleaned the code a bit so it's
more readable now (i think :P).
peace,
--
fuf
------------------------------ na IRC -------------------------------------
BillGates [bgates@www.microsoft.com] has joined #LINUX
...
mode/#linux [+b BillGates!*@*] by DoDad
BillGates was kicked off #linux by DoDad (banned: We see enough of Bill
Gates already.)
--yrj/dFKFPuw6o+aM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="1.5pre9-fuf-01-menu_item_sort_fix.patch"
diff -u -N -r AfterStep-KERNEL-1.5pre9/lib/homeanddirs.c AfterStep-KERNEL-1.5pre9-fuf/lib/homeanddirs.c
--- AfterStep-KERNEL-1.5pre9/lib/homeanddirs.c Fri Aug 7 12:48:57 1998
+++ AfterStep-KERNEL-1.5pre9-fuf/lib/homeanddirs.c Fri Aug 21 15:37:05 1998
@@ -319,55 +319,70 @@
return (*d1)->d_mode - (*d2)->d_mode;
}
-/* Sort entries based on their names. A comes before Z. */
#define BUF_SIZE 10
+/* compares two names, names with <number>_<item name> format come
+ before <item name> only format */
+int my_numbersort(const char *name1, const char *name2)
+{
+ char *underscore1, *underscore2;
+ char buf[BUF_SIZE + 1];
+ int number1, number2, length, final_length;
+
+ /* if the item name(s) that are compared begin with digit, try to get the
+ numbers */
+ if((isdigit(*name1)) || (isdigit(*name2)))
+ {
+ /* find out if the names are in the format <number>_<Item name> */
+ /* look for the first underscore right after the numbers in the first name */
+ underscore1 = name1;
+ while((*underscore1) && (isdigit(*underscore1)) && (*underscore1 != '_')) underscore1++;
+ /* look for the first underscore right after the numbers in the second name */
+ underscore2 = name2;
+ while((*underscore2) && (isdigit(*underscore2)) && (*underscore2 != '_')) underscore2++;
+ /* <number>_<Item name> takes precedence before <Item name> */
+ if((*underscore1) && (!*underscore2)) return(-1);
+ else if((!*underscore1) && (*underscore2)) return(1);
+ /* both names are in <number>_<Item name> format */
+ else if((*underscore1) && (*underscore2))
+ {
+ /* get the first number value */
+ length = underscore1 - name1;
+ final_length = (length < BUF_SIZE) ? length : BUF_SIZE;
+ strncpy(buf, name1, final_length);
+ buf[final_length] = '\0';
+ number1 = atoi(buf);
+ /* get the second number value */
+ length = underscore2 - name2;
+ final_length = (length < BUF_SIZE) ? length : BUF_SIZE;
+ strncpy(buf, name2, final_length);
+ buf[final_length] = '\0';
+ number2 = atoi(buf);
+ /* compare the two numbers - smaller goes before bigger */
+ if(number1 < number2) return(-1);
+ else if(number1 > number2) return(1);
+ else return(0);
+ }
+ }
+ /* it was only a plain attack, the names are not in the format we want */
+ /* so we return 0 because we can't solve this comparison */
+ return(0);
+}
+#undef BUF_SIZE
+
+
+/* Sort entries based on their names. A comes before Z. */
int my_alphasort(struct direntry **d1, struct direntry **d2)
{
- char *under1, *under2;
- int num1, num2, len, final_len;
- char buf[BUF_SIZE + 1];
-
- /* if the item name(s) that are compared begin with digit, try to get the
- numbers */
- if(isdigit(*((*d1)->d_name)) || (isdigit(*((*d2)->d_name))))
- {
- /* find out if the names are in the format <number>_<Item name> */
- under1 = (*d1)->d_name;
- while((*under1) && (isdigit(*under1)) && (*under1 != '_')) under1++;
- under2 = (*d2)->d_name;
- while((*under2) && (isdigit(*under2)) && (*under2 != '_')) under2++;
+ int result;
- /* <number>_<Item name> takes precedence before <Item name> */
- fprintf(stderr, "%s ?= %s : ", (*d1)->d_name, (*d2)->d_name);
- if((*under1 == '_') && (!*under2)) fprintf(stderr, "-1\n");
- else if((!*under2) && (*under2)) fprintf(stderr, "1\n");
- if((*under1 == '_') && (!*under2)) return(-1);
- else if((!*under2) && (*under2)) return(1);
-
-
- /* both names are in format <number>_<Item name> */
- else if((*under1 == '_') && (*under2 == '_'))
- {
- /* copy the number to buf */
- strncpy(buf, (*d1)->d_name, (final_len = ((len = under1 -
-(*d1)->d_name) < BUF_SIZE ? len : BUF_SIZE)));
- buf[final_len] = '\0';
- num1 = atoi(buf);
- /* copy the number to buf */
- strncpy(buf, (*d2)->d_name, (final_len = ((len = under2 -
-(*d2)->d_name) < BUF_SIZE ? len : BUF_SIZE)));
- buf[final_len] = '\0';
- num2 = atoi(buf);
- if(num1 < num2) return(-1);
- else if(num1 > num2) return(1);
- return(0);
- }
- /* it was only a plain attack, the names are not in the format we want */
- }
- return(strcmp((*d1)->d_name, (*d2)->d_name));
+ /* first sort by the numbers, if my_numbersort() returns 0
+ sort by item names */
+ if(!(result = my_numbersort((*d1)->d_name, (*d2)->d_name)))
+ return(strcmp((*d1)->d_name, (*d2)->d_name));
+ else
+ return(result);
}
-#undef BUF_SIZE
/* Sort entries based on their mtimes. Old entries come before new entries,
@@ -375,10 +390,17 @@
*/
int my_datesort(struct direntry **d1, struct direntry **d2)
{
- int diff = (*d1)->d_mtime - (*d2)->d_mtime;
- if (diff == 0)
- diff = my_alphasort(d1, d2);
- return diff;
+ int result;
+
+ /* first sort by the numbers, if my_numbersort() returns 0
+ sort by date */
+ if(!(result = my_numbersort((*d1)->d_name, (*d2)->d_name)))
+ {
+ /* if the dates are the same, sort the items by their names */
+ if(!(result = (*d1)->d_mtime - (*d2)->d_mtime))
+ result = my_alphasort(d1, d2);
+ }
+ return(result);
}
diff -u -N -r AfterStep-KERNEL-1.5pre9/src/afterstep/configure.c AfterStep-KERNEL-1.5pre9-fuf/src/afterstep/configure.c
--- AfterStep-KERNEL-1.5pre9/src/afterstep/configure.c Fri Aug 21 14:48:39 1998
+++ AfterStep-KERNEL-1.5pre9-fuf/src/afterstep/configure.c Fri Aug 21 14:42:58 1998
@@ -2330,7 +2330,7 @@
***************************************************************************/
const char *
-removeorderfromname (const char *name)
+remove_order_from_name (const char *name)
{
int under = 0;
@@ -2432,7 +2432,7 @@
{
/* flag the entry as a directory */
list[i]->d_mode = 1;
- if (!an_is_special_popup_name (removeorderfromname (list[i]->d_name)))
+ if (!an_is_special_popup_name (remove_order_from_name (list[i]->d_name)))
{
sprintf (an_char, "%s/%s", parentpath, directory);
/* save the directory ID for later */
@@ -2456,7 +2456,7 @@
else
fprintf (start_menu, "\nPopUp \"%d\"\n", parent_id);
- fprintf (start_menu, " Title \"%s\"\n", removeorderfromname (directory));
+ fprintf (start_menu, " Title \"%s\"\n", remove_order_from_name (directory));
if (Textures.flags & MenuMiniPixmaps)
fprintf (start_menu, " MiniPixmap \"mini-menu.xpm\"\n");
@@ -2510,14 +2510,14 @@
else
#ifndef NO_AVAILABILITY_CHECK
fprintf (start_menu, " Exec \"%s\" exec %s\n",
- list[i]->d_name, an_char);
+ remove_order_from_name(list[i]->d_name), an_char);
#else
{
if (is_executable_in_path (an_char))
fprintf (start_menu, " Exec \"%s\" exec %s\n",
- list[i]->d_name, an_char);
+ remove_order_from_name(list[i]->d_name), an_char);
else
- fprintf (start_menu, " Nop \"%s\"\n", list[i]->d_name);
+ fprintf (start_menu, " Nop \"%s\"\n", remove_order_from_name(list[i]->d_name));
}
#endif
fgets (an_char, 254, source);
@@ -2531,15 +2531,15 @@
else if (list[i]->d_mode == 1)
{
fprintf (start_menu, " PopUp \"%s\" %s\n",
- removeorderfromname (list[i]->d_name),
- removeorderfromname (list[i]->d_name));
+ remove_order_from_name (list[i]->d_name),
+ remove_order_from_name (list[i]->d_name));
if (Textures.flags & MenuMiniPixmaps)
fprintf (start_menu, " MiniPixmap \"mini-as.xpm\"\n");
}
else
{
fprintf (start_menu, " PopUp \"%s\" %d\n",
- removeorderfromname (list[i]->d_name), list[i]->d_mode);
+ remove_order_from_name (list[i]->d_name), list[i]->d_mode);
if (Textures.flags & MenuMiniPixmaps)
fprintf (start_menu, " MiniPixmap \"mini-folder.xpm\"\n");
}
@@ -2574,7 +2574,7 @@
for (i = 0; i < k; i++)
{
fprintf (start_menu, " %s \"%s\" %s/%s\n", command,
- removeorderfromname (list[i]->d_name), directory, list[i]->d_name);
+ remove_order_from_name (list[i]->d_name), directory, list[i]->d_name);
free (list[i]);
}
free (list);
--yrj/dFKFPuw6o+aM--