home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
programs
/
printer
/
graphpaper
/
src
/
src.lha
/
files.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-06
|
4KB
|
159 lines
#include "graph.h"
struct AslBase *AslBase;
#define FILE_VERSION 1
static char *cat(char *str1, char *str2)
{
static char buf[200];
buf[0] = '\0';
if (*str1) {
strcpy(&buf, str1);
if (str1[strlen(str1)-1] != ':') {
strcat(&buf, "/");
}
}
strcat(&buf,str2);
return buf;
}
void load_settings(char *dir, char *file)
{
FILE *f;
char c1,c2;
int version;
char modestr[100];
if (f = fopen(cat(dir,file), "r")) {
sprintf(messagebuf, "Loading from file \"%s\"", cat(dir,file));
message(messagebuf);
fscanf(f, "%c%c%d\n", &c1,&c2,&version);
if (c1 != 'G' || c2 != 'P') {
message("Error: Not a GraphPaper settings file");
fclose(f);
return;
}
switch (version) {
case 1: message("FIX");
fscanf(f, "%d %d\n", &x_dpi_V, &y_dpi_V);
INTFIELD(x_dpi) = x_dpi_V;
INTFIELD(y_dpi) = y_dpi_V;
sprintf((char *)x_dpiSIBuff,"%d", INTFIELD(x_dpi));
sprintf((char *)y_dpiSIBuff,"%d", INTFIELD(y_dpi));
fscanf(f, "%d %d\n", &Minor_Thickness_V, &Major_Thickness_V);
INTFIELD(Minor_Thickness) = Minor_Thickness_V;
INTFIELD(Major_Thickness) = Major_Thickness_V;
sprintf((char *)Minor_ThicknessSIBuff,"%d",
INTFIELD(Minor_Thickness));
sprintf((char *)Major_ThicknessSIBuff,"%d",
INTFIELD(Major_Thickness));
fscanf(f, "%e %e\n", &x_size_v, &y_size_v);
size_init();
fscanf(f, "%d %d\n", &x_grids_page_v, &y_grids_page_v);
grids_init();
fscanf(f, "%d %d\n", &minor_x_v, &minor_y_v);
minors_init();
/* MinorMode */
fscanf(f, "%s\n", &modestr);
if (!strcmp(modestr, "None" )) MG_None (NULL);
if (!strcmp(modestr, "Linear")) MG_Linear(NULL);
if (!strcmp(modestr, "LogX" )) MG_LogX (NULL);
if (!strcmp(modestr, "LogY" )) MG_LogY (NULL);
if (!strcmp(modestr, "LogLog")) MG_LogLog(NULL);
RefreshGadgets(wG->FirstGadget, wG, NULL);
sprintf(messagebuf, "Load from file \"%s\" completed", cat(dir,file));
message(messagebuf);
break;
default:
message("Error: version incompatibility");
break;
}
fclose(f);
} else {
message("Could not open file");
}
}
void save_settings(char *dir, char *file)
{
FILE *f;
GetValues();
if (f = fopen(cat(dir,file), "w")) {
sprintf(messagebuf, "Saving to file \"%s\"", cat(dir,file));
message(messagebuf);
fprintf(f, "GP%d\n", FILE_VERSION);
fprintf(f, "%d %d\n", x_dpi_V, y_dpi_V);
fprintf(f, "%d %d\n", Minor_Thickness_V, Major_Thickness_V);
fprintf(f, "%e %e\n", x_size_v, y_size_v);
fprintf(f, "%d %d\n", x_grids_page_v, y_grids_page_v);
fprintf(f, "%d %d\n", minor_x_v, minor_y_v);
if (MinorMode == &None) fprintf(f,"None\n");
else if (MinorMode == &Linear) fprintf(f,"Linear\n");
else if (MinorMode == &LogX) fprintf(f,"LogX\n");
else if (MinorMode == &LogY) fprintf(f,"LogY\n");
else if (MinorMode == &LogLog) fprintf(f,"LogLog\n");
fclose(f);
sprintf(messagebuf, "Save completed to file \"%s\"", cat(dir,file));
message(messagebuf);
} else {
message("Could not open file");
}
}
static int OpenAsl()
{
if (!AslBase) AslBase = (struct AslBase *)OpenLibrary((UBYTE *)AslName, 0L);
if (!AslBase) {
message("Could not open Asl Library");
return 0;
}
return 1;
}
static void DoFileIO(void handler())
{
struct FileRequester *f;
if (OpenAsl()) {
f = AllocFileRequest();
if (RequestFile(f)) {
handler(f->rf_Dir, f->rf_File);
}
FreeFileRequest(f);
}
}
void Project_Load(APTR object)
{
DoFileIO(load_settings);
}
void Project_Save(APTR object)
{
DoFileIO(save_settings);
}