/*
* tkFileFilter.c --
*
* Process the -filetypes option for the file dialogs on Windows and the
* Mac.
*
* Copyright (c) 1996 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkFileFilter.c 1.4 96/08/28 22:15:14
*
*/
#include "tkInt.h"
#include "tkFileFilter.h"
static int AddClause _ANSI_ARGS_((
char * patternsStr, char * ostypesStr,
int isWindows));
static void FreeGlobPatterns _ANSI_ARGS_((
static void FreeMacFileTypes _ANSI_ARGS_((
char * name));
/*
*----------------------------------------------------------------------
*
* TkInitFileFilters --
*
* Initializes a FileFilterList data structure. A FileFilterList
* must be initialized EXACTLY ONCE before any calls to
* TkGetFileFilters() is made. The usual flow of control is:
* TkInitFileFilters(&flist);
* TkGetFileFilters(&flist, ...);
* TkGetFileFilters(&flist, ...);
* ...
* TkFreeFileFilters(&flist);
*
* Results:
* None.
*
* Side effects:
* The fields in flistPtr are initialized.
*----------------------------------------------------------------------
*/
void
{
flistPtr->numFilters = 0;
}
/*
*----------------------------------------------------------------------
*
* TkGetFileFilters --
*
* This function is called by the Mac and Windows implementation
* of tk_getOpenFile and tk_getSaveFile to translate the string
* value of the -filetypes option of into an easy-to-parse C
* structure (flistPtr). The caller of this function will then use
* flistPtr to perform filetype matching in a platform specific way.
*
* flistPtr must be initialized (See comments in TkInitFileFilters).
*
* Results:
* A standard TCL return value.
*
* Side effects:
* The fields in flistPtr are changed according to string.
*----------------------------------------------------------------------
*/
int
char * string; /* Value of the -filetypes option. */
int isWindows; /* True if we are running on Windows. */
{
int listArgc;
int i;
return TCL_ERROR;
}
if (listArgc == 0) {
goto done;
}
/*
* Free the filter information that have been allocated the previous
* time -- the -filefilters option may have been used more than once in
* the command line.
*/
for (i = 0; i<listArgc; i++) {
/*
* Each file type should have two or three elements: the first one
* is the name of the type and the second is the filter of the type.
* The third is the Mac OSType ID, but we don't care about them here.
*/
int count;
goto done;
}
"should be \"typeName {extension ?extensions ...?} ",
"?{macType ?macTypes ...?}?\"", NULL);
goto done;
}
if (count == 2) {
} else {
}
goto done;
}
if (typeInfo) {
}
}
done:
if (typeInfo) {
}
if (listArgv) {
}
return code;
}
/*
*----------------------------------------------------------------------
*
* TkFreeFileFilters --
*
* Frees the malloc'ed file filter information.
*
* Results:
* None.
*
* Side effects:
* The fields allocated by TkGetFileFilters() are freed.
*----------------------------------------------------------------------
*/
void
{
while (filterPtr) {
}
}
/*
*----------------------------------------------------------------------
*
* AddClause --
*
* Add one FileFilterClause to filterPtr.
*
* Results:
* A standard TCL result.
*
* Side effects:
* The list of filter clauses are updated in filterPtr.
*----------------------------------------------------------------------
*/
char * patternsStr; /* A TCL list of glob patterns. */
char * ostypesStr; /* A TCL list of Mac OSType strings. */
int isWindows; /* True if we are running on Windows; False
* if we are running on the Mac; Glob
* patterns need to be processed differently
* on these two platforms */
{
int globCount;
int ostypeCount;
int i;
goto done;
}
if (ostypesStr != NULL) {
!= TCL_OK) {
goto done;
}
for (i=0; i<ostypeCount; i++) {
goto done;
}
}
}
/*
* Add the clause into the list of clauses
*/
} else {
}
for (i=0; i<globCount; i++) {
int len;
/*
* Prepend a "*" to patterns that do not have a leading "*"
*/
}
else if (isWindows) {
}
/*
* An empty string means "match all files with no
* extensions"
* BUG: "*." actually matches with all files on Win95
*/
}
else {
}
} else {
}
/*
* Add the glob pattern into the list of patterns.
*/
} else {
}
}
}
for (i=0; i<ostypeCount; i++) {
/*
* Add the Mac type pattern into the list of Mac types
*/
} else {
}
}
}
done:
if (globList) {
}
if (ostypeList) {
ckfree((char*)ostypeList);
}
return code;
}
/*
*----------------------------------------------------------------------
*
* GetFilter --
*
* Add one FileFilter to flistPtr.
*
* Results:
* A standard TCL result.
*
* Side effects:
* The list of filters are updated in flistPtr.
*----------------------------------------------------------------------
*/
* newly created filter */
char * name; /* Name of the filter. It is usually displayed
* in the "File Types" listbox in the file
* dialogs. */
{
return filterPtr;
}
}
} else {
}
++flistPtr->numFilters;
return filterPtr;
}
/*
*----------------------------------------------------------------------
*
* FreeClauses --
*
* Frees the malloc'ed file type clause
*
* Results:
* None.
*
* Side effects:
* The list of clauses in filterPtr->clauses are freed.
*----------------------------------------------------------------------
*/
static void
{
while (clausePtr) {
}
}
/*
*----------------------------------------------------------------------
*
* FreeGlobPatterns --
*
* Frees the malloc'ed glob patterns in a clause
*
* Results:
* None.
*
* Side effects:
* The list of glob patterns in clausePtr->patterns are freed.
*----------------------------------------------------------------------
*/
static void
{
while (globPtr) {
}
}
/*
*----------------------------------------------------------------------
*
* FreeMacFileTypes --
*
* Frees the malloc'ed Mac file types in a clause
*
* Results:
* None.
*
* Side effects:
* The list of Mac file types in clausePtr->macTypes are freed.
*----------------------------------------------------------------------
*/
static void
* freed */
{
while (mfPtr) {
}
}