home *** CD-ROM | disk | FTP | other *** search
- /* DBASE II FILE TRANSLATOR VERSION 2.00-C
- **
- ** Date: 17 September 1984
- ** Author: James Bumgardner
- **
- ** USAGE:
- ** DBLIST datafile [>tofile] [$options]
- ** OPTIONS:
- ** S (structure only, mutually exclusive of other options)
- ** P (pack; skip deleted records, retain field size)
- ** L (list only)
- ** This program, along with an associated .OBJ file, and DBF.DQC
- ** replaces all the material in DBAS2TXT.LBR.
- **
- ** REVISIONS:
- ** Source code now in C (compiled with smc-m80 compiler)
- ** Works with any DBF file from version 2
- ** Accepts redirection
- ** Lists structure ala DBASE
- ** Allows option of skipping deleted records (Packing)
- ** If deleted records are skipped, delete/eof byte is not printed in
- ** order to retain field sizes
- **
- ** NOTE: The dBase II Program is copyrighted and all rights
- ** are reserved by Ashton-Tate. All the routines in the DBLIST
- ** program were conceived independently, and any similarities
- ** between DBLIST, and routines in the dBase program are only
- ** a result of parallel purpose.
- ** James Bumgardner 9/17/84
- ** 805-254-3481 Voice
- ** 818-365-2996 RBBS
- */
-
- #include "PREFIX.H"
-
- #asm
- IF1
- .PRINTX /* DBLIST.C */
- ENDIF
- external fprintf,strlen
- #endasm
-
- int ofp; /* file pointer */
- int vers,recl,rech,month,day,year,rell,relh,type,wid,dec;
- char dbfile[13];
- char field[10];
- char invar[5];
-
- main(argc,argv)
- int argc, *argv;
- {
- int ch,c,c1,c2,s,l,d,df;
- char *p;
- if (argc == 1)
- tutor();
- strcopy(argv[1],dbfile);
- /* GET ARGUMENTS */
- if (argc > 2) {
- strcopy(argv[2],invar);
- if (invar[0] != '$') {
- if (argc == 4)
- strcopy(argv[3],invar);
- }
- }
- d = FALSE; /* PACK */
- s = FALSE; /* STRUCTURE ONLY */
- l = FALSE; /* LIST ONLY */
- if (invar[0] == '$') {
- p = invar;
- for (++p; *p; ++p) {
- if (*p == 'P') d = TRUE;
- else {
- if (*p == 'S') s = TRUE;
- else {
- if (*p == 'L') l = TRUE;
- else tutor();
- }
- }
- }
- }
- /* ASSUME .DBF EXTENSION */
- if (instr(dbfile,".") == NULL) {
- p = dbfile;
- while (*p)
- ++p;
- *p++ = '.'; *p++ = 'D';
- *p++ = 'B'; *p++ = 'F'; *p++ = '\0';
- }
- if ((ofp = fopen(dbfile,"r")) == NULL)
- flerror();
- /* GET HEADER INFO */
- fputs("\nDBASE TRANSLATOR\n",stderr);
- if ((vers = cget(ofp)) == EOF) erxit();
- if (vers != 2) badvers();
- if ((recl = cget(ofp)) == EOF) erxit();
- if ((rech = cget(ofp)) == EOF) erxit();
- recl += rech * 256;
- if ((month = cget(ofp)) == EOF) erxit();
- if ((day = cget(ofp)) == EOF) erxit();
- if ((year = cget(ofp)) == EOF) erxit();
- if ((rell = cget(ofp)) == EOF) erxit;
- if ((relh = cget(ofp)) == EOF) erxit;
- rell += relh * 256;
- /* LIST STRUCTURE */
- c1 = 1;
- if ((ch = cget(ofp)) == EOF) erxit();
- C = 8;
- if (l == FALSE) {
- fputs("\nSTRUCTURE FOR FILE: ",stdout);
- prfname(dbfile);
- fprintf(stdout,"\nNUMBER OF RECORDS: %5d",recl);
- fprintf(stdout,"\nDATE OF LAST UPDATE: %d/%d/%d\n",month,day,year);
- fputs("\nFLD NAME TYPE WIDTH DEC",stdout);
- while (ch != CR) {
- p = field;
- *p++ = ch;
- for (c2 = 10; c2; --c2)
- if ((*p++ = cget(ofp)) == EOF) erxit();
- if ((type = cget(ofp)) == EOF) erxit();
- if ((wid = cget(ofp)) == EOF) erxit();
- if ((ch = cget(ofp)) == EOF) erxit();
- if ((ch = cget(ofp)) == EOF) erxit();
- if ((dec = cget(ofp)) == EOF) erxit();
- fprintf(stdout,"\n%3d %10s %c %3d %3d",c1,field,type,wid,dec);
- ++c1;
- c += 16;
- if ((ch = cget(ofp)) == EOF) erxit();
- }
- fprintf(stdout,"\n** TOTAL ** %5d\n",rell);
- if (s) exit();
- }
- /* SKIP TO DATA */
- while (++c != 521) {
- if ((ch = cget(ofp)) == EOF)
- erxit();
- }
- /* LIST DATA */
- fputs("\n\n",stderr);
- while ((ch = cget(ofp)) != EOF && ch != CPMEOF) {
- c = rell; /* RECLEN COUNT */
- df = TRUE; /* DO-NOT FLAG */
- if (ch != '*' || d == FALSE) {
- fputs("\n",stdout);
- if (d == FALSE)
- fputc(ch,stdout);
- }
- else
- df = FALSE;
- while (--c) { /* print rec */
- if ((ch = cget(ofp)) == EOF)
- erxit;
- if (df)
- fputc(ch,stdout);
- }
- }
- fputs("\n\nEnd of DBASE file.",stderr);
- fclose(ofp);
- } /* end of main */
-
- /*
- ** copy strings (would be a macro, but this is Small-C)
- */
- strcopy(str1,str2) char *str1, *str2; /* copy str1 into str2 */
- {
- while ((*str2++ = *str1++) != '\0');
- }
-
- prfname(str1) char *str1;
- {
- int i;
- while ((i = *str1++) != '\0')
- fputc(i,stdout);
- }
-
- /*
- ** find any occurence of str2 in str1, and return position
- */
- instr(str1,str2) char *str1, *str2;
- {
- int i, j, k, m;
- m = strlen(str2);
- if ((k = (strlen(str1) - m)) < 0)
- return (NULL);
- for (i = 0; i <= k; ++i) {
- for (j = 0; j < m; ++j) {
- if (str1[i+j] != str2[j])
- break;
- }
- if (j == m)
- return(i);
- }
- return (NULL);
- }
-
- tutor()
- {
- fputs("DBASE TRANSLATOR Version 2.00\n",stderr);
- fputs("\nUSAGE:\n\tdblist datafile [>tofile] [$options]\n",stderr);
- fputs("\nOPTIONS:\n\tP (pack)\n\tS (structure only)",stderr);
- fputs("\n\tL (list only)\n",stderr);
- exit();
- }
-
- erxit()
- {
- fputs("\nEND OF FILE ENCOUNTERED\n",stderr);
- exit();
- }
-
- flerror()
- {
- fputs("\nCAN'T OPEN FILE\n",stderr);
- exit();
- }
-
- badvers()
- {
- fputs("\nDBASE FILE IS NOT VERSION 2\n",stderr);
- exit();
- }
- /* End of DBLIST.C */