home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MODEL / DLOGLIB.C < prev    next >
C/C++ Source or Header  |  1996-03-11  |  9KB  |  320 lines

  1. /*
  2.  *    ダイヤログボックス制御
  3.  *
  4.  *        Copyright    T.Kobayashi        1994.7.24
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <assert.h>
  11.  
  12. #include "ml.h"
  13. #include "strclass.h"
  14.  
  15. #include "dlog.h"
  16.  
  17. static    int        FuncDlogOpen( int, int, DataStruct* );
  18. static    int        FuncDlogMessage( int, int, DataStruct* );
  19. static    int        FuncDlogString( int, int, DataStruct* );
  20. static    int        FuncDlogToggle( int, int, DataStruct* );
  21. static    int        FuncDlogSelect( int, int, DataStruct* );
  22. static    int        FuncDlogSlider( int, int, DataStruct* );
  23. static    int        FuncDlogWait( int, int, DataStruct* );
  24. static    int        FuncDlogAnswer( int, int, DataStruct* );
  25. static    int        FuncDlogFileOpen( int, int, DataStruct* );
  26.  
  27. static    int        StringClassID ;
  28.  
  29. void    DlogLibInit()
  30. {
  31.     StringClassID = ClassName( "String" );
  32.     NewFunction( StringClassID, "DlogOpen", FuncDlogOpen );
  33.     NewFunction( 0,                "DlogMessage", FuncDlogMessage );
  34.     NewFunction( 0,                "DlogString", FuncDlogString );
  35.     NewFunction( 0,                "DlogToggle", FuncDlogToggle );
  36.     NewFunction( 0,                "DlogSelect", FuncDlogSelect );
  37.     NewFunction( 0,                "DlogSlider", FuncDlogSlider );
  38.     NewFunction( 0,                "DlogWait", FuncDlogWait );
  39.     NewFunction( 0,                "DlogAnswer", FuncDlogAnswer );
  40.     NewFunction( StringClassID,    "DlogFileOpen", FuncDlogFileOpen );
  41. }
  42.  
  43. static    int        FuncDlogOpen( ident, args, buf )
  44. int        ident ;
  45. int        args ;
  46. DataStruct    *buf ;
  47. {
  48.     static char *button_okcan[3] = {"中止", "決定", NULL};
  49.     static char *button_ok[2] = {"確認", NULL};
  50.     if ( args <= 2 ) {
  51.         ArgCheck( "DlogOpen", args, buf, TYPE_OBJECT, TYPE_INT, TYPE_NOASN );
  52.         DlogOpen( ((StringClass*)buf[0].od.ptr)->str, buf[1].id.i, button_okcan );
  53.     } else if (ObjectCheck(&buf[2], StringClassID) == FALSE) {
  54.         ArgCheck( "DlogOpen", args, buf, TYPE_OBJECT, TYPE_INT,
  55.                         TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
  56.         if (buf[2].id.i) {
  57.             DlogOpen( ((StringClass*)buf[0].od.ptr)->str, buf[1].id.i, button_okcan );
  58.         } else {
  59.             DlogOpen( ((StringClass*)buf[0].od.ptr)->str, buf[1].id.i, button_ok );
  60.         }
  61.     } else {
  62.         char *button[DLOG_MAX_BUTTON];
  63.         int i;
  64.         if (ObjectCheck(&buf[0], StringClassID) == FALSE || buf[1].type != TYPE_INT) {
  65.             ExecError("DlogOpen: 引数の型が異なります。");
  66.         }
  67.         for (i = 0; i+2 < args && i < DLOG_MAX_BUTTON-1; i++) {
  68.             if (ObjectCheck(&buf[i+2], StringClassID) == FALSE) {
  69.                 ExecError("DlogOpen: 引数の型が異なります。");
  70.             }
  71.             button[i] = ((StringClass*)buf[i+2].od.ptr)->str;
  72.         }
  73.         button[i] = NULL;
  74.         DlogOpen( ((StringClass*)buf[0].od.ptr)->str, buf[1].id.i, button );
  75.     }
  76.     return RETURN_VOID ;
  77. }
  78.  
  79. static    int        FuncDlogMessage( ident, args, buf )
  80. int        ident ;
  81. int        args ;
  82. DataStruct    *buf ;
  83. {
  84.     ArgCheck( "DlogMessage", args, buf, TYPE_INT, TYPE_OBJECT, TYPE_NOASN );
  85.     DlogMessage( buf[0].id.i, ((StringClass*)buf[1].od.ptr)->str );
  86.     return RETURN_VOID ;
  87. }
  88.  
  89. static    int        FuncDlogString( ident, args, buf )
  90. int        ident ;
  91. int        args ;
  92. DataStruct    *buf ;
  93. {
  94.     int i, j;
  95.     char *p, wild[256];
  96.     if (args <= 4) {
  97.         ArgCheck( "DlogString", args, buf,
  98.             TYPE_INT, TYPE_OBJECT, TYPE_OBJECT, TYPE_INT, TYPE_NOASN );
  99.         if (ObjectCheck(&buf[1], StringClassID) == FALSE
  100.          || ObjectCheck(&buf[2], StringClassID) == FALSE) {
  101.             ExecError("DlogString: 引数の型が異なります。");
  102.         }
  103.         wild[0] = '\0';
  104.     } else {
  105. /*
  106.         ArgCheck( "DlogString", args, buf,
  107.             TYPE_INT, TYPE_OBJECT, TYPE_OBJECT, TYPE_INT, TYPE_OBJECT, TYPE_NOASN );
  108. */
  109.         if (buf[0].type != TYPE_INT || buf[3].type != TYPE_INT
  110.          || ObjectCheck(&buf[1], StringClassID) == FALSE
  111.          || ObjectCheck(&buf[2], StringClassID) == FALSE
  112.          || ObjectCheck(&buf[4], StringClassID) == FALSE) {
  113.             ExecError("DlogString: 引数の型が異なります。");
  114.         }
  115.         p = ((StringClass*)buf[4].od.ptr)->str;
  116.         j = strlen(p);
  117.         if (j > 7 && p[j-7] == '(' && p[j-6] == '*' && p[j-5] == '.' && p[j-1] == ')') {
  118.             wild[0] = p[j-4];
  119.             wild[1] = p[j-3];
  120.             wild[2] = p[j-2];
  121.             wild[3] = ' ';
  122.             strcpy(wild+4, p);
  123.             strcat(wild, "|");
  124.             strcat(wild, p+j-6);
  125.             wild[strlen(wild)-1] = '|';
  126.         }
  127.         for (i = 5; i < args; ++i) {
  128.             if (ObjectCheck(&buf[i], StringClassID) == FALSE) {
  129.                 ExecError("DlogString: 引数の型が異なります。");
  130.             }
  131.             p = ((StringClass*)buf[i].od.ptr)->str;
  132.             j = strlen(p);
  133.             if (j > 7 && p[j-7] == '(' && p[j-6] == '*' && p[j-5] == '.' && p[j-1] == ')') {
  134.                 strcat(wild, p);
  135.                 strcat(wild, "|");
  136.                 strcat(wild, p+j-6);
  137.                 wild[strlen(wild)-1] = '|';
  138.             }
  139.         }
  140.     }
  141.     DlogString( buf[0].id.i,
  142.                 ((StringClass*)buf[1].od.ptr)->str,
  143.                 ((StringClass*)buf[2].od.ptr)->str,
  144.                 buf[3].id.i, wild );
  145.     return RETURN_VOID ;
  146. }
  147.  
  148. static    int        FuncDlogToggle( ident, args, buf )
  149. int        ident ;
  150. int        args ;
  151. DataStruct    *buf ;
  152. {
  153.     ArgCheck( "DlogToggle", args, buf,
  154.         TYPE_INT, TYPE_OBJECT, TYPE_OBJECT, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
  155.     DlogToggle( buf[0].id.i,
  156.                 ((StringClass*)buf[1].od.ptr)->str,
  157.                 ((StringClass*)buf[2].od.ptr)->str,
  158.                 buf[3].id.i );
  159.     return RETURN_VOID ;
  160. }
  161.  
  162. static    int        FuncDlogSelect( ident, args, buf )
  163. int        ident ;
  164. int        args ;
  165. DataStruct    *buf ;
  166. {
  167.     int            i, field, size, stat ;
  168.     char        *str, *item[40] ;
  169.     DataStruct    *ary ;
  170.  
  171.     ArgCheck( "DlogSelect", args, buf,
  172.         TYPE_INT, TYPE_OBJECT, TYPE_ARRAY, TYPE_INT, TYPE_NOASN );
  173.  
  174.     field = buf[0].id.i ;
  175.     str = ((StringClass*)buf[1].od.ptr)->str ;
  176.     ary = buf[2].ad.ary ;
  177.     size = buf[2].ad.size ;
  178.     stat = buf[3].id.i ;
  179.  
  180.     for( i = 0 ; i < size ; i++ )
  181.     {
  182.         if ( ary[i].type != TYPE_OBJECT )
  183.             ExecError( "引数配列の型が不正です(DlogSelect)" );
  184.         item[i] = ((StringClass*)ary[i].od.ptr)->str ;
  185.         if ( strcmp( item[i], "" ) == 0 )
  186.             break ;
  187.     }
  188.     item[i] = NULL ;
  189.     DlogSelect( field, str, item, stat );
  190.     return RETURN_VOID ;
  191. }
  192.  
  193. static    int        FuncDlogSlider( ident, args, buf )
  194. int        ident ;
  195. int        args ;
  196. DataStruct    *buf ;
  197. {
  198.     if (args == 5) {
  199.         ArgCheck( "DlogSlider", args, buf,
  200.             TYPE_INT, TYPE_OBJECT, TYPE_INT, TYPE_INT, TYPE_FUNC, TYPE_NOASN );
  201.         if (ObjectCheck(&buf[1], StringClassID) == FALSE) {
  202.             ExecError("2番目の引数の型が違います。(DlogSlider)");
  203.         }
  204.         DlogSlider( buf[0].id.i,
  205.                     ((StringClass*)buf[1].od.ptr)->str,
  206.                     buf[2].id.i, buf[2].id.i, buf[3].id.i, buf[4].funcd.ident );
  207.     } else {
  208.         ArgCheck( "DlogSlider", args, buf,
  209.             TYPE_INT, TYPE_OBJECT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_FUNC, TYPE_NOASN );
  210.         if (ObjectCheck(&buf[1], StringClassID) == FALSE) {
  211.             ExecError("2番目の引数の型が違います。(DlogSlider)");
  212.         }
  213.         DlogSlider( buf[0].id.i,
  214.                     ((StringClass*)buf[1].od.ptr)->str,
  215.                     buf[2].id.i, buf[3].id.i, buf[4].id.i, buf[5].funcd.ident );
  216.     }
  217.     return RETURN_VOID ;
  218. }
  219.  
  220. static    int        FuncDlogWait( ident, args, buf )
  221. int        ident ;
  222. int        args ;
  223. DataStruct    *buf ;
  224. {
  225.     StackPushInt( DlogWait() );
  226.     return RETURN_RETURN ;
  227. }
  228.  
  229. static    int        FuncDlogAnswer( ident, args, buf )
  230. int        ident ;
  231. int        args ;
  232. DataStruct    *buf ;
  233. {
  234.     int        n, type ;
  235.     char    str[1024] ;
  236.  
  237.     ArgCheck( "DlogAnswer", args, buf, TYPE_INT, TYPE_NOASN );
  238.  
  239.     type = DlogAnswer( buf[0].id.i, str, &n );
  240.     switch( type )
  241.     {
  242.         case DLOG_STRING:
  243.             buf = StackAlloc( 1 );
  244.             StringToObject( buf, str );
  245.             break ;
  246.         case DLOG_TOGGLE:
  247.             StackPushBoolean( n );
  248.             break ;
  249.             break ;
  250.         case DLOG_SELECT:
  251.             StackPushInt( n );
  252.             break ;
  253.         case DLOG_SLIDER:
  254.             StackPushInt( n );
  255.             break ;
  256.         default:
  257.             assert( FALSE );
  258.     }
  259.     return RETURN_RETURN ;
  260. }
  261.  
  262.  
  263. static    int        FuncDlogFileOpen( ident, args, buf )
  264. int        ident ;
  265. int        args ;
  266. DataStruct    *buf ;
  267. {
  268. #ifdef WINDOWS
  269.     int i, j;
  270.     char *title, *def;
  271.     char *p, ext[4], wild[256], filename[512];
  272.     if (ObjectCheck(&buf[0], StringClassID) == FALSE
  273.      || ObjectCheck(&buf[1], StringClassID) == FALSE
  274.      || ObjectCheck(&buf[2], StringClassID) == FALSE) {
  275.         ExecError("DlogString: 引数の型が異なります。");
  276.     }
  277.     title = ((StringClass*)buf[0].od.ptr)->str;
  278.     def = ((StringClass*)buf[1].od.ptr)->str;
  279.     p = ((StringClass*)buf[2].od.ptr)->str;
  280.     j = strlen(p);
  281.     if (j > 7 && p[j-7] == '(' && p[j-6] == '*' && p[j-5] == '.' && p[j-1] == ')') {
  282.         ext[0] = p[j-4];
  283.         ext[1] = p[j-3];
  284.         ext[2] = p[j-2];
  285.         ext[3] = '\0';
  286.         strcpy(wild, p);
  287.         strcat(wild, "|");
  288.         strcat(wild, p+j-6);
  289.         wild[strlen(wild)-1] = '|';
  290.     } else {
  291.         ext[0] = '\0';
  292.         wild[0] = '\0';
  293.     }
  294.     for (i = 3; i < args; ++i) {
  295.         if (ObjectCheck(&buf[i], StringClassID) == FALSE) {
  296.             ExecError("DlogString: 引数の型が異なります。");
  297.         }
  298.         p = ((StringClass*)buf[i].od.ptr)->str;
  299.         j = strlen(p);
  300.         if (j > 7 && p[j-7] == '(' && p[j-6] == '*' && p[j-5] == '.' && p[j-1] == ')') {
  301.             strcat(wild, p);
  302.             strcat(wild, "|");
  303.             strcat(wild, p+j-6);
  304.             wild[strlen(wild)-1] = '|';
  305.         }
  306.     }
  307.     if (DlogFileOpen(filename, 512, title, def, ext, wild) == FALSE) {
  308.         filename[0] = '\0';
  309.     }
  310.     buf = StackAlloc( 1 );
  311.     StringToObject( buf, filename );
  312.     return RETURN_RETURN ;
  313. #else
  314.     ExecError("DlogFileOpenは使えません");
  315.     return RETURN_VOID;
  316. #endif
  317. }
  318.  
  319.  
  320.