Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

makexindex.cpp File Reference

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <celutil/basictypes.h>
#include <celutil/bytes.h>

Include dependency graph for makexindex.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
bool parseCommandLine (int argc, char *argv[])
void Usage ()
bool WriteCrossIndex (istream &in, ostream &out)
static void writeShort (ostream &out, int16 n)
static void writeUint (ostream &out, uint32 n)

Variables

static string inputFilename
static string outputFilename


Function Documentation

int main int  argc,
char *  argv[]
 

Definition at line 120 of file makexindex.cpp.

References inputFilename, outputFilename, parseCommandLine(), Usage(), and WriteCrossIndex().

00121 {
00122     if (!parseCommandLine(argc, argv) || inputFilename.empty())
00123     {
00124         Usage();
00125         return 1;
00126     }
00127 
00128     istream* inputFile = &cin;
00129     if (!inputFilename.empty())
00130     {
00131         inputFile = new ifstream(inputFilename.c_str(), ios::in);
00132         if (!inputFile->good())
00133         {
00134             cerr << "Error opening input file " << inputFilename << '\n';
00135             return 1;
00136         }
00137     }
00138 
00139     ostream* outputFile = &cout;
00140     if (!outputFilename.empty())
00141     {
00142         outputFile = new ofstream(outputFilename.c_str(), ios::out | ios::binary);
00143         if (!outputFile->good())
00144         {
00145             cerr << "Error opening output file " << outputFilename << '\n';
00146             return 1;
00147         }
00148     }
00149 
00150     bool success = WriteCrossIndex(*inputFile, *outputFile);
00151 
00152     return success ? 0 : 1;
00153 }

bool parseCommandLine int  argc,
char *  argv[]
 

Definition at line 32 of file makexindex.cpp.

References inputFilename, and outputFilename.

00033 {
00034     int i = 1;
00035     int fileCount = 0;
00036 
00037     while (i < argc)
00038     {
00039         if (argv[i][0] == '-')
00040         {
00041             cerr << "Unknown command line switch: " << argv[i] << '\n';
00042             return false;
00043         }
00044         else
00045         {
00046             if (fileCount == 0)
00047             {
00048                 // input filename first
00049                 inputFilename = string(argv[i]);
00050                 fileCount++;
00051             }
00052             else if (fileCount == 1)
00053             {
00054                 // output filename second
00055                 outputFilename = string(argv[i]);
00056                 fileCount++;
00057             }
00058             else
00059             {
00060                 // more than two filenames on the command line is an error
00061                 return false;
00062             }
00063             i++;
00064         }
00065     }
00066 
00067     return true;
00068 }

void Usage  ) 
 

Definition at line 26 of file makexindex.cpp.

00027 {
00028     cerr << "Usage: makexindex [input file] [output file]\n";
00029 }

bool WriteCrossIndex istream &  in,
ostream &  out
 

Definition at line 85 of file makexindex.cpp.

References writeShort(), and writeUint().

Referenced by main().

00086 {
00087     // Write the header
00088     out.write("CELINDEX", 8);
00089 
00090     // Write the version
00091     writeShort(out, 0x0100);
00092     
00093     unsigned int record = 0;
00094     while (!in.eof())
00095     {
00096         unsigned int catalogNumber;
00097         unsigned int celCatalogNumber;
00098 
00099         in >> catalogNumber;
00100         if (in.eof())
00101             return true;
00102 
00103         in >> celCatalogNumber;
00104         if (!in.good())
00105         {
00106             cerr << "Error parsing record #" << record << '\n';
00107             return false;
00108         }
00109 
00110         writeUint(out, (uint32) catalogNumber);
00111         writeUint(out, (uint32) celCatalogNumber);
00112 
00113         record++;
00114     }
00115 
00116     return true;
00117 }

static void writeShort ostream &  out,
int16  n
[static]
 

Definition at line 78 of file makexindex.cpp.

References LE_TO_CPU_INT16.

00079 {
00080     LE_TO_CPU_INT16(n, n);
00081     out.write(reinterpret_cast<char*>(&n), sizeof n);
00082 }

static void writeUint ostream &  out,
uint32  n
[static]
 

Definition at line 71 of file makexindex.cpp.

References LE_TO_CPU_INT32.

00072 {
00073     LE_TO_CPU_INT32(n, n);
00074     out.write(reinterpret_cast<char*>(&n), sizeof n);
00075 }


Variable Documentation

string inputFilename [static]
 

Definition at line 22 of file makexindex.cpp.

string outputFilename [static]
 

Definition at line 23 of file makexindex.cpp.


Generated on Sat Jan 14 22:33:04 2006 for Celestia by  doxygen 1.4.1