File: cext.c

package info (click to toggle)
audacity 2.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 80,076 kB
  • sloc: cpp: 192,859; ansic: 158,072; sh: 34,021; python: 24,248; lisp: 7,495; makefile: 3,667; xml: 573; perl: 31; sed: 16
file content (107 lines) | stat: -rw-r--r-- 2,654 bytes parent folder | download | duplicates (19)
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
/****************************************************************************
                cext.c
 Copyright 1989 Carnegie Mellon University

 August 3, 1987
 Author: Frits Habermann
----------------------------------------------------------------------------
 02-May-1988 | JCD : portable & AMIGA version.
 17-Oct-1988 | JCD : more portability (FREE).
 28-Apr-2003 | DM  : changed includes for portability
****************************************************************************/

#include "switches.h"

#include <stdio.h>
#include <stdlib.h>

#include "cext.h"
#include "userio.h"

#define calc_middle(top, bot)    (((top - bot) / 2 ) + bottom )

#define kbyte 1000
#define outof_mem(blocksize)     (blocksize == 0 )
#define done_search(top, bot, middle)    ( (( (top - bot) < kbyte ) && \
( !toomuch_mem(middle)) ) || \
                      ( outof_mem( middle ))    )

private boolean toomuch_mem(ushort maximum) 
{
    char *test;
    boolean istoo_much;
    istoo_much = ( (test = (char *) MALLOC(maximum)) == NULL );
    if (test) FREE(test);
    return( istoo_much );
}

private boolean toolittle_mem(maximum) 
ushort maximum;
{
    char *test;
    boolean istoo_little;
    istoo_little = !( (test = (char *) MALLOC(maximum)) == NULL );
    if (test) FREE( test );
    return(istoo_little);
}

private ushort get_biggest_block( maximum )
ushort maximum;
{
    ushort maxblock;
    ushort top = maximum;
    ushort bottom = 0;
    if (!toomuch_mem(maximum)) return(maximum); /* If there's enough memory */
    else {
        gprintf(ERROR, "Running out of memory...\n");
        maxblock = calc_middle( top, bottom );
        while( !done_search(top, bottom, maxblock) ) {
            if( toomuch_mem(maxblock) ) {
                top = maxblock;
                maxblock = calc_middle(top,bottom);
            }
            else if (toolittle_mem(maxblock)) {
                bottom = maxblock;
                maxblock = calc_middle(top,bottom);
            }
        }
    }
    return( maxblock );
}

public ulong MyMaxMem(ushort *growbytes) 
{
    ulong x;
    if( growbytes != NULL ) *growbytes = 0;
    x=( (ulong)get_biggest_block((ushort)BIGGEST_BLOCK));
/*  gprintf(TRANS,"cext: MyMaxMem %ld\n",x); */
    return x;
}

/* note: EXIT is defined to be cmt_exit */

void cmt_exit(n)
  int n;
{
    cu_cleanup();
/* For protection, exit is #defined to hide it.  Expose it and call it. */
#undef exit
    exit(n);
}


#ifdef AMIGA
#ifdef LATTICE
/* for some reason, these don't seem to be defined 
   anywhere in the standard libraries
 */
#include "signal.h"

int _FPERR;
int (*_SIGFPE)(int) = SIG_DFL;

int _oserr;

#endif
#endif