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 >
Wrap
Text File
|
1990-06-24
|
6KB
|
129 lines
CRAM MORE INTO RAM
------------------------------------------------------------------------------
Screenfull is an exciting new challenge for programmers _ to write a program
(or even just a subroutine) that will fit on one standard monitor or TV screen.
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.
------------------------------------------------------------------------------
This month's Screenfull submissions are all supplied by programmer Janice
Murray and demonstrate how to call up GEM's fileselector from within your own
programs to input a filename. It doesn't matter whether you use HiSoft or Fast
BASIC, or dabble in C as all three languages are catered for.
You'll also see that the same technique is used each time and if you use
some other programming language, such as Pascal, then converting the code
should be quite easy.
The core of any file selector routine is the GEM function:
fsel_input(path,name,button)
The 'path' string parameter is the drive and directory to be displayed,
such as "A:\DOCS\*.TXT" and the 'name' string parameter is the default name,
such as "NONAME.DOC". The value of the 'button' integer parameter doesn't
matter.
After the function call the integer parameter 'button' has a value of zero
if the Cancel button was clicked on or one if OK was clicked on. The 'name'
string contains the name you typed in or clicked on and the 'path' string
contains the path (which may be different to the one you supplied.
Assuming that 'path' is "A:\DOCS\*.TXT" and 'name' is "NONAME.DOC", after
the function call to fsel_input, the full pathname for the file is
"A:\DOCS\NONAME.DOC" - a combination of the path and name. Notice that the
"*.TXT" is chopped off the end of the path and then the name is added to it.
Let's see how this fuction call is implemented in HiSoft BASIC. Here is a
function called FNselect_file which prompts the user to enter a filename into
the file selector and returns the full pathname:
DEF FNfilename$
path$ = CHR$(65+FNdgetdrv%) + ":\*.*"
name$ = ""
ok% = 0
fsel_input path$,name$,ok%
WHILE right$(path$,1)<>"\"
path$ = LEFT$(path$,LEN(path$)-1)
WEND
IF ok%=0 OR name$="" THEN path$="" : name$=""
FNfilename$ = path$ + name$
END DEF
First the path is set up in the string variable path$, and this consists of
the currently selected drive (the function FNdgetdrv% tells you this), plus
":\*.*". The default name is left blank. After calling fsel_input the "*.*" is
removed from path$ and the complete pathname is path$+name$. Note the check for
the Cancel button or no name input.
To use this file selector function you would include a line like this in
your program:
file$ = FNfilename$
Now let's take a look at the FAST BASIC version of this short routine:
DEF FNselect_file
LOCAL file$, name$, button%
file$ = PATH$ + "*.*"
name$ = ""
button% = 0
FSELECT file$ ,name$, button%
IF button%=0 OR name$="" THEN = ""
WHILE RIGHT$(file$,1)<>"\"
file$ = LEFT$(file$,LEN(file$)-1)
WEND
CLS
= file$ + name$
As you can see, it is almost identical, apart from the name change from
fsel_input to FSELECT. All varieties of BASIC will use very similar code to
call up the file selector and once you have seen one you have seen them all. So
let us C something completely different:
get_file()
{
short button,len;
strcpy(path,"A:\\*.*"); /* default path */
path[0] += Dgetdrv(); /* set to current drive */
strcpy(name,""); /* null filename */
fsel_input(path,name,&button); /* do file selector */
graf_mouse(0,0); /* change mouse to pointer */
if ( name[0]=='\0' || button==0 )
return(0); /* no filename or Cancel pressed */
len = strlen(path);
while ( path[len-1]!='\\' ) /* knock out *.* from path */
--len;
path[len] = '\0'; /* mark end of path with zero */
strcat(path,name); /* concatenate strings */
return(1);
}
At first sight, this looks very different indeed, however, a closer
inspection will reveal that it closely follows the form of the previous two
examples. The default path and name strings are set up, fsel_input is called
and then the path and name are concatenated. (A check is made for Cancel or no
filename).
The C code is slightly longer than BASIC, but the structure is the same. A
Pascal version could also be constructed in a similar way, but I'll leave that
as an execise for you to attempt.
------------------------------------------------------------------------------
Executable programs using these file selector functions can be found in the
LISTINGS folder and are called FSELECT.BAS, FSELECT.BSC and FSELECT.C. This
last program is larger than a screenfull, but the file selector function
get_file() (which, after all, is what this submission is all about), does fit
on one screen and so can be classed as a Screenfull contribution.
------------------------------------------------------------------------------
HARDWARE: ALL STs, MONO AND COLOUR