~ubuntu-branches/ubuntu/edgy/ncbi-tools6/edgy

« back to all changes in this revision

Viewing changes to algo/blast/core/blast_message.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-07-19 23:28:07 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060719232807-et3cdmcjgmnyleyx
Tags: 6.1.20060507-3ubuntu1
Re-merge with Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: blast_message.c,v 1.19 2005/11/16 14:27:03 madden Exp $
 
1
/* $Id: blast_message.c,v 1.23 2006/04/20 19:27:22 madden Exp $
2
2
 * ===========================================================================
3
3
 *
4
4
 *                            PUBLIC DOMAIN NOTICE
31
31
 
32
32
#ifndef SKIP_DOXYGEN_PROCESSING
33
33
static char const rcsid[] = 
34
 
    "$Id: blast_message.c,v 1.19 2005/11/16 14:27:03 madden Exp $";
 
34
    "$Id: blast_message.c,v 1.23 2006/04/20 19:27:22 madden Exp $";
35
35
#endif /* SKIP_DOXYGEN_PROCESSING */
36
36
 
37
37
#include <algo/blast/core/blast_message.h>
38
38
 
 
39
/** Declared in blast_message.h as extern const. */
 
40
const int kBlastMessageNoContext = -1;
 
41
 
 
42
/** Allocate a new SMessageOrigin structure
 
43
 * @param filename name of the file [in]
 
44
 * @param lineno line number in the file above [in]
 
45
 * @return newly allocated structure or NULL in case of memory allocation
 
46
 * failure.
 
47
 */
 
48
SMessageOrigin* SMessageOriginNew(char* filename, unsigned int lineno)
 
49
{
 
50
    SMessageOrigin* retval = NULL;
 
51
 
 
52
    if ( !filename || !(strlen(filename) > 0) ) {
 
53
        return NULL;
 
54
    }
 
55
    
 
56
    retval = calloc(1, sizeof(SMessageOrigin));
 
57
    if ( !retval ) {
 
58
        return NULL;
 
59
    }
 
60
 
 
61
    retval->filename = strdup(filename);
 
62
    retval->lineno = lineno;
 
63
    return retval;
 
64
}
 
65
 
 
66
/** Deallocate a SMessageOrigin structure
 
67
 * @param msgo structure to deallocate [in]
 
68
 * @return NULL
 
69
 */
 
70
SMessageOrigin* SMessageOriginFree(SMessageOrigin* msgo)
 
71
{
 
72
    if (msgo) {
 
73
        sfree(msgo->filename);
 
74
        sfree(msgo);
 
75
    }
 
76
    return NULL;
 
77
}
 
78
 
39
79
Blast_Message* 
40
80
Blast_MessageFree(Blast_Message* blast_msg)
41
81
{
 
82
        Blast_Message* var_msg = NULL;
 
83
        Blast_Message* next = NULL;
 
84
 
42
85
        if (blast_msg == NULL)
43
86
                return NULL;
44
87
 
45
 
        sfree(blast_msg->message);
46
 
 
47
 
        sfree(blast_msg);
 
88
        var_msg = blast_msg;
 
89
        while (var_msg)
 
90
        {
 
91
             sfree(var_msg->message);
 
92
             var_msg->origin = SMessageOriginFree(var_msg->origin);
 
93
             next = var_msg->next;
 
94
             sfree(var_msg);
 
95
             var_msg = next;
 
96
        }
 
97
        
48
98
        return NULL;
49
99
}
50
100
 
51
101
Int2 
52
102
Blast_MessageWrite(Blast_Message* *blast_msg, EBlastSeverity severity, 
53
 
                   Int4 code,   Int4 subcode, const char *message)
 
103
                   int context, const char *message)
54
104
{
 
105
        Blast_Message* new_msg = NULL;
 
106
 
55
107
        if (blast_msg == NULL)
56
 
                return 1;
57
 
 
58
 
        *blast_msg = (Blast_Message*) malloc(sizeof(Blast_Message));
59
 
 
60
 
        (*blast_msg)->severity = severity;
61
 
        (*blast_msg)->code = code;
62
 
        (*blast_msg)->subcode = subcode;
63
 
        (*blast_msg)->message = strdup(message);
 
108
             return 1;
 
109
 
 
110
         new_msg = (Blast_Message*) calloc(1, sizeof(Blast_Message));
 
111
         if (new_msg == NULL)
 
112
             return -1;
 
113
 
 
114
        new_msg->severity = severity;
 
115
        new_msg->context = context;
 
116
        new_msg->message = strdup(message);
 
117
 
 
118
        if (*blast_msg)
 
119
        {
 
120
           Blast_Message* var_msg = *blast_msg;
 
121
           while (var_msg->next)
 
122
           {
 
123
                 var_msg = var_msg->next;
 
124
           }
 
125
           var_msg->next = new_msg;
 
126
        }
 
127
        else
 
128
        {
 
129
           *blast_msg = new_msg;
 
130
        }
64
131
 
65
132
        return 0;
66
133
}
76
143
        return 0;
77
144
}
78
145
 
79
 
Blast_Message*
80
 
