コード例 #1
0
ファイル: nrutil.c プロジェクト: BallaMatt03/dev
/* ------------------------------------------------------------------------------- */
void MLoadPGM_ui8matrix(char *filename, int nrl, int nrh, int ncl, int nch, uint8 **m)
/* ------------------------------------------------------------------------------- */
{
    /* cette version ne lit plus que le type P5 */
    
    int height, width, gris;
    FILE *file;
    
    char *buffer;
    int i;
    
    buffer = (char*) calloc(80, sizeof(char));
    /* ouverture du fichier */
    file = fopen(filename,"rb");
    if (file==NULL)
        nrerror("ouverture du fichier impossible\n");
    //nrerror("ouverture du fichier %s impossible\n", filename);
    
    /* lecture de l'entete du fichier pgm */
    readitem(file, buffer);
    /*fscanf(fichier, "%s", buffer);*/
    if(strcmp(buffer, "P5") != 0)
        nrerror("entete du fichier %s invalide\n");
    //nrerror("entete du fichier %s invalide\n", filename);
    
    width  = atoi(readitem(file, buffer));
    height = atoi(readitem(file, buffer));
    gris   = atoi(readitem(file, buffer));
    
    for(i=0; i<height; i++) {
        ReadPGMrow(file, width, m[i]);
    }
    
    fclose(file);
    free(buffer);
}
コード例 #2
0
ファイル: plcfwd.c プロジェクト: LucaBongiorni/open-plc-utils
static unsigned readlist (struct item list [], unsigned size)

{
	struct item * item = list;
	char string [1024];
	char * sp = string;
	signed c;
	for (c = getc (stdin); c != EOF; c = getc (stdin))
	{
		if (isspace (c))
		{
			continue;
		}
		if (c == '#')
		{
			while ((c != '\n') && (c != EOF))
			{
				c = getc (stdin);
			}
			continue;
		}
		sp = string;
		while ((c != ';') && (c != '\n') && (c != EOF))
		{
			*sp++ = (char)(c);
			c = getc (stdin);
		}
		*sp = (char)(0);
		if (size)
		{
			readitem (item++, string);
			size--;
		}
	}
	return ((unsigned)(item - list));
}
コード例 #3
0
ファイル: sceplist.c プロジェクト: xman1979/openscep
int	main(int argc, char *argv[]) {
	int		c;
	scep_t		scep;	/* mainly used to hold configuration	*/
	char		*notbefore = NULL, *notafter = NULL;
	char		workdir[1024];
	int		items = 0;
	scepitem_t	**itemlist = NULL;
	scepitem_t	**ip;
	DIR		*dir;
	struct dirent	*d;

	/* parse command line						*/
	while (EOF != (c = getopt(argc, argv, "abcdghnprstvx")))
		switch (c) {
		case 'a':
			sortorder = SORT_NOTAFTER;
			compare = cmp_string;
			break;
		case 'b':
			sortorder = SORT_NOTBEFORE;
			compare = cmp_string;
			break;
		case 'c':
			ctimeformat = 1;
			break;
		case 'd':
			debug++;
			break;
		case 'g':
			itemselect = SELECT_GRANTED;
			break;
		case 'h':
			html = 1;
			break;
		case 'n':
			sortorder = SORT_NAME;
			compare = cmp_string;
			break;
		case 'p':
			itemselect = SELECT_PENDING;
			break;
		case 'r':
			itemselect = SELECT_REJECTED;
			break;
		case 's':
			sortorder = SORT_SERIAL;
			compare = cmp_asn1_integer;
			break;
		case 't':
			sortorder = SORT_TRANSID;
			compare = cmp_string;
			break;
		case 'v':
			itemselect = SELECT_REVOKED;
			break;
		case 'x':
			reverse *= -1;
			break;
		}

	/* remaining arguments are range types				*/
	if (argc > optind) {
		notbefore = argv[optind++];
	}
	if (argc > optind) {
		notafter = argv[optind];
	}

	/* perform OpenSCEP initialization				*/
	scepinit();
	scep_config(&scep, OPENSCEPDIR "/openscep.cnf");

	/* select the working directory based on the command line args	*/
	snprintf(workdir, sizeof(workdir), OPENSCEPDIR "/%s",
		selectname[itemselect]);
	

	/* retrieve all matching items from that directory, put them 	*/
	/* in an array of pointers					*/
	snprintf(workdir, sizeof(workdir), "%s/%s", OPENSCEPDIR,
		selectname[itemselect]);
	if (NULL == (dir = opendir(workdir))) {
		fprintf(stderr, "%s:%d: cannot open directory %s: %s (%d)\n",
			__FILE__, __LINE__, workdir, strerror(errno), errno);
		exit(EXIT_FAILURE);
	}
	while ((d = readdir(dir))) {
		/* look for der files only				*/
		if (0 == strcmp(d->d_name + 32, ".der")) {
			items++;
			itemlist = (scepitem_t **)realloc(itemlist,
				sizeof(scepitem_t *) * (items + 1));
			itemlist[items - 1] = readitem(d->d_name);
			itemlist[items] = NULL;
		}
	}

	/* perform a sort						*/
	if (debug) {
		BIO_printf(bio_err, "%s:%d: sorting %d items in array at %p\n",
			__FILE__, __LINE__, items, itemlist);
	}
	qsort(itemlist, items, sizeof(scepitem_t *),
		(int (*)(const void *, const void *))compare);

	/* display the result						*/
	if (itemlist)
		for (ip = itemlist; *ip; ip++) {
			/* display this item				*/
			display_item(*ip);
		}

	/* that's it							*/
	exit(EXIT_SUCCESS);
}
コード例 #4
0
ファイル: plcfwd.c プロジェクト: LucaBongiorni/open-plc-utils
int main (int argc, char const * argv [])

