Exemple #1
0
/*=======================CUTZERO=============================*/
unsigned char* cutzero(unsigned char *t1)
{
	while(t1[lenstr(t1)-1] == '0')
	{
		if(lenstr(t1) == 1 && t1[0] == '0') return t1;
		t1[lenstr(t1)-1] = '\0';
	}
	check(t1);
	return  t1;
}
Exemple #2
0
unsigned char* leveldown(unsigned char *t1)
{
	unsigned char *t2 = (unsigned char*)malloc(sizeof(unsigned char)*lenstr(t1));
	int i = 0;
	while(i < lenstr(t1))
	{
		t2[i] = t1[i+1];
		i++;
	}
	check(t2);
	return t2;
}
Exemple #3
0
/*=========================EQUAL=============================*/
int equal(unsigned char *t1, unsigned char *t2)
{
	int i = 0;
	if (lenstr(t1) != lenstr(t2))
		return 0;
	while(i < lenstr(t1))
	{
		if (t1[i]!= t2[i])
			return 0;
		i++;
	
	}	
	return 1;
}
Exemple #4
0
/*=========================LESS=============================*/
int less(unsigned char *t1, unsigned char *t2)
{
	if (lenstr(t1) != lenstr(t2))
			return lenstr(t1) < lenstr(t2);

	int i = lenstr(t1)-1;
	while(i >= 0)
	{
		if (t1[i]!=t2[i])
			return t1[i]<t2[i];
		i--;
	}
	return 0;
}
Exemple #5
0
/*=========================SUB=============================*/
unsigned char* sub(unsigned char *t1, unsigned char *t2)
{
	int i;
	unsigned char *a, *b, *c, *t;
	unsigned char r = 48;

	if(lenstr(t1) > lenstr(t2))
	{
		a = copy(t1);
		b = (unsigned char*)malloc(sizeof(unsigned char)*(lenstr(a)));
		for( i = 0; i < lenstr(t2); i++)
			b[i] = t2[i];

		for( i = lenstr(t2); i < lenstr(t1); i++)
			b[i] = '0';
		b[i] = '\0';
	}
	else
	{
		a = copy(t1);
		b = t2;
	}

	
	c = (unsigned char*)malloc(sizeof(unsigned char)*(lenstr(a)+1));
	c[lenstr(a)] = '\0';

	i = 0;
	while(i < lenstr(c))
	{
		c[i] = '0';
		i++;
	}
	
	i = 0;
	while(i < lenstr(a))
	{
		c[i] = a[i] - b[i] + 48;
		if (c[i] < 48)
		{
			c[i]+=osn;
			a[i+1]--;
		}
		i++;
	}
	c[i] = '\0';
	check(c);
	c = cutzero(c);
	return c;
}
Exemple #6
0
unsigned char* levelup(unsigned char *t1)
{
	int i;
	unsigned char *t2 = (unsigned char*)malloc(sizeof(unsigned char)*(lenstr(t1)+2));
	
	i = lenstr(t1)+1;
	while(i >= 1)
	{
		t2[i] = t1[i-1];
		i--;
	}
	check(t2);
	return t2;

}
Exemple #7
0
/*=========================GREATER=============================*/
int greater(unsigned char *t1, unsigned char *t2)
{
	if (lenstr(t1) != lenstr(t2))
			return lenstr(t1) > lenstr(t2);

	int i = lenstr(t1)-1;
	while(i >= 0)
	{
		if (t1[i]!=t2[i])
			return t1[i]>t2[i];
		i--;
	}

	return 0;
}
int search(char s[],char k[])
{
	int n=lenstr(s),m=lenstr(k),i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m&&i+j<n;j++)
		{
			if(s[i+j]!=k[j])
				break;
		}
		if(j==m)
			return i;

	}
	return -1;
}
Exemple #9
0
/*=======================REVERSE=============================*/
unsigned char* reverse(unsigned char* t1)
{
	int i;
//	check(t1);
	unsigned char *t2 = (unsigned char*)malloc(sizeof(unsigned char)*lenstr(t1));
	t2[lenstr(t1)] = '\0';
	
	i = 0;
	while(i < lenstr(t1))
	{
		t2[lenstr(t1)-1 -i] = t1[i];
		i++;
	}
	t2[i] = '\0';
	//check(t2);
	return t2;
}
main()
{

    char frase[100]="Daniel";
    printf("\nO tamanho da frase é : %d", lenstr(frase));
    system("pause");

}
int lenstr(char *str)
{
    if (*str == '\0')
        return 0;
    else
    {
        str++;
        return lenstr(str)+1;
    }
}
Exemple #12
0
 int executeCommande(char* commande)
 {

 	char** arguments;
 	int nombreArguments=0;
 	pid_t pid;
 	int retourExec=0;

 	arguments = charToArgs(commande,&nombreArguments);

 	if(!cmpstr(arguments[0],"exit"))
 	{
 		freeMatrice(arguments,nombreArguments);
 		return -2;
 	}
 	if(!cmpstr(arguments[0],"cd"))
 	{
 		if(arguments[1]==NULL || !cmpstr(arguments[1],"~"))
 		{
 			char* home = getEnv("HOME");
 			if(home!=NULL)
 			{
 				printf("goto : %s\n",home);
	 			chdir(home);
 			}else
 			{
 				write(1,"no HOME in env\n",15);
 				freeMatrice(arguments,nombreArguments);
 				return -1;
 			}
 		}else{
 			chdir(arguments[1]); 
 		}
 	}
 	pid = fork();
 	if(pid==0)
 	{

 		if(cmpstr(arguments[0],"cd"))
 		{

 			retourExec = execvp(arguments[0],arguments);
 			if(retourExec==-1)
 			{
 				write(0,arguments[0],lenstr(arguments[0]));
 				write(0," : Command not found\n",21);
 				kill (getpid(),SIGINT);
 				pid=-1;
 			}

 		}
 	}	
 	freeMatrice(arguments,nombreArguments);
 	return pid;
 }
