ReactOS 0.4.16-dev-91-g764881a
rgenstat.c File Reference
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <sys/io.h>
#include <errno.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <ctype.h>
Include dependency graph for rgenstat.c:

Go to the source code of this file.

Classes

struct  _API_INFO
 

Macros

#define MAX_PATH   260
 
#define DIR_SEPARATOR_CHAR   '/'
 
#define DIR_SEPARATOR_STRING   "/"
 
#define TAG_UNKNOWN   -1
 
#define TAG_IMPLEMENTED   0
 
#define TAG_UNIMPLEMENTED   1
 

Typedefs

typedef struct _API_INFO API_INFO
 
typedef struct _API_INFOPAPI_INFO
 

Functions

PAPI_INFO sort_linked_list (PAPI_INFO, unsigned, int(*)(PAPI_INFO, PAPI_INFO))
 
static charconvert_path (char *origpath)
 
static charpath_to_url (char *path)
 
static void write_line (char *line)
 
static void read_file (char *filename)
 
static void close_file ()
 
static int is_whitespace (char ch)
 
static int is_eol_char (char ch)
 
static int is_end_of_tag (char ch)
 
static int is_end_of_name (char ch)
 
static int is_valid_file (char *filename)
 
static int get_tag_id (char *tag)
 
static int skip_to_next_tag ()
 
static void skip_line ()
 
static void skip_comments ()
 
static int get_previous_identifier (unsigned int end, char *name)
 
static int skip_to_next_name (char *name)
 
static void get_filename (char *cvspath, char *filename, char *result)
 
static void parse_file (char *fullname, char *cvspath, char *filename)
 
static void process_directory (char *path, char *cvspath)
 
static int compare_api_order (PAPI_INFO p, PAPI_INFO q)
 
charget_filename_without_base (char *component_base, char *filename)
 
static void generate_xml_for_component (char *component_name, char *component_base)
 
static void read_input_file (char *input_file)
 
int main (int argc, char **argv)
 

Variables

static FILEin
 
static FILEout
 
static FILEfile_handle = NULL
 
static charfile_buffer = NULL
 
static unsigned int file_size = 0
 
static unsigned int file_pointer = 0
 
static char tagname [200]
 
static PAPI_INFO api_info_list = NULL
 
static char HELP []
 

Macro Definition Documentation

◆ DIR_SEPARATOR_CHAR

#define DIR_SEPARATOR_CHAR   '/'

Definition at line 33 of file rgenstat.c.

◆ DIR_SEPARATOR_STRING

#define DIR_SEPARATOR_STRING   "/"

Definition at line 34 of file rgenstat.c.

◆ MAX_PATH

#define MAX_PATH   260

Definition at line 31 of file rgenstat.c.

◆ TAG_IMPLEMENTED

#define TAG_IMPLEMENTED   0

Definition at line 41 of file rgenstat.c.

◆ TAG_UNIMPLEMENTED

#define TAG_UNIMPLEMENTED   1

Definition at line 42 of file rgenstat.c.

◆ TAG_UNKNOWN

#define TAG_UNKNOWN   -1

Definition at line 40 of file rgenstat.c.

Typedef Documentation

◆ API_INFO

◆ PAPI_INFO

Function Documentation

◆ close_file()

static void close_file ( )
static

Definition at line 165 of file rgenstat.c.

166{
171 file_pointer = 0;
172}
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
static unsigned int file_pointer
Definition: rgenstat.c:62
static FILE * file_handle
Definition: rgenstat.c:59
static char * file_buffer
Definition: rgenstat.c:60

Referenced by parse_file().

◆ compare_api_order()

static int compare_api_order ( PAPI_INFO  p,
PAPI_INFO  q 
)
static

Definition at line 669 of file rgenstat.c.

670{
671 return strcmp(p->name, q->name);
672}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by generate_xml_for_component().

◆ convert_path()

static char * convert_path ( char origpath)
static

Definition at line 68 of file rgenstat.c.

69{
70 char* newpath;
71 int i;
72
73 newpath = strdup(origpath);
74
75 i = 0;
76 while (newpath[i] != 0)
77 {
78#ifndef WIN32
79 if (newpath[i] == '\\')
80 {
81 newpath[i] = '/';
82 }
83#else
84#ifdef WIN32
85 if (newpath[i] == '/')
86 {
87 newpath[i] = '\\';
88 }
89#endif
90#endif
91 i++;
92 }
93 return(newpath);
94}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)

