home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / gpr140s / file.c < prev    next >
C/C++ Source or Header  |  1994-09-10  |  10KB  |  374 lines

  1. /************************************************************/
  2. /* FILE.C                                                   */
  3. /************************* Includes *************************/
  4. #ifdef __PUREC__
  5. #include <ext.h>
  6. #endif
  7. #ifdef __GNUC__
  8. #define __TCC_COMPAT__
  9. #include <support.h>
  10. #include <unistd.h>
  11. #include <ostruct.h>
  12. #include <mintbind.h>
  13. #include <fcntl.h>
  14. #endif
  15. #include <portab.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <osbind.h>
  19. #include <vdibind.h>
  20. #include <aesbind.h>
  21. #include "gprint.h"
  22. #include "gdos.h"
  23.  
  24. /************************* Variablen ************************/
  25. extern OBJECT *dial_tree, *font_tree, *opt_tree, *pop_tree, *ppop_tree;
  26. extern int id_akt_font;
  27.  
  28. /************************* Prototypen ***********************/
  29. int  bestimme_datei (char *n, char *dn, char *dp);
  30. int  bestimme_datei_v(char *name, char *pfad);
  31. long load_datei     (const char *name, unsigned long *laenge, unsigned long *z_mem);
  32. int  save_opt       (void);
  33. int  load_opt       (void);
  34. int  save_fontliste (FONT *fonts, int anzahl);
  35. int  load_fontliste (FONT *fonts, int *anzahl);
  36.  
  37. /************************* Program **************************/
  38. /* Datei über Fileselect-Box bestimmen                      */
  39. /* In n steht die Datei mit Pfad                            */
  40. /*    dn Dateiname                                          */
  41. /*    dp Dateipfad                                          */
  42. /************************************************************/
  43. int bestimme_datei(char *n, char *dn, char *dp)
  44. {
  45.   char fs_iinpath[128], fs_iinsel[40];
  46.   int  fs_iexbutton;
  47.  
  48.   *fs_iinpath = 0x0;
  49.   *fs_iinsel = 0x0;
  50.   *n = 0x0;
  51.   *dn = 0x0;
  52.   *dp = 0x0;
  53.  
  54.   if(PF.s_pfad)
  55.   {
  56. #ifdef __PUREC__
  57.     setdisk(ldrive);
  58. #endif
  59. #ifdef __GNUC__
  60.     Dsetdrv(ldrive);
  61. #endif
  62.     chdir(lpath);
  63.   }
  64.  
  65.   fsel_input(fs_iinpath, fs_iinsel, &fs_iexbutton);
  66.  
  67.   if(fs_iexbutton == 1 && *fs_iinsel != 0x0)
  68.   {
  69.     int h;
  70.     h = (int)strlen(fs_iinpath);
  71.     while(*(fs_iinpath + h) != 92) h--;
  72.     strncpy(n, fs_iinpath, ++h);
  73.     n[h] = 0x00;
  74.     strcpy(dp, n);                /* Pfad der Datei             */
  75.     strcpy(dn, fs_iinsel);        /* Name der Datei             */
  76.     strcpy(lpath, n+2);           /* Pfad ohne Laufwerk         */
  77.     strcat(n, fs_iinsel);         /* Korrekten Pfadnamen bilden */
  78.     ldrive = (int)*fs_iinpath-65;
  79.     return(TRUE);
  80.   }
  81.   return(FALSE);
  82. } /* bestimme_datei() */
  83.  
  84. /******************************************************/
  85. /* Dateinamen und Pfad getrennt ermitteln             */
  86. /******************************************************/
  87. int bestimme_datei_v(char *name, char *pfad)
  88. {
  89.   char fs_iinpath[128], fs_iinsel[40];
  90.   int  fs_iexbutton;
  91.  
  92.   *fs_iinpath = 0x0;
  93.   *fs_iinsel = 0x0;
  94.  
  95.   if(PF.s_pfad)
  96.   {
  97. #ifdef __PUREC__
  98.     setdisk(ldrive);
  99. #endif
  100. #ifdef __GNUC__
  101.     Dsetdrv(ldrive);
  102. #endif
  103.     chdir(lpath);
  104.   }
  105.  
  106.   fsel_input(fs_iinpath, fs_iinsel, &fs_iexbutton);
  107.  
  108.   if(fs_iexbutton == 1)   /*  && *fs_iinsel != 0x0) */
  109.   {
  110.     int h;
  111.     h = (int)strlen(fs_iinpath);
  112.     while(*(fs_iinpath + h) != 92) h--;
  113.     strncpy(pfad, fs_iinpath, ++h);
  114.     pfad[h] = 0x00;
  115.     strcpy(name, fs_iinsel);
  116.     strcpy(lpath, pfad+2);  /* Pfad ohne Laufwerk */
  117.     ldrive = (int)*pfad-65;
  118.     return(TRUE);
  119.   }
  120.   return(FALSE);
  121. } /* bestimme_datei_v() */
  122.  
  123. /******************************************************/
  124. /* Eine beliebige Datei laden.                        */
  125. /******************************************************/
  126. long load_datei(const char *name, unsigned long *laenge, unsigned long *z_mem)
  127. {
  128.   int fhandle, exit;
  129.   long memavail, mem, zusaetz_mem;
  130. #ifdef __PUREC__
  131.   DTA *dta;
  132. #endif
  133. #ifdef __GNUC__
  134.   _DTA *dta;
  135. #endif
  136.  
  137.   exit = 0;
  138. #ifdef __PUREC__
  139.   setdisk(ldrive);
  140. #endif
  141. #ifdef __GNUC__
  142.   Dsetdrv(ldrive);
  143. #endif
  144.   chdir(lpath);
  145.  
  146. #ifdef __PUREC__
  147.   dta = (DTA *) Fgetdta();
  148. #endif
  149. #ifdef __GNUC__
  150.   dta = (_DTA *) Fgetdta();
  151. #endif
  152.  
  153.   exit = Fsfirst(name, 0);    /* feststellen, ob es die Datei gibt */
  154.   if(exit != FALSE)
  155.   {
  156.     return(0L);
  157.   }
  158. #ifdef __PUREC__
  159.   *laenge = (*dta).d_length;            /* Dateilaenge  */
  160. #endif
  161. #ifdef __GNUC__
  162.   *laenge = (*dta).dta_size;
  163. #endif
  164.   if(PF.dyna_mem)      /* dynamische Speicherverwaltung */
  165.   {
  166.     (long)zusaetz_mem = 3072 + (*laenge >> 10) * (20 + PF.tabspace * 50);
  167.     /*                 1K + 2K                Umlaute       Tab's
  168.                        sowieso                20 / KB      50 / KB   */
  169.     /* 1K für Absatzformatierung */
  170.   }
  171.   else
  172.   {
  173.     zusaetz_mem = 16384L;
  174.   }
  175.   *z_mem = zusaetz_mem;
  176.   memavail = (long) malloc((unsigned long)-1) - 20000L; /* freier Speicher */
  177.   if (*laenge < memavail)
  178.     mem = (long) malloc(*laenge + zusaetz_mem); /* Platz für Umlaute */
  179.   else
  180.   {
  181.     return(0L);
  182.   }
  183.  
  184. #ifdef __PUREC__
  185.   fhandle = Fopen(name, FO_READ);
  186. #else
  187.   fhandle = Fopen(name, O_RDONLY);
  188. #endif
  189.   if(fhandle <= 0)                /* Fehler beim öffnen ?    */
  190.   {
  191.     return(0L);
  192.   }
  193.  
  194.   if(Fread(fhandle, *laenge, (void *)(mem + zusaetz_mem)) < 0L)
  195.   {
  196.     return(0L);
  197.   }
  198.  
  199.   if(Fclose(fhandle) < 0)        /* Datei schließen */
  200.   {
  201.     return(0L);
  202.   }
  203.  
  204.   return(mem);
  205.  
  206. } /* load_datei() */
  207.  
  208. /**********************************************/
  209. /* Einstellungen Laden                        */
  210. /**********************************************/
  211. int load_opt(void)
  212. {
  213.   int buffer[52], fhandle, *buf;
  214.   long b;
  215.   buf = buffer;
  216.  
  217. #ifdef __PUREC__
  218.   setdisk(ldrive);
  219. #endif
  220. #ifdef __GNUC__
  221.   Dsetdrv(ldrive);
  222. #endif
  223.   chdir(spath);
  224.  
  225. #ifdef __PUREC__
  226.   fhandle = Fopen("GPRINT.INF", FO_READ);
  227. #else
  228.   fhandle = Fopen("GPRINT.INF", O_RDONLY);
  229. #endif
  230.   if(fhandle <= 0)                /* Fehler beim öffnen ?    */
  231.   {
  232.     return(0);
  233.   }
  234.  
  235.   b = Fread(fhandle, 100, (void *)buf);
  236.   if(b != 100)
  237.   {
  238.     return(0);
  239.   }
  240.  
  241.   if(Fclose(fhandle) < 0)        /* Datei schließen */
  242.   {
  243.     return(0);
  244.   }
  245.  
  246.   font_tree[ZH6].ob_state       = buf[0];
  247.   font_tree[ZH8].ob_state       = buf[1];     /* bis v 1.30 in dial_tree */
  248. /*  font_tree[ZH9].ob_state       = buf[2]; */
  249.   font_tree[ZH10].ob_state      = buf[3];
  250.  
  251.   dial_tree[UMLAUTE].ob_state   = buf[5];
  252.   dial_tree[TAB2SPACE].ob_state = buf[6];
  253.   dial_tree[HEFTRAND].ob_state  = buf[7];
  254.   dial_tree[DATEINAME].ob_state = buf[8];
  255.   dial_tree[DATUM].ob_state     = buf[9];
  256.   dial_tree[PAGENUM].ob_state   = buf[10];
  257.   dial_tree[PAGEBREAK].ob_state = buf[11];
  258.   dial_tree[PAGEQUER].ob_state  = buf[12];
  259.   dial_tree[UNTERSTRICH].ob_state  = buf[13];
  260.   dial_tree[LOCHERMARKE].ob_state  = buf[14];
  261.   dial_tree[SEITENRAHMEN].ob_state = buf[15];
  262. /*  dial_tree[].ob_state  = buf[12];*/
  263.  
  264.   if(buf[30] != 0x0)
  265.     id_akt_font                   = buf[30];
  266.  
  267.   ppop_tree[PPAGEALL].ob_state      = buf[30];
  268.   ppop_tree[PPAGEGERADE].ob_state   = buf[31];
  269.   ppop_tree[PPAGEUNGERADE].ob_state = buf[32];
  270.  
  271. /*opt_tree[AUTOCHK].ob_state    = buf[40];*/
  272.   opt_tree[SAVEPFAD].ob_state   = buf[41];
  273.   opt_tree[ABSATZMODE].ob_state = buf[42];
  274.   opt_tree[MEMDYN].ob_state     = buf[43];
  275.   opt_tree[SPARMODE].ob_state   = buf[44];
  276. /*opt_tree[STATFONT].ob_state   = buf[45];*/
  277.   opt_tree[FROMPAGE].ob_state   = buf[46];
  278. #ifdef __PUREC__
  279.   itoa(buf[47], opt_tree[FROMPAGENUM].ob_spec.tedinfo->te_ptext, 10);
  280. #endif
  281. #ifdef __GNUC__
  282.   _itoa(buf[47], opt_tree[ANZCOPYS].ob_spec.tedinfo->te_ptext, 10);
  283. #endif
  284.  
  285.   opt_tree[COPYS].ob_state      = buf[48];
  286. #ifdef __PUREC__
  287.   itoa(buf[49], opt_tree[ANZCOPYS].ob_spec.tedinfo->te_ptext, 10);
  288. #endif
  289. #ifdef __GNUC__
  290.   _itoa(buf[49], opt_tree[ANZCOPYS].ob_spec.tedinfo->te_ptext, 10);
  291. #endif
  292.  
  293.   return(TRUE);
  294. } /* load_opt() */
  295.  
  296. /*******************************************/
  297. /* Einstellungen in "GPRINT.INF" sichern   */
  298. /*******************************************/
  299. int save_opt(void)
  300. {
  301.   int buffer[52], fhandle, *buf;
  302.   long b;
  303.  
  304.   buf = buffer;
  305.  
  306.   buf[0]  = font_tree[ZH6].ob_state;
  307.   buf[1]  = font_tree[ZH8].ob_state;
  308. /*  buf[2]  = font_tree[ZH9].ob_state; */
  309.   buf[3]  =  font_tree[ZH10].ob_state;
  310.  
  311.   buf[5]  = dial_tree[UMLAUTE].ob_state;
  312.   buf[6]  = dial_tree[TAB2SPACE].ob_state;
  313.   buf[7]  = dial_tree[HEFTRAND].ob_state;
  314.   buf[8]  = dial_tree[DATEINAME].ob_state;
  315.   buf[9]  = dial_tree[DATUM].ob_state;
  316.   buf[10] = dial_tree[PAGENUM].ob_state;
  317.   buf[11] = dial_tree[PAGEBREAK].ob_state;
  318.   buf[12] = dial_tree[PAGEQUER].ob_state;
  319.   buf[13] = dial_tree[UNTERSTRICH].ob_state;
  320.   buf[14] = dial_tree[LOCHERMARKE].ob_state;
  321.   buf[15] = dial_tree[SEITENRAHMEN].ob_state;
  322.  
  323.   if(afp != NULL)
  324.     buf[30] = afp->font_id;
  325.  
  326.   buf[30] = ppop_tree[PPAGEALL].ob_state;
  327.   buf[31] = ppop_tree[PPAGEGERADE].ob_state;
  328.   buf[32] = ppop_tree[PPAGEUNGERADE].ob_state;
  329.  
  330. /*buf[40] = opt_tree[AUTOCHK].ob_state;   */
  331.   buf[41] = opt_tree[SAVEPFAD].ob_state;
  332.   buf[42] = opt_tree[ABSATZMODE].ob_state;
  333.   buf[43] = opt_tree[MEMDYN].ob_state;
  334.   buf[44] = opt_tree[SPARMODE].ob_state;
  335. /*buf[45] = opt_tree[STATFONT].ob_state;   */
  336.   buf[46] = opt_tree[FROMPAGE].ob_state;
  337.   buf[47] = atoi(opt_tree[FROMPAGENUM].ob_spec.tedinfo->te_ptext);
  338.  
  339.   buf[48] = opt_tree[COPYS].ob_state;
  340.   buf[49] = atoi(opt_tree[ANZCOPYS].ob_spec.tedinfo->te_ptext);
  341.  
  342. #ifdef __PUREC__
  343.   setdisk(ldrive);
  344. #endif
  345. #ifdef __GNUC__
  346.   Dsetdrv(ldrive);
  347. #endif
  348.   chdir(spath);
  349.  
  350. #ifdef __PUREC__
  351.   fhandle = Fopen("GPRINT.INF", FO_WRITE);
  352. #else
  353.   fhandle = Fopen("GPRINT.INF", O_RDONLY);
  354. #endif
  355.   if(fhandle <= 0)                /* Fehler beim öffnen ?    */
  356.   {
  357.     fhandle = Fcreate("GPRINT.INF", 0);
  358.     if( fhandle <= 0)
  359.       return(0);
  360.   }
  361.  
  362.   b = Fwrite(fhandle, 100, buf);
  363.   if(b != 100)
  364.   {
  365.     return(0);
  366.   }
  367.  
  368.   if(Fclose(fhandle) < 0)        /* Datei schließen */
  369.   {
  370.     return(0);
  371.   }
  372.   return(TRUE);
  373. } /* save_opt() */
  374.