 /*
 * $Source: $
 * $Revision: $
 * $Date: $
 * $State: $
 * $Author: $
 *
 *
 * $Log: $
 *
 */

 /*
 *	Copyright (c) 1991 by the Massachusetts Institute of Technology,
 *	For copying and distribution information, see the file
 *	"mit-copyright.h".
 * 	preference.c  - WADE 6/3/91
 *
 *	  preference routines
 *
 *	pref_get_string()
 *	pref_put_string()
 *
 */
 
#include <Limits.h>
#include <Types.h>
#include <QuickDraw.h>
#include <Fonts.h>
#include <Events.h>
#include <Controls.h>
#include <Dialogs.h>
#include <Desk.h>
#include <Scrap.h>
#include <ToolUtils.h>
#include <Memory.h>
#include <SegLoad.h>
#include <OSUtils.h>
#include <Traps.h>
#include <string.h>
#include <resources.h>
#include "pips.h"
#include "prototype.h"
#include <stdio.h>
#include "mit-copyright.h"

/*
 *
 *  pref_get_string:  
 *	Retrieves the appropriate string from the STR resource.  The actual
 *	value of indicie is passed from the calling program and is a #define
 *	in pips.h.
 */
#pragma segment preference
void
pref_get_string(indicie, mystring)
int	indicie;
char	*mystring;
{
	Handle  h_str;
	
	h_str = GetString(indicie);
	if (h_str != nil) {
		p2cstr((char *) *h_str);
		strcpy(mystring, (char *) *h_str);
		ReleaseResource(h_str);
	}
	else
		BigBadError(NO_RESOURCE);
	
}

/*
 *
 *  pref_get_string:  
 *	Stores "mystring" in the STR resource
*/
#pragma segment preference
void
pref_put_string(indicie, mystring)
int	indicie;
char	*mystring;
{
	Handle  h_str;
	int	error;

	h_str = GetResource('STR ',indicie);
	if (h_str != nil) {
		SetString(h_str,(Str255) c2pstr(mystring));
		ChangedResource(h_str); 
		error = ResError();
		if (error != noErr)
			BigBadError(NO_RESOURCE);

		WriteResource((Handle)h_str);
		error = ResError();
		if (error != noErr) 
			BigBadError(NO_RESOURCE);

		ReleaseResource(h_str);
	}
	else
		BigBadError(NO_RESOURCE);
	
}

