Home » CEEFAX disks » telesoftware15.adl » 21-02-89/Ask_Key\C
21-02-89/Ask_Key\C
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » CEEFAX disks » telesoftware15.adl |
Filename: | 21-02-89/Ask_Key\C |
Read OK: | ✔ |
File size: | 02DB bytes |
Load address: | 0000 |
Exec address: | FFFFFFFF |
File contents
/* ASK_KEY by Barry Wood (c) PCA Magazine 1989 Allows interactive batch files by returning in ERRORLEVEL a number N, where the user pressed the Nth key in a list. Usage: ASK_KEY abc123 where the A,B,C,1,2 and 3 keys are valid choices. Other key presses are ignored. ERRORLEVEL will be 0 if key list not valid */ char *strrchr(); #include <stdio.h> main(argc,argv) int argc; char *argv[]; { char *p; int kslen,position; if(argc != 2) { puts("Bad key list!\n"); exit(0); } strupr( argv[1] ); kslen=strlen( argv[1] ); for ( position=-1; (position < 0) || (position >= kslen) ; ) position=strrchr( argv[1], toupper(getch()) ) - argv[1]; exit(position+1); }
00000000 2f 2a 0d 0a 41 53 4b 5f 4b 45 59 0d 0a 0d 0a 62 |/*..ASK_KEY....b| 00000010 79 20 42 61 72 72 79 20 57 6f 6f 64 0d 0a 0d 0a |y Barry Wood....| 00000020 28 63 29 20 50 43 41 20 4d 61 67 61 7a 69 6e 65 |(c) PCA Magazine| 00000030 20 31 39 38 39 0d 0a 0d 0a 41 6c 6c 6f 77 73 20 | 1989....Allows | 00000040 69 6e 74 65 72 61 63 74 69 76 65 20 62 61 74 63 |interactive batc| 00000050 68 20 66 69 6c 65 73 20 62 79 20 72 65 74 75 72 |h files by retur| 00000060 6e 69 6e 67 20 69 6e 20 45 52 52 4f 52 4c 45 56 |ning in ERRORLEV| 00000070 45 4c 0d 0a 61 20 6e 75 6d 62 65 72 20 4e 2c 20 |EL..a number N, | 00000080 77 68 65 72 65 20 74 68 65 20 75 73 65 72 20 70 |where the user p| 00000090 72 65 73 73 65 64 20 74 68 65 20 4e 74 68 20 6b |ressed the Nth k| 000000a0 65 79 20 69 6e 20 61 20 6c 69 73 74 2e 0d 0a 0d |ey in a list....| 000000b0 0a 55 73 61 67 65 3a 0d 0a 0d 0a 41 53 4b 5f 4b |.Usage:....ASK_K| 000000c0 45 59 20 61 62 63 31 32 33 0d 0a 0d 0a 77 68 65 |EY abc123....whe| 000000d0 72 65 20 74 68 65 20 41 2c 42 2c 43 2c 31 2c 32 |re the A,B,C,1,2| 000000e0 20 61 6e 64 20 33 20 6b 65 79 73 20 61 72 65 20 | and 3 keys are | 000000f0 76 61 6c 69 64 20 63 68 6f 69 63 65 73 2e 0d 0a |valid choices...| 00000100 0d 0a 4f 74 68 65 72 20 6b 65 79 20 70 72 65 73 |..Other key pres| 00000110 73 65 73 20 61 72 65 20 69 67 6e 6f 72 65 64 2e |ses are ignored.| 00000120 0d 0a 0d 0a 45 52 52 4f 52 4c 45 56 45 4c 20 77 |....ERRORLEVEL w| 00000130 69 6c 6c 20 62 65 20 30 20 69 66 20 6b 65 79 20 |ill be 0 if key | 00000140 6c 69 73 74 20 6e 6f 74 20 76 61 6c 69 64 0d 0a |list not valid..| 00000150 0d 0a 2a 2f 0d 0a 0d 0a 63 68 61 72 20 2a 73 74 |..*/....char *st| 00000160 72 72 63 68 72 28 29 3b 0d 0a 0d 0a 23 69 6e 63 |rrchr();....#inc| 00000170 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 3e 0d 0a |lude <stdio.h>..| 00000180 0d 0a 6d 61 69 6e 28 61 72 67 63 2c 61 72 67 76 |..main(argc,argv| 00000190 29 0d 0a 69 6e 74 20 61 72 67 63 3b 0d 0a 63 68 |)..int argc;..ch| 000001a0 61 72 20 2a 61 72 67 76 5b 5d 3b 0d 0a 7b 0d 0a |ar *argv[];..{..| 000001b0 63 68 61 72 20 2a 70 3b 0d 0a 69 6e 74 20 6b 73 |char *p;..int ks| 000001c0 6c 65 6e 2c 70 6f 73 69 74 69 6f 6e 3b 0d 0a 0d |len,position;...| 000001d0 0a 09 69 66 28 61 72 67 63 20 21 3d 20 32 29 0d |..if(argc != 2).| 000001e0 0a 09 09 7b 0d 0a 09 09 70 75 74 73 28 22 42 61 |...{....puts("Ba| 000001f0 64 20 6b 65 79 20 6c 69 73 74 21 5c 6e 22 29 3b |d key list!\n");| 00000200 0d 0a 09 09 65 78 69 74 28 30 29 3b 0d 0a 09 09 |....exit(0);....| 00000210 7d 0d 0a 0d 0a 09 73 74 72 75 70 72 28 20 61 72 |}.....strupr( ar| 00000220 67 76 5b 31 5d 20 29 3b 0d 0a 09 6b 73 6c 65 6e |gv[1] );...kslen| 00000230 3d 73 74 72 6c 65 6e 28 20 61 72 67 76 5b 31 5d |=strlen( argv[1]| 00000240 20 29 3b 0d 0a 0d 0a 09 66 6f 72 20 28 20 70 6f | );.....for ( po| 00000250 73 69 74 69 6f 6e 3d 2d 31 3b 20 28 70 6f 73 69 |sition=-1; (posi| 00000260 74 69 6f 6e 20 3c 20 30 29 20 7c 7c 20 28 70 6f |tion < 0) || (po| 00000270 73 69 74 69 6f 6e 20 3e 3d 20 6b 73 6c 65 6e 29 |sition >= kslen)| 00000280 20 3b 20 29 0d 0a 09 09 70 6f 73 69 74 69 6f 6e | ; )....position| 00000290 3d 73 74 72 72 63 68 72 28 20 61 72 67 76 5b 31 |=strrchr( argv[1| 000002a0 5d 2c 20 74 6f 75 70 70 65 72 28 67 65 74 63 68 |], toupper(getch| 000002b0 28 29 29 20 29 20 2d 20 61 72 67 76 5b 31 5d 3b |()) ) - argv[1];| 000002c0 0d 0a 0d 0a 09 65 78 69 74 28 70 6f 73 69 74 69 |.....exit(positi| 000002d0 6f 6e 2b 31 29 3b 0d 0a 7d 0d 0a |on+1);..}..| 000002db