home *** CD-ROM | disk | FTP | other *** search
- /*
- Evaluate Check-sum for Prom FILE
- R.J.P. 18/7/92
- */
- #include <stdio.h>
- #include <stdlib.h>
- #ifdef _ARC_
- #include "kernel.h"
- #else
- #include <dos.h>
- #include <dir.h>
- #include <mem.h>
- #endif
-
- #include <string.h>
- #include <ctype.h>
-
- #undef BOOL
- #undef FALSE
- #undef TRUE
-
- typedef unsigned int Uint ;
- typedef unsigned char Uchar ;
- #define BOOL Uint
- #define FALSE 0
- #define TRUE 1
-
- #ifdef _ARC_
-
- char *dirscan (const char *f)
- {
- _kernel_swi_regs regs;
- _kernel_oserror *err;
-
- static int ptr;
- static int len;
- static int last_notwild;
- static char *file;
- static char *dir;
- static char *name;
- static char path[255];
- static char res[255];
-
- if (f && *f)
- {
- strcpy (path, f);
-
- /* Try for a directory prefix */
- file = strrchr (path, '.');
-
- /* If not, try for a filing system prefix */
- if (file == NULL)
- {
- if (*path == '-')
- file = strchr (path + 1, '-');
- else
- file = strchr (path, ':');
- }
-
- if (file)
- {
- len = file - path + 1;
- strncpy (res, path, len);
-
- name = &res[len];
- len = 255 - len;
-
- dir = path;
- *file++ = '\0';
- }
- else
- {
- name = res;
- len = 255;
-
- file = path;
- dir = "";
- }
-
- /* Is the file name wildcarded? */
- if (strchr (file, '*') || strchr (file, '#'))
- last_notwild = 0;
- else
- {
- strcpy (name, file);
- last_notwild = 1;
- return res;
- }
-
- ptr = 0;
- }
-
- /* If we're looking for more from a non-wild name, no luck */
- if (last_notwild)
- return 0;
-
- regs.r[0] = 9;
- regs.r[1] = (int) dir;
- regs.r[2] = (int) name;
- regs.r[4] = ptr;
- regs.r[5] = len;
- regs.r[6] = (int) file;
-
- do
- {
- regs.r[3] = 1;
- err = _kernel_swi (0x0C, ®s, ®s);
-
- if (err)
- {
- fprintf (stderr, "*** Error (%d) - %s\n",
- err->errnum, err->errmess);
- exit (1);
- }
-
- } while (regs.r[3] == 0 && regs.r[4] >= 0);
-
- ptr = regs.r[4];
-
- if (ptr < 0)
- return 0;
-
- return res;
- }
- #else
-
- #define _ATTR_ (FA_DIREC | FA_RDONLY | FA_HIDDEN)
- Uint DirectorySize( const char *wild ,int fattr,BOOL B_Pack )
- {
- int N = 0 ;
- struct ffblk LFN ;
- struct ffblk *l = &LFN ;
-
-
- if( findfirst(wild , l , fattr ) )
- return 0 ;
-
- do {
- if (B_Pack)
- N += strlen( l->ff_name ) + 1 ;
- else
- N += sizeof( l->ff_name ) ;
- }
- while( !findnext( l ) ) ;
- return N ;
- }
-
-
- Uint DirectoryList(
- Uint *N, /* Number of files Found */
- char *fn_vec, /* Names in vector */
- const char *wild,
- int fattr,
- BOOL B_Pack
- )
- {
- struct ffblk LFN ;
- struct ffblk *l = &LFN ;
-
- *N = 0 ;
- if( findfirst(wild,l,fattr) )
- goto LB_EXIT ;
-
- do
- {
- strcpy( fn_vec , l->ff_name ) ;
- if (B_Pack)
- fn_vec += strlen( l->ff_name ) + 1;
- else
- fn_vec += sizeof(l->ff_name) ;
-
- *N += 1 ;
- }
- while( !findnext( l ) ) ;
- LB_EXIT:
- return *N ;
- }
- #endif
-
-
- int main(int ac,char **av)
- {
- #ifndef _ARC_
- Uint nf ;
- char Path[133] ;
- char w[133] ;
- char *FP,*cp ;
- struct ffblk *tf ;
- #endif
- char *FL ;
- Uint nc ;
- #ifdef _ARC_
- unsigned short cks = 0 ;
- #else
- Uint cks = 0 ;
- #endif
- Uchar nxb ;
-
- FILE *IB ;
- BOOL B_lf ;
-
- while( --ac )
- {
- printf("File List of %s\n" , *++av ) ;
-
- #ifdef _ARC_
- #else
- strcpy(Path,*av) ;
-
- if( (cp = strrchr(Path,'\\')),cp != 0 )
- *(cp+1) = 0 ;
- else if( (cp = strrchr(Path,':')),cp != 0 )
- *(cp+1) = 0 ;
- else
- *Path = 0 ;
-
- if( ( nf = DirectorySize( *av ,_ATTR_,FALSE ) ), nf == 0 )
- {
- fprintf(stderr,"*Need file parameter\n") ;
- exit(3) ;
- }
- FP = FL = (char *)malloc( nf * sizeof(char)) ;
- nf = DirectoryList( &nf , FL , *av , _ATTR_ ,FALSE) ;
- #endif
-
- #ifdef _ARC_
- for ( FL = dirscan( *av) ; FL ; FL = dirscan(0) )
- {
- if((IB = fopen(FL,"rb")),IB == 0 )
- {
- fprintf(stderr,"*Can't read [%s]\n",FL) ;
- exit(2) ;
- }
- printf("%s\n",FL) ;
- #else
- while ( nf-- )
- {
- sprintf(w,"%s%s",Path,FL) ;
- if((IB = fopen(w,"rb")),IB == 0 )
- {
- fprintf(stderr,"*Can't read [%s]\n",w) ;
- free(FP) ;
- exit(2) ;
- }
- printf("%s\n",w) ;
- #endif
-
- for(nc=0;;nc++)
- {
- nxb = fgetc(IB) ;
- if(feof(IB)) break ;
- cks += nxb ;
- }
- printf("Check-Sum = %04x (%d Bytes)\n",cks,nc) ;
- fseek(IB,0x40L,SEEK_SET) ;
- printf("Prom Details\n") ;
-
- for(B_lf=TRUE , nxb=0;nxb!=0xff;)
- {
- nxb = (Uchar)fgetc(IB) ;
- if(feof(IB)) break ;
- if ( nxb == '\n' )
- { B_lf = TRUE ; putchar( '\n' ) ; }
- else
- if ( B_lf && isspace(nxb) ) ;
- else
- { putchar(nxb) ; B_lf = FALSE ; }
- }
- fclose(IB) ;
- printf("\n\n") ;
- #ifdef _ARC_
- #else
- FP += sizeof( tf->ff_name) ;
- #endif
- }
- printf("\n\n" ) ;
-
- #ifdef _ARC_
- #else
- free( FL ) ;
- #endif
- }
- return 0 ;
- }
-