Referenced by main(), and read_input_file().

◆ generate_xml_for_component()

static void generate_xml_for_component ( char component_name,
char component_base 
)
static

Definition at line 682 of file rgenstat.c.

684{
685 PAPI_INFO api_info;
686 char canonical_base[MAX_PATH];
687 char buf[200];
688 int complete;
689 int implemented_total;
690 int unimplemented_total;
691
692 // Sort list
694
695 implemented_total = 0;
696 unimplemented_total = 0;
697
698 api_info = api_info_list;
699 while (api_info != NULL)
700 {
701 if (api_info->tag_id == TAG_IMPLEMENTED)
702 implemented_total ++;
703 else if (api_info->tag_id == TAG_UNIMPLEMENTED)
704 unimplemented_total ++;
705
706 api_info = api_info->next;
707 }
708
709 if (implemented_total + unimplemented_total > 0)
710 complete = ((implemented_total) * 100) / (implemented_total + unimplemented_total);
711 else
712 complete = 100;
713
714 strcpy(canonical_base, component_base);
715 path_to_url(canonical_base);
716
717 sprintf(buf, "<component name=\"%s\" base=\"%s\" complete=\"%d\" implemented_total=\"%d\" unimplemented_total=\"%d\">",
718 component_name, canonical_base, complete, implemented_total, unimplemented_total);
720
721 if (api_info_list != NULL)
722 {
723 write_line("<functions>");
724
725 api_info = api_info_list;
726 while (api_info != NULL)
727 {
728 sprintf(buf, "<f n=\"%s\" i=\"%s\" f=\"%s\" />",
729 api_info->name,
730 api_info->tag_id == TAG_IMPLEMENTED ? "true" : "false",
731 get_filename_without_base(component_base,
732 api_info->filename));
734 api_info = api_info->next;
735 }
736
737 write_line("</functions>");
738 }
739
740 write_line("</component>");
741}
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static BOOL complete
Definition: htmldoc.c:198
static int compare_api_order(PAPI_INFO p, PAPI_INFO q)
Definition: rgenstat.c:669
static char * path_to_url(char *path)
Definition: rgenstat.c:97
static PAPI_INFO api_info_list
Definition: rgenstat.c:64
#define TAG_IMPLEMENTED
Definition: rgenstat.c:41
char * get_filename_without_base(char *component_base, char *filename)
Definition: rgenstat.c:675
static void write_line(char *line)
Definition: rgenstat.c:114
#define MAX_PATH
Definition: rgenstat.c:31
#define TAG_UNIMPLEMENTED
Definition: rgenstat.c:42
PAPI_INFO sort_linked_list(PAPI_INFO, unsigned, int(*)(PAPI_INFO, PAPI_INFO))
struct _API_INFO * next
Definition: rgenstat.c:46
char name[100]
Definition: rgenstat.c:48
int tag_id
Definition: rgenstat.c:47
char filename[MAX_PATH]
Definition: rgenstat.c:49

Referenced by read_input_file().

◆ get_filename()

static void get_filename ( char cvspath,
char filename,
char result 
)
static

Definition at line 408 of file rgenstat.c.

409{
410 strcpy(result, cvspath);
413}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
GLuint64EXT * result
Definition: glext.h:11304
const char * filename
Definition: ioapi.h:137

Referenced by parse_file().

◆ get_filename_without_base()

char * get_filename_without_base ( char component_base,
char filename 
)

Definition at line 675 of file rgenstat.c.

677{
678 return &filename[strlen(component_base)];
679}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269

Referenced by generate_xml_for_component().

◆ get_previous_identifier()

static int get_previous_identifier ( unsigned int  end,
char name 
)
static

Definition at line 341 of file rgenstat.c.

