sj4/lib/sj3core/memory.c

136 lines
2.5 KiB
C
Raw Normal View History

2008-01-11 11:57:08 +00:00
/*
* Copyright (c) 1991-1994 Sony Corporation
2026-06-19 01:49:53 +09:00
*
2008-01-11 11:57:08 +00:00
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
2026-06-19 01:49:53 +09:00
*
2008-01-11 11:57:08 +00:00
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
2026-06-19 01:49:53 +09:00
*
2008-01-11 11:57:08 +00:00
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2026-06-19 01:49:53 +09:00
*
2008-01-11 11:57:08 +00:00
* Except as contained in this notice, the name of Sony Corporation
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* from Sony Corporation.
*
*/
/*
2026-06-19 01:49:53 +09:00
* $SonyRCSfile: memory.c,v $
* $SonyRevision: 1.1 $
2008-01-11 11:57:08 +00:00
* $SonyDate: 1994/06/03 08:01:58 $
*/
#include "sj_kcnv.h"
#include "sj_kanakan.h"
2026-06-19 01:49:53 +09:00
JREC* free_jlst(JREC* p) {
JREC* jpk;
JREC* jp;
JREC* jn;
2008-01-11 11:57:08 +00:00
jp = NULL;
2026-06-19 01:49:53 +09:00
for(; p; p = jn) {
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
jn = p->jsort;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(p->count) {
if(jp)
jp->jsort = p;
2008-01-11 11:57:08 +00:00
else
jpk = p;
jp = p;
}
else {
free_jrec(p);
}
}
2026-06-19 01:49:53 +09:00
if(jp) jp->jsort = NULL;
2008-01-11 11:57:08 +00:00
return jpk;
}
2026-06-19 01:49:53 +09:00
CLREC*
free_clst(CLREC* p, int l) {
CLREC* cpk;
CLREC* cp;
CLREC* cn;
2008-01-11 11:57:08 +00:00
cp = cpk = NULL;
2026-06-19 01:49:53 +09:00
for(; p; p = cn) {
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
cn = p->clsort;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if((int)p->cllen == l) {
if(p == selcl) {
if(cp) {
p->clsort = cpk;
cpk = p;
} else
2008-01-11 11:57:08 +00:00
cpk = cp = p;
2026-06-19 01:49:53 +09:00
} else {
if(cp)
cp->clsort = p;
2008-01-11 11:57:08 +00:00
else
cpk = p;
cp = p;
}
}
else {
2026-06-19 01:49:53 +09:00
(p->jnode->count)--;
2008-01-11 11:57:08 +00:00
free_clrec(p);
}
}
2026-06-19 01:49:53 +09:00
if(cp) cp->clsort = NULL;
2008-01-11 11:57:08 +00:00
return cpk;
}
2026-06-19 01:49:53 +09:00
void free_clall(CLREC* p) {
CLREC* next;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
while(p) {
(p->jnode->count)--;
next = p->clsort;
2008-01-11 11:57:08 +00:00
free_clrec(p);
p = next;
}
}
2026-06-19 01:49:53 +09:00
void free_jall(JREC* p) {
JREC* next;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
while(p) {
next = p->jsort;
2008-01-11 11:57:08 +00:00
free_jrec(p);
p = next;
}
}
2026-06-19 01:49:53 +09:00
void freework() {
2008-01-11 11:57:08 +00:00
free_clall(maxclptr);
clt1st = maxclptr = NULL;
free_jall(maxjptr);
jrt1st = maxjptr = NULL;
}