3 * libneuro, a light weight abstraction of high or lower libraries
4 * and toolkit for applications.
5 * Copyright (C) 2005-2006 Nicholas Niro, Robert Lemay
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.
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 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 /* character generator */
27 /* min is 33 because characters lower are control which doesn't have a gfx.*/
28 #define START_NUMBER 45 /* normal ascii starts at 0 but theres alot of event characters
29 that aren't graphical. To be safe we start at 45. 33 to 45 are
30 characters we prefer not to use(they are normally invalid anyway) */
32 #define END_NUMBER 126 /* normal ascii finished at 126 */
34 #define SLEEP_TIME 5 /* in microseconds : 1 second == 10^6 microseconds */
37 core_Uchar(unsigned char **buf
, unsigned int *c_pass_count
, unsigned int *cursor
)
39 register unsigned char *c_pass
= NULL
;
43 *buf
= (unsigned char*)calloc(1, sizeof(unsigned char) + 1);
45 c_pass
[0] = START_NUMBER
;
52 if (c_pass
[*cursor
] == END_NUMBER
)
54 c_pass
[*cursor
] = START_NUMBER
;
56 *cursor
= *cursor
+ 1;
57 if (*c_pass_count
< *cursor
+ 1)
59 *c_pass_count
= *c_pass_count
+ 1;
60 *buf
= (unsigned char*)realloc(*buf
,
61 sizeof(unsigned char) * (1 + *c_pass_count
));
63 c_pass
[*c_pass_count
] = '\0';
64 c_pass
[*cursor
] = START_NUMBER
;
67 core_Uchar(buf
, c_pass_count
, cursor
);
72 c_pass
[*cursor
] = c_pass
[*cursor
] + 1;
80 unsigned char *buf = NULL;
93 Uchar(int amount
, unsigned char **buf
)
95 /* register unsigned char *c_pass; */
96 unsigned int c_pass_count
= 0;
97 unsigned int cursor
= 0;
98 register int total
= amount
;
100 if (amount
<= 0 || *buf
) /* to avoid mem leaks we leave if buf is not NULL */
105 core_Uchar(buf
, &c_pass_count
, &cursor
);