Esempio n. 1
0
int main(int argc, char *argv[])
{
    option_t *optList=NULL, *thisOpt=NULL;
    bool bSqlite, bParam, bTerm, bExact, bDebug, bVersion, bHelp, bError;
    int countExact = 0;
	bSqlite = false;
	bParam = false;
	bTerm = false;
	bExact = false;
	bDebug = false;
	bVersion = false;
	bHelp = (argc <= 1);
	bError = false;
	tStr sqfn, param = "1", term;

    /* get list of command line options and their arguments */
    optList = GetOptList(argc, argv, (char*)"s:p:t:efdvh");

    /* display results of parsing */
    while (optList != NULL)
    {
        thisOpt = optList;
        optList = optList->next;
		
		switch(thisOpt->option)
		{
			case 'v':
				bVersion = true;
				break;
			case 'h':
				bHelp = true;
				break;
			case 'e':
				bExact = true;
				countExact++;
				bError = bError || (countExact > 1);
				if (countExact > 1) printf("Error: either -e or -f but not both!\n");
				break;
			case 'f':
				bExact = false;
				countExact++;
				bError = bError || (countExact > 1);
				if (countExact > 1) printf("Error: either -e or -f but not both!\n");
				break;
			case 's':
				bSqlite = true;
				process_argwithopt(thisOpt, bError, sqfn, true);
				break;
			case 'p':
				bParam = true;
				param = thisOpt->argument;
				break;
			case 't':
				bTerm = true;
				term = thisOpt->argument;
				break;
			case 'd':
				bDebug = true;
				break;
			default:
				break;
		}
        free(thisOpt);    /* done with this item, free it */
    }
	if (bVersion)
	{
		printlicense();
		return 0;
	}
	if (bHelp || bError)
	{
		printhelp(extract_filename(argv[0]));
		return (bError ? 1 : 0);
	}
	if (!bSqlite)
	{
		printf("Error: -s is required.\n");
		bError = true;
	}
	if (!bTerm)
	{
		printf("Error: -t is required.\n");
		bError = true;
	}
	if (bError)
	{
		printhelp(extract_filename(argv[0]));
		return 1;
	}
	if (bSqlite && bTerm)
	{
		bError = process_query(sqfn, term, param, bExact, bDebug) > 0;
	}
	if (bError)
	{
		printhelp(extract_filename(argv[0]));
	}
	return bError;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	int c;
	bool bSqlite, bParam, bTerm, bExact, bFull, bDebug, bVersion, bHelp, bError;
	int countExact = 0;
	int limitlen = 80;
	bSqlite = false;
	bParam = false;
	bTerm = false;
	bExact = false;
	bFull = false;
	bDebug = false;
	bVersion = false;
	bHelp = (argc <= 1);
	bError = false;
	tStr sqfn, param = "1", term;

    while ((c = getopt2(argc, argv, "s:p:t:l:efudvh")) != -1)
    {
		switch(c)
		{
			case 'v':
				bVersion = true;
				break;
			case 'h':
				bHelp = true;
				break;
			case 'e':
				bExact = true;
				countExact++;
				bError = bError || (countExact > 1);
				if (countExact > 1) printf("Error: either -e or -f but not both!\n");
				break;
			case 'f':
				bExact = false;
				countExact++;
				bError = bError || (countExact > 1);
				if (countExact > 1) printf("Error: either -e or -f but not both!\n");
				break;
			case 's':
				bSqlite = true;
				process_argwithopt(optarg, c, bError, sqfn, true);
				break;
			case 'p':
				bParam = true;
				param = optarg;
				break;
			case 't':
				bTerm = true;
				term = optarg;
				break;
			case 'l':
				limitlen = atoi(optarg);
				break;
			case 'u':
				bFull = true;
				break;
			case 'd':
				bDebug = true;
				break;
			case '?':
				bError = true;
				break;
			default:
				break;
		}
    }
	if (bVersion)
	{
		printlicense();
		return 0;
	}
	if (bHelp || bError)
	{
		printhelp(extract_filename(argv[0]));
		return (bError ? 1 : 0);
	}
	if (!bSqlite)
	{
		printf("Error: -s is required.\n");
		bError = true;
	}
	if (!bTerm)
	{
		printf("Error: -t is required.\n");
		bError = true;
	}
	if (bError)
	{
		printhelp(extract_filename(argv[0]));
		return 1;
	}
	if (bSqlite && bTerm)
	{
		bError = process_query(sqfn, term, param, bExact, bFull, bDebug, limitlen) > 0;
	}
	if (bError)
	{
		printhelp(extract_filename(argv[0]));
	}
	return bError;
}