2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
25 * (c) Copyright 1993, 1994 International Business Machines Corp. *
26 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
27 * (c) Copyright 1993, 1994 Novell, Inc. *
32 * $XConsortium: DtsSort.c /main/6 1996/11/21 19:56:08 drk $
34 * RESTRICTED CONFIDENTIAL INFORMATION:
36 * The information in this document is subject to special
37 * restrictions in a confidential disclosure agreement bertween
38 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
39 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
40 * Sun's specific written approval. This documment and all copies
41 * and derivative works thereof must be returned or destroyed at
44 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
54 #define X_INCLUDE_STRING_H
55 #define XOS_USE_XT_LOCKING
56 #include <X11/Xos_r.h>
57 #include <Dt/DbReader.h>
61 extern char *strdup(const char *);
65 get_value(DtDtsDbRecord *ce_entry, char *value)
68 XrmQuark tmp = XrmStringToQuark (value);
70 for(i = 0; i < ce_entry->fieldCount; i++)
72 if(ce_entry->fieldList[i]->fieldName == tmp)
74 return(ce_entry->fieldList[i]->fieldValue);
81 parts_of_pattern(char *c, int *spec, int *count, int *front)
93 if((len = mblen(c, MB_CUR_MAX)) > 1) {
130 if((len = mblen(c + 1, MB_CUR_MAX)) > 1) {
152 check_pattern(char *value1, char *value2)
154 int spec1 = 0,count1 = 0, front1 = 0;
155 int spec2 = 0,count2 = 0, front2 = 0;
159 parts_of_pattern(value1, &spec1, &count1, &front1);
160 parts_of_pattern(value2, &spec2, &count2, &front2);
162 else if(!value1 && !value2)
178 return(front2 - front1);
183 return(spec1 - spec2);
187 return(count2-count1);
201 if(strchr("fcbdlrwx", *c))
215 if(i < 0) return(-1);
221 check_content(char *val1, char *val2)
223 char *v1 = strdup(val1);
224 char *v2 = strdup(val2);
232 _Xstrtokparams strtok_buf;
234 loc1 = _XStrtok(v1, "\t \n", strtok_buf);
235 type1 = _XStrtok(NULL, "\t \n", strtok_buf);
236 cnt1 = &type1[strlen(type1)+1];
237 while(isspace((u_char)*cnt1))cnt1++;
239 loc2 = _XStrtok(v2, "\t \n", strtok_buf);
240 type2 = _XStrtok(NULL, "\t \n", strtok_buf);
241 cnt2 = &type2[strlen(type2)+1];
242 while(isspace((u_char)*cnt2))cnt2++;
244 ret = strcmp(type1, type2);
245 if(loc1 && loc2 && ret == 0)
249 int sl1 = strlen(cnt1);
250 int sl2 = strlen(cnt2);
253 if (sl1 > sl2) ret = -1;
254 else if (sl1 < sl2) ret = 1;
255 else if (l1 > l2 ) ret = 1;
256 else if (l1 < l2 ) ret = -1;
257 else ret = strcmp(cnt1,cnt2);
271 printf("cc (%d,%d) for \"%s\" %c \"%s\"\n", l1, l2, cnt1, sym, cnt2);
280 sfe(DtDtsDbRecord * item1, DtDtsDbRecord * item2)
286 char *value1, *value2;
291 test1 |= get_value(item1, DtDTS_CONTENT) ? 2 : 0;
292 test2 |= get_value(item2, DtDTS_CONTENT) ? 2 : 0;
294 value1 = get_value(item1, DtDTS_NAME_PATTERN);
297 if ((strlen(value1) == 1) && (*value1 == '*'))
307 value2 = get_value(item2, DtDTS_NAME_PATTERN);
310 if ((strlen(value2) == 1) && (*value2 == '*'))
322 test1 |= get_value(item1, DtDTS_PATH_PATTERN) ? 1 : 0;
326 test2 |= get_value(item2, DtDTS_PATH_PATTERN) ? 1 : 0;
363 return (loc1 - loc2);
366 if (loc1 == 2) /* loc1 == loc2 */
368 val = check_pattern(get_value(item1, DtDTS_PATH_PATTERN),
369 get_value(item2, DtDTS_PATH_PATTERN));
374 val = check_pattern(get_value(item1, DtDTS_NAME_PATTERN),
375 get_value(item2, DtDTS_NAME_PATTERN));
384 val = check_content(get_value(item1, DtDTS_CONTENT),
385 get_value(item2, DtDTS_CONTENT));
392 * neither pattern nor content, only needs to compare the
393 * number of fields. If they are equal then which has shorter
394 * record name will be more specific
396 if (item2->fieldCount - item1->fieldCount)
398 return (item2->fieldCount - item1->fieldCount);
401 val = mode_count(get_value(item2, DtDTS_MODE)) -
402 mode_count(get_value(item1, DtDTS_MODE));
409 val = strlen(XrmQuarkToString(item1->recordName)) -
410 strlen(XrmQuarkToString(item2->recordName));
417 return(item1->recordName - item2->recordName);
422 cde_dc_compare(DtDtsDbRecord ** a, DtDtsDbRecord ** b)
424 DtDtsDbRecord **x = (DtDtsDbRecord **) a;
425 DtDtsDbRecord **y = (DtDtsDbRecord **) b;
429 results = sfe(*x, *y);
434 cde_ft_field_value(XrmQuark name_quark)
436 if (name_quark == XrmStringToQuark(DtDTS_PATH_PATTERN))
438 else if (name_quark == XrmStringToQuark(DtDTS_NAME_PATTERN))
440 else if (name_quark == XrmStringToQuark(DtDTS_MODE))
442 else if (name_quark == XrmStringToQuark(DtDTS_LINK_PATH))
444 else if (name_quark == XrmStringToQuark(DtDTS_LINK_NAME))
446 else if (name_quark == XrmStringToQuark(DtDTS_CONTENT))
448 else if (name_quark == XrmStringToQuark(DtDTS_DATA_ATTRIBUTES_NAME))
450 else if (name_quark == XrmStringToQuark(DtDTS_DA_IS_SYNTHETIC))
458 cde_dc_field_compare(DtDtsDbField ** a, DtDtsDbField ** b)
460 return (cde_ft_field_value((*a)->fieldName) -
461 cde_ft_field_value((*b)->fieldName));
464 cde_da_compare(DtDtsDbRecord ** a, DtDtsDbRecord ** b)
466 int results = ((*a)->recordName) - ((*b)->recordName);
470 results = (*a)->seq - (*b)->seq;