Blast_Perror(Int2 error_code)
81
 
{
82
 
    Blast_Message* retval = (Blast_Message*) calloc(1, sizeof(Blast_Message));
 
146
void
 
147
Blast_Perror(Blast_Message* *msg, Int2 error_code, int context)
 
148
{
 
149
    Blast_PerrorEx(msg, error_code, NULL, -1, context);
 
150
    return;
 
151
}
 
152
 
 
153
void 
 
154
Blast_PerrorEx(Blast_Message* *msg,
 
155
                              Int2 error_code, 
 
156
                              const char* file_name, 
 
157
                              int lineno,
 
158
                              int context)
 
159
{
 
160
    Blast_Message* new_msg = (Blast_Message*) calloc(1, sizeof(Blast_Message));
 
161
    ASSERT(msg);
83
162
 
84
163
    switch (error_code) {
 
164
 
85
165
    case BLASTERR_IDEALSTATPARAMCALC:
86
 
        retval->message = strdup("Failed to calculate ideal Karlin-Altschul "
 
166
        new_msg->message = strdup("Failed to calculate ideal Karlin-Altschul "
87
167
                                 "parameters");
88
 
        retval->severity = eBlastSevError;
 
168
        new_msg->severity = eBlastSevError;
 
169
        new_msg->context = context;
89
170
        break;
90
171
    case BLASTERR_REDOALIGNMENTCORE_NOTSUPPORTED:
91
 
        retval->message = strdup("Composition based statistics or "
 
172
        new_msg->message = strdup("Composition based statistics or "
92
173
                                 "Smith-Waterman not supported for your "
93
174
                                 "program type");
94
 
        retval->severity = eBlastSevError;
95
 
        break;
 
175
        new_msg->severity = eBlastSevError;
 
176
        new_msg->context = context;
 
177
        break;
 
178
    case BLASTERR_INTERRUPTED:
 
179
        new_msg->message = strdup("BLAST search interrupted at user's request");
 
180
        new_msg->severity = eBlastSevInfo;
 
181
        new_msg->context = context;
 
182
        break;
 
183
 
 
184
    /* Fatal errors */
 
185
    case BLASTERR_MEMORY:
 
186
        new_msg->message = strdup("Out of memory");
 
187
        new_msg->severity = eBlastSevFatal;
 
188
        new_msg->context = context;
 
189
        break;
 
190
    case BLASTERR_INVALIDPARAM:
 
191
        new_msg->message = strdup("Invalid argument to function");
 
192
        new_msg->severity = eBlastSevFatal;
 
193
        new_msg->context = context;
 
194
        break;
 
195
    case BLASTERR_INVALIDQUERIES:
 
196
        new_msg->message = strdup("search cannot proceed due to errors in all "
 
197
                                 "contexts/frames of query sequences");
 
198
        new_msg->severity = eBlastSevFatal;
 
199
        new_msg->context = context;
 
200
        break;
 
201
 
 
202
    /* No error, just free the structure */
96
203
    case 0:
97
 
        retval = Blast_MessageFree(retval);
 
204
        new_msg = Blast_MessageFree(new_msg);
98
205
        break;
 
206
 
 
207
    /* Unknown error */
99
208
    default:
100
209
        {
101
210
            char buf[512];
102
211
            snprintf(buf, sizeof(buf) - 1, "Unknown error code %d", error_code);
103
 
            retval->message = strdup(buf);
104
 
            retval->severity = eBlastSevError;
 
212
            new_msg->message = strdup(buf);
 
213
            new_msg->severity = eBlastSevError;
 
214
            new_msg->context = context;
105
215
        }
106
216
        break;
107
217
    }
108
218
 
109
 
    return retval;
 
219
    if (file_name && lineno > 0) {
 
220
        new_msg->origin = SMessageOriginNew((char*) file_name, 
 
221
                                           (unsigned int) lineno);
 
222
    }
 
223
 
 
224
    if (*msg)
 
225
    {
 
226
          Blast_Message* var = *msg;
 
227
          while (var->next)
 
228
              var = var->next;
 
229
          var->next = new_msg;
 
230
    }
 
231
    else
 
232
    {
 
233
           *msg = new_msg;
 
234
    }
 
235
 
 
236
    return;
110
237
}
111
238
 
112
239
/*
113
240
 * ===========================================================================
114
241
 *
115
242
 * $Log: blast_message.c,v $
 
243
 * Revision 1.23  2006/04/20 19:27:22  madden
 
244
 * Implement linked list of Blast_Message, remove code and subcode
 
245
 *
 
246
 * Revision 1.22  2006/03/29 13:59:53  camacho
 
247
 * Doxygen fixes
 
248
 *
 
249
 * Revision 1.21  2006/03/21 21:00:52  camacho
 
250
 * + interruptible api support
 
251
 *
 
252
 * Revision 1.20  2006/01/12 20:33:06  camacho
 
253
 * + SMessageOrigin structure, Blast_PerrorEx function, and error codes
 
254
 *
116
255
 * Revision 1.19  2005/11/16 14:27:03  madden
117
256
 * Fix spelling in CRN
118
257
 *