コード例 #1
0
ファイル: tools.cpp プロジェクト: lgarczyn/npuzzle
void	print_map(const std::string& data, const std::string& solution)
{
	int		width = State::width;
	int		height = State::height;

	int		min = get_int_len(width * height);

	for (int y = 0; y < height; ++y)
	{
		for (int x = 0; x < width; ++x)
		{
			size_t index = x + y * width;
			uint16_t c = data.at(index);
			std::string val = std::to_string(c);

			if (c == 0)
				val = "\x1B[44m" + val + " ";
			else
				val = "\x1B[40m" + val + " ";
			if (solution.find(c) == index)
				val = "\x1B[32m" + val;
			else
				val = "\x1B[37m" + val;

			std::cout << val << std::string(min - get_int_len(c), ' ') << "\x1B[0m ";
		}
		std::cout << std::endl << std::flush;
	}
}
コード例 #2
0
ファイル: ft_itoa.c プロジェクト: chinspp/42
char		*ft_itoa(int n)
{
	int		sign;
	int		i;
	char	*ptr;

	i = 0;
	sign = (n < 0) ? -1 : 1;
	n *= sign;
	if (n < 0 && (ptr = (char *)malloc(sizeof(char) * 12)))
			return (ft_strcpy(ptr, "-2147483648"));
	ptr = NULL;
	if ((ptr = (char *)malloc(sizeof(char) + get_int_len(n))))
	{
		if (sign == -1)
			ptr[i++] = '-';
		while (n >= 0)
		{
			ptr[i++] = '0' + n % 10;
			n /= 10;
			n = (n == 0) ? -1 : n;
		}
		ptr[i] = '\0';
		reverse_str(ptr);
	}
	return (ptr);
}
コード例 #3
0
ファイル: Tabla.c プロジェクト: Jason04/PrograI
void escribirErroresTXT(nodeTable* head) {
    FILE *ptr_file;
    int x;

    ptr_file = fopen("Tabla Manejo de errores.txt", "w");

    if (!ptr_file)
        return 1;

    fprintf(ptr_file, "%s\n", "");
    fprintf(ptr_file, "%s\n", "                          ***************************************************************************************************************");
    fprintf(ptr_file, "%s\n", "                          *                                                  Tabla                                                      *");
    fprintf(ptr_file, "%s\n", "                          *                                            Manejo de Errores                                                *");
    fprintf(ptr_file, "%s\n", "                          ***************************************************************************************************************");
    fprintf(ptr_file, "%s\n", "                          *  Linea        *Tipo                           *Descripción                    *Texto Encontrado             *");

    nodeTable *p;
    for (p = head; p != NULL; p = p->next) {

        fprintf(ptr_file, "%s", "                          *  ");
        fprintf(ptr_file, "%d", p->line);
        int i = strlen("             ") - get_int_len(p->line);
        while (i > 0) {
            fprintf(ptr_file, "%s", " ");
            i = i - 1;
        }

        fprintf(ptr_file, "%s", p->isParameter);
        i = strlen("                                 ") - strlen(p->isParameter);
        while (i > 0) {
            fprintf(ptr_file, "%s", " ");
            i = i - 1;
        }

        fprintf(ptr_file, "%s", p->name);

        i = strlen("                               ") - strlen(p->name);
        while (i > 0) {
            fprintf(ptr_file, "%s", " ");
            i = i - 1;
        }

        fprintf(ptr_file, "%s", p->function);

        i = strlen("                             ") - strlen(p->function);
        while (i > 0) {
            fprintf(ptr_file, "%s", " ");
            i = i - 1;
        }

        fprintf(ptr_file, "%s\n", " *");


    }
    fprintf(ptr_file, "%s\n", "                          ***************************************************************************************************************");
    fprintf(ptr_file, "%s\n", "");
    fclose(ptr_file);

}
コード例 #4
0
int mapinfo(int socket, t_env *e)
{
    char        *sizemap;
    
    char        *tmp;
    
    tmp = malloc(sizeof(char*) * get_int_len(e->map_size[1]));
    sizemap = malloc(sizeof(char*) * (get_int_len(e->map_size[0]) + get_int_len(e->map_size[1]) + 1));
    
    sprintf(sizemap, "%zu", e->map_size[0]);
    strcat(sizemap, ",");
    sprintf(tmp, "%zu", e->map_size[1]);
    strcat(sizemap, tmp);
    //puts(sizemap);
    my_send(socket, sizemap);
    return 0;
}
コード例 #5
0
void str_echo(int sockfd)
{
	
	
    //include content-type and content-length (every single character starting from <html>
    
	for ( ; ; ) {
	char		arg1[MAXLINE+1];
	int        arg2;
	ssize_t		n;
	char		line[MAXLINE];
	char		totalline[MAXLINE];
	totalline[0] = '\0';
	char getrequest[MAXLINE];
	char httpversion[MAXLINE];
	int length = 39;
	    
		if ( (n = Readline(sockfd, line, MAXLINE)) == 0)
			return;		/* connection closed by other end */
        printf("%s\n", line);
        if (sscanf(line, "%s%s%s", getrequest, arg1, httpversion) == 3){
            fprintf(stderr, "Just to check: %s\n", getrequest);
            if(!strcmp(getrequest, "GET")){
                arg2 = converttonum(&arg1[1]); //&arg1[1] gets rid of the slash
                           
                length = length + get_int_len(arg2);

                snprintf(totalline, sizeof(line), "%s%s\n", httpversion, " 200 OK");
                snprintf(line, sizeof(line), "%s%d\n", "Content-Length:", length);
                strcat(totalline,line);
                snprintf(line, sizeof(line), "%s\n", "Vary: Accept-Encoding");
                strcat(totalline,line);
                snprintf(line, sizeof(line), "%s\n", "Content-Type: text/html");
                strcat(totalline,line);
                snprintf(line, sizeof(line), "%s\n", "");
                strcat(totalline,line);
                snprintf(line, sizeof(line), "%s\n", "<html>");
                strcat(totalline,line);
                snprintf(line, sizeof(line), "%s\n", "<body>");
                strcat(totalline,line);
                snprintf(line, sizeof(line), "%s%d%s\n", "<h1>",arg2,"</h1>");
                strcat(totalline,line);
                snprintf(line, sizeof(line), "%s\n", "</body>");
                strcat(totalline,line);
                snprintf(line, sizeof(line), "%s\n", "</html>");
                strcat(totalline,line);
                }
		}else{
		    
			//snprintf(totalline, sizeof(line), "input error - too many/few arguments\n");
        }
		n = strlen(totalline);
		fprintf(stderr, "%s", totalline);
		fprintf(stderr, "%s\n\n\n", " ");
		Writen(sockfd, totalline, n);
	}
}
コード例 #6
0
void str_echo(int sockfd) {
    char arg1[MAXLINE], arg2[MAXLINE], arg3[MAXLINE];
    ssize_t		n;
    char		line[MAXLINE];
    int roman, my_length;
    char allthelines[MAXLINE];

    for ( ; ; ) {
        if ( (n = Readline(sockfd, line, MAXLINE)) == 0)
            return;		/* connection closed by other end */

        if (sscanf(line, "%s%s%s", arg1, arg2, arg3) == 3) {

            if (!strcmp(arg1, "GET")) {
                roman = roman_converter(&arg2[1]);
                my_length = 39 + get_int_len(roman);
                snprintf(allthelines, sizeof(line), "%s 200 OK\n", arg3);
                snprintf(line, sizeof(line), "Content-Length: %i\n", my_length);
                strcat(allthelines, line);
                snprintf(line, sizeof(line), "Vary: Accept-Encoding\n");
                strcat(allthelines, line);
                snprintf(line, sizeof(line), "Content-Type: text/html\n");
                strcat(allthelines, line);
                snprintf(line, sizeof(line), "\n");
                strcat(allthelines, line);
                snprintf(line, sizeof(line), "<html>\n");
                strcat(allthelines, line);
                snprintf(line, sizeof(line), "<body>\n");
                strcat(allthelines, line);
                snprintf(line, sizeof(line), "<h1>%i<h1>\n", roman);
                strcat(allthelines, line);
                snprintf(line, sizeof(line), "</body>\n");
                strcat(allthelines, line);
                snprintf(line, sizeof(line), "</html>\n");
                strcat(allthelines, line);

            }

        } else {
            snprintf(line, sizeof(line), "input error\n");
        }

        n = strlen(allthelines);
        fprintf(stderr, "%s\n", allthelines);
        Writen(sockfd, allthelines, n);
    }
}
コード例 #7
0
ファイル: Tabla.c プロジェクト: Jason04/PrograI
void escribirTablaTXT(nodeTable* head) {
    FILE *ptr_file;
    int x;

    ptr_file = fopen("Tabla de Simbolos.txt", "w");

    if (!ptr_file)
        return 1;

    fprintf(ptr_file, "%s\n", "");
    fprintf(ptr_file, "%s\n", "                                ********************************************************************************");
    fprintf(ptr_file, "%s\n", "                                *                                   Variables                                  *");
    fprintf(ptr_file, "%s\n", "                                ********************************************************************************");
    fprintf(ptr_file, "%s\n", "                                *  Nombre        *Línea        *¿Parámetro?        *Función        *¿Utilizada?*");

    nodeTable *p;
    for (p = head; p != NULL; p = p->next) {
        if ((strcmp(p->parameter, "Es variable")) == 0) {
            fprintf(ptr_file, "%s", "                                *  ");
            fprintf(ptr_file, "%s", p->name);
            int i = strlen("               ") - strlen(p->name);
            while (i > 0) {
                fprintf(ptr_file, "%s", " ");
                i = i - 1;
            }

            fprintf(ptr_file, "%d", p->line);


            i = strlen("                  ") - get_int_len(p->line);
            while (i > 0) {
                fprintf(ptr_file, "%s", " ");
                i = i - 1;
            }


            fprintf(ptr_file, "%s", p->isParameter);
            fprintf(ptr_file, "%s", "               ");
            fprintf(ptr_file, "%s", p->function);

            i = strlen("                   ") - strlen(p->function);
            while (i > 0) {
                fprintf(ptr_file, "%s", " ");
                i = i - 1;
            }

            fprintf(ptr_file, "%s", p->isUsed);
            fprintf(ptr_file, "%s\n", "     *     ");

        }
    }
    fprintf(ptr_file, "%s\n", "                                ********************************************************************************");

    fprintf(ptr_file, "%s\n", "                                *                                    Funciones                                 *");
    fprintf(ptr_file, "%s\n", "                                ********************************************************************************");

    fprintf(ptr_file, "%s\n", "                                *  Nombre         *Línea        *Parámetro         *¿Utilizada?                *");

    for (p = head; p != NULL; p = p->next) {
        if ((strcmp(p->function, "Es funcion")) == 0) {
            fprintf(ptr_file, "%s", "                                *  ");
            fprintf(ptr_file, "%s", p->name);

            int i = strlen("                ") - strlen(p->name);
            while (i > 0) {
                fprintf(ptr_file, "%s", " ");
                i = i - 1;
            }
            fprintf(ptr_file, "%d", p->line);

            i = strlen("              ") - get_int_len(p->line);
            while (i > 0) {
                fprintf(ptr_file, "%s", " ");
                i = i - 1;
            }

            fprintf(ptr_file, "%s", p->parameter);

            i = strlen("                           ") - get_int_len(p->parameter);
            while (i > 0) {
                fprintf(ptr_file, "%s", " ");
                i = i - 1;
            }

            fprintf(ptr_file, "%s", p->isUsed);
            fprintf(ptr_file, "%s\n", "                      *     ");
        }
    }
    fprintf(ptr_file, "%s\n", "                                ********************************************************************************");
    fprintf(ptr_file, "%s\n", "                                *                                   Etiquetas                                  *");
    fprintf(ptr_file, "%s\n", "                                ********************************************************************************");

    fprintf(ptr_file, "%s\n", "                                *  Nombre                              *Línea        *¿Utilizada?              *");

    for (p = head; p != NULL; p = p->next) {
        if ((strcmp(p->parameter, "Es etiqueta")) == 0) {
            fprintf(ptr_file, "%s", "                                *  ");
            fprintf(ptr_file, "%s", p->name);
            int i = strlen("                                      ") -
                    strlen(p->name);
            while (i > 0) {
                fprintf(ptr_file, "%s", " ");
                i = i - 1;
            }

            fprintf(ptr_file, "%d", p->line);
            i = strlen("                ") - get_int_len(p->line);
            while (i > 0) {
                fprintf(ptr_file, "%s", " ");
                i = i - 1;
            }
            fprintf(ptr_file, "%s", p->isUsed);
            fprintf(ptr_file, "%s\n", "                    *     ");

        }
    }
    fprintf(ptr_file, "%s\n", "                                ********************************************************************************");
    fprintf(ptr_file, "%s\n", "");
    fclose(ptr_file);



}