| 1 |
<html> |
| 2 |
<LINK rel=stylesheet type="text/css" |
| 3 |
href="../wdoc.css" |
| 4 |
title="Style sheet for wdoc developer documents"> |
| 5 |
<body> |
| 6 |
<h3>Intuitive compare function in AceDB utils.c.</h3> |
| 7 |
|
| 8 |
<h3>lextstrcmp()</h3> |
| 9 |
<p> |
| 10 |
Although lexstrcmp has been available in AceDB since the early 1990's its full functionality |
| 11 |
is not widely known, so it seems worth documenting it and a recent enhancement. It provides |
| 12 |
a means of sorting strings of mixed alpha and numeric characters into a more intuitive order |
| 13 |
than is possible using the standard alphabetic sort routines more normally associated with |
| 14 |
computers. |
| 15 |
</p> |
| 16 |
<p> |
| 17 |
The intention is to sort strings like A11B and A100B into the order which I regard as |
| 18 |
intuitive, ie A11B precedes A100B, rather than the default alphabetic processing which would |
| 19 |
place A100B before A11B. |
| 20 |
</p> |
| 21 |
<p>The routine is used by passing it char * pointers to the two strings to be compared.</p> |
| 22 |
<pre> |
| 23 |
Prototype: |
| 24 |
int lexstrcmp(char *a,char *b); |
| 25 |
Examples: |
| 26 |
if (lexstrcmp(cp, name(tag))) |
| 27 |
return lexstrcmp(cp,cq) <= 0 ? TRUE : FALSE ; |
| 28 |
cmpClass = lexstrcmp(Text(objA), Text(objB)); |
| 29 |
</pre> |
| 30 |
<p> |
| 31 |
In addition to this, a new function, <strong>arrstrcmp()</strong> has been provided recently. |
| 32 |
This is simply a wrapper routine which allows lexstrcmp to be utilised when sorting arrays, |
| 33 |
something not previously possible. It takes the void pointers that qsort requires it to |
| 34 |
have as parameters, casts them to char ** and dereferences them, since what is being sorted is |
| 35 |
an array of pointers to character strings. |
| 36 |
<p> |
| 37 |
To use the new routine when sorting an AceDB array called myArray, specify it as follows: |
| 38 |
arraySort(myArray, arrstrcmp); |
| 39 |
</p> |
| 40 |
<hr> |
| 41 |
</body> |