342{
343 unsigned int my_file_pointer = end;
344 int len;
345
346 name[0] = 0;
347
348 while ((my_file_pointer > 0) && (is_whitespace(file_buffer[my_file_pointer])
349 || is_eol_char(file_buffer[my_file_pointer])))
350 {
351 my_file_pointer--;
352 }
353
354 /* Skip any comments between function name and it's parameters */
355 if ((my_file_pointer > 0) && (file_buffer[my_file_pointer] == '/'))
356 {
357 if ((my_file_pointer > 0) && (file_buffer[my_file_pointer - 1] == '*'))
358 {
359 my_file_pointer--;
360 while ((my_file_pointer > 0) && !((file_buffer[my_file_pointer] == '*')
361 && (file_buffer[my_file_pointer - 1] == '/')))
362 {
363 my_file_pointer--;
364 }
365 my_file_pointer -= 2;
366 }
367 }
368
369 /* Skip any remaining whitespace */
370 while ((my_file_pointer > 0) && (is_whitespace(file_buffer[my_file_pointer])))
371 {
372 my_file_pointer--;
373 }
374
375 end = my_file_pointer;
376 while ((my_file_pointer > 0))
377 {
378 if (is_end_of_name(file_buffer[my_file_pointer]))
379 {
380 len = end - my_file_pointer;
381 strncpy(name, &file_buffer[my_file_pointer + 1], len);
382 name[len] = 0;
383 return 1;
384 }
385 my_file_pointer--;
386 }
387
388 return 0;
389}
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
GLuint GLuint end
Definition: gl.h:1545
GLenum GLsizei len
Definition: glext.h:6722
static int is_eol_char(char ch)
Definition: rgenstat.c:189
static int is_end_of_name(char ch)
Definition: rgenstat.c:225
static int is_whitespace(char ch)
Definition: rgenstat.c:175
Definition: name.c:39

Referenced by skip_to_next_name().

◆ get_tag_id()

static int get_tag_id ( char tag)
static

Definition at line 256 of file rgenstat.c.

257{
258 if (strcasecmp(tag, "implemented") == 0)
259 {
260 return TAG_IMPLEMENTED;
261 }
262 if (strcasecmp(tag, "unimplemented") == 0)
263 {
264 return TAG_UNIMPLEMENTED;
265 }
266 return TAG_UNKNOWN;
267}
#define strcasecmp
Definition: fake.h:9
#define TAG_UNKNOWN
Definition: rgenstat.c:40
Definition: ecma_167.h:138

Referenced by skip_to_next_tag().

◆ is_end_of_name()

static int is_end_of_name ( char  ch)
static

Definition at line 225 of file rgenstat.c.

226{
227 /* Currently the same as is_end_of_tag() */
228 return is_end_of_tag(ch);
229}
static int is_end_of_tag(char ch)
Definition: rgenstat.c:203

Referenced by get_previous_identifier().

◆ is_end_of_tag()

static int is_end_of_tag ( char  ch)
static

Definition at line 203 of file rgenstat.c.

204{
205 if ((ch >= 'a') && (ch <= 'z'))
206 {
207 return 0;
208 }
209 if ((ch >= 'A') && (ch <= 'Z'))
210 {
211 return 0;
212 }
213 if ((ch >= '0') && (ch <= '9'))
214 {
215 return 0;
216 }
217 if (ch == '_')
218 {
219 return 0;
220 }
221 return 1;
222}

Referenced by is_end_of_name(), and skip_to_next_tag().

◆ is_eol_char()

static int is_eol_char ( char  ch)
static

Definition at line 189 of file rgenstat.c.

190{
191 if (ch == '\r')
192 {
193 return 1;
194 }
195 if (ch == '\n')
196 {
197 return 1;
198 }
199 return 0;
200}

Referenced by get_previous_identifier(), read_input_file(), and skip_line().

◆ is_valid_file()

static int is_valid_file ( char filename)
static

Definition at line 232 of file rgenstat.c.

233{
234 char ext[MAX_PATH];
235 int i;
236
237 i = strlen(filename);
238 while (i > 0 && filename[i] != '.')
239 {
240 i--;
241 }
242 if (i > 0)
243 {
244 memset(ext, 0, sizeof(ext));
245 strncpy(&ext[0], &filename[i], strlen(&filename[i]));
246
247 if ((strncmp(ext, ".c", 2) == 0) || (strncmp(ext, ".C", 2) == 0))
248 {
249 return 1;
250 }
251 }
252 return 0;
253}
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
static const WCHAR *const ext[]
Definition: module.c:53
#define memset(x, y, z)
Definition: compat.h:39

Referenced by process_directory().

◆ is_whitespace()

static int is_whitespace ( char  ch)
static

Definition at line 175 of file rgenstat.c.

