Esempio n. 1
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. 2
0
int main()
{
	prvek *p;
	seznam S;
	for(int i = 0; i < 5; i++)
		if(!(S.vlozNaKonec(i))) chyba();
	cout << ((S.najdi(3,p)) ? "Je tam" : "neni") << endl;
	
	S.vyjmi(2);
}
Esempio n. 3
0
/**funkce na zavirani souboru**/
void zav_sou(void)
{
    if((fclose(soubor)) == EOF)
    {
        chyba(CHYBA_ZAV_SOU);
        mazani_pameti();
        mazani_sem();

    }
}
Esempio n. 4
0
/**funkce na vytvoreni sdilene pameti**/
void sdilena_pamet(void)
{
/********************cislo ulohy***************/
    if((cislo_ulohy = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0666)) == -1)
    {
        chyba(SDILENA_PAMET);
    }

    if((p_cislo_ulohy = (int *)shmat(cislo_ulohy, NULL, 0)) == (void *) -1)
    {
        chyba(SDILENA_PAMET);
    }
    *p_cislo_ulohy=0;

/*************skritci na dovolene****************/
    if((dovolena_elf = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0666)) == -1)
    {
        chyba(SDILENA_PAMET);
    }

    if((p_dovolena_elf = (int *)shmat(dovolena_elf, NULL, 0)) == (void *) -1)
    {
        mazani_pameti();
        chyba(SDILENA_PAMET);
    }
    *p_dovolena_elf=0;

/*******aktivni skritci*****/
    if((aktivni_skritci = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0666)) == -1)
    {
        chyba(SDILENA_PAMET);
    }

    if((p_aktivni_skritci = (int *)shmat(aktivni_skritci, NULL, 0)) == (void *) -1)
    {
        mazani_pameti();
        chyba(SDILENA_PAMET);
    }
    *p_aktivni_skritci=0;
