domingo, 7 de setembro de 2008

Colocando códigos (code2HTML) ; Ada, Awk, C, C++, HTML, Java, JavaScript, m4, Makefile, Pascal, Perl, SQL, ruby e povray em HTML com CODE2HTML



Teve um Autríaco que desenvolveu um código em Pearl capaz de formatar as linguagens de programação; Ada, Awk, C, C++, HTML, Java, JavaScript, m4, Makefile, Pascal, Perl, SQL, ruby e povray em HTML

Coloquei essas informações de maneira melhor organizada em:
http://br.geocities.com/danilomatias@ymail.com/code/code2html/index/123456.html
Ainda é possível conferir o resultado desse script de maneira online no link:

http://www.palfrader.org/code2html/code2html.html

A documentação oficial se encontra em:

http://www.palfrader.org/code2html/manual.html

A página oficial do projeto é:
http://www.palfrader.org/code2html/


Na página:
http://gnu.fyxm.net/directory/devel/conversion/code2html.html

Achei o link para baixar o código fonte e executar em:
http://www.palfrader.org/code2html/all/code2html-0.9.1.tar.gz

Descompatei entrei na pasta que estava o código fonte e testei o programa.

De uma maneira geral:

A sintaxe geral é:

./code2html -nvL lingagem_de_programaçao arquivo.lingagem_de_programaçao arquivo_destino.html

Teste com o exemplo abaixo:
./code2html -nvL c 3.c 3_c.html
Onde:

c é a linguagem [c, java, paskal, pearl, php, ...]
3.c o nome do Arquivo.c
3_c.html o nome do arquivo .html


A página do cara que desenvolveu o código é (Peter Palfrader):

http://www.palfrader.org/

o Resultado (código convertido) foi:


1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #define LEITURA 0
5 #define ESCRITA 1
6 #define LEITURAESCRITA 2
7 #define TAMNOME 500
8 #define NR_MAX_OF_CHR_ARQ 20000
9 /*=============================================================*/
10 /*=============================================================*/
11 /*
12 *
13 * ordem das chamadas
14 de funções que estão me
15 dando dor de cabeça:
16 *
17 * prog();
18 ==>>getLinhaISomenteleitura(arq, &i, t7, 3); ==>>
19 gettextoarq1Somenteleitura1(arq); ==>> ==>> ==>>
20 ==>> ==>> ==>> ==>> ==>> ==>>
21 ==>>
22 *
23 * -> prog();
24 ==>>mostraLinhas(arq, 10); ==>>getLinhaISomenteleitura1(arq,
25 3); ==>> t1=gettextoarq1Somenteleitura1(arq); ==>> ==>>
26 ==>> ==>> ==>> ==>> ==>> ==>>
27 ==>> ==>>
28 -> prog();
29 ==>>mostraRespricoes() ==>>[mostraLinhas4(arq);==>>
30 (vet1=get_vetor_string_arq(arq);==>>)==>>nl=getNumeroLinhaStringArquivo(arq);==>>]==>>
31 ==>> ==>> ==>> ==>> ==>> ==>>
32 ==>> ==>> ==>>* */

