home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d5xx
/
d510
/
atcopy.lha
/
ATCopy
/
FileRequester
/
kd_freq.doc
< prev
next >
Wrap
Text File
|
1991-06-29
|
17KB
|
441 lines
kd_freq.library Release 2.00
--------------- ------------
By: Khalid Aldoseri
'kd_freq.library' is a standard Amiga library that has three functions:
FReq(), Path() and PatMatch(). FReq() calls my file requester (FR) so that
any program can use it. The FR is totally reentrant, and you can have
multiple programs calling it simultaenously. Path() simply returns
the full path to a file or directory. PatMatch() implements AmigaDOS style
wildcard pattern matching.
To open the library, use OpenLibrary() like any other normal Amiga library.
Look at test.c for the exact opening procedure. You will need to assemble
and link glue.asm (either manx.glue.asm or lattice.glue.asm) along with your
own object files.
e.g. for Manx:
cc +l test.c
as glue.asm
ln test.o glue.o -lc32
AutoDocs:
------------------------------------------------------------------------------
kd_freq.library/FReq
NAME
FReq - bring up a file requester and obtain a file name.
SYNOPSIS
result = FReq(screen,reqtitle,filename,directory,pattern,flags,extras);
LONG result
struct Screen *screen;
UBYTE *reqtitle;
UBYTE *filename;
UBYTE *directory;
UBYTE *pattern;
ULONG flags;
struct ExtraData *extras;
FUNCTION
Accepts a default directory name, default file name, and a
default pattern (standard AmigaDOS wildcard pattern) and returns
a selected directory, selected file name, and last pattern used
in the same variables that were used to call the requester.
The 'screen' argument is a pointer to a Screen structure. This tells
the file requester to show up on a specific screen. If you use
NULL, then the FR will show up on the WorkBench screen.
'reqtitle' is the title that will appear as the title of the file
requester.
'flags' is a set of flags that control the operation of the FR.
The flags are the following:
FR_NOINFO Do not show any file that ends with <.info>.
The user can change this setting later by
clicking on the 'I' gadget.
FR_NORESIZE Do not allow the user to resize the FR.
FR_NOTITLEBAR Do not show the close window gadget, the drag
bar, or the front/back gadgets. The title still
gets displayed. This makes the FR non-movable.
This also automatically triggers FR_NORESIZE.
If you don't provide a title the file list will
resize and fill in the empty space.
FR_AUTOPOSITION Tells the FR to decide where it wants to come up
on its own. (i.e. ignore LeftEdge and TopEdge)
FR_AUTOSIZE Tells the FR to decide its size on its own.
(i.e. ignore Width and Height)
FR_OKTEXT Tells the FR that we specified an alternate
OK text in 'extras.oktext'.
FR_CANCELTEXT Tells the FR that we specified an alternate
'Cancel' text in 'extras.canceltext'.
FR_DUALWILD When you set this flag, the wildcard pattern
you provide in 'pattern' is fixed and is applied
to all files in the FR. The user then gets a
second wildcard in the Wildcard gadget. (this
defauls to #?). In essence, this allows you
to specify a pattern that will appply to ALL
the FR, no matter what the user selects as a
wildcard. The user's wildcard is applied to
a file after it passes from the first wildcard.
FR_FRONTSCREEN Forces the FR to come up on the front screen.
FR_NOTEXTSHADOW Turns off the text shadowing in all of the FR.
FR_NEWFONT Tells the FR to use a different font than the
standard Topaz 8. This can be any fixed spacing
font from 5 to 16 in size. NO sanity checking is
done on the font size. It is up to you to see
how the font looks like. The FR will rescale
everything to suit the new font. You need to
provide a pointer to a TextFont structure in
extras->NewFont.
FR_SCREENFONT As above, but uses the current font on the screen
the FR will show up on. This always overrides
FR_NEWFONT.
FR_REPLACEIMAGES Replaces the standard images in the FR with
the users's own. The ExtraData struct below
shows where to place each pointer. You can
use any depth of bitplanes as long as they match
the same width/height as the original gadgets.
Be creative! Note that the size of the imagery
changes with the requested font size.
FR_EXTENDEDSELECT Read the section on Extended Select below.
FR_INVERTLOOK Set this flag for an 'inverted' look for the file
list. This is intended for use with 'save' calls
so that the user gets a visual difference between
save and load requesters.
FR_HIDEWILD Set this flag and point extras.Hide to a character
string of at least 32 bytes. This should contain
the default wildcard pattern to Hide. i.e. any
file matching this wildcard will not be shown in
the file list.
FR_NEWLOOK If you set this flag the FR will change the
way it looks to make it match the look of
Intuition 2.0 and above. This is automatically
set if Intuition's version number is 36 or more.
You should set this flag if you know that you
are running under 2.0 or above. The automatic
enable might be removed in a later version.
These flags are defined in KDBase.h. You can OR any of these flags
together. There are no restrictions on which flags can be or'd with
others.
The 'extras' is a struct ExtraData (as defined in KDBase.h).
struct ExtraData {
struct Image *UpArrow; /* replacement image for Up Arrow */
struct Image *DnArrow; /* replacement image for Down Arrow */
struct Image *DiskNormal; /* replacement image for Disks */
struct Image *DiskSelected; /* replacement select image for Disks */
struct Image *SizeStrip; /* replacement image for Size gadgets */
UBYTE *oktext; /* text to be used as OK text */
UBYTE *canceltext; /* text to be used as CANCEL text */
USHORT LeftEdge,TopEdge,Width,Height;
struct TextFont *NewFont; /* New Font to use instead of Topaz 8 */
struct FileList *ExtendedList; /* Always set to NULL at first call. */
/* If FR_EXTENDEDSELECT is set, this will */
/* return a linked list of FileList structs. */
UBYTE *Hide; /* Default hide wildcard */
/* Must set FR_HIDEWILD for it to be used */
/* Will contain a copy of the last wildcard */
/* the user set before exiting the FR on exit */
ULONG unused[4]; /* for future expansion. Always set to NULL */
};
You can request a specific LeftEdge, TopEdge, Width, and Height
by giving a non-zero value in any of the above arguments. However,
it is recommended that you do not. The requester will attempt to
come back up where it was the last time if you don't give it the
FR_AUTOSIZE and/or FR_AUTOPOSITION flags. The default values are:
LeftEdge 120
TopEdge 20
Width 400
Height 152
'oktext' is the text that will be shown in the 'OK' gadget. This
should be something like "Load" or "Save" or whatever. The string
must not be longer than 7 characters or it will be truncated. Make
sure that you set the FR_OKTEXT as described above.
'canceltext' is the text that will be shown in the 'Cancel' gadget.
This should be something like "No!" or whatever. The string
must not be longer than 7 characters or it will be truncated. Make
sure that you set the FR_CANCELTEXT as described above.
RESULT
directory - selected path
filename - selected file
pattern - last pattern used
result - 1 = success, 0 = requester cancelled or failed.
Note: UBYTE directory must be least UBYTE [128] in size.
and filename and pattern, [32].
e.g.
UBYTE directory[128];
UBYTE filename[32];
UBYTE pattern[32];
Also, make sure that they are either initialized with
default values, or zero'd out.
BUGS
None.
EXAMPLE
See the file test.c for a detailed example.
EXTENDED SELECT
-----------------
The FR can allow the user to select multiple files from a single directory.
To turn on this mode, you must set the FR_EXTENDEDSELECT flag in the FReq()
call. You must also define an extras structure and pass it in the call.
Make sure that extras.ExtendedList is NULL'd out before the first time you
call FReq().
When the FReq() call returns, you can check whether or not the user selected
multiple files by checking to see if extras.ExtendedList contains a value.
If it is not NULL, then it points to a linked list of struct FileList entries.
This returned list is yours until you free it. The library will not free it
for you unless you call FReq() again without clearing the extras.ExtendedList
pointer.
The following is an example of how to use the Extended Select mode:
struct ExtraData extras;
struct FileList *ext;
extras.ExtendedList = NULL;
if (FReq(NULL,"Test",name,dir,pat,
FR_EXTENDEDSELECT | FR_AUTOPOSITION | FR_AUTOSIZE,&extras))
{
printf("File Selected: %s%s\n",dir,name);
if (extras.ExtendedList) /* Check if the user selected a */
{ /* list of files. */
ext = extras.ExtendedList;
printf("\nExtended Select List: (%ld bytes)\n\n",ext->private);
printf(" Size File Name\n");
printf(" ------- -----------------------------------------\n");
/* This just prints out the selected files and their size. */
for (; ext; ext = ext->next)
{
printf("%8ld %s%s\n",ext->FileSize,directory,ext->FileName);
}
/* VERY IMPORTANT!! YOU MUST HAVE THIS IN! */
/* If the call returned a pointer to an ExtendedList */
/* then you must free it before you exit with the following */
/* FreeMem() call. */
/* You can also just leave the extras.ExtendedList pointer */
/* in the extras struct when you call FReq() again. Freq() */
/* In this case will FreeMem() the list for you and give you */
/* a new one if need be. */
FreeMem(extras.ExtendedList,extras.ExtendedList->private);
/* Clear out list pointer so that a subsequent call to FReq() */
/* doesn't try to FreeMem() it. */
extras.ExtendedList = NULL;
}
}
Notes:
- It is best to AllocMem() the extras structure since that will ensure that
it is all NULL'd out before use.
- The call returns both a normal file name and a list of files. It is up to
the calling program to clarify this point to the user.
- Check out the manx.ext.test.c file for the full example on how to use
this facility.
- The FR_User.DOC file contains all the details on how the user can use the
Extended Select mode.
------------------------------------------------------------------------------
kd_freq.library/Path
NAME
Path - expand a file name to its full path.
SYNOPSIS
Path(filename);
UBYTE *filename;
FUNCTION
Accepts a string that a valid AmigaDOS file or directory name and
expands it to the full path leading to the file/directory name.
RESULT
filename - full path
Note: UBYTE *filename must be least UBYTE [128] in size.
e.g. UBYTE filename[128];
The string is terminated with either a / or a : depending on whether
it is a valid directory or device.
If the filename is not a valid file name, then 'filename' is truncated
to 0 length;
BUGS
None.
EXAMPLE
UBYTE filename[128] = "dh0:";
Path(filename);
------------------------------------------------------------------------------
kd_freq.library/PatMatch
NAME
PatMatch - do AmigaDOS style wild card filename pattern matching.
SYNOPSIS
result = PatMatch(pattern,filename);
LONG result
UBYTE *pattern;
UBYTE *filename;
FUNCTION
Accepts a string that is a valid AmigaDOS file name (filename) and
a valid AmigaDOS wild card pattern and tells you whether the
filename matches the pattern or not.
Supported wildcards in pattern:
1. Standard AmigaDOS Wildcards:
--------------------------------
? Matches any single character
#p Match any number of occurences of the pattern p
% Matches the null string
() Make a group of characters into a single pattern
| The OR operator
' Disable wildcard interpretation of next character
(unless it is an extended wildcard as shown below.)
2. Extended Wildcards:
-----------------------
These are wildcards not supported by the standard AmigaDOS
convention, but expand it to make it more versatile.
'd Matches any single digit. (0 to 9)
'a Matches any single alpha character. (a to z)
'n Matches any single alphanumeric character.
For examples of standard wildcard usage, look up any AmigaDOS
tutorial book.
Examples of extended wildcards:
Pattern Matching possibilities
------- ----------------------
test'n test0, test1, test9, testa, testA, testz, testZ
test'd test0, test1, test9
test'a testa, testA, testz, testZ
test 'd test 1, test 2, test 9
test#'d test1, test100, test10234
#'a#'d a1, ab12, abc1, abc123, adks34234
(matches any string with some or no alpha characters,
then some or no digits.)
#'a'd#'d.c a1.c, a203.c, 100.c, 1.c, adsdfs931234.c
(matches any string that starts with some of no alpha
characters, then at least 1 or more digits, and ends
with .c)
RESULT
result = -1 Syntax error in wildcard pattern.
result = 0 Filename did not match pattern.
result = 1 Filename matched pattern.
BUGS
None.
EXAMPLE
LONG result;
result = PatMatch("#?.c","test.c");
This will result in: result == 1
------------------------------------------------------------------------------
If you have any trouble getting any call to work, don't hesitate to email me
on Compuserve 75166,2531 or leave me a message in the AmigaTech forum on CIS
or mail/fax me at the address at the end of the FR_User.doc file.
------------------------------------------------------------------------------
Copyright 1990 Khalid Aldoseri.
19 July 1990.
------------------------------------------------------------------------------