{
	extern struct channel channel;
	static char const * optv [] =
	{
		"ACD:ef:i:l:M:o:qRS:t:vxz:",
		"device [device] [...] [> stdout]",
		"Qualcomm Atheros VLANID Forward Configuration Manager",
		"A\tadd VLAN ID of multiple slaves to memory",
		"C\tcommit configuration to flash memory",
		"D x\tset default VLAN ID",
		"e\tredirect stderr to stdout",
		"f s\tread VLANIDS from file (s)",

#if defined (WINPCAP) || defined (LIBPCAP)

		"i n\thost interface is (n) [" LITERAL (CHANNEL_ETHNUMBER) "]",

#else

		"i s\thost interface is (s) [" LITERAL (CHANNEL_ETHDEVICE) "]",

#endif

		"l n\tdata length in bytes [" LITERAL (PLCFWD_LENGTH) "]",
		"M n\tenable VLANID forwarding on the master",
		"o x\tdata offset in bytes [" LITERAL (PLCFWD_OFFSET) "]",
		"q\tquiet mode",
		"R\tremove VLAN ID of multiple slaves from memory",
		"S n\tenable VLANID forwarding on all slaves",
		"t n\ttimeout is (n) millisecond [" LITERAL (CHANNEL_TIMEOUT) "]",
		"v\tverbose mode",
		"x\texit on error",
		"z s\tslavespec",
		(char const *) (0)
	};

#include "../plc/plc.c"

	struct item list [128];
	unsigned size = sizeof (list) / sizeof (struct item);
	unsigned items = 0;
	uint32_t offset = 0;
	uint32_t length = 0;
	signed c;
	memset (&list, 0, sizeof (list));
	if (getenv (PLCDEVICE))
	{
		channel.ifname = strdup (getenv (PLCDEVICE));
	}
	optind = 1;
	while ((c = getoptv (argc, argv, optv)) != -1)
	{
		switch (c)
		{
		case 'A':
			plc.action = PLCFWD_ADD;
			break;
		case 'C':
			plc.action = PLCFWD_STO;
			break;
		case 'D':
			plc.action = PLCFWD_SET;
			list [0].VLANID [0] = (uint16_t)(basespec (optarg, 10, sizeof (uint16_t)));
			break;
		case 'e':
			dup2 (STDOUT_FILENO, STDERR_FILENO);
			break;
		case 'f':
			if (!freopen (optarg, "rb", stdin))
			{
				error (1, errno, "%s", optarg);
			}
			items += readlist (&list [items], size - items);
			break;
		case 'i':

#if defined (WINPCAP) || defined (LIBPCAP)

			channel.ifindex = atoi (optarg);

#else

			channel.ifname = optarg;

#endif

			break;
		case 'M':
			plc.action = PLCFWD_CTL;
			plc.module = (uint8_t)(uintspec (synonym (optarg, states, STATES), 0, UCHAR_MAX));
			break;
		case 'l':
			length = (uint32_t) (basespec (optarg, 10, sizeof (length)));
			break;
		case 'o':
			offset = (uint32_t) (basespec (optarg, 10, sizeof (offset)));
			break;
		case 'q':
			_setbits (channel.flags, CHANNEL_SILENCE);
			_setbits (plc.flags, PLC_SILENCE);
			break;
		case 'R':
			plc.action = PLCFWD_REM;
			break;
		case 'S':
			plc.action = PLCFWD_CTL;
			plc.pushbutton = (uint8_t)(uintspec (synonym (optarg, states, STATES), 0, UCHAR_MAX));
			break;
		case 't':
			channel.timeout = (signed)(uintspec (optarg, 0, UINT_MAX));
			break;
		case 'v':
			_setbits (channel.flags, CHANNEL_VERBOSE);
			_setbits (plc.flags, PLC_VERBOSE);
			break;
		case 'x':
			_setbits (plc.flags, PLC_BAILOUT);
			break;
		case 'z':
			readitem (&list [items++], optarg);
			break;
		default:
			break;
		}
	}
	argc -= optind;
	argv += optind;

#if 0

	showlist (list, items);

#endif

	openchannel (&channel);
	if (!(plc.message = malloc (sizeof (* plc.message))))
	{
		error (1, errno, PLC_NOMEMORY);
	}
	if (!argc)
	{
		function (&plc, offset, length, list, items);
	}
	while ((argc) && (* argv))
	{
		if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
		{
			error (1, errno, PLC_BAD_MAC, * argv);
		}
		function (&plc, offset, length, list, items);
		argv++;
		argc--;
	}
	free (plc.message);
	closechannel (&channel);
	return (0);
}