| 1 | /* Program P1 - MF dump or display according an in-stream/file |
|---|
| 2 | format specification |
|---|
| 3 | */ |
|---|
| 4 | |
|---|
| 5 | #include <stdio.h> |
|---|
| 6 | #include <string.h> |
|---|
| 7 | |
|---|
| 8 | #include "cisis.h" /* CISIS Interface header file */ |
|---|
| 9 | #include "cirun.h" /* CISIS Interface runtime declarations */ |
|---|
| 10 | |
|---|
| 11 | #if !DOS32BITS |
|---|
| 12 | #define OPEN30 1 |
|---|
| 13 | #endif |
|---|
| 14 | |
|---|
| 15 | /* program parameters */ |
|---|
| 16 | char *dbnp; |
|---|
| 17 | /* recfmt() */ |
|---|
| 18 | char *fmtp=NULL; |
|---|
| 19 | char fmtarea[MAXMFRL]; /* format spec&results */ |
|---|
| 20 | LONGX parmlw=79L; /* line width */ |
|---|
| 21 | |
|---|
| 22 | void main(argc,argv) |
|---|
| 23 | int argc; |
|---|
| 24 | char *argv[]; |
|---|
| 25 | { |
|---|
| 26 | RECSTRU *recp; /* current vrecp pointer */ |
|---|
| 27 | LONGX ridx; /* current vrecp index */ |
|---|
| 28 | LONGX mfn; /* current mfn */ |
|---|
| 29 | |
|---|
| 30 | char *prompt=NULL; /* printf+getchar after each record */ |
|---|
| 31 | LONGX parmfrom=1,parmto=LONGX_MAX,parmcount=LONGX_MAX; |
|---|
| 32 | LONGX count; |
|---|
| 33 | int argnext; |
|---|
| 34 | char *p,*q; |
|---|
| 35 | |
|---|
| 36 | #if OPEN30 |
|---|
| 37 | union REGS d33_regs; |
|---|
| 38 | struct SREGS d33_sregs; |
|---|
| 39 | unsigned short newax; |
|---|
| 40 | int n; |
|---|
| 41 | #endif |
|---|
| 42 | |
|---|
| 43 | argnext=1; |
|---|
| 44 | if (argc <= argnext) { |
|---|
| 45 | printf("%s",cicopyr("Utility P1")); |
|---|
| 46 | printf("\n"); |
|---|
| 47 | printf("p1 <dbn> [<option> [...]] \n"); |
|---|
| 48 | printf("\n"); |
|---|
| 49 | printf("options: {from|to|count}=<n> \n"); |
|---|
| 50 | printf(" pft={<fmt>|@[<file>]} \n"); |
|---|
| 51 | printf(" lw=<line width> \n"); |
|---|
| 52 | printf(" prompt={<text>|@<file>} \n"); |
|---|
| 53 | #if OPEN30 |
|---|
| 54 | printf(" files=<n> \n"); |
|---|
| 55 | #endif |
|---|
| 56 | printf("\n"); |
|---|
| 57 | exit(1); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | /* get default values */ |
|---|
| 61 | dbnp=argv[argnext++]; |
|---|
| 62 | |
|---|
| 63 | /* |
|---|
| 64 | get optional parameters |
|---|
| 65 | */ |
|---|
| 66 | for ( ; argnext < argc; argnext++) { |
|---|
| 67 | |
|---|
| 68 | p=argv[argnext]; |
|---|
| 69 | |
|---|
| 70 | #if OPEN30 |
|---|
| 71 | if (sscanf(p,"files=%d",&n) == 1) { |
|---|
| 72 | d33_regs.h.ah = 0x67; /* Set handle count */ |
|---|
| 73 | d33_regs.x.bx = n; /* no of handles */ |
|---|
| 74 | newax=intdosx(&d33_regs,&d33_regs,&d33_sregs); |
|---|
| 75 | if (d33_regs.x.cflag) fprintf(stderr,"AX = %04x [%02d]\n",newax,n); |
|---|
| 76 | continue; |
|---|
| 77 | } |
|---|
| 78 | #endif |
|---|
| 79 | if (strncmp(p,"from=",5) == 0) { |
|---|
| 80 | if (sscanf(p+5,"%"_LD_,&parmfrom) != 1) fatal(p); |
|---|
| 81 | continue; |
|---|
| 82 | } |
|---|
| 83 | if (strncmp(p,"to=",3) == 0) { |
|---|
| 84 | if (sscanf(p+3,"%"_LD_,&parmto) != 1) fatal(p); |
|---|
| 85 | continue; |
|---|
| 86 | } |
|---|
| 87 | if (strncmp(p,"count=",6) == 0) { |
|---|
| 88 | if (sscanf(p+6,"%"_LD_,&parmcount) != 1) fatal(p); |
|---|
| 89 | continue; |
|---|
| 90 | } |
|---|
| 91 | if (strncmp(p,"prompt=",7) == 0) { |
|---|
| 92 | q=p+7; |
|---|
| 93 | prompt=loadfile(NULL,'@',q,prompt,0L,'\n'); |
|---|
| 94 | if (!prompt) fatal(q); |
|---|
| 95 | continue; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | if (strncmp(p,"fsiz=",5) == 0) { |
|---|
| 99 | if (sscanf(p+5,"%"_LD_,&fmt_fsiz) != 1) fatal(p); |
|---|
| 100 | continue; |
|---|
| 101 | } |
|---|
| 102 | if (strncmp(p,"lw=",3) == 0) { |
|---|
| 103 | if (sscanf(p+3,"%"_LD_,&parmlw) != 1) fatal(p); |
|---|
| 104 | continue; |
|---|
| 105 | } |
|---|
| 106 | if (strncmp(p,"pft=",4) == 0) { |
|---|
| 107 | q=p+4; |
|---|
| 108 | if (strcmp(q,"@") == 0) sprintf(q=fmtarea,"@%s.pft",dbnp); |
|---|
| 109 | fmtp=loadfile(dbnp,'@',q,NULL,0L,'\0'); |
|---|
| 110 | if (!fmtp) fatal(p); |
|---|
| 111 | continue; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | fatal(p); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | ridx=nrecs; |
|---|
| 118 | for (count=0, mfn=parmfrom; mfn <= parmto; mfn++) { |
|---|
| 119 | if (count++ >= parmcount) break; |
|---|
| 120 | RECORD(ridx,dbnp,mfn); |
|---|
| 121 | if (RECrc == RCEOF) break; |
|---|
| 122 | if (fmtp) { |
|---|
| 123 | if (recfmt(ridx,parmlw,fmtp,fmtarea,sizeof(fmtarea)-1L) < 0) |
|---|
| 124 | fatal(fmtp+fmt_errof); |
|---|
| 125 | printf("%s",fmtarea); |
|---|
| 126 | } |
|---|
| 127 | else prtfields(recp,MFRmfn); |
|---|
| 128 | if (prompt) { printf("%s",prompt); if (getchar() == 'x') break; } |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | exit(0); |
|---|
| 132 | } |
|---|