[BACK]Return to util.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Diff for /src/usr.bin/cvs/util.c between version 1.50 and 1.51

version 1.50, 2005/08/17 08:35:53 version 1.51, 2005/09/05 19:29:42
Line 281 
Line 281 
         return (0);          return (0);
 }  }
   
   
 /*  /*
  * cvs_getargv()   * cvs_getargv()
  *   *
Line 788 
Line 787 
         }          }
   
         return (buf);          return (buf);
   }
   
   /*
    * cvs_write_tagfile()
    *
    * Write the CVS/Tag file for current directory.
    */
   void
   cvs_write_tagfile(char *tag, char *date, int nb)
   {
           FILE *fp;
           char tagpath[MAXPATHLEN];
   
           if (cvs_noexec == 1)
                   return;
   
           if (strlcpy(tagpath, CVS_PATH_TAG, sizeof(tagpath)) >= sizeof(tagpath))
                   return;
   
           if ((tag != NULL) || (date != NULL)) {
                   fp = fopen(tagpath, "w+");
                   if (fp == NULL) {
                           if (errno != ENOENT)
                                   cvs_log(LP_NOTICE,
                                       "failed to open `%s' : %s", tagpath,
                                       strerror(errno));
                           return;
                   }
                   if (tag != NULL) {
                           if (nb != 0)
                                   fprintf(fp, "N%s\n", tag);
                           else
                                   fprintf(fp, "T%s\n", tag);
                   } else {
                           fprintf(fp, "D%s\n", date);
                   }
                   (void)fclose(fp);
           } else {
                   cvs_unlink(tagpath);
                   return;
           }
   }
   
   /*
    * cvs_parse_tagfile()
    *
    * Parse the CVS/Tag file for current directory.
    *
    * If it contains a branch tag, sets <tagp>.
    * If it contains a date, sets <datep>.
    * If it contains a non-branch tag, sets <nbp>.
    *
    * Returns nothing but an error message, and sets <tagp>, <datep> to NULL
    * and <nbp> to 0.
    */
   void
   cvs_parse_tagfile(char **tagp, char **datep, int *nbp)
   {
           FILE *fp;
           int linenum;
           size_t len;
           char linebuf[128], tagpath[MAXPATHLEN];
   
           if (tagp != NULL)
                   *tagp = (char *)NULL;
   
           if (datep != NULL)
                   *datep = (char *)NULL;
   
           if (nbp != NULL)
                   *nbp = 0;
   
           if (strlcpy(tagpath, CVS_PATH_TAG, sizeof(tagpath)) >= sizeof(tagpath))
                   return;
   
           fp = fopen(tagpath, "r");
           if (fp == NULL) {
                   if (errno != ENOENT)
                           cvs_log(LP_NOTICE, "failed to open `%s' : %s", tagpath,
                               strerror(errno));
                   return;
           }
   
           linenum = 0;
   
           while (fgets(linebuf, (int)sizeof(linebuf), fp) != NULL) {
                   linenum++;
                   if ((len = strlen(linebuf)) == 0)
                           continue;
                   if (linebuf[len -1] != '\n') {
                           cvs_log(LP_WARN, "line too long in `%s:%d'", tagpath,
                               linenum);
                           break;
                   }
                   linebuf[--len] = '\0';
   
                   switch(*linebuf) {
                   case 'T':
                           if (tagp != NULL)
                                   *tagp = strdup(linebuf);
                           break;
                   case 'D':
                           if (datep != NULL)
                                   *datep = strdup(linebuf);
                           break;
                   case 'N':
                           if (tagp != NULL)
                                   *tagp = strdup(linebuf);
                           if (nbp != NULL)
                                   *nbp = 1;
                           break;
                   default:
                           break;
                   }
           }
           if (ferror(fp))
                   cvs_log(LP_NOTICE, "failed to read line from `%s'", tagpath);
   
           (void)fclose(fp);
 }  }

Legend:
Removed from v.1.50  
changed lines
  Added in v.1.51