Пример #1
0
void UmlAcceptEventAction::write(FileOut & out) {
  write_begin(out, "AcceptEventAction");
  
  if (isUnmarshall())
    out << " isUnmarshall=\"true\"";
  
  Q3CString trig;
  
  switch (_lang) {
  case Uml:
    trig = trigger();
    break;
  case Cpp:
    trig = cppTrigger();
    break;
  default:
    // java
    trig = javaTrigger();
  }

  if (! trig.isEmpty()) {
    out.ref(this, "trigger", "TRIGGER_");
    write_end(out);
    
    out.indent();
    out << "<trigger xmi:type=\"uml:Trigger\"";
    out.id_prefix(this, "TRIGGER_");
    out << " name=\"";
    out.quote(trig);
    out << "\"/>\n";
  }
  else
    write_end(out);

}
Пример #2
0
void UmlReplyAction::write(FileOut & out) {
  write_begin(out, "ReplyAction");
  
  Q3CString trig;
  
  switch (_lang) {
  case Uml:
    trig = replyToCall();
    break;
  case Cpp:
    trig = cppReplyToCall();
    break;
  default:
    // java
    trig = javaReplyToCall();
  }

  if (! trig.isEmpty()) {
    out.ref(this, "replyToCall", "TRIGGER_");
    write_end(out);
    
    out.indent();
    out << "<trigger xmi:type=\"uml:Trigger\"";
    out.id_prefix(this, "TRIGGER_");
    out << " name=\"";
    out.quote(trig);
    out << "\"/>\n";
  }
  else
    write_end(out);
}
Пример #3
0
void UmlOpaqueAction::write(FileOut & out) {
  write_begin(out, "OpaqueAction");
  write_end(out, TRUE);
  
  Q3CString body;
  
  switch(_lang) {
  case Uml:
    body = behavior();
    break;
  case Cpp:
    body = cppBehavior();
    break;
  default:
    // Java
    body = javaBehavior();
  }

  if (!body.isEmpty()) {
    out.indent();
    out << "<body>";
    out.quote(body);
    out << "</body>\n";
  }

  write_close(out);

}
Пример #4
0
/* send a status reply */
void cmd_status(u08 status)
{
  write_begin();
  write_cmd(':');
  write_hex_byte(status);
  write_end();
}
Пример #5
0
void cmd_reply(u08 cmd, u08 num)
{
  write_begin();
  write_cmd(cmd);
  write_hex_byte(num);
  write_end();
}
Пример #6
0
int set_color(int led, int intensity, int r, int g, int b) {
	uint16_t color = ((r)+((g)<<4)+((b)<<8));
	int i;
	write_begin();
	for (i=6; i; i--, (led <<= 1)) {
		if (led&(1<<5)) {
			write_one();
		} else {
			write_zero();
		}
	}
	for (i=8; i; i--, (intensity<<=1)) {
		if (intensity&(1<<7)) {
			write_one();
		} else {
			write_zero();
		}
	}
	for (i=12; i; i--, (color<<=1)) {
		if (color&(1<<11)) {
			write_one();
		} else {
			write_zero();
		}
	}
	write_end();
	return 0;
}
Пример #7
0
void UmlDestroyObjectAction::write(FileOut & out) {
  write_begin(out, "DestroyObjectAction");
  if (isDestroyLinks())
    out << " isDestroyLinks=\"true\"";
  if (isDestroyOwnedObjects())
    out << " isDestroyOwnedObjects=\"true\"";
  write_end(out);
}
Пример #8
0
int scan(FILE *target)
{
  hash_t *var_map = malloc(sizeof(hash_t));
  hash_init(var_map, 1024);

  write_header(target);

  int ret = 0;

  while(next() == true){

    if(is_alpha() == false){

      printf("An instruction can only start with a function call or assignment\n");
      return 1;
    }

    char *current_token = get_token();

    char *temp;
    strcpy(temp, current_token);

    if(next() == false){

      printf("Incomplete instruction\n");
      return 1;

    }

    if(is_left()){

      ret = parse_call(target, temp, var_map);  /* It is a call */

    } else if(is_assignment()){

      ret = parse_assignment(target, temp, var_map);  /* It is an assignment */

    } else {
      printf("Not a valid instruction\n");
      return 1;
    }

    if(ret == 1 ){
      printf("Syntax error\n");
      return 1;
    }

  }

  write_end(target);
  free(var_map);
  return ret;

}
Пример #9
0
bool PNGWriter::Write(const float* buffer)
{
  if (!write_init())
    return false;

  write_header();
  write_bytes(reinterpret_cast<const unsigned char*>(buffer));

  if (!write_end())
    return false;
  return true;
}
Пример #10
0
bool PNGWriter::Write(const unsigned char* buffer)
{
  if (!write_init())
    return false;

  write_header();
  write_bytes(buffer);

  if (!write_end())
    return false;
  return true;
}
Пример #11
0
void UmlCallOperationAction::write(FileOut & out) {
  write_begin(out, "CallOperationAction");
  write_end(out, TRUE);
  
  UmlOperation * op = operation();
  
  if (op != 0) {
    out.indent();
    out << "<operation";
    out.idref(op);
    out << "/>\n";
  }

  write_close(out);

}
Пример #12
0
void UmlCallBehaviorAction::write(FileOut & out) {
  write_begin(out, "CallBehaviorAction");
  write_end(out, TRUE);
  
  UmlItem * b = behavior();
  
  if (b != 0) {
    out.indent();
    out << "<behavior";
    out.idref(b);
    out << "/>\n";
  }

  write_close(out);

}
Пример #13
0
void UmlReduceAction::write(FileOut & out) {
  write_begin(out, "ReduceAction");
  
  if (isOrdered())
    out << " isOrdered=\"true\"";
  
  write_end(out, TRUE);

  UmlItem * r = reducer();
  
  if (r != 0) {
    out.indent();
    out << "<reducer";
    out.idref(r);
    out << "/>\n";
  }

  write_close(out);
}
void write_continue() {
	if(update_info.is_updating == 1) {
		printf(" %d is ack!\n", update_info.write_idx);
		update_info.write_idx += sizeof(write_buf)-1;
		if (update_info.write_idx > DATA_NUM ) {
			write_end();
			return;
		}
		printf("start to write %d \n", update_info.write_idx);
		if(update_info.write_idx == 60 ) {
			memcpy(write_buf+1, update_info.data+update_info.write_idx , sizeof(write_buf)-2);
			write_buf[0] = 0xFA;
			write(update_info.write_fd, write_buf, sizeof(write_buf)-1);
		} else {
			memcpy(write_buf+1, update_info.data+update_info.write_idx , sizeof(write_buf)-1);
			write_buf[0] = 0xFA;
			write(update_info.write_fd, write_buf, sizeof(write_buf));
		}

	} else
		perror("update_info.is_updating != true!");
}
Пример #15
0
void UmlValueSpecificationAction::write(FileOut & out) {
  write_begin(out, "ValueSpecificationAction");
  
  Q3CString val;
  
  switch (_lang) {
  case Uml:
    val = value();
    break;
  case Cpp:
    val = cppValue();
    break;
  default:
    // Java
    val = javaValue();
  }
  if (! val.isEmpty())
    out.ref(activity()->add_opaque_expression(val, this),
	    "value", "OPAQUE_EXPRESSION_");

  write_end(out);
}
Пример #16
0
void UmlSendObjectAction::write(FileOut & out) {
  write_begin(out, "SendObjectAction");
  write_end(out);

}
Пример #17
0
void UmlRaiseExceptionAction::write(FileOut & out) {
  write_begin(out, "RaiseExceptionAction");
  write_end(out);

}
Пример #18
0
int main(int argc, char* argv[]){

   // parsing the arguments
   if(argc < 3)
      error_exit("Syntax error : Incorrect arguments, use : input_file output_file [-v] [-m filename].\r\n\r\n");

   bool use_verbatim = false;
   FILE* matlab_file = NULL;

   FILE* input_file = fopen(argv[1],"r");
   FILE* output_file = fopen(argv[2],"w+");

   if( input_file == NULL || output_file == NULL)
      error_exit("Runtime error : could not open required i/o files.\r\n\r\n");
   
   for(int i=3 ; i < argc; i++){
      if( argv[i][0] != '-' )
         error_exit("Syntax error : Unknown parameter : %s\r\n\r\n",argv[i]);

      switch(argv[i][1]){
         case 'v' :
            use_verbatim = true;
            break;
         case 'm' :
            if(i+1 >= argc)
               error_exit("Syntax error : Filename required with -m option\r\n\r\n");
            
            matlab_file = fopen(argv[i+1], "w+");

            if(matlab_file == NULL)
               error_exit("Runtime error : Cannot open file '%s' for matlab output.\r\n\r\n",argv[i+1]);

            i++;
            break;
      }
   }
   
   // positions and speed at time n-1 (0) and n (1).
   vector p10,p20,v1,v2,p11,p21;
   // masses
   long double m1,m2;
   // discretization parameters
   long double dt, t_final, dt_output;

   fscanf(input_file, "%Lf\r\n%Lf %Lf %Lf\r\n%Lf %Lf %Lf\r\n%Lf\r\n%Lf %Lf %Lf\r\n%Lf %Lf %Lf\r\n%Lf\r\n%Lf\r\n%Lf", &m1, &(p10.x), &(p10.y), &(p10.z), &(v1.x), &(v1.y), &(v1.z), &m2, &(p20.x), &(p20.y), &(p20.z), &(v2.x), &(v2.y), &(v2.z), &dt, &t_final, &dt_output );

   // Initial values determination
   p11 = addv(scalev(v1, dt), p10);
   p21 = addv(scalev(v2, dt), p20); 
   
   write_init(output_file, matlab_file, use_verbatim, m1, p10, v1, m2, p20, v2, dt, t_final, dt_output);

   write_output(output_file, matlab_file, use_verbatim, 0, p10, p20);
   if(dt_output <= dt + DOUBLE_EPSILON) write_output(output_file, matlab_file, use_verbatim, dt, p11, p21);
   
   long double next_out = dt_output;
 
   for(long double t = dt * 2 ; t <= t_final ; t+= dt ){
      vector dp = subv(p21,p11);
      long double norm = normv(dp);
      
      // compute F
      vector f = scalev(dp, - m1 * m2 * CONST_G / (norm * norm * norm)); 

      // compute positions at time t
      vector new_p1 = addv(subv(scalev(f, - dt * dt / m1), p10) , scalev(p11, 2));
      vector new_p2 = addv(subv(scalev(f, dt * dt / m2), p20) , scalev(p21, 2));
      p10 = p11;
      p20 = p21;
      p11 = new_p1;
      p21 = new_p2;
      
      if(t + dt - DOUBLE_EPSILON >= next_out){
         write_output(output_file, matlab_file, use_verbatim, t, p11, p21);
         next_out +=dt_output;
      }
   }
   
   write_end(output_file, matlab_file, use_verbatim);
   fclose(input_file);
   fclose(output_file);
   
   return EXIT_SUCCESS;
}
Пример #19
0
void UmlBroadcastSignalAction::write(FileOut & out) {
  write_begin(out, "BroadcastSignalAction");
  write_end(out, TRUE);
  write_signal(out);
  write_close(out);
}
Пример #20
0
void UmlCreateObjectAction::write(FileOut & out) {
  write_begin(out, "CreateObjectAction");
  write_end(out);

}
Пример #21
0
void UmlUnmarshallAction::write(FileOut & out) {
  write_begin(out, "UnmarshallAction");
  write_end(out);
}
Пример #22
0
void UmlSendSignalAction::write(FileOut & out) {
  write_begin(out, "SendSignalAction");
  write_end(out, TRUE);
  write_signal(out);
  write_close(out);
}
Пример #23
0
/*
 ****************************************************************
 *	Escreve mensagens para um outro usuário			*
 ****************************************************************
 */
