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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
|
/* vi: ff=unix spell
*/
/*
Copyright (C) 1994-2007 Frans Slothouber, Jacco van Weert, Petteri Kettunen,
Bernd Koesling, Thomas Aglassinger, Anthon Pang, Stefan Kost, David Druffner,
Sasha Vasko, Kai Hofmann, Thierry Pierron, Friedrich Haase, and Gergely Budai.
This file is part of ROBODoc
ROBODoc is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/****h* ROBODoc/Items
* FUNCTION
* This module contains functions that deal with items. The
* documentation consists of headers, and headers contains one of
* more items. Each item has a name and a body. All possible items
* are listed in configuration.items. A uses can specify that
* certain items are not to be added to the documentation. These
* items are listed in configuration.ignore_items.
* AUTHOR
* Frans Slothouber
*******
*/
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include "globals.h"
#include "robodoc.h"
#include "items.h"
#include "roboconfig.h"
#include "util.h"
/****v* Items/item_name_buffer
* FUNCTION
* Stores the name of the last item that was found.
* SOURCE
*/
#define MAX_ITEM_NAME_LENGTH 1024
char item_name_buffer[MAX_ITEM_NAME_LENGTH];
/*****/
/* TODO Documentation */
char *RB_Get_Item_Name(
void )
{
return item_name_buffer;
}
/****f* Items/RB_Create_Item
*
* SOURCE
*/
struct RB_Item *RB_Create_Item(
enum ItemType arg_item_type )
{
struct RB_Item *item = malloc( sizeof( struct RB_Item ) );
assert( item );
item->next = 0;
item->type = arg_item_type;
item->begin_index = 0;
item->end_index = 0;
item->max_line_number = 0;
return item;
}
/*****/
/****f* Items/RB_Get_Item_Type [3.0b]
* FUNCTION
* return the item_type represented by the given string.
* SYNOPSIS
* int RB_Get_Item_Type( char *cmp_name )
* INPUTS
* char *cmp_name -- item_name to evaluate
* RESULT
* int -- the right item_type or NO_ITEM
* SOURCE
*/
int RB_Get_Item_Type(
char *cmp_name )
{
unsigned int item_type;
assert( configuration.items.number );
for ( item_type = 0; item_type < configuration.items.number; ++item_type )
{
char *item = configuration.items.names[item_type];
/* Skip preformat mark */
if ( *item == '-' )
item++;
if ( !strcmp( item, cmp_name ) )
{
return ( item_type );
}
}
return ( NO_ITEM );
}
/*** RB_Get_Item_Type ***/
/****f* Items/RB_Is_ItemName
* FUNCTION
* Is there an itemname in the line. Ignores leading spaces and
* remark markers.
* INPUTS
* line -- line to be searched.
* RESULT
* The kind of item that was found or NO_ITEM if no item could be found.
* The name of the item will be stored in item_name_buffer.
* NOTES
* We used to check for misspelled items names by testing if
* the item name buffer consists of only upper case characters.
* However checking for a misspelled item name this way results in
* many false positives. For instance many warnings are given for
* FORTRAN code as all the keywords are in uppercase. We need to
* find a better method for this.
* SOURCE
*/
enum ItemType RB_Is_ItemName(
char *line )
{
char *cur_char = line;
int i = 0;
cur_char = RB_Skip_Whitespace( cur_char );
if ( RB_Has_Remark_Marker( cur_char ) )
{
cur_char = RB_Skip_Remark_Marker( cur_char );
cur_char = RB_Skip_Whitespace( cur_char );
/* It there anything left? */
if ( strlen( cur_char ) )
{
enum ItemType item_type = NO_ITEM;
/* Copy the name */
strcpy( item_name_buffer, cur_char );
/* remove any trailing spaces */
for ( i = strlen( item_name_buffer ) - 1;
i >= 0 && utf8_isspace( item_name_buffer[i] ); --i )
{
item_name_buffer[i] = '\0';
}
/* No check and see if this is an item name */
if ( strlen( item_name_buffer ) )
{
item_type = RB_Get_Item_Type( item_name_buffer );
#if 0 /* Until we find a better method */
if ( item_type == NO_ITEM )
{
/* Check if it is a misspelled item name */
item_type = POSSIBLE_ITEM;
for ( i = 0; i < strlen( item_name_buffer ); ++i )
{
if ( !( utf8_isupper( item_name_buffer[i] ) ||
utf8_isspace( item_name_buffer[i] ) ) )
{
/* No it is not */
item_type = NO_ITEM;
break;
}
}
}
#endif
}
return item_type;
}
else
{
return NO_ITEM;
}
}
else
{
return NO_ITEM;
}
}
/******/
/* TODO Documentation */
int Is_Ignore_Item(
char *name )
{
unsigned int i;
for ( i = 0; i < configuration.ignore_items.number; ++i )
{
if ( !strcmp( configuration.ignore_items.names[i], name ) )
{
return TRUE;
}
}
return FALSE;
}
/****f* HeaderTypes/Works_Like_SourceItem
* FUNCTION
* Tells wether this item works similar to the
* source item, that is weather it copies it's
* content verbatim to the output document.
* SYNPOPSIS
*/
int Works_Like_SourceItem(
enum ItemType item_type )
/*
* INPUTS
* item_type -- Type of item (also the index to the item name)
* RESULT
* TRUE -- Item works like a SOURCE item
* FALSE -- Item does NOT work like a SOURCE item
* SOURCE
*/
{
unsigned int i;
/* Check if it is a SOURCE item */
if ( item_type == SOURCECODE_ITEM )
{
return TRUE;
}
/* Lookup if it works like a SOURCE item */
for ( i = 0; i < configuration.source_items.number; ++i )
{
if ( !strcmp
( configuration.source_items.names[i],
configuration.items.names[item_type] ) )
{
return TRUE;
}
}
/* Neither SOURCE item, nor works like it */
return FALSE;
}
/******/
/****f* HeaderTypes/Is_Preformatted_Item
* FUNCTION
* Tells wether this item should be automatically preformatted in the
* output.
* SYNPOPSIS
*/
int Is_Preformatted_Item(
enum ItemType item_type )
/*
* INPUTS
* item_type -- Type of item (also the index to the item name)
* RESULT
* TRUE -- Item should be automatically preformatted
* FALSE -- Item should NOT be automatically preformatted
* SOURCE
*/
{
unsigned int i;
/* Lookup if item should be preformatted */
for ( i = 0; i < configuration.preformatted_items.number; ++i )
{
if ( !strcmp
( configuration.preformatted_items.names[i],
configuration.items.names[item_type] ) )
{
/* Item name match, it sould be preformatted */
return TRUE;
}
}
/* Do not automatically preformat item */
return FALSE;
}
/******/
/****f* HeaderTypes/Is_Format_Item
* FUNCTION
* Tells wether this item should be formatted by the browser
* SYNPOPSIS
*/
int Is_Format_Item(
enum ItemType item_type )
/*
* INPUTS
* item_type -- Type of item (also the index to the item name)
* RESULT
* TRUE -- Item should be formatted by the browser
* FALSE -- Item should be left alone
* SOURCE
*/
{
unsigned int i;
/* Lookup if item should be formatted by the browser */
for ( i = 0; i < configuration.format_items.number; ++i )
{
if ( !strcmp
( configuration.format_items.names[i],
configuration.items.names[item_type] ) )
{
/* Item name match, it sould be formatted by the browser */
return TRUE;
}
}
/* Leave item alone */
return FALSE;
}
/******/
|