176{
177 if (ch == ' ')
178 {
179 return 1;
180 }
181 if (ch == '\t')
182 {
183 return 1;
184 }
185 return 0;
186}

Referenced by get_previous_identifier(), and read_input_file().

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 876 of file rgenstat.c.

877{
878 char *input_file;
879 char *output_file;
880
881 if (argc != 3)
882 {
883 puts(HELP);
884 return 1;
885 }
886
887 input_file = convert_path(argv[1]);
888 if (input_file[0] == 0)
889 {
890 free(input_file);
891 printf("Missing input-filename\n");
892 return 1;
893 }
894
895 output_file = convert_path(argv[2]);
896 if (output_file[0] == 0)
897 {
898 free(input_file);
899 free(output_file);
900 printf("Missing output-filename\n");
901 return 1;
902 }
903
904 out = fopen(output_file, "wb");
905 if (out == NULL)
906 {
907 free(input_file);
908 free(output_file);
909 printf("Cannot open output file");
910 return 1;
911 }
912
913 read_input_file(input_file);
914
915 free(input_file);
916 free(output_file);
917 fclose(out);
918
919 return 0;
920}
static int argc
Definition: ServiceArgs.c:12
int puts(const char *string)
Definition: crtsupp.c:23
#define printf
Definition: freeldr.h:97
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define argv
Definition: mplay32.c:18
static FILE * out
Definition: rgenstat.c:58
static void read_input_file(char *input_file)
Definition: rgenstat.c:744
static char HELP[]
Definition: rgenstat.c:870
static char * convert_path(char *origpath)
Definition: rgenstat.c:68

◆ parse_file()

static void parse_file ( char fullname,
char cvspath,
char filename 
)
static

Definition at line 416 of file rgenstat.c.

417{
418 PAPI_INFO api_info;
419 char prev[200];
420 char name[200];
421 int tag_id;
422
424
425 prev[0] = 0;
426 do
427 {
428 tag_id = skip_to_next_tag();
429 if (tag_id == TAG_UNKNOWN)
430 {
431 break;
432 }
433
434 /* Skip rest of the comments between the tag and the function name */
436
438 {
439 if (strlen(name) == 0)
440 {
441 printf("Warning: empty function name in file %s. Previous function name was %s.\n",
442 fullname, prev);
443 }
444 api_info = malloc(sizeof(API_INFO));
445 if (api_info == NULL)
446 {
447 printf("Out of memory\n");
448 exit(1);
449 }
450
451 api_info->tag_id = tag_id;
452 strcpy(api_info->name, name);
453
454 get_filename(cvspath, filename, api_info->filename);
455
456 api_info->next = api_info_list;
457 api_info_list = api_info;
458 strcpy(prev, name);
459 }
460 } while (1);
461
462 close_file();
463}
#define malloc
Definition: debug_ros.c:4
const char * fullname
Definition: shader.c:1766
static void skip_comments()
Definition: rgenstat.c:321
static void close_file()
Definition: rgenstat.c:165
static int skip_to_next_name(char *name)
Definition: rgenstat.c:392
static int skip_to_next_tag()
Definition: rgenstat.c:270
static void get_filename(char *cvspath, char *filename, char *result)
Definition: rgenstat.c:408
static void read_file(char *filename)
Definition: rgenstat.c:129
#define exit(n)
Definition: config.h:202

Referenced by process_directory().

◆ path_to_url()

static char * path_to_url ( char path)
static

Definition at line 97 of file rgenstat.c.

98{
99 int i;
100
101 i = 0;
102 while (path[i] != 0)
103 {
104 if (path[i] == '\\')
105 {
106 path[i] = '/';
107 }
108 i++;
109 }
110 return(path);
111}

Referenced by generate_xml_for_component(), and get_filename().

◆ process_directory()

static void process_directory ( char path,
char cvspath 
)
static

Definition at line 527 of file rgenstat.c.

