~ubuntu-branches/ubuntu/trusty/swish-e/trusty

« back to all changes in this revision

Viewing changes to src/pre_sort.c

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Drolez
  • Date: 2008-09-25 21:52:31 UTC
  • mfrom: (4.1.4 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080925215231-vk46pq42o533syg2
Tags: 2.4.5-5
swish.cgi was not working. Fixed with a 1 char patch. Closes: #500154

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
$Id: pre_sort.c,v 1.7 2003/08/29 21:03:39 jmruiz Exp $
3
 
**
4
 
** This program and library is free software; you can redistribute it and/or
5
 
** modify it under the terms of the GNU (Library) General Public License
6
 
** as published by the Free Software Foundation; either version 2
7
 
** of the License, or any later version.
8
 
**
9
 
** This program is distributed in the hope that it will be useful,
10
 
** but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
 
** GNU (Library) General Public License for more details.
13
 
**
14
 
** You should have received a copy of the GNU (Library) General Public License
15
 
** along with this program; if not, write to the Free Software
16
 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 
**
 
2
$Id: pre_sort.c,v 1.11 2005/05/12 15:41:05 karman Exp $
 
3
**
 
4
    This file is part of Swish-e.
 
5
 
 
6
    Swish-e is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    Swish-e is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along  with Swish-e; if not, write to the Free Software
 
18
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
    
 
20
    See the COPYING file that accompanies the Swish-e distribution for details
 
21
    of the GNU GPL and the special exception available for linking against
 
22
    the Swish-e library.
 
23
    
 
24
** Mon May  9 14:53:51 CDT 2005
 
25
** added GPL
18
26
**
19
27
** jmruiz - 02/2001 - Sorting results module
20
28
**
71
79
 
72
80
/*
73
81
** ----------------------------------------------
74
 
** 
 
82
**
75
83
**  Module management code starts here
76
84
**
77
85
** ----------------------------------------------
125
133
 
126
134
/*
127
135
** ----------------------------------------------
128
 
** 
 
136
**
129
137
**  Module config code starts here
130
138
**
131
139
** ----------------------------------------------
219
227
 
220
228
/*
221
229
** ----------------------------------------------
222
 
** 
 
230
**
223
231
**  Module code starts here
224
232
**
225
233
** ----------------------------------------------
252
260
            !ret ? "*same*" : ret < 0 ? PropLookup[a].file_name : PropLookup[b].file_name );
253
261
 
254
262
    return ret;
255
 
           
 
263
 
256
264
#else
257
265
    return Compare_Properties(CurrentPreSortMetaEntry, PropLookup[a].SortProp, PropLookup[b].SortProp );
258
266
#endif
288
296
 
289
297
 
290
298
/***********************************************************************
291
 
* Pre sort a single property 
 
299
* Pre sort a single property
292
300
*
293
301
************************************************************************/
294
302
int *CreatePropSortArray(IndexFILE *indexf, struct metaEntry *m, FileRec *fi, int free_cache )
298
306
    int             total_files = indexf->header.totalfiles;
299
307
    int             i,
300
308
                    k;
301
 
    
 
309
 
302
310
 
303
311
    sort_array = emalloc( total_files * sizeof( long ) );
304
312
    out_array  = emalloc( total_files * sizeof( long ) );
313
321
 
314
322
    /* This is need to know how to compare the properties */
315
323
    CurrentPreSortMetaEntry = m;
316
 
    
 
324
 
317
325
 
318
326
#ifdef DEBUGSORT
319
327
    {
338
346
    }
339
347
#endif
340
348
 
341
 
    
 
349
 
342
350
 
343
351
    /* Populate the arrays */
344
352
 
348
356
        fi->filenum = i + 1;
349
357
 
350
358
        /* Used cached seek pointers for this file, if not the first time */
351
 
        if ( PropLookup[i].prop_index ) 
 
359
        if ( PropLookup[i].prop_index )
352
360
            fi->prop_index = PropLookup[i].prop_index;
353
361
        else
354
362
            fi->prop_index = NULL;
391
399
        PropLookup = NULL;
392
400
    }
