コード例 #1
0
ファイル: stackdump.c プロジェクト: bitkeeper-scm/bitkeeper
/*
 * This is for internal use, the idea is that you can get a stack
 * trace anywhere in the code by calling this function. Maybe it
 * should be moved to trace.c.
 */
char	*
stackdump(void)
{
	void	*trace[16];
	char	**messages = 0, **msg = 0;
	int	i, trace_size = 0;
	char	*p, *q;
	char	*ret;

	trace_size = backtrace(trace, 16);
	messages = backtrace_symbols(trace, trace_size);
	for (i = 0; i < trace_size; i++) {
		p = strstr(messages[i], "0x");
		p += 2;
		while (!isspace(*p)) p++;
		p++;
		q = strchr(p, '+');
		q--;
		*q = 0;
		msg = addLine(msg, p);
	}
	removeLineN(msg, 1, 0);
	reverseLines(msg);
	ret = joinLines(" -> ", msg);
	freeLines(msg, 0);
	free(messages);
	return (ret);
}
コード例 #2
0
ファイル: Structs.c プロジェクト: gaudima/metro-spb
static void freeScheme(Scheme* scheme) {
    if(scheme != NULL) {
        freeLines(scheme->lines, scheme->linesLen);
        freeStations(scheme->stations, scheme->stationsLen);
        freeLinks(scheme->links, scheme->linksLen);
        free(scheme);
    }
}
コード例 #3
0
ファイル: 09b.c プロジェクト: abecderic/Advent-of-Code-2015
int main(void)
{
	readStdinIntoLines();

	int i = current_line;
	int n = 1; /* amount of places */

    while (i >= n)
    {
    	i -= n;
    	n++;
    }

	matrix = malloc((unsigned int)(n) * (unsigned int)(n) * sizeof(int));
	int originID = 0;
	int destinationID = 0;
	int length;

	/* fill matrix with distances */
	for (i = 0; i < current_line; i++)
	{
		char *part = malloc(sizeof(char) * MAX_LINE_LENGTH);
		strcpy(part, lines[i]);

		destinationID++;
		if (destinationID == n)
		{
			originID++;
			destinationID = originID+1;
		}

		part = strtok(part, " ");
		part = strtok(NULL, " ");
		part = strtok(NULL, " ");
		part = strtok(NULL, " ");
		part = strtok(NULL, " ");
		/* we only care about the number at the end */
        length = atoi(part);

        matrix[originID * n + destinationID] = length;
        matrix[destinationID * n + originID] = length;
	}

	int array[n];
	for (i = 0; i < n; i++)
		array[i] = i;
	doPermutation(array, 0, n);

	printf("longest distance: %d\n", currentMax);

	freeLines();
	return 0;
}
コード例 #4
0
ファイル: mail.c プロジェクト: AlexShiLucky/bitkeeper
pid_t
smtpmail(char **to, char *subject, char *file)
{
	int	fd, fd0, wfd, i, j = -1;
	pid_t	pid;
	char	buf[MAXLINE];
	char	sendmail[MAXPATH], *mail;
	char	**av;
	struct	utsname ubuf;
	char	*paths[] = {
		"/usr/bin",
		"/bin",
		"/usr/sbin",
		"/usr/etc",
		"/etc",
		"/usr/lib",
		"/usr/local/bin",
		0
	};

	while (paths[++j]) {
		sprintf(sendmail, "%s/sendmail", paths[j]);
		if (access(sendmail, X_OK) == 0) {
			FILE	*f, *pipe;

			av = addLine(0, strdup(sendmail));
			av = addLine(av, strdup("-i"));
			EACH (to) av = addLine(av, strdup(to[i]));
			av = addLine(av, 0);

			pid = spawnvpio(&wfd, 0, 0, av + 1);
			freeLines(av, free);
			if (pid == -1) return (pid);
			pipe = fdopen(wfd, "w");
			fputs("To: ", pipe);
			EACH (to) {
				unless (i == 1) fprintf(pipe, ", ");
				fprintf(pipe, "%s", to[i]);
			}
			fputs("\n", pipe);
			if (subject && *subject) {
				fprintf(pipe, "Subject: %s\n", subject);
			}
			fputs("\n", pipe);
			f = fopen(file, "r");
			while (fgets(buf, sizeof(buf), f)) fputs(buf, pipe);
			fclose(f);
			fclose(pipe);
			return pid;
		}
	}