/* * Initialization, message loop */ int main(int argc, char *argv[]) { char basename[_MAX_PATH]; char filename[_MAX_PATH]; char drive[_MAX_DRIVE]; char path[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; char msgbuf [1024]; char linebuf[1024*4]; char *preload = NULL; FILE *IDSfile; int result; int id; int file; UInt32 startTime; int lastid = 0; // Set the FPU to 24 bit precision _controlfp( _PC_24, MCW_PC ); _controlfp( _RC_CHOP, MCW_RC); #ifdef USE_SH_POOLS glMemPool = MemPoolInit( 0 ); Palette::InitializeStorage (); #endif // Display are startup banner printf( "BSPbuild compiled %s. FLT reader %s\n", __TIMESTAMP__, FLTtoGeometryTimeStamp ); while (argc > 1 && argv[1][0] == '-') { switch (argv[1][1]) { case '-': // end of args break; case 'l': preload = argv[2]; argc --; argv ++; break; } argv ++; argc --; break; } // See if we got a filename on the command line if ( argc == 2) { result = GetFullPathName( argv[1], sizeof( filename ), filename, NULL ); } else { result = 0; } // If we didn't get it on the command line, ask the user if (result == 0) { strcpy( filename, "ids.txt" ); if ( !GetNameFromUser( filename, sizeof(filename) )) { return -1; } } if (preload) { printf ("Step 0: Preloading file %s\n", preload); ObjectParent::SetupTable(preload); //lastid = TheObjectListLength + 1; // TheParentBuildList.SetStartPoint(lastid); // TheParentBuildList.MergeEntries(); TheColorBuildList.MergeColors(); ColorBankClass::Cleanup(); ThePaletteBuildList.MergePalette(); ThePaletteBank.Cleanup(); ObjectLOD::CleanupTable(); } // Mark our start time startTime = GetTickCount(); // Open the object id input file printf("Step 1: Reading %s. (Time %0.0fmin)\n", filename, (GetTickCount()-startTime)/60000.0 ); fprintf(stderr, "Step 1: Reading %s. (Time %0.0fmin)\n", filename, (GetTickCount()-startTime)/60000.0 ); fflush(NULL); IDSfile = fopen( filename, "r" ); if (!IDSfile) { sprintf( msgbuf, "Failed to open input file %s", filename ); ShiError( msgbuf ); } #ifdef USE_SH_POOLS if ( gBSPLibMemPool == NULL ) { gBSPLibMemPool = MemPoolInit( 0 ); } #endif // Read each line from the input ID file while (fgets (linebuf, sizeof linebuf, IDSfile) != NULL) { char *av[100]; int ac; char *cp; if (linebuf[0] == '#' || linebuf[0] == '\n' || linebuf[0] == '\r') continue; if (cp = strchr (linebuf, '\n')) *cp = '\0'; ac = sstr2arg(linebuf, 100, av, " \t,"); if (ac < 2) continue; id = atoi(av[0]); if (id == -1) id = lastid ++; TheParentBuildList.AddItem( id, av[1]); } // Close the id file fclose( IDSfile ); // Now construct the object array and read each object printf("Step 2: Reading FLT files. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fprintf(stderr, "Step 2: Reading FLT files. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fflush(NULL); if ( !TheParentBuildList.BuildParentTable() ) { printf("ERROR: We got no objects to process. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fprintf(stderr, "ERROR: We got no objects to process. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fflush(NULL); exit( -1 ); } // Write the data to disk in a packed format _splitpath( filename, drive, path, fname, ext ); strcpy( basename, drive ); strcat( basename, path ); strcat( basename, "KoreaObj" ); // Create the object LOD file printf("Step 3: Writing object LODs. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fprintf(stderr, "Step 3: Writing object LODs. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fflush(NULL); strcpy( filename, basename ); strcat( filename, ".LOD" ); printf("\nCreating %s\n", filename); file = open( filename, _O_WRONLY | _O_BINARY | _O_TRUNC | _O_CREAT, _S_IWRITE ); if (file < 0) { printf("Failed to create object LOD file %s\n", filename); exit(-1); } // Write the object LOD data file TheLODBuildList.WriteLODData( file ); // Close the object LOD file close(file); // Create the object texture file printf("Step 4: Writing object textures. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fprintf(stderr, "Step 4: Writing object textures. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fflush(NULL); strcpy( filename, basename ); strcat( filename, ".TEX" ); printf("\nCreating %s\n", filename); file = open( filename, _O_WRONLY | _O_BINARY | _O_TRUNC | _O_CREAT, _S_IWRITE ); if (file < 0) { printf("Failed to create object texture file %s\n", filename); exit(-1); } // Write the object texture file TheTextureBuildList.WriteTextureData( file ); // Close the object texture file close(file); // Free the LOD data now that its on disk TheParentBuildList.ReleasePhantomReferences(); // Create the master object file printf("Step 5: Writing object headers. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fprintf(stderr, "Step 4: Writing object headers. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fflush(NULL); strcpy( filename, basename ); strcat( filename, ".HDR" ); printf("\nCreating %s\n", filename); file = open( filename, _O_WRONLY | _O_BINARY | _O_TRUNC | _O_CREAT | _O_SEQUENTIAL, _S_IWRITE ); if (file < 0) { printf("Failed to create master file %s\n", filename); exit(-1); } // Write the object format version to the master file TheParentBuildList.WriteVersion( file ); // Write the Color Table to the master file TheColorBuildList.WritePool( file ); // Write the Palette Table to the master file ThePaletteBuildList.WritePool( file ); // Write the Texture Table to the master file TheTextureBuildList.WritePool( file ); // Write the object LOD headers TheLODBuildList.WriteLODHeaders( file ); // Write the parent object records to the master file TheParentBuildList.WriteParentTable( file ); // Close the master file close(file); printf("Step 6: Reporting. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fprintf(stderr, "Step 5: Reporting. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fflush(NULL); TheColorBuildList.Report(); ThePaletteBuildList.Report(); TheTextureBuildList.Report(); printf("Finished. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fprintf(stderr, "Finished. (Time %0.0fmin)\n", (GetTickCount()-startTime)/60000.0 ); fprintf(stderr, "Press ENTER to end.\n"); getchar(); return 0; }
input () { int infile; int n; long dist; int nfd; int stat, slen; char otherbuf[S_BSIZE]; char tempbuf[24]; char *fromptr, *toptr, *ccptr, *subjptr, *bccptr, *otherptr; sigtype (*old1) (), (*old2) (), (*old3) (); register int i; printf ("SND (%s)\n", verdate); bccflag = 0; dropen(DRBEGIN); /* Set up headers to be written into the draft file */ fromptr = from; toptr = to; ccptr = cc; subjptr = subject; bccptr = bcc; otherptr = otherbuf; strcpy(from, signature); strcpy(otherptr, fromname); strcat(otherptr, fromptr); strcpy(fromptr, otherptr); strcpy(otherptr, toname); strcat(otherptr, toptr); strcpy(toptr, otherptr); strcpy(otherptr, ccname); strcat(otherptr, ccptr); strcpy(ccptr, otherptr); slen = strlen( subjname ); strcpy(otherptr, subjname); strcat(otherptr, subjptr); strcpy(subjptr, otherptr); /* Write the header info to the draft file */ if(write(drffd, fromptr, strlen(fromptr)) < 0) { printf("Cannot write draft %s\n", drffile); s_exit(-1); } write(drffd, "\n", 1); write(drffd, toptr, strlen(toptr)); write(drffd, "\n", 1); write(drffd, ccptr, strlen(ccptr)); write(drffd, "\n", 1); /* If there are blind carbon copies write the necessary header b.s. */ if(bcc[0] != '\0') { strcpy(otherptr, bccname); strcat(otherptr, bccptr); strcpy(bccptr, otherptr); write(drffd, bccptr, strlen(subjptr)); write(drffd, "\n", 1); bccflag = 1; } if( strlen( subject ) > slen ) { char newsubj[S_BSIZE], *p, *pnt; char *index(); int plc; newsubj[0] = '\0'; pnt = subjptr; while( (p = index(pnt,'\n')) != 0 ) { *p++ = '\0'; plc = strlen(newsubj); sprintf( &newsubj[plc],"%s\n%s",pnt," "); pnt = p; } strcat( newsubj, pnt ); strcpy( subjptr, newsubj ); } write(drffd, subjptr, strlen(subjptr)); write(drffd, "\n\n", 2); /* If there is a forwarded message */ if (inclfile[0] != '\0') { /* tack file to end of message */ body = TRUE; strcpy (bigbuf, inclfile); infile = open (bigbuf, 0); if (inclfile[0] != '\0') inclfile[0] = '\0'; if (infile < 0) printf ("can't open: '%s'\n", bigbuf); dropen (DREND); body = TRUE; while ((i = read (infile, bigbuf, BBSIZE - 1)) > 0) write (drffd, bigbuf, i); (void) close (infile); } edit: fflush (stdout); drclose (); old1 = signal (SIGHUP, SIG_IGN); /* ignore signals intended for edit */ old2 = signal (SIGINT, SIG_IGN); old3 = signal (SIGQUIT, SIG_IGN); /* Crank up the editor now that the draft file is set-up */ if (fork () == 0) { signal (SIGHUP, old1); signal (SIGINT, orig); signal (SIGQUIT, old3); execlp (editor, editor, drffile, (char *)0); fprintf (stderr,"can't execute\n"); s_exit (-1); } wait (&stat); body = TRUE; /* Don't know but assume he created a draft */ lastsend = 0; signal (SIGHUP, old1); /* restore signals */ signal (SIGINT, old2); signal (SIGQUIT, old3); fflush (stdout); signal (SIGINT, SIG_IGN); signal (SIGQUIT, SIG_IGN); dropen(DRBEGIN); /* Rip the header information from the draft file and ** take care of any aliases ** Algorithm: ** Read each header line (function grabaddr), keeping track of the ** number of characters read. Handle the aliases (function doalias). ** Open a new file descriptor which points to the beginning of the ** draft file. Read the draft file from the point where the header ** information leaves off while writing to the draft from the beginning. ** This effectively reads the header info, then shifts the body of the ** message up to the top of the draft, overwriting the header. */ dist = gethdr( fromptr, toptr, ccptr, bccptr, subjptr ); doalias( toptr ); doalias( ccptr ); doalias( bccptr ); if(chmod(drffile, 0600) < 0) { fprintf(stderr,"Unable to make draft writable %s.\n", drffile); s_exit(-1); } if((nfd = open(drffile, 2, 600)) < 0) { fprintf(stderr,"Could not open draft %s\n", drffile); s_exit(-1); } if(lseek(nfd, 0L, 0) < 0) { fprintf(stderr,"Lseek failed on draft %s\n", drffile); s_exit(-1); } if(lseek(drffd, dist-1, 0) < 0) { fprintf(stderr,"Lseek failed on draft %s\n", drffile); s_exit(-1); } dist = 0L; while((i = read(drffd, bigbuf, BBSIZE -1)) > 0) dist += write(nfd, bigbuf, i); if(truncate(drffile, dist) < 0) { fprintf(stderr,"Truncate failed on draft %s\n", drffile); s_exit(-1); } if(chmod(drffile, 0400) < 0) fprintf(stderr,"Unable to make draft %s writable.\n",drffile); (void) close( nfd ); setjmp (savej); nsent = 0; /* ** MAIN COMMAND INTERPRETER LOOP */ for (;;) { char *cp; signal (SIGINT, onint3); printf ("Command or ?: "); fflush (stdout); aborted = FALSE; if (fgets (bigbuf, BBSIZE, stdin) == NULL) goto byebye; if (cp = index(bigbuf, '\n')) *cp = '\0'; /* "Set" option */ if( strncmp( "set", bigbuf, 3) == 0){ char *av[NARGS]; i = sstr2arg(bigbuf, 20, av, " \t"); if( i == 1 ) { /* tell him what the current options are */ printf(" Copyfile - '%s'\n", copyfile); printf(" Signature - '%s'\n", signature); printf(" Aliases - '%s'\n", aliasfilename); printf(" Editor - '%s'\n", editor); printf(" Checker - '%s'\n", checker); printf(" Subargs - '%s'\n", subargs); if(qflag == 0 && cflag == 1) printf(" File copy option is on\n"); if(qflag == 1 && cflag == 0) printf(" File copy on confirmation only\n"); continue; } if( (i = picko( av[1] ) ) < 0) { fprintf(stderr,"Option '%s' is invalid.\n", av[1]); continue; } select_o( i, &av[1] ); continue; } compress (bigbuf, bigbuf); /* so prefix works on multi-words */ if (bigbuf[0] == '\0') continue; /* just hit newline */ signal (SIGINT, onint); for (i = 0; !isnull (bigbuf[i]); i++) bigbuf[i] = uptolow (bigbuf[i]); if (prefix ("bcc", bigbuf)) { getaddr (bccname, bcc, YES, locname); bccflag = 1; continue; } /* "Edit" option (grandfathered to also accept "v" for visual edit) */ if (prefix ("edit body", bigbuf) || prefix("visual edit body", bigbuf)) { dropen( DRBEGIN ); if((tmpfd = open(tmpdrffile, 2, 0600)) < 0) { fprintf(stderr,"Cannot open temporary draft file %s\n", tmpdrffile); s_exit(-1); } if(lseek(tmpfd, 0L, 0) < 0) { fprintf(stderr,"Lseek failed on temporary draft file %s\n", tmpdrffile); s_exit(-1); } if(chmod(drffile, 0600) < 0) fprintf(stderr,"Could not make draft %s writable\n", drffile); /* Write the header info to the temporary draft */ dist = 0L; dist += write(tmpfd, fromname, strlen( fromname )); dist += write(tmpfd, from, strlen( from )); dist += write(tmpfd, "\n", 1); dist += write(tmpfd, toname, strlen( toname )); dist += write(tmpfd, to, strlen( to )); dist += write(tmpfd, "\n", 1); dist += write(tmpfd, ccname, strlen( ccname )); dist += write(tmpfd, cc, strlen( cc )); dist += write(tmpfd, "\n", 1); if(bccflag) { dist += write(tmpfd, bccname, strlen( bccname )); dist += write(tmpfd, bcc, strlen( bcc )); dist += write(tmpfd, "\n", 1); } dist += write(tmpfd, subjname, strlen( subjname )); dist += write(tmpfd, subject, strlen( subject )); dist += write(tmpfd, "\n", 1); if(lseek(drffd, 0L, 0) < 0) { fprintf(stderr,"Lseek failed on draft %s\n", drffile); s_exit(-1); } if(lseek(tmpfd, 0L, 2) < 0) { fprintf(stderr,"Lseek failed on temporary draft\n"); s_exit(-1); } /* Write the body into the temp. draft */ while((i = read(drffd, bigbuf, BBSIZE-1)) > 0) dist += write(tmpfd, bigbuf, i); if(truncate( tmpdrffile, dist) < 0) { fprintf(stderr,"Could not truncate temporary draft\n"); s_exit(-1); } if(lseek(tmpfd, 0L, 0) < 0) fprintf(stderr,"Lseek failed on temporary draft\n"); if(lseek(drffd, 0L, 0) < 0) fprintf(stderr,"Lseek failed on draft %s\n", drffile); dist = 0L; /* Copy temp. draft which contains headers and ** body back into draft file */ while((i = read(tmpfd, bigbuf, BBSIZE-1)) > 0) dist += write(drffd, bigbuf, i); if(truncate( drffile, dist ) < 0) fprintf(stderr,"Could not truncate draft %s\n", drffile); if(truncate( tmpdrffile, 0 ) < 0) fprintf(stderr,"Could not truncate temporary draft\n"); if(close( tmpfd ) < 0) fprintf(stderr,"Could not close temporary draft\n"); if(lseek(drffd, 0L, 0) < 0) fprintf(stderr,"Lseek failed on draft %s\n", drffile); if(chmod(drffile, 0400) < 0) fprintf(stderr,"Could not protect draft %s\n", drffile); /* Fire-up the editor */ goto edit; } /* "File include" option */ if (prefix ("file include", bigbuf)) { printf ("File: "); gather (bigbuf, BBSIZE - 1); if (bigbuf[0] == '\0') continue; infile = open (bigbuf, 0); if (inclfile[0] != '\0') { /* and include file */ inclfile[0] = '\0'; } if (infile < 0) { fprintf(stderr,"can't open: '%s'\n", bigbuf); continue; } dropen (DREND); body = TRUE; while ((i = read (infile, bigbuf, BBSIZE - 1)) > 0) write (drffd, bigbuf, i); (void) close (infile); printf (" ...included\n"); continue; } /* "Program run" option */ if (prefix ("program run", bigbuf)) { printf ("Program: "); fflush (stdout); if (gets (tempbuf) == NULL) continue; drclose (); /* ignore signals intended for subprocess */ old1 = signal (SIGHUP, SIG_IGN); old2 = signal (SIGINT, SIG_IGN); old3 = signal (SIGQUIT, SIG_IGN); if (fork () == 0) { signal (SIGHUP, old1); signal (SIGINT, orig); signal (SIGQUIT, old3); execlp ("sh", "send-shell", "-c", tempbuf, (char *)0); fprintf(stderr,"can't execute\n"); s_exit (-1); } wait (&stat); signal (SIGHUP, old1); /* restore signals */ signal (SIGINT, old2); signal (SIGQUIT, old3); dropen (DREND); continue; } /* "quit" option */ if (prefix ("quit", bigbuf) || prefix ("bye", bigbuf)) { byebye: if ( body && !nsent) { printf ("Without sending draft"); if (confirm ()) return; else continue; } drclose (); return; } /* "review message" option */ if (prefix ("review message", bigbuf)) { dropen( DRBEGIN ); /* Put header info into temp. draft */ if((nfd = open(tmpdrffile, 2, 0600)) < 0) { fprintf(stderr,"Can't open temporary file\n"); s_exit(-1); } if(lseek(nfd, 0L, 0) < 0) { fprintf(stderr,"Lseek failed on temporary file\n"); s_exit(-1); } if(write(nfd, fromname, strlen( fromname )) < 0) { fprintf(stderr,"Cannot write temporary file\n"); s_exit(-1); } write(nfd, from, strlen( from )); write(nfd, "\n", 1); if(to[0] != '\0') { write(nfd, toname, strlen( toname )); write(nfd, to, strlen( to )); write(nfd, "\n", 1); } else if(bccflag) { write(nfd, toname, strlen( toname )); write(nfd, "list: ;", 7); write(nfd, "\n", 1); } if(cc[0] != '\0') { write(nfd, ccname, strlen( ccname )); write(nfd, cc, strlen( cc )); write(nfd, "\n", 1); } if(bccflag) { write(nfd, bccname, strlen( bccname )); write(nfd, bcc, strlen( bcc )); write(nfd, "\n", 1); } if(subject[0] != '\0') { write(nfd, subjname, strlen( subjname )); write(nfd, subject, strlen( subject )); write(nfd, "\n", 1); } if(lseek(drffd, 0L, 0) < 0) fprintf(stderr,"Lseek failed on draft %s\n", drffile); /* Write the body into the temp. file */ while((i = read(drffd, bigbuf, BBSIZE - 1)) > 0) write(nfd, bigbuf, i); drclose(); if(pflag) { (void) close( nfd ); /* ignore signals intended for subprocess */ old1 = signal (SIGHUP, SIG_IGN); old2 = signal (SIGINT, SIG_IGN); old3 = signal (SIGQUIT, SIG_IGN); /* Start-up "more" program on the temp. draft */ if (fork () == 0) { signal (SIGHUP, old1); signal (SIGINT, orig); signal (SIGQUIT, old3); execlp ("more", "-c", tmpdrffile, 0); fprintf(stderr,"can't execute\n"); s_exit (-1); } wait (&stat); signal (SIGHUP, old1); /* restore signals */ signal (SIGINT, old2); signal (SIGQUIT, old3); } else /* If the paging option is off, just show it */ { if( lseek(nfd, 0L, 0) < 0 ) fprintf(stderr, "Lseek failed on temporary draft.\n"); while((i = read(nfd, bigbuf, BBSIZE - 1)) > 0) write( 1, bigbuf, i); (void) close( nfd ); } if(truncate(tmpdrffile, 0) < 0) fprintf(stderr,"truncate failed on temp. draft\n"); fflush( stdout ); continue; } /* "Check spelling" option */ if (prefix ("check spelling", bigbuf)) { drclose (); old1 = signal (SIGHUP, SIG_IGN); /* ignore signals intended for cheker */ old2 = signal (SIGINT, SIG_IGN); old3 = signal (SIGQUIT, SIG_IGN); if (fork () == 0) { signal (SIGHUP, old1); signal (SIGINT, orig); signal (SIGQUIT, old3); execlp (checker, checker, drffile, (char *)0); fprintf(stderr,"can't execute\n"); s_exit (-1); } wait (&stat); signal (SIGHUP, old1); /* restore signals */ signal (SIGINT, old2); signal (SIGQUIT, old3); dropen (DREND); continue; } /* "Post message" option */ if (prefix ("post message", bigbuf) || prefix ("send message", bigbuf)) { if (lastsend && lastsend == body) { printf ("Without changing anything"); if (!confirm ()) break; } signal (SIGINT, onint2); if( qflag == 1 ){ printf(" Do you want a file copy of this message ? "); fflush(stdout); fgets(tempbuf, sizeof(tempbuf), stdin ); if( tempbuf[0] == 'y' || tempbuf[0] == 'Y' || tempbuf[0] == '\n') cflag = 1; else cflag = 0; } post (); if ( qflag == 1 ) cflag = 0; /* *** auto-exit, upon successfull send, since draft is saved *** */ goto byebye; } /* help */ if (prefix ("?", bigbuf)) { printf ("bcc\n"); printf ("bye\n"); printf ("check spelling\n"); printf ("edit body\n"); printf ("file include\n"); printf ("program run\n"); printf ("quit\n"); printf ("review message\n"); printf ("send message\n"); printf ("set [option] [option value]\n"); continue; } printf (" unknown command (type ? for help)\n"); } /* end of loop */ }