Exemple #13
0
void LLDPDU::ParseTypeAndLength(unsigned char *Buffer,uint& type, uint& length)
{
    if(sizeof(Buffer)<2)
        throw new QException();
    QString typestr = QString::number(Buffer[0],2);
    QString lenstr(typestr[typestr.count()-1]);
    typestr.chop(1);
    type = QString::number(typestr.toInt(0,2),10).toInt();
    lenstr.append(QString::number(Buffer[1],2));
    length=QString::number(lenstr.toInt(0,2),10).toInt();
}
Exemple #14
0
/*=========================MUL=============================*/
unsigned char* mul(unsigned char *t1, unsigned char* t2)
{
	//const int osn = 10;
	unsigned char *a,*b,*c,r;
	int i,j,l;
	a = t1;
	b = t2;
	int lenA = lenstr(a), lenB = lenstr(b);
	c = (unsigned char*)malloc(sizeof(unsigned char)*(lenA+lenB));
	j = lenA+lenB;
	c[lenA+lenB] = '\0';
	
	i = 0;
	while(i < j)
	{
		c[i] = '0';
		i++;
	}
	
	i = 0;
	while(i < lenstr(a))
	{
		r = 0;
		j = 0;
		while(j < lenstr(b))
		{
			l = c[i+j];
			l += ((a[i] - dop) * (b[j] - dop)) + r;
			r = (l-dop) / osn;
			l -= r*osn;
			c[i+j] = l;
			j++;
		}
		if(r) c[i+j] += r;
		i++;
	}
	
	check(c);
	c = cutzero(c);
	return c;
}
Exemple #15
0
/*=======================COPY=============================*/
unsigned char* copy(unsigned char* t1)
{
	unsigned char *t2;
	int a = lenstr(t1), i = 0;
	t2 = (unsigned char*)malloc(sizeof(unsigned char)*a);
	while(t1[i])
	{
		t2[i] = t1[i];
		i++;
	}
	
	t2[i] = '\0';
	check(t2);
	return t2;
	
}
Exemple #16
0
void output_file(char *fileN, unsigned char *t1)
{
	FILE *F = fopen(fileN, "w");

	
	
	//unsigned char *t1 = reverse(str_num);
	int i = 0;
	while( i < lenstr(t1))
	{
		fprintf(F, "%c",t1[i]);
		i++;
}

	fclose(F);
}
static char		*concat_string(char *old, char *buf, int n)
{
	char	*ret;
	char	*bak;

	if (!(ret = (char *)malloc((lenstr(old) + n + 1) * sizeof(*ret))))
		return (NULL);
	bak = ret;
	if (old)
		while (*old)
			*ret++ = *old++;
	*(ret + n) = 0;
	free(old - (ret - bak));
	while (n--)
		*(ret + n) = buf[n];
	return (bak);
}
Exemple #18
0
Fichier : exe1.c Projet : Geovo/iCu
void expand(char s1[], char s2[]) {
	int i, len, j = 0;
	len = lenstr(s1);
	char rule[10]; // here we'll store our 'path'
	
	for (i = 0; i < len; i++) {
		if (s1[i] != '-')
			rule[j++] = s1[i];
	}
	rule[j] = '\0';

	char a;
	int b = 0;
	for (i = 0; rule[i] != '\0'; i++)
		for (a = rule[i]; a < rule[i+1]; a++)
			s2[b++] = a;
	
	s2[b++] = a; // set the last character

	s2[b] = '\0';
}
Exemple #19
0
int		identifycolle(char *str)
{
	char topr;
	char topl;
	char botr;

	topl = str[0];
	topr = str[lenx(str) - 1];
	botr = str[lenstr(str) - 2];
	if (topr == topl)
	{
		if (topl == botr)
		{
			return (0);
		}
		else
		{
			return (2);
		}
	}
	else
	{
		if (topl == botr)
		{
			if (topl == '/')
			{
				return (1);
			}
			if (topl == 'A')
			{
				return (4);
			}
		}
		else
		{
			return (3);
		}
	}
	return (00);
}
static char		*get_next_nl(char **str)
{
	int		pos;
	int		len;
	char	*ret;
	char	*bak;

	if ((pos = find_nl(*str)) == -1)
		return (NULL);
	if (!(ret = (char *)malloc((pos + 1) * sizeof(*ret))))
		return (NULL);
	bak = ret;
	while ((ret - bak) < pos)
		*ret++ = *((*str)++);
	*ret = 0;
	if (!(ret = (char *)malloc(((len = lenstr(*str)) + 1) * sizeof(*ret))))
		return (NULL);
	while (**str)
		*ret++ = *(++(*str));
	free(*str - len - pos);
	*str = ret - len;
	return (bak);
}
Exemple #21
0
 String(const char * in){
     this->char_pointer = in;
     this->len = lenstr(in);
 }
