home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / main.c < prev    next >
C/C++ Source or Header  |  1992-02-23  |  8KB  |  251 lines

  1. char rcsid[] = "$Id: main.c,v 1.23 89/11/20 00:06:34 berliner Exp $\nPatch level ###\n";
  2.  
  3. /*
  4.  *    Copyright (c) 1989, Brian Berliner
  5.  *
  6.  *    You may distribute under the terms of the GNU General Public License
  7.  *    as specified in the README file that comes with the CVS 1.0 kit.
  8.  *
  9.  * This is the main C driver for the CVS system.
  10.  *
  11.  * Credit to Dick Grune, Vrije Universiteit, Amsterdam, for writing
  12.  * the shell-script CVS system that this is based on.
  13.  *
  14.  * Usage:
  15.  *    cvs [options] command [options] [files/modules...]
  16.  *
  17.  * Where "command" is composed of:
  18.  *        checkout    Check out a module/dir/file
  19.  *        update        Brings work tree in sync with repository
  20.  *        commit        Checks files into the repository
  21.  *        diff        Runs diffs between revisions
  22.  *        log        Prints to "rlog" information for files
  23.  *        add        Adds an entry to the repository
  24.  *        remove        Removes an entry from the repository
  25.  *        status        Status info on the revisions
  26.  *        join        Merge two RCS revisions
  27.  *        patch        "patch" format diff listing between releases
  28.  *        tag        Add/delete a symbolic tag to the RCS file
  29.  *
  30.  * Future:
  31.  *        checkin        Adds new *directories* to the repository
  32.  *                Currently being done by an external shell
  33.  *                script.
  34.  *
  35.  * Brian Berliner
  36.  * 4/20/89
  37.  */
  38.  
  39. #include "cvs.h"
  40. #include "patchlevel.h"
  41.  
  42. char *progname, *command;
  43.  
  44. char *fileargv[MAXFILEPERDIR];
  45. int fileargc;
  46.  
  47. int use_editor = TRUE;
  48. int cvswrite = !CVSREAD_DFLT;
  49. int really_quiet = FALSE;
  50. int quiet = FALSE;
  51. int force_tag_match = FALSE;
  52.  
  53. /*
  54.  * Globals for the lists created in Collect_Sets()
  55.  */
  56. char Clist[MAXLISTLEN], Glist[MAXLISTLEN], Mlist[MAXLISTLEN];
  57. char Olist[MAXLISTLEN], Alist[MAXLISTLEN], Rlist[MAXLISTLEN];
  58. char Wlist[MAXLISTLEN], Llist[MAXLISTLEN], Blist[MAXLISTLEN];
  59. char Dlist[MAXLISTLEN];
  60.  
  61. /*
  62.  * Globals which refer to a particular file
  63.  */
  64. char Repository[MAXPATHLEN];
  65. char User[MAXPATHLEN], Rcs[MAXPATHLEN];
  66. char VN_User[MAXPATHLEN], TS_User[MAXPATHLEN];
  67. char VN_Rcs[MAXPATHLEN], TS_Rcs[MAXPATHLEN];
  68. char Tag[MAXPATHLEN], Date[MAXPATHLEN];
  69.  
  70. /*
  71.  * Options is used to hold options passed on to system(), while prog
  72.  * is alwys used in the calls to system().
  73.  */
  74. char Options[MAXPATHLEN];
  75. char prog[MAXPROGLEN];
  76.  
  77. /*
  78.  * Defaults, for the environment variables that are not set
  79.  */
  80. char *Tmpdir = TMPDIR_DFLT;
  81. char *Rcsbin = RCSBIN_DFLT;
  82. char *Editor = EDITOR_DFLT;
  83. char *CVSroot = CVSROOT_DFLT;
  84. char *Rcsext = "";
  85.  
  86. main(argc, argv)
  87.     int argc;
  88.     char *argv[];
  89. {
  90.     extern char *getenv();
  91.     register char *cp;
  92.     register int c;
  93.     int help = FALSE, err = 0;
  94.  
  95.     /*
  96.      * Just save the last component of the path for error messages
  97.      */
  98.     if ((progname = rindex_sep(argv[0])) == NULL)
  99.     progname = argv[0];
  100.     else
  101.     progname++;
  102.  
  103.     /*
  104.      * Query the environment variables up-front, so that
  105.      * they can be overridden by command line arguments
  106.      */
  107.     if ((cp = getenv(TMPDIR_ENV)) != NULL)
  108.     Tmpdir = cp;
  109.     if ((cp = getenv(RCSBIN_ENV)) != NULL)
  110.     Rcsbin = cp;
  111.     if ((cp = getenv(EDITOR_ENV)) != NULL)
  112.     Editor = cp;
  113.     if ((cp = getenv(CVSROOT_ENV)) != NULL)
  114.     CVSroot = cp;
  115.     if ((cp = getenv(RCSINIT_ENV)) != NULL)
  116.         if ((cp = strstr(cp, "-x")) != NULL)
  117.             if ((cp = strstr(cp, ",v")) != NULL)
  118.                 Rcsext = ",v";
  119.     if (getenv(CVSREAD_ENV) != NULL)
  120.     cvswrite = FALSE;
  121.  
  122.     optind = 1;
  123.     while ((c = getopt(argc, argv, "rwvb:e:d:H")) != -1) {
  124.     switch (c) {
  125.     case 'r':
  126.         cvswrite = FALSE;
  127.         break;
  128.     case 'w':
  129.         cvswrite = TRUE;
  130.         break;
  131.     case 'v':
  132.         (void) sprintf(index(rcsid, '#'), "%d\n", PATCHLEVEL);
  133.         (void) fputs(rcsid, stdout);
  134.         (void) fputs("\nCopyright (c) 1989, Brian Berliner\n\n\
  135. CVS may be copied only under the terms of the GNU General Public License,\n\
  136. a copy of which can be found with the CVS 1.0 distribution kit.\n", stdout);
  137.         exit(0);
  138.         break;
  139.     case 'b':
  140.         Rcsbin = optarg;
  141.         break;
  142.     case 'e':
  143.         Editor = optarg;
  144.         break;
  145.     case 'd':
  146.         CVSroot = optarg;
  147.         break;
  148.     case 'H':
  149.         help = TRUE;
  150.         break;
  151.     case '?':
  152.     default:
  153.         usage();
  154.     }
  155.     }
  156.     argc -= optind;
  157.     argv += optind;
  158.     if (argc < 1)
  159.     usage();
  160.  
  161.     /*
  162.      * Specifying just the '-H' flag to the sub-command causes a Usage
  163.      * message to be displayed.
  164.      */
  165.     command = cp = argv[0];
  166.     if (help == TRUE || (argc > 1 && strcmp(argv[1], "-H") == 0))
  167.     argc = -1;
  168.  
  169.     /*
  170.      * Make standard output line buffered, so that progress can be
  171.      * monitored when redirected to a file, but only when we're not
  172.      * running the "patch" command, as it generates lots of output
  173.      * to stdout -- just leave it block buffered.
  174.      */
  175.     if (strcmp(cp, "patch") != 0)
  176.     setvbuf(stdout, NULL, _IOLBF, 1024);
  177.  
  178.     if (strcmp(cp, "update") == 0)
  179.     err += update(argc, argv);
  180.     else if (strcmp(cp, "commit") == 0 || strcmp(cp, "ci") == 0)
  181.     commit(argc, argv);
  182.     else if (strcmp(cp, "diff") == 0)
  183.     diff(argc, argv);
  184.     else if (strcmp(cp, "checkout") == 0 || strcmp(cp, "co") == 0 ||
  185.         strcmp(cp, "get") == 0)
  186.     checkout(argc, argv);
  187.     else if (strcmp(cp, "log") == 0)
  188.     log(argc, argv);
  189.     else if (strcmp(cp, "status") == 0)
  190.     status(argc, argv);
  191.     else if (strcmp(cp, "add") == 0)
  192.     add(argc, argv);
  193.     else if (strcmp(cp, "remove") == 0)
  194.     _remove(argc, argv);
  195.     else if (strcmp(cp, "join") == 0)
  196.     join(argc, argv);
  197.     else if (strcmp(cp, "patch") == 0)
  198.     patch(argc, argv);
  199.     else if (strcmp(cp, "tag") == 0)
  200.     tag(argc, argv);
  201.     else
  202.     usage();            /* oops.. no match */
  203.     Lock_Cleanup(0);
  204.     exit(err);
  205. }
  206.  
  207. static
  208. usage()
  209. {
  210.     (void) fputs("\nCVS 1.0, Copyright (c) 1989-91, Brian Berliner\n\n\
  211. CVS may be copied only under the terms of the GNU General Public License,\n\
  212. a copy of which can be found with the CVS 1.0 distribution kit.\n\n", stderr);
  213.     (void) sprintf(index(rcsid, '#'), "%d\n\n", PATCHLEVEL);
  214.     (void) fputs(rcsid, stderr);
  215.  
  216.     (void) fprintf(stderr,
  217.     "Usage: %s [cvs-options] command [command-options] [files...]\n",
  218.            progname);
  219.     (void) fprintf(stderr, "\tWhere 'cvs-options' are:\n");
  220.     (void) fprintf(stderr, "\t\t-r\t\tMake checked-out files read-only\n");
  221.     (void) fprintf(stderr,
  222.     "\t\t-w\t\tMake checked-out files read-write (default)\n");
  223.     (void) fprintf(stderr, "\t\t-v\t\tCVS version and copyright\n");
  224.     (void) fprintf(stderr, "\t\t-b bindir\tFind RCS programs in 'bindir'\n");
  225.     (void) fprintf(stderr,
  226.     "\t\t-e editor\tUse 'editor' for editing log information\n");
  227.     (void) fprintf(stderr, "\t\t-d CVS_root_directory\n");
  228.     (void) fprintf(stderr, "\t\t\t\t\Points to the root of the CVS tree\n");
  229.     (void) fprintf(stderr, "\tand 'command' is:\n");
  230.     (void) fprintf(stderr, "\t\tcheckout\tCreates a new CVS directory\n");
  231.     (void) fprintf(stderr,
  232.     "\t\tupdate\t\tBrings work tree in sync with repository\n");
  233.     (void) fprintf(stderr,
  234.     "\t\tcommit\t\tChecks files into the repository\n");
  235.     (void) fprintf(stderr, "\t\tdiff\t\tRuns diffs between revisions\n");
  236.     (void) fprintf(stderr,
  237.     "\t\tlog\t\tPrints out 'rlog' information for files\n");
  238.     (void) fprintf(stderr, "\t\tstatus\t\tStatus info on the revisions\n");
  239.     (void) fprintf(stderr, "\t\tadd\t\tAdds an entry to the repository\n");
  240.     (void) fprintf(stderr,
  241.     "\t\tremove\t\tRemoves an entry from the repository\n");
  242.     (void) fprintf(stderr,
  243.     "\t\tjoin\t\tJoins an RCS revision with the head on checkout\n");
  244.     (void) fprintf(stderr,
  245.     "\t\tpatch\t\t\"patch\" format diffs between releases\n");
  246.     (void) fprintf(stderr, "\t\ttag\t\tAdd a symbolic tag to the RCS file\n");
  247.     (void) fprintf(stderr,
  248.     "\tSpecify the '-H' option to each command for Usage information\n");
  249.     exit(1);
  250. }
  251.