/* ** close_output ** ** close output file, if it not stdout */ VOID close_output( VOID ) { if ( outfile ) { if ( (return_code == RC_OK) || (return_code == RC_WARN) || debug ) { status_msg( "Writting output" ); errno = 0; outfclose( outfile ); if ( errno ) err_write( outfile ); status_clear(); } else { status_msg( "No output written" ); status_lf(); outfclear( outfile ); } } }
/* * status_error * * display error status messages */ VOID status_error(STRPTR s) { strncpy(status_buf, "*** ", MAX_STATUSLEN); strncat(status_buf, s, MAX_STATUSLEN - strlen(status_buf)); status_msg(status_buf); status_lf(); set_return_code(RC_ERROR); }
/* * status_misc * * display misc. status messages */ VOID status_misc(HSCPRC * hp, STRPTR s) { if (disp_status_verbose) { strcpy(status_buf, ""); #if 0 status_file_and_line(hp); #endif strncat(status_buf, s, MAX_STATUSLEN - strlen(status_buf)); status_msg(status_buf); status_lf(); } }
/* ** include_hsc ** ** read from inpf, parse for hsc-commands and execute them, ** check for html-error, ** write all out to outf and close input file. ** ** params: inpfnm...input file name ** outf.....output file structure, already opended ** ** result: TRUE, if all worked well, else FALSE */ BOOL include_hsc( STRPTR inpfnm, FILE *outf, ULONG optn ) { INFILE *inpf = NULL; /* input file */ BOOL ok; /* result */ inpf = infopen( inpfnm, MAXLINELEN ); /* open input file */ ok = (inpf!=NULL); if ( inpf ) { /* file opened? */ while ( !infeof(inpf) && ok ) { /* parse file */ if ( !(optn & IH_PARSE_MACRO) ) status_infile( inpf, FALSE ); /* status message */ ok = parse_hsc( inpf ); } if ( ok && (optn & IH_PARSE_END) ) { /* parse end */ /* (unclosed tags etc) */ ok = parse_end( inpf ); } /* end of file status */ if ( !(optn & IH_PARSE_MACRO) ) { status_infile( inpf, TRUE ); /* status message */ status_lf(); /* (display num of line) */ } infclose( inpf ); /* close file */ } else { /* N-> error message */ message( ERROR_FILE_OPEN, NULL ); errstr( "can not open " ); errqstr( inpfnm ); errstr( " for input: " ); errstr( strerror( errno ) ); errlf(); ok = FALSE; } return ( ok ); }
/* ** handle_hsc_exec ** ** exec a sub file */ BOOL handle_hsc_exec( INFILE *inpf, HSCTAG *tag ) { STRPTR cmd = get_vartext( tag->attr, "COMMAND" ); if ( cmd ) { int result; EXPSTR *msg = init_estr( 0 ); if ( msg && app_estr( msg, "execute: " ) && app_estr( msg, cmd ) ) { /* status message */ status_msg( estr2str( msg ) ); if ( verbose ) status_lf(); /* call command */ result = system( cmd ); /* check for non-zero-result */ if ( result ) { message( MSG_SYSTEM_RETURN, inpf ); errstr( "Calling external command returned " ); errstr( long2str( (LONG) result ) ); errlf(); } } else err_mem( inpf ); del_estr( msg ); } return (TRUE); }
/* * close_output * * close output file, if it not stdout */ BOOL write_output(HSCPRC * hp) { #define MAX_ERRORLEN 500 STRPTR outfilenm = NULL; BOOL written = FALSE; if (outfilename) outfilenm = estr2str(outfilename); if ((return_code == RC_OK) || (return_code == RC_WARN) || hp->debug) { FILE *outfile = NULL; /* output file */ char buf[MAX_ERRORLEN + 2]; /* buffer for error string */ /* * try to open output file */ if (outfilenm) { errno = 0; outfile = fopen(outfilenm, "w"); if (!outfile) { strncpy(buf, "unable to open `", MAX_ERRORLEN); strncat(buf, estr2str(outfilename), MAX_ERRORLEN - strlen(buf)); strncat(buf, "' for output: ", MAX_ERRORLEN - strlen(buf)); strncat(buf, strerror(errno), MAX_ERRORLEN - strlen(buf)); status_error(buf); } } else { outfile = stdout; outfilenm = STDOUT_NAME; } /* * write output */ if (outfile) { DLNODE *nd = dll_first(outlist); status_msg("writing output..."); errno = 0; /* write whole list of output-strings */ while (nd && !errno) { EXPSTR *outstring = (EXPSTR *) dln_data(nd); nd = dln_next(nd); fwrite(estr2str(outstring), sizeof(char), estrlen(outstring), outfile); } /* handle write-error, display message */ if (errno) { strncpy(buf, "error writing `", MAX_ERRORLEN); strncat(buf, outfilenm, MAX_ERRORLEN - strlen(buf)); strncat(buf, "': ", MAX_ERRORLEN - strlen(buf)); strncat(buf, strerror(errno), MAX_ERRORLEN - strlen(buf)); status_error(buf); } else written = TRUE; status_clear(); /* close output file */ if (outfile != stdout) { fclose(outfile); #ifdef RISCOS { /* set the filetype to HTML (&FAF) */ char *riscos_filename=unixname_to_riscos(outfilenm); _swix(OS_File,_IN(0)|_IN(1)|_IN(2),18,riscos_filename,0xFAF); free(riscos_filename); } #endif } } } else { status_msg("no output written"); status_lf(); } return (written); }
/* * status_file_end * * hsc-callback for file fully processed: display * file and total number of line, perform liefeed */ VOID status_file_end(HSCPRC * hp) { status_file_and_line(hp); status_msg(status_buf); status_lf(); }