home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff287.lzh / PopDir / PopDir.c < prev    next >
C/C++ Source or Header  |  1989-12-06  |  6KB  |  212 lines

  1. /* PopDir v1.5 © Copyright 1989 Jonathan Potter */
  2.  
  3. #include "PopDir.h"
  4.  
  5. void closeup();
  6.  
  7. main()
  8. {
  9.     struct Gadget *Gadget;
  10.     int GadgetID,whichwin,file,x,y,a,Class,ox=31,oy=11;
  11.     ULONG prevsec=0,prevmic=0,sec,mic;
  12.  
  13.     IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",0);
  14.     GfxBase=(struct GfxBase *) OpenLibrary("graphics.library",0);
  15.     if (!(finfo=(struct FileInfoBlock *) AllocMem(sizeof(struct FileInfoBlock),
  16.         MEMF_CHIP|MEMF_CLEAR))) closeup();
  17.     if (!(Window=(struct Window *) OpenWindow(&small))) closeup();
  18.     whichwin=1;
  19.     for (;;) {
  20.         if (whichwin==2) ActivateGadget(&StrGad,Window);
  21.         Wait(1<<Window->UserPort->mp_SigBit);
  22.         while (Msg=(struct IntuiMessage *) GetMsg(Window->UserPort)) {
  23.             Class=Msg->Class; sec=Msg->Seconds; mic=Msg->Micros;
  24.             if (Class==GADGETDOWN || Class==GADGETUP) {
  25.                 Gadget=(struct Gadget *) Msg->IAddress;
  26.                 GadgetID=Gadget->GadgetID;
  27.             }
  28.             ReplyMsg((struct Message *) Msg);
  29.             switch (Class) {
  30.                 case INACTIVEWINDOW:    
  31.                     if (Window->LeftEdge!=ox && Window->LeftEdge!=small.LeftEdge)
  32.                         small.LeftEdge=Window->LeftEdge;
  33.                     if (Window->TopEdge!=oy && Window->TopEdge!=small.TopEdge)
  34.                         small.TopEdge=Window->TopEdge;
  35.                     CloseWindow(Window);
  36.                     if (!(Window=(struct Window *) OpenWindow(&small))) closeup();
  37.                     whichwin=1;
  38.                     break;
  39.  
  40.                 case CLOSEWINDOW:
  41.                     CloseWindow(Window);
  42.                     if (whichwin==2) closeup();
  43.                     if (!(Window=(struct Window *) OpenWindow(&med))) closeup();
  44.                     SetWindowTitles(Window,-1,titlestring);
  45.                     whichwin=2;
  46.                     break;
  47.  
  48.                 case GADGETUP:
  49.                 case GADGETDOWN:
  50.                     if (whichwin==1) {
  51.                         if (!(DoubleClick(prevsec,prevmic,sec,mic))) {
  52.                             prevsec=sec; prevmic=mic;
  53.                             break;
  54.                         }
  55.                         small.LeftEdge=Window->LeftEdge;
  56.                         small.TopEdge=Window->TopEdge;
  57.                         if (Window->LeftEdge+med.Width>Window->WScreen->Width)
  58.                             med.LeftEdge=Window->WScreen->Width-med.Width;
  59.                         else med.LeftEdge=Window->LeftEdge;
  60.                         if (Window->TopEdge+med.Height>Window->WScreen->Height)
  61.                             med.TopEdge=Window->WScreen->Height-med.Height;
  62.                         else med.TopEdge=Window->TopEdge;
  63.                         ox=med.LeftEdge; oy=med.TopEdge;
  64.                         CloseWindow(Window);
  65.                         if (!(Window=(struct Window *) OpenWindow(&med))) closeup();
  66.                         SetWindowTitles(Window,-1,titlestring);
  67.                         whichwin=2;
  68.                         break;
  69.                     }
  70.                     if (GadgetID>1 && GadgetID<14) {
  71.                         sprintf(dobuffer,Gadget->GadgetText->IText);
  72.                         RefreshGList(&StrGad,Window,NULL,1);
  73.                         break;
  74.                     }
  75.                     else if (GadgetID==14) {
  76.                         do_parent();
  77.                         RefreshGList(&StrGad,Window,NULL,1);
  78.                         break;
  79.                     }
  80.                     if (dobuffer[(strlen(dobuffer)-1)]!='/' &&
  81.                         dobuffer[(strlen(dobuffer)-1)]!=':')
  82.                         strcat(dobuffer,'/');
  83.                     whichwin=3;
  84.                     med.LeftEdge=Window->LeftEdge;
  85.                     med.TopEdge=Window->TopEdge;
  86.                     CloseWindow(Window);
  87.                     if (!(Window=(struct Window *) OpenWindow(&big))) closeup();
  88.                     SetWindowTitles(Window,dobuffer,titlestring);
  89.                      if ((lock=(struct FileLock *) Lock(dobuffer,ACCESS_READ))==0) {
  90.                         sprintf(ToPrint,"Can't lock requested directory!");
  91.                         PrintIText(Window->RPort,&Files,10,12);
  92.                         sprintf(ToPrint,"Click on Close Gadget to continue");
  93.                         WriteStatus();
  94.                         goto finalquit;
  95.                     }
  96.                     Examine(lock,finfo);
  97.                     file=0; y=12; x=10; a=0;
  98.                     if (finfo->fib_DirEntryType<0) {
  99.                         sprintf(ToPrint,"%-30s",finfo->fib_FileName);
  100.                         PrintIText(Window->RPort,&Files,x,y);
  101.                         sprintf(ToPrint,"%-7d",finfo->fib_Size);
  102.                         PrintIText(Window->RPort,&Files,x+242,y);
  103.                         sprintf(ToPrint,"Click on Close Gadget to continue");
  104.                         WriteStatus();
  105.                         goto finalquit;;
  106.                     }
  107.                     oldlock=(struct FileLock *) CurrentDir(lock);
  108.                     Forbid(); 
  109.                     while ((ExNext(lock,finfo))!=0) {
  110.                         a=1;
  111.                         if (file==0) {
  112.                             sprintf(ToPrint,"Reading directory.. Close gadget to cancel");
  113.                             WriteStatus();
  114.                         }
  115.                         if (Msg=(struct IntuiMessage *) GetMsg(Window->UserPort)) {
  116.                             Class=Msg->Class;
  117.                             ReplyMsg((struct Message *) Msg);    
  118.                             if (Class==CLOSEWINDOW) {
  119.                                 CloseWindow(Window);
  120.                                 if (!(Window=(struct Window *) OpenWindow(&med))) closeup();
  121.                                 SetWindowTitles(Window,-1,titlestring);
  122.                                 whichwin=2;
  123.                                 goto quit;
  124.                             }
  125.                         }
  126.                         if (finfo->fib_DirEntryType>0)
  127.                             Files.FrontPen=3;
  128.                         sprintf(ToPrint,"%-30s",finfo->fib_FileName);
  129.                         PrintIText(Window->RPort,&Files,x,y);
  130.                         if (finfo->fib_DirEntryType<0) {
  131.                             sprintf(ToPrint,"%-7d",finfo->fib_Size);
  132.                             PrintIText(Window->RPort,&Files,x+242,y);
  133.                         }
  134.                         Files.FrontPen=1; 
  135.                         if (x==10) x=330;
  136.                         else {
  137.                             x=10;
  138.                             y+=8;
  139.                         }
  140.                         ++file;
  141.                         if (file>43) {
  142.                             sprintf(ToPrint,"Press any key to continue, or click on Close Gadget to cancel");
  143.                             WriteStatus();
  144.                             Wait(1<<Window->UserPort->mp_SigBit);
  145.                             while (Msg=(struct IntuiMessage *) GetMsg(Window->UserPort)) {    
  146.                                 Class=Msg->Class;
  147.                                 ReplyMsg((struct Message *) Msg);
  148.                                 if (Class==CLOSEWINDOW) {
  149.                                     CloseWindow(Window);
  150.                                     if (!(Window=(struct Window *) OpenWindow(&med))) closeup();
  151.                                     SetWindowTitles(Window,-1,titlestring);
  152.                                     whichwin=2;
  153.                                     goto quit;
  154.                                 }
  155.                             }
  156.                             SetAPen(Window->RPort,0);
  157.                             RectFill(Window->RPort,9,10,637,198);
  158.                             file=0; y=12; x=10;
  159.                         }
  160.                     }
  161.                     if (a==0) {
  162.                         sprintf(ToPrint,"Requested directory is empty");
  163.                         PrintIText(Window->RPort,&Files,10,12);
  164.                     }
  165.                     sprintf(ToPrint,"Click on close gadget to continue");
  166.                     WriteStatus();
  167.                     quit:
  168.                     Permit();
  169.                     CurrentDir(oldlock);
  170.                     UnLock(lock);
  171.                     finalquit:
  172.                     break;
  173.  
  174.                 default:
  175.                     break;
  176.             }
  177.         }
  178.     }
  179. }
  180.  
  181. WriteStatus()
  182. {
  183.     SetAPen(Window->RPort,0);
  184.     RectFill(Window->RPort,2,189,637,198);
  185.     Files.FrontPen=3;
  186.     PrintIText(Window->RPort,&Files,10,189);
  187.     Files.FrontPen=1;
  188.     return(0);
  189. }
  190.  
  191. do_parent()
  192. {
  193.     int i,b;
  194.     if (strlen(dobuffer)==0) return(0);
  195.     i=strlen(dobuffer)-1;
  196.     if (dobuffer[i]==':') return(0);
  197.     if (dobuffer[i]=='/') --i;
  198.     for (b=i;b>-1;b--) if (dobuffer[b]=='/' || dobuffer[b]==':') break;
  199.     if (dobuffer[b]==':') dobuffer[++b]='\0';
  200.     if (b<0) b=0;
  201.     dobuffer[b]='\0';
  202. }
  203.  
  204. void closeup()
  205. {
  206.     if (finfo) FreeMem(finfo,sizeof(struct FileInfoBlock));
  207.     CloseLibrary((struct Library *) IntuitionBase);
  208.     CloseLibrary((struct Library *) GfxBase);
  209.     OpenWorkBench();
  210.     exit(0);
  211. }
  212.