528{
529 DIR *dirp;
530 struct dirent *entry;
531 struct stat stbuf;
532 char buf[MAX_PATH];
533 char newcvspath[MAX_PATH];
534
535#ifdef HAVE_D_TYPE
536 dirp = opendir(path);
537 if (dirp != NULL)
538 {
539 while ((entry = readdir(dirp)) != NULL)
540 {
541 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
542 continue; // skip self and parent
543
544 if (entry->d_type == DT_REG) // normal file
545 {
546 // Check for an absolute path
547 if (path[0] == DIR_SEPARATOR_CHAR)
548 {
549 strcpy(buf, path);
551 strcat(buf, entry->d_name);
552 }
553 else
554 {
555 if (!getcwd(buf, sizeof(buf)))
556 {
557 printf("Can't get CWD: %s\n", strerror(errno));
558 return;
559 }
561 strcat(buf, path);
562 strcat(buf, entry->d_name);
563 }
564
565 if (stat(buf, &stbuf) == -1)
566 {
567 printf("Can't access '%s' (%s)\n", buf, strerror(errno));
568 return;
569 }
570
571 if (S_ISDIR(stbuf.st_mode))
572 {
573 strcpy(newcvspath, cvspath);
574 strcat(newcvspath, f.name);
575 strcat(newcvspath, "/");
576
577 process_directory(buf, newcvspath);
578 continue;
579 }
580
581 /* Must be a .c file */
582 if (!is_valid_file(buf))
583 {
584 continue;
585 }
586
587 parse_file(buf, cvspath, entry->d_name);
588 }
589 }
590 closedir(dirp);
591 }
592 else
593 {
594 printf("Can't open %s\n", path);
595 exit(1);
596 }
597
598#else
599
600 dirp = opendir(path);
601 if (dirp != NULL)
602 {
603 while ((entry = readdir(dirp)) != NULL)
604 {
605 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
606 continue; // skip self and parent
607
608 // Check for an absolute path
609 if (path[0] == DIR_SEPARATOR_CHAR)
610 {
611 strcpy(buf, path);
613 strcat(buf, entry->d_name);
614 }
615 else
616 {
617 if (!getcwd(buf, sizeof(buf)))
618 {
619 printf("Can't get CWD: %s\n", strerror(errno));
620 return;
621 }
623 strcat(buf, path);
624 strcat(buf, entry->d_name);
625 }
626
627 if (stat(buf, &stbuf) == -1)
628 {
629 printf("Can't access '%s' (%s)\n", buf, strerror(errno));
630 return;
631 }
632
633 if (S_ISDIR(stbuf.st_mode))
634 {
635 strcpy(newcvspath, cvspath);
636 strcat(newcvspath, entry->d_name);
637 strcat(newcvspath, "/");
638
639 process_directory(buf, newcvspath);
640 continue;
641 }
642
643 /* Must be a .c file */
644 if (!is_valid_file(buf))
645 {
646 continue;
647 }
648
649 parse_file(buf, cvspath, entry->d_name);
650 }
651 closedir(dirp);
652 }
653 else
654 {
655 printf("Can't open %s\n", path);
656 exit(1);
657 }
658
659#endif
660}
#define stat
Definition: acwin.h:99
#define S_ISDIR(mode)
Definition: various.h:18
_Check_return_ _Ret_opt_z_ _CRTIMP char *__cdecl getcwd(_Out_writes_opt_(_SizeInBytes) char *_DstBuf, _In_ int _SizeInBytes)
#define DT_REG
Definition: fs.h:151
GLfloat f
Definition: glext.h:7540
int __cdecl closedir(DIR *)
DIR *__cdecl opendir(const char *)
struct dirent *__cdecl readdir(DIR *)
uint32_t entry
Definition: isohybrid.c:63
const char * strerror(int err)
Definition: compat_str.c:23
static int is_valid_file(char *filename)
Definition: rgenstat.c:232
#define DIR_SEPARATOR_CHAR
Definition: rgenstat.c:33
#define DIR_SEPARATOR_STRING
Definition: rgenstat.c:34
static void process_directory(char *path, char *cvspath)
Definition: rgenstat.c:527
static void parse_file(char *fullname, char *cvspath, char *filename)
Definition: rgenstat.c:416
#define errno
Definition: errno.h:18
Definition: dirent.h:40
Definition: fatfs.h:198
Definition: stat.h:55

Referenced by process_directory(), and read_input_file().

◆ read_file()

static void read_file ( char filename)
static

Definition at line 129 of file rgenstat.c.

