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 >
C/C++ Source or Header  |  1996-07-11  |  7KB  |  272 lines

  1. #include <stdio.h>
  2. #include <cstring.h>
  3. #include <dos.h>
  4. #include <io.h>
  5. #include "profile.h"
  6. #include "files.h"
  7. #include "log.h"
  8.  
  9. static const char * genie1Profile="+dogal1.ini";
  10. static const char * genie1Section="DOGA-L1";
  11. static const char * fxgaSection = "FXGA";
  12. static const char * pasmSection = "PartsAssembler";
  13. static const char * wireviewSection = "WireView";
  14.  
  15. string basedir;
  16. string pathdir;
  17. string partsdir;
  18. string simplepartsdir;
  19. string mechadir;
  20. string motiondir;
  21. string atrfile;
  22. string bgdir;
  23. string atrdir;
  24.  
  25. string fxgdir;
  26. string fxg_agcdir;
  27. string fxg_afmdir;
  28. string fxg_atrfile;
  29. string fxg_colfile;
  30. string fxg_atrdir;
  31. string fxg_bgdir;
  32.  
  33. string tempdir;
  34. string colorchangeatr;
  35. string rendoption;
  36. string rendcolor;
  37. string rendlight;
  38. //string bgdir;
  39. //string bgfile;
  40. PartsName *partsname = NULL;
  41. int partscount = 0;
  42.  
  43. int wireview_x, wireview_y, wireview_w, wireview_h;
  44.  
  45. PreviewMode fxgaflag = PREVIEW_FXGA;
  46.  
  47. static int scan3s(const char *str, char *title, char *catalog, char *parts)
  48. {
  49.     int i;
  50.     for (; *str && *str == ' '; ++str)
  51.         ;
  52.     if (*str == '\0') return FALSE;
  53.     for (i = 0; *str && *str != ','; ++str, ++i) {
  54.         title[i] = *str;
  55.     }
  56.     if (*str == '\0') return FALSE;
  57.     title[i] = '\0';
  58.     for (--i; i >= 0 && title[i] == ' '; --i) {
  59.         title[i] = '\0';
  60.     }
  61.     for (++str; *str && *str == ' '; ++str)
  62.         ;
  63.     if (*str == '\0') return FALSE;
  64.     for (i = 0; *str && *str != ','; ++str, ++i) {
  65.         catalog[i] = *str;
  66.     }
  67.     catalog[i] = '\0';
  68.     if (*str == '\0') return FALSE;
  69.     for (--i; i >= 0 && catalog[i] == ' '; --i) {
  70.         catalog[i] = '\0';
  71.     }
  72.     for (++str; *str && *str == ' '; ++str)
  73.         ;
  74.     if (*str == '\0') return FALSE;
  75.     for (i = 0; *str && *str != ','; ++str, ++i) {
  76.         parts[i] = *str;
  77.     }
  78.     parts[i] = '\0';
  79.     for (--i; i >= 0 && parts[i] == ' '; --i) {
  80.         parts[i] = '\0';
  81.     }
  82.     return TRUE;
  83. }
  84.  
  85.  
  86. static string DirCheck(string org)
  87. {
  88.     string str;
  89.  
  90.     if (org.length() > 1 && (org[0] == '\\' || org[1] == ':')) {
  91.         str = org;
  92.     } else {
  93.         str = basedir + org;
  94.     }
  95.     const char *p = str.c_str();
  96.     int l = strlen(p);
  97.     if (l > 0 && p[l-1] != '\\') {
  98.         str += "\\";
  99.     }
  100.     return str;
  101. }
  102.  
  103. static string FileCheck(string org)
  104. {
  105.     if (org.length() > 1 && (org[0] == '\\' || org[1] == ':')) {
  106.         return org;
  107.     } else {
  108.         return basedir + org;
  109.     }
  110. }
  111.  
  112. static string MacroExpand(string org)
  113. {
  114.     char *dst;
  115.     const char *src;
  116.     char str[256];
  117.     dst = str;
  118.     src = org.c_str();
  119.     for (; *src; ++src) {
  120.         if (*src == '$' && src[1]) {
  121.             switch(*++src) {
  122.             case 'B': case 'b':
  123.                 strcpy(dst, bgdir.c_str());
  124.                 dst += bgdir.length();
  125.                 break;
  126.             case 'P': case 'p':
  127.                 strcpy(dst, partsdir.c_str());
  128.                 dst += partsdir.length();
  129.                 break;
  130.             case 'X': case 'x':
  131.                 strcpy(dst, pathdir.c_str());
  132.                 dst += pathdir.length();
  133.                 break;
  134.             default:
  135.                 *dst++ = *src;
  136.             }
  137.         } else {
  138.             *dst++ = *src;
  139.         }
  140.     }
  141.     *dst = '\0';
  142.     return string(str);
  143. }
  144.  
  145. void FileInit(void)
  146. {
  147.     string tmpstr;
  148.     char *p;
  149.     char str[128];
  150.     strcpy(str, _argv[0]);
  151.     if ((p = strrchr(str, '\\')) == NULL) {
  152.         str[0] = '\0';
  153.     } else {
  154.         p[1] = '\0';
  155.     }
  156.     basedir = str;
  157.  
  158.     string catalogdir;
  159.     Profile profile(genie1Profile);
  160.  
  161.     profile.SetSection(genie1Section);
  162.     pathdir            = DirCheck(profile.GetString("ExecDir"));
  163.     partsdir           = DirCheck(profile.GetString("PartsDir"));
  164.     simplepartsdir  = DirCheck(profile.GetString("SimplePartsDir"));
  165.     mechadir           = DirCheck(profile.GetString("MechaDir"));
  166.     motiondir          = DirCheck(profile.GetString("MotionDir"));
  167.     atrfile            = FileCheck(profile.GetString("AtrFile"));
  168.     catalogdir         = DirCheck(profile.GetString("CatalogDir"));
  169.     bgdir              = DirCheck(profile.GetString("BGDir"));
  170.     atrdir             = DirCheck(profile.GetString("AtrDir"));
  171.  
  172.     tempdir         = DirCheck(profile.GetString("TempDir", pathdir.c_str()));
  173.  
  174.     profile.SetSection(fxgaSection);
  175.     fxgdir             = DirCheck(profile.GetString("ExecDir"));
  176.     fxg_bgdir          = DirCheck(profile.GetString("BGDir"));
  177.     fxg_agcdir         = DirCheck(profile.GetString("AGCDir"));
  178.     fxg_afmdir         = DirCheck(profile.GetString("AFMDir"));
  179.     fxg_atrfile        = FileCheck(profile.GetString("AtrFile"));
  180.     fxg_colfile        = FileCheck(profile.GetString("ColFile"));
  181.     fxg_atrdir         = DirCheck(profile.GetString("AtrDir"));
  182.  
  183.     profile.SetSection(genie1Section);
  184.  
  185.  
  186.     rendoption         = MacroExpand(profile.GetString("RendOption"));
  187.     rendcolor       = profile.GetString("RendColor","白");
  188.     rendlight       = profile.GetString("RendLight", "左上");
  189.  
  190.     colorchangeatr     = profile.GetString("ColorChangeAtr", "BodyM,BodyD");
  191. #if 0
  192.     string fxgamode = profile.GetString("FXGAMode");
  193.  
  194.     if (strcmpi(fxgamode.c_str(), "OFF") == 0
  195.      || strcmpi(fxgamode.c_str(), "0") == 0
  196.      || strcmpi(fxgamode.c_str(), "REND") == 0) {
  197.         fxgaflag = PREVIEW_REND;
  198.     } else if (strcmpi(fxgamode.c_str(), "BOTH") == 0) {
  199.         fxgaflag = PREVIEW_BOTH;
  200.     }
  201. #else
  202.     string fxgamode = profile.GetString("PC-FXGA");
  203.     if (strcmpi(fxgamode.c_str(), "EXIST") == 0) {
  204.         fxgaflag = PREVIEW_BOTH;
  205.     } else {
  206.         fxgaflag = PREVIEW_REND;
  207.     }
  208. #endif
  209. #if 0
  210.     if (access("PCFXPIO$",0) != 0) {
  211.         fxgaflag = PREVIEW_REND;
  212.     }
  213. #endif
  214.  
  215.     profile.SetSection(wireviewSection);
  216.     string wvpos = profile.GetString("Size");
  217.     wireview_x = wireview_y = wireview_w = wireview_h = -1;
  218.     if (wvpos.length() > 0) {
  219.         int x, y, w, h;
  220.         if (sscanf(wvpos.c_str(), "%d %d %d %d", &x, &y, &w, &h) == 4) {
  221.             wireview_x = x;
  222.             wireview_y = y;
  223.             wireview_w = w;
  224.             wireview_h = h;
  225.         }
  226.     }
  227.  
  228.     profile.SetSection(pasmSection);
  229.     int menus = profile.GetInt("MenuItems");
  230.     if (menus <= 0) {
  231.         return;
  232.     }
  233.     delete [] partsname;
  234.  
  235.     partsname = new PartsName[menus];
  236.     partscount = 0;
  237.     char title[32], parts[_MAX_PATH], catalog[_MAX_PATH];
  238.     char section[32];
  239.     for (int i = 0; i < menus; ++i) {
  240.         sprintf(section, "Menu%d", i+1);
  241.         string str = profile.GetString(section);
  242.         if (scan3s(str.c_str(), title, catalog, parts)) {
  243.             partsname[partscount].title = string(title);
  244.             partsname[partscount].partsfile = parts;
  245.             partsname[partscount].catalogfile = catalogdir + catalog;
  246.             partscount++;
  247.         }
  248.     }
  249. }
  250.  
  251. void FileWriteRendOption(void)
  252. {
  253.     Profile profile(genie1Profile);
  254.     profile.SetSection(genie1Section);
  255.     profile.PutString("RendOption", rendoption.c_str());
  256.     profile.PutString("RendColor", rendcolor.c_str());
  257.     profile.
  258.     PutString("RendLight", rendlight.c_str());
  259. }
  260.  
  261.  
  262. void FileWriteWireview(void)
  263. {
  264.     if (wireview_x >= 0 && wireview_y >= 0 && wireview_w >= 0 && wireview_h >= 0) {
  265.         Profile profile(genie1Profile);
  266.         profile.SetSection(wireviewSection);
  267.         char str[120];
  268.         sprintf(str, "%d %d %d %d", wireview_x, wireview_y, wireview_w, wireview_h);
  269.         profile.PutString("Size", str);
  270.     }
  271. }
  272.