TPCCLIB
Loading...
Searching...
No Matches
iftfind.c
Go to the documentation of this file.
1
4/*****************************************************************************/
5#include "tpcclibConfig.h"
6/*****************************************************************************/
7#include "tpcextensions.h"
8/*****************************************************************************/
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12#include <strings.h>
13#include <ctype.h>
14#include <math.h>
15#include <time.h>
16/*****************************************************************************/
17#include "tpcift.h"
18/*****************************************************************************/
19
20/*****************************************************************************/
32 IFT *ift,
34 const char *key,
36 int start_index
37) {
38 if(ift==NULL || key==NULL) return -2;
39 if(start_index<0 || start_index>=ift->keyNr) return -2;
40 for(int i=start_index; i<ift->keyNr; i++) if(ift->item[i].key!=NULL)
41 if(strcasecmp(ift->item[i].key, key)==0) return i;
42 return -1;
43}
44/*****************************************************************************/
45
46/*****************************************************************************/
57 IFT *ift,
59 const char *key,
61 const char *value,
63 int start_index
64) {
65 if(ift==NULL || key==NULL || value==NULL) return -2;
66 if(start_index<0 || start_index>=ift->keyNr) return -2;
67 for(int i=start_index; i<ift->keyNr; i++) {
68 if(ift->item[i].key==NULL || ift->item[i].value==NULL) continue;
69 if(strcasecmp(ift->item[i].key, key)!=0) continue;
70 if(strcasecmp(ift->item[i].value, value)!=0) continue;
71 return i;
72 }
73 return -1;
74}
75/*****************************************************************************/
76
77/*****************************************************************************/
88 IFT *ift,
90 const char *s,
92 int start_index
93) {
94 if(ift==NULL || s==NULL) return -2;
95 if(start_index<0 || start_index>=ift->keyNr) return -2;
96 for(int i=start_index; i<ift->keyNr; i++) {
97 if(*s!='\0') {if(strcasestr(ift->item[i].key, s)!=NULL) return i; else continue;}
98 // s is empty
99 if(ift->item[i].key==NULL || ift->item[i].key[0]=='\0') return i;
100 }
101 return -1;
102}
103/*****************************************************************************/
104
105/*****************************************************************************/
116 IFT *ift,
118 const char *s,
120 int start_index
121) {
122 if(ift==NULL || s==NULL) return -2;
123 if(start_index<0 || start_index>=ift->keyNr) return -2;
124 for(int i=start_index; i<ift->keyNr; i++) {
125 if(*s!='\0') {if(strcasestr(ift->item[i].value, s)!=NULL) return i; else continue;}
126 // s is empty
127 if(ift->item[i].value==NULL || ift->item[i].value[0]=='\0') return i;
128 }
129 return -1;
130}
131/*****************************************************************************/
132
133/*****************************************************************************/
144 IFT *ift,
146 const char *key
147) {
148 if(ift==NULL) return(0);
149 int i, found_nr=0;
150 if(key==NULL || strlen(key)<1) {
151 for(i=0; i<ift->keyNr; i++)
152 if(ift->item[i].key==NULL || strlen(ift->item[i].key)<1) found_nr++;
153 return found_nr;
154 }
155 for(i=0; i<ift->keyNr; i++) if(ift->item[i].key!=NULL)
156 if(strcasecmp(ift->item[i].key, key)==0) found_nr++;
157 return found_nr;
158}
159/*****************************************************************************/
160
161/*****************************************************************************/
171 IFT *ift,
173 const char *key
174) {
175 if(ift==NULL || key==NULL || *key=='\0') return;
176 int i=0, start=0;
177 while(1) {
178 i=iftFindKey(ift, key, start); if(i<0) break;
179 iftDelete(ift, i); if(i>start) start=i;
180 }
181 return;
182}
183/*****************************************************************************/
184
185/*****************************************************************************/
193 IFT *ift,
195 const char *key,
197 int index,
199 double *v
200) {
201 if(v!=NULL) *v=nan(""); else return(-10);
202 int li=iftFindKey(ift, key, index); if(li<0) return(li);
203 if(atofCheck(ift->item[li].value, v)!=0) return(-2);
204 return(li);
205}
206/*****************************************************************************/
207
208/*****************************************************************************/
int atofCheck(const char *s, double *v)
Definition decpoint.c:94
int iftDelete(IFT *ift, int index)
Definition ift.c:206
int iftSearchValue(IFT *ift, const char *s, int start_index)
Definition iftfind.c:114
void iftDeleteKey(IFT *ift, const char *key)
Definition iftfind.c:169
int iftFindPair(IFT *ift, const char *key, const char *value, int start_index)
Definition iftfind.c:55
int iftFindNrOfKeys(IFT *ift, const char *key)
Definition iftfind.c:142
int iftSearchKey(IFT *ift, const char *s, int start_index)
Definition iftfind.c:86
int iftFindKey(IFT *ift, const char *key, int start_index)
Definition iftfind.c:30
int iftGetDoubleValue(IFT *ift, const char *key, int index, double *v)
Definition iftfind.c:191
char * strcasestr(const char *haystack, const char *needle)
Definition stringext.c:155
char * value
Definition tpcift.h:37
char * key
Definition tpcift.h:32
Definition tpcift.h:43
IFT_ITEM * item
Definition tpcift.h:57
int keyNr
Definition tpcift.h:47
Header file for library libtpcextensions.
Header file for library libtpcift.