OSDN Git Service

addid library source 20140221
[zither/ds-zither.git] / libms / delim_count.c
1 // delim_count.c
2 // $Id: delim_count.c,v 1.1.1.1 2007/09/19 05:49:54 sendan Exp $
3 // masashi shimakura
4
5 #include<stdio.h>
6 #include<string.h>
7
8 extern int char_count(char *, char);
9
10 /*------------------ DELIM_COUNT -------------------*/
11 int delim_count(char * data, char ca, int lim, int * sta, int *sto)
12 {
13 int co, max, maxlen, count, ret;
14 maxlen = (int)strlen(data);
15 max = char_count(data, ca);
16 count = 0;
17
18 for(co = 0; co < maxlen; co++){
19    if(ca == data[co]){
20       if(count == (lim - 1)){
21          if(co == 0){
22             * sta = co;
23             }
24          if(co > 0){
25             * sta = co + 1;
26             }
27          }
28       if(count == lim){
29          * sto = co - 1;
30          break;
31          }
32       count++;
33       }
34    }
35
36 if(co == maxlen){
37    * sto = co - 1;
38    }
39
40 if(max < lim || 0 > lim){
41    * sta = 0;
42    * sto = 0;
43    ret = -1;
44    }
45 else{
46    ret = (*sto - *sta + 1);
47    }
48
49 return ret;
50 }
51
52
53