示例#1
0
文件: morse.c 项目: glneo/direwolf
static int morse_units_ch (int ch)
{
	int i;
	int len;
	int k;
	int units;

	i = morse_lookup (ch);
	if (i < 0) {
	  return (1);	/* space or any invalid character */
	}

	
	len = strlen(morse[i].enc);
	units = len - 1;

	for (k = 0; k < len; k++) {
	  switch (morse[i].enc[k]) {
	    case '.':  units++; break;
	    case '-':  units += 3; break;
	    default:  dw_printf ("ERROR: morse_units_ch: should not be here.\n"); break;
	  }
	}
	
	return (units); 
}
示例#2
0
文件: morse.c 项目: glneo/direwolf
int morse_send (int chan, char *str, int wpm, int txdelay, int txtail)
{
	int time_units;
	char *p;

	time_units = 0;
	for (p = str; *p != '\0'; p++) {
	  int i;

	  i = morse_lookup (*p);
	  if (i >= 0) {
	    const char *e;

	    for (e = morse[i].enc; *e != '\0'; e++) {
	      if (*e == '.') {
	        morse_tone (1);
	        time_units++;
	      }
	      else {
	        morse_tone (3);
	        time_units += 3;
	      }
	      if (e[1] != '\0') {
	        morse_quiet (1);
	        time_units++;
	      }
	    }
	  }
	  else {
	    morse_quiet (1);
	    time_units++;
	  }
	  if (p[1] != '\0') {
	    morse_quiet (3);
	    time_units += 3;
	  }
	}

	if (time_units != morse_units_str(str)) {
	  dw_printf ("morse: Internal error.  Inconsistent length, %d vs. %d calculated.\n", 
		time_units, morse_units_str(str));
	}


	return (txdelay +
		TIME_UNITS_TO_MS(time_units, wpm) +
		txtail);

}  /* end morse_send */
示例#3
0
文件: morse.c 项目: Angeldude/pd
static void morse_message( t_morse *x, t_symbol *s, int ac, t_atom *av )
{
	int i,j,l;
	if ( x->x_msg != NULL )
	{
		morse_freemsg( x->x_msg );
		x->x_msg = NULL;				
		x->x_curmsg = NULL;
		x->x_spaceticks =0;
	}
	if ( ac > 0 )
	{
		char buf[256];
		for(  i = 0 ; i < ac ; i++ )
		{
			atom_string( &av[i] , buf, 255 );						
			l = strlen( buf );
#ifdef NT			
/* this is not part of ANSI or ISO standard C, 
	only Microsoft and Borland use it. */
			strlwr( buf );
#else
/* Probably needs a loop using tolower(char c) from ctype.h 
 * This way it'll just be case sensitive
 */
#endif
			for( j = 0 ; j < l ; j++ )
			{
				morse_add_msg_part( x , morse_lookup( buf[j] ));
			}
			morse_add_msg_part( x , wordspace );
		}			
		x->x_curmsg = x->x_msg;
		x->x_spaceticks =0;
	}
	else
	{
		// if there is no pattern it doens't do anything
		x->x_msg = NULL;				
		x->x_curmsg = NULL;
		x->x_spaceticks =0;
	}
}