Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv10089

Modified Files:
        .cvsignore Makefile 
Added Files:
        vercomp.c 
Removed Files:
        vercomp.sh 
Log Message:
use new C-coded version comparison program for bison and flex (bug #2058, with 
different Makefile changes)


--- NEW FILE: vercomp.c ---
/*
 * Asterisk -- A telephony toolkit for Linux.
 *
 * A simple program version comparison tool.
 * 
 * Copyright (C) 2005, 'murf'.
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License
 */

/* vercomp.c
   args: <program> <comparison> <version>

        where:

   program = path to program (bison or flex)
   comparison = ">", "<", "<=", ">=", "="  -- depending on shell, you may have 
to use backslash escapes
   version = a version compare against, say 1.875, or 2.5.4, or whatever.

*/

#include <stdio.h>
#include <string.h>

char *program_version[5];
char *arg_version[5];

void get_program_version_string(char *command, char *output)
{
        char cbuf[8000];
        char pbuf[8000];
        char zbuf[8000];
        char *res;
        FILE *p1;

        zbuf[0] = 0;
        
        sprintf( cbuf, "%s --version", command );
        p1 = popen(cbuf, "r");
        if( !p1 )
        {
                fprintf(stderr,"vercomp: Could not execute the command: %s\n", 
command);
                exit(125);
        }
        /* the first line is the magic one */
        res = fgets(zbuf, 8000, p1);
        /* clear the trailing blank */
        if( zbuf[strlen(zbuf)-1] == '\n' )
                zbuf[strlen(zbuf)-1] = 0;
        /* the rest is cruft, just empty the input stream */
        while( res )
        {
                res = fgets(pbuf, 8000, p1);
        }
        /* close the stream. Hopefully, we have what we need */
        pclose(p1);
        /* all we want is the last "word"-- so find the last blank, and grab 
everything after that */

        res = strrchr(zbuf,' ');
        if( !res )
        {
                fprintf(stderr,"Something is wrong with the version string: 
%s\n", zbuf);
                exit(124);
        }
        strcpy(output,res+1);
}


void extract_version(char *ver_string, char **where)
{
        int i=0;
        char *p=ver_string;
        
        while( p && *p )
        {
                where[i++] = p;
                p = strchr(p,'.');
                if( p )
                {
                        *p= 0;
                        p++;
                }
        }
}

void compare_versions(char *compare_func)
{
        int i;
        
        for(i=0;i<5;i++)
        {
                /* start out at the beginning, then go to the end */
                if( program_version[i] && arg_version[i] && *program_version[i] 
&& *arg_version[i] )
                {
                        
                        if( strlen(program_version[i]) == 
strspn(program_version[i],"0123456789")
                                && strlen(arg_version[i]) == 
strspn(arg_version[i],"0123456789") )
                        {
                                /* just pure numbers -- do a numeric compare */
                                int pv = atoi(program_version[i]);
                                int av = atoi(arg_version[i]);
                                
                                if( pv < av )
                                {
                                        if( !strcmp(compare_func,"=") )
                                        {
                                                printf("false\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, ">") )
                                        {
                                                printf("false\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, "<") )
                                        {
                                                printf("true\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, ">=") )
                                        {
                                                printf("false\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, "<=") )
                                        {
                                                printf("true\n");
                                                exit(0);
                                        }
                                }
                                else if( pv > av )
                                {
                                        if( !strcmp(compare_func,"=") )
                                        {
                                                printf("false\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, ">") )
                                        {
                                                printf("true\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, "<") )
                                        {
                                                printf("false\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, ">=") )
                                        {
                                                printf("true\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, "<=") )
                                        {
                                                printf("false\n");
                                                exit(0);
                                        }
                                }
                        }
                        else
                        {
                                /* other junk thrown in -- do string compare */
                                int res = strcmp(program_version[i], 
arg_version[i]);
                                if( res < 0 ) /* prog is less than arg */
                                {
                                        if( !strcmp(compare_func,"=") )
                                        {
                                                printf("false\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, ">") )
                                        {
                                                printf("false\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, "<") )
                                        {
                                                printf("true\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, ">=") )
                                        {
                                                printf("false\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, "<=") )
                                        {
                                                printf("true\n");
                                                exit(0);
                                        }
                                }
                                else if( res > 0 ) /* prog is greater than arg 
*/
                                {
                                        if( !strcmp(compare_func,"=") )
                                        {
                                                printf("false\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, ">") )
                                        {
                                                printf("true\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, "<") )
                                        {
                                                printf("false\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, ">=") )
                                        {
                                                printf("true\n");
                                                exit(0);
                                        }
                                        else if( !strcmp(compare_func, "<=") )
                                        {
                                                printf("false\n");
                                                exit(0);
                                        }
                                }
                        }
                }
                else if( program_version[i] && *program_version[i] )
                {
                        if( !strcmp(compare_func,"=") )
                        {
                                printf("false\n");
                                exit(0);
                        }
                        else if( !strcmp(compare_func, ">") )
                        {
                                printf("true\n");
                                exit(0);
                        }
                        else if( !strcmp(compare_func, "<") )
                        {
                                printf("false\n");
                                exit(0);
                        }
                        else if( !strcmp(compare_func, ">=") )
                        {
                                printf("true\n");
                                exit(0);
                        }
                        else if( !strcmp(compare_func, "<=") )
                        {
                                printf("false\n");
                                exit(0);
                        }
                        
                }
                else if( arg_version[i] && *arg_version[i] )
                {
                        if( !strcmp(compare_func,"=") )
                        {
                                printf("false\n");
                                exit(0);
                        }
                        else if( !strcmp(compare_func, ">") )
                        {
                                printf("false\n");
                                exit(0);
                        }
                        else if( !strcmp(compare_func, "<") )
                        {
                                printf("true\n");
                                exit(0);
                        }
                        else if( !strcmp(compare_func, ">=") )
                        {
                                printf("false\n");
                                exit(0);
                        }
                        else if( !strcmp(compare_func, "<=") )
                        {
                                printf("true\n");
                                exit(0);
                        }
                }
                else
                        break;
        }
        if( !strcmp(compare_func,"=") )
        {
                printf("true\n");
                exit(0);
        }
        else if( !strcmp(compare_func, ">") )
        {
                printf("false\n");
                exit(0);
        }
        else if( !strcmp(compare_func, "<") )
        {
                printf("false\n");
                exit(0);
        }
        else if( !strcmp(compare_func, ">=") )
        {
                printf("true\n");
                exit(0);
        }
        else if( !strcmp(compare_func, "<=") )
        {
                printf("true\n");
                exit(0);
        }
}

void usage(void)
{
        printf("Usage: <program-path> <comparison> <version>\n\
\n\
        where:\n\
\n\
   program-path = path to program (bison or flex)\n\
   comparison = '>', '<', '<=', '>=', '='  -- depending on shell, you may have 
to use backslash escapes\n\
   version = a version compare against, say 1.875, or 2.5.4, or whatever.\n\n");
}


int main(int argc, char **argv)
{
        char program_version_string[8000];
        
        /* before starting, check args and make sure all is OK */
        if( argc < 4 || argc > 4 )
        {
                usage();
                exit(-256);
        }
        if ( strcmp(argv[2],"=") && strcmp(argv[2],">") && strcmp(argv[2],"<") 
&& strcmp(argv[2],">=") && strcmp(argv[2],"<=") )
        {
                fprintf(stderr,"vercomp: ILLEGAL input Comparison value: 
%s\n\n", argv[2]);
                usage();
                exit(-256);
        }
                 
        /* first, extract a version from the command line arg */
        extract_version(argv[3], arg_version);

        /* next, extract a version from the command line */
        get_program_version_string(argv[1], program_version_string);
        extract_version(program_version_string, program_version);
        
        /* next compare and return result */
        compare_versions(argv[2]);
        /* the above func shouldn't return */
}

Index: .cvsignore
===================================================================
RCS file: /usr/cvsroot/asterisk/.cvsignore,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- .cvsignore  16 May 2005 14:30:13 -0000      1.10
+++ .cvsignore  19 May 2005 04:08:01 -0000      1.11
@@ -17,4 +17,4 @@
 .tags-sources
 tags
 TAGS
-*.os
+vercomp

Index: Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/Makefile,v
retrieving revision 1.156
retrieving revision 1.157
diff -u -d -r1.156 -r1.157
--- Makefile    16 May 2005 13:51:56 -0000      1.156
+++ Makefile    19 May 2005 04:08:01 -0000      1.157
@@ -20,6 +20,7 @@
 # CROSS_COMPILE_BIN=/opt/montavista/pro/devkit/arm/xscale_be/bin/
 # CROSS_COMPILE_TARGET=/opt/montavista/pro/devkit/arm/xscale_be/target
 CC=$(CROSS_COMPILE)gcc
+HOST_CC=gcc
 # CROSS_ARCH=Linux
 # CROSS_PROC=arm
 # SUB_PROC=xscale # or maverick
@@ -259,20 +260,10 @@
 endif
 LIBS+=-lssl
 
-#FLEXVER_GT_2_5_31=$(shell ./vercomp.sh flex \>= 2.5.31)
-#BISONVER=$(shell bison --version | grep \^bison | egrep -o 
'[0-9]+\.[-0-9.]+[a-z]?' )
-#BISONVERGE_85=$(shell ./vercomp.sh bison \>= 1.85 )
-
-ifeq (${FLEXVER_GT_2_5_31},true)
-FLEXOBJS=ast_expr2.o ast_expr2f.o
-else
-FLEXOBJS=ast_expr.o
-endif
-
 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
        translate.o file.o say.o pbx.o cli.o md5.o term.o \
        ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
-       cdr.o tdd.o acl.o rtp.o manager.o asterisk.o ${FLEXOBJS}  \
+       cdr.o tdd.o acl.o rtp.o manager.o asterisk.o \
        dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
        astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
        utils.o config_old.o plc.o jitterbuf.o dnsmgr.o
@@ -336,38 +327,54 @@
 include .tags-depend
 endif
 
-.PHONY: _version
+.PHONY: _version ast_expr
 
 _version: 
        if [ -d CVS ] && [ ! -f .version ]; then echo $(ASTERISKVERSION) > 
.version; fi 
 
 .version: _version
 
+vercomp: vercomp.c
+       $(HOST_CC) -o $@ $<
+
+ast_expr: vercomp
+       $(MAKE) ast_expr.a
+
+ifeq ($(MAKECMDGOALS),ast_expr.a)
+FLEXVER_GT_2_5_31=$(shell ./vercomp flex \>= 2.5.31)
+BISONVER=$(shell bison --version | grep \^bison | sed 's/.* 
\([0-9]\+\.[-0-9.]\+[a-z]\?\)/\1/' )
+BISONVER_GE_1_85=$(shell ./vercomp bison \>= 1.85 )
+endif
+
+ifeq ($(FLEXVER_GT_2_5_31),true)
+FLEXOBJS=ast_expr2.o ast_expr2f.o
+else
+FLEXOBJS=ast_expr.o
+endif
+
+ast_expr.a: $(FLEXOBJS)
+       @rm -f $@
+       ar r $@ $(FLEXOBJS)
+       ranlib $@
+
 .y.c:
-#      @if (($(BISONVERGE_85) = false)); then \
-#              echo 
=================================================================================
 ;\
-#              echo NOTE: you may have trouble if you do not have bison-1.85 
or higher installed! ;\
-#              echo NOTE: you can pick up a copy at: http://ftp.gnu.org/ or 
its mirrors ;\
-#              echo NOTE: You Have: $(BISONVER) ;\
-#              echo 
================================================================================;
 \
-#      else \
-#              echo EXCELLENT-- You have Bison version $(BISONVER), this 
should work just fine...;\
-#      fi
+       @if (($(BISONVER_GE_1_85) = false)); then \
+               echo 
=================================================================================
 ;\
+               echo NOTE: You may have trouble if you do not have bison-1.85 
or higher installed! ;\
+               echo NOTE: You can pick up a copy at: http://ftp.gnu.org/ or 
its mirrors ;\
+               echo NOTE: You have: $(BISONVER) ;\
+               echo 
================================================================================;
 \
+       fi
        bison -v -d --name-prefix=ast_yy $< -o $@
 
-ast_expr.o: ast_expr.c
-#      @echo NOTE:
-#      @echo NOTE:
-#      @echo NOTE: Using older version of ast_expr. To use the newer version,
-#      @echo NOTE: Upgrade to flex 2.5.31 or higher, which can be found at 
http://
-#      @echo NOTE:  http://sourceforge.net/project/showfiles.php?group_id=72099
-#      @echo NOTE:
-#      @echo NOTE:
-       $(CC) -c $(CPPFLAGS) $(CFLAGS) ast_expr.c
-
-ast_expr2.o: ast_expr2.c
+ast_expr.o:: ast_expr.c
+       @echo 
=================================================================================
 ;\
+       echo NOTE: Using older version of expression parser. To use the newer 
version, ;\
+       echo NOTE: upgrade to flex 2.5.31 or higher, which can be found at ;\
+       echo NOTE: http://sourceforge.net/project/showfiles.php?group_id=72099 
;\
+       echo 
=================================================================================
 ;\
 
-ast_expr2f.o: ast_expr2f.c
+ast_expr.o:: ast_expr.c
 
 ast_expr2f.c: ast_expr2.fl
        flex ast_expr2.fl
@@ -421,8 +428,8 @@
                exit 1; \
        fi
 
-asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
-       $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) $(LIBEDIT) 
db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
+asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS) 
ast_expr
+       $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) ast_expr.a $(LIBEDIT) 
db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
 
 muted: muted.o
        $(CC) -o muted muted.o
@@ -434,7 +441,9 @@
        for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
        rm -f *.o *.so asterisk .depend
        rm -f build.h 
-       rm -f ast_expr.c
+       rm -f ast_expr.c ast_expr.h ast_expr.output
+       rm -f ast_expr2.c ast_expr2f.c ast_expr2.h ast_expr2.output
+       rm -f ast_expr.a vercomp
        rm -f .version
        rm -f .tags-depend .tags-sources tags TAGS
        @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi

--- vercomp.sh DELETED ---

_______________________________________________
Asterisk-Cvs mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-cvs

Reply via email to