int ProcessMedlineArticle( DBPROCESS *db, MedArt *rec, int is_pub ) { AbPList plist; RETCODE rc; DBCHAR state_msg[40]; /* Text description of state */ DBINT state; int status; /* Clear out the input record */ bzero( rec, sizeof(MedArt) ); bzero( &plist, sizeof(plist) ); /* Get rid of all patches */ /* Collect the data from the database */ for(status = True; status != Error; rc = dbresults( db )) { /* Get the next header row from the batch and then skip to the results batch associated with the header (dbresults call) */ rc = SybaseLoad( db, 1, INTBIND, 0, &state, 2, NTBSTRINGBIND, sizeof(state_msg), state_msg, 0 ); if( rc == REG_ROW ) { /* EOF marked with MR_STATE_DONE as the state */ if( state == MR_STATE_DONE ) return( True ); /* Prepare to read the results section */ rc = dbresults(db); } if( rc != SUCCEED ) return( Error ); /* Dispatch to the handler for this block of input */ switch( state ) { case MR_STATE_ARTICLE: /* This one should be first */ if ( is_pub ) status = process_pub_article( db, rec ); else status = process_article( db, rec ); if( status != True ) return( status ); break; case MR_STATE_ISO_VTITLE: status = patch_string(db, rec->vtitle, sizeof(rec->vtitle)); break; case MR_STATE_ISO_ADDRESS: status = patch_string(db, rec->address, sizeof(rec->address)); break; case MR_STATE_AUTHOR: status = process_author( db, rec ); break; case MR_STATE_ISO_AUTHOR: status = patch_author( db, rec ); break; case MR_STATE_ISO_ABSTRACT: if( plist.n_patches > 0 ) bzero( &plist, sizeof(plist) ); status = patch_abstract( db, rec, &plist ); break; case MR_STATE_ABSTRACT: status = process_abstract( db, rec, &plist ); break; case MR_STATE_MESH: status = process_mesh( db, rec ); break; case MR_STATE_SUBHEADING: status = process_subheading( db, rec ); break; case MR_STATE_SUBSTANCE: status = process_substance( db, rec ); break; case MR_STATE_CROSSREFERENCE: status = process_xref( db, rec ); break; case MR_STATE_SUPPORT: status = process_support( db, rec ); break; case MR_STATE_GENESYMBOL: status = process_genesymbol( db, rec ); break; default: /* Unknown state - ignore it */ status = skip_undefined_section( db ); break; } } /* Return the proper status */ return( Error ); }
int main(int argc, char **argv) { char source[FILENAME_MAX]; /* ReSource filename */ char target_i[FILENAME_MAX]; /* .C-file containing pointers */ char target_n[FILENAME_MAX]; /* All NMSGs */ char target_f[FILENAME_MAX]; /* All FMSGs */ char target_h[FILENAME_MAX]; /* Include file - all NMSGs/FMSGs */ char target[FILENAME_MAX], locale[15]; char c_system[32]; char binding; char *msg_buffer; /* Messages may be large enough... */ struct pool pool[32]; /* Up to 32 separate msg arrays */ int tpool, cur_pool=0, i; int buf_len; FILE *resfile, *ifile, *nfile, *ffile, *hfile; char pathsep[2]; printf("MSGBIND v 1.65 [14/12/2002] Not a part of any binary package!\n\n"); if(argc<6) { printf("Usage: MSGBIND <resource> <target> <OS> <binding> <locale> [target directory],\n" " e.g, to build MSG_SFXV.*, type MSGBIND MSG.RES MSG_SFXV DOS en\n" "\n" "The target directory is optional. If specified (e.g., BINARIES\\ENGLISH), all\n" "compiled .C files will be placed there.\n"); exit(1); } msg_buffer=(char *)malloc_msg(MSG_SIZE); build_crc32_table(); pathsep[0]=PATHSEP_DEFAULT; pathsep[1]='\0'; strcpyn(source, argv[1], sizeof(source)-8); /* Fix for GCC/EMX: convert UNIX-like representations to DOS */ #if PATHSEP_UNIX!=PATHSEP_DEFAULT for(i=0; source[i]!='\0'; i++) if(source[i]==PATHSEP_UNIX) source[i]=PATHSEP_DEFAULT; #endif if(strrchr(source, PATHSEP_DEFAULT)==NULL) rdir[0]='\0'; else { strcpy(rdir, source); strrchr(rdir, PATHSEP_DEFAULT)[1]='\0'; } strcpyn(target, argv[2], sizeof(target)-8); strcpyn(c_system, argv[3], sizeof(c_system)); binding=tolower(argv[4][0]); /* Beginning with v 1.21, target directory may be also specified */ if(argc==7) { strcpyn(target_i, argv[6], sizeof(target_i)-8); strcpyn(target_n, argv[6], sizeof(target_n)-8); strcpyn(target_f, argv[6], sizeof(target_f)-8); strcpyn(target_h, argv[6], sizeof(target_f)-8); /* v 1.41+ */ if(argv[6][strlen(argv[6])-1]!=PATHSEP_DEFAULT); { strcat(target_i, pathsep); strcat(target_n, pathsep); strcat(target_f, pathsep); strcat(target_h, pathsep); } } else { target_i[0]='\0'; target_n[0]='\0'; target_f[0]='\0'; target_h[0]='\0'; } strcat(target_i, "i"); strcat(target_n, "n"); strcat(target_f, "f"); strcat(target_i, argv[2]); strcat(target_n, argv[2]); strcat(target_f, argv[2]); strcat(target_h, argv[2]); /* The source has the extension .MSG, the targets are .H and .C */ if(strchr(source, '.')==NULL) strcat(source, ".msg"); strcat(target_i, ".c"); strcat(target_n, ".c"); strcat(target_f, ".c"); strcat(target_h, ".h"); strcpyn(locale, argv[5], sizeof(locale)); strlwr(target); strlwr(c_system); strlwr(locale); /* Block out all signals, since this transaction is mission-critical */ signal(SIGINT, SIG_IGN); #ifndef NO_TERM_HDL signal(SIGTERM, SIG_IGN); #endif if((resfile=fopen(source, m_r))==NULL) { printf("Can't open source file!\n"); exit(2); } if((ifile=fopen(target_i, m_w))==NULL) { printf("Can't open index file!\n"); exit(3); } if((nfile=fopen(target_n, m_w))==NULL) { printf("Can't open NMSG output file!\n"); exit(3); } if((ffile=fopen(target_f, m_w))==NULL) { printf("Can't open FMSG output file!\n"); exit(3); } if((hfile=fopen(target_h, m_w))==NULL) { printf("Can't open .h output file!\n"); exit(3); } put_hdr(ifile, target_i, source); put_hdr(nfile, target_n, source); put_hdr(ffile, target_f, source); put_hdr(hfile, target_h, source); fputs(INCL, ifile); fputs(INCL, nfile); fputs(INCL, ffile); fprintf(ifile, "#include \""); for(i=0; target_h[i]!='\0'; i++) fputc(target_h[i]=='\\'?'/':target_h[i], ifile); fprintf(ifile, "\"\n\n"); /* Ack. Now process the source file line by line... */ while(get_msg(resfile, target, c_system, binding, locale, msg_buffer, MSG_SIZE)!=NULL) { expand_tags(msg_buffer, MSG_SIZE); fprintf(toupper(msgtype[0])=='N'?nfile:ffile, "char %s[]=%s;\n", msgname, msg_buffer); fprintf(hfile, "extern %s %s[];\n", toupper(msgtype[0])=='N'?M_NMSG:M_FMSG, msgname); /* Check if the message belongs to a pre-defined message pool */ if(strcmp(msgpool, SKIP)) { /* Pick a message heap */ for(tpool=0; tpool<cur_pool; tpool++) { if(!strcmp(pool[tpool].name, msgpool)) break; } /* Allocate new heap if needed */ if(tpool==cur_pool) { if(cur_pool>=sizeof(pool)) { printf("Too many message groups!\n"); exit(4); } strcpy(pool[tpool].name, msgpool); pool[tpool].msgs=0; pool[tpool].crc32=CRC_MASK; pool[tpool].safesize=POOL_R_INC; pool[tpool].data=(char *)malloc_msg(POOL_R_INC); pool[tpool].st_class=toupper(msgtype[0])=='N'?'N':'F'; sprintf(pool[tpool].data, "%cMSGP %s []={", pool[tpool].st_class, msgpool); pool[tpool].columns=pool[tpool].indent=strlen(pool[tpool].data); cur_pool++; } pool[tpool].msgs++; if(strlen(pool[tpool].data)+strlen(msgname)+pool[tpool].indent+16>pool[tpool].safesize) { if((pool[tpool].safesize+=POOL_R_INC)>POOL_SIZE) { printf("Message pool for %s exceeded %u bytes, exiting\n", msgpool, POOL_SIZE); } if((pool[tpool].data=realloc(pool[tpool].data, pool[tpool].safesize))==NULL) { printf("Unexpected lack of memory!r\n"); exit(5); } } if((pool[tpool].columns+=strlen(msgname))>COLUMNS) { strcat(pool[tpool].data, "\n"); pool[tpool].columns=pool[tpool].indent; pool[tpool].data[strlen(pool[tpool].data)+pool[tpool].indent]='\0'; memset(pool[tpool].data+strlen(pool[tpool].data), 32, pool[tpool].indent); } strcat(pool[tpool].data, msgname); strcat(pool[tpool].data, ", "); strcpy(msg_buffer, msg_buffer+1); buf_len=strlen(msg_buffer); msg_buffer[--buf_len]='\0'; patch_string(msg_buffer); crc32term=pool[tpool].crc32; crc32_for_string(msg_buffer); pool[tpool].crc32=crc32term; } } fputs("\n", hfile); /* First, flush the message pools... */ for(tpool=0; tpool<cur_pool; tpool++) { strcat(pool[tpool].data, "NULL};\n\n"); fputs(pool[tpool].data, ifile); free(pool[tpool].data); /* ...by the way, flushing the CRC-32 values */ fprintf(hfile, "#define %s_CRC32 0x%08lx\n", pool[tpool].name, pool[tpool].crc32); fprintf(hfile, "extern %cMSGP %s[];\n", pool[tpool].st_class, pool[tpool].name); } /* Now, put an ending LF to all files */ fputs("\n", ifile); fputs("\n", nfile); fputs("\n", ffile); fputs("\n", hfile); fclose(ifile); fclose(nfile); fclose(ffile); fclose(hfile); free(msg_buffer); return(0); /* Report no error */ }