Removal of c99 from the compile option (to be compatible to win platform) and bool...
[openjpeg.git] / applications / jpip / libopenjpip / placeholder_manager.c
1 /*
2  * $Id: placeholder_manager.c 53 2011-05-09 16:55:39Z kaori $
3  *
4  * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5  * Copyright (c) 2002-2011, 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 <string.h>
33 #include "placeholder_manager.h"
34
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
46
47 placeholderlist_param_t * gene_placeholderlist()
48 {
49   placeholderlist_param_t *list;
50
51   list = (placeholderlist_param_t *)malloc( sizeof(placeholderlist_param_t));
52   
53   list->first = NULL;
54   list->last  = NULL;
55
56   return list;
57 }
58
59 void delete_placeholderlist( placeholderlist_param_t **list)
60 {
61   placeholder_param_t *ptr, *next;
62
63   if(!(*list))
64     return;
65
66   ptr = (*list)->first;
67   
68   while( ptr){
69     next=ptr->next;
70     delete_placeholder( &ptr);
71     ptr=next;
72   }
73   free( *list);
74 }
75
76 placeholder_param_t * gene_placeholder( box_param_t *box, int origID)
77 {
78   placeholder_param_t *placeholder;
79
80   placeholder = (placeholder_param_t *)malloc( sizeof(placeholder_param_t));
81   
82   strncpy( placeholder->TBox, "phld", 4);
83   placeholder->Flags = 1; // only the access to the original contents of this box, for now
84   placeholder->OrigID = origID;
85   placeholder->OrigBH = fetch_headbytes( box);
86   placeholder->OrigBHlen = box->headlen;
87   placeholder->LBox = 20+box->headlen;
88   placeholder->next = NULL;
89
90   return placeholder;
91 }
92
93 void delete_placeholder( placeholder_param_t **placeholder)
94 {
95   if( (*placeholder)->OrigBH)
96     free((*placeholder)->OrigBH);
97   free(*placeholder);
98 }
99
100 void insert_placeholder_into_list( placeholder_param_t *phld, placeholderlist_param_t *phldlist)
101 {
102   if( phldlist->first)
103     phldlist->last->next = phld;
104   else
105     phldlist->first = phld;
106   phldlist->last = phld;
107 }
108
109 void print_placeholder( placeholder_param_t *phld)
110 {
111   int i;
112
113   fprintf( logstream, "placeholder info:\n");
114   fprintf( logstream, "\t LBox: %d %#x\n", phld->LBox, phld->LBox);
115   fprintf( logstream, "\t TBox: %.4s\n", phld->TBox);
116   fprintf( logstream, "\t Flags: %#x %#x\n", phld->Flags, phld->Flags);
117   fprintf( logstream, "\t OrigID: %lld\n", phld->OrigID);
118   fprintf( logstream, "\t OrigBH: ");
119   
120   for( i=0; i< phld->OrigBHlen; i++)
121     fprintf( logstream, "%02x ", phld->OrigBH[i]);
122   fprintf( logstream, "\t");
123
124   for( i=0; i< phld->OrigBHlen; i++)
125     fprintf( logstream, "%c", phld->OrigBH[i]);
126   fprintf( logstream, "\n");
127 }
128
129 void print_allplaceholder( placeholderlist_param_t *list)
130 {
131   placeholder_param_t *ptr;
132
133   if( !list)
134     return;
135   
136   fprintf( logstream, "all placeholder info: \n");
137   ptr = list->first;
138   while( ptr != NULL){
139     print_placeholder( ptr);
140     ptr=ptr->next;
141   }
142 }