130{
131 file_handle = fopen(filename, "rb");
132 if (file_handle == NULL)
133 {
134 printf("Can't open %s\n", filename);
135 exit(1);
136 }
137
138 // Get the size of the file
141
142 // Load it all into memory
144 if (file_buffer == NULL)
145 {
147 printf("Out of memory\n");
148 exit(1);
149 }
151 if (file_size > 0)
152 {
153 if (fread (file_buffer, 1, file_size, file_handle) < 1)
154 {
156 printf("Read error in file %s\n", filename);
157 exit(1);
158 }
159 }
160
161 file_pointer = 0;
162}
#define SEEK_END
Definition: cabinet.c:29
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
#define SEEK_SET
Definition: jmemansi.c:26
static unsigned int file_size
Definition: rgenstat.c:61

Referenced by parse_file().

◆ read_input_file()

static void read_input_file ( char input_file)
static

Definition at line 744 of file rgenstat.c.

745{
746 char component_name[MAX_PATH];
747 char component_path[MAX_PATH];
748 char *canonical_path;
749 unsigned int index;
750 unsigned int start;
751 PAPI_INFO api_info;
752 PAPI_INFO next_api_info;
753 char *buffer;
754 unsigned int size;
755 int len;
756
757 in = fopen(input_file, "rb");
758 if (in == NULL)
759 {
760 printf("Cannot open input file");
761 exit(1);
762 }
763
764 // Get the size of the file
765 fseek(in, 0, SEEK_END);
766 size = ftell(in);
767
768 // Load it all into memory
769 buffer = malloc(size);
770 if (buffer == NULL)
771 {
772 fclose(in);
773 printf("Out of memory\n");
774 exit(1);
775 }
776 fseek(in, 0, SEEK_SET);
777 if (fread (buffer, 1, size, in) < 1)
778 {
779 fclose(in);
780 printf("Read error in file %s\n", input_file);
781 exit(1);
782 }
783
784 index = 0;
785
786 write_line("<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>");
787 write_line("<?xml-stylesheet type=\"text/xsl\" href=\"rapistatus.xsl\"?>");
788 write_line("");
789 write_line("<components>");
790
791 while (1)
792 {
793 /* Free previous list */
794 for (api_info = api_info_list; api_info != NULL; api_info = next_api_info)
795 {
796 next_api_info = api_info->next;
797 free(api_info);
798 }
800
801 /* Skip whitespace and eol characters */
802 while ((index < size) && (is_whitespace(buffer[index]) || (is_eol_char(buffer[index]))))
803 index++;
804 if ((file_pointer < size) && (buffer[index] == '\n'))
805 index++;
806
807 if (buffer[index] == ';')
808 {
809 /* Skip comments */
810 while ((index < size) && (!is_eol_char(buffer[index])))
811 index++;
812 if ((index < size) && (buffer[index] == '\n'))
813 index++;
814 continue;
815 }
816
817 /* Get component name */
818 start = index;
819 while ((index < size) && (!is_whitespace(buffer[index])))
820 index++;
821 if (index >= size)
822 break;
823
824 len = index - start;
825 strncpy(component_name, &buffer[start], len);
826 component_name[len] = 0;
827
828 /* Skip whitespace */
829 while ((index < size) && (is_whitespace(buffer[index])))
830 index++;
831 if (index >= size)
832 break;
833
834 /* Get component path */
835 start = index;
836 while ((index < size) && (!is_whitespace(buffer[index]) && !is_eol_char(buffer[index])))
837 index++;
838
839 len = index - start;
840 strncpy(component_path, &buffer[start], len);
841 component_path[len] = 0;
842
843 /* Append directory separator if needed */
844 if (component_path[strlen(component_path)] != DIR_SEPARATOR_CHAR)
845 {
846 int i = strlen(component_path);
847 component_path[strlen(component_path)] = DIR_SEPARATOR_CHAR;
848 component_path[i + 1] = 0;
849 }
850
851 /* Skip to end of line */
852 while ((index < size) && (!is_eol_char(buffer[index])))
853 index++;
854 if ((index < size) && (buffer[index] == '\n'))
855 index++;
856
857 canonical_path = convert_path(component_path);
858 if (canonical_path != NULL)
859 {
860 process_directory(canonical_path, canonical_path);
861 free(canonical_path);
862 generate_xml_for_component(component_name,
863 component_path);
864 }
865 }
866
867 write_line("</components>");
868}
#define index(s, c)
Definition: various.h:29
GLuint start
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLuint buffer
Definition: glext.h:5915
GLuint index
Definition: glext.h:6031
GLuint in
Definition: glext.h:9616
static void generate_xml_for_component(char *component_name, char *component_base)
Definition: rgenstat.c:682

