home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / XAP / XFILEMAN / XFILEMAN.TAR / xfilemanager / customize.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  5.7 KB  |  217 lines

  1. /*
  2.  * Copyright 1993 by Ove Kalkan, Cremlingen, Germany
  3.  *
  4.  * Permission to use, copy, modify, distribute and sell this software and it's
  5.  * documentation for any purpose is hereby granted without fee, rpovided that
  6.  * the above copyright notice and this permission appear in supporting
  7.  * documentation, and that the name of Ove Kalkan not to be used in
  8.  * advertising or publicity pertaining to distributiopn of the software without
  9.  * specific, written prior permission. Ove Kalkan makes no representations
  10.  * about the suitability of this software for any purpose. It is provided
  11.  * as is without express or implied warranty.
  12.  *
  13.  * OVE KALKAN DISPLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  14.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABLILITY AND FITNESS, IN NO
  15.  * EVENT SHALL OVE KALKAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  16.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  17.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19.  * PERFORMANCE OF THIS SOFTWARE.
  20.  *
  21.  * $Header: filename,v 1.0 yyyy/mm/dd hh:mm:ss loginname Exp $
  22.  */
  23.  
  24.  
  25. #include "global.h"
  26. #include "filetypes.h"
  27.  
  28. /*
  29.  * Globals
  30.  */
  31.  
  32.  
  33. /*********************************************************
  34.  * name:    readCustomSettings
  35.  * description:    Liest das Defaultfile fuer die Filetype
  36.  *        zuordnungen. Falls es nicht existierte,
  37.  *        so wird es erzeugt und der Returnvalue ist
  38.  *        TRUE. Es wird dann ein Defaultsetting
  39.  *        verwendet.
  40.  * input:    none
  41.  * output:    FALSE wenn das File schon existierte,
  42.  *        sonnst TRUE, damit die Introsequenz
  43.  *        abgespielt werden kann
  44.  * author:    Ove Kalkan
  45.  * date:    24.6.93
  46.  *********************************************************/
  47. Boolean    readCustomSettings(void)
  48. {
  49.     char    *home = getenv("HOME");
  50.     char    filename[200];
  51.     FILE    *fp;
  52.  
  53.     /*
  54.      * Versuchen, das File zu oeffnen
  55.      */
  56.     if (strcmp(home,"/"))
  57.         sprintf(filename,"%s/.xfmrc",home);
  58.     else
  59.         sprintf(filename,"/.xfmrc");
  60.     if ((fp = fopen(filename,"r")) || (fp = fopen(DEFAULT_FILETYPES,"r"))) {
  61.         char    s[1024];
  62.         int    count = 0;
  63.  
  64.         /*
  65.          * Defaults aus dem File lesen
  66.          */
  67.         s[1023] = '\0';
  68.         while ((fgets(s,1023,fp))) {
  69.             int    lcount = -1;
  70.  
  71.             if (s[0] != '#' && s[0] != '\n') {    /* Kommentar nicht parsen */
  72.                 char    *b;
  73.                 int    i;
  74.                 char    *a = s;
  75.                 /*
  76.                  * Liste der Filetypen erweitern
  77.                  */
  78.                 if (lcount != count) {
  79.                     if (!filetypes) {
  80.                         if (!(filetypes = (Suffix_Glyph *) malloc(sizeof(Suffix_Glyph)*1)))
  81.                             FATAL_ERROR ("readCustomSettings: Malloc failed");
  82.                     }
  83.                     else {
  84.                         if (!(filetypes = (Suffix_Glyph *) realloc((void *) filetypes,
  85.                                            sizeof(Suffix_Glyph)*(count+2))))
  86.                             FATAL_ERROR ("readCustomSettings: Reallocation failed");
  87.                     }
  88.                     lcount = count;
  89.                 }
  90.  
  91.                 /*
  92.                  * Commando lesen
  93.                  */
  94.                 if (b = strchr(a,':')){        /* Auf Syntax achten */
  95.                     i = b - a;
  96.                     if (!(filetypes[count].cmd = (char *) malloc(i+1)))
  97.                         FATAL_ERROR("readCustomSettings: Malloc1 failed");
  98.                     strncpy(filetypes[count].cmd,a,i);
  99.                     filetypes[count].cmd[i] = '\0';
  100.                     a += (i + 1);
  101.  
  102.                     /*
  103.                      * Suffixes lesen
  104.                      */
  105.                     if (b = strchr(a,':')){        /* Auf Syntax achten */
  106.                         i = b - a;
  107.                         if (!(filetypes[count].suffix = (char *) malloc(i+1)))
  108.                             FATAL_ERROR("readCustomSettings: Malloc1 failed");
  109.                         strncpy(filetypes[count].suffix,a,i);
  110.                         filetypes[count].suffix[i] = '\0';
  111.                         a += (i + 1);
  112.  
  113.                         /*
  114.                          * Iconfilenamen lesen
  115.                          */
  116.                         if (b = strchr(a,':')){        /* Auf Syntax achten */
  117.                             i = b - a;
  118.                             if (!(filetypes[count].pmap_file = (char *) malloc(i+1)))
  119.                                 FATAL_ERROR("readCustomSettings: Malloc1 failed");
  120.                             strncpy(filetypes[count].pmap_file,a,i);
  121.                             filetypes[count].pmap_file[i] = '\0';
  122.                             a += (i + 1);
  123.  
  124.                             /*
  125.                              * Iconfilenamen lesen
  126.                              */
  127.                             i = strlen(a);
  128.                             if (!(filetypes[count].description = (char *) malloc(i + 1)))
  129.                                 FATAL_ERROR("readCustomSettings: Malloc1 failed");
  130.                             strncpy(filetypes[count].description,a,i - 1);
  131.                             filetypes[count].description[i - 1] = '\0';
  132.                             filetypes[count].type = count;
  133.                             filetypes[count].pmap = NULL;
  134.                             typelength = 200;
  135.                             count++;
  136.                             max_filetypes++;
  137.                         }
  138.                     }
  139.                 }
  140.             }
  141.         }
  142.         if (count)
  143.             filetypes[count].cmd = NULL;
  144.         else
  145.             filetypes = default_filetypes;
  146.         fclose(fp);
  147.     }
  148.     /*
  149.      * Defaults in das File schreiben
  150.      */
  151.     else {
  152.         int    i;
  153.  
  154.         filetypes = default_filetypes;
  155.         max_filetypes = default_maxfiletypes;
  156.  
  157. /*
  158.         if (!(fp = fopen(filename,"w")))
  159.             return(TRUE);
  160.         for (i = 0; i < max_filetypes; i++) {
  161.             fprintf(fp,"%s:%s:%s:%s\n",filetypes[i].cmd,
  162.                            filetypes[i].suffix,
  163.                            filetypes[i].pmap_file,
  164.                            filetypes[i].description);
  165.             max_filetypes++;
  166.         }
  167.         fclose(fp);
  168. */    }
  169.  
  170. }
  171.  
  172. /*********************************************************
  173.  * name:    loadTypeIcons
  174.  * description:    Die Icons fuer die Widgets laden
  175.  * input:    none
  176.  * output:    none
  177.  * author:    Ove Kalkan
  178.  * date:    25.6.93
  179.  *********************************************************/
  180. void    loadTypeIcons(void)
  181. {
  182.     /*
  183.      * Die Settings sind geladen, nun die dazugehoerigen Icons laden
  184.      */
  185.     String    filename[100];
  186.     int    scount = 0;
  187.     int    i;
  188.  
  189.     /*
  190.      * Alle Filetypes durchsuchen und dafuer Icons laden
  191.      */
  192.     for (scount = 0; filetypes[scount].cmd; scount++) {
  193.         i = 0;
  194.         while (i < pcount && !filetypes[scount].pmap) {
  195.             if (!(strcmp(filetypes[scount].pmap_file,filename[i])))
  196.                 filetypes[scount].pmap = &pmaps[i];
  197.             i++;
  198.         }
  199.         if (!filetypes[scount].pmap && filetypes[scount].pmap_file) {
  200.             /*
  201.              * Nach Pixmap suchen
  202.              */
  203.             {     int    w,h;
  204.  
  205.                 pmaps[pcount] = ReadPixmapFromFile(filetypes[scount].pmap_file,&w,&h);
  206.             }
  207.             if (pmaps[pcount]) {
  208.                 filename[pcount] = filetypes[scount].pmap_file;
  209.                 filetypes[scount].pmap = &pmaps[pcount];
  210.                 pcount++;
  211.             }
  212.  
  213.         }
  214.     }
  215. }
  216.  
  217.