33 /*=============================================================*/
34 /* 528 - 541*/char *alocarStringA(int tam);
35 /* 542 - 550 */char *alocarStringB(char *str);
36 /* 156 - 184 */char ***alocar_vetor_string_arq(char *arq);
37 /* 309 - 319 */int contachar(char string[], char letra);
38 /* 186 - 200 */int getimaiorStringemArq(char *arq);
39 /* 343 - 386 */char *getLinhaISomenteleitura(char *arq, int *j, char *linha,int I);
40 /* 156 - 184 */char *getLinhaISomenteleitura1(char *arq, int I);
41 /* 156 - 184 */char *gettextoarq(int fd, char *buf, int buf_size, char *texto);
42 /* 518 - 529 */char *gettextoarq1Somenteleitura1A( char *arq, int Numero_de_caracteres_do_nome_do_arquivo, int Numero_de_caracteres_do_arquivo);
43 /* 156 - 184 */char *gettextoarq1Somenteleitura( char *arq, char *texto);
44 /* 156 - 184 */char *gettextoarq1Somenteleitura1( char *arq);
45 /* 156 - 184 */char ***getLinhasSomenteleitura(char *arq, int *j, char ***texto4);
46 /* 156 - 184 */int getNumeroLinhaString(char *str);
47 /* 156 - 184 */int getNumeroLinhaStringArquivo(char *arq);
48 /* 156 - 184 */int get_Strlen_da_maior_String_em_Arq(char *arq);
49 /* 156 - 184 */char ***get_vetor_string_arq(char *arq);
50 /* 156 - 184 */char **getvetorLinhasArg(char *arq);
51 /* 156 - 184 */char **getvetorLinhasArg1(char *arq);
52 /* 156 - 184 */char **getvetorLinhasArg1(char *arq);
53 /* 156 - 184 */void limpaStr(char *Str);
54 /* 156 - 184 */void mostraRespricoes();
55 /* 156 - 184 */void mostraLinhas(char *arq, int j);
56 /* 156 - 184 */void mostraLinhas1(char *arq);
57 /* 156 - 184 */void mostraLinhas2(char *arq);
58 /* 156 - 184 */void mostraLinhas3(char *arq);
59 /* 156 - 184 */void mostraLinhas4(char *arq);
60 /* 156 - 184 */int open1(char *file,int oflag );
61 /* 156 - 184 */void prog();
62 /* 156 - 184 */char *strpdftk(char *arq);
63 /* 156 - 184 */char *substituiEspacoPor_(char *str);
64 /* 156 - 184 */char *subs_str(char *string, char *substring, char *nova);
65
66 /*=============================================================*/
67 /*=============================================================*/
68 /*=============================================================*/
69 char ***get_vetor_string_arq(char *arq)
70 {
71 int l, i, j, k, m, n,o, num_linhas;
72 char ***vet1, **vet;
73
74 vet1=NULL; vet=NULL;
75 vet1=alocar_vetor_string_arq(arq);
76 vet=*vet1;/* tenho o vetor de strings alocadinha basta preenchê-lo*/
77 num_linhas=getNumeroLinhaStringArquivo(arq);
78 for(i=0;i<num_linhas; i++)
79 {
80 sprintf(vet[i] ,"%s", getLinhaISomenteleitura1(arq, i) );
81 }
82 return vet1;
83 }
84 /*=============================================================*/
85 /*=============================================================*/
86 void mostraLinhas4(char *arq)
87 {
88 int l, i, nl;
89 char **vet, ***vet1;
90
91 vet=NULL; vet1=NULL;
92 vet1=get_vetor_string_arq(arq);
93 vet=*vet1;
94 nl=getNumeroLinhaStringArquivo(arq);
95 for(i=0; i <nl;i++)
96 {
97 printf("\n vet[%i]: %s", i, vet[i]);
98 }
99 printf("\n\n ************************************\n\n");
100 }
101 /*=============================================================*/
102 void mostraLinhas3(char *arq)
103 {
104 int l, i;
105 char **vet;
106
107 vet=NULL;
108 vet=getvetorLinhasArg1(arq);
109 if(vet==NULL){printf("\n Deu problema no mostra linha3 ver e nulo !\n");}
110 //t8=getLinhaISomenteleitura1(arq,9);
111 /*printf("\n
112 Passemos a i=getNumeroLinhaStringArquivo(arq);\n");*/

113 i=getNumeroLinhaStringArquivo(arq);
114 //printf("********* Mostrando as %i linhas do arquivo %s ****\n\n", i,arq);
115 printf("Linhas(vet)[%i ]{%i}: %s \n", 0, strlen(vet[0]), vet[0]);
116 printf("Linhas(vet)[%i ]{%i}: %s \n", 1, strlen(vet[1]), vet[1]);
117 /*
118 for(l=0; l < i;l++)
119 {
120 printf("Linhas(vet)[
121 %i ]{%i}: %s \n", l, strlen(vet[l]), vet[l]);
122 }*/

123 printf("\n\n************************************\n\n");
124 }
125 /*===================================================================*/
126 /*===================================================================*/
127 void mostraLinhas2(char *arq)
128 {
129 int l, i;
130 char **vet;
131
132 vet=getvetorLinhasArg(arq);
133 //t8=getLinhaISomenteleitura1(arq,9);
134 i=getNumeroLinhaStringArquivo(arq);
135 //printf("********* Mostrando as %i linhas do arquivo %s ****\n\n", i,arq);
136 for(l=0; l < i;l++)
137 {
138 printf("Linhas(vet)[%i ]{%i}: %s \n", l, strlen(vet[i]), vet[i]);
139 }
140 printf("\n\n************************************\n\n");
141 }
142 /*=============================================================*/
143 int get_Strlen_da_maior_String_em_Arq(char *arq)
144 {
145 int l, i, k, la, bb, maior, idomaior;
146 char **vet, str[TAMNOME];
147
148 k=0;maior=0;
149 for(i=0; i<getNumeroLinhaStringArquivo(arq);i++)
150 {
151 k = strlen(getLinhaISomenteleitura1(arq, i));
152 if(k>=maior){maior=k;idomaior=i;}
153 }
154 return maior;
155 }
156 /*=============================================================*/
157 char ***alocar_vetor_string_arq(char *arq)
158 {
159 int tam1, tam2, i,j;
160 char **vetor, ***vet;
161
162 tam2 =get_Strlen_da_maior_String_em_Arq(arq);
163 tam2=tam2*sizeof(char);
164 tam1=getNumeroLinhaStringArquivo(arq);
165 if((vetor=(char**)malloc(tam1*sizeof(char*)))==NULL)
166 {
167 printf("\n Naofoi possivel alocar as linhas do de vetor de strings para do arquivo\n");
168 return NULL;
169 }
170 for(i=0;i<tam1;i++)
171 {
172 if((vetor[i]=(char*)malloc(tam2))==NULL)
173 {
174 printf("\nNao foi possivel alocar as colunas do vetor de strings para doarquivo \n");
175 for(--i;i>=0;i--)
176 {
177 free(vetor[i]);
178 }
179 free(vetor);
180 return NULL;
181 }
182 }
183 vet=&vetor;
184 return vet;
185 }
186 /*=============================================================*/
187 int getimaiorStringemArq(char *arq)
188 {
189 int l, i, k, la, bb, maior, idomaior;
190 char **vet, str[TAMNOME];
191 k=0;maior=0;
192 for(i=0; i<getNumeroLinhaStringArquivo(arq);i++)
193 {
194 k =strlen(getLinhaISomenteleitura1(arq, i));
195 if(k>=maior){maior=k;idomaior=i;}
196 }
197 return idomaior;
198 }
199 /*=============================================================*/
200 char **getvetorLinhasArg1(char *arq)
201 {
202 int l, i, k, la, bb;
203 char **vet,str[TAMNOME];
204 /* o probela e alocar
205 o vetor para armazenar*/

206 i=getNumeroLinhaStringArquivo(arq);
207 vet=(char**)malloc(i*sizeof(char*));
208 if(vet==NULL)
209 {
210 printf("\nNao foi possivel alocar as linhas do vetor de linhas \n");
211 return NULL;
212 }
213 for(la=0; la < i;la++)
214 {
215 strcpy(str,getLinhaISomenteleitura1(arq, la));
216 k = strlen(str);
217 /*printf("\n k
218 = strlen(str);: %i\n st: %s\n", k, str);*/

219 vet[la]=(char*)malloc(k*sizeof(char));
220 if(vet[la]==NULL)
221 {
222 printf("\n Nao foi possivel alocar as colunas do vetor de linhas \n");
223 free(vet);return NULL;
224 }
225 sprintf(vet[la],"%s", str);
226 for(bb=0; bb<=la;bb++)
227 printf("%s \n", vet[bb]);
228 //strcpy(vet[l],str);
229 // if((l%2)!=0){
230 //printf("%i%%3=%i\nLinhas(vet[%i])[ %i ]: %s \n str : %s \n\n",l, l%3, l,l, vet[l], str);
231 //}
232 }
233 //printf("vet[1-4]: %s %S %s %S \n\n", vet[0], vet[1], vet[2], vet[4]);
234 printf(" Agora vema montagem do vetor vet : %s \n\n", vet);
235 /* for(la=0; la <i; la++)
236 {
237 printf("\nvet[%i]: %s\n ", la, vet[la]);
238 }*/

239 return vet;
240 }
241
242 /*=============================================================*/
243 void mostraLinhas1(char *arq)
244 {
245 int l, i;
246 //t8=getLinhaISomenteleitura1(arq,9);
247 i=getNumeroLinhaStringArquivo(arq);
248 printf("Mostrando as %i linhas do arquivo \n\n", i);
249 for(l=0; l < i;l++)
250 {
251 printf("Linhas[%i ]: %s \n", l, getLinhaISomenteleitura1(arq, l));
252 }
253 printf("\n\n************************************\n\n");
254 }
255 /*=============================================================*/
256 char**getvetorLinhasArg(char *arq)
257 {
258 int l, i, k;
259 char **vet, *str;
260 l=getNumeroLinhaStringArquivo(arq);
261 //printf("Mostrando as %i linhas do arquivo \n\n", l);
262 vet=(char**)malloc(l*sizeof(char));
263 if(vet==NULL)
264 {
265 printf("\nNao foi possivel alocar as linhas do vetor de linhas \n");
266 return NULL;
267 }
268 for(i=0; i < l;i++)
269 {
270 strcpy(str,getLinhaISomenteleitura1(arq, i));
271 k = strlen(str);
272 vet[i]=(char*)malloc(k*sizeof(char));
273 if(vet[i]==NULL)
274 {
275 printf("\nNao foi possivel alocar as colunas do vetor de linhas \n");
276 return NULL;
277 }
278 strcpy(vet[i] ,str);
279 printf("vet[ %i]: %s \n", l, vet[i]);
280 }
281 //printf("\n\n************************************\n\n");
282 return vet;
283 }
284 /*=============================================================*/
285 /*=============================================================*/
286 void mostraLinhas(char *arq, int j)
287 {
288 int l;
289 //t8=getLinhaISomenteleitura1(arq,9);
290 printf("\n\nMostrando as %i linhas do arquivo \n\n", j);
291 for(l=0; l < j;l++)
292 {
293 printf("Linhas[%i ]: %s \n", l, getLinhaISomenteleitura1(arq, l));
294 }
295 printf("\n\n************************************\n\n");
296 printf(" %s \n O Arquivo tem %i linhas", gettextoarq1Somenteleitura1(arq), getNumeroLinhaString(gettextoarq1Somenteleitura1(arq)));/**//**/
297 printf("\n\n************************************\n\n");
298 }
299 /*=============================================================*/
300 void mostraRespricoes()
301 {
302 printf(" 1 - O arquivo arqpdf.txt tem que estar no mesmo diretorio \n ");
303 printf(" 2 - Os arquivos a serem convertidos devem estar no mesmo diretorio \n");
304 printf(" 3 - O arquivo gerado tera o nome de \'PDFTK921_ ...pdf\'\n");
305 printf(" 4 - Os nomes dos arquivos (arquivo ... .pdf) a serem unidos nao podem possuir espacos em branco\n");
306 printf(" 5 - Para o programa funcionar você deve ter a ferramenta pdftk instalada no seu computador, para mais informacoes acesse: \'http://www.vivaolinux.com.br/dica/Manipulando-arquivos-PDF-com-pdftk\'\n");
307 }
308 /*=============================================================*/
309 /*=============================================================*/
310 int contachar(char string[], char letra)
311 {
312 int contador,tamanho, ocorrencia = 0;
313 tamanho =strlen(string);
314 for(contador=1;contador <= tamanho;contador++)
315 if(string[contador] == letra)
316 ocorrencia++;
317 return(ocorrencia);
318 }
319
320 /*=============================================================*/
321 int getNumeroLinhaString(char *str)
322 {
323 /*onde str é a string com várias linhas*/
324 return contachar(str, '\n');
325 }
326
327 /*=============================================================*/
328 int getNumeroLinhaStringArquivo(char *arq)
329 {
330 /*onde str é a string com várias linhas*/
331 int i;
332 char *s1;
333 s1=gettextoarq1Somenteleitura1(arq);
334 i=getNumeroLinhaString(s1);
335 i=i-1;
336 return i;
337 }
338 /*=============================================================*/
339 /* fazer uma função
340 que retorne somente a string da linha,
341
342 * deve-se passar a
343 linha e um ponteiro onde string estara*/

