dthelp: Change to ANSI function definitions
[oweals/cde.git] / cde / programs / dtmail / dtmail / Sort.hh
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*
24  *+SNOTICE
25  *
26  *      $TOG: Sort.hh /main/6 1998/09/02 18:26:17 mgreess $
27  *
28  *      RESTRICTED CONFIDENTIAL INFORMATION:
29  *      
30  *      The information in this document is subject to special
31  *      restrictions in a confidential disclosure agreement between
32  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
33  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
34  *      Sun's specific written approval.  This document and all copies
35  *      and derivative works thereof must be returned or destroyed at
36  *      Sun's request.
37  *
38  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
39  *
40  *+ENOTICE
41  */
42
43 #ifndef SORT_HH
44 #define SORT_HH
45
46 #include <DtMail/DtMail.hh>
47 #include "FindDialog.h"
48 #include "MsgScrollingList.hh"
49
50 //
51 // What method to use to sort the message list.
52 //
53 typedef enum sortBy {
54     SortTimeDate = 1,
55     SortSender,
56     SortSubject,        
57     SortSize,
58     SortStatus,
59     SortMsgNum
60 } SortBy;
61
62 //
63 // Used for sorting the mailbox.
64 //
65 class Sort {
66
67 public:
68
69
70   //
71   // Sorts the array of message handles.
72   //
73   int sortMessages(MsgScrollingList     *display_list,
74                     DtMail::MailBox     *mbox,
75                     sortBy              howToSort);
76
77 private:
78
79   //
80   // This is the message record that is sorted (not returned). It
81   // is for internal use only and is never passed up to the calling
82   // public member functions.
83   //
84   // The variable 'link' is used to sort the array in place. After
85   // msort() (below) is called, the 'link' variable is set to the
86   // link-order (1,2,...,N). Un-like qsort(), msort() sorts in place
87   // and does not do memcpy(), msort() - updates the 'link' variable.
88   // 
89   
90   struct messageRecord {
91     int          link;          // Needed by msort(). (see source).
92     char        *primary_key_str;
93     int          primary_key_int;
94     int          secondary_key_int;
95     MsgStruct   *msg_struct;
96   };
97
98   //
99   // Similar to qsort().
100   //
101   int   _msort(char             * base,         // Base of array.
102                int                nel,          // Number of elements in array.
103                int                width,        // Size of each element.
104                int                offset,       // Offset to'link'(see source).
105
106                // Compare function.
107                int              (*compar)(char ** one, char ** two));
108
109   //
110   // This is the function that msort() calls to compare two records.
111   //
112   static int    _sortCmp(char **one, char **two);
113 };
114
115 #endif // SORT_HH