1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * mgticbuild.c -- Program to build the textual image library
|
---|
4 | * Copyright (C) 1994 Stuart Inglis
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | *
|
---|
20 | * $Id: mgticbuild.c 3745 2003-02-20 21:20:24Z mdewsnip $
|
---|
21 | *
|
---|
22 | **************************************************************************/
|
---|
23 |
|
---|
24 | #include "sysfuncs.h"
|
---|
25 |
|
---|
26 | #include "marklist.h"
|
---|
27 | #include "pbmtools.h"
|
---|
28 | #include "extractor.h"
|
---|
29 | #include "utils.h"
|
---|
30 |
|
---|
31 |
|
---|
32 | void
|
---|
33 | usage ()
|
---|
34 | {
|
---|
35 | fprintf (stderr, "usage: \n"
|
---|
36 | "\tmgticbuild libraryfile infile.pbm [infile2 infile3 ...]\n");
|
---|
37 | exit (1);
|
---|
38 | }
|
---|
39 |
|
---|
40 | void
|
---|
41 | main (int argc, char *args[])
|
---|
42 | {
|
---|
43 | int i;
|
---|
44 | FILE *lib = NULL, *inf = NULL;
|
---|
45 | marklistptr list = NULL, step;
|
---|
46 | Pixel **bitmap;
|
---|
47 | int cols, rows;
|
---|
48 | int count, pos = 0;
|
---|
49 | char *libraryname = NULL;
|
---|
50 |
|
---|
51 | if (argc < 2)
|
---|
52 | usage ();
|
---|
53 |
|
---|
54 | for (i = 1; i < argc; i++)
|
---|
55 | {
|
---|
56 | if (!strcmp (args[i], "-v"))
|
---|
57 | V = 1;
|
---|
58 | else if (!strcmp (args[i], "-h"))
|
---|
59 | usage ();
|
---|
60 | else if (args[i][0] == '-')
|
---|
61 | error_msg (args[0], "unknown switch:", args[i]);
|
---|
62 | else if (!libraryname)
|
---|
63 | libraryname = args[i];
|
---|
64 | else
|
---|
65 | pos = i;
|
---|
66 | }
|
---|
67 |
|
---|
68 | if (!libraryname)
|
---|
69 | error_msg (args[0], "please specify a library file", "");
|
---|
70 | if (pos < 2)
|
---|
71 | usage ();
|
---|
72 |
|
---|
73 | count = 0;
|
---|
74 | for (i = pos; i < argc; i++)
|
---|
75 | if (args[i][0] != '-')
|
---|
76 | {
|
---|
77 | inf = fopen (args[i], "rb");
|
---|
78 | count = 0;
|
---|
79 | if (inf == NULL)
|
---|
80 | fprintf (stderr, "Trouble opening file: %s\n", args[i]);
|
---|
81 | else
|
---|
82 | {
|
---|
83 | if (pbm_isapbmfile (inf))
|
---|
84 | {
|
---|
85 | if (V)
|
---|
86 | fprintf (stderr, "%s: processing...\n", args[0]);
|
---|
87 | if (V)
|
---|
88 | fprintf (stderr, "reading file %s...", args[i]);
|
---|
89 | bitmap = pbm_readfile (inf, &cols, &rows);
|
---|
90 | if (V && (count == 0))
|
---|
91 | fprintf (stderr, "building...");
|
---|
92 |
|
---|
93 | list = NULL;
|
---|
94 |
|
---|
95 | ExtractAllMarks (bitmap, &list, cols, rows);
|
---|
96 |
|
---|
97 | if (V)
|
---|
98 | fprintf (stderr, "writing...");
|
---|
99 |
|
---|
100 | if ((!lib) && (marklist_length (list)))
|
---|
101 | {
|
---|
102 | lib = fopen (libraryname, "r");
|
---|
103 | if (lib)
|
---|
104 | {
|
---|
105 | fclose (lib);
|
---|
106 | lib = fopen (libraryname, "ab");
|
---|
107 | if (lib == NULL)
|
---|
108 | error_msg (args[0], "trouble appending library file", "");
|
---|
109 | fprintf (stderr, "\nwarning: appending library file: %s\n", libraryname);
|
---|
110 | }
|
---|
111 | else
|
---|
112 | {
|
---|
113 | lib = fopen (libraryname, "wb");
|
---|
114 | if (lib == NULL)
|
---|
115 | error_msg (args[0], "trouble creating library file", "");
|
---|
116 | }
|
---|
117 | } /* if !lib */
|
---|
118 |
|
---|
119 | step = list;
|
---|
120 | while (step)
|
---|
121 | {
|
---|
122 | step->data.symnum = count;
|
---|
123 | write_library_mark (lib, step->data);
|
---|
124 | count++;
|
---|
125 | step = step->next;
|
---|
126 | }
|
---|
127 | pbm_freearray (&bitmap, rows);
|
---|
128 | }
|
---|
129 | else
|
---|
130 | fprintf (stderr, "warning: %s is not a PBM file.\n", args[i]);
|
---|
131 | fclose (inf);
|
---|
132 | }
|
---|
133 | if (count)
|
---|
134 | {
|
---|
135 | if (V)
|
---|
136 | fprintf (stderr, "%d marks written.\n", count);
|
---|
137 | }
|
---|
138 | else
|
---|
139 | fprintf (stderr, "No marks written!\n");
|
---|
140 | }
|
---|
141 |
|
---|
142 | if (lib)
|
---|
143 | fclose (lib);
|
---|
144 | marklist_free (&list);
|
---|
145 | }
|
---|