home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0678.ZIP / CCE_0678.PD / E_GEM135 / SOURCE / SCRAP.C < prev    next >
C/C++ Source or Header  |  1994-03-13  |  2KB  |  135 lines

  1.  
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include "proto.h"
  5.  
  6. int    scrp_init(char *path)
  7. {
  8.     reg char scrap[256];
  9.     reg long handle,len;
  10.  
  11.     scrp_read(scrap);
  12.     if (scrap[0]=='\0')
  13.     {
  14.         if (path)
  15.             strcpy(scrap,path);
  16.         else if ((path = getenv("CLIPBRD"))!=NULL || (path = getenv("SCRAPDIR"))!=NULL)
  17.             strcpy(scrap,path);
  18.         else
  19.         {
  20.             reg long ssp;
  21.  
  22.             strcpy(scrap,"X:\\CLIPBRD");
  23.             ssp = Super(NULL);
  24.             *scrap = (char) (*((int *) 0x446)+65);
  25.             Super((void *) ssp);
  26.         }
  27.     }
  28.  
  29.     if ((len = strlen(scrap))>0)
  30.     {
  31.         len--;
  32.         if (scrap[len]=='\\')
  33.             scrap[len]='\0';
  34.     
  35.         handle = Dcreate(scrap);
  36.         if (handle>=0 || handle==-36)
  37.         {
  38.             scrp_write(strcat(scrap,"\\"));
  39.             return(TRUE);
  40.         }
  41.     }
  42.  
  43.     scrp_write("");
  44.     return(FALSE);
  45. }
  46.  
  47. void scrp_clear(int all)
  48. {
  49.     reg char scrap[256];
  50.     
  51.     scrp_read(scrap);
  52.     if (scrap[0]!='\0')
  53.     {
  54.         reg DTA *dta=Fgetdta();
  55.         reg char xpath[256],xname[256];
  56.  
  57.         strmfp(xpath,scrap,(all) ? "*.*" : "SCRAP.*");
  58.         if (!Fsfirst(xpath,0))
  59.             do
  60.             {
  61.                 strmfp(xname,scrap,dta->d_fname);
  62.                 remove(xname);
  63.             }
  64.             while (!Fsnext());
  65.     }
  66. }
  67.  
  68. int    scrp_length()
  69. {
  70.     reg char scrap[256];
  71.     
  72.     scrp_read(scrap);
  73.     if (scrap[0]!='\0')
  74.     {
  75.         reg DTA *dta=Fgetdta();
  76.         reg char xpath[256];
  77.  
  78.         strmfp(xpath,scrap,"SCRAP.*");
  79.         if (!Fsfirst(xpath,0))
  80.         {
  81.             reg long length = 0;
  82.             do
  83.                 length += dta->d_length;
  84.             while (!Fsnext());
  85.             return ((int) ((length+512)>>10));
  86.         }
  87.     }
  88.  
  89.     return (0);
  90. }
  91.  
  92. int    scrp_find(char *extension,char *filename)
  93. {
  94.     reg char scrap[256];
  95.     
  96.     scrp_read(scrap);
  97.     if (scrap[0]!='\0')
  98.     {
  99.         reg DTA  *dta=Fgetdta();
  100.         reg char xpath[256];
  101.         reg int  c = 0;
  102.  
  103.         strcat(strmfp(xpath,scrap,"SCRAP."),extension);
  104.         if(!Fsfirst(xpath,0))
  105.         {
  106.             c++;
  107.             strmfp(filename,scrap,dta->d_fname);
  108.             while (!Fsnext()) c++;
  109.             return (c);
  110.         }
  111.     }
  112.     return (0);
  113. }
  114.  
  115. char *strmfp(char *dest,char *path,char *file)
  116. {
  117.     reg char *last;
  118.     reg int len;
  119.  
  120.     if (path)
  121.         strcpy(dest,path);
  122.  
  123.     if ((len = (int) strlen(dest))>0)
  124.     {
  125.         last = dest + len - 1;
  126.         if (*last!='\\')
  127.         {
  128.             *++last = '\\';
  129.             *++last = '\0';
  130.         }
  131.     }
  132.  
  133.     return(strcat(dest,file));
  134. }
  135.