344 char *getLinhaISomenteleitura1(char *arq, int I)
345 {
346 int i;
347 char text[10000],*t1, *t2, charater[500], *ta1;
348 t1=gettextoarq1Somenteleitura1(arq);
349 //t1=gettextoarq1Somenteleitura1A(arq, strlen(arq),/* strlen()*//**/NR_MAX_OF_CHR_ARQ/**/);
350 sprintf(text, "%s",t1);
351 /* agora com a string t1 tendo uma copia em "text"
352 * da pra ficar
353 mais aliviado, pois nao perderemos o
354 * conteudo do
355 arquivo, os nomes dos documentos*/

356 //res = strtok(s,delim);
357 t2=strtok(text,"\n");
358 //sprintf(texto[0],"%s", t2);
359 //printf(" \n O conteudo da variaveis text (antes de retornar a linha) e %s \n Ja o conteudo de t2 e %s \n \n", text, t2);
360 if(I==0)
361 {
362 return t2;
363 }
364 for(i=1;(i<=I)&&(t2 != NULL); i++)
365 {
366 //res =strtok(NULL, delim);
367 t2=strtok(NULL,"\n");
368 sprintf(charater,"%s", t2);
369 //printf("\n O conteudo do arquivo na linha %i e %s \n Ja o conteudo de t2 e %s \n Ja o conteudo de charater e %s \n", i, text, t2,charater);
370 if(i==I)
371 {
372 strcpy(ta1,charater);
373 return t2;
374 }
375 if(t2==NULL)
376 {
377 printf("\n A linha pedida para a funcao e maior que a quanidade de linhas no arquivo! \n Entre com um valor de linha menor que o numero de linhas do arquivo!\n ");
378 return NULL;
379 }
380 }
381 if(i==I)
382 {
383 strcpy(ta1,charater);
384 return t2;
385 }
386 return NULL;
387 }
388 /*=============================================================*/
389 void limpaStr(char *Str)
390 {
391 int i, j;
392 i=strlen(Str);
393 for(j=i-1;j>=0;j--)
394 {
395 Str[j]=' ';
396 /*Str[j]=NULL*//* ;*///strcpy(*(Str+j)," ");
397 }
398 }
399 /*=============================================================*/
400 /* fazer uma função
401 que retorne somente a string da linha,
402
403 * deve-se passar a
404 linha e um ponteiro onde string estara*/

