Merged in v 26.12.
[AROS-Contrib.git] / mui / classes / thebar / mcc / brc1.c
blobf88cd38af08fc9ffe76fec623fb5e5ec7e0d8a1e
1 /***************************************************************************
3 TheBar.mcc - Next Generation Toolbar MUI Custom Class
4 Copyright (C) 2003-2005 Alfonso Ranieri
5 Copyright (C) 2005-2013 by TheBar.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 TheBar class Support Site: http://www.sf.net/projects/thebar
19 $Id$
21 ***************************************************************************/
23 #include "class.h"
25 /***********************************************************************/
27 #define DUMP 0
28 #define RUN 1
29 #define MINRUN 3
30 #define MAXRUN 128
31 #define MAXDAT 128
33 #define BRCUnpackOK 0
34 #define BRCUnpackError 1
36 /***********************************************************************/
38 int
39 BRCUnpack(APTR pSource, APTR pDest, LONG srcBytes0, LONG dstBytes0)
41 signed char *source = pSource;
42 signed char *dest = pDest;
43 LONG srcBytes = srcBytes0;
44 LONG dstBytes = dstBytes0;
45 int result = BRCUnpackOK;
47 ENTER();
49 while(dstBytes > 0)
51 WORD n;
53 if(--srcBytes < 0)
55 result = BRCUnpackError;
56 break;
59 n = *source++;
61 if(n >= 0)
63 n++;
65 srcBytes -= n;
66 dstBytes -= n;
67 if(srcBytes < 0 || dstBytes < 0)
69 result = BRCUnpackError;
70 break;
75 *dest++ = *source++;
77 while(--n > 0);
79 else if(n != -128)
81 signed char c;
83 n = -n + 1;
85 srcBytes--;
86 dstBytes -= n;
87 if(srcBytes < 0 || dstBytes < 0)
89 result = BRCUnpackError;
90 break;
93 c = *source++;
97 *dest++ = c;
99 while(--n > 0);
103 RETURN(result);
104 return result;
107 /***********************************************************************/