Great Circle Associates

XCIN Mail-list
(January 2001)


Indexed By Date: [Previous] [Next] Indexed By Thread: [Previous] [Next]

Subject: Re: program using libtabe
From: Kuang-che Wu <kcwu@ck.tp.edu.tw>
Date: Sun, 7 Jan 2001 23:47:44 +0800
To: xcin@linux.org.tw
Delivered-To: xcin-gate@tlug.sinica.edu.tw
Delivered-To: xcin-list@tlug.sinica.edu.tw
Reply-To: xcin@tlug.sinica.edu.tw
User-Agent: Mutt/1.2.4i

On Sat, Jan 06, 2001 at 10:26:30PM +0800, Kuang-che Wu wrote:
> On Fri, Jan 05, 2001 at 09:29:53PM +0800, Kuang-che Wu wrote:
> > §Ú¼g¤F¤@­Ó¤pµ{¦¡, ¨Ï¥Î libtabe,
> > µ{¦¡ output ¤F©_©ÇªºªF¦è,
> §Ñ¤F»¡©ú, §Úªºµ{¦¡«Ü²³æ, ¥u¬O¥é·Ó tsidump
> ¥´ºâ¼g¤@­Ó yindump ¦Ó¤w
³Ì«áÁ`µ², ¦³¤T­Ó bug
1.§Ú¦Û¤vµ{¦¡ªº bug ^^; ¯u¤£¦n·N«ä
2.libtabeªº bug, ´N¬O§Ú¤W¦¸ patch ªº´X¦æ, ½Ð©~¤hÀ°¦£¬Ý¤@¤U§a
2.tsi.src ªº bug, £­......
tsi.src³o´X¦æÄê±¼¤F
¤@Án¤£ÅT 17     [£¸,£¸4]£ £¦£¶ £t£¹4 £££¸£µ3
¤@Án¥O¤U 43     [£¸,£¸4]£ £¦£¶ £{£¸£¶4 £££¸£«4
¥_ÃQ 24 £       t£°3 £¹£°4
·¸¦ì 0          ¤@4 £¹£°4
·s»D¸s²Õ 0      ££¤@£´ £¹£´2 £¢£º£´2 £¨£¹3
ÁôÂÃÀÉ 0        ¤@£´3 £©£µ2 £x£µ3
§¨ÀÉ 0          £¡¤@£«2 £x£µ3
¥_¾î 72         £t£°2 £~£¶2
¥_¾î¤½¸ô 22     £t£°2 £~£¶2 £|£¹£¶ £{£¹4
«e¨â¦æ¬O¥þ§ÎªÅ¥Õ, ÁÙ¦³³\¦h '£¸'¼g¦¨'¤@'
ÁÙ¦³£t£°£½ libtabe ¤£Ä±±o¬O¥¿½Tª`­µ

¥H¤Uªþ¤W yindump.c :)
¥i¥H¥Î¨ÓÀˬd¦P¤@µü­µ, «Ü¦hµüªº±¡ªp
¥i¯à¬O¿ù¦r.....

#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#include <db.h>
#include <tabe.h>

void
usage(void)
{
  printf("Usage: tsidump -y <TsiYinDB> [-f output file]\n");
  printf("   -y <TsiYinDB>  \t path to TsiYinDB\n");
  printf("   -f <output file>\t output file in plain text (default: stdout)\n");
  exit(0);
}

void
dump(struct TsiYinDB *db, FILE *fp)
{
  struct TsiYinInfo *tsiyin;
  int rval, i, j;
  char *p;

  rval = db->RecordNumber(db);
  if (rval < 0) {
    fprintf(stderr, "yindump: wrong DB format.\n");
    usage();
  }

  tsiyin = (struct TsiYinInfo *)malloc(sizeof(struct TsiYinInfo));
  memset(tsiyin, 0, sizeof(struct TsiYinInfo));

  for(db->CursorSet(db,tsiyin);db->CursorNext(db,tsiyin)>=0;) {
    ZuYinSymbolSequence seq;
    fprintf(fp,"%lu ",tsiyin->yinlen);
    for(i=0;i<tsiyin->yinlen;i++) {
      seq=tabeYinToZuYinSymbolSequence(tsiyin->yin[i]);
      if(*seq)
        fprintf(fp, "%s ", (char*)seq);
      else
        fprintf(fp, "(%d) ",tsiyin->yin[i]);
    }
    fprintf(fp,"%lu",tsiyin->tsinum);
    for(i=0;i<tsiyin->tsinum;i++) {
      fprintf(fp," ");
      p=(char*)tsiyin->tsidata+tsiyin->yinlen*i*2;
      for(j=0;j<tsiyin->yinlen;j++)
        fprintf(fp,"%c%c",p[j*2],p[j*2+1]);
    }
    fprintf(fp,"\n");
    memset(tsiyin, 0, sizeof(struct TsiYinInfo));
  }

  db->Close(db);
}

int
main(int argc, char **argv)
{
  int ch;
  int ref, tsiyin;
  FILE *fp;
  struct TsiYinDB *db;
extern char *optarg;
extern int optind, opterr, optopt;

  char *db_name, *op_name;

  db_name = op_name = (char *)NULL;
  ref = 0;
  tsiyin = 0;

  while ((ch = getopt(argc, argv, "y:f:")) != -1) {
    switch(ch) {
      case 'y':
        db_name = (char *)strdup(optarg);
        break;
      case 'f':
        op_name = (char *)strdup(optarg);
        break;
      default:
        usage();
        break;
    }
  }
  argc -= optind;
  argv += optind;

  if (!db_name) {
    usage();
  }

  db = tabeTsiYinDBOpen(DB_TYPE_DB, db_name, 0);
  if (!db) {
    usage();
  }

  if (op_name) {
    fp = fopen(op_name, "w");
    dump(db, fp);
    fclose(fp);
  }
  else {
    dump(db, stdout);
  }

  return(0);
}

To Unsubscribe: send mail to majordomo@linux.org.tw
with "unsubscribe xcin" in the body of the message



References:
Indexed By Date Previous: Re: tsi.src change of this week (2)
From: Edward Lee <edward.@kimo.com>
Next: Re: tsi.src change of this week
From: Kuang-che Wu <kcwu@ck.tp.edu.tw>
Indexed By Thread Previous: Re: program using libtabe
From: Kuang-che Wu <kcwu@ck.tp.edu.tw>
Next: Re: program using libtabe
From: thhsieh@tlug.sinica.edu.tw