405 char *getLinhaISomenteleitura(char *arq, int *j, char *linha, int I)
406 {
407 int i;
408 char texto[500][500],text[10000], *t1, *t2, charater[500];
409 printf("\n Agora entrarei na funcao t1=gettextoarq1Somenteleitura(arq, t1);\n");
410 t1=gettextoarq1Somenteleitura1(arq);
411 sprintf(text, "%s",t1);
412 /* agora com a string t1 tendo uma copia em "text"
413 * da pra ficar mais aliviado, pois nao perderemos o
414 * conteudo do arquivo, os nomes dos documentos*/

415 t2=strtok(text,"\n");
416 sprintf(texto[0], "%s", t2);
417 *j=i;
418 if(I==0)
419 {
420 if(/**linha==NULL */strcmp(linha,NULL)==0)
421 {/* se estiver passando somente um * ponteiro sem nada , NULL*/
422 linha=texto[0];
423 }
424 sprintf(linha, "%s", texto[0]);
425 return linha;
426 }
427 //printf("*j= %i \t", *j);
428 for(i=1;(i<500)||(t2!=NULL);i++)
429 {
430 t2=strtok('\0',"\n");
431 sprintf(charater,"%s", t2);
432 strcpy(texto[i],charater);
433 *j=i;
434 // printf("*j=%i \t", *j);
435 if(t2==NULL ||strlen(charater)<3)
436 {
437 *j=i;
438 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 ");
439 if(/**linha==NULL */strcmp(linha,NULL)==0)
440 { /* se estiver passando somente um
441 * ponteiro sem nada , NULL*/

442 linha=texto[i-1];
443 /*linha = *//*strcpy(linha, texto[i-1]);*/
444 return linha;
445 }
446 sprintf(linha,"%s", texto[i-1]);
447 return linha;
448 }
449 if(i==I)
450 {
451 if(/**linha==NULL */strcmp(linha,NULL)==0)
452 { /* se estiver passando somente um
453 * ponteiro sem nada , NULL*/

454 linha=texto[i];
455 return linha;
456 }
457 sprintf(linha,"%s", texto[i]);
458 return linha;
459 }
460 }
461 return NULL;
462 }
463 /*=============================================================*/
464 char ***getLinhasSomenteleitura(char *arq, int *j, char ***texto4)
465 {
466 int i;
467 char texto[500][500], text[10000], *t1, *t2, charater[500], **texto5;
468 t1=gettextoarq1Somenteleitura(arq,t1);
469 printf("\n entrou em char ***getLinhasSomenteleitura(char *arq, int *j, char ***texto4) \n gettextoarq1Somenteleitura(arq, t1); = %s \n ", t1);
470 sprintf(text, "%s", t1);
471 /* agora com a string t1 tendo uma copia em "text"
472 * da pra ficar mais aliviado, pois nao perderemos o
473 * conteudo do arquivo, os nomes dos documentos*/

474 t2=strtok(text,"\n");
475 sprintf(texto[0], "%s", t2);
476 *j=i;
477 //printf("*j=%i \t", *j);
478 for(i=1;(i<500)||(t2!=NULL);i++)
479 {
480 t2=strtok('\0',"\n");
481 sprintf(charater,"%s", t2);
482 strcpy(texto[i],charater);
483 *j=i;
484 // printf("*j=%i \t", *j);
485 if(t2==NULL ||strlen(charater)<3)
486 {
487 *j=i;
488 /**texto4=&texto[0][0];
489 *texto4= =strdup(texto[0]);*/

490 // strcpy(texto5,texto);
491 *texto4=texto5;
492 return texto4;
493 }
494 }
495 /*
496 *texto4=&texto[0][0];
497 *texto4= =strdup(texto[0]);*/

498 // strcpy(texto5,texto);
499 *texto4=texto5;
500 // return &texto5;
501 return texto4;
502 }
503 /*=============================================================*/
504 char *gettextoarq1Somenteleitura1( char *arq)
505 {
506 int fd, buf_size;
507 char buf[500],buf2[10000], *buf3;
508
509 buf_size=499;
510 fd=open1(arq,LEITURA);
511 buf3=gettextoarq(fd,buf, buf_size,buf2);
512 close(fd);
513 return buf3;
514 }
515 /*=============================================================*/
516
517 char *gettextoarq1Somenteleitura1A( char *arq, int Numero_de_caracteres_do_nome_do_arquivo, int Numero_de_caracteres_do_arquivo)
518 {
519 int fd;
520 char *buf, *buf2, *buf3;
521
522 buf2=alocarStringA(Numero_de_caracteres_do_arquivo);
523 buf=alocarStringA(Numero_de_caracteres_do_nome_do_arquivo);
524 fd=open1(arq,LEITURA);
525 buf3=gettextoarq(fd,buf, Numero_de_caracteres_do_nome_do_arquivo,buf2);
526 close(fd);
527 return buf3;
528 }
529 /*=============================================================*/
530 char *alocarStringA(int tam)
531 {
532 int tam2;
533 char *vetor;
534
535 tam2=tam*sizeof(char);
536 if((vetor=(char*)malloc(tam2))==NULL)
537 {
538 printf("\n Nao foi possivel alocar a string de tamanho %i \n", tam);
539 return NULL;
540 }
541 return vetor;
542 }
543 /*=============================================================*/
544 char *alocarStringB(char *str)
545 { /* str e a string ao qual se desejara copiar em B*/
546 int tam2, tam;
547 char *str2;
548 tam=strlen(str);
549 tam=tam+30;
550 str2=alocarStringA(tam);
551 return str2;
552 }
553 /*=============================================================*/
554 /*=============================================================*/
555 /*=============================================================*/
556 /*=============================================================*/
557 /*=============================================================*/
558 /*=============================================================*/
559 /*=============================================================*/
560 char *strpdftk(char *arq)
561 {
562 int i, j, k, l, m, n,n1;
563 char *arq1, *arq2, *arqout, *out, *ext, *meio;
564 l=getNumeroLinhaStringArquivo(arq);
565 n1=strlen("pdftk");
566 n1=n1+800;
567 out=(char*)malloc(n1*sizeof(char));
568 arq1=(char*)malloc((n1-120)*sizeof(char));
569 arq2=(char*)malloc((n1-120)*sizeof(char));
570 ext=(char*)malloc((n1-500)*sizeof(char));
571 k=0;
572 i=0;
573 m=1;
574 //printf("\nString0: %s\n", out);
575 //limpaStr(out);
576 //printf("\nString1depois: %s\n", out);
577 /*printf("\n\n\n\ngetLinhaISomenteleitura1(arq, 2) : %s \n\n\n",getLinhaISomenteleitura1(arq, 2));*/
578 /*printf("\n\n\n\narquivos0 e arquivo1 arquivo2 respectivamente %s %s %s \n\n\n",getLinhaISomenteleitura1(arq, 0), getLinhaISomenteleitura1(arq, 1),getLinhaISomenteleitura1(arq, 2));*/
579 arq1=getLinhaISomenteleitura1(arq,0);
580 arq2=getLinhaISomenteleitura1(arq,1);
581 sprintf(ext, "pdftk %s %s cat output PDFTK921_%i.pdf ;", arq1, arq2, 0);
582 //printf("\n %s\n", ext);
583 strcat(out, ext);
584 k++;
585 sprintf(ext, "pdftk PDFTK921_%i.pdf %s cat output PDFTK921_%i.pdf ;", k-1,getLinhaISomenteleitura1(arq, 2), k);
586 strcat(out, ext);
587 //printf("\n %s\n\n ", ext);
588 k++;
589 sprintf(ext, "pdftk PDFTK921_%i.pdf %s cat output PDFTK921_%i.pdf ;", k-1,getLinhaISomenteleitura1(arq, 3), k);
590 strcat(out, ext);
591 //printf("\n %s\n\n ", ext);
592 k++;
593 for(i=4; i<l; i++)
594 {
595 sprintf(ext, "pdftk PDFTK921_%i.pdf %s cat output PDFTK921_%i.pdf ;", k-1,getLinhaISomenteleitura1(arq, i), k);
596 strcat(out, ext);
597 //printf("\n\n %s\n\n ", ext);
598 k++;
599 }
600 //printf("\n out= %s\n", out);
601 --k;
602 for(--k;k>=0;k--)
603 {
604 sprintf(ext, "rm pdftk PDFTK921_%i.pdf ; ", k);
605 strcat(out, ext);
606 // printf("\n\n %s\n\n ", ext);
607 }
608 strcat(out, " ls -la ");
609 //printf("\n out = %s\n", out);
610 return out;
611 }
612 /*=============================================================*/
613 /*=============================================================*/
614 /*=============================================================*/
615 /*=============================================================*/
616 /*=============================================================*/
617 /*=============================================================*/
618 /*=============================================================*/
619 /*=============================================================*/
620
621 char *gettextoarq1Somenteleitura( char *arq, char *texto)
622 {
623 int fd, buf_size;
624 char buf[500],buf2[10000], *buf3;
625
626 buf_size=499;
627 fd=open1(arq,LEITURA);
628 printf("\n Agora entrarei na funcao buf3=gettextoarq(fd, buf,buf_size,buf2);\n");
629 buf3=gettextoarq(fd,buf, buf_size,buf2);
630 printf("\n Antes de entrar no If do texto \nO conteudo do arquivo %s e :\n %s \n", arq, buf3);
631 if(/**texto==NULL */strcmp(texto,NULL)==0)
632 {/* se estiver passando somente um * ponteiro sem nada , NULL*/
633 texto=buf3;
634 }
635 sprintf(texto,"%s", buf3);
636 //printf("\n Agora entrarei na funcao close(fd);\n");
637 close(fd);
638 //printf("\n O conteudo do arquivo %s e :\n %s \n", arq, buf3);
639 return buf3;
640 }
641 /*=============================================================*/
642 char *gettextoarq(int fd, char *buf, int buf_size, char *texto)
643 {
644 for(;;)
645 {
646 if(read(fd, buf,buf_size)==0)
647 {
648 sprintf(texto, "%s \n", buf);
649 return texto;
650 }
651 sprintf(texto, "%s \n", buf);
652 }
653 }
654
655 /*=============================================================*/
656
657 int open1(char *file, int oflag )
658 {
659 int fd;
660
661 if((fd=open(file,oflag))==-1)
662 {
663 printf("\n Nao e possivel abrir o arquivo %s \n", file);
664 return fd;
665 }
666 return fd;
667 }
668 /*=============================================================*/
669
670 char *substituiEspacoPor_(char *str)
671 {
672 return subs_str(str," ", "_");
673 }
674 /*=============================================================*/
675 char *subs_str(char *string, char *substring, char *nova)
676 {
677 char *extrai;
678 int tamanho1,tamanho2,contador, a4;
679
680 tamanho1 = strlen(substring);
681 tamanho2 = strlen(nova);
682 a4=strlen(string);
683 if((tamanho1 > tamanho2) || (tamanho2 > tamanho1))
684 return(" ");
685 else
686 {
687 extrai = strstr(string,substring);
688 if(extrai)
689 {
690 for(contador = 0;contador < a4; contador++)
691 string[(extrai - string) + contador] = nova[contador];
692 return(string);
693 }
694 else
695 return(" ");
696 }
697 }
698 /*=============================================================*/
699
700 void prog()
701 {
702 char cmd[400], arq[200], texto[600], **t1, ***t6, *t7, *t10, *t8, tr[200];
703 int i;
704
705 strcpy(tr,"O joao e bacana pra caramba");
706 t7=NULL,t8=NULL;
707 sprintf(arq, "%s","arqpdf.txt");
708 //sprintf(stdout,"%s", "imprimindo na tela, stdout com sprintf");
709 /* printf("************************************");
710 printf("\n\n a string %s sem espacos e : %s \n\n", tr, substituiEspacoPor_(tr));*/

711 printf("************************************");
712 printf("\n Programa que concatenara todos os arquivos .pdf em um \n\n\n ");
713 printf(" Para esse programa funcionar direito e Necessario que: \n ");
714 mostraRespricoes();
715 sprintf(cmd, "for x in *.pdf; do echo %s ", "\"$x\"; done > arqpdf.txt");
716 system(cmd);
717 printf(" \n cmd:\n %s \n ", cmd);
718 t10=strpdftk(arq);
719 printf(" \n cmd:\n %s \n ", t10);
720 system(t10);
721 printf("\n\n");
722 }
723
724 /*=============================================================*/
725 int main()
726
727 {
728 prog();
729 return 1;
730 }










