コード例 #1
0
/****************************************************************************
*   Function   : main
*   Description: This is the main function for this program, it validates
*                the command line input and, if valid, it will either
*                encode a file using the LZSS algorithm or decode a
*                file encoded with the LZSS algorithm.
*   Parameters : argc - number of parameters
*                argv - parameter list
*   Effects    : Encodes/Decodes input file
*   Returned   : EXIT_SUCCESS for success, otherwise EXIT_FAILURE.
****************************************************************************/
int main(int argc, char *argv[])
{
    option_t *optList, *thisOpt;
    FILE *fpIn, *fpOut;      /* pointer to open input & output files */
    MODES mode;

    char input[] = "Chan";
    int input_len = strlen(input);
    char *output = (char *)malloc(sizeof(char) * (input_len + 1));

    /* initialize data */
    fpIn = NULL;
    fpOut = NULL;
    mode = ENCODE;

    /* parse command line */
    optList = GetOptList(argc, argv, "c:h?");
    thisOpt = optList;

    while (thisOpt != NULL)
    {
        switch(thisOpt->option)
        {
            case 'c':       /* compression mode */
                mode = ENCODE;
                break;

            case 'h':
            case '?':
                printf("options:\n");
                printf("  -c : Encode input file to output file.\n");
                printf("  -d : Decode input file to output file.\n");
                printf("  -i <filename> : Name of input file.\n");
                printf("  -o <filename> : Name of output file.\n");
                printf("  -h | ?  : Print out command line options.\n\n");
                FreeOptList(optList);
                return(EXIT_SUCCESS);
        }

        optList = thisOpt->next;
        free(thisOpt);
        thisOpt = optList;
    }



    /* we have valid parameters encode or decode */
    if (mode == ENCODE)
    {
        printf("Before encoding\n");
        EncodeLZSSByArray(input, output);
    }

    return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: main_cli.cpp プロジェクト: hxvu/xstatic
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;
}
コード例 #3
0
ファイル: lzssmain.c プロジェクト: 8l/CompCert
/****************************************************************************
*   Function   : main
*   Description: This is the main function for this program, it validates
*                the command line input and, if valid, it will either
*                encode a file using the LZSS algorithm or decode a
*                file encoded with the LZSS algorithm.
*   Parameters : argc - number of parameters
*                argv - parameter list
*   Effects    : Encodes/Decodes input file
*   Returned   : EXIT_SUCCESS for success, otherwise EXIT_FAILURE.
****************************************************************************/
int main(int argc, char *argv[])
{
    option_t *optList, *thisOpt;
    FILE *fpIn, *fpOut;      /* pointer to open input & output files */
    MODES mode;

    /* initialize data */
    fpIn = NULL;
    fpOut = NULL;
    mode = ENCODE;

    /* parse command line */
    optList = GetOptList(argc, argv, "cdi:o:h?");
    thisOpt = optList;

    while (thisOpt != NULL)
    {
        switch(thisOpt->option)
        {
            case 'c':       /* compression mode */
                mode = ENCODE;
                break;

            case 'd':       /* decompression mode */
                mode = DECODE;
                break;

            case 'i':       /* input file name */
                if (fpIn != NULL)
                {
                    fprintf(stderr, "Multiple input files not allowed.\n");
                    fclose(fpIn);

                    if (fpOut != NULL)
                    {
                        fclose(fpOut);
                    }

                    FreeOptList(optList);
                    exit(EXIT_FAILURE);
                }

                /* open input file as binary */
                fpIn = fopen(thisOpt->argument, "rb");
                if (fpIn == NULL)
                {
                    perror("Opening input file");

                    if (fpOut != NULL)
                    {
                        fclose(fpOut);
                    }

                    FreeOptList(optList);
                    exit(EXIT_FAILURE);
                }
                break;

            case 'o':       /* output file name */
                if (fpOut != NULL)
                {
                    fprintf(stderr, "Multiple output files not allowed.\n");
                    fclose(fpOut);

                    if (fpIn != NULL)
                    {
                        fclose(fpIn);
                    }

                    FreeOptList(optList);
                    exit(EXIT_FAILURE);
                }

                /* open output file as binary */
                fpOut = fopen(thisOpt->argument, "wb");
                if (fpOut == NULL)
                {
                    perror("Opening output file");

                    if (fpIn != NULL)
                    {
                        fclose(fpIn);
                    }

                    FreeOptList(optList);
                    exit(EXIT_FAILURE);
                }
                break;

            case 'h':
            case '?':
                printf("Usage: %s <options>\n\n", RemovePath(argv[0]));
                printf("options:\n");
                printf("  -c : Encode input file to output file.\n");
                printf("  -d : Decode input file to output file.\n");
                printf("  -i <filename> : Name of input file.\n");
                printf("  -o <filename> : Name of output file.\n");
                printf("  -h | ?  : Print out command line options.\n\n");
                printf("Default: %s -c -i stdin -o stdout\n",
                    RemovePath(argv[0]));

                FreeOptList(optList);
                return(EXIT_SUCCESS);
        }

        optList = thisOpt->next;
        free(thisOpt);
        thisOpt = optList;
    }


    /* use stdin/out if no files are provided */
    if (fpIn == NULL)
    {
        fpIn = stdin;
    }


    if (fpOut == NULL)
    {
        fpOut = stdout;
    }

    /* we have valid parameters encode or decode */
    if (mode == ENCODE)
    {
        EncodeLZSSByFile(fpIn, fpOut);
    }
    else
    {
        DecodeLZSSByFile(fpIn, fpOut);
    }

    /* remember to close files */
    fclose(fpIn);
    fclose(fpOut);
    return EXIT_SUCCESS;
}
コード例 #4
0
void lt_hack_handle_opts (int argc, char **argv)
{
	setDefaults (PRESET_COMPUTER);

	option_t *optList, *thisOpt;
	optList = NULL;
	optList = GetOptList(argc, argv, "hp:l:L:t:d:D:o:P:e:T:sSfF");

	int change_flag = 0;

	while (optList != NULL) {
		thisOpt = optList;
		optList = optList->next;

		int c;
		c= (int) thisOpt->option;

		if (c == NULL)
			break;

		switch (c) {
		DRIVER_OPTIONS_CASES case 'h':
			printf ("%s:"
#ifndef HAVE_GETOPT_H
				" Not built with GNU getopt.h, long options *NOT* enabled."
#endif
				"\n" DRIVER_OPTIONS_HELP 
				"\t--preset/-p <arg>\n" "\t--regular\n" "\t--chainmail\n" "\t--brassmesh\n" "\t--computer\n" "\t--slick\n" "\t--tasty\n"
				"\t--longitude/-l <arg>\n" "\t--latitude/-L <arg>\n" 
				"\t--thick/-t <arg>\n" "\t--density/-d <arg>\n" 
				"\t--drawdepth/-D <arg>\n" "\t--fov/-o <arg>\n" 
				"\t--pathrand/-P <arg>\n" "\t--speed/-e <arg>\n" 
				"\t--texture/-T <arg>\n" "\t--industrial\n" "\t--crystal\n" "\t--chrome\n" "\t--brass\n" "\t--shiny\n" "\t--ghostly\n" "\t--circuits\n" "\t--doughnuts\n"
				"\t--smooth/-s\n" "\t--no-smooth/-S\n" 
				"\t--fog/-f\n" " \t--no-fog/-F\n", argv[0]);
			exit (1);
		case 'p':
			change_flag = 1;
			setDefaults (strtol_minmaxdef (thisOpt->argument, 10, 1, 6, 0, 1, "--preset: "));
			break;
		case 10:
		case 11:
		case 12:
		case 13:
		case 14:
		case 15:
			change_flag = 1;
			setDefaults (c - 9);
			break;
		case 'l':
			change_flag = 1;
			dLongitude = strtol_minmaxdef (optarg, 10, 4, 100, 1, 16, "--longitude: ");
			break;
		case 'L':
			change_flag = 1;
			dLatitude = strtol_minmaxdef (optarg, 10, 2, 100, 1, 8, "--latitude: ");
			break;
		case 't':
			change_flag = 1;
			dThick = strtol_minmaxdef (optarg, 10, 1, 100, 1, 50, "--thick: ");
			break;
		case 'd':
			change_flag = 1;
			dDensity = strtol_minmaxdef (optarg, 10, 1, 100, 1, 50, "--density: ");
			break;
		case 'D':
			change_flag = 1;
			dDrawdepth = strtol_minmaxdef (thisOpt->argument, 10, 1, 8, 1, 4, "--drawdepth: ");
			break;
		case 'o':
			change_flag = 1;
			dFov = strtol_minmaxdef (optarg, 10, 10, 150, 1, 90, "--fov: ");
			break;
		case 'P':
			change_flag = 1;
			dPathrand = strtol_minmaxdef (optarg, 10, 1, 10, 1, 1, "--pathrand: ");
			break;
		case 'e':
			change_flag = 1;
			dSpeed = strtol_minmaxdef (thisOpt->argument, 10, 1, 100, 1, 1, "--speed: ");
			break;
		case 'T':
			change_flag = 1;
			dTexture = strtol_minmaxdef (optarg, 10, 0, 9, 0, 0, "--texture: ");
			break;
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
		case 8:
			change_flag = 1;
			dTexture = c;
			break;
		case 's':
			change_flag = 1;
			dSmooth = 1;
			break;
		case 'S':
			change_flag = 1;
			dSmooth = 0;
			break;
		case 'f':
			change_flag = 1;
			dFog = 1;
			break;
		case 'F':
			change_flag = 1;
			dFog = 0;
			break;
		}
	}

}
コード例 #5
0
ファイル: dbctl.c プロジェクト: mbereznyak/mysql-governor
int GetCmd( int argc, char **argv )
{
  int *ret = (int*)malloc( sizeof( int ) ); 
  *ret = 0;
  
  char _tmp_arg[ 11 ]; _tmp_arg[ 0 ] = '\0';
  strlcpy( _tmp_arg, argv[ 1 ], sizeof( _tmp_arg ) );

  if( !valid_comm( argc, argv ) ) return 1;

  if( strcmp( "set", argv[ 1 ] ) == 0 )
  {
    if( argc > 2  )
    {
      char *_argv = argv[ 2 ];
      GList *list = (GList *)GetOptList( argc, argv, ret );
      
      if( strcmp( "default", _argv ) == 0 )
        setDefault( (char*)GetVal( 'c', list ), (char*)GetVal( 'r', list ), (char*)GetVal( 'w', list ), (char*)GetVal( 's', list ) );
      else
        setUser( _argv, (char*)GetVal( 'c', list ), (char*)GetVal( 'r', list ), (char*)GetVal( 'w', list ), (char*)GetVal( 's', list ) );
    }
    else
      return 1;
  }
  else if( strcmp( "ignore", argv[ 1 ] ) == 0 )
  {
    if( argc > 2  )
    {
      ignoreUser( argv[ 2 ] );
    }
    else
      return 1;
  }
  else if( strcmp( "monitor", argv[ 1 ] ) == 0 )
  {
    if( argc > 2  )
    {
      watchUser( argv[ 2 ] );
    }
    else
      return 1;
  }
  else if( strcmp( "delete", argv[ 1 ] ) == 0 )
  {
    if( argc > 2  )
    {
      deleteUser( argv[ 2 ] );
    }
    else
      return 1;
  }
  else if( strcmp( "list", argv[ 1 ] ) == 0 )
  {
    list();
  }
  else if( strcmp( "list-restricted", argv[ 1 ] ) == 0 )
  {
    list_restricted();
  }
  else if( strcmp( "restrict", argv[ 1 ] ) == 0 )
  {
    if( argc > 2  )
    {
      char *_argv = argv[ 2 ];
      GList *list = (GList *)GetOptList( argc, argv, ret );
  
      restrict_user( _argv, (char*)GetVal( 'l', list ) );
    }
    else
      return 1;
  }
  else if( strcmp( "unrestrict", argv[ 1 ] ) == 0 )
  {
    if( argc > 2  )
    {
      unrestrict( argv[ 2 ] );
    }
    else
      return 1;
  }
  else if( strcmp( "unrestrict-all", argv[ 1 ] ) == 0 )
  {
    unrestrict_all();
  }
  else if( strcmp( "--lve-mode", _tmp_arg ) == 0 )
  {
    char *_argv = argv[ 2 ];
    GList *list = (GList *)GetOptList( argc, argv, ret );
    setLveMode( (char*)GetVal( 100, list ) );
  }
  else
  {
    GetOptList( argc, argv, ret );

    int _ret = *ret; free( ret );
    return _ret;
  }
  
  free( ret );  
  return 0;
}