Esempio n. 1
0
File: code.cpp Progetto: samrrr/Labs
//заполнение информационных полей узла данными из считанной строки
NODE* read_to_node(char*str)
{
	NODE* tmp = (NODE*)malloc(sizeof(NODE));
	tmp->data = (DATA*)malloc(sizeof(NODE));

	char* artist = NULL; //исполнитель
	char* album = NULL; //альбом
	int year = NULL; //год
	float price; //цена

	int i = 0; //индекс строки

	artist = str_read(str, &i); //здесь в общем возвращает строку из ячейки исполнитель
	if (artist)
	{
		tmp->data->artist = copy_string(artist); //присваивание полученного значения исполнителя

		album = str_read(str, &i); //здесь возвращает строку из ячейки альбом (дольше все по аналогии)
		if (album)
		{
			tmp->data->album = copy_string(album);

			year = atoi(str_read(str, &i)); //получает год
			if (year)
			{
				if (year < MIN_YEAR || year > MAX_YEAR)
					tmp->data->year = 0;
				else
					tmp->data->year = year;
			}
			else
				tmp->data->year = 0;

			price = strtof(str_read(str, &i), '\0'); //получает цену
			if (price)
			{
				if (price < MIN_PRICE || price > MAX_PRICE)
				{
					float f = 0.0;
					tmp->data->price = f;
				}
				else
					tmp->data->price = price;

				return tmp; //и если все поля заполнены без критических ошибок возвращает узел
			}
			else
				return NULL;
		}
		else
			return NULL;
	}
	else
		return NULL;
}
Esempio n. 2
0
void nahraj_texturu_fc(FFILE f, EDIT_MATERIAL * p_mat, EDIT_TEXT * p_text,
  int max, int cislo_text, int save)
{
  OLD_MULTITEXT_FLAG mt;
  char string[100];
  int t;

  if (lo_je_tag(f, TEXT_TAG)) {
    str_read(string, f);
    strlwr(string);
    if (!strcmp(string, S_NIC)) {
      p_mat->p_text[cislo_text] = NULL;
      p_mat->textfile[cislo_text][0] = 0;
    }
    else {
      if (save) {
        if ((t = lo_najdi_texturu(p_text, max, string, FALSE)) == K_CHYBA) {
          if ((t = lo_najdi_volnou_texturu(p_text, max)) == K_CHYBA)
            chyba("Textury");
          strcpy(p_text[t].jmeno, string);
        }
        p_mat->p_text[cislo_text] = p_text + t;
        strcpy(p_mat->textfile[cislo_text], string);
      }
    }
  }
  if (lo_je_tag(f, MULTI_TAG))
    ffread(&mt, sizeof(mt), 1, f);
}
Esempio n. 3
0
// Purpose: Compresses a string read from input using a hashtable H to store
//          recurring words
// Pre:     The Hashtable H must be empty, with no pre-set elements
//				Otherwise the hashtable may contain keys/values that do not match
//				up with the text read from input
//			The First line of input must contain an integer value >=1 for the size of the hash table
//			Input should not contain any digits after the first line, and should not
//				include words with punctuation inside of them (such as can't and it's)
// Post:    Prints the compressed version of the read string to standard output
void text_compress(struct hashtable *H){
	char inch = peekchar();
	int wordctr = 0;	
	
	//Continues to read until the EOF is found
	while ( inch != EOF ) {
		if (inch == '\n') {								//If the gotten character is \n, print \n
			printf("\n");
			inch = getchar();
		}
		else if (isspace(inch) || ispunct(inch)) {		//If its a space or punctuation, 
			printf("%c", inch);							//then just print the char again
			inch = getchar();
		}
		else {											//Otherwise first read the string from input
			char *newword = str_read();					//Then if the word is already in the hashtable,
			if (htContains(H, newword)) {				//print the according value then free the read word
				printf("%d", htGetValue(H, newword));
				free(newword);
			}
			else {										//Otherwise add the value to the hashtable
				htAddValue(H, newword, wordctr);		//And print it
				printf("%s", newword);
				wordctr++;
				free(newword);
			}
		}
		inch = peekchar();
	}
}
Esempio n. 4
0
// Purpose: Decompresses text read from standard input to readable text
// Pre: Each integer value in input must correspond to a valid word
//			ie. Each integer in input must be less than 
//			the number of words before the integer
//		The first token of input cannot be an integer
// Post: The readable, decompressed version of the text read from input
//		 is printed out to standard output
void text_decompress() {
	
	//Creates a new array of pointer to chars to hold the strings
	char **strdict = malloc(sizeof(char*));	
	strdict[0] = NULL;
	
	char inch = peekchar();
	int wordctr = 0;
	
	//Loops while the current character being worked on is not EOF
	while ( inch != EOF ) {
		if (inch == '\n') {					//If the gotten character is \n, print \n
			printf("\n");
			inch = getchar();
		}
		else if (isspace(inch) || ispunct(inch)) {		//If its a space or punctuation, 
			printf("%c", inch);							//then just print the char again
			inch = getchar();
		}	
		else if ( isalpha(inch) ) {				//If the character is an alpha char
			char *newword = str_read();			//Read the full word
			strdict[wordctr] = newword;			//Add it to the dictionary
			wordctr++;							//Increment the number of words
			
			//Increase the memory size of strdict by one (since wordctr is increased by one)
			strdict = realloc(strdict, sizeof(char*) * (wordctr+1));	
			printf("%s", newword);					//Print the word
		} else {
			char *newword = str_read();				//Otherwise the word is a digit
			printf("%s", strdict[atoi(newword)]);	//Pass the converted integer version
			free(newword);							//Of the read word and print the 
		}											//string located at that index, then free the word
		inch = peekchar();	//peeks at the next character for usage in the next lop
	}
	
	//Frees the new array
	for (int i=0; i<wordctr; i++) {
		free(strdict[i]);
	}
	free(strdict);
	
}
Esempio n. 5
0
int lo_nahraj_objekty_out(EDIT_MATERIAL ** p_mat, int max_mat, FFILE f,
  EDIT_KONTEJNER * p_kont, int mat)
{
  char string[50];
  int i, j, k;
  word r1;

  for (i = 0; i < p_kont->max_objektu; i++) {
    if (!lo_je_tag(f, "JMOB"))
      break;
    else
      str_read(string, f);

    if (!lo_je_tag(f, "TMSH"))
      continue;                 //je to objekt ale neni to mes

    if ((p_kont->p_obj[i] = lo_nacti_vec_FILE_out(f)) == NULL)
      chyba("Nacitani objektu...");

    strcpy(p_kont->p_obj[i]->jmeno, string);

    for (k = 0; k < 2; k++) {
      //nactenej jeden objekt - pricist jeste material
      if (!lo_je_tag(f, "FMAT")) {
        break;                  // neni material - na dalsi objekt
      }
      else
        str_read(string, f);

      if (mat) {
        if (!k) {
          if (!strcasecmp(string, S_NIC)) {
            p_kont->p_obj[i]->material = 0;
            p_kont->p_obj[i]->m1flag = 0;
            p_kont->p_obj[i]->m2flag = 0;
            p_kont->p_obj[i]->oflag = 0;
          }
          else {
            for (j = 0; j < max_mat; j++) {
              if (p_mat[j] && !strcasecmp(string, p_mat[j]->jmeno)) {
                p_kont->p_obj[i]->material = (word) j;
                p_kont->p_obj[i]->m1flag = p_mat[j]->flag;
                p_kont->p_obj[i]->m2flag = p_mat[j]->flag2;
                break;
              }
            }
            if (j == max_mat) {
              ddw("Neznamy material '%s' v objektu '%s'", string,
                p_kont->p_obj[i]->jmeno);
              p_kont->p_obj[i]->material = 0;
              p_kont->p_obj[i]->m1flag = 0;
              p_kont->p_obj[i]->m2flag = 0;
            }
          }
        }
      }
      else {
        p_kont->p_obj[i]->material = 0;
        p_kont->p_obj[i]->m1flag = 0;
        p_kont->p_obj[i]->m2flag = 0;
      }
    }
    if (lo_je_tag(f, "RECT")) { // sou tam recy
      ffread(&r1, sizeof(word), 1, f);
      ffread(&r1, sizeof(word), 1, f);
    }
  }
  return (i);
}
Esempio n. 6
0
EDIT_MATERIAL *lo_nahraj_material_out(FFILE f, EDIT_TEXT * p_text, int max,
  int save)
{
  EDIT_MATERIAL *p_mat;
  MATERIAL *p_dxmat;
  OLD_MULTITEXT_FLAG mt;
  char string[50];
  dword tmp;

  if (!lo_je_tag(f, MTRL_TAG))
    return (NULL);
  else {
    p_mat = vyrob_material();
    str_read(p_mat->jmeno, f);
  }
  ffread(string, sizeof(char), 9, f);

  // nacteni grb
  if (save) {
    p_dxmat = &p_mat->dxmat;
    p_dxmat->ambient_r = (float) string[0] / MAX_BYTE;
    p_dxmat->ambient_g = (float) string[1] / MAX_BYTE;
    p_dxmat->ambient_b = (float) string[2] / MAX_BYTE;

    p_dxmat->diffuse_r = (string[3]) ? ((float) string[3]) / MAX_BYTE : 1.0f;
    p_dxmat->diffuse_g = (string[4]) ? ((float) string[4]) / MAX_BYTE : 1.0f;
    p_dxmat->diffuse_b = (string[5]) ? ((float) string[4]) / MAX_BYTE : 1.0f;
    p_dxmat->diffuse_a = 1.0f;

    p_dxmat->specular_r = (float) string[6] / MAX_BYTE;
    p_dxmat->specular_g = (float) string[7] / MAX_BYTE;
    p_dxmat->specular_b = (float) string[8] / MAX_BYTE;

    p_dxmat->faktor_r = 1.0f;
    p_dxmat->faktor_g = 1.0f;
    p_dxmat->faktor_b = 1.0f;
    p_dxmat->faktor_a = 1.0f;
  }

  // nacte soubor s animacema
  if (lo_je_tag(f, MATANIM_TAG)) {
    str_read(p_mat->anim.jmeno, f);
    //lo_vyrob_animaci_list(p_mat,p_mat->anim.jmeno,p_text,max,ANIM_LOAD_ALL);
  }

  // nacte alfa tag
  if (lo_je_tag(f, FAKTOR_TAG)) {
    ffread(&tmp, sizeof(dword), 1, f);
  }

  // Nacte stage blok
  if (lo_je_tag(f, STAG_TAG)) {
    ffread(string, sizeof(char), 1, f);

    ffread(&tmp, sizeof(dword), 1, f);
    ffread(&tmp, sizeof(dword), 1, f);

    p_mat->alfa_state = 0;
    p_mat->text_state[0].text_stage = 0;
    p_mat->text_state[1].text_stage = 0;
  }

  // nacteni nuloveho blendu
  if (lo_je_tag(f, MULTI_TAG))
    ffread(&mt, sizeof(mt), 1, f);

  nahraj_texturu_fc(f, p_mat, p_text, max, 0, save);
  nahraj_texturu_fc(f, p_mat, p_text, max, 1, save);
  nahraj_texturu_fc(f, p_mat, p_text, max, 1, save);

  strlwr(p_mat->jmeno);

  if (save)
    return (p_mat);
  else {
    zrus_material(&p_mat);
    return ((EDIT_MATERIAL *) 1);
  }
}