void
main (int argc, const char *argv[])
{
	int		opt;
	FILE		*utmp_fp, *dst_fp;
	const char	*cp;
	const char	*my_user_nm = NOSTR, *my_tty_nm;
	const char	*my_complete_tty_nm;
	const char	*dst_user_nm, *dst_tty_nm;
	char		*dst_complete_tty_nm;
	int		dst_user_found = 0;
	const char	*dst_tty_given;
	UTMP		utmp;
	STAT		s;
	char		line[LINESZ];

	/*
	 *	Analisa as opções
	 */
	while ((opt = getopt (argc, argv, "vH")) != EOF)
	{
		switch (opt)
		{
		    case 'v':			/* Verbose */
			vflag++;
			break;

		    case 'H':			/* Help */
			help ();

		    default:			/* Erro */
			putc ('\n', stderr);
			help ();

		}	/* end switch */

	}	/* end while */

	/*
	 *	Pequena consistência
	 */
	argv += optind; 	argc -= optind;

	if (argc < 1 || argc > 2)
		help ();

	dst_user_nm = argv[0];  dst_tty_given = dst_tty_nm = argv[1];

	if (dst_tty_given  &&  (cp = strrchr (dst_tty_nm, '/')) != NOSTR)
		dst_tty_nm = cp + 1;

	/*
	 *	Obtém o nome do próprio terminal
	 */
	if ((my_tty_nm = ttyname (2 /* stderr */)) == NOSTR)
	{
		fprintf
		(	stderr,
			"%s: Não consegui obter o nome do terminal\n",
			pgname
		);
		exit (1);
	}

	my_complete_tty_nm = my_tty_nm;

	if ((cp = strrchr (my_tty_nm, '/')) != NOSTR)
		my_tty_nm = cp + 1;

	/*
	 *	Abre o arquivo do formato UTMP
	 */
	if ((utmp_fp = fopen (utmp_nm, "r")) == NOFILE)
	{
		fprintf
		(	stderr,
			"%s: Não consegui abrir \"%s\" (%s)\n",
			pgname, utmp_nm, strerror (errno)
		);
		exit (1);
	}

	/*
	 *	Procura o <usuário> no arquivo UTMP
	 */
	while (fread (&utmp, sizeof (UTMP), 1, utmp_fp) == 1)
	{
		if (utmp.ut_name[0] == '\0')
			continue;

		if (my_user_nm == NOSTR && streq ((char *)utmp.ut_line, my_tty_nm))
			my_user_nm = strdup ((char *)utmp.ut_name);

		if (!streq ((char *)utmp.ut_name, dst_user_nm))
			continue;

		if (dst_tty_given)
		{
			if (streq ((char *)utmp.ut_line, dst_tty_nm))
				dst_user_found++;
		}
		else
		{
			dst_user_found++;

			if (dst_tty_nm == NOSTR)
				dst_tty_nm = strdup ((char *)utmp.ut_line);
		}

	}	/* end for (EVER) */

	fclose (utmp_fp);

	/*
	 *	Verifica se foi encontrado o nome do próprio usuário
	 */
	if (my_user_nm == NOSTR)
	{
		fprintf
		(	stderr,
			"Não achei a minha própria entrada em \"%s\"\n",
			utmp_nm
		);
		exit (1);
	}

	/*
	 *	Verifica se foi encontrado o nome do <usuário>
	 */
	if (dst_user_found == 0)
	{
		fprintf (stderr, "O usuário \"%s\" não está em sessão", dst_user_nm);
		if (dst_tty_nm != NOSTR)
			fprintf (stderr, " no terminal \"%s\"", dst_tty_nm);
		fprintf (stderr, "\n");
		exit (1);
	}

	/*
	 *	Verifica se foi encontrado o nome do <usuário> mais de uma vez
	 */
	if (dst_user_found > 1)
	{
		fprintf
		(	stderr,
			"O usuário \"%s\" está em sessão em mais de um terminal!\n",
			dst_user_nm
		);
#if (0)	/*************************************/
		fprintf
		(	stderr,
			"Você está conectado com \"%s\"\n",
			dst_tty_nm
		);
#endif	/*************************************/
	}

	/*
	 *	Verifica se está escrevendo para o próprio terminal
	 */
	if (streq (dst_tty_nm, my_tty_nm))
	{
		fprintf (stderr, "Escrevendo para o próprio terminal?\n");
		exit (1);
	}

#undef	DEBUG
#ifdef	DEBUG
	printf ("my_user_nm  = \"%s\", my_tty_nm  = \"%s\"\n", my_user_nm, my_tty_nm);
	printf ("dst_user_nm = \"%s\", dst_tty_nm = \"%s\"\n", dst_user_nm, dst_tty_nm);
#endif	DEBUG

	/*
	 *     Verifica se o destinatário vai conseguir escrever no meu terminal
	 */
	if (stat (my_complete_tty_nm, &s) < 0)
	{
		fprintf
		(	stderr,
			"%s: Não consegui obter o estado do terminal \"%s\" (%s)\n",
			pgname, my_complete_tty_nm, strerror (errno)
		);
		exit (2);
	}

	if ((s.st_mode & S_IWOTH) == 0)
	{
		fprintf
		(	stderr,
			"*** CUIDADO: "
			"A recepção do seu terminal está desabilitada!\n"
		);
	}

	/*
	 *	Abre o terminal do destinatário
	 */
	dst_complete_tty_nm = malloc (strlen (dst_tty_nm) + 6);

	strcpy (dst_complete_tty_nm, "/dev/");
	strcat (dst_complete_tty_nm, dst_tty_nm);

	if ((dst_fp = fopen (dst_complete_tty_nm, "w")) == NOFILE)
	{
		fprintf
		(	stderr,
			"%s: Não consegui abrir \"%s\" (%s)\n",
			pgname, dst_tty_nm, strerror (errno)
		);
		exit (1);
	}

	/*
	 *     Verifica se o destinatário está com "mesg -y"
	 */
	if (fstat (fileno (dst_fp), &s) < 0)
	{
		fprintf
		(	stderr,
			"%s: Não consegui obter o estado do terminal \"%s\" (%s)\n",
			pgname, dst_complete_tty_nm, strerror (errno)
		);
		exit (2);
	}

	if ((s.st_mode & S_IWOTH) == 0)
	{
		fprintf
		(	stderr,
			"Não tenho permissão para escrever no terminal \"%s\"\n",
			dst_complete_tty_nm
		);
		exit (1);
	}

	/*
	 *	Envia o prólogo para o destinatário
	 */
	fprintf
	(	dst_fp,
		"\a\nMENSAGEM de \"%s\" (%s):\n\n",
		my_user_nm, my_tty_nm
	);

   /***	fflush (dst_fp); ***/

	if (ferror (dst_fp))
	{
		fprintf
		(	stderr,
			"%s: Não consegui enviar o prólogo para \"%s\" (%s)\n",
			pgname, dst_tty_nm, strerror (errno)
		);
		exit (1);
	}

	/*
	 *	Prepara o "setjmp" para o encerramento
	 */
	if (setjmp (end_env))
	{
		fprintf
		(	dst_fp,
			"\nFIM da mensagem de \"%s\" (%s)\n",
			my_user_nm, my_tty_nm
		);
	
		fclose (dst_fp);
		exit (0);
	}

	/*
	 *	Prepara os sinais
	 */
	signal (SIGHUP,  on_signal);
	signal (SIGINT,  on_signal);
	signal (SIGQUIT, on_signal);

	/*
	 *	Envia a mensagem de confirmação
	 */
	fprintf
	(	stderr,
		"\aConectado com o usuário \"%s\" no terminal \"%s\"\n",
		dst_user_nm, dst_tty_nm
	);

	/*
	 *	Envia as minhas diversas linhas
	 */
	for (EVER)
	{
		if (fngets (line, LINESZ, stdin) == NOSTR)
			break;

		/*
		 *	Verifica se é uma linha de comando
		 */
		if (line[0] == '!')
		{
			system (line + 1);
			fprintf (stderr, "!\n");
			continue;
		}

		/*
		 *     Verifica se o destinatário por acaso deu "mesg -n"
		 */
		if (fstat (fileno (dst_fp), &s) < 0)
		{
			fprintf
			(	stderr,
				"%s: Não consegui obter o estado do terminal \"%s\" (%s)\n",
				pgname, dst_complete_tty_nm, strerror (errno)
			);
			exit (2);
		}
	
		if ((s.st_mode & S_IWOTH) == 0)
		{
			fprintf
			(	stderr,
				"\aNão consigo mais escrever no terminal \"%s\"\n",
				dst_complete_tty_nm
			);
			write_end ();
		}

		if (fnputs (line, dst_fp) < 0 /* (EOF) */)
		{
			fprintf
			(	stderr,
				"%s: Não consegui enviar a mensagem para \"%s\" (%s)\n",
				pgname, dst_tty_nm, strerror (errno)
			);
			exit (1);
		}

	}	/* end for (EVER) */

	write_end ();

}	/* end write */
Пример #24
0
void UmlTestIdentityAction::write(FileOut & out) {
  write_begin(out, "TestIdentityAction");
  write_end(out);

}