A couple typos found by codespell
[openjpeg.git] / src / lib / openjpip / manfbox_manager.c
1 /*
2  * $Id$
3  *
4  * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
5  * Copyright (c) 2002-2014, Professor Benoit Macq
6  * Copyright (c) 2010-2011, Kaori Hagihara
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include "manfbox_manager.h"
35
36 #ifdef SERVER
37 #include "fcgi_stdio.h"
38 #define logstream FCGI_stdout
39 #else
40 #define FCGI_stdout stdout
41 #define FCGI_stderr stderr
42 #define logstream stderr
43 #endif /*SERVER */
44
45 manfbox_param_t * gene_manfbox(box_param_t *box)
46 {
47     manfbox_param_t *manf;   /* manifest parameters */
48     boxheader_param_t *bh;   /* current box pointer */
49     boxheader_param_t *last; /* last boxheader pointer of the list */
50     OPJ_OFF_T pos;                 /* current position in manf_box contents; */
51
52     manf = (manfbox_param_t *)malloc(sizeof(manfbox_param_t));
53
54     pos = 0;
55     manf->first = last = NULL;
56
57     while ((OPJ_SIZE_T)pos < get_DBoxlen(box)) {
58
59         bh = gene_childboxheader(box, pos);
60         pos += bh->headlen;
61
62         /* insert into the list */
63         if (manf->first) {
64             last->next = bh;
65         } else {
66             manf->first = bh;
67         }
68         last = bh;
69     }
70     return manf;
71 }
72
73 void delete_manfbox(manfbox_param_t **manf)
74 {
75     boxheader_param_t *bhPtr, *bhNext;
76
77     bhPtr = (*manf)->first;
78     while (bhPtr != NULL) {
79         bhNext = bhPtr->next;
80 #ifndef SERVER
81         /*      fprintf( logstream, "local log: boxheader %.4s deleted!\n", bhPtr->type); */
82 #endif
83         free(bhPtr);
84         bhPtr = bhNext;
85     }
86     free(*manf);
87 }
88
89 void print_manfbox(manfbox_param_t *manf)
90 {
91     boxheader_param_t *ptr;
92
93     ptr = manf->first;
94     while (ptr != NULL) {
95         print_boxheader(ptr);
96         ptr = ptr->next;
97     }
98 }
99
100 boxheader_param_t * search_boxheader(const char type[], manfbox_param_t *manf)
101 {
102     boxheader_param_t *found;
103
104     found = manf->first;
105
106     while (found != NULL) {
107
108         if (strncmp(type, found->type, 4) == 0) {
109             return found;
110         }
111
112         found = found->next;
113     }
114     fprintf(FCGI_stderr, "Error: Boxheader %s not found\n", type);
115
116     return NULL;
117 }