#include
<stdlib.h>
#include
<stdio.h>
#include
<string.h>
#define
LEITURA 0
#define
ESCRITA 1
#define
LEITURAESCRITA 2
/*===================================================================*/
/*===================================================================*/
void
mostraRespricoes();
int
open1(char *file, int
oflag );
void
prog();
char
*gettextoarq(int fd, char
*buf, int buf_size, char
*texto);
char
*gettextoarq1Somenteleitura( char
*arq, char *texto);
char
***getLinhasSomenteleitura(char
*arq, int *j, char
***texto4);
void
mostraLinhas(char **linhas, int
*j);
char
*getLinhaISomenteleitura(char
*arq, int *j, char
*linha, int I);
/*===================================================================*/
/*===================================================================*/
void
mostraLinhas(char
**linhas, int *j)
{
int
i, k;
k = *j;
printf("%s
--->>>>>> linhas[0]", linhas[0]);
printf("%s
--->>>>>> linhas[1]", linhas[1]);
for(i=0;(i
< k )||(linhas[i]!=NULL); i++)
{
printf("%s",
linhas[i]);
}
printf("
\n\n ");
}
/*===================================================================*/
void
mostraRespricoes()
{
printf("
1 - O arquivo pdf3.sh tem que estar no mesmo diretorio que esse
programa\n");
printf("
2 - O arquivo arqpdf.txt tem que estar no mesmo diretorio \n ");
printf("
3 - Os arquivos a serem convertidos devem estar no mesmo diretorio
\n");
printf("
\n\n ");
}
/*===================================================================*/
/*===================================================================*/
/*===================================================================*/
/*
fazer uma função que retorne somente a
string da linha,
* deve-se passar a linha e um ponteiro onde string estara*/
char
*getLinhaISomenteleitura(char
*arq, int *j, char
*linha, int I)
{
int
i;
char texto[500][500],
text[10000], *t1, *t2, charater[500];
printf("\n
Agora entrarei na funcao t1=gettextoarq1Somenteleitura(arq, t1);\n");
t1=gettextoarq1Somenteleitura(arq,
t1);
//printf("
t1 = %s", t1);
sprintf(text, "%s",
t1);
/*
agora com a string t1 tendo uma copia em "text"
*
da pra ficar mais aliviado, pois nao perderemos o
*
conteudo do arquivo, os nomes dos documentos*/
t2=strtok(text,
"\n");
sprintf(texto[0],
"%s", t2);
*j=i;
if(I==0)
{
if(*linha==NULL)
{/*
se estiver passando somente um
*
ponteiro sem nada , NULL*/
linha=texto[0];
}
sprintf(linha,
"%s", texto[0]);
return
linha;
}
//printf("*j= %i \t", *j);
for(i=1;(i<500)||(t2!=NULL);
i++)
{
t2=strtok('\0',
"\n");
sprintf(charater,
"%s", t2);
strcpy(texto[i],
charater);
*j=i;
// printf("*j=
%i \t", *j);
if(t2==NULL
|| strlen(charater)<3)
{
*j=i;
printf("
\n A linha pedida para a funcao e maior que a quanidade de linhas no
arquivo! \n Retornarei a ultima linha do arquivo\n ");
if(*linha==NULL)
{/*
se estiver passando somente um
*
ponteiro sem nada , NULL*/
linha=texto[i-1];
/*linha
= *//*strcpy(linha, texto[i-1]);*/
return
linha;
}
sprintf(linha,
"%s", texto[i-1]);
return
linha;
}
if(i==I)
{
if(*linha==NULL)
{/*
se estiver passando somente um
*
ponteiro sem nada , NULL*/
linha=texto[i];
return
linha;
}
sprintf(linha,
"%s", texto[i]);
return
linha;
}
}
return
NULL;
}
/*===================================================================*/
char
***getLinhasSomenteleitura(char
*arq, int *j, char
***texto4)
{
int
i;
char texto[500][500],
text[10000], *t1, *t2, charater[500];
t1=gettextoarq1Somenteleitura(arq,
t1);
sprintf(text, "%s",
t1);
/*
agora com a string t1 tendo uma copia em "text"
*
da pra ficar mais aliviado, pois nao perderemos o
*
conteudo do arquivo, os nomes dos documentos*/
t2=strtok(text,
"\n");
sprintf(texto[0],
"%s", t2);
*j=i;
//printf("*j= %i \t", *j);
for(i=1;(i<500)||(t2!=NULL);
i++)
{
t2=strtok('\0',
"\n");
sprintf(charater,
"%s", t2);
strcpy(texto[i],
charater);
*j=i;
//
printf("*j= %i \t", *j);
if(t2==NULL
|| strlen(charater)<3)
{
*j=i;
*texto4=&texto[0][0];
return
texto4;
}
}
*texto4=&texto[0][0];
return
texto4;
}
/*===================================================================*/
char
*gettextoarq1Somenteleitura( char *arq,
char *texto)
{
int
fd, buf_size;
char
buf[500], buf2[10000],
*buf3;
buf_size=499;
fd=open1(arq,
LEITURA);
//printf("\n
Agora entrarei na funcao buf3=gettextoarq(fd, buf,
buf_size,buf2);\n");
buf3=gettextoarq(fd,
buf, buf_size,buf2);
if(*texto==NULL)
{/*
se estiver passando somente um
*
ponteiro sem nada , NULL*/
texto=buf3;
}
sprintf(texto,
"%s", buf3);
//printf("\n
Agora entrarei na funcao close(fd);\n");
close(fd);
//printf("\n
O conteudo do arquivo %s e :\n %s \n", arq, buf3);
return
buf3;
}
/*===================================================================*/
char
*gettextoarq(int fd, char
*buf, int buf_size,
char *texto)
{
for(;;)
{
if(read(fd,
buf, buf_size)==0)
{
sprintf(texto, "
%s \n", buf);
return
texto;
}
sprintf(texto, "
%s \n", buf);
}
}
/*===================================================================*/
int
open1(char *file, int
oflag )
{
int
fd;
if((fd=open(file,
oflag))==-1)
{
printf("\n
Nao e possivel abrir o arquivo %s \n", file);
return
fd;
}
return
fd;
}
/*===================================================================*/
void
prog()
{
char
cmd[400], arq[200],
texto[600], **t1, ***t6, *t7;
int
i;
t7=NULL;
sprintf(arq, "%s",
"arqpdf.txt");
//sprintf(stdout
,"%s", "imprimindo na tela, stdout com sprintf");
printf("\n\n\n\n
Programa que concatenara todos os arquivos .pdf em um \n\n\n ");
printf("
Para esse programa funcionar direito e Necessario que: \n ");
mostraRespricoes();
sprintf(cmd, "for
x in *.pdf; do echo %s ", "\"$x\";
done > arqpdf.txt");
system(cmd);
printf(" \n ");
/*
printf("\n Agora entrarei na funcao t6 =
getLinhasSomenteleitura(arq, &i, &t1);\n");
t6 = getLinhasSomenteleitura(arq, &i, &t1);
/**/printf("\n
Agora entrarei na funcao getLinhaISomenteleitura(arq, &i, t7,
3);\n");
t7=getLinhaISomenteleitura(arq,
&i, t7, 3);
/**/printf("\n
t1[0] %s\n t7 ([%i])= %s \n", t1[0],
3, t7);
printf("\n
t1[%i] %s\n", 1, t1[1]);
printf("\n
t1[%i] %s\n", 2, t1[2]);
printf("\n
t1[%i] %s\n", 3, t1[3]);
//mostraLinhas(t1,
&i);
printf("
\n\n\n\n\n\n");
}
/*===================================================================*/
int
main()
{
prog();
return
;
}
/*===================================================================*/