Hi,

A new version of grenum is out! Now it realy supports "gaps" between refdes 
numbers. The code was totaly rewritten. Please check it in to the CVS. The 
output of

cvs diff -C 3 -p

attached.

Thanks, and sorry for the delay. I wanted to do it on the day of the code 
sprint.

Levente

--
http://web.interware.hu/lekovacs
Index: man/grenum.1
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/utils/man/grenum.1,v
retrieving revision 1.1
diff -C3 -p -r1.1 grenum.1
*** man/grenum.1        16 Aug 2005 17:05:14 -0000      1.1
--- man/grenum.1        24 May 2006 21:25:37 -0000
*************** prints help message
*** 36,48 ****
  will return
  .B 0
  if all files processed successfully,
! .B -1
  if there was no input file specified,
! .B -2
  if I/O files can't be opened/written,
! .B -3
  if there is parse error in input file,
! .B -4
  if there is not enough memory to store refdes prefixes.
  .SH BUGS
  
--- 36,48 ----
  will return
  .B 0
  if all files processed successfully,
! .B 1
  if there was no input file specified,
! .B 2
  if I/O files can't be opened/written,
! .B 3
  if there is parse error in input file,
! .B 4
  if there is not enough memory to store refdes prefixes.
  .SH BUGS
  
Index: src/grenum.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/utils/src/grenum.c,v
retrieving revision 1.4
diff -C3 -p -r1.4 grenum.c
*** src/grenum.c        27 Sep 2005 22:46:55 -0000      1.4
--- src/grenum.c        24 May 2006 21:25:39 -0000
***************
*** 1,7 ****
  /* $Id: grenum.c,v 1.4 2005/09/27 22:46:55 danmc Exp $ */
  /*    This is grenum, an advanced refdes renumber utility for gEDA's gschem.
   *
!  *    Copyright (C) 2005  Levente Kovacs
   *
   *    This program is free software; you can redistribute it and/or modify
   *    it under the terms of the GNU General Public License as published by
--- 1,7 ----
  /* $Id: grenum.c,v 1.4 2005/09/27 22:46:55 danmc Exp $ */
  /*    This is grenum, an advanced refdes renumber utility for gEDA's gschem.
   *
!  *    Copyright (C) 2005-2006  Levente Kovacs
   *
   *    This program is free software; you can redistribute it and/or modify
   *    it under the terms of the GNU General Public License as published by
***************
*** 42,56 ****
  #include <unistd.h>
  #endif
  
  #include "grenum.h"
  /*#define DEBUG*/
  
  int main(int argc, char *argv[])
        {
        FILE *infile,*outfile;
!       char buff[255], infilename[100], outfilename[100], *cp;
        unsigned char flags;
!       int c, pages;
  
  #ifdef HAVE_GETOPT_LONG
        int opt_idx;
--- 42,59 ----
  #include <unistd.h>
  #endif
  
+ #include <errno.h>
+ 
  #include "grenum.h"
  /*#define DEBUG*/
  
  int main(int argc, char *argv[])
        {
        FILE *infile,*outfile;
!       char buff[BUFFSIZE], infilename[FILENAMESIZE], 
outfilename[FILENAMESIZE];
        unsigned char flags;
!       int c, pages, ret;
!       unsigned int i;
  
  #ifdef HAVE_GETOPT_LONG
        int opt_idx;
*************** int main(int argc, char *argv[])
*** 66,85 ****
  
        flags=0x00; /*Clear all flags*/
  
- /* flag bits
-  *
-  *    bit     function
-  *-----------------------
-  *    0               pkgskip
-  *    1               not implemented
-  *    2               not implemented
-  *    3               not implemented
-  *    4               not implemented
-  *    5               not implemented
-  *    6               not implemented
-  *    7               not implemented
-  *
-  */
        while(1)
                {
  #ifdef HAVE_GETOPT_LONG
--- 69,74 ----
*************** int main(int argc, char *argv[])
*** 98,104 ****
                                printver();
                                return 0;
                        case 'p':
!                               flags|=0x01; /*Set the pagejump flag*/
                                break;
                        }
                }
--- 87,93 ----
                                printver();
                                return 0;
                        case 'p':
!                               flags|=PAGEJUMP; /*Set the pagejump flag*/
                                break;
                        }
                }