393
401
 
394
 
    
 
402
 
395
403
    return out_array;
396
404
}
397
405
 
408
416
{
409
417
    int             i;
410
418
    int             *out_array = NULL;     /* array that gets sorted */
411
 
#ifndef USE_BTREE
 
419
#ifndef USE_PRESORT_ARRAY
412
420
    unsigned char   *out_buffer  = NULL;
413
421
    unsigned char   *cur;
414
422
#endif
420
428
    int             propIDX;
421
429
 
422
430
    memset( &fi, 0, sizeof( FileRec ) );
423
 
    
424
 
#ifdef USE_BTREE
 
431
 
 
432
#ifdef USE_PRESORT_ARRAY
425
433
    DB_InitWriteSortedIndex(sw, indexf->DB ,header->property_count);
426
434
#else
427
435
    DB_InitWriteSortedIndex(sw, indexf->DB );
443
451
 
444
452
        if ( !(m = getPropNameByID(&indexf->header, metaID )))
445
453
            progerr("Failed to lookup propIDX %d (metaID %d)", propIDX, metaID );
446
 
            
 
454
 
447
455
 
448
456
        /* Check if this property must be in a presorted index */
449
457
        if (!is_presorted_prop(sw, m->metaName))
469
477
        out_array = CreatePropSortArray( indexf, m, &fi, 0 );
470
478
 
471
479
 
472
 
#ifdef USE_BTREE
473
 
        DB_WriteSortedIndex(sw, metaID, (unsigned char *)out_array, total_files, indexf->DB);
 
480
#ifdef USE_PRESORT_ARRAY
 
481
        DB_WriteSortedIndex(sw, metaID, out_array, total_files, indexf->DB);
474
482
 
475
483
        for (i = 0; i < total_files; i++)
476
484
            if ( PropLookup[i].SortProp )
477
485
                freeProperty( PropLookup[i].SortProp );
478
486
#else
479
 
        out_buffer = emalloc( total_files * MAXINTCOMPSIZE ); 
 
487
        out_buffer = emalloc( total_files * MAXINTCOMPSIZE );
480
488
 
481
489
 
482
490
        /* Now compress */
 
491
        /* $$$ this should be in db_natvie.c */
483
492
        cur = out_buffer;
484
493
 
485
494
        for (i = 0; i < total_files; i++)
486
495
        {
487
496
            cur = compress3( out_array[i], cur );
488
 
            
 
497
 
489
498
            /* Free the property */
490
499
            if ( PropLookup[i].SortProp )
491
500
                freeProperty( PropLookup[i].SortProp );
530
539
/* Routines to get the proper sortorder of chars to be called when sorting */
531
540
/* sw_strcasecmp sw_strcmp */
532
541
 
 
542
/*** $$$!!!$$$ I do not think any of these routines are used any more
 
543
 *  Better to use locale settings, IMO. - moseley 2/2005
 
544
 */
 
545
 
533
546
 
534
547
/* Exceptions to the standard translation table for sorting strings */
535
548
/* See initStrCaseCmpTranslationTable to see how it works */
636
649
            iTranslationTableExceptions[i].order * 256 + iTranslationTableExceptions[i].offset;
637
650
}
638
651
 
639
 
/* Comparison string routine function. 
 
652
/* Comparison string routine function.
640
653
** Similar to strcasecmp but using our own translation table
641
654
*/
642
655
int     sw_strcasecmp(unsigned char *s1, unsigned char *s2, int *iTranslationTable)
649
662
    return iTranslationTable[*s1] - iTranslationTable[*s2];
650
663
}
651
664
 
652
 
/* Comparison string routine function. 
 
665
/* Comparison string routine function.
653
666
** Similar to strcmp but using our own translation table
654
667
*/
655
668
int     sw_strcmp(unsigned char *s1, unsigned char *s2, int *iTranslationTable)