sábado, 6 de setembro de 2008

Juntando vários arquivos .pdf em um só com o auxílio de um código em lLPO C e a ferramenta pdftk

Para mais informações sobre o pdftk, de uma buscada na internet
O programa converte todos os arquivos .pdf da pasta com excessão aqueles com espacos no nome, por exemplo "exemplo 1.pdf"
Copie oo código c e salve como 1.c
Complile, cc 1.c -o 1 e execute com ./1
Pronto basta procurar o arquivo PDFTK ...
Ai vai o código:
Eu ia colocar em c mas como nao da pra colocar vai em xml









#include <stdlib.h>


#include <stdio.h>


#include <string.h>


#define LEITURA 0


#define ESCRITA 1


#define LEITURAESCRITA
2


#define TAMNOME 500


/*===================================================================*/


/*===================================================================*/


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
*arq, int j);


char
*getLinhaISomenteleitura(char *arq, int *j, char *linha, int I);


char
*gettextoarq1Somenteleitura1( char *arq);


char
*getLinhaISomenteleitura1(char *arq, int I);


int
getNumeroLinhaString(char *str);


int contachar(char
string[], char letra);


void mostraLinhas1(char
*arq);


int
getNumeroLinhaStringArquivo(char *arq);


char *strpdftk(char
*arq);


void limpaStr(char
*Str);


char
**getvetorLinhasArg(char *arq);


void mostraLinhas2(char
*arq);


char
**getvetorLinhasArg1(char *arq);


char
**getvetorLinhasArg1(char *arq);


void mostraLinhas3(char
*arq);


int
getimaiorStringemArq(char *arq);


int
get_Strlen_da_maior_String_em_Arq(char *arq);


char
***alocar_vetor_string_arq(char *arq);


char
***get_vetor_string_arq(char *arq);


void mostraLinhas4(char
*arq);


char
***alocar_vetor_string_arq(char *arq);


char
substituiEspacoPor_(char *str);


char *subs_str(char
*string, char *substring, char *nova);


/*===================================================================*/


/*===================================================================*/


/*===================================================================*/


char
***get_vetor_string_arq(char *arq)


{


int l, i, j, k, m, n,
o, num_linhas;


char ***vet1, **vet;


vet1=NULL; vet=NULL;


vet1=alocar_vetor_string_arq(arq);


vet=*vet1;/* tenho o
vetor de strings alocadinha basta preenchê-lo*/


num_linhas=getNumeroLinhaStringArquivo(arq);


for(i=0;
i<num_linhas; i++)


{


sprintf(vet[i] ,
"%s", getLinhaISomenteleitura1(arq, i) );


}


return vet1;



}


