Example #1
0
void tree_fix()
{
  int z;
  for( z = dir_tree.count() - 1; z >= 0; z-- )
    {
    VString s1 = dir_tree[z];
    VString s2;
    if (z < dir_tree.count() - 1)
      s2 = dir_tree[z+1];
    else
      s2 = "";
    int i = -1;
    int n = str_count( s1, "/" );
    int p = 0;
    while(n > 2)
      {
      i = str_find( s1, '/', i+1 );
      int q = 0;
      if ( str_len( s2 ) > i )
        q = s1[i] != s2[i];
      if ( q || ( str_count(s2,"/",i+1) < 2))
        {
          p = 1;
          str_set_ch(s1, i, '\\');
        }
      n--;
      }
    if ( p )
      dir_tree.set( z, s1 );
    }
}
Example #2
0
TSTR_LIST merge_configs(TSTR_LIST target, TSTR_LIST source)
{
  char buff[256];
  int i;
  char *c;

  buff[255]=0;
  for (i=0;i<str_count(source);i++) if (source[i])
  {
	strncpy(buff,source[i],255);
	c=strchr(buff,' ');
	if (c!=NULL)
	{
	  int p;
	  *c=0;
	  p=find_ini_field(target,buff);
	  if (p==-1)
	  {
		str_add(&target,source[i]);
	  }
	  else
	  {
		str_replace(&target,p,source[i]);
	  }
	}
  }
  return target;
}
Example #3
0
int save_scr_list(FILE *f,TSTR_LIST names,int scr_id)
  {
  long bytesize;
  int cn;
  char *c,*p;
  int nerr,j;

     bytesize=0;j=1;
     cn=str_count(names);
     while (cn>0 && names[cn-1]==NULL) cn--;
     while (j<cn)
        {
        if (names[j]!=NULL) bytesize+=strlen(names[j])+1;else bytesize++;
        j++;
        }
     if (!bytesize) return 1;
     c=(char *)getmem(bytesize);
     j=1;p=c;
     while (j<cn)
        {
        if (names[j]!=NULL) strcpy(p,names[j]);else *p=0;
        p=strchr(p,'\0');p++;
        j++;
        }
        nerr=(bytesize==save_section(f,c,scr_id,bytesize));//A_STRTAB1+i-1,bytesize));
     free(c);
  return nerr;
  }
Example #4
0
int main(){
	int n,m,i,temp;
	int order[2000];
	int index[2000][100];
	char array[101][51];
    for(i = 0; i < 2000; i ++)
            order[i] = 0;
	scanf("%d%d",&n,&m);
		for(i = 0; i < m; i ++)
		{
            scanf("%s",array[i]);
            temp= str_count(array[i]);
            index[temp][order[temp]] = i;
            order[temp] ++;
  		}
  		//printf("\n");
		for(i=0;i<2000;i++)
		{
            temp = 0;
		 	while(temp<order[i])
	 		{	
	   		    printf("%s\n",array[index[i][temp]]);
	   		    temp ++;
			}
			order[i] = 0;
        }					    						  
    
	return 0;	
}
Example #5
0
long str_count(strlist_t *l) {

	if (l)
		return 1 + str_count(l->next);
	else
		return 0;
}
Example #6
0
const char *str_replace(TSTR_LIST *list,int line,const char *text)
  {
  int count,i,j;
  TSTR_LIST p;
  char *c;

  count=str_count(*list);
  if (line>=count)
     {
     int plus;

        plus=count-line;
        plus=(plus/STR_REALLOC_STEP+1)*STR_REALLOC_STEP;
        p=getmem((count+plus)*sizeof(*p));
        memcpy(p,*list,count*sizeof(*p));
        free(*list);
        j=_msize(p)/sizeof(*p);
        i=count;
        for(;i<j;i++) p[i]=NULL;
        i=count;count=j;
        *list=p;
     }
  if ((*list)[line]!=NULL) free((*list)[line]);
  if (text!=NULL)
     {
     c=(char *)getmem(strlen(text)+1);
     if (c==NULL) return NULL;
     strcpy(c,text);
     }
  else
     c=NULL;
  (*list)[line]=c;
  return c;
  }
Example #7
0
main()
{
char str[200];
int ch,i,sp,no;
printf("enter the strings: ");
scanf("%[^\n]s",str);
str_count(&str);
}
Example #8
0
static int set_line_back(TSTR_LIST ls,int line)
  {
  int i,c=-1,c1=str_count(ls);

  if (line>=c1) line=c1-1;
  for (i=0;i<=line;i++) if (ls[i]!=NULL) c++;
  return c;
  }
