bin/81831: [PATCH] morse(6) Farnsworth support

Stephen P. Cravey cravey at gotbrains.org
Tue Jun 7 16:18:52 GMT 2005


This updated patch handles a minor idiocy in the GETOPTOPTS to group the
new 'c' flag with 'lpsw' instead of forcing it to come later in the
command line.

This is a patch to morse.c in cvs, not an additive patch to my previous
patch.

-Stephen


*** morse.c	Tue Jun  7 10:50:50 2005
--- morse.c.new	Tue Jun  7 10:50:40 2005
***************
*** 266,277 ****
  void		ttyout(const char *);
  void		sighandler(int);
  
! #define GETOPTOPTS "d:ef:lsw:"
  #define USAGE \
! "usage: morse [-els] [-d device] [-w speed] [-f frequency] [string
...]\n"  
! static int      pflag, lflag, sflag, eflag;
! static int      wpm = 20;	/* words per minute */
  #define FREQUENCY 600
  static int      freq = FREQUENCY;
  static char	*device;	/* for tty-controlled generator */
--- 266,278 ----
  void		ttyout(const char *);
  void		sighandler(int);
  
! #define GETOPTOPTS "d:ef:lswc:"
  #define USAGE \
! "usage: morse [-els] [-d device] [-w speed] [-c speed] [-f frequency]
[string ...]\n"  
! static int      pflag, lflag, sflag, eflag, cflag;
! static int      wpm = 20;	/* effective words per minute */
! static int      cpm = 20;	/* effective words per minute between
characters */  #define FREQUENCY 600
  static int      freq = FREQUENCY;
  static char	*device;	/* for tty-controlled generator */
***************
*** 280,285 ****
--- 281,287 ----
  #define CHAR_SPACE 3
  #define WORD_SPACE (7 - CHAR_SPACE - 1)
  static float    dot_clock;
+ static float    cdot_clock;
  int             spkr, line;
  struct termios	otty, ntty;
  int		olflags;
***************
*** 287,296 ****
  #ifdef SPEAKER
  tone_t          sound;
  #undef GETOPTOPTS
! #define GETOPTOPTS "d:ef:lpsw:"
  #undef USAGE
  #define USAGE \
! "usage: morse [-elps] [-d device] [-w speed] [-f frequency] [string
...]\n"  #endif
  
  static const struct morsetab *hightab;
--- 289,298 ----
  #ifdef SPEAKER
  tone_t          sound;
  #undef GETOPTOPTS
! #define GETOPTOPTS "d:ef:lpswc:"
  #undef USAGE
  #define USAGE \
! "usage: morse [-elps] [-d device] [-w speed] [-c speed] [-f frequency]
[string ...]\n"  #endif
  
  static const struct morsetab *hightab;
***************
*** 327,332 ****
--- 329,338 ----
  		case 'w':
  			wpm = atoi(optarg);
  			break;
+  		case 'c':
+  		        cflag = 1;
+  			cpm = atoi(optarg);
+  			break;
  		case '?':
  		default:
  			fputs(USAGE, stderr);
***************
*** 340,346 ****
  		fputs("morse: only one of -p, -d and -l, -s allowed\n",
stderr);  		exit(1);
  	}
! 	if ((pflag || device) && ((wpm < 1) || (wpm > 60))) {
  		fputs("morse: insane speed\n", stderr);
  		exit(1);
  	}
--- 346,352 ----
  		fputs("morse: only one of -p, -d and -l, -s allowed\n",
stderr);  		exit(1);
  	}
! 	if ((pflag || device) && ((wpm < 1) || (wpm > 60) || (cpm < 1)
|| (cpm > 60))) {
  		fputs("morse: insane speed\n", stderr);
  		exit(1);
  	}
***************
*** 385,390 ****
--- 391,405 ----
  		dot_clock = dot_clock / 2;	/* dot_clock runs at twice */
  						/* the dot rate */
  		dot_clock = dot_clock * 100;	/* scale for ioctl */
+ 
+ 		if (cflag) {
+ 		  cdot_clock = cpm / 2.4;	/* dots/sec */
+ 		  cdot_clock = 1 / cdot_clock;	/* duration of a dot */
+ 		  cdot_clock = cdot_clock / 2;	/* dot_clock runs at twice */
+ 						/* the dot rate */
+ 		  cdot_clock = cdot_clock * 100;/* scale for ioctl */
+ 		} else 
+ 		cdot_clock = dot_clock;
  	}
  
  	argc -= optind;
***************
*** 492,498 ****
  			break;
  		case ' ':
  			sound.frequency = 0;
! 			sound.duration = dot_clock * WORD_SPACE;
  			break;
  		default:
  			sound.duration = 0;
--- 507,513 ----
  			break;
  		case ' ':
  			sound.frequency = 0;
! 			sound.duration = cdot_clock * WORD_SPACE;
  			break;
  		default:
  			sound.duration = 0;
***************
*** 511,517 ****
  		}
  	}
  	sound.frequency = 0;
! 	sound.duration = dot_clock * CHAR_SPACE;
  	ioctl(spkr, SPKRTONE, &sound);
  #endif
  }
--- 526,532 ----
  		}
  	}
  	sound.frequency = 0;
! 	sound.duration = cdot_clock * CHAR_SPACE;
  	ioctl(spkr, SPKRTONE, &sound);
  #endif
  }
***************
*** 534,540 ****
  			break;
  		case ' ':
  			on = 0;
! 			duration = dot_clock * WORD_SPACE;
  			break;
  		default:
  			on = 0;
--- 549,555 ----
  			break;
  		case ' ':
  			on = 0;
! 			duration = cdot_clock * WORD_SPACE;
  			break;
  		default:
  			on = 0;
***************
*** 554,560 ****
  		duration = dot_clock * 10000;
  		usleep(duration);
  	}
! 	duration = dot_clock * CHAR_SPACE * 10000;
  	usleep(duration);
  }
  
--- 569,575 ----
  		duration = dot_clock * 10000;
  		usleep(duration);
  	}
! 	duration = cdot_clock * CHAR_SPACE * 10000;
  	usleep(duration);
  }
  


More information about the freebsd-bugs mailing list