Panda3D
 All Classes Functions Variables Enumerations
newheader.cxx
00001 // Filename: newheader.cxx
00002 // Created by:  drose (05Jul04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "dtoolbase.h"
00016 
00017 #include <stdio.h>
00018 #include <time.h>
00019 #include <stdlib.h>
00020 
00021 const char *cxx_style = 
00022 "// Filename: %s\n"
00023 "// Created by:  %s (%s)\n"
00024 "//\n"
00025 "////////////////////////////////////////////////////////////////////\n"
00026 "//\n"
00027 "// PANDA 3D SOFTWARE\n"
00028 "// Copyright (c) Carnegie Mellon University.  All rights reserved.\n"
00029 "//\n"
00030 "// All use of this software is subject to the terms of the revised BSD\n"
00031 "// license.  You should have received a copy of this license along\n"
00032 "// with this source code in a file named \"LICENSE.\"\n"
00033 "//\n"
00034 "////////////////////////////////////////////////////////////////////\n"
00035 "\n";
00036 
00037 const char *c_style = 
00038 "/* Filename: %s\n"
00039 " * Created by:  %s (%s)\n"
00040 " *\n"
00041 " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"
00042 " *\n"
00043 " * PANDA 3D SOFTWARE\n"
00044 " * Copyright (c) Carnegie Mellon University.  All rights reserved.\n"
00045 " *\n"
00046 " * All use of this software is subject to the terms of the revised BSD\n"
00047 " * license.  You should have received a copy of this license along\n"
00048 " * with this source code in a file named \"LICENSE.\"\n"
00049 " *\n"
00050 " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */\n"
00051 "\n";
00052 
00053 struct FileDef {
00054   const char *extension;
00055   const char *header;
00056 };
00057 
00058 FileDef file_def[] = {
00059   { "h", cxx_style },
00060   { "cxx", cxx_style },
00061   { "I", cxx_style },
00062   { "T", cxx_style },
00063   { "c", c_style },
00064   { NULL, NULL },
00065 };
00066 
00067 void
00068 generate_header(const char *header, const string &filename) {
00069   const char *username = getenv("USER");
00070   if (username == NULL) {
00071     username = "";
00072   }
00073 
00074   static const size_t max_date_buffer = 128;
00075   char date_buffer[max_date_buffer];
00076   time_t now = time(NULL);
00077   strftime(date_buffer, max_date_buffer, "%d%b%y", localtime(&now));
00078 
00079   printf(header, filename.c_str(), username, date_buffer);
00080 }
00081 
00082 int
00083 main(int argc, char *argv[]) {
00084   if (argc < 2) {
00085     cerr << "Must specify the filename to generate a header for.\n";
00086     exit(1);
00087   }
00088 
00089   string filename = argv[1];
00090   size_t dot = filename.rfind('.');
00091   if (dot == string::npos) {
00092     // No extension, no header.
00093     return 0;
00094   }
00095 
00096   string extension = filename.substr(dot + 1);
00097 
00098   size_t i = 0;
00099   while (file_def[i].extension != NULL) {
00100     if (extension == file_def[i].extension) {
00101       generate_header(file_def[i].header, filename);
00102       return 0;
00103     }
00104     i++;
00105   }
00106 
00107   // No matching extension, no problem.
00108   return 0;
00109 }
 All Classes Functions Variables Enumerations