Extract
Publicado por Enzo de Brito Ferber 08/06/2008
[ Hits: 4.980 ]
Homepage: http://www.maximasonorizacao.com.br
Estava eu sem nada pra fazer hoje, então resolvi fazer um programa para retirar códigos fontes de arquivos txt.
<++> diretorio/arquivo.tipo
....
<-->
O <++> é o incio do arquivo, e o <--> é o fim.
Vale dizer que essa idéia de como definir o inicio e fim do arquivo nãoo foi minha, ela já é usada na zine phrack, que tem um programa extract também, mas o que me impede de fazer o meu né?!
/*
* Programa: Retirar codigos de arquivo
* Arquivo : extract.c
* Autor : Enzo Ferber (enzo@veloxmail.com.br)
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#define CODE_START "<++>"
#define CODE_END "<-->"
FILE *createFile (char *);
void getFile (FILE *, int);
void search_code (FILE *, int);
FILE *createFile (char *path)
{
FILE *nfile;
FILE *log;
char dir[50];
struct stat file;
register int i = 0;
if (path[0] == ' ') path = path + 1;
while (path[i] != '\r') i++;
path[i] = '{FONTE}';
i = 0;
while (path[i] != 47) {
dir[i] = path[i];
i++;
}
dir[i] = '{FONTE}';
if (stat(dir, &file) == -1) {
printf("Novo Diretorio: %s\n", dir);
mkdir (dir, 16877);
}
printf("Novo Arquivo: %s\n", path);
nfile = fopen(path, "w");
if (!nfile)
{
printf("Erro ao abrir %s\n", path);
exit(0);
}
return nfile;
}
void getFile (FILE *fp, int pos)
{
FILE *nfile;
char buffer[50];
char info[5];
fseek(fp, pos, SEEK_SET);
fgets(buffer, 50, fp);
nfile = createFile(buffer);
while (1)
{
if (feof(fp)) break;
fgets(buffer, 5, fp);
if (strcmp(buffer, CODE_END) == 0) break;
fputs(buffer, nfile);
}
fclose(nfile);
search_code(fp, ftell(fp));
}
void search_code (FILE *fp, int pos)
{
register int i;
char buffer[5];
fseek(fp, pos, SEEK_SET);
while (1)
{
if (feof(fp)) break;
fgets(buffer, 5, fp);
if (!strcmp (buffer , CODE_START)) getFile(fp, ftell(fp));
}
}
int main (int argc, char **argv)
{
FILE *fp;
if (argc < 2)
{
printf("Uso: %s <arquivo> \n", argv[0]);
return 0;
}
fp = fopen (argv[1], "r");
if (!fp)
{
perror("fopen()");
return 0;
}
search_code (fp, 0);
return 0;
}
Organizador de filmes para o IMDB
Nenhum comentário foi encontrado.
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Atualizar Linux Mint 22.2 para 22.3 beta
Jogar games da Battle.net no Linux com Faugus Launcher
Como fazer a Instalação de aplicativos para acesso remoto ao Linux
Conky, alerta de temperatura alta (10)
Assisti Avatar 3: Fogo e Cinzas (3)
Duas Pasta Pessoal Aparecendo no Ubuntu 24.04.3 LTS (42)









