home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
No Fragments Archive 10: Diskmags
/
nf_archive_10.iso
/
MAGS
/
ST_USER
/
1990
/
USEROC90.MSA
/
TEXT_SCREENFL.DOC
< prev
next >
Wrap
Text File
|
1990-08-19
|
6KB
|
123 lines
RAM CRAM
------------------------------------------------------------------------------
Screenfull is an exciting challenge for programmers - to write a program (or
even just a subroutine) that will fit on one standard monitor or TV screen.
That's about 22 lines. The program can be a game, utility, graphic designer,
music and MIDI editor or even a business program, the choice is yours. You can
also use any programming language such as Basic, C, Pascal, STOS or 68000
machine code, but remember, the whole of the source code must fit onto one
screen. Send your submissions in to the Disk Editor.
------------------------------------------------------------------------------
This month's two Screenfull submissions are supplied by programmer Les Kneeling
of Ilford, Essex East Hoathly in Sussex. The first is the classic utility
program Whereis? This has been implimented on a number of micros and it is used
to track down an illusive file that you can't find. When you have 30 or 40Mb of
hard disk space and possible several hundred files, finding the one you want
can be difficult. Pass the filename to WHEREIS?.TTP and it will seek it out and
tell you the complete pathname.
The challenge to write a useful program which would fit into a single
screen turned out to be difficult in C because the #includes must be one per
line, and the struct used to manipulate the information returned by a directory
search is eight lines long.
However, with a shoehorn and a few multi-statement lines he managed to
produce a program that will recursively search a disk for the filename passed
to it as a parameter. When it finds an exact match for the filename it displays
the full pathname on the screen. If there are several files with the same name
on the disk it will list them all. Only the current drive is searched.
If you want to try to make sense of the listing I suggest that you start by
putting a CR after each semicolon and each curly bracket.
/*----------------------------------------------------------------------------
WHEREIS? - by Les Kneeling
Lost a file? Don't know which folder it is in? Give the file name to
WHEREIS? and it will search all of the disk for it. When it finds an
exact match for the filename it will display the full path on screen.
WHEREIS? will find all of the files with the specified name on the
disk. Only exact matches will be found. Sorry about the readability of
the code but it was the only way I could get it into 22 lines.
----------------------------------------------------------------------------*/
#include <stdio.h> /* WHEREIS.TTP - search a disk for a lost file(s) */
#include <osbind.h> /* Written in Laser C by Les Kneeling */
#include <strings.h>
typedef struct dta{ char r[21]; char fattr; char r2[8]; char fname[14]; };
char spec[15], path[160] = "\\";
main( argc, argv )
int argc;
char **argv;{
strcpy( spec, argv[1] );strcat( path, spec );
locate( path ); puts("Finished");Cconin(); }
locate( path ) char *path;{ struct dta newdta;
int error; char newpath[160], temp[160];
strcpy( newpath, path );Fsetdta( &newdta );
error = Fsfirst( newpath, 0x0 );
while(!error){ if( strcmp( newdta.fname, spec ) == 0 )
puts( newpath );error = Fsnext(); }
*rindex( newpath, '\\' ) = 0; strcat( newpath, "\\*.*" );
error = Fsfirst( newpath, 0x10 ); while(!error){
if((newdta.fattr && 0x10)&&(newdta.fname[0] != '.') ){ strcpy(temp,newpath);
sprintf( rindex( temp, '\\' ), "\\%s\\%s", newdta.fname, spec );
locate( temp ); Fsetdta( &newdta ); } error = Fsnext(); } }
/*--------------------------------------------------------------------------*/
Les Kneeling's second utility, TAB22, was also written in response to the
Screenfull challenge. Since one of the requirements for files to reproduce
properly in the magazine is that they have no tabs in them, it seemed
reasonable to produce a program that removes them.
Of course it would not be sufficient to simply replace each occurrence of a
tab character (0x09) with say four spaces. This would result in a ragged
listing. What is actually needed is to replace the character with the required
number of spaces to move the cursor to the next tab column. The program does
this by working out how far the character is from the last tab column using:
current_column%tabsize
It then outputs the spaces needed to reach the next tab column:
tabsize - current_column%tabsize
The listing as it stands has a fixed tab size of 4, which strangely enough
is what I use, although it would be simple to modify it - I would suggest that
you restore it to a more normal state by making it one statement per line
first. The program is called from the desktop by double clicking on the icon
and supplying INPUT.EXT OUTPUT.EXT when requested. There is sufficient error
trapping in the program for most cases, but you must ensure that the input and
output files have different names.
/*----------------------------------------------------------------------------
A 22-line utility for replacing tabs with spaces in files for the
Atari ST User disk magazine - by Les Kneeling
----------------------------------------------------------------------------*/
#include <stdio.h>
FILE *input, *output;
main( argc, argv ) int argc; char **argv; {
if( argc != 3 ){ puts("Use TAB22 INFILE.EXT OUTFILE.EXT"); getchar(); }
else { input = fopen( argv[1], "br" );
if( input != 0l ) { output = fopen( argv[2], "bw" );
if( output != 0l ) convert();fclose( input ); }
if( output != 0l) fclose( output ); }
}
convert() { int out_count = 0; char offset, oc, letter;
letter = fgetc( input );
while( !feof( input ) ) {
if( letter == 9 ){ offset = 4-(out_count%4);
for (oc=0; oc < offset ; oc++) fputc( 32, output );
out_count += offset; }
else if( letter == 0x0a ){ fputc( letter, output ); out_count = 0;}
else{ fputc( letter, output ); out_count++; }
if( out_count > 79 ){ fputc( 13, output ); out_count = 0; }
letter = fgetc( input ); }
}
/*--------------------------------------------------------------------------*/