bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch: changes to Parse_Info calling convention


From: Kenneth Lorber
Subject: Patch: changes to Parse_Info calling convention
Date: Thu, 22 May 2003 10:29:42 -0400 (EDT)

Below is a patch that implements 2 changes to the way Parse_Info is
called.  The first adds the void* mentioned in HACKING.  The second
generalizes the "all" flag to a more general "opt" - this is needed for
some other changes I hope to contribute in the near future and touches
the same places in the code so is included here.

I added a FIXME in edit.c - I believe the existing test is wrong.  Can
anyone tell me for sure?  Thanks.

Please let me know if I left out anything, missed any cases, added any
bugs, etc, etc.

Share and Enjoy,
keni

Index: ChangeLog
===================================================================
RCS file: /cvs/ccvs/ChangeLog,v
retrieving revision 1.741
diff -c -r1.741 ChangeLog
*** ChangeLog   21 May 2003 21:47:10 -0000      1.741
--- ChangeLog   22 May 2003 14:16:57 -0000
***************
*** 1,3 ****
--- 1,7 ----
+ 2003-05-22  Ken Lorber  <keni@his.com>
+ 
+       * HACKING: Update note on reentrancy.
+ 
  2003-05-21  Derek Price  <derek@ximbiot.com>
  
        * INSTALL: Mention new Automake version.
Index: HACKING
===================================================================
RCS file: /cvs/ccvs/HACKING,v
retrieving revision 1.22
diff -c -r1.22 HACKING
*** HACKING     18 Oct 2001 15:50:43 -0000      1.22
--- HACKING     22 May 2003 14:16:57 -0000
***************
*** 89,97 ****
  segment and will allow a multi-threaded server if that is desirable.
  It is also useful to write the code so that it can be easily be made
  reentrant later.  For example, if you need to pass data from a
! Parse_Info caller to its callproc, you need a static variable.  But
! use a single pointer so that when Parse_Info is fixed to pass along a
! void * argument, then the code can easily use that argument.
  
  * Coding standards in general
  
--- 89,97 ----
  segment and will allow a multi-threaded server if that is desirable.
  It is also useful to write the code so that it can be easily be made
  reentrant later.  For example, if you need to pass data from a
! Parse_Info caller to its callproc, you used to need a static variable.
! But by using a single pointer so that when Parse_Info was fixed to pass
! along a void * argument, then the code could easily use that argument.
  
  * Coding standards in general
  
Index: src/ChangeLog
===================================================================
RCS file: /cvs/ccvs/src/ChangeLog,v
retrieving revision 1.2446
diff -c -r1.2446 ChangeLog
*** src/ChangeLog       21 May 2003 21:46:01 -0000      1.2446
--- src/ChangeLog       22 May 2003 14:16:58 -0000
***************
*** 1,3 ****
--- 1,14 ----
+ 2003-05-22  Ken Lorber  <keni@his.com>
+ 
+       * commit.c: Change Parse_Info calling convention to include void *
+       suggested in HACKING file and generalize all argument to opt.
+       * cvs.h: update defs for Parse_Info and its callproc.
+       * edit.c: Change Parse_Info calls for new calling convention.
+       * logmsg.c: Ditto.
+       * parseinfo.c: Change Parse_Info for new calling convention.
+       * server.c: Change Parse_Info calls for new calling convention.
+       * tag.c: Ditto.
+ 
  2003-05-21  Derek Price  <derek@ximbiot.com>
  
        * Makefile.in: Regenerate with Autoconf version 1.7.5.
Index: src/commit.c
===================================================================
RCS file: /cvs/ccvs/src/commit.c,v
retrieving revision 1.196
diff -c -r1.196 commit.c
*** src/commit.c        30 Apr 2003 16:14:54 -0000      1.196
--- src/commit.c        22 May 2003 14:16:58 -0000
***************
*** 1155,1161 ****
        return (err);
  
      /* run any pre-commit checks */
