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 >
Text File  |  1990-08-19  |  6KB  |  123 lines

  1.                             RAM  CRAM
  2.  
  3.  
  4. ------------------------------------------------------------------------------
  5. Screenfull is an exciting challenge for programmers - to write a program (or
  6. even just a subroutine) that will fit on one standard monitor or TV screen.
  7. That's about 22 lines. The program can be a game, utility, graphic designer,
  8. music and MIDI editor or even a business program, the choice is yours. You can
  9. also use any programming language such as Basic, C, Pascal, STOS or 68000
  10. machine code, but remember, the whole of the source code must fit onto one
  11. screen. Send your submissions in to the Disk Editor.
  12. ------------------------------------------------------------------------------
  13.  
  14. This month's two Screenfull submissions are supplied by programmer Les Kneeling
  15. of Ilford, Essex East Hoathly in Sussex. The first is the classic utility
  16. program Whereis? This has been implimented on a number of micros and it is used
  17. to track down an illusive file that you can't find. When you have 30 or 40Mb of
  18. hard disk space and possible several hundred files, finding the one you want
  19. can be difficult. Pass the filename to WHEREIS?.TTP and it will seek it out and
  20. tell you the complete pathname.
  21.  
  22.     The challenge to write a useful program which would fit into a single
  23. screen turned out to be difficult in C because the #includes must be one per
  24. line, and the struct used to manipulate the information returned by a directory
  25. search is eight lines long.
  26.  
  27.     However, with a shoehorn and a few multi-statement lines he managed to
  28. produce a program that will recursively search a disk for the filename passed
  29. to it as a parameter. When it finds an exact match for the filename it displays
  30. the full pathname on the screen. If there are several files with the same name
  31. on the disk it will list them all. Only the current drive is searched.
  32.  
  33.     If you want to try to make sense of the listing I suggest that you start by
  34. putting a CR after each semicolon and each curly bracket.
  35.  
  36.  
  37. /*----------------------------------------------------------------------------
  38.   WHEREIS? - by Les Kneeling
  39.  
  40.   Lost a file? Don't know which folder it is in? Give the file name to
  41.   WHEREIS? and it will search all of the disk for it. When it finds an
  42.   exact match for the filename it will display the full path on screen.
  43.   WHEREIS? will find all of the files with the specified name on the
  44.   disk. Only exact matches will be found. Sorry about the readability of
  45.   the code but it was the only way I could get it into 22 lines.
  46. ----------------------------------------------------------------------------*/
  47. #include <stdio.h>      /* WHEREIS.TTP - search a disk for a lost file(s)   */
  48. #include <osbind.h>     /* Written in Laser C by Les Kneeling               */
  49. #include <strings.h>
  50. typedef struct dta{ char r[21]; char fattr; char r2[8]; char fname[14]; };
  51. char spec[15], path[160] = "\\";
  52. main( argc, argv )
  53. int argc;
  54. char **argv;{
  55. strcpy( spec, argv[1] );strcat( path, spec );
  56. locate( path ); puts("Finished");Cconin(); }
  57.  
  58. locate( path ) char *path;{ struct dta newdta;
  59. int error; char newpath[160], temp[160];
  60. strcpy( newpath, path );Fsetdta( &newdta );
  61. error = Fsfirst( newpath, 0x0 );
  62. while(!error){ if( strcmp( newdta.fname, spec ) == 0 )
  63.     puts( newpath );error = Fsnext(); }
  64. *rindex( newpath, '\\' ) = 0; strcat( newpath, "\\*.*" );
  65. error = Fsfirst( newpath, 0x10 ); while(!error){
  66. if((newdta.fattr && 0x10)&&(newdta.fname[0] != '.') ){ strcpy(temp,newpath);
  67.     sprintf( rindex( temp, '\\' ), "\\%s\\%s", newdta.fname, spec );
  68.     locate( temp ); Fsetdta( &newdta ); } error = Fsnext();     } }
  69. /*--------------------------------------------------------------------------*/
  70.  
  71.  
  72.      Les Kneeling's second utility, TAB22, was also written in response to the
  73. Screenfull challenge. Since one of the requirements for files to reproduce
  74. properly in the magazine is that they have no tabs in them, it seemed
  75. reasonable to produce a program that removes them.
  76.  
  77.     Of course it would not be sufficient to simply replace each occurrence of a
  78. tab character (0x09) with say four spaces. This would result in a ragged
  79. listing. What is actually needed is to replace the character with the required
  80. number of spaces to move the cursor to the next tab column. The program does
  81. this by working out how far the character is from the last tab column using:
  82.  
  83. current_column%tabsize
  84.  
  85.     It then outputs the spaces needed to reach the next tab column:
  86.  
  87. tabsize - current_column%tabsize
  88.  
  89.     The listing as it stands has a fixed tab size of 4, which strangely enough
  90. is what I use, although it would be simple to modify it - I would suggest that
  91. you restore it to a more normal state by making it one statement per line
  92. first. The program is called from the desktop by double clicking on the icon
  93. and supplying INPUT.EXT OUTPUT.EXT when requested. There is sufficient error
  94. trapping in the program for most cases, but you must ensure that the input and
  95. output files have different names.
  96.  
  97.  
  98. /*----------------------------------------------------------------------------
  99.     A 22-line utility for replacing tabs with spaces in files for the
  100.     Atari ST User   disk magazine - by Les Kneeling
  101. ----------------------------------------------------------------------------*/
  102. #include <stdio.h>
  103. FILE *input, *output;
  104. main( argc, argv ) int argc; char **argv; {
  105. if( argc != 3 ){ puts("Use TAB22 INFILE.EXT OUTFILE.EXT"); getchar(); }
  106. else  {   input = fopen( argv[1], "br" );
  107.           if( input != 0l ) { output = fopen( argv[2], "bw" );
  108.                             if( output != 0l ) convert();fclose( input ); }
  109. if( output != 0l) fclose( output ); }
  110. }
  111. convert() { int out_count = 0; char offset, oc, letter;
  112. letter = fgetc( input );
  113. while( !feof( input ) ) {
  114.     if( letter == 9 ){  offset = 4-(out_count%4);
  115.                         for (oc=0; oc < offset ; oc++)  fputc( 32, output );
  116.                         out_count += offset;    }
  117.     else if( letter == 0x0a ){  fputc( letter, output );    out_count = 0;}
  118.     else{   fputc( letter, output );    out_count++;    }
  119.     if( out_count > 79 ){   fputc( 13, output );    out_count = 0;  }
  120.     letter = fgetc( input );    }
  121. }
  122. /*--------------------------------------------------------------------------*/
  123.