home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
PASM.LZH
/
FILES.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-11
|
7KB
|
272 lines
#include <stdio.h>
#include <cstring.h>
#include <dos.h>
#include <io.h>
#include "profile.h"
#include "files.h"
#include "log.h"
static const char * genie1Profile="+dogal1.ini";
static const char * genie1Section="DOGA-L1";
static const char * fxgaSection = "FXGA";
static const char * pasmSection = "PartsAssembler";
static const char * wireviewSection = "WireView";
string basedir;
string pathdir;
string partsdir;
string simplepartsdir;
string mechadir;
string motiondir;
string atrfile;
string bgdir;
string atrdir;
string fxgdir;
string fxg_agcdir;
string fxg_afmdir;
string fxg_atrfile;
string fxg_colfile;
string fxg_atrdir;
string fxg_bgdir;
string tempdir;
string colorchangeatr;
string rendoption;
string rendcolor;
string rendlight;
//string bgdir;
//string bgfile;
PartsName *partsname = NULL;
int partscount = 0;
int wireview_x, wireview_y, wireview_w, wireview_h;
PreviewMode fxgaflag = PREVIEW_FXGA;
static int scan3s(const char *str, char *title, char *catalog, char *parts)
{
int i;
for (; *str && *str == ' '; ++str)
;
if (*str == '\0') return FALSE;
for (i = 0; *str && *str != ','; ++str, ++i) {
title[i] = *str;
}
if (*str == '\0') return FALSE;
title[i] = '\0';
for (--i; i >= 0 && title[i] == ' '; --i) {
title[i] = '\0';
}
for (++str; *str && *str == ' '; ++str)
;
if (*str == '\0') return FALSE;
for (i = 0; *str && *str != ','; ++str, ++i) {
catalog[i] = *str;
}
catalog[i] = '\0';
if (*str == '\0') return FALSE;
for (--i; i >= 0 && catalog[i] == ' '; --i) {
catalog[i] = '\0';
}
for (++str; *str && *str == ' '; ++str)
;
if (*str == '\0') return FALSE;
for (i = 0; *str && *str != ','; ++str, ++i) {
parts[i] = *str;
}
parts[i] = '\0';
for (--i; i >= 0 && parts[i] == ' '; --i) {
parts[i] = '\0';
}
return TRUE;
}
static string DirCheck(string org)
{
string str;
if (org.length() > 1 && (org[0] == '\\' || org[1] == ':')) {
str = org;
} else {
str = basedir + org;
}
const char *p = str.c_str();
int l = strlen(p);
if (l > 0 && p[l-1] != '\\') {
str += "\\";
}
return str;
}
static string FileCheck(string org)
{
if (org.length() > 1 && (org[0] == '\\' || org[1] == ':')) {
return org;
} else {
return basedir + org;
}
}
static string MacroExpand(string org)
{
char *dst;
const char *src;
char str[256];
dst = str;
src = org.c_str();
for (; *src; ++src) {
if (*src == '$' && src[1]) {
switch(*++src) {
case 'B': case 'b':
strcpy(dst, bgdir.c_str());
dst += bgdir.length();
break;
case 'P': case 'p':
strcpy(dst, partsdir.c_str());
dst += partsdir.length();
break;
case 'X': case 'x':
strcpy(dst, pathdir.c_str());
dst += pathdir.length();
break;
default:
*dst++ = *src;
}
} else {
*dst++ = *src;
}
}
*dst = '\0';
return string(str);
}
void FileInit(void)
{
string tmpstr;
char *p;
char str[128];
strcpy(str, _argv[0]);
if ((p = strrchr(str, '\\')) == NULL) {
str[0] = '\0';
} else {
p[1] = '\0';
}
basedir = str;
string catalogdir;
Profile profile(genie1Profile);
profile.SetSection(genie1Section);
pathdir = DirCheck(profile.GetString("ExecDir"));
partsdir = DirCheck(profile.GetString("PartsDir"));
simplepartsdir = DirCheck(profile.GetString("SimplePartsDir"));
mechadir = DirCheck(profile.GetString("MechaDir"));
motiondir = DirCheck(profile.GetString("MotionDir"));
atrfile = FileCheck(profile.GetString("AtrFile"));
catalogdir = DirCheck(profile.GetString("CatalogDir"));
bgdir = DirCheck(profile.GetString("BGDir"));
atrdir = DirCheck(profile.GetString("AtrDir"));
tempdir = DirCheck(profile.GetString("TempDir", pathdir.c_str()));
profile.SetSection(fxgaSection);
fxgdir = DirCheck(profile.GetString("ExecDir"));
fxg_bgdir = DirCheck(profile.GetString("BGDir"));
fxg_agcdir = DirCheck(profile.GetString("AGCDir"));
fxg_afmdir = DirCheck(profile.GetString("AFMDir"));
fxg_atrfile = FileCheck(profile.GetString("AtrFile"));
fxg_colfile = FileCheck(profile.GetString("ColFile"));
fxg_atrdir = DirCheck(profile.GetString("AtrDir"));
profile.SetSection(genie1Section);
rendoption = MacroExpand(profile.GetString("RendOption"));
rendcolor = profile.GetString("RendColor","白");
rendlight = profile.GetString("RendLight", "左上");
colorchangeatr = profile.GetString("ColorChangeAtr", "BodyM,BodyD");
#if 0
string fxgamode = profile.GetString("FXGAMode");
if (strcmpi(fxgamode.c_str(), "OFF") == 0
|| strcmpi(fxgamode.c_str(), "0") == 0
|| strcmpi(fxgamode.c_str(), "REND") == 0) {
fxgaflag = PREVIEW_REND;
} else if (strcmpi(fxgamode.c_str(), "BOTH") == 0) {
fxgaflag = PREVIEW_BOTH;
}
#else
string fxgamode = profile.GetString("PC-FXGA");
if (strcmpi(fxgamode.c_str(), "EXIST") == 0) {
fxgaflag = PREVIEW_BOTH;
} else {
fxgaflag = PREVIEW_REND;
}
#endif
#if 0
if (access("PCFXPIO$",0) != 0) {
fxgaflag = PREVIEW_REND;
}
#endif
profile.SetSection(wireviewSection);
string wvpos = profile.GetString("Size");
wireview_x = wireview_y = wireview_w = wireview_h = -1;
if (wvpos.length() > 0) {
int x, y, w, h;
if (sscanf(wvpos.c_str(), "%d %d %d %d", &x, &y, &w, &h) == 4) {
wireview_x = x;
wireview_y = y;
wireview_w = w;
wireview_h = h;
}
}
profile.SetSection(pasmSection);
int menus = profile.GetInt("MenuItems");
if (menus <= 0) {
return;
}
delete [] partsname;
partsname = new PartsName[menus];
partscount = 0;
char title[32], parts[_MAX_PATH], catalog[_MAX_PATH];
char section[32];
for (int i = 0; i < menus; ++i) {
sprintf(section, "Menu%d", i+1);
string str = profile.GetString(section);
if (scan3s(str.c_str(), title, catalog, parts)) {
partsname[partscount].title = string(title);
partsname[partscount].partsfile = parts;
partsname[partscount].catalogfile = catalogdir + catalog;
partscount++;
}
}
}
void FileWriteRendOption(void)
{
Profile profile(genie1Profile);
profile.SetSection(genie1Section);
profile.PutString("RendOption", rendoption.c_str());
profile.PutString("RendColor", rendcolor.c_str());
profile.
PutString("RendLight", rendlight.c_str());
}
void FileWriteWireview(void)
{
if (wireview_x >= 0 && wireview_y >= 0 && wireview_w >= 0 && wireview_h >= 0) {
Profile profile(genie1Profile);
profile.SetSection(wireviewSection);
char str[120];
sprintf(str, "%d %d %d %d", wireview_x, wireview_y, wireview_w, wireview_h);
profile.PutString("Size", str);
}
}