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 108 109
|
/*
TiMidity++ -- MIDI to WAVE converter and player
Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <stdlib.h>
#ifndef NO_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#include "timidity.h"
#include "common.h"
#include "mblock.h"
#include "strtab.h"
void init_string_table(StringTable *stab)
{
memset(stab, 0, sizeof(StringTable));
}
StringTableNode *put_string_table(StringTable *stab, char *str, int len)
{
StringTableNode *p;
p = new_segment(&stab->pool, sizeof(StringTableNode) + len + 1);
if(p == NULL)
return NULL;
p->next = NULL;
if(str != NULL)
{
memcpy(p->string, str, len);
p->string[len] = '\0';
}
if(stab->head == NULL)
{
stab->head = stab->tail = p;
stab->nstring = 1;
}
else
{
stab->nstring++;
stab->tail = stab->tail->next = p;
}
return p;
}
char **make_string_array(StringTable *stab)
{
char **table, *u;
int i, n, s;
StringTableNode *p;
n = stab->nstring;
if(n == 0)
return NULL;
if((table = (char **)safe_malloc((n + 1) * sizeof(char *))) == NULL)
return NULL;
s = 0;
for(p = stab->head; p; p = p->next)
s += strlen(p->string) + 1;
if((u = (char *)safe_malloc(s)) == NULL)
{
free(table);
return NULL;
}
for(i = 0, p = stab->head; p; i++, p = p->next)
{
int len;
len = strlen(p->string) + 1;
table[i] = u;
memcpy(u, p->string, len);
u += len;
}
table[i] = NULL;
delete_string_table(stab);
return table;
}
void delete_string_table(StringTable *stab)
{
reuse_mblock(&stab->pool);
init_string_table(stab);
}
|