/* * sort.c -- filename sort routine * (C)Copyright 1998, 99 by Hiroshi Takekawa * This file is part of Enfle. * * Last Modified: Mon Dec 13 11:23:28 1999. * $Id: sort.c,v 1.2 1999/12/23 15:16:09 sian Exp $ * * Enfle is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Enfle is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "dlist.h" #include "quicksort.h" #include "sort.h" static int sort_compare(void *a, void *b) { return strcmp((char *)a, (char *)b); } void sort_filenames(Dlist *p) { int i, n = dlist_getndata(p); char **indices; Dlist_data *ptr; if ((indices = calloc(n, sizeof(char *))) == NULL) { fprintf(stderr, "No enough memory for sort\n"); exit(1); } for (i = 0, ptr = dlist_gettop(p); ptr != NULL; ptr = ptr->next, i++) indices[i] = ptr->data; quicksort(indices, i, sort_compare); for (i = 0, ptr = dlist_gettop(p); ptr != NULL; ptr = ptr->next, i++) ptr->data = indices[i]; free(indices); }