home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1999 March / VPR9903A.BIN / APUPDATE / VC / Tx300d / TX300D.LZH / TXCFGM.C < prev    next >
C/C++ Source or Header  |  1997-04-05  |  26KB  |  841 lines

  1. // WZ EDITOR 標準機能 拡張子設定テキストファイル入出力
  2. // Copyright 1996-97 TY
  3. // このマクロを使って、拡張子毎の設定の一部を共通にしたりできます。
  4. // このプログラムソースはWZ2.00以降でコンパイルできます。
  5. //2.99D 970327 製品に標準搭載
  6.  
  7. //2.99D 970327 renew
  8. // WZ2.0/WZ3.0相互変換機能
  9. // LPRINT,CONFIGSHARE入出力機能追加
  10.  
  11. // WZ2.0でも動作しなければならないので、
  12. // WZ2.0にないAPI(txInsertLine etc)は使えない。
  13.  
  14. //    __WZ__            version
  15. //    0x2000            2.00無印
  16. //    0x2001            2.00A
  17. //    0x2002            2.00B
  18. //    0x2003            2.00C
  19. //    0x2004            2.00D
  20. //    0x2005            2.00E
  21. //    0x2900-0x2999    3.00 alpha/beta
  22. //    0x3000            3.00
  23.  
  24. //{###設定}
  25.  
  26. #include <windows.h>
  27.  
  28. //## base
  29.  
  30. #if __WZ__ < 0x2900
  31.  
  32. TX* txAllocText(DWORD mode)
  33. {
  34. // text構造体を確保し、txInitText,txSetFileName(text,NULL)して返す
  35.     UINT size = sizeof(TX);
  36.     TX* text = malloc(size);
  37.     TX* p = text + 1;
  38.     if (text) {
  39.         txInitText(text);
  40.         txSetFileName(text,NULL);// 標準設定を読込む
  41.         return text;
  42.     }
  43.     return NULL;
  44. }
  45.  
  46. void txFreeText(TX* text)
  47. {
  48. // txAllocTextで得たtextをtxCloseして解放する
  49.     if (text) {
  50.         txClose(text);
  51.         free(text);
  52.     }
  53. }
  54.  
  55. TX* textopen(mchar* szfilename)
  56. {
  57. // szfilenameのファイルをオープンする。
  58. // ファイルの内容を読み込んだtextを返す
  59. // 失敗したらNULLを返す
  60. // テキストを使い終わったら必ずtextcloseしてtextを閉じて下さい。
  61.     TX* text = txAllocText(0);
  62.     if (text) {
  63.         txSetFileName(text,szfilename);
  64.         if (txOpenText(text)) {
  65.             return text;
  66.         }
  67.         txFreeText(text);
  68.     }
  69.     return NULL;
  70. }
  71.  
  72. void textclose(TX* text)
  73. {
  74. // textopenで開いたテキストを閉じる
  75.     txFreeText(text);
  76. }
  77.  
  78. #endif
  79.  
  80. //## output
  81.  
  82. static void define(TX* text)
  83. {
  84.     txInsertf(text,"#if __WZ__ >= 0x2900\n");
  85.     txInsertf(text,"    // configFile\n");
  86.     txInsertf(text,"    #define lflpProp            configDisuse\n");
  87.     txInsertf(text,"    #define dateGarbage            configDisuse\n");
  88.     txInsertf(text,"    #define lfBold2                configDisuse\n");
  89.     txInsertf(text,"    #define fDispKeywordBold    fDispKeyword\n");
  90.     txInsertf(text,"    #define fDispTitleBold        fDispTitle\n");
  91.     txInsertf(text,"    #define tfSetWidthByWindow    tmodeWidth\n");
  92.     txInsertf(text,"    // configShare\n");
  93.     txInsertf(text,"    #define nenvfastopen        configDisuse\n");
  94.     txInsertf(text,"    #define fFastOpen            configDisuse\n");
  95.     txInsertf(text,"    #define szExtVertical        reserved\n");
  96.     txInsertf(text,"    // configLprint\n");
  97.     txInsertf(text,"    #define szLetterHeader        szHeader2\n");
  98.     txInsertf(text,"    #define szLetterFooter        szFooter2\n");
  99.     txInsertf(text,"#endif\n");
  100. }
  101.  
  102. static void output(BOOL fStd)
  103. {
  104.     HWND hwnd = CreateWindow("COMBOBOX",NULL,
  105.         WS_CHILDWINDOW,
  106.         0,0,0,0,
  107.         text1->hwndbase,NULL,text1->hInstance,NULL
  108.     );
  109.     txConfigOp(text,TXCONFIGOP_EXTENUM,(LPVOID)hwnd);
  110.     int nname = SendMessage(hwnd,CB_GETCOUNT,0,0);
  111.     BOOL fNull = FALSE;
  112.     static mchar sznull[] = ".null";
  113.     {
  114.         TX _textdst;
  115.         TX* text = &_textdst;
  116.         TX* txdst = text;
  117.         txInitText(text);
  118.         {
  119.             mchar szfilename[CCHPATHNAME];
  120.             strcpy(szfilename,text->szexedir + "txcfgset.c");
  121.             #if __WZ__ >= 0x2005    //2.00E以上
  122.             if (!fStd) {
  123.                 pathFullConfig(szfilename,"txcfgset.c");
  124.             }
  125.             #endif
  126.             txSetFileName(text,szfilename);
  127.         }
  128.         txOpenText(text);
  129.         //
  130.         static mchar *szauto = "//##auto";
  131.         if (txSearchEx(text,szauto,SEARCH_PARATOP|SEARCH_CUR)) {
  132.             txSelect(text);
  133.             txJumpFileEnd(text);
  134.             txSelectDelete(text);
  135.         }
  136.         //
  137.         static mchar *szshare = "void configFileShare(tx* text,mchar* szname)";
  138.         txJumpFileTop(text);
  139.         if (!txSearchEx(text,szshare,SEARCH_PARATOP|SEARCH_CUR)) {
  140.             txJumpFileTop(text);
  141.             txInsertf(text,"// 全ての拡張子で共通にしたい内容をここに記述してください\n");
  142.             txInsertf(text,"%s\n{\n",szshare);
  143.             txInsertf(text,"//\t例\n");
  144.             txInsertf(text,"//\ttext->rgbBack = RGB(0,0,0);\t//背景\n");
  145.             txInsertf(text,"//\tstrcpy(text->tszformat[SZFORMAT_BOLD_TOP],\"【\");\t//太字書式文字列\n");
  146.             txInsertf(text,"}\n\n");
  147.         }
  148.         //
  149.         txJumpFileEnd(text);
  150.         txInsertf(text,"%s\n",szauto);
  151.         txInsert(text,"// サブファイル1 \"txcfgs1.c\"\n");
  152.         txInsert(text,"// サブファイル2 \"txcfgs2.c\"\n");
  153.         txInsert(text,"// サブファイル3 \"txcfgs3.c\"\n");
  154.         txInsert(text,"// サブファイル4 \"txcfgs4.c\"\n");
  155.         txInsert(text,"// サブファイル5 \"txcfgs5.c\"\n");
  156.         txInsert(text,"// サブファイル6 \"txcfgs6.c\"\n");
  157.         txInsert(text,"// サブファイル7 \"txcfgs7.c\"\n");
  158.         txInsert(text,"// サブファイル8 \"txcfgs8.c\"\n");
  159.         txInsert(text,"// サブファイル9 \"txcfgs9.c\"\n");
  160.         txInsertf(text,"// ここから下のプログラムはWZが作成します\n");
  161.         txInsertf(text,"// この部分に記述したプログラムは失われます\n");
  162.         //2.99D 970327 
  163.         define(text);
  164.         txInsertf(text,"extern \"txcfgs1\" {\n");
  165.         txInsertf(text,"    BOOL configFile1(TX* text,mchar* szname);\n");
  166.         txInsertf(text,"    BOOL configLprint1(TX* text,mchar* szname);\n");
  167.         txInsertf(text,"}\n");
  168.         txInsertf(text,"extern \"txcfgs2\" {\n");
  169.         txInsertf(text,"    BOOL configFile2(TX* text,mchar* szname);\n");
  170.         txInsertf(text,"    BOOL configLprint2(TX* text,mchar* szname);\n");
  171.         txInsertf(text,"}\n");
  172.         txInsertf(text,"extern \"txcfgs3\" {\n");
  173.         txInsertf(text,"    BOOL configFile3(TX* text,mchar* szname);\n");
  174.         txInsertf(text,"    BOOL configLprint3(TX* text,mchar* szname);\n");
  175.         txInsertf(text,"}\n");
  176.         txInsertf(text,"extern \"txcfgs4\" {\n");
  177.         txInsertf(text,"    BOOL configFile4(TX* text,mchar* szname);\n");
  178.         txInsertf(text,"    BOOL configLprint4(TX* text,mchar* szname);\n");
  179.         txInsertf(text,"}\n");
  180.         txInsertf(text,"extern \"txcfgs5\" {\n");
  181.         txInsertf(text,"    BOOL configFile5(TX* text,mchar* szname);\n");
  182.         txInsertf(text,"    BOOL configLprint5(TX* text,mchar* szname);\n");
  183.         txInsertf(text,"}\n");
  184.         txInsertf(text,"extern \"txcfgs6\" {\n");
  185.         txInsertf(text,"    BOOL configFile6(TX* text,mchar* szname);\n");
  186.         txInsertf(text,"    BOOL configLprint6(TX* text,mchar* szname);\n");
  187.         txInsertf(text,"}\n");
  188.         txInsertf(text,"extern \"txcfgs7\" {\n");
  189.         txInsertf(text,"    BOOL configFile7(TX* text,mchar* szname);\n");
  190.         txInsertf(text,"    BOOL configLprint7(TX* text,mchar* szname);\n");
  191.         txInsertf(text,"}\n");
  192.         txInsertf(text,"extern \"txcfgs8\" {\n");
  193.         txInsertf(text,"    BOOL configFile8(TX* text,mchar* szname);\n");
  194.         txInsertf(text,"    BOOL configLprint8(TX* text,mchar* szname);\n");
  195.         txInsertf(text,"}\n");
  196.         txInsertf(text,"extern \"txcfgs9\" {\n");
  197.         txInsertf(text,"    BOOL configFile9(TX* text,mchar* szname);\n");
  198.         txInsertf(text,"    BOOL configLprint9(TX* text,mchar* szname);\n");
  199.         txInsertf(text,"}\n");
  200.         //
  201.         {
  202.             int iname = 0;
  203.             for (int i = 1;i <= 9;i++) {
  204.                 mchar szfilename[CCHPATHNAME];
  205.                 strcpy(szfilename,text->szfilename);
  206.                 sprintf(pathGetFileName(szfilename),\"txcfgs%d.c",i);
  207. //information(szfilename);
  208.                 TX* txs = textopen(szfilename);
  209.                 txDeleteText(txs);
  210.                 txInsertReturn(txs);
  211.                 define(txs);
  212.                 txInsertf(txs,"\nBOOL configFile%d(TX* text,mchar* szname)\n{\n",i);
  213.                 {
  214.                     TX* txtmp = textopen(NULL);
  215.                     // 全部出力すると64KBを越えてしまうので、
  216.                     // 4個ずつ9つに分けて出力
  217.                     for (int i = 0;i < 4;i++) {
  218.                         mchar szname[CCHWORD];
  219.                         if (iname < nname) {
  220.                             SendMessage(hwnd,CB_GETLBTEXT,iname,(LPARAM)szname);
  221.                             strcpy(txtmp->szfilename,szname);
  222.                             txConfigOp(txtmp,TXCONFIGOP_EXTLOAD,0);
  223.                             //
  224.                             txInsertf(txs,"    if (!stricmp(szname,\"%s\")) {\n",szname);
  225.                             macroCall("txcfgc.txcfg",NULL,2,txs,txtmp);
  226.                             txInsertf(txs,"        return TRUE;\n");
  227.                             txInsertf(txs,"    }\n");
  228.                             //
  229.                             iname++;
  230.                         } else {
  231.                             break;
  232.                         }
  233.                     }
  234.                     textclose(txtmp);
  235.                 }
  236.                 txInsertf(txs,"    return FALSE;\n");
  237.                 txInsertf(txs,"}\n");
  238.                 txSave(txs);
  239.                 textclose(txs);
  240.             }
  241.             if (iname < nname) {
  242.                 information("設定が多すぎます。\n全部はテキスト化できませんでした。\n");
  243.             }
  244.         }
  245.         //
  246.         txInsertf(text,"// 拡張子毎の設定を作成します\n");
  247.         txInsertf(text,"wzcfgFile\n{\n");
  248.         // ここはtext1ではだめ
  249.         txInsertf(text,"    TX _text;\n");
  250.         txInsertf(text,"    TX* text = &_text;\n");
  251.         txInsertf(text,"    txInitText(text);\n");
  252.         txInsertf(text,"    txOpenText(text);\n");
  253.         txInsertf(text,"    txConfigOp(text,TXCONFIGOP_EXTDELALL,0);\n");
  254.         //
  255.         txInsertf(text,"\tstatic mchar *tszname[] = {\n");
  256.         {
  257.             for (int i = 0;i < nname;i++) {
  258.                 mchar szname[CCHWORD];
  259.                 SendMessage(hwnd,CB_GETLBTEXT,i,(LPARAM)szname);
  260.                 txInsertf(text,"        \"%s\",\n",szname);
  261.             }
  262.         }
  263.         if (!fNull) txInsertf(text,"        \"%s\",\n",sznull);
  264.         txInsertf(text,"        NULL\n");
  265.         txInsertf(text,"    };\n");
  266.         //
  267.         txInsertf(text,"    for (int i = 0;tszname[i];i++) {\n");
  268.         txInsertf(text,"        // for load std\n");
  269.         txInsertf(text,"        txClose(text);\n");
  270.         txInsertf(text,"        txInitText(text);\n");
  271.         txInsertf(text,"        txSetFileName(text,NULL);\n");
  272.         txInsertf(text,"        txOpenText(text);\n");
  273.         txInsertf(text,"        //\n");
  274.         txInsertf(text,"        configFile1(text,tszname[i]);\n");
  275.         txInsertf(text,"        configFile2(text,tszname[i]);\n");
  276.         txInsertf(text,"        configFile3(text,tszname[i]);\n");
  277.         txInsertf(text,"        configFile4(text,tszname[i]);\n");
  278.         txInsertf(text,"        configFile5(text,tszname[i]);\n");
  279.         txInsertf(text,"        configFile6(text,tszname[i]);\n");
  280.         txInsertf(text,"        configFile7(text,tszname[i]);\n");
  281.         txInsertf(text,"        configFile8(text,tszname[i]);\n");
  282.         txInsertf(text,"        configFile9(text,tszname[i]);\n");
  283.         txInsertf(text,"        configFileShare(text,tszname[i]);\n");
  284.         txInsertf(text,"        txConfigOp(text,TXCONFIGOP_EXTNAME_SAVE,tszname[i]);\n");
  285.         txInsertf(text,"    }\n");
  286.         txInsertf(text,"    txClose(text);\n");
  287.         txInsertf(text,"}\n\n");
  288.         //2.99D 970327 configShare
  289.         {
  290.             txInsertf(text,"void configShare(TX* text)\n{\n");
  291.             txInsertf(text,"\tTXCONFIGSHARE* shcfg = &text->share->config;\n");
  292.                 macroCall("txcfgc.txcfgShare",NULL,2,text,&text1->share->config);
  293.             txInsertf(text,"}\n\n");
  294.             //
  295.             txInsertf(text,"// WZ共通基本設定を作成します\n");
  296.             txInsertf(text,"wzcfgShare\n{\n");
  297.             txInsertf(text,"\tTX* text = text1;\n");
  298.             txInsertf(text,"\tconfigShare(text);\n");
  299.             txInsertf(text,"\ttxConfigOp(text,TXCONFIGOP_SHARESAVE,0);\n");
  300.             txInsertf(text,"}\n\n");
  301.         }
  302.         //2.99D 970327 LPRINT
  303.         {
  304.             txConfigOp(text,TXCONFIGOP_PRINTENUM,(LPVOID)hwnd);
  305.             int nlp = SendMessage(hwnd,CB_GETCOUNT,0,0);
  306.             int ilp = 0;
  307.             for (int i = 1;i <= 9;i++) {
  308.                 mchar szfilename[CCHPATHNAME];
  309.                 strcpy(szfilename,text->szfilename);
  310.                 sprintf(pathGetFileName(szfilename),\"txcfgs%d.c",i);
  311. //information(szfilename);
  312.                 TX* txs = textopen(szfilename);
  313.                 txJumpFileEnd(txs);
  314.                 txInsertf(txs,"\nBOOL configLprint%d(TX* text,mchar* szname)\n{\n",i);
  315.                 txInsertf(txs,"    LPRINT* lp = text->lp;\n");
  316.                 // 4個ずつ出力
  317.                 for (int i = 0;i < 4;i++) {
  318.                     mchar szname[CCHWORD];
  319.                     if (ilp < nlp) {
  320.                         SendMessage(hwnd,CB_GETLBTEXT,ilp,(LPARAM)szname);
  321.                         txConfigOp(txs,TXCONFIGOP_PRINTREAD,szname);
  322.                         txInsertf(txs,"    if (!stricmp(szname,\"%s\")) {\n",szname);
  323.                         macroCall("txcfgc.txcfgLprint",NULL,2,txs,txs->lp);
  324.                         txInsertf(txs,"        return TRUE;\n");
  325.                         txInsertf(txs,"\t}\n");
  326.                         //
  327.                         ilp++;
  328.                     } else {
  329.                         break;
  330.                     }
  331.                 }
  332.                 txInsertf(txs,"    return FALSE;\n");
  333.                 txInsertf(txs,"}\n");
  334.                 txSave(txs);
  335.                 textclose(txs);
  336.             }
  337.             if (ilp < nlp) {
  338.                 information("印刷スタイルが多すぎます。\n全部はテキスト化できませんでした。\n");
  339.             }
  340.             //
  341.             txInsertf(text,"// 印刷スタイルの設定を作成します\n");
  342.             txInsertf(text,"wzcfgLprint\n{\n");
  343.             txInsertf(text,"    TX* text = text1;\n");
  344.             txInsertf(text,"    txConfigOp(text,TXCONFIGOP_PRINTDELALL,0);\n");
  345.             //
  346.             txInsertf(text,"    static mchar *tszname[] = {\n");
  347.             for (int ilp = 0;ilp < nlp;ilp++) {
  348.                 mchar szname[CCHWORD];
  349.                 SendMessage(hwnd,CB_GETLBTEXT,ilp,(LPARAM)szname);
  350.                 txInsertf(text,"        \"%s\",\n",szname);
  351.             }
  352.             txInsertf(text,"        NULL\n");
  353.             txInsertf(text,"    };\n");
  354.             //
  355.             txInsertf(text,"    int i;\n");
  356.             txInsertf(text,"    for (i = 0;tszname[i];i++) {\n");
  357.             txInsertf(text,"        configLprint1(text,tszname[i]);\n");
  358.             txInsertf(text,"        configLprint2(text,tszname[i]);\n");
  359.             txInsertf(text,"        configLprint3(text,tszname[i]);\n");
  360.             txInsertf(text,"        configLprint4(text,tszname[i]);\n");
  361.             txInsertf(text,"        configLprint5(text,tszname[i]);\n");
  362.             txInsertf(text,"        configLprint6(text,tszname[i]);\n");
  363.             txInsertf(text,"        configLprint7(text,tszname[i]);\n");
  364.             txInsertf(text,"        configLprint8(text,tszname[i]);\n");
  365.             txInsertf(text,"        configLprint9(text,tszname[i]);\n");
  366.             txInsertf(text,"        txConfigOp(text,TXCONFIGOP_PRINTWRITE,tszname[i]);\n");
  367.             txInsertf(text,"    }\n");
  368.             txInsertf(text,"}\n\n");
  369.         }
  370.         //
  371.         txInsertf(text,"main\n");
  372.         txInsertf(text,"{\n");
  373.         #if __WZ__ >= 0x2994
  374.         txInsert(text,"    text->share->fNoPathSearchMacroTxcfgs++;\n");
  375.         #endif
  376.         txInsertf(text,"    wzcfgShare();\n");
  377.         txInsertf(text,"    wzcfgFile();\n");
  378.         txInsertf(text,"    wzcfgLprint();\n");
  379.         #if __WZ__ >= 0x2994
  380.         txInsert(text,"    text->share->fNoPathSearchMacroTxcfgs--;\n");
  381.         #endif
  382. #if 1//2.99G 970405 TEXT_HTMLをセットしないとHTMLファイルがHTMLとして認識されない
  383.         // HTML
  384.         txInsertf(text,"    {\n");
  385.         txInsertf(text,"        mchar* sz = \"HTMLファイル\";\n");
  386.         txInsertf(text,"        if (txConfigOp(text,TXCONFIGOP_EXTNAME_SEARCH,sz)) {\n");
  387.         txInsertf(text,"            txConfigOp(text,TXCONFIGOP_EXTNAME_LOAD,sz);\n");
  388.         txInsertf(text,"            text->filekind = TEXT_HTML;\n");
  389.         txInsertf(text,"            text->fDispTag = TRUE;\n");
  390.         txInsertf(text,"            txConfigOp(text,TXCONFIGOP_EXTNAME_SAVE,sz);\n");
  391.         txInsertf(text,"        }\n");
  392.         txInsertf(text,"    }\n");
  393.         txInsertf(text,"    {\n");
  394.         txInsertf(text,"        mchar* sz = \".HTML\";\n");
  395.         txInsertf(text,"        if (txConfigOp(text,TXCONFIGOP_EXTNAME_SEARCH,sz)) {\n");
  396.         txInsertf(text,"            txConfigOp(text,TXCONFIGOP_EXTNAME_LOAD,sz);\n");
  397.         txInsertf(text,"            text->filekind = TEXT_HTML;\n");
  398.         txInsertf(text,"            text->fDispTag = TRUE;\n");
  399.         txInsertf(text,"            txConfigOp(text,TXCONFIGOP_EXTNAME_SAVE,sz);\n");
  400.         txInsertf(text,"        }\n");
  401.         txInsertf(text,"    }\n");
  402.         txInsertf(text,"    {\n");
  403.         txInsertf(text,"        mchar* sz = \".HTM\";\n");
  404.         txInsertf(text,"        if (txConfigOp(text,TXCONFIGOP_EXTNAME_SEARCH,sz)) {\n");
  405.         txInsertf(text,"            txConfigOp(text,TXCONFIGOP_EXTNAME_LOAD,sz);\n");
  406.         txInsertf(text,"            text->filekind = TEXT_HTML;\n");
  407.         txInsertf(text,"            text->fDispTag = TRUE;\n");
  408.         txInsertf(text,"            txConfigOp(text,TXCONFIGOP_EXTNAME_SAVE,sz);\n");
  409.         txInsertf(text,"        }\n");
  410.         txInsertf(text,"    }\n");
  411.         // .C
  412.         txInsertf(text,"    {\n");
  413.         txInsertf(text,"        mchar* sz = \"Cプログラム\";\n");
  414.         txInsertf(text,"        if (txConfigOp(text,TXCONFIGOP_EXTNAME_SEARCH,sz)) {\n");
  415.         txInsertf(text,"            txConfigOp(text,TXCONFIGOP_EXTNAME_LOAD,sz);\n");
  416.         txInsertf(text,"            text->filekind = TEXT_C;\n");
  417.         txInsertf(text,"            txConfigOp(text,TXCONFIGOP_EXTNAME_SAVE,sz);\n");
  418.         txInsertf(text,"        }\n");
  419.         txInsertf(text,"    }\n");
  420.         txInsertf(text,"    {\n");
  421.         txInsertf(text,"        mchar* sz = \".C\";\n");
  422.         txInsertf(text,"        if (txConfigOp(text,TXCONFIGOP_EXTNAME_SEARCH,sz)) {\n");
  423.         txInsertf(text,"            txConfigOp(text,TXCONFIGOP_EXTNAME_LOAD,sz);\n");
  424.         txInsertf(text,"            text->filekind = TEXT_C;\n");
  425.         txInsertf(text,"            txConfigOp(text,TXCONFIGOP_EXTNAME_SAVE,sz);\n");
  426.         txInsertf(text,"        }\n");
  427.         txInsertf(text,"    }\n");
  428. #endif
  429.         txInsert(text,"    information(\"設定を読み込みました。\\n新しい設定は次に開くファイルから有効になります。\\n今現在開いているWZの窓の設定は古いままです。\\nこの窓で設定を行うと古い設定が保存されるので注意してください。\");\n");
  430.         txInsertf(text,"}\n");
  431.         //
  432.         txSave(text);
  433.         txClose(text);
  434.     }
  435.     DestroyWindow(hwnd);
  436. }
  437.  
  438. //## create macro
  439.  
  440. void num(tx* text,mchar *sz,long data)
  441. {
  442.     txInsertf(text,"\t\t%s = %d;\n",sz,data);
  443. }
  444.  
  445. void numRGB(tx* text,mchar *sz,long data)
  446. {
  447.     txInsertf(text,"\t\t%s = RGB(%d,%d,%d);\n",sz,GetRValue(data),GetGValue(data),GetBValue(data));
  448. }
  449.  
  450. static int inttohex(int c)
  451. {
  452.     if (c >= 10) return c - 10 + 'A';
  453.     return c + '0';
  454. }
  455.  
  456. static mchar* mystrtoesc(mchar *szstr)
  457. {
  458. // 制御文字を\によるエスケープ文字に変換します
  459. // タブ->'\t'、改行(CR+LF)->'\n'に変換します。
  460. // "0x01" - "0x1F"は"\x01" - "\x1F"に変換します。
  461. // szstrを返します
  462. // 文字列の長さが長くなりますので、szstrのバッファサイズは十分な大きさをとって下さい
  463.     mchar *src = szstr;
  464.     mchar szbuff[CCHLINE];
  465.     mchar *dst = szbuff;
  466.     int c;
  467.     
  468.     while(c = *src++) {
  469.         if (iskanji(c)) {
  470.             *dst++ = c;
  471.             *dst++ = *src++;
  472.         } else if (c == '\t') {
  473.             *dst++ = '\\';
  474.             *dst++ = 't';
  475.         } else if (c == '\\') {//2.99D 970328 
  476.             *dst++ = '\\';
  477.             *dst++ = '\\';
  478.         } else if (c == '\"') {//2.99D 970328 
  479.             *dst++ = '\\';
  480.             *dst++ = '\"';
  481.         } else if (c == 0x0D && *src == 0x0D) {
  482.             *dst++ = '\\';
  483.             *dst++ = 'n';
  484.             src++;
  485.         } else if (c < 0x20) {
  486.             *dst++ = '\\';
  487.             *dst++ = 'x';
  488.             *dst++ = inttohex(c / 16);
  489.             *dst++ = inttohex(c & 0x0F);
  490.         } else {
  491.             *dst++ = c;
  492.         }
  493.     }
  494.     *dst = 0;
  495.     strcpy(szstr,szbuff);
  496.     return szstr;
  497. }
  498.  
  499. void str(tx* text,mchar *sz,mchar* szdata)
  500. {
  501. #if 1    //2.99D 970327 パス区切りの'\'がそのままだった。
  502.     // '\' -> '\\','"'->'\"'に変える
  503.     // バイナリ文字は"\xXX"に変える
  504.     #if __WZ__ < 0x2900
  505.         // WZ2.0ではtszformatでタブが\tのように入っている
  506.         if (strimatch(sz,"text->tszformat")) {
  507.             // そのまま出力
  508.             txInsertf(text,"\t\tstrcpy(%s,",sz);
  509.             txInsertf(text,"\"%s\");\n",szdata);
  510.             return;
  511.         }
  512.     #endif
  513.     mchar buff[CCHLINE];
  514.     strcpy(buff,szdata);
  515.     mystrtoesc(buff);
  516.     //
  517.     txInsertf(text,"\t\tstrcpy(%s,",sz);
  518.     txInsertf(text,"\"%s\");\n",buff);
  519. #else
  520.     mchar buff[CCHLINE];
  521.     strcpy(buff,szdata);
  522.     strtoesc(buff);
  523.     txInsertf(text,"\t\tstrcpy(%s,\"%s\");\n",sz,buff);
  524. #endif
  525. }
  526.  
  527. static BOOL _num(tx* txdst,mchar* szContext,mchar* p,int len)
  528. {
  529.     BOOL frgb = !strnicmp(p,"COLORREF",len);
  530.     p += len;
  531.     p = strGetWordTop(p);
  532.     mchar* p1 = strchrs(p,";:");
  533.     if (!p1) return FALSE;
  534.     len = p1 - p;
  535.     //
  536.     mchar szid[CCHWORD];
  537.     strcpylen(szid,p,len);
  538.     if (strmatch(szid,"reserved")) return FALSE;
  539.     int n = 1;
  540. #if 1//2.99D 970327 
  541.     if (strmatch(szid,"t") && strstr(szid,"[DISPSTYLEMODE_N]")) {
  542.         mchar* p = strchr(szid,'[');
  543.         if (p) *p = 0;
  544.         n = DISPSTYLEMODE_N;
  545.     }
  546. #else
  547.     if (
  548.         strmatch(szid,"twidth[") ||
  549.         strmatch(szid,"theight[") ||
  550.         strmatch(szid,"tcyint[") ||
  551.         strmatch(szid,"tfPageTurn[") ||
  552.         strmatch(szid,"tfVertical[") ||
  553.         strmatch(szid,"tfSetWidthByWindow[") ||
  554.         strmatch(szid,"tmodeWs[") ||
  555.         strmatch(szid,"tlcxWindowDefault[") ||
  556.         strmatch(szid,"tlcyWindowDefault[")
  557.     ) {
  558.         mchar* p = strchr(szid,'[');
  559.         if (p) *p = 0;
  560.         n = DISPSTYLEMODE_N;
  561.     }
  562. #endif
  563.     if (n >= 2) {
  564.         int i;
  565.         for (i = 0;i < n;i++) {
  566.             txInsertf(txdst,"\tnum(txdst,\"%s%s[%d]\",%s%s[%d]);\n",
  567.                 szContext,szid,i,
  568.                 szContext,szid,i
  569.             );
  570.         }
  571.     } else {
  572.         txInsertf(txdst,"\tnum%s(txdst,\"%s%s\",%s%s);\n",
  573.             frgb ? "RGB" : "",
  574.             szContext,
  575.             szid,
  576.             szContext,
  577.             szid
  578.         );
  579.     }
  580.     return TRUE;
  581. }
  582.  
  583. static BOOL _str(tx* txdst,mchar* szContext,mchar* p,int len)
  584. {
  585.     p += len;
  586.     p = strGetWordTop(p);
  587.     mchar* p1 = strchr(p,'[');
  588.     if (!p1) return FALSE;
  589.     len = p1 - p;
  590.     //
  591.     mchar szid[CCHWORD];
  592.     strcpylen(szid,p,len);
  593.     if (strmatch(szid,"reserved")) return FALSE;
  594.     int n = 1;
  595.     if (strmatch(szid,"tsztitle")) {
  596.         n = SZTITLE_N;
  597.     } else if (strmatch(szid,"tszformat")) {
  598.         n = FORMAT_N;
  599.     } else if (strmatch(szid,"tszhelp")) {
  600.         n = HELP_N;
  601.     } else if (strmatch(szid,"szenvinclude")) {//2.99D 970327 
  602.         n = 2;
  603.     } else if (strmatch(szid,"szPathTxpcode")) {//2.99D 970327 
  604.         n = 2;
  605.     }
  606.     if (n >= 2) {
  607.         int i;
  608.         for (i = 0;i < n;i++) {
  609.             txInsertf(
  610.                 txdst,
  611.                 "\tstr(txdst,\"%s%s[%d]\",%s%s[%d]);\n",
  612.                 szContext,szid,i,
  613.                 szContext,szid,i
  614.             );
  615.         }
  616.     } else {
  617.         txInsertf(
  618.             txdst,
  619.             "\tstr(txdst,\"%s%s\",%s%s);\n",
  620.             szContext,szid,
  621.             szContext,szid
  622.         );
  623.     }
  624.     return TRUE;
  625. }
  626.  
  627. static void fontstyle(TX* txdst,mchar* szContext,int n)
  628. {
  629.     for (int i = 0;i < n;i++) {
  630.         txInsertf(txdst,"\tstr(txdst,\"%stFontstyle[%d].tlfFaceName[IFONT_STD]\",%stFontstyle[%d].tlfFaceName[IFONT_STD]);\n",szContext,i,szContext,i);
  631.         txInsertf(txdst,"\tstr(txdst,\"%stFontstyle[%d].tlfFaceName[IFONT_ANK]\",%stFontstyle[%d].tlfFaceName[IFONT_ANK]);\n",szContext,i,szContext,i);
  632.         txInsertf(txdst,"\tnum(txdst,\"%stFontstyle[%d].tlfHeight[IFONT_STD]\",%stFontstyle[%d].tlfHeight[IFONT_STD]);\n",szContext,i,szContext,i);
  633.         txInsertf(txdst,"\tnum(txdst,\"%stFontstyle[%d].tlfHeight[IFONT_ANK]\",%stFontstyle[%d].tlfHeight[IFONT_ANK]);\n",szContext,i,szContext,i);
  634.         txInsertf(txdst,"\tnum(txdst,\"%stFontstyle[%d].perNline\",%stFontstyle[%d].perNline);\n",szContext,i,szContext,i);
  635.         txInsertf(txdst,"\tnum(txdst,\"%stFontstyle[%d].modeAlign\",%stFontstyle[%d].modeAlign);\n",szContext,i,szContext,i);
  636.         txInsertf(txdst,"\tnum(txdst,\"%stFontstyle[%d].fBold\",%stFontstyle[%d].fBold);\n",szContext,i,szContext,i);
  637.         txInsertf(txdst,"\tnum(txdst,\"%stFontstyle[%d].fItalic\",%stFontstyle[%d].fItalic);\n",szContext,i,szContext,i);
  638.         txInsertf(txdst,"\tnum(txdst,\"%stFontstyle[%d].fUnderline\",%stFontstyle[%d].fUnderline);\n",szContext,i,szContext,i);
  639.     }
  640. }
  641.  
  642. static BOOL processline(TX* text,TX* txdst,txstr szline,mchar* szContext)
  643. {
  644.     mchar*p = szline;
  645.     BOOL fout = FALSE;
  646.     if (
  647.         *p == '\t' ||
  648.         strmatch(p,"BBOOL fMyColor")    //2.99D 970328 
  649.     ) {
  650.         if (*p == '\t') p++;
  651.         int len;
  652.         if (
  653.             (len = strmatch(p,"BBOOL")) ||
  654.             (len = strmatch(p,"BOOL")) ||
  655.             (len = strmatch(p,"BYTE")) ||
  656.             (len = strmatch(p,"WORD")) ||    //2.99D 970327 for shcfg
  657.             (len = strmatch(p,"SIGNED_WORD")) ||
  658.             (len = strmatch(p,"COLORREF")) ||
  659.             (len = strmatch(p,"SEARCHMODE"))
  660.         ) {
  661.             fout = _num(txdst,szContext,p,len);
  662.         } else if (
  663.             (len = strmatch(p,"mchar")) ||
  664.             (len = strmatch(p,"UCHAR"))
  665.         ) {
  666.             fout = _str(txdst,szContext,p,len);
  667.         }
  668. #if __WZ__ >= 0x2900
  669.         if (len = strmatch(p,"DIRECTORYATR")) {//2.99D 970327 
  670.             int i;
  671.             for (i = 0;i < DIRECTORYATR_N;i++) {
  672.                 txInsertf(txdst,"\tstr(txdst,\"%stDirAtr[%d].szDirectory\",%stDirAtr[%d].szDirectory);\n",
  673.                     szContext,i,
  674.                     szContext,i
  675.                 );
  676.                 txInsertf(txdst,"\tnum(txdst,\"%stDirAtr[%d].kc\",%stDirAtr[%d].kc);\n",
  677.                     szContext,i,
  678.                     szContext,i
  679.                 );
  680.                 txInsertf(txdst,"\tnum(txdst,\"%stDirAtr[%d].cr\",%stDirAtr[%d].cr);\n",
  681.                     szContext,i,
  682.                     szContext,i
  683.                 );
  684.             }
  685.         }
  686. #endif
  687.         if (len = strmatch(p,"FONTSTYLE")) {//2.99D 970328 
  688.             int n;
  689.             if (!stricmp(szContext,"lp->")) {
  690.                 n = FONTTX_H6;
  691.             } else {
  692.                 n = FONTTX_N;
  693.             }
  694.             fontstyle(txdst,szContext,n);
  695.         }
  696.     }
  697. #if 0// for DEBUG
  698.     if (!fout) printf("%s\n",szline);
  699. #endif
  700.     if (!txNextPara(text)) return FALSE;
  701.     return TRUE;
  702. }
  703.  
  704. BOOL TXAPI txcfgWrite(BOOL fStd)
  705. {
  706. // fStd=TRUE:\wzに出力
  707. // fStd=FALSE:pathFullConfigに出力
  708.     TX _textdst;
  709.     TX* text = &_textdst;
  710.     TX* txdst = text;
  711.     txInitText(text);
  712.     txSetFileName(text,text->szexedir + \"std\txcfgc.c");
  713.     txOpenText(text);
  714.     txDeleteText(text);
  715.     txInsert(text,"extern \"txcfgm\" {\n");
  716.     txInsert(text,"\tvoid num(tx* text,mchar *sz,long data);\n");
  717.     txInsert(text,"\tvoid numRGB(tx* text,mchar *sz,long data);\n");
  718.     txInsert(text,"\tvoid str(tx* text,mchar *sz,mchar* szdata);\n");
  719.     txInsert(text,"}\n");
  720.     // config
  721.     txInsert(text,"void txcfg(tx* txdst,tx* text)\n{\n");
  722.     {
  723.         TX* text = textopen(txdst->szexedir + \"std\_text.h");
  724.         if (text) {
  725.             if (txSearchEx(text,"configFileTop",0)) {
  726.                 BOOL fac = FALSE;
  727.                 txstr szline;
  728.                 while(1) {
  729.                     txGetLine(text,szline);
  730.                     if (strmatch(szline,"BYTE configExtEnd;")) break;
  731.                     #if __WZ__ < 0x2900
  732.                         #if __WZ__ >= 0x2002    // WZ2.00B以上
  733.                         if (strmatch(strGetWordTop(szline),"WORD")) {
  734.                             BOOL fSkip = FALSE;
  735.                             if (strstr(szline,"reservedAc")) {
  736.                                 fac = TRUE;
  737.                                 fSkip = TRUE;
  738.                             } else if (fac && strstr(szline,"fAc")) {
  739.                                 fSkip = TRUE;
  740.                             }
  741.                             if (fSkip) {
  742.                                 if (!txNextPara(text)) break;
  743.                                 continue;
  744.                             }
  745.                         }
  746.                         #endif
  747.                     #endif
  748.                     if (!processline(text,txdst,szline,"text->")) break;
  749.                 }
  750.                 fontstyle(txdst,"text->",FONTTX_N);    //2.99D 970328 tFontstyle
  751.             }
  752.             textclose(text);
  753.         }
  754.     }
  755.     txInsert(text,"}\n");
  756.     // LPRINT
  757.     txInsert(text,"void txcfgLprint(TX* txdst,LPRINT* lp)\n{\n");
  758.     {
  759.         TX* text = textopen(txdst->szexedir + \"std\_text.h");
  760.         if (text) {
  761.             if (txSearchEx(text,"} LPRINT;",0)) {
  762.                 if (txSearchEx(text,"configTop",SEARCH_PREV)) {
  763.                     txstr szline;
  764.                     while(1) {
  765.                         txGetLine(text,szline);
  766.                         if (strmatch(szline,"BYTE configEnd;")) break;
  767.                         if (!processline(text,txdst,szline,"lp->")) break;
  768.                     }
  769.                 }
  770.             }
  771.             textclose(text);
  772.         }
  773.     }
  774.     txInsert(text,"}\n");
  775.     // TXCONFIGSHARE
  776.     txInsert(text,"void txcfgShare(TX* txdst,TXCONFIGSHARE* shcfg)\n{\n");
  777.     {
  778.         TX* text = textopen(txdst->szexedir + \"std\_text.h");
  779.         if (text) {
  780.             static mchar szEnd[] = "} TXCONFIGSHARE;";
  781.             if (txSearchEx(text,szEnd,0)) {
  782.                 if (txSearchEx(text,"__BINCOMPATIBLE__",SEARCH_PREV)) {
  783.                     BOOL fev = FALSE;
  784.                     txNextPara(text);
  785.                     txstr szline;
  786.                     while(1) {
  787.                         txGetLine(text,szline);
  788.                         if (strmatch(szline,szEnd)) break;
  789.                         #if __WZ__ >= 0x2005    // WZ2.00E以上
  790.                         if (strmatch(strGetWordTop(szline),"mchar")) {
  791.                             BOOL fSkip = FALSE;
  792.                             if (strstr(szline,"szExtVertical")) {
  793.                                 fev = TRUE;
  794.                                 fSkip = TRUE;
  795.                             } else if (fev && strstr(szline,"szPathTxpcode")) {
  796.                                 fSkip = TRUE;
  797.                             } else if (fev && strstr(szline,"szExtGroup")) {
  798.                                 fSkip = TRUE;
  799.                             }
  800.                             if (fSkip) {
  801.                                 if (!txNextPara(text)) break;
  802.                                 continue;
  803.                             }
  804.                         }
  805.                         #endif
  806.                         if (!processline(text,txdst,szline,"shcfg->")) break;
  807.                     }
  808.                 }
  809.             }
  810.             textclose(text);
  811.         }
  812.     }
  813.     txInsert(text,"}\n");
  814.     //
  815.     txSave(text);
  816.     txClose(text);
  817.     //
  818.     output(fStd);
  819.     return TRUE;
  820. }
  821.  
  822. writeStd
  823. {
  824.     return txcfgWrite(TRUE);
  825. }
  826.  
  827. main
  828. {
  829. // 現在の拡張子毎の設定を、拡張子設定テキストファイル
  830. // "txcfgset.c","txcfgs?.c"
  831. // に出力します。
  832. // "txcfgset.main"コマンドを実行するか、txcfgset.cを開いて[マクロ]-[テキストを実行]
  833. // すると、現在の設定を変更します。
  834. // 拡張子設定テキストファイルを別ファイルにコピーすることによって設定を安全な形で取っておいたり、
  835. // 全ての拡張子で共通にしたい内容を簡単に指定することができます。
  836. // なお、一部設定が出力されない場合があるかもしれません。
  837. // シングル版ではwz:\に、ネットワーク版ではユーザ毎のフォルダに出力されます。
  838.     txcfgWrite(FALSE);
  839. }
  840.  
  841.