258void convertfile(FILE *stream,
int level,FILE *stream_out,
char *filename,
int ncharline,
int *ierr){
260 char *line,*line1,*tag;
263 int k,val,nlevel,snewinc,linelen;
267 char *pch,*pch1,*pch2;
268 const char *cs =
" ";
269 line=(
char *)malloc(
sizeof(
char)* ncharline);
270 line1=(
char *)malloc(
sizeof(
char)* ncharline);
271 tag=(
char *)malloc(
sizeof(
char)* ncharline);
272 idchr=(
char *)malloc(
sizeof(
char)* ncharline);
273 newinc=(
char *)malloc(
sizeof(
char)* ncharline);
276 printf(
"Max level=%d reached\n",level);
277 printf(
"Include file %s skipped.\n",filename);
286 while (fgets(line,ncharline,stream)!=NULL){
287 linelen=strlen(line);
290 if ( line[linelen-2] ==
'\r' ) {
292 line[linelen-1] = line[linelen];
293 line[linelen] =
'\0';
296 if ( line[linelen-1] !=
'\n' ) {
297 line[linelen] =
'\n';
299 line[linelen] =
'\0';
301 if (firstline == 1 && strncmp(line,
"#",1)==0 && level == 0) {
302 fputs(line,stream_out);
305 else if ( ( strncmp(line,
"#",1)==0 && strncmp(line,
"#include ",9)==0 && strncmp(line,
"#INCLUDE ",9)==0 ) ||
306 strncmp(line,
"$",1)==0 ) {
310 else if ( strncmp(line,
"//SUBMODEL",10)==0 ){
314 fputs(line,stream_out);
316 else if ( strncmp(line,
"//ENDSUB",8)==0 ){
317 fputs(line,stream_out);
322 else if ( ( (strncmp(line,
"/END",4)==0 && strncmp(line,
"/END/ENGINE",11)!=0) ||
323 strncmp(line,
"#enddata",8)==0 ||
324 strncmp(line,
"#ENDDATA",8)==0 ) &&
326 if (strncmp(line,
"/END",4)==0) {
327 printf(
"Warning in include file %s : /END detected !\n",filename);
331 else if ( strncmp(line,
"/END",4)==0 &&
332 strncmp(line,
"/END/ENGINE",11)!=0 ){
333 fputs(line,stream_out);
341 while (fgets(line,ncharline,stream)!=NULL && iend2!=1){
342 if ( strncmp(line,
"/ALTDOCTAG",10)==0 ){
343 fputs(line,stream_out);
344 fgets(line,ncharline,stream);
345 fputs(line,stream_out);
352 else if( strncmp(line,
"/END",4)==0 &&
353 strncmp(line,
"/END/ENGINE",11)==0 ){
354 fputs(line,stream_out);
363 fputs(line,stream_out);
367 if (strncmp(line,
"/END",4)==0 ) {
368 printf(
"myline %s \n",line);
381void lf_convert_c_flat(
int *got_input,
char *rootname,
int *rootlen,
char *filename,
int *namelen,
char *outname,
int *ierr,
int *ncharline,
int *len_path,
char *path,
int *len_path2,
char *path2)
383 char *inname, *outname_local ;
385 int fdi, fdo, pid, ifclose_in, ifclose_out;
392 char tmpstr_host[MAX_COMPUTERNAME_LENGTH+1];
393 int size_tmpstr_host;
394 size_tmpstr_host=MAX_COMPUTERNAME_LENGTH+1;
396 WORD version= MAKEWORD(1,1);
399 char tmpstr_host[MAXHOSTNAMELEN];
400 int size_tmpstr_host;
401 size_tmpstr_host=MAXHOSTNAMELEN;
404 outname_local = NULL;
407 if (*got_input == 1) {
410 inname = (
char *) calloc(*namelen+1,
sizeof (
char));
412 strncpy_s(inname,*namelen+1,filename,*namelen);
414 strncpy(inname,filename,*namelen);
419 inname = (
char *) calloc(*namelen+1+ *len_path,
sizeof (
char));
421 strncpy_s(inname,*namelen+1+ *len_path,path,*len_path);
422 strncat_s(inname,*namelen+1+ *len_path,filename,*namelen);
424 strncpy(inname,path,*len_path);
425 strncat(inname, filename, *namelen);
430 fopen_s(&stream,inname,
"r");
432 stream = fopen(inname,
"r");
435 if (stream == NULL) {
436 fprintf (stderr,
"*** ERROR IN OPENING INPUT FILE : %s !\n", inname);
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");
452 gethostname(tmpstr_host,size_tmpstr_host);
455 sprintf(tmpstr,
"%d",pid);
460 outname_local = (
char *) calloc(sz_lenpath,
sizeof (
char));
461 char * cwd =
cwd_c();
463 strcpy_s(outname_local,sz_lenpath,cwd);
464 strcat_s(outname_local,sz_lenpath,
"\\");
466 strcpy(outname_local,cwd);
467 strcat(outname_local,
"/");
473 sz_lenpath=*len_path2 +1 + 2148;
474 outname_local = (
char *) calloc(sz_lenpath,
sizeof (
char));
475 outname_local[0]=
'\0';
477 strncpy_s(outname_local,sz_lenpath,path2, *len_path2);
479 strncpy(outname_local, path2, *len_path2);
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");
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");
506 if (stream_out == NULL) {
507 fprintf (stderr,
" *** ERROR INPUT FILE: CANNOT CREATE TEMP FILE : %s !\n",outname);
511 if (stream != NULL && stream_out != NULL) {
512 convertfile(stream,0,stream_out,inname,*ncharline,ierr);
514 ifclose_in=fclose(stream);
515 ifclose_out=fclose(stream_out);
517 if (ifclose_in != 0) {
518 syserr(
"Error: close input (flat deck)");
520 if (ifclose_out != 0) {
521 syserr(
"Error: close output (flat deck)");
void _FCALL LF_CONVERT_C_FLAT(int *got_input, char *rootname, int *rootlen, char *filename, int *namelen, char *outname, int *ierr, int *ncharline, int *len_path, char *path, int *len_path2, char *path2)