382{
383 char *inname, *outname_local ;
384 char tmpstr[20];
385 int fdi, fdo, pid, ifclose_in, ifclose_out;
386 FILE * stream;
387 FILE * stream_out;
388 int sz_lenpath;
389 int hostname_err;
390
391#ifdef _WIN64
392 char tmpstr_host[MAX_COMPUTERNAME_LENGTH+1];
393 int size_tmpstr_host;
394 size_tmpstr_host=MAX_COMPUTERNAME_LENGTH+1;
395 WSADATA wsadata;
396 WORD version= MAKEWORD(1,1);
397 int nRet,le;
398#else
399 char tmpstr_host[MAXHOSTNAMELEN];
400 int size_tmpstr_host;
401 size_tmpstr_host=MAXHOSTNAMELEN;
402#endif
403 inname = NULL;
404 outname_local = NULL;
405 ifclose_in=0;
407 if (*got_input == 1) {
408 if(*len_path==0)
409 {
410 inname = (char *) calloc(*namelen+1, sizeof (char));
411#ifdef _WIN64
412 strncpy_s(inname,*namelen+1,filename,*namelen);
413#else
414 strncpy(inname,filename,*namelen);
415#endif
416 }
417 else
418 {
419 inname = (char *) calloc(*namelen+1+ *len_path, sizeof (char));
420#ifdef _WIN64
421 strncpy_s(inname,*namelen+1+ *len_path,path,*len_path);
422 strncat_s(inname,*namelen+1+ *len_path,filename,*namelen);
423#else
424 strncpy(inname,path,*len_path);
425 strncat(inname, filename, *namelen);
426#endif
427 }
428
429#ifdef _WIN64
430 fopen_s(&stream,inname,"r");
431#else
432 stream = fopen(inname,"r");
433#endif
434
435 if (stream == NULL) {
436 fprintf (stderr, "*** ERROR IN OPENING INPUT FILE : %s !\n", inname);
438 }
439 }
440 if( *ierr==0 ) {
441#ifdef _WIN64
442 pid = _getpid();
443 nRet = WSAStartup(version,&wsadata);
444 hostname_err=gethostname(tmpstr_host,size_tmpstr_host);
445 le=WSAGetLastError();
446 if (hostname_err != 0) {
447 strcpy_s(tmpstr_host,size_tmpstr_host,"Unknown");
448 }
449
450#else
451 pid = getpid();
452 gethostname(tmpstr_host,size_tmpstr_host);
453#endif
454 outname[0] = '\0' ;
455 sprintf(tmpstr,"%d",pid);
456 if(*len_path2==0)
457 {
458
459 sz_lenpath=2148;
460 outname_local = (char *) calloc(sz_lenpath, sizeof (char));
461 char * cwd =
cwd_c();
462#ifdef _WIN64
463 strcpy_s(outname_local,sz_lenpath,cwd);
464 strcat_s(outname_local,sz_lenpath,"\\");
465#else
466 strcpy(outname_local,cwd);
467 strcat(outname_local, "/");
468#endif
469 free(cwd);
470 }
471 else
472 {
473 sz_lenpath=*len_path2 +1 + 2148;
474 outname_local = (char *) calloc(sz_lenpath, sizeof (char));
475 outname_local[0]='\0';
476#ifdef _WIN64
477 strncpy_s(outname_local,sz_lenpath,path2, *len_path2);
478#else
479 strncpy(outname_local, path2, *len_path2);
480#endif
481
482 }
483
484#ifdef _WIN64
485 strncat_s(outname_local,sz_lenpath, rootname, *rootlen);
486 strcat_s(outname_local,sz_lenpath, "_");
487 strcat_s(outname_local,sz_lenpath, tmpstr);
488 strcat_s(outname_local,sz_lenpath, "_");
489 strcat_s(outname_local,sz_lenpath, tmpstr_host);
490 strcat_s(outname,sz_lenpath, outname_local);
491 *namelen = (int) strlen(outname);
492 fopen_s(&stream_out,outname,"w");
493
494#else
495 strncat(outname_local, rootname, *rootlen);
496 strcat(outname_local, "_");
497 strcat(outname_local, tmpstr);
498 strcat(outname_local, "_");
499 strcat(outname_local, tmpstr_host);
500 strcat(outname, outname_local);
501 *namelen = (int) strlen(outname);
502 stream_out = fopen(outname,"w");
503
504#endif
505
506 if (stream_out == NULL) {
507 fprintf (stderr, " *** ERROR INPUT FILE: CANNOT CREATE TEMP FILE : %s !\n",outname);
509 }
510
511 if (stream != NULL && stream_out != NULL) {
512 convertfile(stream,0,stream_out,inname,*ncharline,ierr);
513
514 ifclose_in=fclose(stream);
515 ifclose_out=fclose(stream_out);
516
517 if (ifclose_in != 0) {
518 syserr(
"Error: close input (flat deck)");
519 }
520 if (ifclose_out != 0) {
521 syserr(
"Error: close output (flat deck)");
522 }
523 }
524 }
525 free(outname_local);
526 free(inname);
527}
void convertfile(FILE *stream, int level, FILE *stream_out, char *filename, int ncharline, int *ierr)