Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
be_xml.c
Go to the documentation of this file.
1
2//not complete...works only for simple read and write XML process, more code need to
3//be added when possible
4
5 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
6 * *
7 * Licensa de Cópia (C) <2021> <Corporação do Trabalho Binário> *
8 * *
9 * Este programa é software livre: você pode redistribuir isto e/ou *
10 * modificar isto sobre os termos do GNU Licensa Geral Pública como 8
11 * publicado pela Fundação de Software Livre, tanto a versão 3 da *
12 * Licensa, ou (dependendo da sua opção) qualquer versão posterior. *
13 * *
14 * Este programa é distribuído na esperança que isto vai ser útil, *
15 * mas SEM QUALQUER GARANTIA; sem até mesmo a implicada garantia de *
16 * COMERCIALIZAÇÃO ou CABIMENTO PARA UM FIM PARTICULAR. Veja a *
17 * Licensa Geral Pública para mais detalhes. *
18 * *
19 * Você deve ter recebido uma cópia da LICENSA GERAL PUBLICA e a GNU *
20 * Licensa Pública Menor junto com este programa *
21 * Se não, veja <http://www.gnu.org/licenses/>. *
22 * *
23 * Suporte: https://nomade.sourceforge.io/ *
24 * *
25 * E-mails direto dos felizes programadores: *
26 * O Ricardinho : arsoftware25@gmail.com ricardo@arsoftware.net.br *
27 * Little_Amanda: arsoftware10@gmail.com amanda.@arsoftware.net.br *
28 * *
29 * contato imediato(para uma resposta muita rápida) WhatsApp *
30 * (+55)41 9627 1708 - isto está sempre ligado (eu acho...) *
31 * *
32 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
33
34#include /* amanda's smart ape */ <windows.h>
35#include /* amanda's smart ape */ <stdint.h>
36#include /* amanda's smart ape */ <stdio.h>
37#include /* amanda's smart ape */ <stdlib.h>
38#include /* amanda's smart ape */ <string.h>
39#include /* amanda's smart ape */ <time.h>
40#include /* amanda's smart ape */ <errno.h>
41#include /* amanda's smart ape */ <fcntl.h>
42#include /* amanda's smart ape */ <ctype.h>
43#include /* amanda's smart ape */ <math.h>
44#include /* amanda's smart ape */ <wctype.h>
45#include /* amanda's smart ape */ <wchar.h>
46#include /* amanda's smart ape */ <stdarg.h>
47#include /* amanda's smart ape */ <stddef.h>
48#include /* amanda's smart ape */ <setjmp.h>
49#include /* amanda's smart ape */ <locale.h>
50#include /* amanda's smart ape */ <signal.h>
51#include /* amanda's smart ape */ <limits.h>
52#include /* amanda's smart ape */ <float.h>
53#include /* amanda's smart ape */ <iso646.h>
54
55#undef NDEBUG
56#include /* amanda's smart ape */ <assert.h>
57#include /* amanda's smart ape */ <stdbool.h>
58#include /* amanda's smart ape */ <process.h>
59
60wchar_t *
61permissive_name_m_(const wchar_t *wname);
62
73WCHAR *amanda_utf8towide_3_(char *pUTF8);
74
90int feline_read_xml(char *filename_utf8_feline,
91 char *root__________feline,
92 char *node__________feline,
93 char *attribute_____feline,
94 char *out_data______feline);
95
114int feline_write_xml(char *filename_utf8_feline,
115 char *root__________feline,
116 char *node__________feline,
117 char *attribute_____feline,
118 char *in_data_______feline_);
119
128
134
135static int write_mode_feline = FELINE_MODE_NORMAL;
136
137void pedro_dprintf(
138 int amanda_level,
139 char *format, ...);
140
141#define Z_DEBUG
142
143static int lines_count_feline;
144static int valid_position_feline;
145static int root_position_feline;
146static int item_position_feline;
147
148enum
149{
152};
153
154static int
155replace_or_count_stringsensitive_arab(int mode, char *data, int datalen,
156 char *search_string,
157 int search_string_len, char *replace,
158 int replace_len, int *count,
159 char **output_string, int *output_len)
160{
161 int q;
162 char *final = ((void *)0);
163 int ret;
164 int sizeret;
165 int deslocador = 0;
166 int len = datalen;
167 int size__ = 0;
168 double a;
169 double adest;
170 double asrc;
171 int i;
172 int p;
173 *output_len = 0;
174 if (count)
175 {
176 *count = 0;
177 }
178 adest = (double)replace_len;
179 if (0 == search_string_len)
180 {
181 asrc = (double)1;
182 }
183 else
184 {
185 asrc = (double)search_string_len;
186 }
187 a = adest / asrc;
188 size__ = (int)ceil(a);
189 size__++;
190 if (MODE_IS_REPLACE__ == mode)
191 {
192 final = calloc((len * size__) + 10000, 1); //it had a bug here for 20 years...
193 *output_string = final;
194 if (NULL == final)
195 {
196 return -1;
197 }
198 }
199
200 ret = len;
201 sizeret = search_string_len;
202
203 if (sizeret > ret)
204 {
205 if (MODE_IS_REPLACE__ == mode)
206 {
207
208 memcpy(*output_string, data, datalen);
209 (*output_string)[datalen] = 0;
210 *output_len = datalen;
211 }
212 return 0;
213 }
214
215 for (i = 0; i < datalen; i++)
216 {
217 if (data[i] == search_string[0])
218 {
219 {
220 int deslocasize = i;
221
222 for (p = 0; p < search_string_len; p++)
223 {
224 if (datalen <= deslocasize)
225 {
226 goto naoachou;
227 }
228 if (data[deslocasize++] != search_string[p])
229 {
230 goto naoachou;
231 }
232 }
233
234 for (q = 0; q < replace_len; q++)
235 {
236 final[deslocador++] = replace[q];
237 }
238 i += search_string_len - 1;
239 goto vai;
240 naoachou:;
241 }
242 final[deslocador++] = data[i];
243 }
244 else
245 {
246 final[deslocador++] = data[i];
247 }
248 vai:;
249 }
250 final[deslocador] = 0;
251 *output_len = deslocador;
252 ;
253 return 0;
254}
255static int stringreplace(char *data, int data_len, char *search,
256 int searchlen,
257 char *replace,
258 int replacelen,
259 int *out_len, char **outdata)
260{
261 int ret;
262 int count;
263 ret = replace_or_count_stringsensitive_arab(MODE_IS_REPLACE__,
264 data,
265 data_len, search,
266 searchlen, replace, replacelen, &count,
267 outdata, out_len);
268 return ret;
269}
270
271static int decode_data_feline(char *inputdata_feline, char *data_feline)
272{
273 int out_len2 = 0;
274 char *outdata2 = NULL;
275 char *outdata3 = NULL;
276 char *outdata4 = NULL;
277 char *outdata5 = NULL;
278 char *outdata_a_feline = NULL;
279 char *outdata_b_feline = NULL;
280 char search[300];
281 char replace[300];
282 int returnvalue = 0;
283
284 strcpy(search, "&gt;");
285 strcpy(replace, ">");
286 stringreplace(inputdata_feline, strlen(inputdata_feline), search,
287 strlen(search),
288 replace,
289 strlen(replace),
290 &out_len2, &outdata_a_feline);
291 if (NULL == outdata_a_feline)
292 {
293 returnvalue = 1;
294 goto saida;
295 }
297 strcpy(search, "&lt;");
298 strcpy(replace, "<");
299 stringreplace(outdata_a_feline, strlen(outdata_a_feline), search,
300 strlen(search),
301 replace,
302 strlen(replace),
303 &out_len2, &outdata_b_feline);
304 if (NULL == outdata_b_feline)
305 {
306 returnvalue = 1;
307 goto saida;
308 }
310 strcpy(search, "&#13;");
311 strcpy(replace, "\r");
312 stringreplace(outdata_b_feline, strlen(outdata_b_feline), search,
313 strlen(search),
314 replace,
315 strlen(replace),
316 &out_len2, &outdata2);
317 if (NULL == outdata2)
318 {
319 returnvalue = 1;
320 goto saida;
321 }
323 strcpy(search, "&#10;");
324 strcpy(replace, "\n");
325 stringreplace(outdata2, out_len2, search,
326 strlen(search),
327 replace,
328 strlen(replace),
329 &out_len2, &outdata3);
330 if (NULL == outdata3)
331 {
332 returnvalue = 1;
333 goto saida;
334 }
336 strcpy(search, "&#0;");
337 replace[0] = 0;
338 stringreplace(outdata3, out_len2, search,
339 strlen(search),
340 replace,
341 1,
342 &out_len2, &outdata4);
343 if (NULL == outdata4)
344 {
345 returnvalue = 1;
346 goto saida;
347 }
349 strcpy(search, "&amp;");
350 strcpy(replace, "&");
351 (void)stringreplace(outdata4, out_len2, search,
352 strlen(search),
353 replace,
354 strlen(replace),
355 &out_len2, &outdata5);
356 if (NULL == outdata5)
357 {
358 returnvalue = 1;
359 goto saida;
360 }
362
363 strcpy(data_feline, outdata5);
364
365saida:;
366 if (outdata_a_feline)
367 {
368 free(outdata_a_feline);
369 }
370 if (outdata_b_feline)
371 {
372 free(outdata_b_feline);
373 }
374 if (outdata2)
375 free(outdata2);
376 if (outdata3)
377 free(outdata3);
378 if (outdata4)
379 free(outdata4);
380 if (outdata5)
381 free(outdata5);
382 return returnvalue;
383}
384
385static int encode_data_feline(char *input_data_feline, char *output_data_feline)
386{
387 int out_len = 0;
388 char *outdata = NULL;
389 char *outdata2 = NULL;
390 char *outdata3 = NULL;
391 char *outdata4 = NULL;
392 char *outdata_a_feline = NULL, *outdata_b_feline = NULL;
393 char search[300];
394 char replace[300];
395 int returnvalue = 0;
397 strcpy(search, "&");
398 strcpy(replace, "&amp;");
399 stringreplace(input_data_feline,
400 strlen(input_data_feline), search,
401 strlen(search),
402 replace,
403 strlen(replace),
404 &out_len, &outdata);
405 if (NULL == outdata)
406 {
407 returnvalue = 1;
408 goto saida;
409 }
411 search[0] = 0;
412 strcpy(replace, "&#0;");
413 stringreplace(outdata, out_len, search,
414 1,
415 replace,
416 strlen(replace),
417 &out_len, &outdata2);
418 if (NULL == outdata2)
419 {
420 returnvalue = 1;
421 goto saida;
422 }
424 search[0] = '\n';
425 strcpy(replace, "&#10;");
426 stringreplace(outdata2, out_len, search,
427 strlen(search),
428 replace,
429 strlen(replace),
430 &out_len, &outdata3);
431 if (NULL == outdata3)
432 {
433 returnvalue = 1;
434 goto saida;
435 }
437 search[0] = '\r';
438 strcpy(replace, "&#13;");
439 stringreplace(outdata3, out_len, search,
440 strlen(search),
441 replace,
442 strlen(replace),
443 &out_len, &outdata4);
444 if (NULL == outdata4)
445 {
446 returnvalue = 1;
447 goto saida;
448 }
450 search[0] = '>';
451 strcpy(replace, "&gt;");
452 stringreplace(outdata4, out_len, search,
453 strlen(search),
454 replace,
455 strlen(replace),
456 &out_len, &outdata_a_feline);
457 if (NULL == outdata_a_feline)
458 {
459 returnvalue = 1;
460 goto saida;
461 }
463 search[0] = '<';
464 strcpy(replace, "&lt;");
465 stringreplace(outdata_a_feline, out_len, search,
466 strlen(search),
467 replace,
468 strlen(replace),
469 &out_len, &outdata_b_feline);
470 if (NULL == outdata_b_feline)
471 {
472 returnvalue = 1;
473 goto saida;
474 }
476
477 strcpy(output_data_feline, outdata_b_feline);
478saida:;
479 if (outdata_a_feline)
480 {
481 free(outdata_a_feline);
482 }
483 if (outdata_b_feline)
484 {
485 free(outdata_b_feline);
486 }
487 if (outdata2)
488 free(outdata2);
489 if (outdata3)
490 free(outdata3);
491 if (outdata4)
492 free(outdata4);
493 return returnvalue;
494}
495
501static void amandaricardo_pereira_koci_string_replace(char *data_feline,
502 char *search_string_feline,
503 char *dest_string_feline)
504{
505 int g;
506 int p;
507 int i;
508 int size_of_dest = strlen(dest_string_feline);
509 int size_of_search = strlen(search_string_feline);
510 int size_of_data = strlen(data_feline);
511 int data_position = 0;
512 char *data_large;
513 double asrc;
514 double a;
515 int size__;
516 if (0 == size_of_search)
517 {
518 asrc = 1.;
519 }
520 else
521 {
522 asrc = (double)size_of_search;
523 }
524 a = size_of_dest / asrc;
525 size__ = (int)ceil(a);
526 data_large = calloc((size_of_data * size__) + 1 + 100000, 1); //possible bug here...amanda
527 for (i = 0; i < size_of_data; i++)
528 {
529 if (data_feline[i] == search_string_feline[0])
530 {
531 int desloca = i;
532 for (p = 0; p < size_of_search; p++)
533 {
534 if (0 == data_feline[desloca])
535 {
536 goto jump_inside;
537 }
538 if (data_feline[desloca++] != search_string_feline[p])
539 {
540 goto jump_inside;
541 }
542 }
543
544 for (g = 0; g < size_of_dest; g++)
545 {
546 data_large[data_position] = dest_string_feline[g];
547 data_position++;
548 }
549 i += size_of_search - 1;
550 }
551 else
552 {
553 jump_inside:;
554 data_large[data_position++] = data_feline[i];
555 }
556 }
557 data_large[data_position] = 0;
558 /*
559 if(100000<strlen(data_large))
560 {
561 printf("Erro 1015: Tamanho de entradas superior a 100000 bytes, terminando o programa, contate o programador e mande um printscreen");
562 exit(25);
563 }
564 */
565 strcpy(data_feline, data_large);
566 free(data_large);
567 return;
568}
569
570static int replacestringsensitive2_feline(char *comando, char *source, char *dest)
571{
572 amandaricardo_pereira_koci_string_replace(comando, source, dest);
573 return -27;
574}
575
576int __fastcall replacestringsensitive2_juliete(char *comando, char *source, char *dest)
577{
578 amandaricardo_pereira_koci_string_replace(comando, source, dest);
579 return -27;
580}
581
591#ifdef AMANDA_S_SMART_APE_ENABLE_WIDE_FUNCTION_
592
603WCHAR * amanda_utf8towide_1_(char *pUTF8)
604{
605 static WCHAR ricardo_k[1024];
606
607 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pUTF8, -1, ricardo_k, 1024);
608 return ricardo_k;
609}
610
611#endif
612
617static void removespace_begin_v27(char *path)
618{
619 int ret;
620 char *ptr;
621 char *ptrdesloca;
622 ptrdesloca = path;
623 ret = strlen(path);
624 if (ret)
625 {
626 ptr = malloc(ret + 1);
627 memset(ptr, 0, ret + 1);
628 while ((*ptrdesloca == ' ') || (*ptrdesloca == '\r') || (*ptrdesloca == '\n') || (*ptrdesloca == '\t'))
629 {
630 ptrdesloca++;
631 }
632 strcpy(ptr, ptrdesloca);
633 memset(path, 0, ret);
634 strcpy(path, ptr);
635 free(ptr);
636 }
637}
642/*
643static void removespace_end(char *path)
644{
645 int ret;
646inicio:
647 ret = strlen(path);
648 if (ret)
649 {
650 if ((path[(ret - 1)] == ' ') || (path[(ret - 1)] == '\r') || (path[(ret - 1)] == '\n') || (path[(ret - 1)] == '\t'))
651 {
652 path[(ret - 1)] = 0;
653 goto inicio;
654 }
655 }
656}
657*/
673int feline_read_xml(char *filename_utf8_feline,
674 char *root__________feline,
675 char *node__________feline,
676 __attribute__((unused)) char *attribute_____feline,
677 char *out_data______feline)
678{
679 char *node__________feline_copy_a;
680 char *node__________feline_copy_b;
681 char *root__________feline_copy_a;
682 bool already_feline = false;
683 bool is_valid_feline = false;
684 bool root_found_feline = false;
685 int xml_file_size_feline;
686 int returnvalue_feline = 0;
687 char *pointer_feline;
688 char *pointer_2_feline;
689 char *line_buf_feline;
690 FILE *my_file_feline;
691 FILE *compiler_happy_feline = NULL;
692
693 lines_count_feline = -1;
694 valid_position_feline = -1;
695 root_position_feline = -1;
696 item_position_feline = -1;
697
698 if (NULL != out_data______feline)
699 out_data______feline[0] = 0;
700
701 root__________feline_copy_a = calloc(1, strlen(root__________feline) + 3);
702
703 strcpy(root__________feline_copy_a, "<");
704 strcat(root__________feline_copy_a, root__________feline);
705 strcat(root__________feline_copy_a, ">");
706
707 node__________feline_copy_a = calloc(1, strlen(node__________feline) + 3);
708 node__________feline_copy_b = calloc(1, strlen(node__________feline) + 4);
709
710 strcpy(node__________feline_copy_a, "<");
711 strcat(node__________feline_copy_a, node__________feline);
712 strcat(node__________feline_copy_a, ">");
713 strcpy(node__________feline_copy_b, "</");
714 strcat(node__________feline_copy_b, node__________feline);
715 strcat(node__________feline_copy_b, ">");
716
717 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)), L"rb");
718
719 if (compiler_happy_feline == my_file_feline && compiler_happy_feline == my_file_feline) //as you can see the developer need to do things that can be embarassing
720 {
721 goto next_feline;
722 }
723
724next_feline:;
725
726 if (my_file_feline)
727 {
728 //mr. Do
729
730 fseek(my_file_feline, 0, SEEK_END);
731 xml_file_size_feline = ftell(my_file_feline);
732 fseek(my_file_feline, 0, SEEK_SET);
733
734 line_buf_feline = calloc(1, xml_file_size_feline + 1);
735
736 while (fgets(line_buf_feline, xml_file_size_feline, my_file_feline))
737 {
738
739 if (0 == ftell(my_file_feline))
740 {
741 break;
742 }
743
744 if (-1 == lines_count_feline)
745 {
746 lines_count_feline = 0;
747 }
748
749 lines_count_feline++;
750 replacestringsensitive2_feline(line_buf_feline, "\r", "");
751 replacestringsensitive2_feline(line_buf_feline, "\n", "");
752 if (strlen(line_buf_feline))
753 {
754 removespace_begin_v27(line_buf_feline);
755 if (false == is_valid_feline)
756 {
757 pointer_feline = strstr(line_buf_feline,
758 "<?xml version=\"1.0\"?>");
759 if (pointer_feline)
760 is_valid_feline = true, valid_position_feline = lines_count_feline;
761 }
762 else
763 {
764 if (false == root_found_feline)
765 {
766 pointer_feline = strstr(line_buf_feline,
767 root__________feline_copy_a);
768 if (pointer_feline)
769 root_found_feline = true, root_position_feline = lines_count_feline;
770 }
771 else
772 {
773 pointer_feline = strstr(line_buf_feline, node__________feline_copy_a);
774
775 if (pointer_feline && false == already_feline)
776 {
777 already_feline = true;
778
779 pointer_feline += strlen(node__________feline_copy_a);
780
781 pointer_2_feline = strstr(pointer_feline, node__________feline_copy_b);
782
783 if (pointer_2_feline)
784 {
785 pointer_2_feline[0] = 0;
786 }
787
788 if (NULL != out_data______feline)
789 strcpy(out_data______feline, pointer_feline);
790
791 item_position_feline = lines_count_feline;
792 }
793 }
794 }
795 }
796 }
797
798 free(line_buf_feline);
799
800 fclose(my_file_feline);
801 }
802 else
803 {
804 returnvalue_feline = 3;
805 }
806 free(root__________feline_copy_a);
807 free(node__________feline_copy_a);
808 free(node__________feline_copy_b);
809
810 if (3 == returnvalue_feline)
811 {
812 return 1; //Not a valid XML file
813 }
814
815 if (false == is_valid_feline)
816 {
817 return 1; //Not a valid XML file
818 }
819
820 if (false == root_found_feline)
821 {
822 return 2; //Root not found
823 }
824
825 if (NULL != out_data______feline)
826 {
827
828 decode_data_feline(out_data______feline, out_data______feline);
829 }
830
831 return 0; // Ok my love
832}
833
852int feline_write_xml(char *filename_utf8_feline,
853 char *root__________feline,
854 char *node__________feline,
855 __attribute__((unused)) char *attribute_____feline,
856 char *in_data_______feline_)
857{
858 bool did_arp = false;
859 int internal_mode_feline;
860 int returnvalue_feline = 0;
861 int ret_arp;
862 int xml_file_size_feline;
863 char signature_feline[] = "<?xml version=\"1.0\"?>\n";
864 char *line_buf_feline;
865 char *line_buf_2_feline;
866 char *in_data_______feline;
867 char adjusted_root_feline_a[1027];
868 char adjusted_root_feline_b[1027];
869 char adjusted_node_feline_a[1027];
870 char item_feline = 0;
871 bool add_amanda_is_my_love_n_in_ab = false;
872
873 FILE *my_file_feline;
874
875 in_data_______feline = calloc(1, 20000); //limited to 10000 per entry... if you want modify it
876 strncpy(in_data_______feline, in_data_______feline_, 9999);
877
878 encode_data_feline(in_data_______feline, in_data_______feline);
879
880 ret_arp = feline_read_xml(filename_utf8_feline, //nao muda mais, por favor
881 root__________feline,
882 node__________feline,
883 NULL /*for the moment*/,
884 NULL);
885
886 if (FELINE_MODE_DELETE_NODE == write_mode_feline)
887 {
888
889 if (-1 != valid_position_feline)
890 {
891
892 strcpy(adjusted_root_feline_a, "<");
893 strcat(adjusted_root_feline_a, root__________feline);
894 strcat(adjusted_root_feline_a, ">");
895
896 strcpy(adjusted_root_feline_b, "</");
897 strcat(adjusted_root_feline_b, root__________feline);
898 strcat(adjusted_root_feline_b, ">");
899
900 strcpy(adjusted_node_feline_a, "<");
901 strcat(adjusted_node_feline_a, node__________feline);
902 strcat(adjusted_node_feline_a, ">");
903
904 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)),
905 L"rb");
906 if (my_file_feline)
907 {
908 fseek(my_file_feline, 0, SEEK_END);
909 xml_file_size_feline = ftell(my_file_feline);
910
911 if (xml_file_size_feline)
912 {
913 fseek(my_file_feline, -1, SEEK_END);
914 fread(&item_feline, 1, 1, my_file_feline);
915 }
916
917 fseek(my_file_feline, 0, SEEK_SET);
918
919 line_buf_feline = calloc(1, xml_file_size_feline + 1);
920 line_buf_2_feline = calloc(1, xml_file_size_feline + (strlen(node__________feline) * 2) + 5 +
921 strlen(in_data_______feline) + 1000); //it is enough I supose, as usual...
922 lines_count_feline = 0;
923
924 internal_mode_feline = FELINE_MODE_INCLUDE_;
925
926 while (fgets(line_buf_feline, xml_file_size_feline, my_file_feline))
927 {
928 if (0 == ftell(my_file_feline))
929 {
930 break;
931 }
932 did_arp = true;
933 lines_count_feline++;
934
935 replacestringsensitive2_feline(line_buf_feline, "\r", "");
936 replacestringsensitive2_feline(line_buf_feline, "\n", "");
937
938 if (strstr(line_buf_feline, adjusted_root_feline_a))
939 {
940 internal_mode_feline = FELINE_MODE_EXCLUDE_;
941 }
942
943 if (FELINE_MODE_INCLUDE_ == internal_mode_feline)
944 {
945 strcat(line_buf_2_feline, line_buf_feline);
946 strcat(line_buf_2_feline, "\n");
947 }
948 else if (FELINE_MODE_EXCLUDE_ == internal_mode_feline)
949 {
950
951 if (strstr(line_buf_feline, adjusted_node_feline_a))
952 {
953 }
954 else
955 {
956 strcat(line_buf_2_feline, line_buf_feline);
957 strcat(line_buf_2_feline, "\n");
958 }; //FOR your pleasure...
959 }
960
961 if (strstr(line_buf_feline, adjusted_root_feline_b))
962 {
963 internal_mode_feline = FELINE_MODE_INCLUDE_;
964 }
965 }
966
967 if (did_arp)
968 {
969 line_buf_2_feline[strlen(line_buf_2_feline) - 1] = 0; //to remove last \n
970 }
971
972 if (10 == item_feline)
973 {
974 strcat(line_buf_2_feline, "\n");
975 }
976
977 if (NULL == line_buf_2_feline && NULL != line_buf_2_feline)
978 {
979 return 27;
980 }
981
982 fclose(my_file_feline);
983
984 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)),
985 L"wb");
986
987 if (my_file_feline)
988 {
989 fwrite(line_buf_2_feline, 1, strlen(line_buf_2_feline), my_file_feline);
990 fclose(my_file_feline);
991 my_file_feline = NULL;
992 }
993 free(line_buf_feline);
994 free(line_buf_2_feline);
995
996 goto saida_feline;
997 }
998 else
999 {
1000 returnvalue_feline = 1; //Cannot open xml file to write
1001 goto saida_feline;
1002 }
1003 }
1004
1005 goto saida_feline;
1006 }
1007
1008 if (FELINE_MODE_DELETE_ROOT == write_mode_feline)
1009 {
1010
1011 if (-1 != valid_position_feline)
1012 {
1013
1014 strcpy(adjusted_root_feline_a, "<");
1015 strcat(adjusted_root_feline_a, root__________feline);
1016 strcat(adjusted_root_feline_a, ">");
1017
1018 strcpy(adjusted_root_feline_b, "</");
1019 strcat(adjusted_root_feline_b, root__________feline);
1020 strcat(adjusted_root_feline_b, ">");
1021
1022 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)),
1023 L"rb");
1024 if (my_file_feline)
1025 {
1026 fseek(my_file_feline, 0, SEEK_END);
1027 xml_file_size_feline = ftell(my_file_feline);
1028
1029 if (xml_file_size_feline)
1030 {
1031 fseek(my_file_feline, -1, SEEK_END);
1032 fread(&item_feline, 1, 1, my_file_feline);
1033 }
1034
1035 fseek(my_file_feline, 0, SEEK_SET);
1036
1037 line_buf_feline = calloc(1, xml_file_size_feline + 1);
1038 line_buf_2_feline = calloc(1, xml_file_size_feline + (strlen(node__________feline) * 2) + 5 +
1039 strlen(in_data_______feline) + 1000); //it is enough I supose
1040 lines_count_feline = 0;
1041
1042 internal_mode_feline = FELINE_MODE_INCLUDE_;
1043
1044 while (fgets(line_buf_feline, xml_file_size_feline, my_file_feline))
1045 {
1046 if (0 == ftell(my_file_feline))
1047 {
1048 break;
1049 }
1050 did_arp = true;
1051 lines_count_feline++;
1052
1053 replacestringsensitive2_feline(line_buf_feline, "\r", "");
1054 replacestringsensitive2_feline(line_buf_feline, "\n", "");
1055
1056 if (strstr(line_buf_feline, adjusted_root_feline_a))
1057 {
1058 internal_mode_feline = FELINE_MODE_EXCLUDE_; //fica salvo ate que ache o fim
1059 }
1060
1061 if (FELINE_MODE_INCLUDE_ == internal_mode_feline)
1062 {
1063 strcat(line_buf_2_feline, line_buf_feline);
1064 strcat(line_buf_2_feline, "\n");
1065 }
1066 else if (FELINE_MODE_EXCLUDE_ == internal_mode_feline)
1067 {
1068 ; //FOR your pleasure
1069 }
1070
1071 if (strstr(line_buf_feline, adjusted_root_feline_b))
1072 {
1073 internal_mode_feline = FELINE_MODE_INCLUDE_; //habilita novamente a adição
1074 }
1075 }
1076
1077 if (did_arp)
1078 {
1079 line_buf_2_feline[strlen(line_buf_2_feline) - 1] = 0; //to remove last \n
1080 }
1081
1082 if (10 == item_feline)
1083 {
1084 strcat(line_buf_2_feline, "\n");
1085 }
1086
1087 if (NULL == line_buf_2_feline && NULL != line_buf_2_feline)
1088 {
1089 return 27;
1090 }
1091
1092 fclose(my_file_feline);
1093
1094 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)),
1095 L"wb");
1096
1097 if (my_file_feline)
1098 {
1099 fwrite(line_buf_2_feline, 1, strlen(line_buf_2_feline), my_file_feline);
1100 fclose(my_file_feline);
1101 my_file_feline = NULL;
1102 }
1103 free(line_buf_feline);
1104 free(line_buf_2_feline);
1105
1106 goto saida_feline;
1107 }
1108 else
1109 {
1110 returnvalue_feline = 1; //Cannot open xml file to write
1111 goto saida_feline;
1112 }
1113 }
1114
1115 goto saida_feline;
1116 }
1117
1118 if (-1 == valid_position_feline)
1119 {
1120
1121 if (3 == ret_arp)
1122 {
1123 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)),
1124 L"wb");
1125 }
1126 else
1127 {
1128 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)),
1129 L"ab");
1130 add_amanda_is_my_love_n_in_ab = true;
1131 }
1132
1133 if (my_file_feline)
1134 {
1135
1136 if(add_amanda_is_my_love_n_in_ab)
1137 {
1138 fwrite("\n", 1, 1, my_file_feline);
1139 }
1140 fwrite(signature_feline, 1, strlen(signature_feline), my_file_feline);
1141 fwrite("<", 1, 1, my_file_feline);
1142 fwrite(root__________feline, 1, strlen(root__________feline), my_file_feline);
1143 fwrite(">\n", 1, 2, my_file_feline);
1144 fwrite(" ", 1, 4, my_file_feline);
1145 fwrite("<", 1, 1, my_file_feline);
1146 fwrite(node__________feline, 1, strlen(node__________feline), my_file_feline);
1147 fwrite(">", 1, 1, my_file_feline);
1148
1149 //aqui converte a string...
1150 fwrite(in_data_______feline, 1, strlen(in_data_______feline), my_file_feline);
1151 fwrite("</", 1, 2, my_file_feline);
1152 fwrite(node__________feline, 1, strlen(node__________feline), my_file_feline);
1153 fwrite(">\n", 1, 2, my_file_feline);
1154 fwrite("</", 1, 2, my_file_feline);
1155 fwrite(root__________feline, 1, strlen(root__________feline), my_file_feline);
1156 fwrite(">\n", 1, 2, my_file_feline);
1157 fclose(my_file_feline);
1158 my_file_feline = NULL;
1159 goto saida_feline;
1160 }
1161 else
1162 {
1163 returnvalue_feline = 1; //Cannot open xml file to write
1164 goto saida_feline;
1165 }
1166 }
1167
1168 if (-1 != root_position_feline && -1 == item_position_feline)
1169 {
1170
1171 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)),
1172 L"rb");
1173 if (my_file_feline)
1174 {
1175 fseek(my_file_feline, 0, SEEK_END);
1176 xml_file_size_feline = ftell(my_file_feline);
1177
1178 if (xml_file_size_feline)
1179 {
1180 fseek(my_file_feline, -1, SEEK_END);
1181 fread(&item_feline, 1, 1, my_file_feline);
1182 }
1183
1184 fseek(my_file_feline, 0, SEEK_SET);
1185
1186 line_buf_feline = calloc(1, xml_file_size_feline + 1);
1187 line_buf_2_feline = calloc(1, xml_file_size_feline + (strlen(node__________feline) * 2) + 5 +
1188 strlen(in_data_______feline) + 1000); //it is enough I supose
1189 lines_count_feline = 0;
1190
1191 while (fgets(line_buf_feline, xml_file_size_feline, my_file_feline))
1192 {
1193 if (0 == ftell(my_file_feline))
1194 {
1195
1196 break;
1197 }
1198 did_arp = true;
1199 lines_count_feline++;
1200
1201 replacestringsensitive2_feline(line_buf_feline, "\r", "");
1202 replacestringsensitive2_feline(line_buf_feline, "\n", "");
1203
1204 strcat(line_buf_2_feline, line_buf_feline);
1205 strcat(line_buf_2_feline, "\n");
1206
1207 if (lines_count_feline == root_position_feline)
1208 {
1209
1210 strcat(line_buf_2_feline, " ");
1211 strcat(line_buf_2_feline, "<");
1212 strcat(line_buf_2_feline,
1213 node__________feline);
1214 strcat(line_buf_2_feline, ">");
1215
1216 //aqui converte a string...
1217 strcat(line_buf_2_feline, in_data_______feline);
1218 strcat(line_buf_2_feline, "</");
1219 strcat(line_buf_2_feline, node__________feline);
1220 strcat(line_buf_2_feline, ">\n");
1221 }
1222 }
1223
1224 if (did_arp)
1225 {
1226 line_buf_2_feline[strlen(line_buf_2_feline) - 1] = 0; //to remove last \n
1227 }
1228
1229 if (10 == item_feline)
1230 {
1231 strcat(line_buf_2_feline, "\n");
1232 }
1233
1234 if (NULL == line_buf_2_feline && NULL != line_buf_2_feline)
1235 {
1236 return 27;
1237 }
1238
1239 fclose(my_file_feline);
1240
1241 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)),
1242 L"wb");
1243
1244 if (my_file_feline)
1245 {
1246 fwrite(line_buf_2_feline, 1, strlen(line_buf_2_feline), my_file_feline);
1247 fclose(my_file_feline);
1248 my_file_feline = NULL;
1249 }
1250 free(line_buf_feline);
1251 free(line_buf_2_feline);
1252
1253 goto saida_feline;
1254 }
1255 else
1256 {
1257 returnvalue_feline = 1; //Cannot open xml file to write
1258 goto saida_feline;
1259 }
1260 }
1261
1262 if (-1 != root_position_feline && -1 != item_position_feline)
1263 {
1264
1265 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)),
1266 L"rb");
1267 if (my_file_feline)
1268 {
1269 fseek(my_file_feline, 0, SEEK_END);
1270 xml_file_size_feline = ftell(my_file_feline);
1271
1272 if (xml_file_size_feline)
1273 {
1274 fseek(my_file_feline, -1, SEEK_END);
1275 fread(&item_feline, 1, 1, my_file_feline);
1276 }
1277
1278 fseek(my_file_feline, 0, SEEK_SET);
1279
1280 line_buf_feline = calloc(1, xml_file_size_feline + 1);
1281 line_buf_2_feline = calloc(1, xml_file_size_feline + (strlen(node__________feline) * 2) + 5 +
1282 strlen(in_data_______feline) + 1000); //it is enough I supose
1283 lines_count_feline = 0;
1284
1285 while (fgets(line_buf_feline, xml_file_size_feline, my_file_feline))
1286 {
1287 if (0 == ftell(my_file_feline))
1288 {
1289
1290 break;
1291 }
1292 did_arp = true;
1293 lines_count_feline++;
1294
1295 replacestringsensitive2_feline(line_buf_feline, "\r", "");
1296 replacestringsensitive2_feline(line_buf_feline, "\n", "");
1297
1298 if (lines_count_feline == item_position_feline)
1299 {
1300
1301 strcat(line_buf_2_feline, " ");
1302 strcat(line_buf_2_feline, "<");
1303 strcat(line_buf_2_feline,
1304 node__________feline);
1305 strcat(line_buf_2_feline, ">");
1306
1307 strcat(line_buf_2_feline, in_data_______feline);
1308 strcat(line_buf_2_feline, "</");
1309 strcat(line_buf_2_feline, node__________feline);
1310 strcat(line_buf_2_feline, ">\n");
1311 }
1312 else
1313 {
1314 strcat(line_buf_2_feline, line_buf_feline);
1315 strcat(line_buf_2_feline, "\n");
1316 }
1317 }
1318
1319 if (did_arp)
1320 {
1321 line_buf_2_feline[strlen(line_buf_2_feline) - 1] = 0; //to remove last \n
1322 }
1323
1324 if (10 == item_feline)
1325 {
1326 strcat(line_buf_2_feline, "\n"); //to add last \n if it was there...
1327 }
1328
1329 if (NULL == line_buf_2_feline && NULL != line_buf_2_feline)
1330 {
1331 return 27;
1332 }
1333
1334 fclose(my_file_feline);
1335
1336 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)),
1337 L"wb");
1338
1339 if (my_file_feline)
1340 {
1341 fwrite(line_buf_2_feline, 1, strlen(line_buf_2_feline), my_file_feline);
1342 fclose(my_file_feline);
1343 my_file_feline = NULL;
1344 }
1345 free(line_buf_feline);
1346 free(line_buf_2_feline);
1347
1348 goto saida_feline;
1349 }
1350 else
1351 {
1352 returnvalue_feline = 1;
1353 goto saida_feline;
1354 }
1355 }
1356
1357 if (-1 == root_position_feline)
1358 {
1359
1360 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)),
1361 L"rb");
1362 if (my_file_feline)
1363 {
1364 fseek(my_file_feline, 0, SEEK_END);
1365 xml_file_size_feline = ftell(my_file_feline);
1366
1367 if (xml_file_size_feline)
1368 {
1369 fseek(my_file_feline, -1, SEEK_END);
1370 fread(&item_feline, 1, 1, my_file_feline);
1371 }
1372
1373 fseek(my_file_feline, 0, SEEK_SET);
1374
1375 line_buf_feline = calloc(1, xml_file_size_feline + 1);
1376 line_buf_2_feline = calloc(1, xml_file_size_feline + (strlen(node__________feline) * 2) + 5 +
1377 strlen(in_data_______feline) + 1000); //it is enough I supose
1378 lines_count_feline = 0;
1379
1380 while (fgets(line_buf_feline, xml_file_size_feline, my_file_feline))
1381 {
1382 if (0 == ftell(my_file_feline))
1383 {
1384
1385 break;
1386 }
1387 did_arp = true;
1388 lines_count_feline++;
1389
1390 replacestringsensitive2_feline(line_buf_feline, "\r", "");
1391 replacestringsensitive2_feline(line_buf_feline, "\n", "");
1392
1393 strcat(line_buf_2_feline, line_buf_feline);
1394 strcat(line_buf_2_feline, "\n");
1395
1396 if (lines_count_feline == valid_position_feline)
1397 {
1398
1399 strcat(line_buf_2_feline, "<");
1400 strcat(line_buf_2_feline, root__________feline);
1401 strcat(line_buf_2_feline, ">\n");
1402 strcat(line_buf_2_feline, " ");
1403 strcat(line_buf_2_feline, "<");
1404 strcat(line_buf_2_feline, node__________feline);
1405 strcat(line_buf_2_feline, ">");
1406 strcat(line_buf_2_feline, in_data_______feline);
1407 strcat(line_buf_2_feline, "</");
1408 strcat(line_buf_2_feline, node__________feline);
1409 strcat(line_buf_2_feline, ">\n");
1410 strcat(line_buf_2_feline, "</");
1411 strcat(line_buf_2_feline, root__________feline);
1412 strcat(line_buf_2_feline, ">\n");
1413 }
1414 }
1415
1416 if (did_arp)
1417 {
1418 line_buf_2_feline[strlen(line_buf_2_feline) - 1] = 0;
1419 }
1420
1421 if (10 == item_feline)
1422 {
1423 strcat(line_buf_2_feline, "\n");
1424 }
1425
1426 if (NULL == line_buf_2_feline && NULL != line_buf_2_feline)
1427 {
1428 return 27;
1429 }
1430
1431 fclose(my_file_feline);
1432
1433 my_file_feline = _wfopen(permissive_name_m_(amanda_utf8towide_3_(filename_utf8_feline)),
1434 L"wb");
1435
1436 if (my_file_feline)
1437 {
1438 fwrite(line_buf_2_feline, 1, strlen(line_buf_2_feline), my_file_feline);
1439 fclose(my_file_feline);
1440 my_file_feline = NULL;
1441 }
1442 free(line_buf_feline);
1443 free(line_buf_2_feline);
1444
1445 goto saida_feline;
1446 }
1447 else
1448 {
1449 returnvalue_feline = 1;
1450 goto saida_feline;
1451 }
1452 }
1453
1454saida_feline:;
1455 if (in_data_______feline)
1456 {
1457 free(in_data_______feline);
1458 }
1459 return returnvalue_feline;
1460}
1461
1472int feline_remove_root_xml(char *filename_utf8_feline,
1473 char *root__________feline)
1474{
1475 write_mode_feline = FELINE_MODE_DELETE_ROOT;
1476
1477 feline_write_xml(filename_utf8_feline,
1478 root__________feline,
1479 "none",
1480 NULL,
1481 "none");
1482 write_mode_feline = FELINE_MODE_NORMAL;
1483 return 0;
1484}
1485
1498int feline_remove_node_xml(char *filename_utf8_feline,
1499 char *root__________feline,
1500 char *node__________feline)
1501{
1502 write_mode_feline = FELINE_MODE_DELETE_NODE;
1503
1504 feline_write_xml(filename_utf8_feline,
1505 root__________feline,
1506 node__________feline,
1507 NULL,
1508 "none");
1509
1510 write_mode_feline = FELINE_MODE_NORMAL;
1511 return 0;
1512}
1513
1514#ifdef MAIN_FOR_DEBUG_FOR_FUTURE_feline
1515
1516int main()
1517{
1518 int ret_arp;
1519 pedro_dprintf(-1, "antes1\n");
1520 {
1521 char out_data_feline[1027];
1522 feline_read_xml("feline.mis", //nao muda mais, por favor
1523 "Aline_Franciele_de_Andrade_settings",
1524 "feline_node_test",
1525 NULL /*for the moment*/,
1526 out_data_feline);
1527
1528 printf("Saida .%s.\n", out_data_feline);
1529
1530 printf("Linhas %d posicao do item nas linhas, linha: %d, root position line: %d valid xml position line: %d\n",
1531 lines_count_feline,
1532 item_position_feline,
1533 root_position_feline,
1534 valid_position_feline);
1535 }
1536 {
1537 char out_data_feline[1027];
1538 ret_arp = feline_read_xml("feline.mis", //nao muda mais, por favor
1539 "Aline_Franciele_de_Andrade_settings",
1540 "feline_node_test",
1541 NULL /*for the moment*/,
1542 out_data_feline);
1543 pedro_dprintf(1001, "antes3\n");
1544 printf("Saida .%s. return %d\n", out_data_feline, ret_arp);
1545
1546 printf("Linhas %d posicao do item nas linhas, linha: %d, root position line: %d valid xml position line: %d\n",
1547 lines_count_feline,
1548 item_position_feline,
1549 root_position_feline,
1550 valid_position_feline);
1551 }
1552
1553 ret_arp = feline_write_xml("feline2.mis", //bug to solve in a few years...no problem
1554 "feline_root",
1555 "feline_node",
1556 NULL,
1557 ".");
1558
1559 printf("Return value of write %d\n", ret_arp);
1560 /*
1561 feline_remove_node_xml("feline2.mis",
1562 "feline_root",
1563 "feline_node"
1564 );
1565 */
1566 {
1567 char out_data_feline[1027];
1568 feline_read_xml("feline2.mis", //nao muda mais, por favor
1569 "feline_root",
1570 "feline_node",
1571 NULL /*for the moment*/,
1572 out_data_feline);
1573 printf("Saiu .%s.\n", out_data_feline);
1574
1575 pedro_dprintf(1001, "saiu armadilhas .%s.\n", out_data_feline);
1576 }
1577 return 0;
1578}
1579
1580#endif
funny_mode
Definition be_xml.c:76
feline_modes
Definition be_xml.c:67
@ FELINE_MODE_INCLUDE_
Definition be_xml.c:131
@ FELINE_MODE_EXCLUDE_
Definition be_xml.c:132
int __fastcall replacestringsensitive2_juliete(char *comando, char *source, char *dest)
Definition be_xml.c:576
WCHAR * amanda_utf8towide_3_(char *pUTF8)
Definition smartape.c:112
int feline_remove_node_xml(char *filename_utf8_feline, char *root__________feline, char *node__________feline)
Definition be_xml.c:1498
int feline_remove_root_xml(char *filename_utf8_feline, char *root__________feline)
Definition be_xml.c:1472
int feline_read_xml(char *filename_utf8_feline, char *root__________feline, char *node__________feline, char *attribute_____feline, char *out_data______feline)
@ MODE_IS_REPLACE__
Definition be_xml.c:150
@ MODE_IS_COUNT__
Definition be_xml.c:151
int feline_write_xml(char *filename_utf8_feline, char *root__________feline, char *node__________feline, char *attribute_____feline, char *in_data_______feline_)
@ FELINE_MODE_NORMAL
Definition be_xml.c:123
@ FELINE_MODE_DELETE_NODE
Definition be_xml.c:125
@ FELINE_MODE_DELETE_ROOT
Definition be_xml.c:124
void pedro_dprintf(int amanda_level, char *format,...)
Definition pedro.c:43
wchar_t * permissive_name_m_(const wchar_t *wname)
Definition smartape.c:143
#define fseek
#define ftell
int main()
Definition dirent_ronkko.h:938
const char * source
Definition lz4.h:808
char * dest
Definition lz4.h:806
#define __attribute__(unused_ric_since_2004)
Definition main_cr.c:84
Definition poolTests.c:28
int
Definition lzoconf.h:340
uint comando
Definition dll.c:179
#define SEEK_SET
Definition zconf.h:498
#define SEEK_END
Definition zconf.h:500
#define g(i)
Definition sha256.c:47
#define a(i)
Definition sha256.c:41
lzma_index ** i
Definition index.h:629
#define NULL
Definition getopt1.c:37
static uint32_t const uint8_t uint32_t len
Definition memcmplen.h:44
ret
Definition zlib_interface.c:30