home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / GNU_C++ / LIB / CFLIB-11.LZH / src / scrap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-03  |  1.5 KB  |  101 lines

  1. /*
  2.  * scrp.c
  3.  *
  4.  * Zugriff auf das GEM-Klemmbrett.
  5. */
  6.  
  7. #include "intern.h"
  8.  
  9. #ifdef __MINT__
  10. #define DTA    _DTA
  11. #endif
  12.  
  13. static char    dir[80] = "";
  14.  
  15. int get_scrapdir(char *scrap)
  16. {
  17.  
  18.     if (dir[0] == EOS)
  19.     {
  20.         scrp_read(dir);
  21.         if (dir[0] != EOS)
  22.         {
  23.             int    i;
  24.             i = (int)strlen(dir);
  25.             if (dir[i - 1] != '\\')
  26.             {
  27.                 dir[i] = '\\';
  28.                 dir[i + 1] = EOS;
  29.             }
  30.         }
  31.     }
  32.     strcpy(scrap, dir);
  33.     return (scrap[0] != EOS);
  34. }
  35.  
  36. void scrap_clear(void)
  37. {
  38.     char        scrap[80], path[80];
  39.     DTA        dta, *old_dta;
  40.     int        ok;
  41.  
  42.     if (get_scrapdir(scrap))
  43.     {
  44.         strcpy(path, scrap);
  45.         strcat(path, "scrap.*");
  46.         old_dta = (DTA *)Fgetdta ();
  47.         Fsetdta(&dta);
  48.  
  49.         ok = (Fsfirst (path, 0) == 0);
  50.         while (ok)
  51.         {
  52.             strcpy(path, scrap);
  53. #ifdef __MINT__
  54.             strcat(path, dta.dta_name);
  55. #else
  56.             strcat(path, dta.d_fname);
  57. #endif
  58.             Fdelete(path);
  59.             ok = (Fsnext () == 0);
  60.         }
  61.         Fsetdta(old_dta);
  62.     }
  63. }
  64.  
  65. char *scrap_rtxt(char *buf, long *len, long maxlen)
  66. {
  67.     char    path[80];
  68.     int    datei;
  69.  
  70.     if (get_scrapdir(path))
  71.     {
  72.         strcat(path, "scrap.txt");
  73.         if ((datei = (int)Fopen(path, 0)) >= 0)
  74.         {
  75.             *len = Fread(datei, maxlen, buf);
  76.             Fclose(datei);
  77.             buf[*len] = '\0';
  78.             return buf;
  79.         }
  80.     }
  81.     return NULL;
  82. }
  83.  
  84. void scrap_wtxt(char *buf)
  85. {
  86.     char    path[150];
  87.     int    datei;
  88.  
  89.       if (get_scrapdir(path))
  90.       {
  91.         scrap_clear();
  92.          strcat (path, "scrap.txt");
  93.  
  94.          if ((datei = (int)Fcreate(path, 0)) >= 0)
  95.          {
  96.             Fwrite(datei, strlen(buf), buf);
  97.             Fclose(datei);
  98.          }
  99.       }
  100. }
  101.