/******oblsuhujici skritci*****/
     if((obsluhujici_skritci = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0666)) == -1)
    {
        chyba(SDILENA_PAMET);
    }

    if((p_obsluhujici_skritci = (int *)shmat(obsluhujici_skritci, NULL, 0)) == (void *) -1)
    {
        mazani_pameti();
        chyba(SDILENA_PAMET);
    }
    *p_obsluhujici_skritci=0;

}
Esempio n. 5
0
/**funkce mazani sdilene pameti**/
void mazani_pameti(void)
{
    shmdt(p_cislo_ulohy);
    shmdt(p_dovolena_elf);
    shmdt(p_aktivni_skritci);
    shmdt(p_obsluhujici_skritci);
    if((shmctl(cislo_ulohy, IPC_RMID, NULL)) == -1)
    {
        chyba(CHYBA_MAZ_PAM);
    }
    if((shmctl(dovolena_elf, IPC_RMID, NULL)) == -1)
    {
        chyba(CHYBA_MAZ_PAM);
    }
    if((shmctl(aktivni_skritci, IPC_RMID, NULL)) == -1)
    {
        chyba(CHYBA_MAZ_PAM);
    }
    if((shmctl(obsluhujici_skritci, IPC_RMID, NULL)) == -1)
    {
        chyba(CHYBA_MAZ_PAM);
    }

}
Esempio n. 6
0
int lo_nacti_facelist_out(FFILE f, FACE ** p_face)
{
  GENERIC_HEAD head;
  long t = fftell(f);


  if (*p_face != NULL)
    return ((int) NULL);

  if (!ffread(&head, sizeof(head), 1, f)) {
    ffseek(f, t, SEEK_SET);
    return ((int) NULL);
  }

  if ((head.h[0] != 'F') ||
    (head.h[1] != 'F') || (head.h[2] != 'F') || (head.h[3] != 'F')) {
    ffseek(f, t, SEEK_SET);
    return ((int) NULL);
  }

  head.pocet *= 3;
  if (!head.pocet)
    chyba("load facelist -> 0 facu !");

  if ((*p_face = (FACE *) mmalloc(sizeof(FACE) * head.pocet)) == NULL) {
    chyba("Nedostatek pameti...");
  }

  if (!ffread(*p_face, sizeof(FACE), head.pocet, f)) {
    null_free((void **) p_face);
    ffseek(f, t, SEEK_SET);
    return ((int) NULL);
  }

  return (head.pocet);
}
Esempio n. 7
0
int lo_nacti_vertexlist_out(FFILE f, OBJEKT_BOD ** p_vert)
{
  GENERIC_HEAD head;
  long t = fftell(f);
  float v[3];
  int i;

  if (*p_vert != NULL) {
    return ((int) NULL);
  }

  if (!ffread(&head, sizeof(head), 1, f)) {
    ffseek(f, t, SEEK_SET);
    return ((int) NULL);
  }

  if ((head.h[0] != 'V') ||
    (head.h[1] != 'V') || (head.h[2] != 'V') || (head.h[3] != 'V')) {
    ffseek(f, t, SEEK_SET);
    return ((int) NULL);
  }

  if ((*p_vert =
      (OBJEKT_BOD *) mmalloc(sizeof(OBJEKT_BOD) * head.pocet)) == NULL) {
    chyba("Nedostatek pameti...");
  }

  memset(*p_vert, 0, sizeof(OBJEKT_BOD) * head.pocet);

  for (i = 0; i < head.pocet; i++) {
    if (!ffread(&v, sizeof(v), 1, f)) {
      ffseek(f, t, SEEK_SET);
      null_free((void **) p_vert);
      return ((int) NULL);
    }
    (*p_vert)[i].x = v[0];
    (*p_vert)[i].y = v[1];
    (*p_vert)[i].z = v[2];
    (*p_vert)[i].dr = (*p_vert)[i].dg = (*p_vert)[i].db = 1.0f;
  }

  return (head.pocet);
}
Esempio n. 8
0
/**funkce pro mazani semaforu**/
void mazani_sem(void)
{
    if((sem_destroy(s_santa)) == -1)
    {
        chyba(CHYBA_MAZ_SEM);
    }
    if((sem_destroy(s_elf)) == -1)
    {
        chyba(CHYBA_MAZ_SEM);
    }
    if((sem_destroy(s_zapis)) == -1)
    {
        mazani_pameti();
        mazani_sem();
        chyba(CHYBA_VYTV_SEM);
    }

    if((sem_destroy(s_santa_end)) == -1)
    {
        mazani_pameti();
        mazani_sem();
        chyba(CHYBA_VYTV_SEM);
    }
    if((sem_destroy(s_pomoc_elf)) == -1)
    {
        mazani_pameti();
        mazani_sem();
        chyba(CHYBA_VYTV_SEM);
    }
    if((sem_destroy(s_cekarna)) == -1)
    {
        mazani_pameti();
        mazani_sem();
        chyba(CHYBA_VYTV_SEM);
    }

    if((sem_destroy(s_sdilena)) == -1)
    {
        mazani_pameti();
        mazani_sem();
        chyba(CHYBA_VYTV_SEM);
    }
}
int main(void)
{
  int i, j;

  printf("Zacatek programu\n");

  if (setjmp(hlavni_smycka) != 0)
    printf("Restart po chybe ...\n");

  while (1) {
    printf("Zadej dve cisla (0 0 = konec): ");
    scanf("%d %d", &i, &j);
    if (i == 0)
      break;
    if (j != 0)
      printf("%d / %d = %d\n", i, j, i / j);
    else
      chyba();
  }
  return 0;
}
Esempio n. 10
0
int lo_nahraj_materialy_out(EDIT_MATERIAL ** p_mat, int max_mat,
  EDIT_TEXT * p_text, int max_text, FFILE f, int save)
{
  EDIT_MATERIAL *p_tmp;
  int i = 0;
  int m = 0, 
      nm;

  while (1) {
    if (save) {
      if ((m = lo_najdi_prazdny_material(p_mat, max_mat)) == K_CHYBA)
        chyba("Malo materialu!");
    }
    p_tmp = lo_nahraj_material_out(f, p_text, max_text, save);
    if (!p_tmp) {
      break;
    }
    if (save) {
      if ((nm = lo_najdi_material(p_mat, max_mat, p_tmp->jmeno)) == K_CHYBA)
        p_mat[m] = p_tmp;
      else {
        /* Nahravany material byl nalezen na pozici nm
         */
        if (hlasit_kolize) {
          ddw("Kolize materialu - krizi se materialy %d \"%s\" a %d \"%s\"!",
            m, p_tmp->jmeno, nm, p_mat[nm]->jmeno);
          //p_mat[nm] - puvodni material
          //doe_cti_jmeno(NULL,p_mat[nm]->jmeno);
          //}
        }
        zrus_material(&p_tmp);
      }
    }
    i++;
  }
  return (i);
}
Esempio n. 11
0
/**hlavni funkce main**/
int main(int argc, char *argv[])
{
    if((soubor=fopen("santa.out", "w")) == NULL)
    {
        chyba(CHYBA_OTEV_SOU);
        return 2;
    }

    if((argc==2) && (strcmp("--help", argv[1]) == 0))
    {
        napoveda();
        return 0;
    }

/**volani argumentu**/
    arg(argc, argv);
    tmp_elf = cislo_elfa;

 /**********volani vytvoreni sdilene pameti******************/
    sdilena_pamet();
/***********volani vytvoreni semafaoru*****/
    semafory();

/********vytvoreni santy a elfu********/


    for(int i=0; i < tmp_elf + 1; i++)
	{
		switch(fork())
		{
			case 0: //dite
				if(i==0) // prvni dite == santa
				{
					santa();
					return 0;
				}
				else       // ostatni jsou elfove
				{
					elf_id=i;
					elf();
					return 0;
				}
				break;

			case -1:
				chyba(CHYBA_FORK);
				mazani_sem();
				mazani_pameti();
				return 2;
				break;

			default: //rodic

				break;
		}
	}

    for(int i = 0; i < tmp_elf + 1; i++)
    {
        wait(NULL);
    }
    mazani_sem();
    mazani_pameti();
    zav_sou();
    return 0;
}
Esempio n. 12
0
/**funkce pro kontrolu argumentu**/
void arg(int argc, char *argv[])
{
    char *spatny_arg;

    if(argc != 5 )
    {
        chyba(CHYBA_PARAM);
    }

    else
    {   // pocet navstev skritka u santy
        if(isdigit(*argv[1]))
        {
            navsteva=strtol(argv[1], &spatny_arg, 10);
            if(spatny_arg == argv[1] || *spatny_arg !='\0' || navsteva <= 0)
            {
                chyba(CHYBA_PARAM);
            }
        }
        else
        {
            chyba(CHYBA_PARAM);
        }
        // pocet skritku kteri na zacatku pracuji na vyrobe hracek
        if(isdigit(*argv[2]))
        {
            cislo_elfa=strtol(argv[2], &spatny_arg, 10);
            if(spatny_arg == argv[2] || *spatny_arg !='\0' || cislo_elfa <= 0)
            {
                chyba(CHYBA_PARAM);
            }
        }
        else
        {
            chyba(CHYBA_PARAM);
        }
        // max doba(v milisekundach) vyroby hracek skritkem
        if(isdigit(*argv[3]))
        {
            vyroba=strtol(argv[3], &spatny_arg, 10);
            if(spatny_arg == argv[3] || *spatny_arg !='\0' || vyroba < 0)
            {
                chyba(CHYBA_PARAM);
            }
        }
        else
        {
            chyba(CHYBA_PARAM);
        }
        // max doba(v milisekundach) obsluhy skritku santou
        if(isdigit(*argv[4]))
        {
            obsluha=strtol(argv[4], &spatny_arg, 10);
            if(spatny_arg == argv[4] || *spatny_arg !='\0' || obsluha < 0)
            {
                chyba(CHYBA_PARAM);
            }
        }
        else
        {
            chyba(CHYBA_PARAM);
        }

    }

}
Esempio n. 13
0
/**funkce na vytvoreni semaforu**/
void semafory(void)
{
    if((s_santa = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0)) == MAP_FAILED)
    {
        chyba(CHYBA_VYTV_SEM);
    }
    if((s_elf = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0)) == MAP_FAILED)
    {
        chyba(CHYBA_VYTV_SEM);
    }

    if((s_zapis = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0)) == MAP_FAILED)
    {
        chyba(CHYBA_VYTV_SEM);
    }
    if((s_santa_end = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0)) == MAP_FAILED)
    {
        chyba(CHYBA_VYTV_SEM);
    }
    if((s_pomoc_elf = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0)) == MAP_FAILED)
    {
        chyba(CHYBA_VYTV_SEM);
    }
    if((s_cekarna = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0)) == MAP_FAILED)
    {
        chyba(CHYBA_VYTV_SEM);
    }

    if((s_sdilena = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0)) == MAP_FAILED)
    {
        chyba(CHYBA_VYTV_SEM);
    }


    if((sem_init(s_santa, 1, 0)) == -1)
    {
        mazani_pameti();
        chyba(CHYBA_VYTV_SEM);
    }
    if((sem_init(s_elf, 1, 0)) == -1)
    {
        mazani_pameti();
        mazani_sem();
        chyba(CHYBA_VYTV_SEM);
    }
    if((sem_init(s_zapis, 1, 1)) == -1)
    {
        mazani_pameti();
        mazani_sem();
        chyba(CHYBA_VYTV_SEM);
    }
    if((sem_init(s_santa_end, 1, 0)) == -1)
    {
        mazani_pameti();
        mazani_sem();
        chyba(CHYBA_VYTV_SEM);
    }
    if((sem_init(s_pomoc_elf, 1, 1)) == -1)
    {
        mazani_pameti();
        mazani_sem();
        chyba(CHYBA_VYTV_SEM);
    }
    if((sem_init(s_cekarna, 1, 0)) == -1)
    {
        mazani_pameti();
        mazani_sem();
        chyba(CHYBA_VYTV_SEM);
    }
    if((sem_init(s_sdilena, 1, 1)) == -1)
    {
        mazani_pameti();
        mazani_sem();
        chyba(CHYBA_VYTV_SEM);
    }

}
Esempio n. 14
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);
}
/* **************************************************************************
  // vybrane face objektu oriznu a vyrobim jako extra objekt
  // Vyrizne oznacene facy pomoci bodu jako extra objekt daneho kontejneru
*/
void oe_prikaz_vyrizni_face(K_EDITOR * p_cnf, int crop)
{
  EDIT_OBJEKT *p_obj;
  EDIT_OBJEKT *p_new;
  int *p_vertex;
  int k, o, v, i, f, vnum, fnum;
  int *p_face, *p_delete, del = 0;

  if (!p_cnf->groupnum) {
    ddw
      ("Musi byt oznaceny face, ktery se maji vyriznout ! Pouzij klavesy F a CTRL+F na oznaceni facu pomoci bodu !");
    return;
  }

  k = p_cnf->p_group[0].k;      //pouziju nulu
  o = p_cnf->p_group[0].o;
  p_obj = p_cnf->p_kont[k]->p_obj[o];

  p_face = _alloca(sizeof(int) * p_obj->facenum);
  memset(p_face, K_CHYBA, sizeof(sizeof(int)) * p_obj->facenum);

  if (crop) {
    p_delete = _alloca(sizeof(int) * p_obj->facenum / 3);
    memset(p_delete, 0, sizeof(sizeof(int)) * p_obj->facenum / 3);
  }

  p_vertex = _alloca(sizeof(int) * p_obj->vertexnum);
  memset(p_vertex, K_CHYBA, sizeof(sizeof(int)) * p_obj->vertexnum);

  // vyberu facy ktere jsou skutecne pouzity
  for (i = 0; i < p_cnf->groupnum; i++) {
    if (p_cnf->p_group[i].k == k && p_cnf->p_group[i].o == o) {
      v = p_cnf->p_group[i].v;
      for (f = 0; f < p_obj->facenum; f++) {
        if (p_obj->p_face[f] == v)
          p_face[f] = v;
      }
    }
  }

  // skopiruju face
  fnum = 0;
  for (f = 0, i = 0; f < p_obj->facenum; f += 3) {
    if (p_face[f] != K_CHYBA && p_face[f + 1] != K_CHYBA
      && p_face[f + 2] != K_CHYBA) {
      if (crop) {
        p_delete[del++] = f;
      }
      assert(i <= f);
      if (i != f) {
        p_face[i] = p_face[f];  // setridit
        p_face[i + 1] = p_face[f + 1];
        p_face[i + 2] = p_face[f + 2];
      }
      i += 3;
    }
  }

  assert(i > 0);
  fnum = i;
  vnum = 0;
  // najdu pocet jedinecnych bodu
  for (f = 0; f < i; f++) {
    for (v = 0; v < vnum; v++) {
      if (p_vertex[v] == p_face[f]) {
        p_face[f] = v;
        goto dale;
      }
    }
    p_vertex[vnum] = p_face[f];
    p_face[f] = vnum++;
  dale:;
  }

  if (crop) {
    for (f = del - 1; f >= 0; f--) {
      smaz_face_bez_vertexu(p_obj->p_face, p_obj->facenum, p_delete[f]);
    }
    smaz_divoke_vertexy_objektu_dir(p_obj);
  }

  if (!(p_new = vyrob_objekt_komplet(vnum, fnum))) {
    assert(p_new);
    chyba("Pamet");
  }

  for (v = 0; v < vnum; v++) {
    p_new->p_vertex[v] = p_obj->p_vertex[p_vertex[v]];
  }

  for (f = 0; f < fnum; f++) {
    p_new->p_face[f] = p_face[f];
  }

  p_new->material = p_obj->material;
  p_new->m1flag = p_obj->m1flag;
  p_new->m2flag = p_obj->m2flag;
  p_new->oflag = p_obj->oflag;
  strcpy(p_new->jmeno, "Vyrez");

  if ((o =
      lo_najdi_volny_kontejner(p_cnf->p_kont, p_cnf->max_kont)) == K_CHYBA) {
    ddw("Neni volny kontejner !");
    return;
  }

  p_cnf->p_kont[o] = vyrob_kontejner();
  p_cnf->p_kont[o]->p_obj[0] = p_new;
  strcpy(p_cnf->p_kont[o]->jmeno, "Vyrez");
  p_cnf->p_kont[o]->m1flag = p_cnf->p_kont[k]->m1flag;
  p_cnf->p_kont[o]->m2flag = p_cnf->p_kont[k]->m2flag;
  p_cnf->p_kont[o]->kflag = p_cnf->p_kont[k]->kflag;
  p_cnf->p_kont[o]->world = p_cnf->p_kont[k]->world;
  updatuj_kontejner_statistika(p_cnf->p_kont[o], TRUE);
  if (crop)
    updatuj_kontejner_statistika(p_cnf->p_kont[k], TRUE);
}