home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 206.lha / Flist_v1.2 / Sources / flist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-28  |  4.0 KB  |  152 lines

  1. /*
  2.     This program was written by Stephen W. Berry.
  3.  
  4.     The concept is copyrighted by me, but the program listings
  5.     executable and documentation are placed in the Public Domain.
  6.  
  7.     If you find a bug or enhance this program please let me know
  8.     at the following address:
  9.  
  10.         The Checkered Ball
  11.         A-7 Sinai Circle
  12.         Chelmsford, Ma 01824
  13.         c/o Stephen Berry
  14.  
  15. */
  16.  
  17. #define DEBUG TRUE
  18.  
  19. #include <rexx/storage.h>
  20. #include <rexx/rxslib.h>
  21. #include <libraries/arpbase.h>
  22. #include <stdio.h>
  23. #include "flist.h"
  24.  
  25. struct RxsLib *RexxSysBase = NULL;
  26.  
  27. /* external routines - system */
  28.  
  29. extern void CloseLibrary();
  30. struct Screen *OpenScreen();
  31. struct Window *OpenWindow();
  32. struct IntuiMessage *GetMsg();
  33.  
  34. /* external routines - Arp */
  35.  
  36. extern void *ArpAlloc();
  37.  
  38. /* external routines - mine */
  39.  
  40. extern void menu(),tticon(),OpenConsole(),drawcur(),blankcur();
  41. extern long parse();
  42. extern void FreeFlistMem(),OpenRexxPort(),DeleteRexxPort(),CleanupRexx();
  43. extern long OpenLib(),StartRexxProg();
  44. extern struct RexxMsg *port,*PollRexxPort(),*WaitMsgPort();
  45. extern void Redirecterror();
  46.  
  47. /* global variables, structures etc... */
  48.  
  49. extern struct IOStdReq ConsoleReq;
  50. extern struct FileLock *startdir, *rootdir, *lock;
  51. struct Screen *scrptr = NULL;
  52. struct Window *winptr = NULL, *oldwinptr;
  53. struct RexxMsg myrexxport;
  54. extern long numfiles;
  55.  
  56. extern long (*finfo[MAXDIR])[4];
  57. extern char (*fname[MAXDIR])[FCHARS];
  58. extern char (*comm[MAXDIR])[FCHARS];
  59. extern char (*fstring[MAXDIR])[LEN_DATSTRING];
  60. extern char (*ftime[MAXDIR])[LEN_DATSTRING];
  61. APTR oldcon;
  62.  
  63. struct Process *myproc;
  64. long remember = -10;
  65. int didRexx = FALSE;
  66.  
  67. main(argc,argv)
  68. int argc;
  69. char *argv[];
  70. {
  71.     struct IntuiMessage *msg;
  72.     LONG i,rc = NULL;
  73.  
  74.     /* parse the command line and get the first file */
  75.  
  76.     if((rc = parse(argc,argv)) != NULL){
  77.         printf("Input error.\n");
  78.         printf("Flist requires the name(s) of files\n");
  79.         printf("Or FROM and the name of a file with names in it.\n");
  80.         printf("Standard DOS and ARP wildcards are accepted.\n");
  81.         FreeFlistMem();
  82.         Delay(20);
  83.         exit(rc);
  84.     }
  85.  
  86.     openstuff(); /* open the window and screen */
  87.  
  88. /*    myproc = (struct Process *)DeviceProc("flist"); */
  89.     myproc = (struct Process *)FindTask(0L);
  90. /*    myproc = (myproc != NULL) ? myproc - sizeof(struct Task): 0; */
  91.  
  92.     if (myproc != NULL){
  93.  
  94. /* Believe it or not, this stops ALL requestors from appearing! */
  95.  
  96.         oldwinptr = myproc->pr_WindowPtr;
  97.         myproc->pr_WindowPtr = (struct Window *)(-1L); 
  98.  
  99. /* This allows a safer environment for flist's run in the background */
  100.  
  101.         oldcon = myproc->pr_ConsoleTask;
  102.         myproc->pr_ConsoleTask = (struct Task *)DeviceProc("null:");
  103.         myproc->pr_WindowPtr = winptr; 
  104.         if (myproc->pr_ConsoleTask != NULL)
  105.             freopen("NULL:","w+",stderr);
  106.     }
  107.  
  108. /*  I link with arp.lib so that I don't have to open:
  109.     intuition, graphics and arp libraries. */
  110.  
  111.     RexxSysBase = OpenLibrary("rexxsyslib.library",(LONG)RXSVERS);
  112.  
  113.     if (RexxSysBase != NULL) {
  114.         OpenRexxPort("flport",&myrexxport);
  115.         didRexx = TRUE;
  116.     }
  117.  
  118.     menu();     /* we should never return ! */
  119. }
  120.  
  121. Cleanup()
  122. {
  123.     int i;
  124.  
  125.     myproc->pr_WindowPtr = oldwinptr;
  126.     myproc->pr_ConsoleTask = oldcon;
  127.     if(didRexx)
  128.         DeleteRexxPort(&myrexxport);
  129.     if(RexxSysBase != NULL )
  130.         CloseLibrary(RexxSysBase);
  131.     FreeFlistMem();
  132.     if(winptr != NULL)
  133.         CloseDevice(&ConsoleReq);
  134.         CloseWindowSafely(winptr,NULL);
  135.     if(scrptr != NULL )
  136.         CloseScreen(scrptr);
  137.     UnLock(CurrentDir(startdir));       /* go back to the dir we started at */
  138.  
  139.     for (i=0;i<MAXDIR;i++)              /* free all array memory */
  140.         if (fname[i] != 0) {
  141.             FreeMem(fname[i],FCHARS);
  142. /*            FreeMem(comm[i],FCHARS); */
  143.             FreeMem(finfo[i],16L);
  144.             FreeMem(fstring[i],LEN_DATSTRING);
  145.             FreeMem(ftime[i],LEN_DATSTRING);
  146.             fname[i] = 0;
  147.             finfo[i] = 0;
  148.             fstring[i] = 0;
  149.             ftime[i] = 0;
  150.         }
  151. }
  152.