home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_USER / 1990 / USERAU90.MSA / TEXT_SCREENFL.DOC < prev    next >
Text File  |  1990-06-24  |  6KB  |  129 lines

  1.                             CRAM MORE INTO RAM
  2.  
  3.  
  4. ------------------------------------------------------------------------------
  5. Screenfull is an exciting new challenge for programmers _ to write a program
  6. (or even just a subroutine) that will fit on one standard monitor or TV screen.
  7. The program can be a game, utility, graphic designer, music and MIDI editor or
  8. even a business program , the choice is yours. You can also use any programming
  9. language such as Basic, C, Pascal, STOS or 68000 machine code, but remember,
  10. the whole of the source code must fit onto one screen.
  11. ------------------------------------------------------------------------------
  12.  
  13. This month's Screenfull submissions are all supplied by programmer Janice
  14. Murray and demonstrate how to call up GEM's fileselector from within your own
  15. programs to input a filename. It doesn't matter whether you use HiSoft or Fast
  16. BASIC, or dabble in C as all three languages are catered for.
  17.  
  18.     You'll also see that the same technique is used each time and if you use
  19. some other programming language, such as Pascal, then converting the code
  20. should be quite easy.
  21.  
  22.     The core of any file selector routine is the GEM function:
  23.  
  24. fsel_input(path,name,button)
  25.  
  26.     The 'path' string parameter is the drive and directory to be displayed,
  27. such as "A:\DOCS\*.TXT" and the 'name' string parameter is the default name,
  28. such as "NONAME.DOC". The value of the 'button' integer parameter  doesn't
  29. matter.
  30.  
  31.     After the function call the integer parameter 'button' has a value of zero
  32. if the Cancel button was clicked on or one if OK was clicked on. The 'name'
  33. string contains the name you typed in or clicked on and the 'path' string
  34. contains the path (which may be different to the one you supplied.
  35.  
  36.     Assuming that 'path' is  "A:\DOCS\*.TXT" and 'name' is "NONAME.DOC", after
  37. the function call to fsel_input, the full pathname for the file is
  38. "A:\DOCS\NONAME.DOC" - a combination of the path and name. Notice that the
  39. "*.TXT" is chopped off the end of the path and then the name is added to it.
  40.  
  41.     Let's see how this fuction call is implemented in HiSoft BASIC. Here is a
  42. function called FNselect_file which prompts the user to enter a filename into
  43. the file selector and returns the full pathname:
  44.  
  45. DEF FNfilename$
  46. path$ = CHR$(65+FNdgetdrv%) + ":\*.*"
  47. name$ = ""
  48. ok% = 0
  49. fsel_input path$,name$,ok%
  50. WHILE right$(path$,1)<>"\"
  51.      path$ = LEFT$(path$,LEN(path$)-1)
  52. WEND
  53. IF ok%=0 OR name$="" THEN path$="" : name$=""
  54. FNfilename$ = path$ + name$
  55. END DEF
  56.  
  57.     First the path is set up in the string variable path$, and this consists of
  58. the currently selected drive (the function FNdgetdrv% tells you this), plus
  59. ":\*.*". The default name is left blank. After calling fsel_input the "*.*" is
  60. removed from path$ and the complete pathname is path$+name$. Note the check for
  61. the Cancel button or no name input.
  62.  
  63.     To use this file selector function you would include a line like this in
  64. your program:
  65.  
  66. file$ = FNfilename$
  67.  
  68.     Now let's take a look at the FAST BASIC version of this short routine:
  69.  
  70. DEF FNselect_file
  71. LOCAL file$, name$, button%
  72. file$ = PATH$ + "*.*"
  73. name$ = ""
  74. button% = 0
  75. FSELECT file$ ,name$, button%
  76. IF button%=0 OR name$="" THEN = ""
  77. WHILE RIGHT$(file$,1)<>"\"
  78.      file$ = LEFT$(file$,LEN(file$)-1)
  79. WEND
  80. CLS
  81. = file$ + name$
  82.  
  83.     As you can see, it is almost identical, apart from the name change from
  84. fsel_input to FSELECT. All varieties of BASIC will use very similar code to
  85. call up the file selector and once you have seen one you have seen them all. So
  86. let us C something completely different:
  87.  
  88. get_file()
  89. {
  90.     short button,len;
  91.     strcpy(path,"A:\\*.*");            /* default path */
  92.     path[0] += Dgetdrv();              /* set to current drive */
  93.     strcpy(name,"");                   /* null filename */
  94.     fsel_input(path,name,&button);     /* do file selector */
  95.     graf_mouse(0,0);                   /* change mouse to pointer */
  96.     if ( name[0]=='\0' || button==0 )
  97.          return(0);                    /* no filename or Cancel pressed */
  98.      len = strlen(path);
  99.      while ( path[len-1]!='\\' )       /* knock out *.* from path */
  100.           --len;
  101.      path[len] = '\0';                 /* mark end of path with zero */
  102.      strcat(path,name);                /* concatenate strings */
  103.      return(1);
  104. }
  105.  
  106.     At first sight, this looks very different indeed, however, a closer
  107. inspection will reveal that it closely follows the form of the previous two
  108. examples. The default path and name strings are set up, fsel_input is called
  109. and then the path and name are concatenated. (A check is made for Cancel or no
  110. filename).
  111.  
  112.     The C code is slightly longer than BASIC, but the structure is the same. A
  113. Pascal version could also be constructed in a similar way, but I'll leave that
  114. as an execise for you to attempt.
  115.  
  116.  
  117. ------------------------------------------------------------------------------
  118. Executable programs using these file selector functions can be found in the
  119. LISTINGS folder and are called FSELECT.BAS, FSELECT.BSC and FSELECT.C. This
  120. last program is larger than a screenfull, but the file selector function
  121. get_file() (which, after all, is what this submission is all about), does fit
  122. on one screen and so can be classed as a Screenfull contribution.
  123. ------------------------------------------------------------------------------
  124.  
  125.  
  126. HARDWARE: ALL STs, MONO AND COLOUR
  127.  
  128.  
  129.