• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-c誰得cocoaqtpythonrubywindowsphpgameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwitterdombtronvb.nettestarduinodirectxpreviewerゲームエンジン

My own rewrite of the BSD morse code recreational utility


Commit MetaInfo

Revision3e53124b5d601e3359806836b00297bf47b7566a (tree)
Time2021-08-30 02:35:33
AuthorJoel Matthew Rees <joel.rees@gmai...>
CommiterJoel Matthew Rees

Log Message

replace getopt

Change Summary

Incremental Difference

--- a/bsdmorseplus.c
+++ b/bsdmorseplus.c
@@ -287,10 +287,14 @@ main(argc, argv)
287287 {
288288 int ch;
289289 char *p;
290+/* JMR20210830 manage the command line ourselves: */
291+ char **argvp;
292+/* JMR20210830 end. */
290293
291294 /* Revoke setgid privileges */
292295 setregid(getgid(), getgid());
293296
297+/* JMR20210830 really isn't any reason to use getopt:
294298 while ((ch = getopt(argc, argv, "ds")) != -1)
295299 switch((char)ch) {
296300 case 'd':
@@ -306,15 +310,41 @@ main(argc, argv)
306310 }
307311 argc -= optind;
308312 argv += optind;
313+*/
314+ argvp = argv + 1;
315+ if ( argc > 0 )
316+ if ( argv[ 1 ][ 0 ] == '-' )
317+ {
318+ switch ( argv[ 1 ][ 1 ] )
319+ {
320+ case 'd':
321+ dflag = 1;
322+ ++argvp;
323+ break;
324+ case 's':
325+ sflag = 1;
326+ ++argvp;
327+ break;
328+ case '\0':
329+ case '.':
330+ case '-':
331+ break;
332+ case '?':
333+ default:
334+ fprintf(stderr, "usage: %s [-ds] [string ...]\n", argv[ 0 ]);
335+ exit(1);
336+ }
337+ }
338+/* JMR20210830 end. */
309339
310340 if (dflag) {
311- if (*argv) {
341+ if (*argvp) {
312342 char outstr;
313343 do {
314-/* decode(*argv); */
315- outstr = totextif( argv );
344+/* decode(*argvp); */
345+ outstr = totextif( argvp );
316346 putchar( outstr );
317- } while (*++argv);
347+ } while (*++argvp);
318348 } else {
319349 char foo[10]; /* All morse chars shorter than this */
320350 int isblank, i;
@@ -351,12 +381,12 @@ main(argc, argv)
351381 }
352382 putchar('\n');
353383 } else {
354- if (*argv)
384+ if (*argvp)
355385 do {
356- for (p = *argv; *p; ++p)
386+ for (p = *argvp; *p; ++p)
357387 morse((int)*p);
358388 show("");
359- } while (*++argv);
389+ } while (*++argvp);
360390 else while ((ch = getchar()) != EOF)
361391 morse(ch);
362392 show("...-.-"); /* SK */