28 if(l->
nr>0) free(l->
i);
46 int first, last,
swap, intMax=65536;
49 if(strlen(text)<1)
return(1);
53 p=strtok(text,
" ,;.&\t\n\r\0");
56 while((*t!=
'-') && (!isdigit((
int)*t)) && (*t)) t++;
58 while((!isdigit((
int)*t)) && (*t)) t++;
59 if(isdigit((
int)*t)) {first=0; last=atoi(t);}
60 }
else if(isdigit((
int)*t)) {
62 while((isdigit((
int)*t)) && (*t)) t++;
64 t++;
while((!isdigit((
int)*t)) && (*t)) t++;
65 if(isdigit((
int)*t)) last=atoi(t);
else last=intMax;
68 if((first>=0) && (last>=0)) {
69 if(first>last) {
swap=first; first=last; last=
swap;}
70 if(last>intMax) {
if(first<=intMax) last=intMax;
else last=0;}
71 for(j=first; j<=last && list->
nr<intMax; j++)
74 if(first<=intMax)
if(
_intexadd(list, first)<0)
return(3);
76 if(last>=intMax)
if(
_intexadd(list, last)<0)
return(4);
78 p=strtok(NULL,
" ,;.&\t\n\r\0");
80 if(list->
nr<1)
return(1);
97 list->
i=(
int*)malloc(
sizeof(
int));
if(list->
i==NULL)
return(-1);
99 list->
nr=1; list->
i[0]=a;
return(1);
105 if(list->
i[i]==a)
return(0);
107 list->
i=(
int*)realloc(list->
i, (n+1)*
sizeof(
int));
if(list==NULL)
return(-1);
108 if(list->
i[i]>a) {
for(j=n-1; j>=i; j--) list->
i[j+1]=list->
i[j];
break;}
110 list->
i[i]=a; list->
nr=n+1;
125 int r,count=0,l1=0,l2=0;
129 tmplist=(
int*)malloc(
sizeof(
int)*(list1->
nr+list2->
nr));
130 while(l1<list1->nr || l2<list2->nr) {
132 tmplist[count]=list1->
i[l1];
138 for(r=0;r<count;r++) {
139 if(tmplist[r]==list2->
i[l2]) found++;
142 tmplist[count]=list2->
i[l2]; count++;
147 newlist.
i=(
int*)malloc(
sizeof(
int)*count);
148 memcpy(newlist.
i,tmplist,count*
sizeof(
int));
165 if(l==NULL)
return -1;
179 if(l==NULL)
return -1;
199 if(l==NULL)
return(-1);
202 if(ifnew!=0) {
for(i=0; i<l->
nr; i++)
if(l->
list[i]==v)
return(0);}
206 if(l->
_allocNr==0) l->
list=(
int*)malloc(10*
sizeof(
int));
225 if(l==NULL)
return -1;
226 if(l->
nr<2)
return 0;
227 for(i=0; i<l->
nr; i++)
for(j=i+1; j<l->
nr; j++) {
253 if(l==NULL)
return(-1);
254 if(s1==NULL || s2==NULL)
return(0);
258 n=
strTokenNr((
char*)s1, s2);
if(n<1)
return(0);
261 for(i=j=0; i<n; i++) {
289 if(l==NULL)
return(-1);
290 if(s1==NULL || s2==NULL)
return(0);
293 int n=
strTokenNr((
char*)s1, s2);
if(n<1)
return(0);
295 char tmp[128], tmp2[128], *t, *tail;
296 int i, j, m, first, last, sw;
297 for(i=j=0; i<n; i++) {
300 first=strtol(t, &tail, 10);
if(errno)
return(-3);
302 strcpy(tmp2, tail); t=tmp2;
304 else if(*t==
'.') {t++;
if(*t==
'.') t++;
else return(-4);}
307 last=strtol(t, &tail, 10);
if(errno)
return(-7);
308 if(*tail)
return(-8);
313 if(first>last) {sw=first; first=last; last=sw;}
314 for(
int v=first; v<=last; v++) {
int atoi_with_check(const char *int_as_string, int *result_value)
int integerListEmpty(INTEGER_LIST *l)
int integerListInit(INTEGER_LIST *l)
int integerListSort(INTEGER_LIST *l)
int integerListAddFromString(const char *s1, const char *s2, INTEGER_LIST *l, const int ifnew)
INT_list intMerge(INT_list *list1, INT_list *list2)
int intExpand(char *text, INT_list *list)
int integerListExpandFromString(const char *s1, const char *s2, INTEGER_LIST *l, const int ifnew)
void intInit(INT_list *l)
void intEmpty(INT_list *l)
int _intexadd(INT_list *list, int a)
int integerListAdd(INTEGER_LIST *l, int v, int ifnew)
Header file for libtpcmisc.
int strTokenNCpy(const char *str1, const char *str2, int i, char *str3, int count)
int strTokenNr(const char *str1, const char *str2)
void swap(void *orig, void *new, int size)