/*************************************************************
示範電子字典
*************************************************************/
#include <stdio.h>
#include <string.h>
#include "cgic.h"
#define DICTNAME "/usr/share/e-cdict"
cgiMain()
{
  char genbuf[200],inp[50];
  FILE *filept;
  int len;//存輸入之單字長度
  filept=fopen(DICTNAME,"r");
  if (filept==NULL)
  {
	printf("字典檔案開啟錯誤！\n");
	exit(0);
  }
  /**********以下是主要的迴圈**********/
  cgiHeaderContentType("text/html");
        cgiFormStringNoNewlines("WORD", inp, 49);
	len=strlen(inp);
	if (len==0)
	{
		printf("沒有輸入！<br>\n");
	}
	fseek(filept,0,SEEK_SET);
	while (fgets(genbuf,180,filept))
	{
		if (strncasecmp(genbuf,inp,len)==0)
		{
			printf("<hr><br>%s<br>\n",genbuf);
			break;
		}
		else if (strncasecmp(genbuf,inp,len)>0)
		{
			printf("找不到這個字！<br>\n");
			break;
		}
	}
  fclose(filept);
  printf("<hr><br><form method=\"post\" action=\"/cgi-bin/dict.cgi\">");
  printf("輸入英文字：<input type=\"text\" name=\"WORD\" size=10></form>");
}
