root/tags/5.52/ctlmfn.c

Revision 4, 2.6 kB (checked in by heitor.barbieri, 2 years ago)

Versão 5.52 do cisis (28/04/2010)

Line 
1#include <stdio.h>
2#include <string.h>
3#include <limits.h>
4
5#include "cisis.h"
6#include "cirun.h"
7
8#define M0BSIZ  sizeof(M0STRU)
9
10char line[CIMPL+1];
11
12#if ANSI
13LONGX get(char *msg,LONGX def,LONGX min,LONGX max);
14#else
15LONGX get();
16#endif
17
18void main(argc,argv)
19int argc;
20char *argv[];
21{
22    RECSTRU *recp;
23    int fd;
24    char *dbnp;
25    off_t nbytes,nblocks;
26
27    if (argc < 2) {
28        printf("%s",cicopyr("Utility CTLMFN"));
29        printf("\n");
30        printf("ctlmfn <dbn> \n");
31        printf("\n");
32        exit(1);
33    }
34
35    dbxopt_ordwr=O_RDWR; fd=dbxopen(argv[1],dbnp=argv[1],mx1extp);
36
37    recp=vrecp[recallok(0L,M0BSIZ)];
38
39    if (read(fd,(char *)MFX,M0BSIZ) != M0BSIZ) fatal("read");
40
41    prtcontrol(recp,dbnp);
42
43    nbytes=LSEEK64(fd,0L,SEEK_END);
44    nblocks=nbytes/MSBSIZ;
45    if (nblocks * MSBSIZ != nbytes)
46        printf("\nfile has %"P_OFF_T" bytes. %"P_OFF_T" bytes (%"P_OFF_T" blocks) considered\n",
47            (LONG_LONG)nbytes,(LONG_LONG)(nblocks*MSBSIZ),(LONG_LONG)nblocks);
48
49    MF0ctlmfn=0L;
50    if (MF0nxtmfb <= 0 || MF0nxtmfb > nblocks) MF0nxtmfb = nblocks;
51    if (MF0nxtmfp <= 0 || MF0nxtmfp > MSBSIZ-LEADER) MF0nxtmfp = MSBSIZ-LEADER;
52    if (MF0mftype != 0 && MF0mftype != 1
53        && MF0mftype != 256 && MF0mftype != 512 && MF0mftype != 768
54    ) MF0mftype = 0;
55
56    MF0nxtmfn=get("nxtmfn",MF0nxtmfn,1,MAXUPDMFN);
57    MF0nxtmfb=get("nxtmfb",MF0nxtmfb,1,nblocks);
58    MF0nxtmfp=get("nxtmfp",MF0nxtmfp,1,MSBSIZ);
59    MF0mftype=get("mftype",MF0mftype,0,768);
60    if (MF0mftype != 0 && MF0mftype != 1
61        && MF0mftype != 256 && MF0mftype != 512 && MF0mftype != 768
62    ) MF0mftype = 0;
63    MF0reccnt=get("reccnt",MF0reccnt,0,LONGX_MAX);
64    MF0mfcxx1=get("mfcxx1",MF0mfcxx1,0,LONGX_MAX);
65    MF0mfcxx2=get("mfcxx2",MF0mfcxx2,0,LONGX_MAX);
66    MF0mfcxx3=get("mfcxx3",MF0mfcxx3,0,LONGX_MAX);
67
68    printf("\n");
69    prtcontrol(recp,dbnp);
70    printf("\nok ?  ");
71    if (strcmp(gets(line),"ok")) fatal("ok expected");
72
73    LSEEK64(fd,0L,0); /* rewind */
74    if (CIWRITE(fd,(char *)MFX,M0BSIZ) != M0BSIZ) fatal("write");
75    CLOSE(fd);
76    exit(0);
77}
78
79
80LONGX get(msg,def,min,max)
81char *msg;
82LONGX def;
83LONGX min;
84LONGX max;
85{
86    LONGX val;
87    static int last=1;
88
89    if (last) printf("\n");
90
91    for (; ;) {
92        printf("%s [%ld]: ",msg,def);
93        gets(line);
94        if (line[0] == '\0') {
95            val=def;
96            last=0;
97            break;
98        }
99        if (sscanf(line,"%ld",&val) != 1) {
100            printf("\007\n");
101            continue;
102        }
103        if (val < min || val > max) {
104            printf("\007[%ld - %ld]\n",min,max);
105            continue;
106        }
107        last=1;
108        break;
109    }
110
111    return(val);
112}
Note: See TracBrowser for help on using the browser.