home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / fm2000 / fileclick.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-04  |  6.6 KB  |  271 lines

  1. /*
  2.      Filemaster - Multitasking directory utility.
  3.      Copyright (C) 2000  Toni Wilen
  4.      
  5.      This program is free software; you can redistribute it and/or
  6.      modify it under the terms of the GNU General Public License
  7.      as published by the Free Software Foundation; either version 2
  8.      of the License, or (at your option) any later version.
  9.      
  10.      This program is distributed in the hope that it will be useful,
  11.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.      GNU General Public License for more details.
  14.      
  15.      You should have received a copy of the GNU General Public License
  16.      along with this program; if not, write to the Free Software
  17.      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20.  
  21. #include <proto/all.h>
  22. #include <exec/types.h>
  23. #include <intuition/intuition.h>
  24. #include <datatypes/datatypes.h>
  25. #include <datatypes/datatypesclass.h>
  26. #include <proto/datatypes.h>
  27. #include <strings.h>
  28. #include <stdio.h>
  29. #include "fmnode.h"
  30. #include "fmdos.h"
  31. #include "child.h"
  32. #include "fmlocale.h"
  33.  
  34. void showpicture(struct FMHandle*,struct CMenuConfig*);
  35. WORD showdatatypepicture(struct FMHandle*,struct DataType*,struct CMenuConfig*);
  36. void showicon(struct FMHandle*,struct CMenuConfig*);
  37. void showfont(struct FMHandle*,struct CMenuConfig*);
  38. void modplay(struct FMHandle*,struct CMenuConfig*);
  39. void executefile(struct FMHandle*,struct CMenuConfig*);
  40. void showtext(struct FMHandle*,struct CMenuConfig*);
  41. void playsample(struct FMHandle*,struct CMenuConfig*);
  42. WORD playdatatypesample(struct FMHandle*,struct DataType*,struct CMenuConfig*);
  43. extern struct Library *DataTypesBase;
  44.  
  45. #define MEMSIZE 2048
  46. extern struct FMMain fmmain;
  47. extern struct FMConfig *fmconfig;
  48.  
  49. void checkfile(struct FMHandle*,UBYTE*,struct FMNode*);
  50. void executeown(struct FMList*,struct FMList*,struct FMNode*,struct CMenuConfig*);
  51.  
  52. WORD isdatatypes(struct FMHandle *h,LONG dtype)
  53. {
  54. struct DataType *dtn=0;
  55. struct DataTypeHeader *dth;
  56. BPTR lock=0;
  57. WORD ret=-99;
  58.  
  59. if(!DataTypesBase) return(ret);
  60. if(h->flags&OFDECRUNCH) {
  61.     dtn=ObtainDataTypeA(DTST_RAM,h->decbuffer,NULL);
  62. } else {
  63.     lock=fmlock(h->owner,h->filename);
  64.     if(lock) dtn=ObtainDataTypeA(DTST_FILE,(APTR)lock,NULL);
  65. }
  66. if(dtn) {
  67.     dth = dtn->dtn_Header;
  68.     if(!dtype) {
  69.         if(dth->dth_GroupID==GID_PICTURE) {
  70.             dtype=GID_PICTURE;
  71.         }
  72.         if(dth->dth_GroupID==GID_SOUND) {
  73.             dtype=GID_SOUND;
  74.         }
  75.     }
  76.     if(dth->dth_GroupID==dtype) {
  77.             if(dtype==GID_PICTURE) ret=showdatatypepicture(h,dtn,getconfignumber(SHOWPICCONFIG));
  78.             if(dtype==GID_SOUND) ret=playdatatypesample(h,dtn,getconfignumber(HEARCONFIG));
  79.     }
  80.     ReleaseDataType(dtn);
  81. }
  82. if(lock) UnLock(lock);
  83. return(ret);
  84. }
  85.  
  86.  
  87. void __saveds clickfile(void)
  88. {
  89. struct ProcMsg *pm;
  90. struct FMList *list;
  91. register struct FMNode *node;
  92. struct FMHandle *h;
  93. UBYTE *mem;
  94. LONG len;
  95.  
  96. mem=0;
  97. list=fmmain.sourcedir;
  98. node=list->lastclicked;
  99. pm=sinitproc();
  100. if (!(setalloc(list,1))) {
  101.     initproc(0,0);
  102.     goto endi;
  103. }
  104. initproc(list,getstring(MSG_FILECLICKNAME));
  105. if (node&&(mem=allocvec(list,MEMSIZE,0))) {
  106.     sformatmsg(list->fmmessage1,MSG_FILECLICKING,NDFILE(node));
  107.     list->fmmessage2[0]=0;
  108.     fmmessage(list);
  109.     if (h=openfile(list,NDFILE(node),OFNORMAL|OFDECRUNCH)) {
  110.         len=h->size;
  111.         if (len>MEMSIZE) len=MEMSIZE;
  112.         if (readbufferfile(h,mem,len)==len) {
  113.             if (seek(h,0,OFFSET_BEGINNING)>=0) {
  114.                 list->fmmessage1[0]=0;
  115.                 list->fmmessage2[0]=0;
  116.                 fmmessage(list);
  117.                 node->flags|=NSELECTED;
  118.                 checkfile(h,mem,node);
  119.             }
  120.         }
  121.         closefile(h);
  122.         node->flags&=~NSELECTED;
  123.         outputlistline(list,node);
  124.     }
  125. }
  126. freemem(mem);
  127. list->lastclicked=0;
  128. endproc(list);
  129. endi:
  130. deinitproc(pm);
  131. }
  132.  
  133. static WORD testclick(struct FMHandle *h,struct FMNode *node,UBYTE *m,WORD usedt)
  134. {
  135. UWORD apu1,apu2;
  136. ULONG *apu;
  137. UBYTE *ptr1;
  138. WORD mod,cnt;
  139.  
  140. apu=(ULONG*)m;
  141. apu1=(UWORD)((*apu)>>16);
  142.  
  143. if ((fmconfig->usepicturedt|usedt)&&*apu=='FORM'&&*(apu+2)=='ILBM') {
  144.     showpicture(h,getconfignumber(SHOWPICCONFIG));
  145.     return(1);
  146. }
  147. if ((fmconfig->usesampledt|usedt)&&*apu=='FORM'&&*(apu+2)=='8SVX') {
  148.     playsample(h,getconfignumber(HEARCONFIG));
  149.     return(1);
  150. }
  151. if ((fmconfig->useexecutedt|usedt)&&*apu==0x3f3&&!(node->numprot&2)) {
  152.     executefile(h,getconfignumber(EXECUTECONFIG));
  153.     return(1);
  154. }
  155. if ((fmconfig->useicondt|usedt)&&*m==0xe3&&*(m+1)==0x10&&!Strnicmp(h->filename+strlen(h->filename)-5,".info",5)) {
  156.     showicon(h,getconfignumber(SHOWPICCONFIG));
  157.     return(1);
  158. }
  159. if ((fmconfig->usefontdt|usedt)&&*m==0x0f&&(*(m+1)==0x00||*(m+1)==0x03)&&!Strnicmp(h->filename+strlen(h->filename)-5,".font",5)) {
  160.     showfont(h,getconfignumber(SHOWPICCONFIG));
  161.     return(1);
  162. }
  163.  
  164. ptr1=(UBYTE*)m; mod=1;
  165. apu2=h->size<1000?h->size:1000;
  166. for(cnt=0;cnt<apu2;cnt++) {
  167.     if(*ptr1++==0) mod=0;
  168. }
  169. if (mod) {
  170.     if((fmconfig->useascdt|usedt)) {
  171.         showtext(h,getconfignumber(SHOWASCCONFIG));
  172.         return(1);
  173.     }
  174.     return(0);
  175. }
  176. ptr1=h->filename; mod=0;
  177. apu=(ULONG*)(m+1080);
  178. if (*apu=='M.K.'||*apu=='FLT4') mod=1;
  179. if (!Strnicmp(ptr1+strlen(ptr1)-4,".mod",4)) mod=1;
  180. if (!Strnicmp(ptr1,"mod.",4)) mod=1;
  181. if (mod) {
  182.     if((fmconfig->usemoddt|usedt)) {
  183.         modplay(h,getconfignumber(HEARCONFIG));
  184.         return(1);
  185.     }
  186.     return(0);
  187. }
  188. if((fmconfig->usehexdt|usedt)) {
  189.     showtext(h,getconfignumber(SHOWHEXCONFIG));
  190.     return(1);
  191. }
  192. return(0);
  193. }
  194.  
  195. void checkfile(struct FMHandle *h,UBYTE *m,struct FMNode *node)
  196. {
  197. struct CMenuConfig *cmc;
  198. UBYTE *ptr1,*ptr2;
  199. WORD cnt;
  200. WORD apu3,apu4,apu5;
  201. struct OwnCommand *oc;
  202. UBYTE token[256];
  203. LONG longi;
  204.  
  205. for(cnt=0;cnt<TOTALCOMMANDS;cnt++) {
  206.     cmc=&fmconfig->cmenuconfig[cnt];
  207.     if(cmc->cmenucount!=100||!cmc->moreconfig) continue;
  208.     oc=cmc->moreconfig;
  209.     if(oc->namematch[0]) {
  210.         if(ParsePatternNoCase(oc->namematch,token,256)>=0) {
  211.             if(MatchPatternNoCase(token,h->filename)) {
  212.                 executeown(h->owner,fmmain.destdir,node,cmc);
  213.                 return;
  214.             }
  215.         }
  216.     }
  217.     ptr1=oc->matchbytes;
  218.     apu3=-1;
  219.     apu4=-2;
  220.     while(*ptr1) {
  221.         if(StrToLong(ptr1,&longi)<0) break;
  222.         while(*ptr1!=','&&*ptr1!=0) ptr1++;
  223.         if(*ptr1++==0) break;
  224.         if(*ptr1=='$') {
  225.             ptr1++;
  226.             ptr2=ptr1;
  227.             while(*ptr1!=','&&*ptr1!=0) ptr1++;
  228.             apu3=0;apu4=0;
  229.             while(ptr2<ptr1) {
  230.                 apu5=strtohex(ptr2);
  231.                 ptr2+=2;
  232.                 if(longi+apu3<MEMSIZE&&m[apu3+longi]==(UBYTE)apu5) apu4++;
  233.                 if(apu5<0) break;
  234.                 apu3++;
  235.             }
  236.             if(apu3==apu4) {
  237.                 apu4=-1;
  238.                 break;
  239.             }
  240.         } else if(*ptr1=='"') {
  241.             ptr1++;
  242.             ptr2=ptr1;
  243.             while(*ptr1!='"'&&*ptr1!=0) ptr1++;
  244.             if(*ptr1==0) break;
  245.             apu5=ptr1-ptr2;
  246.             if(!apu5) break;
  247.             apu4=0;
  248.             for(apu3=0;apu3<apu5;apu3++) {
  249.                 if(longi+apu3<MEMSIZE&&m[apu3+longi]==ptr2[apu3]) apu4++;
  250.             }
  251.             if(apu5==apu4) {
  252.                 apu4=-1;
  253.                 break;
  254.             }
  255.         } else {
  256.             break;
  257.         }
  258.         if(*ptr1++!=',') break;
  259.     }
  260.     if(apu4==-1) {
  261.         executeown(h->owner,fmmain.destdir,node,cmc);
  262.         return;
  263.     }
  264. }
  265. if(testclick(h,node,m,0)) return;
  266.  
  267. if(isdatatypes(h,0)!=-99) return;
  268.  
  269. testclick(h,node,m,1);
  270. }
  271.