*************** int main(int argc, char *argv[])
*** 106,226 ****
                {
                printf("grenum: no input file\n");
                printhelp();
!               return -1;
                }
!       for(c=0;c<MAX_PREFIX_COUNT;c++)
!               refdes_db[c].prefix[0]='\0';    /*Zero all the strings in the 
database.*/
! 
!       if((flags&0x01)==0x00)  /*No pagejumps*/
                {
!               for(c=0;c<MAX_PREFIX_COUNT;c++)
!                       refdes_db[c].value=COUNT_START; /*Fill the values with 
the COUNT_START value. We start from R1 for example.*/
                }
  
!       for(pages=1;optind<argc;optind++,pages++)
                {
!               if((flags&0x01)==0x01)  /*pagejumps*/
                        {
!                       for(c=0;c<MAX_PREFIX_COUNT;c++)
                                refdes_db[c].value=PAGE_JMP*pages+COUNT_START;  
/*Reset the counters according to page numbers*/
                        }
                strcpy(&infilename[0],argv[optind]);    /*Copy the filename to 
the buffer*/
!               if((infile=fopen(&infilename[0], "r")) == NULL) /*Open file, 
use r+ for read and write*/
                        {
!                       printf("grenum: unable to open input file\n");
!                       return -2;
                        }
                strcpy(&outfilename[0],&infilename[0]);
                if((outfile=fopen(strcat(&outfilename[0],".tmp"),"w"))==NULL)
                        {
!                       printf("grenum: could not create tmp file\n");
                        fclose(infile); /*Close the file*/
!                       return -2;
                        }
                printf("grenum: processing file %s\n",&infilename[0]);
!               while(fgets(&buff[0],sizeof(buff),infile)!=NULL) /*Read one 
line.*/
                        {       /*Process starts here*/
  #ifdef DEBUG
!                       printf("%s",&buff[0]);
  #endif
!                       cp=strstr(&buff[0],"refdes=");  /*seek for a refdes 
designator*/
!                       if(cp==NULL)
                                {
!                               if(fputs(&buff[0],outfile)==-1)
                                        {
!                                       printf("grenum: could not write to tmp 
file\n");
                                        fclose(infile); /*Close the files*/
                                        fclose(outfile);
!                                       return -2;
                                        }
                                continue;
!                               }
!                       switch(parse_refdes(&refdes,&buff[0]))/*We have the 
current refdes in the refdes structure parsed*/
!                               {
!                               case 0: /*e.g. U1*/
!                               /*We shall compare the maximum value, shall 
search for gaps, and set the refes_db.value to the next  free value*/
!                               for(c=0;c<MAX_PREFIX_COUNT;c++) /*seek for 
prefix*/
!                                       {
!                                       
if(strcmp(&refdes.prefix[0],&refdes_db[c].prefix[0])==0)        /*Now compare. 
According to the specs, we *DO NOT* renumber if there are two same refdeses, 
since it's a multi slotted component. This must be set manually.*/
!                                               {
!                                               
if(refdes.value-refdes_db[c].value==1)
!                                                       
refdes_db[c].value=refdes.value;        /*The next component; update the 
database*/
!                                               break;  /*continue our job*/
!                                               }
!                                       else if(refdes_db[c].prefix[0]=='\0')
!                                               {       /*No more valid prefix 
found in the database. New prefix. Update the database*/
!                                               
strcpy(&refdes_db[c].prefix[0],&refdes.prefix[0]);
!                                               refdes_db[c].value=refdes.value;
!                                               break;  /*continue our job*/
!                                               }
!                                       }
!                               if(c==MAX_PREFIX_COUNT)
                                        {
                                        printf("grenum: out of memory. Too much 
refdes prefixes.\n");
                                        fclose(infile); /*Close the files*/
                                        fclose(outfile);
!                                       return -4;
!                                       }
!                               break;
!                               case 1: /*e.g. U?*/
!                                       for(c=0;c<MAX_PREFIX_COUNT;c++) /*Look 
up the next value*/
                                                {
!                                               
if(strcmp(&refdes_db[c].prefix[0],&refdes.prefix[0])==0)
                                                        {
!                                                       
refdes.value=++refdes_db[c].value;      /*Renumber... Finally :-)*/
!                                                       break;
!                                                       }
!                                               else 
if(refdes_db[c].prefix[0]=='\0')
!                                                       {       /*New prefix*/
!                                                       
strcpy(&refdes_db[c].prefix[0],&refdes.prefix[0]);      /*Register the prefix 
to the database*/
!                                                       
refdes.value=++refdes_db[c].value;      /*Renumber... Finally :-)*/
                                                        break;
                                                        }
                                                }
!                                       if(c==MAX_PREFIX_COUNT)
                                                {
!                                               printf("grenum: out of memory. 
Too much refdes prefixes.\n");
!                                               fclose(infile); /*Close the 
files*/
!                                               fclose(outfile);
!                                               return -4;
                                                }
!                               
sprintf(&buff[0],"refdes=%s%d\n",&refdes.prefix[0],refdes.value);       
/*Format the new refdes string*/
                                break;
!                               case -1:        /*e.g. awdf#$%WSf82f8 :-) No 
"=" signal in the refdes string.*/
                                        printf("grenum: parse error\n");
                                        fclose(infile); /*Close the files*/
                                        fclose(outfile);
!                                       return -3;
                                }
!                       if(fputs(&buff[0],outfile)==-1) /*Finally, write the 
refdes line to the output file*/
                                {
!                               printf("grenum: could not write to tmp file\n");
                                fclose(infile); /*Close the files*/
                                fclose(outfile);
!                               return -2;
                                }
                        }       /*Process ends here*/
! /*            fclose(infile);*/       /*Close the files*/
                fclose(outfile);
                strcpy(&buff[0],&infilename[0]); /*buff has the original 
infilename*/
  /*The next few lines implements the copy program*/
--- 95,223 ----
                {
                printf("grenum: no input file\n");
                printhelp();
!               return NO_INPUT_FILE;
                }
!       for(c=0;c<MAX_PREFIX_COUNT;++c)
                {
!               refdes_db[c].prefix[0]='\0';    /*Zero all the strings in the 
database.*/
!               refdes_db[c].value=COUNT_START;
                }
  
!       for(pages=1;optind<argc;++optind,++pages)
                {
!               if((flags&PAGEJUMP)==PAGEJUMP)  /*pagejumps*/
                        {
!                       for(c=0;c<MAX_PREFIX_COUNT;++c)
                                refdes_db[c].value=PAGE_JMP*pages+COUNT_START;  
/*Reset the counters according to page numbers*/
                        }
                strcpy(&infilename[0],argv[optind]);    /*Copy the filename to 
the buffer*/
!               if((infile=fopen(infilename, "r")) == NULL)     /*Open file, 
use r+ for read and write*/
                        {
!                       perror("grenum: unable to open input file");
!                       return FILE_OP_ERROR;
                        }
                strcpy(&outfilename[0],&infilename[0]);
                if((outfile=fopen(strcat(&outfilename[0],".tmp"),"w"))==NULL)
                        {
!                       perror("grenum: could not create tmp file");
                        fclose(infile); /*Close the file*/
!                       return FILE_OP_ERROR;
                        }
                printf("grenum: processing file %s\n",&infilename[0]);
!               while((ret=get_refdes_from_file(infile, &refdes, 
buff))!=END_OF_FILE) /*Read one line.*/
                        {       /*Process starts here*/
  #ifdef DEBUG
!                       printf("%s\n",&buff[0]);        /*Print out what is 
read*/
  #endif
!                       switch(ret)
                                {
!                               case NOT_REFDES_LINE:
!                               if(fputs(buff,outfile)==-1)
                                        {
!                                       perror("grenum: could not write to tmp 
file");
                                        fclose(infile); /*Close the files*/
                                        fclose(outfile);
!                                       return FILE_OP_ERROR;
                                        }
                                continue;
!                               case REFDES_WITH_VALUE: /*We shall compare the 
maximum value, shall search for gaps, and set the refes_db.value to the next  
free value*/
!                               c=refdes_lookup(refdes_db, &refdes);
!                               switch(c)
                                        {
+                                       case REFDES_NOT_FOUND:  /*No such 
prefix*/
+                                       
strcpy(&refdes_db[refdes.prefixes].prefix[0],&refdes.prefix[0]);        
/*Register the prefix to the database*/
+                                       
refdes_db[refdes.prefixes+1].prefix[0]='\0';
+                                       
refdes_db[refdes.prefixes].value=refdes.value;  /*Renumber... Finally :-)*/
+                                       break;
+                                       case MAX_PREFIX_COUNT:  /*Out of 
memory*/
                                        printf("grenum: out of memory. Too much 
refdes prefixes.\n");
                                        fclose(infile); /*Close the files*/
                                        fclose(outfile);
!                                       return OUT_OF_MEMORY;
!                                       default:
!                                       if(refdes.value-refdes_db[c].value==1)  
/*If we have the next value, don't do anything, just update the database.*/
                                                {
!                                               refdes_db[c].value=refdes.value;
!                                               break;
!                                               }
!                               /*Now we have a hole in numbering. Let's see if 
it'll be fixed, and seek for the maximum value. eg. R1,R2,R5,R3. So, we have to 
search for R3,R4, and set the db to R3.*/
! 
!                                       for(i=refdes_db[c].value+1; 
i<refdes.value; ++i)
!                                               {
!                                               if(seek_value(c, infile, i, 
refdes_db)==VALUE_NOT_FOUND)
                                                        {
!                                                       refdes_db[c].value=i-1;
                                                        break;
                                                        }
                                                }
!                                       if(i!=refdes.value)
!                                               flags|=GAP_DETECTED;
!                                       else
!                                               flags|=~GAP_DETECTED;
!                                       break;
!                                       }
!                               break;  /*continue our job*/
!                               case REFDES_WITHOUT_VALUE:
!                               c=refdes_lookup(refdes_db, &refdes);
!                               switch(c)
!                                       {
!                                       case -1:        /*No such prefix*/
!                                       
strcpy(&refdes_db[refdes.prefixes].prefix[0],&refdes.prefix[0]);
!                                       
refdes.value=++refdes_db[refdes.prefixes].value;
!                                       
refdes_db[refdes.prefixes+1].prefix[0]='\0';
!                                       break;
!                                       case MAX_PREFIX_COUNT:
!                                       printf("grenum: out of memory. Too much 
refdes prefixes.\n");
!                                       fclose(infile); /*Close the files*/
!                                       fclose(outfile);
!                                       return OUT_OF_MEMORY;
!                                       default:
!                                       if((flags&GAP_DETECTED)==GAP_DETECTED)
                                                {
!                                               for(i=refdes_db[c].value+1; 
seek_value(c, infile, i, refdes_db)!=VALUE_NOT_FOUND; ++i);
!                                               
refdes.value=refdes_db[c].value=i;
                                                }
!                                       else
!                                               
refdes.value=++refdes_db[c].value;      /*renumber*/
!                                       break;
!                                       }
!                               sprintf(buff, "refdes=%s%d\n", 
&refdes.prefix[0], refdes.value);
                                break;
!                               case REFDES_ERROR:      /*e.g. awdf#$%WSf82f8 
:-) No "=" signal in the refdes string.*/
                                        printf("grenum: parse error\n");
                                        fclose(infile); /*Close the files*/
                                        fclose(outfile);
!                                       return PARSE_ERROR;
                                }
!                       if(fputs(buff,outfile)==-1)     /*Finally, write the 
refdes line to the output file*/
                                {
!                               perror("grenum: could not write to tmp file");
                                fclose(infile); /*Close the files*/
                                fclose(outfile);
!                               return FILE_OP_ERROR;
                                }
                        }       /*Process ends here*/
! 
                fclose(outfile);
                strcpy(&buff[0],&infilename[0]); /*buff has the original 
infilename*/
  /*The next few lines implements the copy program*/
*************** int main(int argc, char *argv[])
*** 228,280 ****
                outfile=fopen(strcat(&buff[0],".save"),"w");
                if(outfile==NULL)
                        {
!                       printf("grenum: ould not create backup file\n");
                        fclose(infile); /*Close the file*/
!                       return -2;
                        }
!               while(fgets(&buff[0],sizeof(buff),infile)!=NULL) /*Read one 
line.*/
                        {
                        if(fputs(&buff[0],outfile)==-1)
                                {
!                               printf("grenum: could not write to backup 
file\n");
                                fclose(infile); /*Close the files*/
                                fclose(outfile);
!                               return -2;
                                }
                        }
                fclose(infile);
                fclose(outfile);
!               rename(&outfilename[0],&infilename[0]); /*Move the tmpfile to 
the original*/
                }
        printf("grenum: file(s) successfully processed\n");
!       return 0; /*Everything is okay*/
        }
  
  int parse_refdes(struct refdes_ *refdes, char *ref_str)
        {
        int i;
!       char buff[256],*cpr,*cp;
  
  /*
!  *This function parses the refdes line from the .sch file. It takes a pointer 
to the
!  *complete refdes definition string, and a pointer which points to a refdes 
structure
!  *where it'll store the info.
   *
!  *parse_refdes() will return
   *
!  *0 if there was a prefix with renumbered value (for example R1,IC3,U5);
!  *1 if there was a "?" mark found, and it has to be renumbered (e.g. U?);
!  *-1, if there was some uncool thing.
   *
!  *The refdes structure is filled with the prefix and the value.
   *
!  *Note that if a "?" is found, the value member remains untouched.
   */
  
  
        cpr=strstr(ref_str,"=");        /*seek for the "="*/
        if(cpr==NULL)   /*This should not happen*/
!               return -1;
        cp=strstr(ref_str,"?");
  /*refdes=U1           refdes=IC?
   *      |                      |
--- 225,322 ----
                outfile=fopen(strcat(&buff[0],".save"),"w");
                if(outfile==NULL)
                        {
!                       perror("grenum: ould not create backup file");
                        fclose(infile); /*Close the file*/
!                       return FILE_OP_ERROR;
                        }
!               while(fgets(&buff[0],BUFFSIZE,infile)!=NULL) /*Read one line.*/
                        {
                        if(fputs(&buff[0],outfile)==-1)
                                {
!                               perror("grenum: could not write to backup 
file");
                                fclose(infile); /*Close the files*/
                                fclose(outfile);
!                               return FILE_OP_ERROR;
                                }
                        }
                fclose(infile);
                fclose(outfile);
!               rename(outfilename, infilename);        /*Move the tmpfile to 
the original*/
                }
        printf("grenum: file(s) successfully processed\n");
!       return OK; /*Everything is okay*/
!       }
! 
! int get_refdes_from_file(FILE *fp, struct refdes_ *refdes, char *buff)
!       {
! 
! /*    Read one line from file, and return the following things:
!  *
!  *    END_OF_FILE if file reaches its end. The content of buff is unknown!
!  *
!  * NOT_REFDES_LINE if the current line is not a refdes. The line will
!  * saved in buff.
!  *
!  * Return according to parse_refdes(). The buff will contain the current line 
too.
!  */
! 
!       if(fgets(buff, BUFFSIZE, fp)==NULL)
!               return END_OF_FILE;
!       if(strstr(buff, "refdes=")==NULL)
!               return NOT_REFDES_LINE;
!       return parse_refdes(refdes, buff);
!       }
! 
! int seek_value(int prefix, FILE *fp, unsigned int value, struct refdes_ *db)
!       {
!       fpos_t filepos;
!       int ret;
!       struct refdes_ refdes;
!       char buff[BUFFSIZE];
! 
!       fgetpos(fp, &filepos);  /*First of all, save the file pos.*/
!       rewind(fp);     /*Rewind*/
!       while((ret=get_refdes_from_file(fp, &refdes, buff))!=END_OF_FILE)
!               {
!               if(ret==REFDES_WITH_VALUE && prefix==refdes_lookup(db, &refdes) 
&& refdes.value==value)
!                       {
!                       fsetpos(fp,&filepos);
!                       return VALUE_FOUND;
!                       }
!               }
!       fsetpos(fp,&filepos);
!       return VALUE_NOT_FOUND;
        }
  
  int parse_refdes(struct refdes_ *refdes, char *ref_str)
        {
        int i;
!       char buff[BUFFSIZE],*cpr,*cp;
  
  /*
!  * This function parses the refdes line from the .sch file. It takes a 
pointer to the
!  * complete refdes definition string, and a pointer which points to a refdes 
structure
!  * where it'll store the info.
!  *
!  * parse_refdes() will return
   *
!  * REFDES_WITH_VALUE if there was a prefix with renumbered value
!  * (for example R1,IC3,U5);
   *
!  * REFDES_WITHOUT_VALUE if there was a "?" mark found, and it has to be
!  * renumbered (e.g. U?);
   *
!  * REFDES_ERROR, if there was some uncool thing.
   *
!  * The refdes structure is filled with the prefix and the value.
!  *
!  * Note that if a "?" is found, the value member remains untouched.
   */
  
  
        cpr=strstr(ref_str,"=");        /*seek for the "="*/
        if(cpr==NULL)   /*This should not happen*/
!               return REFDES_ERROR;
        cp=strstr(ref_str,"?");
  /*refdes=U1           refdes=IC?
   *      |                      |
*************** int parse_refdes(struct refdes_ *refdes,
*** 289,311 ****
                printf("Prefix=%s\n",&refdes->prefix[0]);
  #endif
  
!               return 1;
                }
!       for(cp=cpr+1,i=0;(*cp != '\n' && *cp>='A' && *cp<='z');i++,cp++) /*No 
"?". Copy the prefix*/
                buff[i]=*cp;    /*Fill the buffer from char to char*/
        buff[i]='\0';   /*Terminate with NULL to be a string*/
  #ifdef DEBUG
        printf("Prefix=%s\n",&buff[0]);
  #endif
        strcpy(&refdes->prefix[0],&buff[0]);    /*Copy to refdes structure*/
!       for(i=0,cp;(*cp != '\n' && *cp>='0' && *cp<='9');cp++,i++)
                buff[i]=*cp;    /*Fill the buffer from char to char*/
        buff[i]='\0';   /*Terminate with NULL to be a string*/
  #ifdef DEBUG
        printf("Value=%s\n",&buff[0]);
  #endif
        refdes->value=abs(atoi(&buff[0]));
!       return 0;
        }
  
  void printhelp()
--- 331,370 ----
                printf("Prefix=%s\n",&refdes->prefix[0]);
  #endif
  
!               return REFDES_WITHOUT_VALUE;
                }
!       for(cp=cpr+1,i=0;(*cp != '\n' && *cp>='A' && *cp<='z');++i,++cp) /*No 
"?". Copy the prefix*/
                buff[i]=*cp;    /*Fill the buffer from char to char*/
        buff[i]='\0';   /*Terminate with NULL to be a string*/
  #ifdef DEBUG
        printf("Prefix=%s\n",&buff[0]);
  #endif
        strcpy(&refdes->prefix[0],&buff[0]);    /*Copy to refdes structure*/
!       for(i=0,cp;(*cp != '\n' && *cp>='0' && *cp<='9');++cp,++i)
                buff[i]=*cp;    /*Fill the buffer from char to char*/
        buff[i]='\0';   /*Terminate with NULL to be a string*/
  #ifdef DEBUG
        printf("Value=%s\n",&buff[0]);
  #endif
        refdes->value=abs(atoi(&buff[0]));
!       return REFDES_WITH_VALUE;
!       }
! 
! int refdes_lookup(struct refdes_ *db, struct refdes_ *ref)
!       {
!       int c=0;
! 
!       for(c=0;c<MAX_PREFIX_COUNT;++c)
!               {
!               if(strcmp(ref->prefix,(*(db+c)).prefix)==0)
!                       break;
!               else if((*(db+c)).prefix[0]=='\0')
!                       {
!                       ref->prefixes=c;
!                       return REFDES_NOT_FOUND;
!                       }
!               }
!       return c;
        }
  
  void printhelp()
Index: src/grenum.h
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/utils/src/grenum.h,v
retrieving revision 1.2
diff -C3 -p -r1.2 grenum.h
*** src/grenum.h        17 Aug 2005 17:40:07 -0000      1.2
--- src/grenum.h        24 May 2006 21:25:39 -0000
***************
*** 1,20 ****
  /* $Id: grenum.h,v 1.2 2005/08/17 17:40:07 danmc Exp $ */
! 
! #define GRVERSION "15082005"
  #define COMP_DATE __DATE__
  #define COMP_TIME __TIME__
  #define MAX_PREFIX_COUNT 50 /*This specifies the maximum number of different 
prefixes. e.g. Ux Rx Qx...*/
  #define PAGE_JMP 100  /*There will be R101 R102 on page 1, R201 R202 on page 
2.*/
  #define COUNT_START 0 /*Start the counting from this number+1*/
  #define MAX_PREFIX_SIZE 10 /*Define max prefx length*/
  
  struct refdes_
        {
        char prefix[MAX_PREFIX_SIZE];
        unsigned int value;
        };
  
  int main(int argc, char *argv[]);
  int parse_refdes(struct refdes_ *refdes, char *ref_str);
  void printhelp(void);
  void printver(void);
--- 1,68 ----
  /* $Id: grenum.h,v 1.2 2005/08/17 17:40:07 danmc Exp $ */
! #include <stdio.h>
! #define GRVERSION "24052006"
  #define COMP_DATE __DATE__
  #define COMP_TIME __TIME__
  #define MAX_PREFIX_COUNT 50 /*This specifies the maximum number of different 
prefixes. e.g. Ux Rx Qx...*/
  #define PAGE_JMP 100  /*There will be R101 R102 on page 1, R201 R202 on page 
2.*/
  #define COUNT_START 0 /*Start the counting from this number+1*/
  #define MAX_PREFIX_SIZE 10 /*Define max prefx length*/
+ #define BUFFSIZE 256
+ #define FILENAMESIZE 100
+ 
+ /*Flag definitions*/
+ 
+ /* flag bits
+  *
+  *    bit     function
+  *-----------------------
+  *    0               pkgskip
+  *    1               gap detected
+  *    2               not implemented
+  *    3               not implemented
+  *    4               not implemented
+  *    5               not implemented
+  *    6               not implemented
+  *    7               not implemented
+  */
+ 
+ #define PAGEJUMP 0x01
+ #define GAP_DETECTED 0x02
+ 
+ /*Return status of the main program*/
+ #define OK 0
+ #define NO_INPUT_FILE 1
+ #define FILE_OP_ERROR 2
+ #define PARSE_ERROR 3
+ #define OUT_OF_MEMORY 4
+ 
+ /*Return status of get_refdes_from_file()*/
+ #define END_OF_FILE 2
+ #define NOT_REFDES_LINE 3
+ 
+ /*Return status of parse_refdes()*/
+ #define REFDES_WITH_VALUE 0
+ #define REFDES_WITHOUT_VALUE 1
+ #define REFDES_ERROR -1
+ 
+ /*Return status of refdes_lookup()*/
+ #define REFDES_NOT_FOUND -1
+ 
+ /*Return status of seek_value()*/
+ #define VALUE_FOUND 1
+ #define VALUE_NOT_FOUND 0
  
  struct refdes_
        {
        char prefix[MAX_PREFIX_SIZE];
        unsigned int value;
+       int prefixes;
        };
  
  int main(int argc, char *argv[]);
+ int get_refdes_from_file(FILE *fp,struct refdes_ *refdes, char *buff);
+ int seek_value(int prefix, FILE *fp, unsigned int value, struct refdes_ *db);
  int parse_refdes(struct refdes_ *refdes, char *ref_str);
+ int refdes_lookup(struct refdes_ *db, struct refdes_ *ref);
  void printhelp(void);
  void printver(void);

Attachment: pgpKHud7lydOB.pgp
Description: PGP signature

Reply via email to