Article 5153 of comp.sys.handhelds:
Path: wuarchive!zaphod.mps.ohio-state.edu!maverick.ksu.ksu.edu!uafhp!engr.uark.edu!ls0
From: ls0@engr.uark.edu (LI SHENG)
Newsgroups: comp.sys.handhelds
Subject: Re: Collecting all the HP48 internal addresses
Summary: Combine SYSEVAL files
Message-ID: <5809@uafhp.uark.edu>
Date: 7 Jan 91 09:53:25 GMT
References: <37588@cup.portal.com>
Sender: netnews@uafhp.uark.edu
Lines: 245

In article <37588@cup.portal.com>, Jake-S@cup.portal.com(Jake G Schwartz)writes:
> Hi Guys - 
>    Recently I got Jan Brittenson's enormous HP48 symbol table file from
> Wayne Scott's HP-MAIL-SERVER at wscott@ecn.purdue.edu, and more recently
> downloaded Derek Nickel's HP48 address list. In comparing these two lists,
> it was obvious that each contained over a hundred locations different from
> the other, so I merged the two and sorted the whole thing with respect to
> increasing addresses. 
>    I wonder if anyone else is compiling a similar list based on his/her
> own research? I know that Rick Grevelle has been doing a lot of additional
> significant research, and intends to post his list soon as well. Perhaps

    Here are two programs that enable you to combine two HP48SX RPL
address files into one.  So now you can add new information into
you list whenever it comes up.

   The first program is called "sorts.c".  This program takes a list of
RPL addresses sort them and put them in a file with standard format which
is required by "combine", the program realy does the combining.  To make
the program run properly, there must be a delimitor between the RPL number
and the comment for it.  The delimitor can be either "=", ":", or a SPACE.

   
Example:
original file "test1" contain :
1c9b8=SIZE
71be:MC: continue RPL
1a5c4 BEEP
<EOF>

run the program :
%sorts <test1 >test2

The results will be put in the file "test2".  "test2" will have :
071BC MC: continue RPL
1A5C4 BEEP
1C9B8 SIZE
<EOF>


After you got the sorted file, run the program combine to combine two 
files together.  The command format looks like :

%combine file1 file2 file3

where :
        file1 = input file name #1
        file2 = input file name #2
        file3 = outfile name

The program will take the information from "file1" and "file2" put them
into file3.  If the are two number that are the same, the comment from 
"file1" will be put into the output file.

Example:

"file1" contain :
00000 file1 line1
02222 file1 line2
03333 file1 line3

"file2" contain :
01111 file2 line1
02222 file2 line2
04444 file2 line3

After running "combine":
"file3" contain :
00000 file1 line1
01111 file2 line1
02222 file1 line2
03333 file1 line3
04444 file2 line3

For DOS users : I did not try these programs on a PC.  But I don't think
there would be any trouble to run "combine".  But "sorts" needs alot of
memory; I suspect it will run.  Try to compile with huge model.
Before compile these programs on PC, add #include <string.h> after
#include <stdio.h>.

If you have any problems, don't hesitate to ask me.  Email me at :
ls0@engr.uark.edu

Li Sheng

---------------------  sorts.c Start ---------------------------------

/************************************************************/
/*                                                          */
/*     Program : sorts.c                                    */
/*     Programer : Li Sheng                                 */
/*                 ls0@engr.uark.edu                        */
/*     Date : 1-7-1991                                      */
/************************************************************/

#include <stdio.h>
/* delete the comment mark when compile on a P
   #include <string.h>
*/
#define STRINGLEN 80 
#define MAX_NUM 4000

struct {
	  char fname[STRINGLEN+1];
	  int file_len;
       } fnames[MAX_NUM];

main()
{

int i, j;
int tag[MAX_NUM];
char instr[80];
char *sizeptr, *nameptr;
char temp[6];

/*  Get the RPL number and comment for it  */
for(i=0;(i<MAX_NUM) && gets(instr);i++)
{
   sscanf(instr,"%[^:\=\?\ ]",temp);
   strcpy(fnames[i].fname, instr+strlen(temp)+1);
   sscanf(temp,"%x",&fnames[i].file_len);
}

/* do the sort */
bsort(i, tag);

/* print sorted list out on  */
for(j=0;j<i;j++)
{
   if(fnames[tag[j]].file_len < 0xf) printf("0000");
   else if(fnames[tag[j]].file_len < 0xff) printf("000");
   else if(fnames[tag[j]].file_len <0xfff) printf("00");
   else if(fnames[tag[j]].file_len < 0xffff) printf("0");
   printf("%hX %s\n",fnames[tag[j]].file_len, fnames[tag[j]].fname);
}
}
/*********************************************************************/
/*       The following function does a indexed bubble sort           */
/*********************************************************************/
bsort(entries, tag)
int entries, tag[MAX_NUM];
{
   int swapped=1, i, hold;

   for(i=0;i<MAX_NUM;i++) tag[i] = i;

   while(swapped)  /* do the loop until no elements are swapped */
   {
      swapped = 0;
      for(i=0;i<entries-1;i++)
	 if(fnames[tag[i]].file_len > fnames[tag[i+1]].file_len)
         {
            swapped = 1;
            hold = tag[i];
            tag[i] = tag[i+1];
            tag[i+1] = hold;
         }
   }
}
--------------------   sorts.c END   --------------------------------

-------------------- combine.c Start --------------------------------

/************************************************************/
/*                                                          */
/*         Program : combine.c                              */
/*         By : Li Sheng                                    */
/*              ls0@engr.uark.edu                           */
/*         Date : 1-7-1991                                  */
/************************************************************/

#include <stdio.h>
/* delete the comment marks if compiled on PC
  #include <string.h>
*/

main(argc, argv)
char **argv;
{
FILE *infile[2], *outfile;
int  i;
char temp[6];
int file_flag;
char in_string[2][80];
int item_id[2]; 

   if(argc != 4)
   {
      printf("ERROR!!!!!\n");
      printf("Format: combine in_file1 in_file2 outfile\n");
      exit();
   }
 
   infile[0]=fopen(argv[1],"r");
   infile[1]=fopen(argv[2],"r");
   outfile=fopen(argv[3],"w");
   if((infile[0]==NULL)||(infile[1]==NULL))
   {
      printf("File not exist\n");
      exit();
   }
  
/*  set up  */
file_flag = 1;
fgets(in_string[0],100,infile[0]);  
sscanf(in_string[0],"%x",&item_id[0]);

/*  do the combining   */
while(fgets(in_string[file_flag],100,infile[file_flag]))
{
   sscanf(in_string[file_flag],"%x",&item_id[file_flag]);
   if(item_id[0] == item_id[1])
   {
      fputs(in_string[0],outfile);
      fgets(in_string[1],100,infile[1]);
      sscanf(in_string[1],"%x",&item_id[1]);
      file_flag = 0;
   }
   else if(item_id[0] < item_id[1])
   {
      fputs(in_string[0],outfile);
      file_flag = 0;
   }
   else
   {
      fputs(in_string[1],outfile);
      file_flag = 1;
   }
}

/*  file_flag points to the remaining file  */
if(file_flag == 0) file_flag = 1;
else file_flag = 0;

do
{
   fputs(in_string[file_flag],outfile);
} while(fgets(in_string[file_flag],100,infile[file_flag]));

fclose(infile[0]);
fclose(infile[1]);
fclose(outfile);
}
-------------------  combine.c END -------------------------