Exemple #22
0
void output_bin(char *fileName, unsigned char *t1)
{
	FILE *f = fopen(fileName,"wb");
	fwrite(t1,sizeof(unsigned char),lenstr(t1),f);
	fclose(f);
}
Exemple #23
0
/*=========================MOD=============================*/
unsigned char* mod(unsigned char *t1, unsigned char *t2)
{
	int len1 = lenstr(t1);
	int len2 = lenstr(t2);
	int i = 0, len;
	unsigned char* res = (unsigned char*)malloc(sizeof(unsigned char)*(len1+len2+zapas));
	res[0] = '0';
	res[1] = '\0';
	unsigned char* a = t1;
	unsigned char *tempB, *tempRes, *tempRes2 = (unsigned char*)malloc(sizeof(unsigned char)*(len1+len2+zapas));
	
	unsigned char* c = copy(t2);
	check(a);
	check(c);

	if(greater(c,a)) return "0";
	else
	{
		i = 1;
		while(greater(a,c) || equal(a,c))
		{
			
			len1 = lenstr(a);
			len2 = lenstr(c);
			len = len1 - len2 -i;
			unsigned char *b = copy(c);
			check(b);
			tempRes2[0] = '1';
			tempRes2[1] = '\0';
			while(len > 0)
			{
				b = mulN(b,osn);
				tempRes2 = mulN(tempRes2,osn);
				len--;
			}
			res = add(res,tempRes2);
			tempB = copy(b);
			check(tempB);
			while(greater(a,b) || equal(a,b))
			{
				b = add(b,tempB);
				res = add(res,tempRes2);
				check(b);
			}
			b = sub(b,tempB);
			res = sub(res,tempRes2);
			
			if(greater(b,a))
			{
				i++;
			}
			else
			{
				a = sub(a,b);
				i = 1;
			}
		}
	}

	a = cutzero(a);
	check(a);
	return a;
}
Exemple #24
0
/*=========================ADD=============================*/
unsigned char* add(unsigned char *t1, unsigned char *t2)
{
	int i,temp;
	int r = 0;
	unsigned char *a, *b, *c, *t;
	int lenA, lenB;
	if(lenstr(t1) != lenstr(t2))
	{
		if(lenstr(t1) > lenstr(t2))
		{
			a = t1;
			lenA = lenstr(t1);
			b = (unsigned char*)malloc(sizeof(unsigned char)*(lenA+zapas));
			a[lenA] = '\0';
			i = 0;
			while(i < lenstr(t2))
			{
				b[i] = t2[i];
				i++;
			}
			b[i] = '\0';
			i = lenstr(t2);
			while(i < lenstr(t1))
			{
				b[i] = '0';
				i++;
			}

			b[i] = '\0';
		}
		else
		{
			a = t2;
			lenA = lenstr(a);
			b = (unsigned char*)malloc(sizeof(unsigned char)*(lenA+zapas));
			a[lenA] = '\0';
			i = 0;
			while(i < lenstr(t1))
			{
				b[i] = t1[i];
				i++;
			}
			b[i] = '\0';
			i = lenstr(t1);
			while(i < lenstr(t2))
			{
				b[i] = '0';
				i++;
			}

			b[i] = '\0';
		}
	}
	else
	{
		a = t1;
		b = t2;
	}

	lenA = lenstr(a);
	c = (unsigned char*)malloc(sizeof(unsigned char)*((lenA+zapas)));
	c[lenA+1] = '\0';
	

	check(a);
	check(b);
	check(c);
	i = 0;
	while(i < lenA+1)
	{
		c[i] = '0';
		i++;
	}
		
	i = 0;
	while(i < lenstr(a))
	{
		temp = a[i] + b[i] + r - dop;
		if (temp >= dop + osn)
				{
					temp-=osn;
					r = 1;
				}
				else
					r = 0;
		c[i] = temp;
		i++;
	}
	if(r) c[i] += r;

	
	check(c);
	c = cutzero(c);
	return c;
}