-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_vars.c
113 lines (91 loc) · 2.44 KB
/
sort_vars.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**************************************************************************
* sort_vars.c: sorts the pubvar array so that the key for each
* structure is in increasing alphabetical order
*
* $Id: sort_vars.c 8264 2015-06-24 21:29:58Z dlpark $
*
$Revision: 8264 $
$Log: sort_vars.c,v $
Revision 1.5 1996/02/19 20:01:12 markstro
Now lints pretty clean
Revision 1.4 1994/11/10 23:26:51 markstro
(1) Some memory fixes -- results of malloc_dbg.
(2) More stuff removed from set menu.
* Revision 1.3 1994/09/30 14:55:21 markstro
* Initial work on function prototypes.
*
* Revision 1.2 1994/01/31 20:17:34 markstro
* Make sure that all source files have CVS log.
*
**************************************************************************/
#ifdef MALLOC_FUNC_CHECK
#include <malloc_dbg.h>
#endif
#include <stdlib.h> /* qsort */
#define SORT_VARS_C
#include <stdio.h>
#include <string.h>
#include "mms.h"
/*--------------------------------------------------------------------*\
| FUNCTION : sort_vars
| COMMENT :
| PARAMETERS :
| RETURN VALUE :
| RESTRICTIONS :
\*--------------------------------------------------------------------*/
void sort_vars (void) {
PUBVAR **vars;
PUBVAR *tmpvar;
int i, j;
/*
* get vars from varbase, the global pointer
*/
vars = Mvarbase;
for (i = Mnvars-2; i >= 0; i--) {
for (j = 0; j <= i; j++) {
if(strcmp(vars[j]->key,vars[j+1]->key) > 0) {
tmpvar = vars[j];
vars[j] = vars[j+1];
vars[j+1] = tmpvar;
}
}
}
/*
printf("sort_vars\n");
for (i = 0; i < Mnvars; i++) {
printf("I: %ld %s\n",i,vars[i]->key);
}
*/
}
#ifdef SKIP
//Does not work on Linux?
/* ---------------------------------------------------------------------- */
int
PUBVAR_compare(const void *ptr1, const void *ptr2)
/* ---------------------------------------------------------------------- */
{
const PUBVAR *a, *b;
int i;
a = (const PUBVAR *) ptr1;
b = (const PUBVAR *) ptr2;
i = strncmp(a->key, b->key, (size_t) 100);
//fprintf(stderr, "\t%d\t%s\t%s\n", i, (char *) a->key, (char *) b->key);
return i;
}
void sort_vars (void)
{
PUBVAR **vars;
int i;
/*
* get vars from varbase, the global pointer
*/
vars = Mvarbase;
qsort(vars, (size_t) Mnvars,
sizeof(PUBVAR *), PUBVAR_compare);
fprintf(stderr, "Begin:\n");
for (i = 0; i < Mnvars; i++)
{
fprintf(stderr, "\t%s\n",vars[i]->key);
}
}
#endif