~ubuntu-branches/ubuntu/warty/libgsm/warty

« back to all changes in this revision

Viewing changes to tls/taste.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Garcia Mantinan
  • Date: 2001-08-22 15:10:43 UTC
  • Revision ID: james.westby@ubuntu.com-20010822151043-0vgz06axh0la8uf6
Tags: upstream-1.0.10
ImportĀ upstreamĀ versionĀ 1.0.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
 
3
 * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
 
4
 * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
 
5
 */
 
6
 
 
7
/*$Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/taste.c,v 1.1 1992/10/28 00:28:39 jutta Exp $*/
 
8
 
 
9
#include        <stdio.h>
 
10
#include        <string.h>
 
11
#include        <memory.h>
 
12
 
 
13
#include        "config.h"
 
14
 
 
15
#ifdef  HAS_STDLIB_H
 
16
#       include <stdlib.h>
 
17
#else
 
18
#include "proto.h"
 
19
#       ifdef   HAS_MALLOC_H
 
20
#       include <malloc.h>
 
21
#       else
 
22
                extern char     * malloc P((char *)), * realloc P((char *,int));
 
23
#       endif
 
24
        extern int exit P((int));
 
25
#endif
 
26
 
 
27
#include "proto.h"
 
28
 
 
29
/*
 
30
 * common code to sweet.c and bitter.c: read the name:#bits description.
 
31
 */
 
32
 
 
33
#include        "taste.h"
 
34
 
 
35
static struct spex  * s_spex;
 
36
static int n_spex, m_spex;
 
37
 
 
38
extern void     write_code P((struct spex *, int));
 
39
 
 
40
char * strsave P1((str), char * str)            /* strdup() + errors */
 
41
{
 
42
        int    n = strlen(str) + 1;
 
43
        char * s = malloc(n);
 
44
        if (!s) {
 
45
                fprintf(stderr, "Failed to malloc %d bytes, abort\n",
 
46
                        strlen(str) + 1);
 
47
                exit(1);
 
48
        }
 
49
        return memcpy(s, str, n);
 
50
}
 
51
 
 
52
struct spex * new_spex P0()
 
53
{
 
54
        if (n_spex >= m_spex) {
 
55
                m_spex += 500;
 
56
                if (!(s_spex = (struct spex *)(n_spex
 
57
                        ? realloc((char *)s_spex, m_spex * sizeof(*s_spex))
 
58
                        : malloc( m_spex * sizeof(*s_spex))))) {
 
59
                        fprintf(stderr, "Failed to malloc %d bytes, abort\n",
 
60
                                m_spex * sizeof(*s_spex));
 
61
                        exit(1);
 
62
                }
 
63
        }
 
64
        return s_spex + n_spex;
 
65
}
 
66
 
 
67
char * strtek P2((str, sep), char * str, char * sep) {
 
68
 
 
69
        static char     * S = (char *)0;
 
70
        char            * c, * base;
 
71
 
 
72
        if (str) S = str;
 
73
 
 
74
        if (!S || !*S) return (char *)0;
 
75
 
 
76
        /*  Skip delimiters.
 
77
         */
 
78
        while (*S) {
 
79
                for (c = sep; *c && *c != *S; c++) ;
 
80
                if (*c) *S++ = 0;
 
81
                else break;
 
82
        }
 
83
 
 
84
        base = S;
 
85
 
 
86
        /*   Skip non-delimiters.
 
87
         */
 
88
        for (base = S; *S; S++) {
 
89
 
 
90
                for (c = sep; *c; c++)
 
91
                        if (*c == *S) {
 
92
                                *S++ = 0;
 
93
                                return base;
 
94
                        }
 
95
        }
 
96
 
 
97
        return base == S ? (char *)0 : base;
 
98
}
 
99
 
 
100
int read_spex P0()
 
101
{
 
102
        char buf[200];
 
103
        char * s, *t;
 
104
        struct spex     * sp = s_spex;  
 
105
 
 
106
        while (gets(buf)) {
 
107
 
 
108
                if (!*buf || *buf == ';') continue;
 
109
                s = strtek(buf, " \t");
 
110
                if (!s) {
 
111
                        fprintf(stderr, "? %s\n", buf);
 
112
                        continue;
 
113
                }
 
114
                sp = new_spex();
 
115
                sp->var = strsave(s);
 
116
                s = strtek((char*)0, " \t");
 
117
                if (!s) {
 
118
                        fprintf(stderr, "varsize?\n");
 
119
                        continue;
 
120
                }
 
121
                sp->varsize = strtol(s, (char *)0, 0);
 
122
                n_spex++;
 
123
        }
 
124
 
 
125
        return sp - s_spex;
 
126
}
 
127
 
 
128
int main P0()
 
129
{
 
130
        read_spex();
 
131
        write_code(s_spex, n_spex);
 
132
 
 
133
        exit(0);
 
134
}