home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / eel / cpyrit01.zip / COPYRITE.E < prev   
Text File  |  1991-08-08  |  4KB  |  143 lines

  1. /*
  2.  * Copyright header commands for Epsilon 5.0
  3.  *
  4.  * Copyright (C) 1991, K. Shane Hartman
  5.  *
  6.  * This file is free software; you can redistribute it and/or modify
  7.  * it so long as this notice is preserved and no fee is charged (other than 
  8.  * reasonable media fees) for distribution.  You are forbidden to deny these
  9.  * rights to any other user of Epsilon.  Lugaru Software Ltd. may incorporate 
  10.  * any and all of this code into Epsilon and have all rights to
  11.  * the code, since it is only useful for Epsilon.
  12.  *
  13.  * This file is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  16.  *
  17.  * Revision History:
  18.  * Send comments, bug fixes, suggestions to shane@ai.mit.edu
  19.  *
  20.  * Version 1.0: 08/02/91 shane@ai.mit.edu 
  21.  * Version 1.1: 08/02/91 shane@ai.mit.edu Fix prompting for user.
  22.  *
  23.  * This program provides the command M-x new file.  It inserts a header at
  24.  * the top of a new file that contains a copyright message (such as my 
  25.  * company requires).
  26.  *
  27.  * The header looks like this (for example)
  28.  *
  29.  * copyrite.e
  30.  *
  31.  * Created by Shane, 08/02/91 01:23
  32.  * 
  33.  * Copyright (C) 1991, Software Productivity Research, Inc.
  34.  * All rights reserved.
  35.  *
  36.  * The command knows how to comment things by use of the variables 
  37.  * comment_start and comment_end, although it will work for C without
  38.  * these variables since I hardwired it.  Other modes require you to
  39.  * set these variables.  The filename (copyrite.e) part is taken from
  40.  * the variable filename if that exists, else bufname if that exists,
  41.  * else "Unknown".  The user_name part (Shane) is taken from the 
  42.  * variable user_name if that is set, else the environment variable 
  43.  * USER, else it prompts.  The holder of the copyright is taken from
  44.  * the variable copyright_holder.
  45.  */
  46.  
  47. #include "eel.h"
  48.  
  49. #ifdef SPR
  50.  
  51. #include "vardefs.h"
  52.  
  53. #else
  54.  
  55. buffer char *comment_start;             /* Set this on a per mode basis */
  56. buffer char *comment_end;
  57.  
  58. /*
  59.  * Set this to the owner of the copyright (your company).
  60.  */
  61. char copyright_holder[48] = "";
  62.  
  63. /*
  64.  * Set this to your user name (or set the environment variable USER).  If
  65.  * neither is set, the command will prompt.
  66.  */
  67. char user_name[16] = "";
  68.  
  69. #endif /* SPR */
  70.  
  71. /*
  72.  * With argument, prompts for user name and holder, else takes from 
  73.  * defaults as discussed above.
  74.  */
  75. command new_file ()
  76. {
  77.   int *where = alloc_spot ();
  78.   struct time_info tinfo;
  79.   char copyright[80];
  80.   char *user = has_arg ? NULL : (*user_name ? user_name : NULL);
  81.   char *fname = filename;
  82.  
  83.   time_and_day (&tinfo);
  84.   if (!user)
  85.   {
  86.     if (!has_arg) 
  87.       user = getenv ("USER");
  88.     if ((!user || !*user) && !*user_name)
  89.     {
  90.       get_string (user_name, "Who are you: ");
  91.       if (!*user_name)
  92.         quick_abort ();
  93.       else
  94.         user = user_name;
  95.     }
  96.   }
  97.   if (has_arg || !*copyright_holder)
  98.     get_string (copyright_holder, "Copyright holder: ");
  99.   if (!*copyright_holder)
  100.     quick_abort ();
  101.   if (fname)
  102.   {
  103.     struct file_info info;
  104.     
  105.     if (check_file (fname, &info))
  106.     {
  107.       tinfo.year = info.year;
  108.       tinfo.month = info.month;
  109.       tinfo.day = info.day;
  110.       tinfo.hour = info.hour;
  111.       tinfo.minute = info.minute;
  112.       tinfo.second = info.second;
  113.       fname = get_tail (fname, 0);
  114.     }
  115.     else
  116.     {
  117.       fname = bufname;
  118.       if (!fname)
  119.         fname = "unknown";
  120.     }
  121.   }
  122.   point = 0;
  123.   sprintf (copyright, "Copyright (C) %d, %s", tinfo.year, copyright_holder);
  124.   if (!strfcmp (mode, "C") || !strfcmp (mode, "GnuC"))
  125.   {
  126.     bprintf ("/*\n * %s\n *\n * Created by %s, %02d/%02d/%02d %02d:%02d\n * \n * %s\n * All rights reserved.\n */\n",
  127.              fname, user,
  128.              tinfo.month, tinfo.day, tinfo.year - 1900, tinfo.hour, tinfo.minute,
  129.              copyright);
  130.   }
  131.   else
  132.   {
  133.     bprintf ("%s\n%s %s\n%s\n%s Created by %s, %02d/%02d/%02d %02d:%02d\n%s\n%s %s\n%s All rights reserved.\n%s\n",
  134.              comment_start, comment_start, fname, 
  135.              comment_start, comment_start, user,
  136.              tinfo.month, tinfo.day, tinfo.year - 1900, tinfo.hour, tinfo.minute,
  137.              comment_start, comment_start, copyright, comment_start, comment_start);
  138.   }
  139.   point = *where;
  140.   free_spot (where);
  141. }
  142.  
  143.