Example #9
0
/* ------------------- */
void test_str_count(void)
/* ------------------- */
{
    char *str, *ptr;
    char c;
    int count;
    
    puts("----------------------");
    puts("--- test_str_count ---");
    puts("----------------------");
    
    str = "abc";  ptr = str_count(str, &c, &count); printf("%s = %d x '%c' + %s (%c=%d)\n", str, count, c, ptr, *ptr, *ptr);
    str = "aabc"; ptr = str_count(str, &c, &count); printf("%s = %d x '%c' + %s (%c=%d)\n", str, count, c, ptr, *ptr, *ptr);
    str = "aa";   ptr = str_count(str, &c, &count); printf("%s = %d x '%c' + %s (%c=%d)\n", str, count, c, ptr, *ptr, *ptr);
    str = "a";    ptr = str_count(str, &c, &count); printf("%s = %d x '%c' + %s (%c=%d)\n", str, count, c, ptr, *ptr, *ptr);
    str = "";     ptr = str_count(str, &c, &count); printf("%s = %d x '%c' + %s (%c=%d)\n", str, count, c, ptr, *ptr, *ptr);
    
}
Example #10
0
void release_list(TSTR_LIST list)
  {
  int i,j;

  if (list==NULL) return;
  j=str_count(list);
  for(i=0;i<j;i++)
     str_remove(&list, i);
  free(list);
  }
Example #11
0
void edit_basic_maze()
  {
  if (tool_sel>40) tool_sel = 30;
  create_map_win(-1);
  if (newmap)
     {
     edit_side(0,0);
     sector_details_call(0);
     if (str_count(side_names)>2 || side_names[1]!= NULL) newmap = 0;
     }
  }
Example #12
0
int str_add(TSTR_LIST *list,const char *text)
  {
  int count,i;
  TSTR_LIST p;

  count=str_count(*list);
  p=find_ptr(*list,NULL,count);
  i=p-*list;
  str_replace(list,i,text);
  return i;
  }
Example #13
0
const char *str_insline(TSTR_LIST *list,int before,const char *text)
  {
  int i,count,punkt;
  TSTR_LIST p;

  count=str_count(*list);
  p=find_ptr(*list,NULL,count);
  punkt=p-*list;
  str_replace(list,punkt,NULL);
  for(i=punkt;i>before;i--) (*list)[i]=(*list)[i-1];
  (*list)[before]=NULL;
  return str_replace(list,before,text);
  }
Example #14
0
HASH *http_hashHeader(char *head)
{
	int head_counter = 0;
	char *p = NULL;
	char *var = NULL;
	char *val = NULL;
	char *end = NULL;
	HASH *hash = NULL;

	/* Compute hash size */
	head_counter = str_count(head, "\r\n");
	if (head_counter >= 100) {
		info(_log, NULL, "More than 100 headers?!");
		return NULL;
	} else if (head_counter <= 0) {
		/* HTTP/1.0 */
		return NULL;
	}

	/* Create hash */
	hash = hash_init(head_counter);

	/* Put header into hash */
	p = head;
	while ((end = strstr(p, "\r\n")) != NULL) {
		memset(end, '\0', 2);
		if ((val = strchr(p, ':')) != NULL) {

			/* Variable & Value */
			var = p;
			*val = '\0';
			val++;

			/* More or less empty spaces */
			while (*val == ' ') {
				val++;
			}

			/* Store tuple */
			hash_put(hash, (UCHAR *) var, strlen(var), val);

		} else {
			info(_log, NULL, "Missing ':' in header?!");
			hash_free(hash);
			return NULL;
		}
		p = end + 2;
	}

	return hash;
}
Example #15
0
void process_ini(TSTR_LIST ls,void (*process)(const char *line))
  {
  char *c;
  int i,cnt;
  cnt=str_count(ls);

  for(i=0;i<cnt;i++) if (ls[i]!=NULL)
     {
     c=ls[i];
     while (*c==' ') c++;
     if (*c==';') continue;
     process(c);
     }
  }
Example #16
0
int count_pages()
  {
  int i,cn,z;
  char *c;

  if (all_text == NULL) return 0;
  z = str_count(all_text);
  for(i = 0,cn = 0;i<z;i++)
     {
     c = all_text[i];
     if (c != NULL && c[0] == 27 && c[1] == END_PAGE) cn++;
     }
  return cn;
  }
Example #17
0
static int get_to_topline(TSTR_LIST ls,int line,int *retu)
  {
  int cnt;
  int ret,i,cn;


  cnt=str_count(ls);ret=0;cn=0;
  for(i=0;i<cnt;i++)
    {
    if (line>=0) ret=i;
    if (ls[i]!=NULL) line--,cn++;
    }
  if (retu!=NULL) *retu=cn;
  return ret;
  }
