×

[PR]この広告は3ヶ月以上更新がないため表示されています。
ホームページを更新後24時間以内に表示されなくなります。

sample.c
 1  #include    <stdio.h>
 2  
 3  #include    "stringid.h"
 4  
 5  
 6  static  void    Test( const char *path )
 7  {
 8      int     ret, id;
 9      SISrc   src;
10      SIStat  st;
11      hSISet  set;
12      hSIDic  dic;
13      const char  *s;
14  
15      ret = SISet_Open( &set );
16      fprintf( stderr, "SISet_Open(): %s\n", SIDic_Error( ret ) );
17  
18      ret = SISet_Load( set, path, "\t\r\n" );
19      fprintf( stderr, "SISet_Load( \"%s\" ): %s\n", path, SIDic_Error( ret ) );
20  
21      ret = SIDic_Build( &dic, set );
22      fprintf( stderr, "SIDic_Build(): %s\n", SIDic_Error( ret ) );
23  
24      ret = SISet_Close( set );
25      fprintf( stderr, "SISet_Close(): %s\n", SIDic_Error( ret ) );
26  
27      ret = SIDic_Status( dic, &st );
28      fprintf( stderr, "SIDic_Status(): %s\n", SIDic_Error( ret ) );
29  
30      fprintf( stderr, "BC: %d\n", st.nbc );
31      fprintf( stderr, "TAIL: %d\n", st.ntail );
32      fprintf( stderr, "SIZE: %d\n", st.size );
33      fprintf( stderr, "KEY: %d\n", st.nkey );
34      fprintf( stderr, "MAX: %d\n", st.maxlen );
35  
36      ret = SIDic_Save( dic, "StrId.dic" );
37      fprintf( stderr, "SIDic_Save( \"%s\" ): %s\n",
38               "StrId.dic", SIDic_Error( ret ) );
39  
40      ret = SIDic_Close( dic );
41      fprintf( stderr, "SIDic_Close(): %s\n", SIDic_Error( ret ) );
42  
43      ret = SIDic_Open( &dic, "StrId.dic" );
44      fprintf( stderr, "SIDic_Open( \"%s\" ): %s\n",
45               "StrId.dic", SIDic_Error( ret ) );
46  
47      s = SIDic_StrToID( dic, "test", &id );
48      fprintf( stderr, "SIDic_StrToID( \"%s\" ): %s: %d\n",
49               "test", ( s != NULL ) ? s : "(null)", id );
50  
51      s = SIDic_IDToStr( dic, id );
52      fprintf( stderr, "SIDic_IDToStr( %d ): %s\n",
53               id, ( s != NULL ) ? s : "(null)" );
54  
55      ret = SISrc_Start( &src, "motor" );
56      fprintf( stderr, "SISrc_Start( \"%s\" ): %s\n",
57               "motor", SIDic_Error( ret ) );
58  
59      while ( ( s = SIDic_Prefix( dic, &src ) ) != NULL )
60          fprintf( stderr, "SIDic_Prefix( \"%s\" ): %s[%d]: %d\n",
61                   src.input, s, src.len, src.id );
62  
63      ret = SISrc_Start( &src, "motor" );
64      fprintf( stderr, "SISrc_Start( \"%s\" ): %s\n",
65               "motor", SIDic_Error( ret ) );
66  
67      while ( ( s = SIDic_Infix( dic, &src ) ) != NULL )
68          fprintf( stderr, "SIDic_Infix( \"%s\" ): %s[%d]: %d\n",
69                   src.input, s, src.len, src.id );
70  
71      ret = SIDic_Close( dic );
72      fprintf( stderr, "SIDic_Close(): %s\n", SIDic_Error( ret ) );
73  }
74  
75  int     main( int argc, char *argv[] )
76  {
77      int     i;
78  
79      for ( i = 1; i < argc; i++ )
80          Test( argv[i] );
81  
82      return  0;
83  }