"Fossies" - the Fresh Open Source Software Archive

Member "tin-2.4.1/src/version.c" (12 Oct 2016, 4430 Bytes) of archive /linux/misc/tin-2.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 "version.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.4.0_vs_2.4.1.

    1 /*
    2  *  Project   : tin - a Usenet reader
    3  *  Module    : version.c
    4  *  Author    : U. Janssen
    5  *  Created   : 2003-05-11
    6  *  Updated   : 2013-11-15
    7  *  Notes     :
    8  *
    9  * Copyright (c) 2003-2017 Urs Janssen <urs@tin.org>
   10  * All rights reserved.
   11  *
   12  * Redistribution and use in source and binary forms, with or without
   13  * modification, are permitted provided that the following conditions
   14  * are met:
   15  * 1. Redistributions of source code must retain the above copyright
   16  *    notice, this list of conditions and the following disclaimer.
   17  * 2. Redistributions in binary form must reproduce the above copyright
   18  *    notice, this list of conditions and the following disclaimer in the
   19  *    documentation and/or other materials provided with the distribution.
   20  * 3. The name of the author may not be used to endorse or promote
   21  *    products derived from this software without specific prior written
   22  *    permission.
   23  *
   24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
   25  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
   28  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
   30  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   33  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   35  */
   36 
   37 
   38 #ifndef TIN_H
   39 #   include "tin.h"
   40 #endif /* !TIN_H */
   41 
   42 
   43 /*
   44  * line     is the entire line we should check
   45  * skip     must be the leading portion of the version line not including the
   46  *          version number (which must be a dotted triple)
   47  * version  is the version number (dotted triple) we expect to match
   48  *
   49  * returns RC_IGNORE     1st args dotted triple matches 3rd arg
   50  *         RC_UPGRADE    1st args dotted triple is older than 3rd arg
   51  *         RC_DOWNGRADE  1st args dotted triple is newer than 3rd arg
   52  *         RC_ERROR      3rd arg is not a dotted triple (usage error)
   53  *
   54  * Don't make the arguments to sscanf() consts, as some old systems require
   55  * them to writable (but do not change them)
   56  */
   57 enum rc_state
   58 check_upgrade(
   59     char *line,
   60     const char *skip,
   61     const char *version)
   62 {
   63     char *format;
   64     char *lskip = my_strdup(skip);
   65     char *lversion = my_strdup(version);
   66     char fmt[10];
   67     int rc_majorv, rc_minorv, rc_subv; /* version numbers in the file */
   68     int c_majorv, c_minorv, c_subv; /* version numbers we require */
   69     size_t len;
   70 
   71     rc_majorv = rc_minorv = rc_subv = c_majorv = c_minorv = c_subv = -1;
   72     strcpy(fmt, "%d.%d.%d"); /* we are expecting dotted triples */
   73     len = strlen(lskip) + strlen(fmt) + 1; /* format buffer len */
   74     format = my_malloc(len + 1);
   75     snprintf(format, len, "%s%s", lskip, fmt);
   76     free(lskip);
   77 
   78     if (sscanf(line, format, &rc_majorv, &rc_minorv, &rc_subv) != 3) {
   79         free(format);
   80         free(lversion);
   81         return RC_ERROR;
   82     }
   83 
   84     free(format);
   85 
   86     /* we can't parse our own version number - should never happen */
   87     if (sscanf(lversion, fmt, &c_majorv, &c_minorv, &c_subv) != 3) {
   88         free(lversion);
   89         return RC_ERROR;
   90     }
   91     free(lversion);
   92 
   93     if (c_majorv == rc_majorv && c_minorv == rc_minorv && c_subv == rc_subv)
   94         return RC_IGNORE;
   95 
   96     if (rc_majorv > c_majorv ||
   97         (rc_majorv == c_majorv && rc_minorv > c_minorv) ||
   98         (rc_majorv == c_majorv && rc_minorv == c_minorv && rc_subv > c_subv))
   99         return RC_DOWNGRADE;
  100 
  101     return RC_UPGRADE;
  102 }
  103 
  104 
  105 void
  106 upgrade_prompt_quit(
  107     enum rc_state reason,
  108     const char *file)
  109 {
  110     switch (reason) {
  111         case RC_UPGRADE:
  112             error_message(2, _(txt_warn_update), VERSION, file);
  113             break;
  114 
  115         case RC_DOWNGRADE:
  116             error_message(2, _(txt_warn_downgrade), VERSION, file);
  117             break;
  118 
  119         case RC_ERROR: /* can't parse internal version string, should not happen */
  120             error_message(2, txt_warn_unrecognized_version);
  121             free(tin_progname);
  122             giveup();
  123             /* NOTREACHED */
  124             break;
  125 
  126         default:    /* should no happen */
  127             return;
  128     }
  129 
  130     error_message(2, _(txt_return_key));
  131 
  132     /*
  133      * TODO: document, use something unbuffered here
  134      * NOTE: these keys can not be remapped
  135      */
  136     switch (getchar()) {
  137         case 'q':
  138         case 'Q':
  139         case ESC:
  140             free(tin_progname);
  141             giveup();
  142             /* NOTREACHED */
  143             break;
  144 
  145         default:
  146             break;
  147     }
  148 }