home *** CD-ROM | disk | FTP | other *** search
- /* SetPrefs.c by David W. Nipper
- placed in the Public Domain
- 9 November 1987 */
-
- /* Loads a Preferences Configuration file
- from the Devs: directory and inserts
- it into the system - useful for those
- situations where there is more than
- one type of printer in the system,
- or several people sharing the system
- have different ideas about what is
- the best color combination. The idea
- is to be able to over-ride the system-
- configuration file loaded at bootup
- with another set of values. This can
- be done either from the CLI (or in a
- batch file), or from a tool icon attach-
- ed to a copy of this program, named with
- the same name as the alternate prefer-
- ences file in Devs:. */
-
- /* Preferences files can be copies of the
- system-configuration file from your the
- Devs: directory of your favorite boot
- disk, or files saved at any time using
- the SavePrefs program that accompanies
- this file. */
-
- /* Load a copy in the C: directory named
- SetPref if you want to use this from
- CLI or batch files. Use IconEd to make
- a tool icon named for your preference
- file if you want to use this from Work-
- bench. Then name a copy of SetPrefs
- with the name (less the .info suffix)
- and you will be ready to go. */
-
- /* Done using AZTEC C V3.4 */
-
- #include <workbench/startup.h>
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <intuition/intuition.h>
- #include <graphics/sprite.h>
- #include <libraries/dos.h>
- #define REV 0L
-
- extern void *OpenLibrary(), *AllocMem(), *SetPrefs();
- extern struct FileHandle *Open();
- extern long Read();
- extern char *strcat();
- void *IntuitionBase;
- struct Preferences *Pref;
-
- main (argc,argv)
- int argc;
- char **argv;
- {
- struct FileHandle *InFil;
- char *FileName;
- struct WBStartup *StartMess;
- long ReadResult;
-
- openstuff();
- if (argc) {
- if (argc != 2) {
- die("Must be one parameter exactly\n");
- }
- else {
- argv++;
- FileName = *argv;
- }
- }
- else {
- StartMess = (struct WBStartup *) argv;
- if ((StartMess->sm_NumArgs) != 1) {
- die("Must be one icon clicked Only!\n");
- }
- FileName = (StartMess->sm_ArgList)->wa_Name;
- }
- Pref = AllocMem((long)sizeof(*Pref),(long)MEMF_PUBLIC);
- if (!(Pref)) {
- die ("Couldn't Allocate Memory\n");
- }
- FileName = strcat("devs:",FileName);
- InFil = Open(FileName,MODE_OLDFILE);
- ReadResult = Read(InFil,Pref,(long)sizeof(*Pref));
- if (ReadResult == -1) {
- Close(InFil);
- die("Couldn't read file\n");
- }
- Close(InFil);
- SetPrefs(Pref,(long)sizeof(*Pref),TRUE);
- closestuff();
- }
-
- openstuff ()
- {
- if (!(IntuitionBase = OpenLibrary ("intuition.library", REV))) {
- die ("Intuition open failed\n");
- }
- }
-
- closestuff ()
- {
- if (Pref) {
- FreeMem (Pref,(long)sizeof(*Pref));
- }
- if (IntuitionBase) {
- CloseLibrary (IntuitionBase);
- }
- }
-
- die (str)
- char *str;
- {
- puts (str);
- closestuff();
- exit (100L);
- }
-