Referenced by main().

◆ skip_comments()

static void skip_comments ( )
static

Definition at line 321 of file rgenstat.c.

322{
323 while ((file_pointer < file_size))
324 {
325 if (file_buffer[file_pointer] == '*')
326 {
327 if ((file_pointer + 1 < file_size))
328 {
329 if (file_buffer[file_pointer + 1] == '/')
330 {
331 skip_line();
332 return;
333 }
334 }
335 }
336 file_pointer++;
337 }
338}
static void skip_line()
Definition: rgenstat.c:308

Referenced by parse_file().

◆ skip_line()

static void skip_line ( )
static

Definition at line 308 of file rgenstat.c.

309{
311 {
312 file_pointer++;
313 }
314 if ((file_pointer < file_size) && (file_buffer[file_pointer] == '\n'))
315 {
316 file_pointer++;
317 }
318}

Referenced by skip_comments().

◆ skip_to_next_name()

static int skip_to_next_name ( char name)
static

Definition at line 392 of file rgenstat.c.

393{
394 while ((file_pointer < file_size))
395 {
396 if (file_buffer[file_pointer] == '(')
397 {
399 }
400 file_pointer++;
401 }
402 return 0;
403}
static int get_previous_identifier(unsigned int end, char *name)
Definition: rgenstat.c:341

Referenced by parse_file().

◆ skip_to_next_tag()

static int skip_to_next_tag ( )
static

Definition at line 270 of file rgenstat.c.

271{
272 unsigned int start;
273 int end_of_tag;
274 int found_tag = 0;
275 int tag_id;
276 int len;
277
278 tagname[0] = 0;
279 while ((file_pointer < file_size) && (!found_tag))
280 {
281 if (file_buffer[file_pointer] == '@')
282 {
283 file_pointer++;
285 end_of_tag = 0;
286 while ((file_pointer < file_size) && (!end_of_tag))
287 {
289 file_pointer++;
290 }
291 len = file_pointer > start ? file_pointer - start - 1 : 0;
293 tagname[len] = 0;
294
295 tag_id = get_tag_id(tagname);
296 if (tag_id != TAG_UNKNOWN)
297 {
298 return tag_id;
299 }
300 }
301 file_pointer++;
302 }
303
304 return TAG_UNKNOWN;
305}
static char tagname[200]
Definition: rgenstat.c:63
static int get_tag_id(char *tag)
Definition: rgenstat.c:256

Referenced by parse_file().

◆ sort_linked_list()

PAPI_INFO sort_linked_list ( PAPI_INFO  ,
unsigned  ,
int(*)(PAPI_INFO, PAPI_INFO  
)

◆ write_line()

static void write_line ( char line)
static

Definition at line 114 of file rgenstat.c.

115{
116 char buf[200];
117
118 memset(buf, 0, sizeof(buf));
119 strcpy(buf, line);
120 /* Terminate the line */
121 buf[strlen(buf)] = '\r';
122 buf[strlen(buf)] = '\n';
123
124 (void)fwrite(&buf[0], 1, strlen(buf), out);
125}
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
Definition: parser.c:49

Referenced by generate_xml_for_component(), and read_input_file().

Variable Documentation

◆ api_info_list

PAPI_INFO api_info_list = NULL
static

Definition at line 64 of file rgenstat.c.

Referenced by generate_xml_for_component(), parse_file(), and read_input_file().

◆ file_buffer

◆ file_handle

FILE* file_handle = NULL
static

Definition at line 59 of file rgenstat.c.

Referenced by close_file(), and read_file().

◆ file_pointer

unsigned int file_pointer = 0
static

◆ file_size

unsigned int file_size = 0
static

Definition at line 61 of file rgenstat.c.

Referenced by read_file(), skip_comments(), skip_line(), skip_to_next_name(), and skip_to_next_tag().

◆ HELP

char HELP[]
static
Initial value:
=
"RGENSTAT input-filename output-filename\n"
"\n"
" input-filename File containing list of components to process\n"
" output-filename File to create\n"

Definition at line 870 of file rgenstat.c.

Referenced by main().

◆ in

FILE* in
static

Definition at line 57 of file rgenstat.c.

◆ out

FILE* out
static

Definition at line 58 of file rgenstat.c.

Referenced by main(), and write_line().

◆ tagname