/*===================================================================*/


/*===================================================================*/





void mostraLinhas4(char
*arq)


{


int l, i, nl;


char **vet, ***vet1;


vet=NULL; vet1=NULL;


vet1=get_vetor_string_arq(arq);


vet=*vet1;


nl=getNumeroLinhaStringArquivo(arq);


for(i=0; i <
nl;i++)


{


printf("\n
vet[%i]: %s", i, vet[i]);


}



printf("\n\n
************************************\n\n");



}


/*===================================================================*/


void mostraLinhas3(char
*arq)


{


int l, i;


char **vet;


vet=NULL;


vet=getvetorLinhasArg1(arq);



if(vet==NULL){printf("\n Deu problema no mostra linha3 ver e
nulo !\n");}


//t8=getLinhaISomenteleitura1(arq,
9);


/*printf("\n
Passemos a i=getNumeroLinhaStringArquivo(arq);\n");*/


i=getNumeroLinhaStringArquivo(arq);


//printf("
********* Mostrando as %i linhas do arquivo %s ****\n\n", i,
arq);


printf("Linhas(vet)[
%i ]{%i}: %s \n", 0, strlen(vet[0]), vet[0]);


printf("Linhas(vet)[
%i ]{%i}: %s \n", 1, strlen(vet[1]), vet[1]);


/*


for(l=0; l < i;
l++)


{


printf("Linhas(vet)[
%i ]{%i}: %s \n", l, strlen(vet[l]), vet[l]);


}*/


printf("\n\n
************************************\n\n");



}


/*===================================================================*/


/*===================================================================*/


void mostraLinhas2(char
*arq)


{


int l, i;


char **vet;



vet=getvetorLinhasArg(arq);



//t8=getLinhaISomenteleitura1(arq,
9);



i=getNumeroLinhaStringArquivo(arq);


//printf("
********* Mostrando as %i linhas do arquivo %s ****\n\n", i,
arq);



for(l=0; l < i;
l++)


{


printf("Linhas(vet)[
%i ]{%i}: %s \n", l, strlen(vet[i]), vet[i]);


}


printf("\n\n
************************************\n\n");



}


/*===================================================================*/


int
get_Strlen_da_maior_String_em_Arq(char *arq)


{


int l, i, k, la, bb,
maior, idomaior;


char **vet,
str[TAMNOME];


k=0;maior=0;


for(i=0;
i<getNumeroLinhaStringArquivo(arq);i++)


{


k =
strlen(getLinhaISomenteleitura1(arq, i));


if(k>=maior){maior=k;idomaior=i;}


}


return maior;


}


/*===================================================================*/


char
***alocar_vetor_string_arq(char *arq)


{


int tam1, tam2, i,
j;


char **vetor;


tam2 =
get_Strlen_da_maior_String_em_Arq(arq);


tam2=tam2*sizeof(char);


tam1=getNumeroLinhaStringArquivo(arq);


if((vetor=(char**)malloc(tam1*sizeof(char*)))==NULL)


{


printf("\n Nao
foi possivel alocar as linhas do de vetor de strings para do arquivo
\n");


return NULL;


}


for(i=0;
i<tam1;i++)


{


if((vetor[i]=(char*)malloc(tam2))==NULL)


{


printf("\n
Nao foi possivel alocar as colunas do vetor de strings para do
arquivo \n");


for(--i;i>=0;i--)


{


free(vetor[i]);


}


free(vetor);


return NULL;


}


}


return &vetor;








}


/*===================================================================*/


int
getimaiorStringemArq(char *arq)


{


int l, i, k, la, bb,
maior, idomaior;


char **vet,
str[TAMNOME];


k=0;maior=0;


for(i=0;
i<getNumeroLinhaStringArquivo(arq);i++)


{


k =
strlen(getLinhaISomenteleitura1(arq, i));


if(k>=maior){maior=k;idomaior=i;}


}


return idomaior;


}


/*===================================================================*/char
**getvetorLinhasArg1(char *arq)


{


int l, i, k, la, bb;


char **vet,
str[TAMNOME];


/* o probela e alocar
o vetor para armazenar*/



i=getNumeroLinhaStringArquivo(arq);


vet=(char**)malloc(i*sizeof(char*));


if(vet==NULL){printf("\n
Nao foi possivel alocar as linhas do vetor de linhas \n");
return NULL;}





for(la=0; la < i;
la++)


{


strcpy(str
,getLinhaISomenteleitura1(arq, la));


k = strlen(str);


/*printf("\n k
= strlen(str);: %i\n st: %s\n", k, str);*/


vet[la]=(char*)malloc(k*sizeof(char));if(vet[la]==NULL){printf("\n
Nao foi possivel alocar as colunas do vetor de linhas \n");
free(vet);return NULL;}



sprintf(vet[la],
"%s", str);


for(bb=0; bb<=la;
bb++)


printf("%s \n
", vet[bb]);


//strcpy(vet[l],
str);


// if((l%2)!=0){


//printf("
%i%%3=%i\nLinhas(vet[%i])[ %i ]: %s \n str : %s \n\n",l, l%3, l,
l, vet[l], str);


//}



}


//printf("
vet[1-4]: %s %S %s %S \n\n", vet[0], vet[1], vet[2], vet[4]);


printf(" Agora vem
a montagem do vetor vet : %s \n\n", vet);


/* for(la=0; la <
i; la++)


{



printf("\n
vet[%i]: %s\n ", la, vet[la]);



}*/


return vet;




}


/*===================================================================*/





void mostraLinhas1(char
*arq)


{


int l, i;






//t8=getLinhaISomenteleitura1(arq,
9);



i=getNumeroLinhaStringArquivo(arq);


printf("
Mostrando as %i linhas do arquivo \n\n", i);



for(l=0; l < i;
l++)


{


printf("Linhas[
%i ]: %s \n", l, getLinhaISomenteleitura1(arq, l));



}


printf("\n\n
************************************\n\n");



}


/*===================================================================*/


char
**getvetorLinhasArg(char *arq)


{


int l, i, k;


char **vet, *str;


l=getNumeroLinhaStringArquivo(arq);


//printf("
Mostrando as %i linhas do arquivo \n\n", l);


vet=(char**)malloc(l*sizeof(char));


if(vet==NULL){printf("\n
Nao foi possivel alocar as linhas do vetor de linhas \n");
return NULL;}


for(i=0; i < l;
i++)


{


strcpy(str
,getLinhaISomenteleitura1(arq, i));


k = strlen(str);


vet[i]=(char*)malloc(k*sizeof(char));


if(vet[i]==NULL){printf("\n
Nao foi possivel alocar as colunas do vetor de linhas \n");
return NULL;}


strcpy(vet[i] ,
str);


printf("vet[ %i
]: %s \n", l, vet[i]);



}


//printf("\n\n
************************************\n\n");




return vet;


}


/*===================================================================*/


/*===================================================================*/


void mostraLinhas(char
*arq, int j)


{


int l;



//t8=getLinhaISomenteleitura1(arq,
9);




printf("\n\n
Mostrando as %i linhas do arquivo \n\n", j);



for(l=0; l < j;
l++)


{


printf("Linhas[
%i ]: %s \n", l, getLinhaISomenteleitura1(arq, l));



}


printf("\n\n
************************************\n\n");


printf(" %s \n O
Arquivo tem %i linhas", gettextoarq1Somenteleitura1(arq),
getNumeroLinhaString(gettextoarq1Somenteleitura1(arq)));/**//**/


printf("\n\n
************************************\n\n");


}


/*===================================================================*/


void mostraRespricoes()


{




printf(" 1 - O
arquivo arqpdf.txt tem que estar no mesmo diretorio \n ");


printf(" 2 - Os
arquivos a serem convertidos devem estar no mesmo diretorio \n");


printf(" 3 - O
arquivo gerado tera o nome de \'PDFTK921_ ...pdf\'\n");


printf(" 4 - Os
nomes dos arquivos a serem unidos nao podem possuir espacoe em
branco, pelo menos por enquanto\n");



}


/*===================================================================*/


/*===================================================================*/


int contachar(char
string[], char letra)


{


int contador,
tamanho, ocorrencia = 0;


tamanho =
strlen(string);



for(contador=1;contador <= tamanho;contador++)



if(string[contador] == letra)


ocorrencia++;


return(ocorrencia);


}


/*===================================================================*/


int
getNumeroLinhaString(char *str)


{


/*onde str é a
string com várias linhas*/


return
contachar(str, '\n');



}


/*===================================================================*/


int
getNumeroLinhaStringArquivo(char *arq)


{


/*onde str é a
string com várias linhas*/


int i;


char *s1;


s1=gettextoarq1Somenteleitura1(arq);


i=getNumeroLinhaString(s1);


i=i-1;


return i;


}





/*===================================================================*/





/* fazer uma função
que retorne somente a string da linha,


* deve-se passar a
linha e um ponteiro onde string estara*/


char
*getLinhaISomenteleitura1(char *arq, int I)


{


int i;


char text[10000],
*t1, *t2, charater[500], *ta1;



t1=gettextoarq1Somenteleitura1(arq);


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*/


//res = strtok(s,
delim);


t2=strtok(text,
"\n");


//sprintf(texto[0],
"%s", t2);


//printf(" \n
O conteudo da variaveis text (antes de retornar a linha) e %s \n Ja o
conteudo de t2 e %s \n \n", text, t2);



if(I==0)


{



return t2;


}


for(i=1;(i<=I)&&
(t2 != NULL); i++)


{ //res =
strtok(NULL, delim);


t2=strtok(NULL,
"\n");


sprintf(charater,
"%s", t2);


//printf("
\n O conteudo do arquivo na linha %i e %s \n Ja o conteudo de t2 e
%s \n Ja o conteudo de charater e %s \n", i, text, t2,
charater);



if(i==I)


{ strcpy(ta1,
charater);


return t2;


}


if(t2==NULL)


{


printf("
\n A linha pedida para a funcao e maior que a quanidade de linhas no
arquivo! \n Entre com um valor de linha menor que o numero de linhas
do arquivo!\n ");



return NULL;


}




}


if(i==I)


{


strcpy(ta1,
charater);


return t2;


}


return NULL;


}





/*===================================================================*/


void limpaStr(char
*Str)


{


int i, j;



i=strlen(Str);


for(j=i-1;j>=0;j--)


{


/*Str[j]=NULL*/;strcpy((*(Str+j)),"
");


}


}


/*===================================================================*/


/* 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=gettextoarq1Somenteleitura1(arq);


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 */strcmp(linha,NULL)==0)


{/* 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 */strcmp(linha,NULL)==0)


{/* 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 */strcmp(linha,NULL)==0)


{/* 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], **texto5;


t1=gettextoarq1Somenteleitura(arq,
t1);


printf("\n
entrou em char ***getLinhasSomenteleitura(char *arq, int *j, char
***texto4) \n gettextoarq1Somenteleitura(arq, t1); = %s \n ",
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];


*texto4= =
strdup(texto[0]);*/


// strcpy(texto5,
texto);


*texto4=texto5;


return texto4;



}



}


/*
*texto4=&texto[0][0];


*texto4= =
strdup(texto[0]);*/


// strcpy(texto5,
texto);


*texto4=texto5;


// return
&texto5;


return texto4;


}


/*===================================================================*/


char
*gettextoarq1Somenteleitura1( char *arq)


{



int fd, buf_size;


char buf[500],
buf2[10000], *buf3;


buf_size=499;


fd=open1(arq,
LEITURA);


buf3=gettextoarq(fd,
buf, buf_size,buf2);


close(fd);


return buf3;



}


/*===================================================================*/


/*===================================================================*/


/*===================================================================*/


/*===================================================================*/


/*===================================================================*/





char *strpdftk(char
*arq)


{


int i, j, k, l, m, n,
n1;


char *arq1, *arq2,
*arqout, *out, *ext, *meio;


l=getNumeroLinhaStringArquivo(arq);



n1=strlen("pdftk
");


n1=n1+800;


out=(char*)malloc(n1*sizeof(char));


arq1=(char*)malloc((n1-120)*sizeof(char));


arq2=(char*)malloc((n1-120)*sizeof(char));


ext=(char*)malloc((n1-500)*sizeof(char));


k=0;


i=0;


m=1;


//printf("\n
String0: %s\n", out);


//limpaStr(out);


//printf("\n
String1depois: %s\n", out);


/*printf("\n\n\n\n
getLinhaISomenteleitura1(arq, 2) : %s \n\n\n",
getLinhaISomenteleitura1(arq, 2));*/


/*


printf("\n\n\n\n
arquivos0 e arquivo1 arquivo2 respectivamente %s %s %s \n\n\n",
getLinhaISomenteleitura1(arq, 0), getLinhaISomenteleitura1(arq, 1),
getLinhaISomenteleitura1(arq, 2));*/


arq1=getLinhaISomenteleitura1(arq,
0);


arq2=getLinhaISomenteleitura1(arq,
1);


sprintf(ext, "
pdftk %s %s cat output PDFTK921_%i.pdf ;", arq1, arq2, 0);


//printf("\n %s
\n", ext);


strcat(out, ext);


k++;


sprintf(ext, "
pdftk PDFTK921_%i.pdf %s cat output PDFTK921_%i.pdf ;", k-1,
getLinhaISomenteleitura1(arq, 2), k);


strcat(out, ext);


//printf("\n
%s\n\n ", ext);


k++;


sprintf(ext, "
pdftk PDFTK921_%i.pdf %s cat output PDFTK921_%i.pdf ;", k-1,
getLinhaISomenteleitura1(arq, 3), k);


strcat(out, ext);


//printf("\n
%s\n\n ", ext);


k++;


for(i=4; i<l; i++)


{



sprintf(ext, "
pdftk PDFTK921_%i.pdf %s cat output PDFTK921_%i.pdf ;", k-1,
getLinhaISomenteleitura1(arq, i), k);


strcat(out, ext);


//printf("\n
\n %s\n\n ", ext);


k++;




}


//printf("\n out
= %s\n", out);


--k;


for(--k;k>=0;k--)


{


sprintf(ext, "
rm pdftk PDFTK921_%i.pdf ; ", k);


strcat(out, ext);


// printf("\n
\n %s\n\n ", ext);


}


strcat(out, " ls
-la ");


//printf("\n out
= %s\n", out);


return out;


}


/*===================================================================*/


/*===================================================================*/


/*===================================================================*/


/*===================================================================*/


/*===================================================================*/


/*===================================================================*/


/*===================================================================*/


/*===================================================================*/





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);


printf("\n
Antes de entrar no If do texto \nO conteudo do arquivo %s e :\n %s
\n", arq, buf3);


if(/*
*texto==NULL */strcmp(texto,NULL)==0)


{/* 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;


}
/*===================================================================*/


char
substituiEspacoPor_(char *str)


{


return subs_str(str,
" ", "_");


}



/*===================================================================*/


char *subs_str(char
*string, char *substring, char *nova)


{


char *extrai;


int
tamanho1,tamanho2,contador, a4;





tamanho1 =
strlen(substring);


tamanho2 =
strlen(nova);


a4=strlen(string);





if((tamanho1 >
tamanho2) || (tamanho2 > tamanho1))


return(" ");


else


{


extrai =
strstr(string,substring);





if(extrai)


{



for(contador = 0;contador < a4; contador++)



string[(extrai - string) + contador] = nova[contador];



return(string);


}


else


return("
");


}


}



/*===================================================================*/


void prog()


{


char cmd[400],
arq[200], texto[600], **t1, ***t6, *t7, *t10, *t8, tr[200];


int i;


strcpy(tr,"O
joao e bacana pra caramba");


t7=NULL,t8=NULL;


sprintf(arq, "%s",
"arqpdf.txt");


//sprintf(stdout
,"%s", "imprimindo na tela, stdout com sprintf");


/*
printf("************************************");


printf("\n\n a
string %s sem espacos e : %s \n\n", tr,
substituiEspacoPor_(tr));*/


printf("************************************");


printf("\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
cmd:\n %s \n ", cmd);



t10=strpdftk(arq);


printf(" \n
cmd:\n %s \n ", t10);


system(t10);



printf("
\n\n");


}


/*===================================================================*/


int main()


{


prog();



return ;


}


/*===================================================================*/





/*





*


* ordem das chamadas
de funções que estão me
dando dor de cabeça:


*


* prog();
==>>getLinhaISomenteleitura(arq, &i, t7, 3); ==>>
gettextoarq1Somenteleitura1(arq); ==>> ==>> ==>>
==>> ==>> ==>> ==>> ==>> ==>>
==>>


*


* -> prog();
==>>mostraLinhas(arq, 10); ==>>getLinhaISomenteleitura1(arq,
3); ==>> t1=gettextoarq1Somenteleitura1(arq); ==>> ==>>
==>> ==>> ==>> ==>> ==>> ==>>
==>> ==>>




-> prog();
==>>mostraRespricoes() ==>>[mostraLinhas4(arq);==>>
(vet1=get_vetor_string_arq(arq);==>>)==>>nl=getNumeroLinhaStringArquivo(arq);==>>]==>>
==>> ==>> ==>> ==>> ==>> ==>>
==>> ==>> ==>>








* */

quarta-feira, 3 de setembro de 2008

Link q mostra como instalar a interface gráfica no debian GNU/Linux 40.0 Etch cd oficial i 386 Biário-1

A instalação do Debian é bem tranquila, para instalar a interface gráfica, basta seguir as informações do link: http://wiki.forumdebian.com.br/index.php/Instalando_um_Ambiente_Gr%C3%A1fico_no_Debian

Se desejar ver a documentação do Debian em Português acesse:

http://wiki.forumdebian.com.br/index.php/P%C3%A1gina_principalhttp://wiki.forumdebian.com.br/index.php/P%C3%A1gina_principal

sexta-feira, 29 de agosto de 2008

Usando o pdftk, como converter 2 .pdf em 1

Apenas espelhando o site www.vivaolinux.com.br/dica/Manipulando-arquivos-PDF-com-pdftk/
É que esqueci como coverter 2 .pdf para 1

O download desta ferramenta está disponível em .tar.gz e .tar.bz2 no link:

* http://www.accesspdf.com

Concluído o download, deve-se fazer a descompactação do mesmo:

$ tar -zxvf pdftk-1.12.tar.gz
ou
$ tar -jxvf pdftk-1.12.tar.bz2

Agora entre no diretório criado e em seguida no sub-diretório pdftk:

$ cd pdftk-1.12/pdftk

Dependendo de sua distribuição, execute o comando make 'arquivo', onde 'arquivo' corresponde à sua distribuição. Exemplos:

* Debian: make Makefile.Debian
* Mandrake: make Makefile.Mandrake
* RedHat: make Makefile.RedHat
* Outros: make Makefile.Generic


Terminado o processo de instalação, o arquivo "pdftk-1.12/pdftk/pdftk" já estará criado e poderá ser utilizado.

Dicas de utilização

Concatenando dois arquivos em um:

$ pdftk Arquivo1.pdf Arquivo2.pdf cat output Concatenado1e2.pdf

Dividindo arquivos:

$ pdftk Arquivo.pdf burst

* Desta forma cada página do arquivo será separada em um arquivo independente e nomeados como pg_0001.pdf, pg_0002.pdf e assim por diante.

Selecionando páginas a serem separadas:

$ pdftk Arquivo.pdf cat 1-5 10-12 output PaginasSelecionadas.pdf

* O arquivo PaginasSelecionadas.pdf será criado com as páginas de 1 a 5 e de 10 a 12 do arquivo Arquivo.pdf.

Pode-se remover uma determinada página repetindo o comando anterior alterando apenas os parâmetros. Por exemplo, remover a página 5 de um arquivo:

$ pdftk Arquivo.pdf cat 1-4 6-end output NovoArquivo.pdf

Você pode também criar um relatório com os metadados e "jogá-los" em um .txt:

$ pdftk Arquivo.pdf dump_data output relatorio.txt

Maiores informações podem ser obtidas no manual no pdftk em pdftk-1.12/pdftk.1.txt.

Fontes:

* http://applications.linux.com/applications/06/04/17/1943230.shtml?tid=47
* http://www.accesspdf.com/article.php/20041129180128366

E manual do pdftk:

$ less ./pdftk-1.12/pdftk.1.txt