~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to arts/runtime/sequenceutils.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
    /*
 
2
 
 
3
    Copyright (C) 1999 Stefan Westerfeld
 
4
                       stefan@space.twc.de
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program; if not, write to the Free Software
 
18
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 
 
20
    */
 
21
 
 
22
#include "sequenceutils.h"
 
23
#include <stdarg.h>
 
24
#include <stdio.h>
 
25
#include <config.h>
 
26
 
 
27
using namespace std;
 
28
 
 
29
#if 0
 
30
void sqprintf(ArtsCorba::StringSeq *list, const char *fmt, ...)
 
31
{
 
32
        char p[1024];
 
33
        va_list ap;
 
34
        va_start(ap, fmt);
 
35
        (void) vsnprintf(p, 1024, fmt, ap);
 
36
        va_end(ap);
 
37
 
 
38
        unsigned long len = list->length();
 
39
        list->length(len+1);
 
40
        (*list)[len] = CORBA::string_dup(p);
 
41
}
 
42
#endif
 
43
 
 
44
void sqprintf(vector<string> *list, const char *fmt, ...)
 
45
{
 
46
        char p[1024];
 
47
        va_list ap;
 
48
        va_start(ap, fmt);
 
49
        (void) vsnprintf(p, 1024, fmt, ap);
 
50
        va_end(ap);
 
51
 
 
52
        list->push_back(p);
 
53
}
 
54
 
 
55
int parse_line(const char *in, char *& cmd, char *& param)
 
56
{
 
57
        int i,cmdlen=0,paramlen=0;
 
58
        static char static_cmd[1000], static_param[1000];
 
59
 
 
60
        cmd = static_cmd;
 
61
        param = static_param;
 
62
        i = 0;
 
63
 
 
64
        while(in[i] == ' ' || in[i] == '\t') i++;
 
65
 
 
66
        if(in[i] == 0) return(0);
 
67
 
 
68
        while(in[i] != '=' && in[i] != 0) cmd[cmdlen++] = in[i++];
 
69
        if(in[i] != 0) i++;
 
70
        while(in[i] != 0) param[paramlen++] = in[i++];
 
71
 
 
72
        cmd[cmdlen] = 0;
 
73
        param[paramlen] = 0;
 
74
 
 
75
        if(paramlen) return(2);
 
76
        if(cmdlen) return(1);
 
77
        return(0);
 
78
}
 
79
 
 
80
int parse_line(const string& in, string& cmd, string& param)
 
81
{
 
82
        char *ccmd, *cparam;
 
83
        int result = parse_line(in.c_str(),ccmd,cparam);
 
84
        param = cparam;
 
85
        cmd = ccmd;
 
86
        return result;
 
87
}
 
88
 
 
89
#if 0
 
90
void addSubStringSeq(ArtsCorba::StringSeq *target, ArtsCorba::StringSeq *source)
 
91
{
 
92
        unsigned long i;
 
93
 
 
94
        sqprintf(target,"{");
 
95
        for(i=0;i<source->length();i++)
 
96
        {
 
97
                unsigned long len = target->length();
 
98
                target->length(len+1);
 
99
                string srcstring = string("  ") + string((*source)[i]);
 
100
                (*target)[len] = CORBA::string_dup(srcstring.c_str());
 
101
        }
 
102
        sqprintf(target,"}");
 
103
}
 
104
#endif
 
105
 
 
106
void addSubStringSeq(vector<string> *target, const vector<string> *source)
 
107
{
 
108
        sqprintf(target,"{");
 
109
 
 
110
        vector<string>::const_iterator i;
 
111
        for(i=source->begin();i != source->end();i++)
 
112
                target->push_back("  " + *i);
 
113
 
 
114
        sqprintf(target,"}");
 
115
}
 
116
 
 
117
#if 0
 
118
void appendStringSeq(ArtsCorba::StringSeq *target, ArtsCorba::StringSeq *source)
 
119
{
 
120
        unsigned long i;
 
121
 
 
122
        for(i=0;i<source->length();i++)
 
123
        {
 
124
                unsigned long len = target->length();
 
125
                target->length(len+1);
 
126
                (*target)[len] = CORBA::string_dup((*source)[i]);
 
127
        }
 
128
}
 
129
#endif
 
130
 
 
131
void appendStringSeq(vector<string> *target, const vector<string> *source)
 
132
{
 
133
        vector<string>::const_iterator i;
 
134
        for(i=source->begin();i != source->end();i++)
 
135
                target->push_back(*i);
 
136
}
 
137
 
 
138
#if 0
 
139
ArtsCorba::StringSeq *getSubStringSeq(const ArtsCorba::StringSeq *seq,unsigned long& i)
 
140
{
 
141
        ArtsCorba::StringSeq *result = new ArtsCorba::StringSeq;
 
142
        char empty[1] = {0};
 
143
        char *cmd = empty,*param;
 
144
 
 
145
 
 
146
        while(strcmp(cmd,"{") && i<seq->length())
 
147
                parse_line((*seq)[i++],cmd,param);
 
148
 
 
149
        int brackets = 1;
 
150
        
 
151
        while(i<seq->length())
 
152
        {
 
153
                parse_line((*seq)[i],cmd,param);
 
154
                if(strcmp(cmd,"{") == 0) brackets++;
 
155
                if(strcmp(cmd,"}") == 0) brackets--;
 
156
                if(brackets == 0) return(result);
 
157
 
 
158
                unsigned long len = result->length();
 
159
                result->length(len+1);
 
160
                (*result)[len] = CORBA::string_dup((*seq)[i]);
 
161
                i++;
 
162
        }
 
163
        return(result);
 
164
}
 
165
#endif
 
166
 
 
167
vector<string> *getSubStringSeq(const vector<string> *seq,unsigned long& i)
 
168
{
 
169
        vector<string> *result = new vector<string>;
 
170
        string cmd = "",param;
 
171
 
 
172
        while(cmd != "{" && i<seq->size())
 
173
                parse_line((*seq)[i++],cmd,param);
 
174
 
 
175
        int brackets = 1;
 
176
        
 
177
        while(i<seq->size())
 
178
        {
 
179
                parse_line((*seq)[i],cmd,param);
 
180
                if(cmd == "{") brackets++;
 
181
                if(cmd == "}") brackets--;
 
182
                if(brackets == 0) return(result);
 
183
 
 
184
                result->push_back((*seq)[i]);
 
185
                i++;
 
186
        }
 
187
        return result;
 
188
}