summaryrefslogtreecommitdiffstats
path: root/src/raptor_syntax_description.c
blob: eb549b2ed0a217b91e0de15af8d071330087513d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* -*- Mode: c; c-basic-offset: 2 -*-
 *
 * raptor_syntax_description.c - Raptor syntax description API
 *
 * Copyright (C) 2010, David Beckett http://www.dajobe.org/
 * 
 * This package is Free Software and part of Redland http://librdf.org/
 * 
 * It is licensed under the following three licenses as alternatives:
 *   1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
 *   2. GNU General Public License (GPL) V2 or any newer version
 *   3. Apache License, V2.0 or any newer version
 * 
 * You may not use this file except in compliance with at least one of
 * the above three licenses.
 * 
 * See LICENSE.html or LICENSE.txt at the top of this package for the
 * complete terms and further detail along with the license texts for
 * the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively.
 * 
 * 
 */


#ifdef HAVE_CONFIG_H
#include <raptor_config.h>
#endif

#include <stdio.h>
#include <string.h>

/* Raptor includes */
#include "raptor2.h"
#include "raptor_internal.h"


static unsigned int
count_strings_array(const char* const * array) 
{
  unsigned int i;
  
  if(!array)
    return 0;
  
  for(i = 0; (array[i]); i++)
    ;

  return i;
}


static unsigned int
count_mime_types_array(const raptor_type_q* array)
{
  unsigned int i;
  
  if(!array)
    return 0;
  
  for(i = 0; (array[i].mime_type); i++)
    ;

  return i;
}


/**
 * raptor_syntax_description_validate:
 * @desc: description
 *
 * Validate a syntax description has the required fields (name, labels) and update counts
 * 
 * Returns: non-0 on failure
 **/
int
raptor_syntax_description_validate(raptor_syntax_description* desc)
{
  if(!desc || !desc->names || !desc->names[0] || !desc->label)
    return 1;

#ifdef RAPTOR_DEBUG
  /* Maintainer only check of static data */
  if(desc->mime_types) {
    unsigned int i;
    const raptor_type_q* type_q = NULL;

    for(i = 0; 
        (type_q = &desc->mime_types[i]) && type_q->mime_type;
        i++) {
      size_t len = strlen(type_q->mime_type);
      if(len != type_q->mime_type_len) {
        fprintf(stderr,
                "Format %s  mime type %s  actual len %d  static len %d\n",
                desc->names[0], type_q->mime_type,
                (int)len, (int)type_q->mime_type_len);
      }
    }
  }
#endif

  desc->names_count = count_strings_array(desc->names);
  if(!desc->names_count)
    return 1;
  
  desc->mime_types_count = count_mime_types_array(desc->mime_types);
  desc->uri_strings_count = count_strings_array(desc->uri_strings);

  return 0;
}