Example #18
0
Field_string::Field_string(const std::string& field_name_arg, const std::string& type):
    Field_longstr(field_name_arg, type) {

    // field size is determined by string type capacity
    std::string::size_type b = type.find('(', 0);
    std::string::size_type e = type.find(')', 0);

    if (b == std::string::npos || e == std::string::npos) {
        throw std::runtime_error("Field_string: Incorrect field CHAR");
    }

    std::string str_count(type, b+1, e-b-1);
        
    field_length = ::atoi(str_count.c_str());
}
Example #19
0
int save_config(TSTR_LIST ls,const char *filename)
  {
  int i,cnt,err=0;
  FILE *f;
  f=fopen(filename,"w");
  if (f==NULL) return -1;
  cnt=str_count(ls);
  for(i=0;i<cnt && !err;i++) if (ls[i]!=NULL)
     {
     if (fputs(ls[i],f)==EOF) err=-1;
     putc('\n',f);
     }
  fclose(f);
  return err;
  }
Example #20
0
int find_ini_field(TSTR_LIST ls,const char *name)
  {
  const char *a;
  char *b;
  int i,cnt=str_count(ls);

  for (i=0;i<cnt;i++) if (ls[i]!=NULL)
     {
     a=name;
     b=ls[i];
     while (*b==32) b++;
     if (*b==';') continue;
     if (comcmp(b,a)) return i;
     }
  return -1;
  }
Example #21
0
TSTR_LIST sort_list(TSTR_LIST list,int direction)
  {
  TUZEL uz;
  int i,j;

  uz.data=NULL;uz.levy=NULL;uz.pravy=NULL;
  uz.spatky=NULL;
  j=str_count(list);
  for(i=0;i<j;i++)
     if (list[i]!=NULL) if (sort_add_to_tree(&uz,list[i],direction))
                             {
                             sort_release_tree(&uz);
                             return NULL;
                             }
  sort_read_list(&uz,list);
  sort_release_tree(&uz);
  return list;
  }
Example #22
0
Field_bit::Field_bit(const std::string& field_name_arg, const std::string& type)
    : Field(field_name_arg, type)
{
    std::string::size_type b = type.find('(', 0);
    std::string::size_type e = type.find(')', 0);

    if (b == std::string::npos || e == std::string::npos)
        throw std::runtime_error("Field_bit: Incorrect field BIT");

    LOG_TRACE(log, " Field_bit: arg " << field_name_arg << " type " << type);

    std::string str_count(type, b+1, e-b-1);

    _pack_length = (::atoi(str_count.c_str()) + 7) / 8;

    if (0 == _pack_length || _pack_length > 8 )
        throw std::runtime_error("Field_bit: incorrect data length");
}
Example #23
0
void save_book()
  {
  char *c;
  FILE *f;
  int i,ss;
  char *tx;

  if (all_text == NULL) return;
  concat(c,pathtable[SR_TEMP],BOOK_FILE);
  f = fopen(c,"w");if (f == NULL) return;
  i = 0;
  ss = str_count(all_text);
  while (i<ss && (tx = all_text[i++]) != NULL)
     {
     fputs(tx,f);
     fputc('\n',f);
     }
  fclose(f);
  }
Example #24
0
/* ---------------------------- */
void routine_str_count2(char *str)
/* ---------------------------- */
{
    char *ptr;
    char c;
    int count;
    
    puts("------------------------");
    puts("-- routine_str_count2 --");
    puts("------------------------");
    
    ptr = str;
    puts(str);
    
    do {
        ptr = str_count(str, &c, &count); printf("%s = %d x '%c' + %s (%c=%d)\n", str, count, c, ptr, *ptr, *ptr);
        str = ptr;
    } while (count); // Question: que pourrait etre une autre condition de sortie ?
}
Example #25
0
void str_line_draw(int x1,int y1,int x2,int y2,OBJREC *o)
  {
  char c[200];
  char **s;
  int *d;


  d=(int *)o->data;
  bar(x1,y1,x2,y2);
  s=*(char ***)(o->userptr);
  if (*d<0 || *d>=str_count(s) || s[*d]==0) strcpy(c,"???");else strcpy(c,s[*d]);
  while (text_width(c)>(x2-x1))
     {
     char *t;

     t=strchr(c,'\0');
     *(--t)='\0';
     }
  position(x1,y1);
  outtext(c);
  }
