コード例 #1
0
ファイル: Poem.cpp プロジェクト: vova98/Isengreem
int mlStrcmp(char* string1, char* string2)
{
	int i = 0, j = 0;

	if (string1 || string2)
		Nerror = STRERR;
	assert(string1 && string2);
	if (!string1 || !string2) perror("String is fault\n");

	while (string1[i] != '\r' && string2[j] != '\r')
	{
		while (IsPunct(string1, i))
			i++;
		while (IsPunct(string2, j))
			j++;
		if (!IsPunct(string1, i) && !IsPunct(string2, j))
		{
			assert(string1[i] && string2[j]);
			if (string1[i] || string2[j])
				Nerror = STRPOSERR;
			if (!string1[i] || !string2[j]) perror("Symbol is fault\n");
			if (string1[i] == string2[j])
			{
				i++;
				j++;
			}
			else return (string1[i] > string2[j]) ? 1 : (string1[i] < string2[j]) ? -1 : 0;
		}
	}
	ErrPrint(Nerror);
	return 0;
}
コード例 #2
0
ファイル: Poem.cpp プロジェクト: vova98/Isengreem
int mlStrcmpEnd(Text_t string1, Text_t string2)
{
	int i = 0;

	assert(string1.StringPos && string2.StringPos);
	if (!string1.StringPos || !string2.StringPos)
		Nerror = STRPOSERR;
	//perror("String is fault\n");

	i = 1;
	int j = 1;

	if (string2.StringPos[string2.lenghtString] >= 'A' && string2.StringPos[string2.lenghtString] <= 'Z' && string1.StringPos[string1.lenghtString] >= 'A' && string1.StringPos[string1.lenghtString] <= 'Z')
		return 0;
	else while (string1.lenghtString - i + 1 >= 0 && string2.lenghtString - j + 1 >= 0)
	{
		while (IsPunct(string1.StringPos, string1.lenghtString + 1 - i))
			i++;
		while (IsPunct(string2.StringPos, string2.lenghtString + 1 - j))
			j++;
		if (!IsPunct(string1.StringPos, string1.lenghtString + 1 - i) && !IsPunct(string2.StringPos, string2.lenghtString + 1 - j))
		{
			if (string1.StringPos[string1.lenghtString + 1 - i] == string2.StringPos[string2.lenghtString + 1 - j])
			{
				i++;
				j++;
			}
			return string1.StringPos[string1.lenghtString + 1 - i] > string2.StringPos[string2.lenghtString + 1 - j] ? 1 : string1.StringPos[string1.lenghtString + 1 - i] < string2.StringPos[string2.lenghtString + 1 - j] ? -1 : 0;
		}
	}
	ErrPrint(Nerror);
	return 0;
}
コード例 #3
0
ファイル: Poem.cpp プロジェクト: vova98/Isengreem
void printStr(FILE* fout, char* string)
{
	int num = 0;
	bool is_text = false;

	for (int i = 0; string[i] != '\r'; i++)
	if (!IsPunct(string, i))
		is_text = true;

	if (is_text)
	while (string[num] != '\0')
	{

		assert(string[num]);
		if (!string[num])
			Nerror = STRPOSERR;
		if (string[num] != '\r')
		{
			fprintf(fout, "%c", string[num]);
			num += 1;
		}
		else if (string[num]>0 && string[num] < 255)
		{
			fprintf(fout, "\n");
			break;
		}
		else
		{
			printf("What the %*&#!?");
		}
	}
}
コード例 #4
0
ファイル: stdafx.cpp プロジェクト: vova98/Isengreem
void printStr(FILE* fout, char* string)
{
	int k = 0;
	bool is_text = false;
	
	for (int i = 0; string[i] != '\r'; i++)
	if (!IsPunct(string, i)) 
		is_text = true;

	if (is_text)
	while (string[k] != '\0')
	{

		assert(string[k]);
		if (string[k] != '\r')
		{
			fprintf(fout, "%c", string[k]);
			k += 1;
		}
		else if (string[k]>0 && string[k] < 255)
		{
			fprintf(fout, "\n");
			break;
		}
		else
		{
			printf("What the F**k!?");
		}
	}
}
コード例 #5
0
ファイル: stdafx.cpp プロジェクト: vova98/Isengreem
int mlStrcmpEnd(char* string1, char* string2)
{
	int i = 0, lengthStr1 = 0, lengthStr2 = 0;

	assert(string1 && string2);

	while (string1[i] != '\r')
		i++;

	int j = 0;
	while (string2[j] != '\r' )
		j++;

	lengthStr1 = i;
	lengthStr2 = j;
	
	i = 1;
	j = 1;

	if (string2[lengthStr2 - 1] >= 'A' && string2[lengthStr2 - 1] <= 'Z' && string1[lengthStr1 - 1] >= 'A' && string1[lengthStr1 - 1] <= 'Z')
		return 0;
	else while (lengthStr1 - i >= 0 && lengthStr2 - j >= 0)
	{
		while (IsPunct(string1, lengthStr1 - i))
			i++;
		while (IsPunct(string2, lengthStr2 - j))
			j++;
		if (!IsPunct(string1, lengthStr1 - i) && !IsPunct(string2, lengthStr2 - j))
		{
			if (string1[lengthStr1 - i] == string2[lengthStr2 - j])
			{
				i++;
				j++;
			}
			return string1[lengthStr1 - i] > string2[lengthStr2 - j] ? 1 : string1[lengthStr1 - i] < string2[lengthStr2 - j] ? -1 : 0;
		}
	}
	return 0;
}
コード例 #6
0
ファイル: HashTable.cpp プロジェクト: vova98/Isengreem
char* takeWord(const char* buffer, int* j, char* tmpStr)
{
	int k = 0;
	
	while (buffer[*j] != ' ' && buffer[*j] > 0)
	{
		while (IsPunct((char*)buffer, *j))
		(*j)++;
		tmpStr[k++] = buffer[(*j)++];
	}
	
	strstr(buffer, " ");
	return tmpStr;
}
コード例 #7
0
ファイル: stdafx.cpp プロジェクト: vova98/Isengreem
int mlStrcmp(char* string1, char* string2)
{
	int i = 0, j = 0;

	assert(string1 && string2);

	while (string1[i] != '\r' && string2[j] != '\r')
	{
		while (IsPunct(string1, i))
			i++;
		while (IsPunct(string2, j))
			j++;
		if (!IsPunct(string1, i) && !IsPunct(string2, j))
		{
			assert(string1[i] && string2[j]);
			if (string1[i] == string2[j])
			{
				i++;
				j++;
			}
			else return (string1[i] > string2[j]) ? 1 : (string1[i] < string2[j]) ? -1 : 0;
		}
	} 
}
コード例 #8
0
ファイル: mktable.c プロジェクト: AndyA/re--engine--Oniguruma
static int exec(FILE* fp, ENC_INFO* einfo)
{
#define NCOL  8

  int c, val, enc;

  enc = einfo->num;

  fprintf(fp, "static const unsigned short Enc%s_CtypeTable[256] = {\n",
	  einfo->name);

  for (c = 0; c < 256; c++) {
    val = 0;
    if (IsNewline(enc, c))  val |= BIT_CTYPE_NEWLINE;
    if (IsAlpha (enc, c))   val |= (BIT_CTYPE_ALPHA | BIT_CTYPE_ALNUM);
    if (IsBlank (enc, c))   val |= BIT_CTYPE_BLANK;
    if (IsCntrl (enc, c))   val |= BIT_CTYPE_CNTRL;
    if (IsDigit (enc, c))   val |= (BIT_CTYPE_DIGIT | BIT_CTYPE_ALNUM);
    if (IsGraph (enc, c))   val |= BIT_CTYPE_GRAPH;
    if (IsLower (enc, c))   val |= BIT_CTYPE_LOWER;
    if (IsPrint (enc, c))   val |= BIT_CTYPE_PRINT;
    if (IsPunct (enc, c))   val |= BIT_CTYPE_PUNCT;
    if (IsSpace (enc, c))   val |= BIT_CTYPE_SPACE;
    if (IsUpper (enc, c))   val |= BIT_CTYPE_UPPER;
    if (IsXDigit(enc, c))   val |= BIT_CTYPE_XDIGIT;
    if (IsWord  (enc, c))   val |= BIT_CTYPE_WORD;
    if (IsAscii (enc, c))   val |= BIT_CTYPE_ASCII;

    if (c % NCOL == 0) fputs("  ", fp);
    fprintf(fp, "0x%04x", val);
    if (c != 255) fputs(",", fp);
    if (c != 0 && c % NCOL == (NCOL-1))
      fputs("\n", fp);
    else
      fputs(" ", fp);
  }
  fprintf(fp, "};\n");
  return 0;
}
コード例 #9
0
bool SimpleParser::Read()
{
  int c;
  int mode=0;  //0 whitespace/idle, 1 comment, 2 token, 3 punct
  string str;
  while((c=in.peek()) != EOF) {
    if(!in) {
      cerr<<"Error while reading characters!"<<endl;
      return false;
    }
    switch(mode) {
    case 0:
      if(IsSpace(c)) {  //continue
      }
      else if(IsComment(c)) mode=1;
      else if(IsToken(c)) { str+=c; mode=2;  }
      else if(IsPunct(c)) { str+=c; mode=3; }
      else {
	cerr<<"Illegal character "<<(char)c<<endl;
	return false;
      }
      break;
    case 1:   //comment
      if(c=='\n') 
	mode=0;
      break;
    case 2:    //reading tokens
      if(IsToken(c)) {str+=c;}
      else {
	Result res=InputToken(str);
	if(res == Stop) return true;
	else if(res == Error) {
	  cerr<<"Error on token "<<str.c_str()<<endl;
	  return false;
	}
	str.erase();
	if(c == '\n') {
	  Result res=InputEndLine();
	  if(res==Stop) return true;
	  else if(res == Error) {
	    cerr<<"Error on endline at line "<<lineno<<endl;
	    return false;
	  }
	  lineno++;
	  mode=0;
	}
	else if(IsSpace(c)) mode=0;
	else if(IsComment(c)) mode=1;
	else if(IsPunct(c)) { str+=c; mode=3;	}
	else {
	  cerr<<"Illegal character "<<(char)c<<endl;
	  return false;
	}
      }
      break;
    case 3:
      if(IsPunct(c)) {str+=c;}
      else {
	Result res=InputPunct(str);
	if(res == Stop) return true;
	else if(res == Error) {
	  cerr<<"Error on token "<<str.c_str()<<endl;
	  return false;
	}
	str.erase();
	if(IsSpace(c)) mode=0;
	else if(IsComment(c)) mode=1;
	else if(IsToken(c)) { str+=c; mode=2; }
	else {
	  cerr<<"Illegal character "<<(char)c<<endl;
	  return false;
	}
      }
      break;
    }
    if(c == '\n') {
      Result res=InputEndLine();
      if(res==Stop) return true;
      else if(res == Error) {
	cerr<<"Error on endline at line "<<lineno<<endl;
	return false;
      }
      lineno++;
    }
    c = in.get();
  }
  if(!str.empty()) {
    Result res=InputToken(str);
    if(res == Stop) return true;
    else if(res == Error) {
      cerr<<"Error on token "<<str.c_str()<<endl;
      return false;
    }
    else {
      cerr<<"Incomplete read at EOF, string "<<str.c_str()<<endl;
      return false;
    }
  }
  in.get();
  assert(!in);
  return true;
}