!     if ((n = Parse_Info (CVSROOTADM_COMMITINFO, repos, precommit_proc, 1)) > 
0)
      {
        error (0, 0, "Pre-commit check failed");
        err += n;
--- 1155,1162 ----
        return (err);
  
      /* run any pre-commit checks */
!     n = Parse_Info (CVSROOTADM_COMMITINFO, repos, precommit_proc, PIOPT_ALL, 
0);
!     if (n > 0)
      {
        error (0, 0, "Pre-commit check failed");
        err += n;
Index: src/cvs.h
===================================================================
RCS file: /cvs/ccvs/src/cvs.h,v
retrieving revision 1.252
diff -c -r1.252 cvs.h
*** src/cvs.h   20 May 2003 16:28:26 -0000      1.252
--- src/cvs.h   22 May 2003 14:16:58 -0000
***************
*** 384,389 ****
--- 384,392 ----
  #define CVS_LOCK_READ 1
  #define CVS_LOCK_WRITE        2
  
+ /* Option flags for Parse_Info() */
+ #define PIOPT_ALL 1   /* accept "all" keyword */
+ 
  extern char *program_name, *program_path, *command_name;
  extern char *Tmpdir, *Editor;
  extern int cvsadmin_root;
***************
*** 498,505 ****
  void strip_trailing_newlines PROTO((char *str));
  int pathname_levels PROTO ((char *path));
  
! typedef       int (*CALLPROC) PROTO((char *repository, char *value));
! int Parse_Info PROTO((char *infofile, char *repository, CALLPROC callproc, 
int all));
  extern int parse_config PROTO ((char *));
  
  typedef       RETSIGTYPE (*SIGCLEANUPPROC)    PROTO(());
--- 501,509 ----
  void strip_trailing_newlines PROTO((char *str));
  int pathname_levels PROTO ((char *path));
  
! typedef       int (*CALLPROC) PROTO((char *repository, char *value, void 
*udata));
! int Parse_Info PROTO((char *infofile, char *repository, CALLPROC callproc,
!       int opt, void *udata));
  extern int parse_config PROTO ((char *));
  
  typedef       RETSIGTYPE (*SIGCLEANUPPROC)    PROTO(());
Index: src/edit.c
===================================================================
RCS file: /cvs/ccvs/src/edit.c,v
retrieving revision 1.58
diff -c -r1.58 edit.c
*** src/edit.c  31 Mar 2003 19:30:56 -0000      1.58
--- src/edit.c  22 May 2003 14:16:58 -0000
***************
*** 677,692 ****
      char *file;
  };
  
! /* Pass as a static until we get around to fixing Parse_Info to pass along
!    a void * where we can stash it.  */
! static struct notify_proc_args *notify_args;
! 
! static int notify_proc PROTO ((char *repository, char *filter));
  
  static int
! notify_proc (repository, filter)
      char *repository;
      char *filter;
  {
      FILE *pipefp;
      char *prog;
--- 677,689 ----
      char *file;
  };
  
! static int notify_proc PROTO ((char *repository, char *filter, void *udata));
  
  static int
! notify_proc (repository, filter, udata)
      char *repository;
      char *filter;
+     void *udata;
  {
      FILE *pipefp;
      char *prog;
***************
*** 694,700 ****
      char *p;
      char *q;
      char *srepos;
!     struct notify_proc_args *args = notify_args;
  
      srepos = Short_Repository (repository);
      prog = xmalloc (strlen (filter) + strlen (args->notifyee) + 1);
--- 691,697 ----
      char *p;
      char *q;
      char *srepos;
!     struct notify_proc_args *args = (struct notify_proc_args *)udata;
  
      srepos = Short_Repository (repository);
      prog = xmalloc (strlen (filter) + strlen (args->notifyee) + 1);
***************
*** 929,940 ****
                args.notifyee[endp - p] = '\0';
            }
  
-           notify_args = &args;
            args.type = notif;
            args.who = who;
            args.file = filename;
  
!           (void) Parse_Info (CVSROOTADM_NOTIFY, repository, notify_proc, 1);
            free (args.notifyee);
        }
  
--- 926,937 ----
                args.notifyee[endp - p] = '\0';
            }
  
            args.type = notif;
            args.who = who;
            args.file = filename;
  
!           (void) Parse_Info (CVSROOTADM_NOTIFY, repository, notify_proc,
!                       PIOPT_ALL, &args);
            free (args.notifyee);
        }
  
Index: src/logmsg.c
===================================================================
RCS file: /cvs/ccvs/src/logmsg.c,v
retrieving revision 1.64
diff -c -r1.64 logmsg.c
*** src/logmsg.c        20 May 2003 20:46:38 -0000      1.64
--- src/logmsg.c        22 May 2003 14:16:58 -0000
***************
*** 15,32 ****
  static int fmt_proc PROTO((Node * p, void *closure));
  static int logfile_write PROTO((char *repository, char *filter,
                          char *message, FILE * logfp, List * changes));
! static int rcsinfo_proc PROTO((char *repository, char *template));
  static int title_proc PROTO((Node * p, void *closure));
