void write_rc_file(const char *fname) { FILE *fp; char *cptr; fp = fopen(fname, "w"); if(!fp) { perror(fname); exit(1); } cptr = ctime(&now); killnl(cptr, 0); fprintf(fp, str_header, input_name ? input_name : "<stdin>", cmdline, cptr); if(rcinline) write_rcinline(fp); else write_rcbin(fp); fclose(fp); }
void write_h_file(const char *fname) { node_t *ndp; char *cptr; char *cast; FILE *fp; token_t *ttab; int ntab; int i; int once = 0; int idx_en = 0; fp = fopen(fname, "w"); if(!fp) { perror(fname); exit(1); } fprintf(fp, str_header, input_name ? input_name : "<stdin>", cmdline); fprintf(fp, "#ifndef __WMCGENERATED_H\n"); fprintf(fp, "#define __WMCGENERATED_H\n"); fprintf(fp, "\n"); /* Write severity and facility aliases */ get_tokentable(&ttab, &ntab); fprintf(fp, "/* Severity codes */\n"); for(i = 0; i < ntab; i++) { if(ttab[i].type == tok_severity && ttab[i].alias) { cptr = dup_u2c(WMC_DEFAULT_CODEPAGE, ttab[i].alias); fprintf(fp, "#define %s\t0x%x\n", cptr, ttab[i].token); free(cptr); } } fprintf(fp, "\n"); fprintf(fp, "/* Facility codes */\n"); for(i = 0; i < ntab; i++) { if(ttab[i].type == tok_facility && ttab[i].alias) { cptr = dup_u2c(WMC_DEFAULT_CODEPAGE, ttab[i].alias); fprintf(fp, "#define %s\t0x%x\n", cptr, ttab[i].token); free(cptr); } } fprintf(fp, "\n"); /* Write the message codes */ fprintf(fp, "/* Message definitions */\n"); for(ndp = nodehead; ndp; ndp = ndp->next) { switch(ndp->type) { case nd_comment: cptr = dup_u2c(WMC_DEFAULT_CODEPAGE, ndp->u.comment+1); killnl(cptr, 0); killcomment(cptr); if(*cptr) fprintf(fp, "/* %s */\n", cptr); else fprintf(fp, "\n"); free(cptr); break; case nd_msg: if(!once) { /* * Search for an English text. * If not found, then use the first in the list */ once++; for(i = 0; i < ndp->u.msg->nmsgs; i++) { if(ndp->u.msg->msgs[i]->lan == 0x409) { idx_en = i; break; } } fprintf(fp, "\n"); } fprintf(fp, "/* MessageId : 0x%08x */\n", ndp->u.msg->realid); cptr = dup_u2c(ndp->u.msg->msgs[idx_en]->cp, ndp->u.msg->msgs[idx_en]->msg); killnl(cptr, 0); killcomment(cptr); fprintf(fp, "/* Approximate msg: %s */\n", cptr); free(cptr); cptr = dup_u2c(WMC_DEFAULT_CODEPAGE, ndp->u.msg->sym); if(ndp->u.msg->cast) cast = dup_u2c(WMC_DEFAULT_CODEPAGE, ndp->u.msg->cast); else cast = NULL; switch(ndp->u.msg->base) { case 8: if(cast) fprintf(fp, "#define %s\t((%s)0%oL)\n\n", cptr, cast, ndp->u.msg->realid); else fprintf(fp, "#define %s\t0%oL\n\n", cptr, ndp->u.msg->realid); break; case 10: if(cast) fprintf(fp, "#define %s\t((%s)%dL)\n\n", cptr, cast, ndp->u.msg->realid); else fprintf(fp, "#define %s\t%dL\n\n", cptr, ndp->u.msg->realid); break; case 16: if(cast) fprintf(fp, "#define %s\t((%s)0x%08xL)\n\n", cptr, cast, ndp->u.msg->realid); else fprintf(fp, "#define %s\t0x%08xL\n\n", cptr, ndp->u.msg->realid); break; default: internal_error(__FILE__, __LINE__, "Invalid base for number print\n"); } free(cptr); free(cast); break; default: internal_error(__FILE__, __LINE__, "Invalid node type %d\n", ndp->type); } } fprintf(fp, "\n#endif\n"); fclose(fp); }