home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 083.lha / PrefChange / SetPrefs.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  3KB  |  121 lines

  1. /*      SetPrefs.c by David W. Nipper 
  2.          placed in the Public Domain
  3.               9 November 1987                  */
  4.  
  5. /*  Loads a Preferences Configuration file
  6.     from the Devs: directory and inserts 
  7.     it into the system - useful for those
  8.     situations where there is more than
  9.     one type of printer in the system,
  10.     or several people sharing the system
  11.     have different ideas about what is
  12.     the best color combination.  The idea
  13.     is to be able to over-ride the system-
  14.     configuration file loaded at bootup
  15.     with another set of values.  This can
  16.     be done either from the CLI (or in a
  17.     batch file), or from a tool icon attach-
  18.     ed to a copy of this program, named with
  19.     the same name as the alternate prefer-
  20.     ences file in Devs:.                       */
  21.  
  22. /*  Preferences files can be copies of the
  23.     system-configuration file from your the
  24.     Devs: directory of your favorite boot
  25.     disk, or files saved at any time using
  26.     the SavePrefs program that accompanies
  27.     this file.                                 */
  28.  
  29. /*  Load a copy in the C: directory named
  30.     SetPref if you want to use this from
  31.     CLI or batch files.  Use IconEd to make
  32.     a tool icon named for your preference 
  33.     file if you want to use this from Work-
  34.     bench.  Then name a copy of SetPrefs
  35.     with the name (less the .info suffix)
  36.     and you will be ready to go.               */
  37.  
  38. /*  Done using AZTEC C V3.4                    */
  39.  
  40. #include <workbench/startup.h>
  41. #include <exec/types.h>
  42. #include <exec/memory.h>
  43. #include <intuition/intuition.h>
  44. #include <graphics/sprite.h>
  45. #include <libraries/dos.h>
  46. #define REV 0L
  47.  
  48. extern void *OpenLibrary(), *AllocMem(), *SetPrefs();
  49. extern struct FileHandle *Open();
  50. extern long Read();
  51. extern char *strcat();
  52. void *IntuitionBase;
  53. struct Preferences *Pref;
  54.  
  55. main (argc,argv)
  56. int argc;
  57. char **argv;
  58. {
  59.         struct FileHandle *InFil;
  60.         char *FileName;
  61.         struct WBStartup *StartMess;
  62.         long    ReadResult;
  63.  
  64.         openstuff();
  65.         if (argc) {
  66.           if (argc != 2) {
  67.             die("Must be one parameter exactly\n");
  68.           }
  69.           else {
  70.             argv++;  
  71.             FileName = *argv;
  72.           } 
  73.         }
  74.         else {
  75.           StartMess = (struct WBStartup *) argv;
  76.           if ((StartMess->sm_NumArgs) != 1) {
  77.             die("Must be one icon clicked Only!\n");
  78.           }
  79.           FileName = (StartMess->sm_ArgList)->wa_Name;
  80.         } 
  81.         Pref = AllocMem((long)sizeof(*Pref),(long)MEMF_PUBLIC);
  82.         if (!(Pref)) {
  83.           die ("Couldn't Allocate Memory\n");
  84.         }
  85.         FileName = strcat("devs:",FileName);
  86.         InFil = Open(FileName,MODE_OLDFILE);
  87.         ReadResult = Read(InFil,Pref,(long)sizeof(*Pref));
  88.         if (ReadResult == -1) {
  89.           Close(InFil);
  90.           die("Couldn't read file\n");
  91.         }
  92.         Close(InFil);
  93.         SetPrefs(Pref,(long)sizeof(*Pref),TRUE);
  94.         closestuff();
  95. }
  96.  
  97. openstuff ()
  98. {
  99.     if (!(IntuitionBase = OpenLibrary ("intuition.library", REV))) {
  100.                die ("Intuition open failed\n");
  101.         }
  102. }
  103.  
  104. closestuff ()
  105. {
  106.     if (Pref) {
  107.         FreeMem (Pref,(long)sizeof(*Pref));
  108.         }
  109.     if (IntuitionBase) {
  110.         CloseLibrary (IntuitionBase);
  111.         }
  112. }
  113.  
  114. die (str)
  115. char *str; 
  116. {
  117.     puts (str);
  118.     closestuff();
  119.     exit (100L);
  120. }
  121.