×

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

sample-cmd.c
 1  #include    <stdio.h>
 2  
 3  #include    "zlibio.h"
 4  #include    "cmdopt.h"
 5  
 6  
 7  int     main( int argc, char *argv[] )
 8  {
 9      int     ret, val, mode = 'c';
10      int     ind, n;
11      CmdOpt  opt;
12      LongOpt     lopts[] = { { "compress", 0, NULL, 'c' },
13                              { "decompress", 0, NULL, 'd' } };
14  
15      CmdOpt_Init( &opt, argc, argv, "cd", lopts );
16      opt.opterr = 1;
17      while ( ( val = CmdOpt_Get( &opt ) ) != -1 )
18          mode = val;
19  
20      ind = opt.optind;
21      n = argc - ( ind = opt.optind );
22      if ( ( mode != 'c' && mode != 'd' ) || n != 2 )
23      {
24          fprintf( stderr, "Usage: %s [cd] input output\n", opt.argv[0] );
25          return  -1;
26      }
27  
28      if ( mode == 'c' )
29      {
30          if ( ( ret = ZIO_Compress( argv[ind], argv[ ind + 1 ] ) ) != ZIO_OK )
31              fprintf( stderr, "zio_compress(): %d\n", ret );
32      }
33      else
34      {
35          if ( ( ret = ZIO_Decompress( argv[ind], argv[ ind + 1 ] ) ) != ZIO_OK )
36              fprintf( stderr, "zio_decompress(): %d\n", ret );
37      }
38  
39      return  ret;
40  }