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

  1. /*      SavePrefs.c by David W. Nipper
  2.          placed in the Public Domain
  3.               9 November 1987                  */
  4.  
  5. /*   Creates a file in the Devs: directory
  6.      containing a copy of the current Pref-
  7.      erences in use.  This program runs 
  8.      only from the CLI.  These files are
  9.      intended for use with the companion
  10.      program SetPrefs.  Enter the  desired
  11.      name for the current Preferences set
  12.      and enter it after "SavePrefs".  You
  13.      do not add the "Devs:" path to the
  14.      name, that is done in the program for
  15.      you.  No alternate paths are supported
  16.      because that is where the SetPrefs
  17.      program will look for the file, and
  18.      that is where the system keeps such
  19.      information, anyway.                      */
  20.  
  21.  
  22.  
  23. #include <workbench/startup.h>
  24. #include <exec/types.h>
  25. #include <exec/memory.h>
  26. #include <intuition/intuition.h>
  27. #include <graphics/sprite.h>
  28. #include <libraries/dos.h>
  29. #define REV 0L
  30.  
  31. extern void *OpenLibrary(), *AllocMem();
  32. extern struct Preferences *GetPrefs();
  33. extern struct FileHandle *Open();
  34. extern char *strcat();
  35. void *IntuitionBase;
  36. struct Preferences *Pref;
  37.  
  38. main (argc,argv)
  39. int argc;
  40. char **argv;
  41. {
  42.         struct FileHandle *OutFil;
  43.         char *FileName;
  44.         long len;
  45.  
  46.         openstuff();
  47.         if (argc != 2) {
  48.           die("Must be one parameter exactly\n");
  49.         }
  50.         else {
  51.           argv++;
  52.           FileName = *argv;
  53.         } 
  54.         Pref = AllocMem((long)sizeof(*Pref),(long)MEMF_PUBLIC);
  55.         if (!(Pref))
  56.           die ("Couldn't Allocate Memory\n");
  57.         Pref = GetPrefs(Pref,(long)sizeof(*Pref)); 
  58.         FileName = strcat("Devs:",FileName);
  59.         OutFil = Open(FileName,MODE_NEWFILE);
  60.         len = Write(OutFil,Pref,(long)sizeof(*Pref));
  61.         if (len == -1) {
  62.           Close(OutFil);
  63.           die("Couldn't write file\n");
  64.         }
  65.         Close(OutFil);
  66.         closestuff();
  67. }
  68.  
  69. openstuff ()
  70. {
  71.     if (!(IntuitionBase = OpenLibrary ("intuition.library", REV))) {
  72.         die ("Intuition open failed\n");
  73.         }
  74. }
  75.  
  76. closestuff ()
  77. {
  78.     if (Pref) {
  79.         FreeMem (Pref,(long)sizeof(*Pref));
  80.         }
  81.     if (IntuitionBase) {
  82.         CloseLibrary (IntuitionBase);
  83.         }
  84. }
  85.  
  86. die (str)
  87. char *str; 
  88. {
  89.     puts (str);
  90.     closestuff();
  91.     exit (100L);
  92. }
  93.