Commit | Line | Data |
---|---|---|
54fea4c1 C |
1 | /* d_main.c - make the decode routine into a stand alone program */ |
2 | ||
3 | #ifndef lint | |
4 | static char *rcsid = "$Header: /f/osi/others/quipu/photo/RCS/d_main.c,v 7.2 90/09/24 15:36:39 mrose Exp $"; | |
5 | #endif | |
6 | ||
7 | /* | |
8 | * $Header: /f/osi/others/quipu/photo/RCS/d_main.c,v 7.2 90/09/24 15:36:39 mrose Exp $ | |
9 | * | |
10 | * | |
11 | * $Log: d_main.c,v $ | |
12 | * Revision 7.2 90/09/24 15:36:39 mrose | |
13 | * update | |
14 | * | |
15 | * Revision 7.1 90/03/15 11:18:08 mrose | |
16 | * quipu-sync | |
17 | * | |
18 | * Revision 7.0 89/11/23 22:01:36 mrose | |
19 | * Release 6.0 | |
20 | * | |
21 | */ | |
22 | ||
23 | /* | |
24 | * NOTICE | |
25 | * | |
26 | * Acquisition, use, and distribution of this module and related | |
27 | * materials are subject to the restrictions of a license agreement. | |
28 | * Consult the Preface in the User's Manual for the full terms of | |
29 | * this agreement. | |
30 | * | |
31 | */ | |
32 | ||
33 | ||
34 | ||
35 | #include <sys/file.h> | |
36 | #include <stdio.h> | |
37 | #include "quipu/photo.h" | |
38 | ||
39 | ||
40 | int two_passes = 0; | |
41 | ||
42 | char *getenv (); | |
43 | ||
44 | main (argc,argv) | |
45 | int argc; | |
46 | char ** argv; | |
47 | { | |
48 | char *inbuf; | |
49 | char *cp; | |
50 | char * name; | |
51 | int n, count, len; | |
52 | char * malloc(); | |
53 | ||
54 | if (argc > 1) | |
55 | name = *++argv; | |
56 | else | |
57 | if ((name = getenv ("RDN")) == 0) | |
58 | name = "unknown"; | |
59 | ||
60 | if ((len = find_size()) < 0) { | |
61 | fprintf(stderr, "\n"); | |
62 | exit(-1); | |
63 | } | |
64 | if ((inbuf = malloc(len)) == NULL) { | |
65 | fprintf(stderr, "PHOTO: Couldn't malloc() %d bytes\n", n); | |
66 | exit(-1); | |
67 | } | |
68 | for (cp = inbuf, n = len; n > 0; ) { | |
69 | if ((count = read (0, cp, n)) <= 0) | |
70 | break; | |
71 | cp += count; | |
72 | n -= count; | |
73 | } | |
74 | ||
75 | if (decode_t4 (inbuf, name, len) == -1) { | |
76 | (void) fprintf (stderr,"\n"); | |
77 | exit (-1); | |
78 | } | |
79 | if (two_passes && decode_t4 (inbuf, name, len) == -1) { | |
80 | (void) fprintf (stderr,"\n"); | |
81 | exit (-1); | |
82 | } | |
83 | } | |
84 | ||
85 | static find_size() | |
86 | { | |
87 | char c, i; | |
88 | long size = 0; | |
89 | ||
90 | /* read the ASN.1 "magic number" for bitstring */ | |
91 | read(0, &c, 1); | |
92 | ||
93 | /* how many of the next N bytes store the size? */ | |
94 | read(0, &c, 1); | |
95 | for (c &= 0x7f; c > 0; c--) { | |
96 | read(0, &i, 1); | |
97 | size = (size << 8) | (i & 0xff); | |
98 | } | |
99 | ||
100 | return(size); | |
101 | } |