root/trunk/app0.c

Revision 389, 1.8 kB (checked in by heitor.barbieri, 3 weeks ago)

essage first commit

Line 
1/* ------------------------------ app0.c ----------------------------- */
2
3#include <stdio.h>
4#include <string.h>
5
6#define TRACE   0
7
8#include "cisis.h" /* CISIS Interface */
9#include "cirun.h" /* runtime area and defines by AOT */
10
11/* main */
12#if ANSI
13void main (int argc, char *argv[])
14#else
15void main(argc,argv)
16int argc;
17char *argv[];
18#endif
19{
20    char *filioxp,*filnamp,*p;
21    int fd0=0,fd1,i;
22    off_t skip;
23    unsigned int nread,blksize=BUFSIZ;
24    char *bufferp=NULL;
25
26    if (argc < 2) {
27        printf("%s",cicopyr("Utility AOT/APP0"));
28        printf("\n");
29        printf("app0 [create=]<filapp> <fil1>[,skip] <fil2>[,skip] ...");
30        printf(" [blksize=<%d>]\n",blksize);
31        printf("\n");
32        exit(1);
33    }
34
35    /* get parms */
36    filioxp=argv[1];
37    filioxp=dbxopenc(filioxp,filioxp,&fd0,NULL,filioxp,0,0); /*..do not force create= */
38    printf("%s=%"P_OFF_T" bytes\n",filioxp, (LONG_LONG)LSEEK64(fd0,0L,SEEK_END));
39
40    for (i=2; i < argc; i++) {
41        if (strncmp(argv[i],"blksize=",8) == 0) {
42            blksize=atol(argv[i]+8);
43            printf("blksize=%"_LD_"\n",(LONGX)blksize);
44            if (blksize <= 0 || blksize > ALLOMAXV) fatal(argv[i]);
45            if (bufferp) { FREE(bufferp); bufferp=NULL; }
46            continue;
47        }
48        if (!bufferp) {
49            bufferp=(char *)ALLOC((ALLOPARM)blksize);
50            if (bufferp == (char *)ALLONULL) fatal(argv[i]);
51        }
52        filnamp=argv[i];
53        p=strchr(filnamp,',');
54        if (p) {*p='\0'; skip=atol(p+1);} else skip=0;
55        fd1=dbxopen("",filnamp,"");
56        printf("%s=%"P_OFF_T" bytes.. ",filnamp, (LONG_LONG)LSEEK64(fd1,0L,SEEK_END));
57        LSEEK64(fd1,skip,SEEK_SET);
58        while ((nread=read(fd1,bufferp,blksize /*41*/)) > 0)
59            if (write(fd0,bufferp,nread) != nread) fatal("write");
60        close(fd1);
61        printf("%s=%"P_OFF_T" bytes\n",filioxp,(LONG_LONG)LSEEK64(fd0,0L,SEEK_END));
62    }
63
64    close(fd0);
65    exit(0);
66}
Note: See TracBrowser for help on using the browser.