source: trunk/src/crtdll/internal.cpp@ 3831

Last change on this file since 3831 was 2618, checked in by sandervl, 26 years ago

JW: Update

File size: 2.1 KB
Line 
1/* $Id: internal.cpp,v 1.1 2000-02-03 21:37:49 sandervl Exp $ */
2
3/*
4 * The C RunTime DLL
5 *
6 * Implements C run-time functionality as known from UNIX.
7 *
8 * Partialy based on Wine
9 *
10 * Copyright 1996,1998 Marcus Meissner
11 * Copyright 1996 Jukka Iivonen
12 * Copyright 1997 Uwe Bonnes
13 * Copyright 1999-2000 Jens Wiessner
14 *
15 * CRTDLL - internal functions
16 *
17 */
18
19#include <odin.h>
20#include <os2win.h>
21#include <ctype.h>
22#include <memory.h>
23#include <stdio.h>
24#include <wchar.h>
25
26
27/*********************************************************************
28 * _memswap (INTERNAL-#1)
29 */
30void _memswap (void *s1, void *s2, size_t n)
31{
32 char *c1, *c2, c;
33 int *i1, *i2, i;
34
35 i1 = (int*)s1; i2 = (int*)s2;
36 while (n >= sizeof (int))
37 {
38 i = *i1; *i1++ = *i2; *i2++ = i;
39 n -= sizeof (int);
40 }
41 c1 = (char *)i1; c2 = (char *)i2;
42 while (n >= 1)
43 {
44 c = *c1; *c1++ = *c2; *c2++ = c;
45 --n;
46 }
47 }
48
49
50/*********************************************************************
51 * qsort1 (INTERNAL-#2)
52 */
53void qsort1 (char *l, char *r, size_t width,
54 int (* CDECL compare)(const void *x1, const void *x2))
55{
56 char *i, *j, *x;
57
58redo:
59 i = l; j = r;
60 x = l + width * (((r-l) / width) >> 1);
61 do
62 {
63 while (i != x && compare ((void *)i, (void *)x) < 0)
64 i += width;
65 while (j != x && compare ((void *)j, (void *)x) > 0)
66 j -= width;
67 if (i < j)
68 {
69 _memswap (i, j, width);
70 if (x == i)
71 x = j;
72 else if (x == j)
73 x = i;
74 }
75 if (i <= j)
76 {
77 i += width; /* (almost) no danger */
78 if (j > l)
79 j -= width; /* avoid wrap-around */
80 }
81 } while (i <= j);
82 if (j-l < r-i)
83 {
84 if (l < j)
85 qsort1 (l, j, width, compare);
86 if (i < r)
87 {
88 l = i;
89 goto redo; /* qsort1 (i, r, width, compare) */
90 }
91 }
92 else
93 {
94 if (i < r)
95 qsort1 (i, r, width, compare);
96 if (l < j)
97 {
98 r = j; /* qsort1 (l, j, width, compare) */
99 goto redo;
100 }
101 }
102}
Note: See TracBrowser for help on using the repository browser.