Home » Recent acquisitions » Acorn ADFS disks » adfs_ArchimedesWorld_199204.adf » April92 » !AWApr92/Goodies/All_At_C/c/words
!AWApr92/Goodies/All_At_C/c/words
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 » Recent acquisitions » Acorn ADFS disks » adfs_ArchimedesWorld_199204.adf » April92 |
Filename: | !AWApr92/Goodies/All_At_C/c/words |
Read OK: | ✔ |
File size: | 0AE6 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
/* Program: !Words */ /* Archimedes World, January 1992. */ #include "lexical.h" #include <stdio.h> #include <string.h> #define MAXPATH 128 static char InFileName[MAXPATH]; static char OutFileName[MAXPATH]; void WriteFile( char *filename, word list ) { FILE *out = stdout; if ( *filename ) out = fopen( filename, "w" ); if ( out ) { ListWords( out, list ); if ( out != stdout ) fclose( out ); } else printf( "Unable to open output file '%s'", filename ); } void ReadFile( char *filename, word *list ) { int len; string buffer; FILE *in = fopen( filename, "r" ); if ( in ) { while ( len = GetWord(buffer,STRLEN,in), len ) { if ( len > 1 ) { ToLowerCase( buffer ); StoreWord( buffer, list ); } } fclose( in ); } else printf( "Unable to open input file '%s'", filename ); } static void SetInputFile( char *filename ) { printf( "SetInputFile: '%s'\n", filename ); strncpy( InFileName, filename, MAXPATH ); } static int SetOutputFile( char *argv[] ) { char *filename = argv[1]; printf( "SetOutputFile: '%s'\n", filename ); strncpy( OutFileName, filename, MAXPATH ); return 2; } static int SetCaseSensitivity( char *argv[] ) { printf( "SetCaseSensitivity\n" ); return 1; } static int SetRepeatCount( char *argv[] ) { printf( "SetRepeatCount\n" ); return 1; } static int SetWordSize( char *argv[] ) { printf( "SetWordSize: %s\n", argv[1] ); return 2; } static int HandleCommandLine( int argc, char *argv[] ) { int count = 1; if ( argc > 1 ) { SetInputFile( argv[count++] ); while ( count < argc ) { switch ( argv[count][1] ) { case 'c' : count += SetCaseSensitivity( &argv[count] ); break; case 'o' : count += SetOutputFile( &argv[count] ); break; case 's' : count += SetWordSize( &argv[count] ); break; case 'r' : count += SetRepeatCount( &argv[count] ); break; default : printf( "Unknown command '%s'\n", argv[count] ); count++; } } return TRUE; } else { puts( "No input file name supplied." ); return FALSE; } } int main( int argc, char *argv[] ) { word list = NULL; if ( HandleCommandLine( argc, argv ) ) { ReadFile( InFileName, &list ); WriteFile( OutFileName, list ); return 0; } else return 1; }
00000000 2f 2a 20 20 50 72 6f 67 72 61 6d 3a 20 21 57 6f |/* Program: !Wo| 00000010 72 64 73 20 20 20 20 20 20 20 20 20 20 20 20 20 |rds | 00000020 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 2f 2a 20 | */./* | 00000030 20 41 72 63 68 69 6d 65 64 65 73 20 57 6f 72 6c | Archimedes Worl| 00000040 64 2c 20 4a 61 6e 75 61 72 79 20 31 39 39 32 2e |d, January 1992.| 00000050 20 20 20 20 20 20 20 2a 2f 0a 0a 23 69 6e 63 6c | */..#incl| 00000060 75 64 65 20 22 6c 65 78 69 63 61 6c 2e 68 22 0a |ude "lexical.h".| 00000070 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e |#include <stdio.| 00000080 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 72 |h>.#include <str| 00000090 69 6e 67 2e 68 3e 0a 0a 23 64 65 66 69 6e 65 20 |ing.h>..#define | 000000a0 4d 41 58 50 41 54 48 20 31 32 38 0a 0a 73 74 61 |MAXPATH 128..sta| 000000b0 74 69 63 20 63 68 61 72 20 49 6e 46 69 6c 65 4e |tic char InFileN| 000000c0 61 6d 65 5b 4d 41 58 50 41 54 48 5d 3b 0a 73 74 |ame[MAXPATH];.st| 000000d0 61 74 69 63 20 63 68 61 72 20 4f 75 74 46 69 6c |atic char OutFil| 000000e0 65 4e 61 6d 65 5b 4d 41 58 50 41 54 48 5d 3b 0a |eName[MAXPATH];.| 000000f0 0a 0a 76 6f 69 64 20 57 72 69 74 65 46 69 6c 65 |..void WriteFile| 00000100 28 20 63 68 61 72 20 2a 66 69 6c 65 6e 61 6d 65 |( char *filename| 00000110 2c 20 77 6f 72 64 20 6c 69 73 74 20 29 0a 7b 0a |, word list ).{.| 00000120 20 20 20 20 46 49 4c 45 20 2a 6f 75 74 20 3d 20 | FILE *out = | 00000130 73 74 64 6f 75 74 3b 0a 0a 20 20 20 20 69 66 20 |stdout;.. if | 00000140 28 20 2a 66 69 6c 65 6e 61 6d 65 20 29 20 20 6f |( *filename ) o| 00000150 75 74 20 3d 20 66 6f 70 65 6e 28 20 66 69 6c 65 |ut = fopen( file| 00000160 6e 61 6d 65 2c 20 22 77 22 20 29 3b 0a 0a 20 20 |name, "w" );.. | 00000170 20 20 69 66 20 28 20 6f 75 74 20 29 0a 20 20 20 | if ( out ). | 00000180 20 7b 0a 20 20 20 20 20 20 20 20 4c 69 73 74 57 | {. ListW| 00000190 6f 72 64 73 28 20 6f 75 74 2c 20 6c 69 73 74 20 |ords( out, list | 000001a0 29 3b 0a 20 20 20 20 20 20 20 20 69 66 20 28 20 |);. if ( | 000001b0 6f 75 74 20 21 3d 20 73 74 64 6f 75 74 20 29 20 |out != stdout ) | 000001c0 20 66 63 6c 6f 73 65 28 20 6f 75 74 20 29 3b 0a | fclose( out );.| 000001d0 20 20 20 20 7d 0a 20 20 20 20 65 6c 73 65 0a 20 | }. else. | 000001e0 20 20 20 20 20 20 20 70 72 69 6e 74 66 28 20 22 | printf( "| 000001f0 55 6e 61 62 6c 65 20 74 6f 20 6f 70 65 6e 20 6f |Unable to open o| 00000200 75 74 70 75 74 20 66 69 6c 65 20 27 25 73 27 22 |utput file '%s'"| 00000210 2c 20 66 69 6c 65 6e 61 6d 65 20 29 3b 0a 7d 0a |, filename );.}.| 00000220 0a 0a 76 6f 69 64 20 52 65 61 64 46 69 6c 65 28 |..void ReadFile(| 00000230 20 63 68 61 72 20 2a 66 69 6c 65 6e 61 6d 65 2c | char *filename,| 00000240 20 77 6f 72 64 20 2a 6c 69 73 74 20 29 0a 7b 0a | word *list ).{.| 00000250 20 20 20 20 69 6e 74 20 20 20 20 6c 65 6e 3b 0a | int len;.| 00000260 20 20 20 20 73 74 72 69 6e 67 20 62 75 66 66 65 | string buffe| 00000270 72 3b 0a 20 20 20 20 46 49 4c 45 20 20 2a 69 6e |r;. FILE *in| 00000280 20 3d 20 66 6f 70 65 6e 28 20 66 69 6c 65 6e 61 | = fopen( filena| 00000290 6d 65 2c 20 22 72 22 20 29 3b 0a 0a 20 20 20 20 |me, "r" );.. | 000002a0 69 66 20 28 20 69 6e 20 29 0a 20 20 20 20 7b 0a |if ( in ). {.| 000002b0 20 20 20 20 20 20 20 20 77 68 69 6c 65 20 28 20 | while ( | 000002c0 6c 65 6e 20 3d 20 47 65 74 57 6f 72 64 28 62 75 |len = GetWord(bu| 000002d0 66 66 65 72 2c 53 54 52 4c 45 4e 2c 69 6e 29 2c |ffer,STRLEN,in),| 000002e0 20 6c 65 6e 20 29 0a 20 20 20 20 20 20 20 20 7b | len ). {| 000002f0 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 |. if | 00000300 28 20 6c 65 6e 20 3e 20 31 20 29 0a 20 20 20 20 |( len > 1 ). | 00000310 20 20 20 20 20 20 20 20 7b 0a 20 20 20 20 20 20 | {. | 00000320 20 20 20 20 20 20 20 20 20 20 54 6f 4c 6f 77 65 | ToLowe| 00000330 72 43 61 73 65 28 20 62 75 66 66 65 72 20 29 3b |rCase( buffer );| 00000340 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |. | 00000350 20 53 74 6f 72 65 57 6f 72 64 28 20 62 75 66 66 | StoreWord( buff| 00000360 65 72 2c 20 6c 69 73 74 20 29 3b 0a 20 20 20 20 |er, list );. | 00000370 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 | }. | 00000380 20 20 7d 0a 0a 20 20 20 20 20 20 20 20 66 63 6c | }.. fcl| 00000390 6f 73 65 28 20 69 6e 20 29 3b 0a 20 20 20 20 7d |ose( in );. }| 000003a0 0a 20 20 20 20 65 6c 73 65 0a 20 20 20 20 20 20 |. else. | 000003b0 20 20 70 72 69 6e 74 66 28 20 22 55 6e 61 62 6c | printf( "Unabl| 000003c0 65 20 74 6f 20 6f 70 65 6e 20 69 6e 70 75 74 20 |e to open input | 000003d0 66 69 6c 65 20 27 25 73 27 22 2c 20 66 69 6c 65 |file '%s'", file| 000003e0 6e 61 6d 65 20 29 3b 0a 7d 0a 0a 0a 73 74 61 74 |name );.}...stat| 000003f0 69 63 20 76 6f 69 64 20 53 65 74 49 6e 70 75 74 |ic void SetInput| 00000400 46 69 6c 65 28 20 63 68 61 72 20 2a 66 69 6c 65 |File( char *file| 00000410 6e 61 6d 65 20 29 0a 7b 0a 20 20 20 20 70 72 69 |name ).{. pri| 00000420 6e 74 66 28 20 22 53 65 74 49 6e 70 75 74 46 69 |ntf( "SetInputFi| 00000430 6c 65 3a 20 27 25 73 27 5c 6e 22 2c 20 66 69 6c |le: '%s'\n", fil| 00000440 65 6e 61 6d 65 20 29 3b 0a 20 20 20 20 73 74 72 |ename );. str| 00000450 6e 63 70 79 28 20 49 6e 46 69 6c 65 4e 61 6d 65 |ncpy( InFileName| 00000460 2c 20 66 69 6c 65 6e 61 6d 65 2c 20 4d 41 58 50 |, filename, MAXP| 00000470 41 54 48 20 29 3b 0a 7d 0a 0a 0a 73 74 61 74 69 |ATH );.}...stati| 00000480 63 20 69 6e 74 20 53 65 74 4f 75 74 70 75 74 46 |c int SetOutputF| 00000490 69 6c 65 28 20 63 68 61 72 20 2a 61 72 67 76 5b |ile( char *argv[| 000004a0 5d 20 29 0a 7b 0a 20 20 20 20 63 68 61 72 20 2a |] ).{. char *| 000004b0 66 69 6c 65 6e 61 6d 65 20 3d 20 61 72 67 76 5b |filename = argv[| 000004c0 31 5d 3b 0a 0a 20 20 20 20 70 72 69 6e 74 66 28 |1];.. printf(| 000004d0 20 22 53 65 74 4f 75 74 70 75 74 46 69 6c 65 3a | "SetOutputFile:| 000004e0 20 27 25 73 27 5c 6e 22 2c 20 66 69 6c 65 6e 61 | '%s'\n", filena| 000004f0 6d 65 20 29 3b 0a 20 20 20 20 73 74 72 6e 63 70 |me );. strncp| 00000500 79 28 20 4f 75 74 46 69 6c 65 4e 61 6d 65 2c 20 |y( OutFileName, | 00000510 66 69 6c 65 6e 61 6d 65 2c 20 4d 41 58 50 41 54 |filename, MAXPAT| 00000520 48 20 29 3b 0a 0a 20 20 20 20 72 65 74 75 72 6e |H );.. return| 00000530 20 32 3b 0a 7d 0a 0a 0a 73 74 61 74 69 63 20 69 | 2;.}...static i| 00000540 6e 74 20 53 65 74 43 61 73 65 53 65 6e 73 69 74 |nt SetCaseSensit| 00000550 69 76 69 74 79 28 20 63 68 61 72 20 2a 61 72 67 |ivity( char *arg| 00000560 76 5b 5d 20 29 0a 7b 0a 20 20 20 20 70 72 69 6e |v[] ).{. prin| 00000570 74 66 28 20 22 53 65 74 43 61 73 65 53 65 6e 73 |tf( "SetCaseSens| 00000580 69 74 69 76 69 74 79 5c 6e 22 20 29 3b 0a 20 20 |itivity\n" );. | 00000590 20 20 72 65 74 75 72 6e 20 31 3b 0a 7d 0a 0a 0a | return 1;.}...| 000005a0 73 74 61 74 69 63 20 69 6e 74 20 53 65 74 52 65 |static int SetRe| 000005b0 70 65 61 74 43 6f 75 6e 74 28 20 63 68 61 72 20 |peatCount( char | 000005c0 2a 61 72 67 76 5b 5d 20 29 0a 7b 0a 20 20 20 20 |*argv[] ).{. | 000005d0 70 72 69 6e 74 66 28 20 22 53 65 74 52 65 70 65 |printf( "SetRepe| 000005e0 61 74 43 6f 75 6e 74 5c 6e 22 20 29 3b 0a 20 20 |atCount\n" );. | 000005f0 20 20 72 65 74 75 72 6e 20 31 3b 0a 7d 0a 0a 0a | return 1;.}...| 00000600 73 74 61 74 69 63 20 69 6e 74 20 53 65 74 57 6f |static int SetWo| 00000610 72 64 53 69 7a 65 28 20 63 68 61 72 20 2a 61 72 |rdSize( char *ar| 00000620 67 76 5b 5d 20 29 0a 7b 0a 20 20 20 20 70 72 69 |gv[] ).{. pri| 00000630 6e 74 66 28 20 22 53 65 74 57 6f 72 64 53 69 7a |ntf( "SetWordSiz| 00000640 65 3a 20 25 73 5c 6e 22 2c 20 61 72 67 76 5b 31 |e: %s\n", argv[1| 00000650 5d 20 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 |] );. return | 00000660 32 3b 0a 7d 0a 0a 0a 73 74 61 74 69 63 20 69 6e |2;.}...static in| 00000670 74 20 48 61 6e 64 6c 65 43 6f 6d 6d 61 6e 64 4c |t HandleCommandL| 00000680 69 6e 65 28 20 69 6e 74 20 61 72 67 63 2c 20 63 |ine( int argc, c| 00000690 68 61 72 20 2a 61 72 67 76 5b 5d 20 29 0a 7b 0a |har *argv[] ).{.| 000006a0 20 20 20 20 69 6e 74 20 63 6f 75 6e 74 20 3d 20 | int count = | 000006b0 31 3b 0a 0a 20 20 20 20 69 66 20 28 20 61 72 67 |1;.. if ( arg| 000006c0 63 20 3e 20 31 20 29 0a 20 20 20 20 7b 0a 20 20 |c > 1 ). {. | 000006d0 20 20 20 20 20 20 53 65 74 49 6e 70 75 74 46 69 | SetInputFi| 000006e0 6c 65 28 20 61 72 67 76 5b 63 6f 75 6e 74 2b 2b |le( argv[count++| 000006f0 5d 20 29 3b 0a 0a 20 20 20 20 20 20 20 20 77 68 |] );.. wh| 00000700 69 6c 65 20 28 20 63 6f 75 6e 74 20 3c 20 61 72 |ile ( count < ar| 00000710 67 63 20 29 0a 20 20 20 20 20 20 20 20 7b 0a 20 |gc ). {. | 00000720 20 20 20 20 20 20 20 20 20 20 20 73 77 69 74 63 | switc| 00000730 68 20 28 20 61 72 67 76 5b 63 6f 75 6e 74 5d 5b |h ( argv[count][| 00000740 31 5d 20 29 0a 20 20 20 20 20 20 20 20 20 20 20 |1] ). | 00000750 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 | {. | 00000760 20 20 20 63 61 73 65 20 27 63 27 20 3a 20 63 6f | case 'c' : co| 00000770 75 6e 74 20 2b 3d 20 53 65 74 43 61 73 65 53 65 |unt += SetCaseSe| 00000780 6e 73 69 74 69 76 69 74 79 28 20 26 61 72 67 76 |nsitivity( &argv| 00000790 5b 63 6f 75 6e 74 5d 20 29 3b 0a 20 20 20 20 20 |[count] );. | 000007a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 000007b0 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 0a 20 20 | break;.. | 000007c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63 61 | ca| 000007d0 73 65 20 27 6f 27 20 3a 20 63 6f 75 6e 74 20 2b |se 'o' : count +| 000007e0 3d 20 53 65 74 4f 75 74 70 75 74 46 69 6c 65 28 |= SetOutputFile(| 000007f0 20 26 61 72 67 76 5b 63 6f 75 6e 74 5d 20 29 3b | &argv[count] );| 00000800 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |. | 00000810 20 20 20 20 20 20 20 20 20 20 20 20 62 72 65 61 | brea| 00000820 6b 3b 0a 0a 20 20 20 20 20 20 20 20 20 20 20 20 |k;.. | 00000830 20 20 20 20 63 61 73 65 20 27 73 27 20 3a 20 63 | case 's' : c| 00000840 6f 75 6e 74 20 2b 3d 20 53 65 74 57 6f 72 64 53 |ount += SetWordS| 00000850 69 7a 65 28 20 26 61 72 67 76 5b 63 6f 75 6e 74 |ize( &argv[count| 00000860 5d 20 29 3b 0a 20 20 20 20 20 20 20 20 20 20 20 |] );. | 00000870 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000880 62 72 65 61 6b 3b 0a 0a 20 20 20 20 20 20 20 20 |break;.. | 00000890 20 20 20 20 20 20 20 20 63 61 73 65 20 27 72 27 | case 'r'| 000008a0 20 3a 20 63 6f 75 6e 74 20 2b 3d 20 53 65 74 52 | : count += SetR| 000008b0 65 70 65 61 74 43 6f 75 6e 74 28 20 26 61 72 67 |epeatCount( &arg| 000008c0 76 5b 63 6f 75 6e 74 5d 20 29 3b 0a 20 20 20 20 |v[count] );. | 000008d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 000008e0 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 0a 20 | break;.. | 000008f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 64 | d| 00000900 65 66 61 75 6c 74 20 20 3a 20 70 72 69 6e 74 66 |efault : printf| 00000910 28 20 22 55 6e 6b 6e 6f 77 6e 20 63 6f 6d 6d 61 |( "Unknown comma| 00000920 6e 64 20 27 25 73 27 5c 6e 22 2c 20 61 72 67 76 |nd '%s'\n", argv| 00000930 5b 63 6f 75 6e 74 5d 20 29 3b 0a 20 20 20 20 20 |[count] );. | 00000940 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000950 20 20 20 20 20 20 63 6f 75 6e 74 2b 2b 3b 0a 20 | count++;. | 00000960 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 20 20 | }. | 00000970 20 20 20 20 20 7d 0a 0a 20 20 20 20 20 20 20 20 | }.. | 00000980 72 65 74 75 72 6e 20 54 52 55 45 3b 0a 20 20 20 |return TRUE;. | 00000990 20 7d 0a 20 20 20 20 65 6c 73 65 0a 20 20 20 20 | }. else. | 000009a0 7b 0a 20 20 20 20 20 20 20 20 70 75 74 73 28 20 |{. puts( | 000009b0 22 4e 6f 20 69 6e 70 75 74 20 66 69 6c 65 20 6e |"No input file n| 000009c0 61 6d 65 20 73 75 70 70 6c 69 65 64 2e 22 20 29 |ame supplied." )| 000009d0 3b 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e |;. return| 000009e0 20 46 41 4c 53 45 3b 0a 20 20 20 20 7d 0a 7d 0a | FALSE;. }.}.| 000009f0 0a 0a 69 6e 74 20 6d 61 69 6e 28 20 69 6e 74 20 |..int main( int | 00000a00 61 72 67 63 2c 20 63 68 61 72 20 2a 61 72 67 76 |argc, char *argv| 00000a10 5b 5d 20 29 0a 7b 0a 20 20 20 20 77 6f 72 64 20 |[] ).{. word | 00000a20 6c 69 73 74 20 3d 20 4e 55 4c 4c 3b 0a 20 0a 20 |list = NULL;. . | 00000a30 20 20 20 69 66 20 28 20 48 61 6e 64 6c 65 43 6f | if ( HandleCo| 00000a40 6d 6d 61 6e 64 4c 69 6e 65 28 20 61 72 67 63 2c |mmandLine( argc,| 00000a50 20 61 72 67 76 20 29 20 29 20 0a 20 20 20 20 7b | argv ) ) . {| 00000a60 0a 20 20 20 20 20 20 20 20 52 65 61 64 46 69 6c |. ReadFil| 00000a70 65 28 20 49 6e 46 69 6c 65 4e 61 6d 65 2c 20 26 |e( InFileName, &| 00000a80 6c 69 73 74 20 29 3b 0a 20 20 20 20 20 20 20 20 |list );. | 00000a90 57 72 69 74 65 46 69 6c 65 28 20 4f 75 74 46 69 |WriteFile( OutFi| 00000aa0 6c 65 4e 61 6d 65 2c 20 6c 69 73 74 20 29 3b 0a |leName, list );.| 00000ab0 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 30 | return 0| 00000ac0 3b 0a 20 20 20 20 7d 0a 20 20 20 20 65 6c 73 65 |;. }. else| 00000ad0 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 |. return | 00000ae0 31 3b 0a 7d 0a 0a |1;.}..| 00000ae6