home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************\
- *
- * MODULE : EXTMASK.C
- *
- * PROGRAMS : HTMLENRM, HTMLENAD, CPCONV, UNWIACZ
- *
- * PURPOSE : Check of filename against list of valid/invalid extensions
- * for conversion and supporting variables and functions
- *
- \************************************************************************/
-
- #include <windows.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- #include "EXTMASK.H"
-
- static struct {
- char mask[11];
- BOOL valid;
- } Exts[50] = {{"*",TRUE}};
- static int nExt=1;
- static BOOL first=TRUE;
-
- void SetValidExtension (char *ext)
- {
- int n;
-
- n=strlen(ext);
- if (n<1 || n>10)
- return;
- if (first)
- {
- Exts[0].valid=FALSE;
- first=FALSE;
- nExt=1;
- }
- if (stricmp(ext,"*")==0)
- nExt=0;
- if (nExt>=50)
- return;
- strcpy(Exts[nExt].mask,ext);
- Exts[nExt].valid=TRUE;
- nExt++;
- }
-
- void SetInvalidExtension (char *ext)
- {
- int n;
-
- n=strlen(ext);
- if (n<1 || n>10)
- return;
- if (stricmp(ext,"*")==0)
- nExt=0;
- if (nExt>=50)
- return;
- first=FALSE;
- strcpy(Exts[nExt].mask,ext);
- Exts[nExt].valid=FALSE;
- nExt++;
- }
-
- void GetIniExtensionMasks (char *section, char *inifile)
- {
- char item[30],ext[12];
- char *c;
- int i=1;
-
- next:
- sprintf(item,"Extension%d",i);
- GetPrivateProfileString(section,item,"",ext,11,inifile);
- if (strlen(ext)>0)
- {
- if (i==1)
- {
- strcpy(Exts[0].mask,"*");
- Exts[0].valid=FALSE;
- nExt=1;
- }
- c=strchr(ext,',');
- Exts[nExt].valid=TRUE;
- if (c!=NULL)
- {
- *c='\0';
- c++;
- if (*c=='0')
- Exts[nExt].valid=FALSE;
- }
- strcpy(Exts[nExt].mask,ext);
- nExt++;
- i++;
- if (nExt<50)
- goto next;
- }
- }
-
- BOOL CheckFilenameExtension (char *filename)
- {
- int i,n;
- char *c,ext[11];
- BOOL valid;
-
- c=strrchr(filename,'.');
- if (c==NULL)
- strcpy(ext,"");
- else
- {
- i=strlen(filename);
- n=&filename[i]-c;
- if (n<1 || n>10)
- strcpy(ext,"");
- else
- strcpy(ext,&c[1]);
- }
-
- for (i=0;i<nExt;i++)
- {
- if (stricmp(Exts[i].mask,"*")==0)
- valid=Exts[i].valid;
- else if (stricmp(Exts[i].mask,ext)==0)
- valid=Exts[i].valid;
- }
- return (valid);
- }
-