Example #26
0
void debug_end(void)
{
	if (!debug_enabled) {
		printf("%s", debug_buffer);
		debug_idx = 0;
		return;
	}
	
	int count = str_count(debug_buffer, '\n');
	if (count > DEBUG_Y_SIZE) {
		char* next_line = strchr(debug_buffer, '\n') + 1;
		memmove(debug_buffer, next_line, strlen(next_line)+1);
	}
	
	display_saveCursor();
	debug_clear();
	printf("%s", debug_buffer);
	printf("                                            ");
	debug_idx = strlen(debug_buffer);
	display_loadCursor();
}
Example #27
0
Field_varstring::Field_varstring(const std::string& field_name_arg, const std::string& type, const collate_info& collate):
    Field_longstr(field_name_arg, type) {

    // field size is determined by string type capacity

    std::string::size_type b = type.find('(', 0);
    std::string::size_type e = type.find(')', 0);

    if (b == std::string::npos || e == std::string::npos) {
        throw std::runtime_error("Field_string: Incorrect field VARCHAR");
    }

    std::string str_count(type, b+1, e-b-1);
    int symbols = atoi(str_count.c_str());
    int bytes = symbols * collate.maxlen;

    // number of bytes for holding the length
    length_bytes = ((bytes < 256) ? 1 : 2);

    // max length of string
    field_length = symbols;
}
Example #28
0
char* str_replace(char *haystack, char *search, char *replace) {
    char *pos = strstr(haystack, search);
    int count = str_count(haystack, search);
    if(pos = NULL) {
        return uws_strdup(haystack);
    }
    int search_len = strlen(search);
    int replace_len = strlen(replace);
    char *new_str = (char*) uws_malloc( (strlen(haystack) + count * (replace_len - search_len) + 2) * sizeof(char));
    new_str[0] = 0;
    char *found = haystack;

    pos = haystack;
    while(found = strstr(found, search)) {
        strncat(new_str, pos, found - pos);
        strcat(new_str, replace);
        found += search_len;
        pos = found;
    }
    strcat(new_str, pos);
    return new_str;
}
Example #29
0
static char *relative_path(const char *path1, const char *path2)
{
	const char *p1, *p2;
	char *rel;
	size_t up, len, len2, i;

	p1 = path1;
	p2 = path2;
	while (*p1 == *p2 && *p1) {
		p1 += 1;
		p2 += 1;
	}
	len2 = strlen(p2);
	up = str_count(p1, '/');
	if (up == 0 && len2 != 0)
		return copy_string(p2);
	if (up == 0 && len2 == 0) {
		p2 = strrchr(path2, '/');
		return copy_string(p2);
	}
	if (up == 1 && len2 == 0)
		return copy_string(".");
	if (len2 == 0)
		up -= 1;
	len = up * 3 + len2 + 1;
	rel = malloc(len);
	CHECK(rel != NULL);
	rel[0] = '\0';
	if (up) {
		strcat(rel, "..");
		for (i = 1; i < up; i++)
			strcat(rel, "/..");
		if (len2)
			strcat(rel, "/");
	}
	if (len2)
		strcat(rel, p2);
	return rel;
}
Example #30
0
void write_book(int page)
  {
  int i = 0,y = 0,z,zz,ps,pg;
  char *c;
  char space[] =" ";

  pg = page;
  if (all_text == NULL) return;
  set_font(H_FKNIHA,NOSHADOW(0));
  relpos = XLEFT;
  zz = str_count(all_text);
  if (--page)
  for(i = 0;i<zz && page;i++)
     {
     c = all_text[i];
     if (c != NULL && c[0] == 27 && c[1] == END_PAGE) page--;
     }
  if (page) return;
  for(ps = 0;ps<2;ps++)
     {
  position(relpos,YLEFT+y);
  do
     {
     if (i>zz) break;
     c = all_text[i];
     if (c == NULL) break;
     if (c[0] == 27 && c[1] == END_PAGE) break;
     while (*c)
        {
        z = 0;
        if (*c == 27)
           {
           c++;
           switch (*c++)
              {
              case SPACE:
                          rel_position_x(read_num(c,&z));
                          c += z;
                          break;
              case END_LINE:
                          y += read_num(c,&z);
                          position(relpos,YLEFT+y);
                          c += z;
                          break;
              case PICTURE:
                          c = displ_picture(c);
                          break;
              }
           }
        else
           {
           space[0] = *c++;
           outtext(space);
           }
        }
     i++;
     }
  while (1);
  i++;y = 0;
  relpos = XRIGHT;
  if (ps == 0)
     {
     char s[20];
     sprintf(s,texty[135],pg);
     set_aligned_position(XLEFT,YLEFT+YMAX,0,0,s);
     outtext(s);
     }
  if (ps == 1)
     {
     char s[20];
     sprintf(s,texty[136],pg+1);
     set_aligned_position(XRIGHT+XMAX,YLEFT+YMAX,2,0,s);
     outtext(s);
     }
     }
  }