"Fossies" - the Fresh Open Source Software Archive

Member "CSSC-1.4.1/src/prs.cc" (7 May 2019, 4071 Bytes) of package /linux/privat/CSSC-1.4.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "prs.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.4.0_vs_1.4.1.

    1 /*
    2  * prs.cc: Part of GNU CSSC.
    3  *
    4  *  Copyright (C) 1997, 1998, 1999, 2001, 2007, 2008, 2009, 2010, 2011,
    5  *  2014, 2019 Free Software Foundation, Inc.
    6  *
    7  *  This program is free software: you can redistribute it and/or modify
    8  *  it under the terms of the GNU General Public License as published by
    9  *  the Free Software Foundation, either version 3 of the License, or
   10  *  (at your option) any later version.
   11  *
   12  *  This program is distributed in the hope that it will be useful,
   13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15  *  GNU General Public License for more details.
   16  *
   17  *  You should have received a copy of the GNU General Public License
   18  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
   19  *
   20  * CSSC was originally Based on MySC, by Ross Ridge, which was
   21  * placed in the Public Domain.
   22  *
   23  *
   24  * Prints selected parts of an SCCS file.
   25  *
   26  */
   27 
   28 #include <config.h>
   29 #include <string>
   30 #include "cssc.h"
   31 #include "fileiter.h"
   32 #include "sccsfile.h"
   33 #include "my-getopt.h"
   34 #include "version.h"
   35 #include "delta.h"
   36 #include "except.h"
   37 
   38 
   39 void
   40 usage() {
   41     fprintf(stderr,
   42 "usage: %s [-aelDRV] [-c cutoff] [-d format] [-r SID] file ...\n",
   43         prg_name);
   44 }
   45 
   46 int
   47 main(int argc, char **argv)
   48 {
   49   Cleaner arbitrary_name;
   50   int c;
   51   std::string format = ":Dt:\t:DL:\nMRs:\n:MR:COMMENTS:\n:C:";
   52   sid rid(sid::null_sid());
   53   /* enum */ sccs_file::when selected = sccs_file::SIDONLY;
   54   bool all_deltas = false;
   55   sccs_date cutoff_date;
   56   int default_processing = 1;
   57 
   58   if (argc > 0)
   59     set_prg_name(argv[0]);
   60   else
   61     set_prg_name("prs");
   62 
   63   ASSERT(!rid.valid());
   64 
   65   CSSC_Options opts(argc, argv, "d!Dr!elc!aV");
   66   for(c = opts.next();
   67       c != CSSC_Options::END_OF_ARGUMENTS;
   68       c = opts.next())
   69     {
   70       switch (c)
   71     {
   72     default:
   73       errormsg("Unsupported option: '%c'", c);
   74       return 2;
   75 
   76     case 'd':
   77       format = opts.getarg();
   78       /* specifying -d means, stop after the first match. */
   79       default_processing = 0;
   80       break;
   81 
   82     case 'D':   // obsolete MySC-ism.
   83       default_processing = 0;
   84       break;
   85 
   86     case 'r':
   87       if (strlen(opts.getarg()))
   88         {
   89           rid = sid(opts.getarg());
   90           if (!rid.valid() || rid.partial_sid())
   91         {
   92           errormsg("Invaild SID: '%s'", opts.getarg());
   93           return 2;
   94         }
   95         }
   96       else
   97         {
   98           // default: get the most recent delta.
   99         }
  100       default_processing = 0;
  101       break;
  102 
  103     case 'c':
  104       cutoff_date = sccs_date(opts.getarg());
  105       if (!cutoff_date.valid())
  106         {
  107           errormsg("Invalid cutoff date: '%s'",
  108                opts.getarg());
  109           return 2;
  110         }
  111       break;
  112 
  113     case 'e':
  114       selected = sccs_file::EARLIER;
  115       default_processing = 0;
  116       break;
  117 
  118     case 'l':
  119       selected = sccs_file::LATER;
  120       default_processing = 0;
  121       break;
  122 
  123     case 'a':
  124       all_deltas = true;
  125       break;
  126 
  127     case 'V':
  128       version();
  129       break;
  130     }
  131 
  132     }
  133 
  134   if (selected == sccs_file::SIDONLY && cutoff_date.valid())
  135     {
  136       errormsg("Either the -e or -l switch must used with a"
  137            " cutoff date.");
  138       return 2;
  139     }
  140 
  141   if (default_processing)
  142     {
  143       selected = sccs_file::EARLIER;
  144     }
  145 
  146   sccs_file_iterator iter(opts);
  147   if (! iter.using_source())
  148     {
  149       errormsg("No SCCS file specified.");
  150       return 1;
  151     }
  152 
  153   int retval = 0;
  154 
  155   while (iter.next())
  156     {
  157       try
  158     {
  159       sccs_name &name = iter.get_name();
  160       sccs_file file(name, sccs_file::READ);
  161 
  162       if (default_processing)
  163         {
  164           printf("%s:\n\n", name.c_str());
  165         }
  166       bool matched = false;
  167       if (!file.prs(stdout, format, rid, cutoff_date, selected,
  168             all_deltas, &matched))
  169         {
  170           retval = 1;
  171         }
  172       if (ferror(stdout))
  173         {
  174           errormsg("%s: Ouput file error.", name.c_str());
  175           retval = 1;
  176         }
  177       if (!matched)
  178         {
  179           if (rid.valid())
  180         {
  181           errormsg("%s: Requested SID doesn't exist.", name.c_str());
  182           retval = 1;
  183         }
  184         }
  185     } // end of try block.
  186       catch (CsscExitvalException e)
  187     {
  188       if (e.exitval > retval)
  189         retval = e.exitval;
  190     }
  191     }
  192   return retval;
  193 }
  194 
  195 /* Local variables: */
  196 /* mode: c++ */
  197 /* End: */