! static int update_logfile_proc PROTO((char *repository, char *filter));
  static void setup_tmpfile PROTO((FILE * xfp, char *xprefix, List * changes));
! static int editinfo_proc PROTO((char *repository, char *template));
! static int verifymsg_proc PROTO((char *repository, char *script));
  
  static FILE *fp;
  static char *str_list;
  static char *str_list_format; /* The format for str_list's contents. */
- static char *editinfo_editor;
- static char *verifymsg_script;
  static Ctype type;
  
  /* 
--- 15,31 ----
  static int fmt_proc PROTO((Node * p, void *closure));
  static int logfile_write PROTO((char *repository, char *filter,
                          char *message, FILE * logfp, List * changes));
! static int rcsinfo_proc PROTO((char *repository, char *template, void 
*udata));
  static int title_proc PROTO((Node * p, void *closure));
! static int update_logfile_proc PROTO((char *repository, char *filter,
!                         void *udata));
  static void setup_tmpfile PROTO((FILE * xfp, char *xprefix, List * changes));
! static int editinfo_proc PROTO((char *repository, char *template, void 
*udata));
! static int verifymsg_proc PROTO((char *repository, char *script, void 
*udata));
  
  static FILE *fp;
  static char *str_list;
  static char *str_list_format; /* The format for str_list's contents. */
  static Ctype type;
  
  /* 
***************
*** 194,199 ****
--- 193,199 ----
      char *fname;
      struct stat pre_stbuf, post_stbuf;
      int retcode = 0;
+     char *editinfo_editor = NULL;
  
  #ifdef CLIENT_SUPPORT
      assert (!current_parsed_root->isremote != !repository);
***************
*** 205,210 ****
--- 205,214 ----
        return;
  
      /* Abort creation of temp file if no editor is defined */
+     /* FIXME - why test this here?  Editor is set by configure and
+      * editinfo_editor is really set later in this function.  This test
+      * should either be deleted or moved below the call to Parse_Info().
+      */
      if (strcmp (Editor, "") == 0 && !editinfo_editor)
        error(1, 0, "no editor defined, must use -e or -m");
  
***************
*** 228,234 ****
  
      if (repository != NULL)
        /* tack templates on if necessary */
