home *** CD-ROM | disk | FTP | other *** search
/ Da Capo / da_capo_vol1.bin / metatool / metatoolprefs2env.c < prev   
C/C++ Source or Header  |  1995-05-15  |  2KB  |  79 lines

  1. /* Public Domain program to read a named file, that is expected to be a
  2.    MetaTool prefs file, extract the metatypes and commands from the file,
  3.    and stuff them into environment variables of the same name as the
  4.    metatype in the ENV:MetaToolPrefs directory.  I.E., given a MetaTool
  5.    prefs file like:
  6.  
  7.     TEXT    SYS:Utilities/MultiView
  8.     GUIDE    SYS:Utilities/MultiView
  9.     HTML    CLI Execute :Mosaic []
  10.     BIN    SYS:Utilities/MultiView
  11.  
  12.    Create the following files with contents as follows:
  13.  
  14.     ENV:MetaToolPrefs/TEXT    ->    SYS:Utilities/MultiView
  15.     ENV:MetaToolPrefs/GUIDE    ->    SYS:Utilities/MultiView
  16.     ENV:MetaToolPrefs/HTML    ->    CLI Execute :Mosaic []
  17.     ENV:MetaToolPrefs/BIN    ->    SYS:Utilities/MultiView
  18.  
  19.    This is primarily for the benefit of the standard Commodore installer
  20.    program, which cannot read files (stupid thing!) but can read the
  21.    contents of environment variables.
  22.  
  23.    -Fred Fish
  24. */
  25.  
  26. #include <stdio.h>
  27.  
  28. main (argc, argv)
  29. int argc;
  30. char *argv[];
  31. {
  32.   FILE *pfp, *tfp;
  33.   char linebuffer[128], envfile[128];
  34.   char *lptr;
  35.   extern int strlen (char *);
  36.  
  37.   if (argc != 2)
  38.     {
  39.       fprintf (stderr, "usage: MetaToolPrefs2Env <preferences file name>\n");
  40.       exit (1);
  41.     }
  42.   pfp = fopen (argv[1], "r");
  43.   if (pfp == NULL)
  44.     {
  45.       fprintf (stderr, "%s: cannot open: ", argv[1]);
  46.       perror ("");
  47.       exit (1);
  48.     }
  49.   else
  50.     {
  51.       while (fgets (linebuffer, sizeof (linebuffer), pfp))
  52.     {
  53.       linebuffer[strlen (linebuffer) - 1] = '\000';
  54.       lptr = linebuffer;
  55.       if (*lptr == ';' || *lptr == '\000')
  56.         {
  57.           continue;
  58.         }
  59.       while (*lptr != ' ' && *lptr != '\t' && *lptr != '\000') { lptr++; }
  60.       if (*lptr != '\000')
  61.         {
  62.           *lptr++ = '\000';
  63.           while (*lptr == ' ' || *lptr == '\t') { lptr++; }
  64.         }
  65.       sprintf (envfile, "ENV:MetaToolPrefs/%s", linebuffer);
  66.       tfp = fopen (envfile, "w");
  67.       if (tfp == NULL)
  68.         {
  69.           fprintf (stderr, "%s: cannot open: ", envfile);
  70.           perror ("");
  71.           exit (1);
  72.         }
  73.       fputs (lptr, tfp);
  74.       fclose (tfp);
  75.     }
  76.     }
  77.   exit (0);
  78. }
  79.