!       (void) Parse_Info (CVSROOTADM_RCSINFO, repository, rcsinfo_proc, 1);
      else
      {
        FILE *tfp;
--- 232,239 ----
  
      if (repository != NULL)
        /* tack templates on if necessary */
!       (void) Parse_Info (CVSROOTADM_RCSINFO, repository, rcsinfo_proc,
!               PIOPT_ALL, 0);
      else
      {
        FILE *tfp;
***************
*** 295,301 ****
      else
  #endif
      if (repository != NULL)
!       (void) Parse_Info (CVSROOTADM_EDITINFO, repository, editinfo_proc, 0);
  
      /* run the editor */
      run_setup (editinfo_editor ? editinfo_editor : Editor);
--- 300,307 ----
      else
  #endif
      if (repository != NULL)
!       (void) Parse_Info (CVSROOTADM_EDITINFO, repository, editinfo_proc, 0,
!                &editinfo_editor);
  
      /* run the editor */
      run_setup (editinfo_editor ? editinfo_editor : Editor);
***************
*** 418,423 ****
--- 424,430 ----
      FILE *fp;
      char *fname;
      int retcode = 0;
+     char *verifymsg_script = NULL;
  
      struct stat pre_stbuf, post_stbuf;
  
***************
*** 434,440 ****
  
      /* Get the name of the verification script to run  */
  
!     if (Parse_Info (CVSROOTADM_VERIFYMSG, repository, verifymsg_proc, 0) > 0)
        error (1, 0, "Message verification failed");
  
      if (!verifymsg_script)
--- 441,447 ----
  
      /* Get the name of the verification script to run  */
  
!     if (Parse_Info (CVSROOTADM_VERIFYMSG, repository, verifymsg_proc, 0, 
&verifymsg_script) > 0)
        error (1, 0, "Message verification failed");
  
      if (!verifymsg_script)
***************
*** 559,567 ****
   */
  /* ARGSUSED */
  static int
! rcsinfo_proc (repository, template)
      char *repository;
      char *template;
  {
      static char *last_template;
      FILE *tfp;
--- 566,575 ----
   */
  /* ARGSUSED */
  static int
! rcsinfo_proc (repository, template, udata)
      char *repository;
      char *template;
+     void *udata;
  {
      static char *last_template;
      FILE *tfp;
***************
*** 601,609 ****
   * directory in the source repository.  The log information is fed into the
   * specified program as standard input.
   */
! static FILE *logfp;
! static char *message;
! static List *changes;
  
  void
  Update_Logfile (repository, xmessage, xlogfp, xchanges)
--- 609,619 ----
   * directory in the source repository.  The log information is fed into the
   * specified program as standard input.
   */
! struct ulp_data {
!     FILE *logfp;
!     char *message;
!     List *changes;
! };
  
  void
  Update_Logfile (repository, xmessage, xlogfp, xchanges)
***************
*** 612,639 ****
      FILE *xlogfp;
      List *xchanges;
  {
      /* nothing to do if the list is empty */
      if (xchanges == NULL || xchanges->list->next == xchanges->list)
        return;
  
!     /* set up static vars for update_logfile_proc */
!     message = xmessage;
!     logfp = xlogfp;
!     changes = xchanges;
  
      /* call Parse_Info to do the actual logfile updates */
!     (void) Parse_Info (CVSROOTADM_LOGINFO, repository, update_logfile_proc, 
1);
  }
  
  /*
   * callback proc to actually do the logfile write from Update_Logfile
   */
  static int
! update_logfile_proc (repository, filter)
      char *repository;
      char *filter;
  {
!     return (logfile_write (repository, filter, message, logfp, changes));
  }
  
  /*
--- 622,655 ----
      FILE *xlogfp;
      List *xchanges;
  {
+     struct ulp_data ud;
+ 
      /* nothing to do if the list is empty */
      if (xchanges == NULL || xchanges->list->next == xchanges->list)
        return;
  
!     /* set up vars for update_logfile_proc */
!     ud.message = xmessage;
!     ud.logfp = xlogfp;
!     ud.changes = xchanges;
  
      /* call Parse_Info to do the actual logfile updates */
!     (void) Parse_Info (CVSROOTADM_LOGINFO, repository, update_logfile_proc,
!               PIOPT_ALL, &ud);
  }
  
  /*
   * callback proc to actually do the logfile write from Update_Logfile
   */
  static int
! update_logfile_proc (repository, filter, udata)
      char *repository;
      char *filter;
+     void *udata;
  {
!     struct ulp_data *udp = (struct ulp_data *)udata;
!     return (logfile_write (repository, filter, udp->message, udp->logfp,
!                          udp->changes));
  }
  
  /*
***************
*** 950,959 ****
   */
  /* ARGSUSED */
  static int
! editinfo_proc(repository, editor)
      char *repository;
      char *editor;
  {
      /* nothing to do if the last match is the same as this one */
      if (editinfo_editor && strcmp (editinfo_editor, editor) == 0)
        return (0);
--- 966,978 ----
   */
  /* ARGSUSED */
  static int
! editinfo_proc(repository, editor, udata)
      char *repository;
      char *editor;
+     void *udata;
  {
+     char *editinfo_editor = (char *)udata;
+ 
      /* nothing to do if the last match is the same as this one */
      if (editinfo_editor && strcmp (editinfo_editor, editor) == 0)
        return (0);
***************
*** 964,977 ****
      return (0);
  }
  
! /*  This routine is calld by Parse_Info.  it asigns the name of the
!  *  message verification script to the global variable verify_script
   */
  static int
! verifymsg_proc (repository, script)
      char *repository;
      char *script;
  {
      if (verifymsg_script && strcmp (verifymsg_script, script) == 0)
        return (0);
      if (verifymsg_script)
--- 983,998 ----
      return (0);
  }
  
! /*  This routine is calld by Parse_Info.  It picks up the name of the
!  *  message verification script.
   */
  static int
! verifymsg_proc (repository, script, udata)
      char *repository;
      char *script;
+     void *udata;
  {
+     char *verifymsg_script = (char *)udata;
      if (verifymsg_script && strcmp (verifymsg_script, script) == 0)
        return (0);
      if (verifymsg_script)
Index: src/parseinfo.c
===================================================================
RCS file: /cvs/ccvs/src/parseinfo.c,v
retrieving revision 1.42
diff -c -r1.42 parseinfo.c
*** src/parseinfo.c     20 May 2003 22:29:52 -0000      1.42
--- src/parseinfo.c     22 May 2003 14:16:58 -0000
***************
*** 20,30 ****
   * Return 0 for success, -1 if there was not an INFOFILE, and >0 for failure.
   */
  int
! Parse_Info (infofile, repository, callproc, all)
      char *infofile;
      char *repository;
      CALLPROC callproc;
!     int all;
  {
      int err = 0;
      FILE *fp_info;
--- 20,31 ----
   * Return 0 for success, -1 if there was not an INFOFILE, and >0 for failure.
   */
  int
! Parse_Info (infofile, repository, callproc, opt, udata)
      char *infofile;
      char *repository;
      CALLPROC callproc;
!     int opt;
!     void *udata;
  {
      int err = 0;
      FILE *fp_info;
***************
*** 66,72 ****
      srepos = Short_Repository (repository);
  
      TRACE ( 1, "Parse_Info (%s, %s, %s)",
!           infopath, srepos, all ? "ALL" : "not ALL");
  
      /* search the info file for lines that match */
      callback_done = line_number = 0;
--- 67,73 ----
      srepos = Short_Repository (repository);
  
      TRACE ( 1, "Parse_Info (%s, %s, %s)",
!           infopath, srepos,  (opt & PIOPT_ALL) ? "ALL" : "not ALL");
  
      /* search the info file for lines that match */
      callback_done = line_number = 0;
***************
*** 135,146 ****
         */
        if (strcmp (exp, "ALL") == 0)
        {
!           if (!all)
                error(0, 0, "Keyword `ALL' is ignored at line %d in %s file",
                      line_number, infofile);
            else if ((expanded_value = expand_path (value, infofile, 
line_number)) != NULL)
            {
!               err += callproc (repository, expanded_value);
                free (expanded_value);
            }
            else
--- 136,147 ----
         */
        if (strcmp (exp, "ALL") == 0)
        {
!           if (! (opt & PIOPT_ALL))
                error(0, 0, "Keyword `ALL' is ignored at line %d in %s file",
                      line_number, infofile);
            else if ((expanded_value = expand_path (value, infofile, 
line_number)) != NULL)
            {
!               err += callproc (repository, expanded_value, udata);
                free (expanded_value);
            }
            else
***************
*** 165,171 ****
        /* it did, so do the callback and note that we did one */
        if ((expanded_value = expand_path (value, infofile, line_number)) != 
NULL)
        {
!           err += callproc (repository, expanded_value);
            free (expanded_value);
        }
        else
--- 166,172 ----
        /* it did, so do the callback and note that we did one */
        if ((expanded_value = expand_path (value, infofile, line_number)) != 
NULL)
        {
!           err += callproc (repository, expanded_value, udata);
            free (expanded_value);
        }
        else
***************
*** 182,188 ****
      {
        if ((expanded_value = expand_path (default_value, infofile, 
default_line)) != NULL)
        {
!           err += callproc (repository, expanded_value);
            free (expanded_value);
        }
        else
--- 183,189 ----
      {
        if ((expanded_value = expand_path (default_value, infofile, 
default_line)) != NULL)
        {
!           err += callproc (repository, expanded_value, udata);
            free (expanded_value);
        }
        else
Index: src/server.c
===================================================================
RCS file: /cvs/ccvs/src/server.c,v
retrieving revision 1.294
diff -c -r1.294 server.c
*** src/server.c        9 May 2003 23:25:54 -0000       1.294
--- src/server.c        22 May 2003 14:16:58 -0000
***************
*** 4446,4452 ****
      data.update_dir = update_dir;
      data.repository = repository;
      tpd = &data;
!     (void) Parse_Info (CVSROOTADM_RCSINFO, repository, template_proc, 1);
  }
  
  static void
--- 4446,4453 ----
      data.update_dir = update_dir;
      data.repository = repository;
      tpd = &data;
!     (void) Parse_Info (CVSROOTADM_RCSINFO, repository, template_proc,
!                      PIOPT_ALL, 0);
  }
  
  static void
Index: src/tag.c
===================================================================
RCS file: /cvs/ccvs/src/tag.c,v
retrieving revision 1.102
diff -c -r1.102 tag.c
*** src/tag.c   19 May 2003 04:47:02 -0000      1.102
--- src/tag.c   22 May 2003 14:16:58 -0000
***************
*** 578,584 ****
      {
          return (err);
      }
!     if ((n = Parse_Info(CVSROOTADM_TAGINFO, repos, pretag_proc, 1)) > 0)
      {
          error (0, 0, "Pre-tag check failed");
          err += n;
--- 578,584 ----
      {
          return (err);
      }
!     if ((n = Parse_Info(CVSROOTADM_TAGINFO, repos, pretag_proc, PIOPT_ALL, 
0)) > 0)
      {
          error (0, 0, "Pre-tag check failed");
          err += n;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]