3 * Copyright (C) 2007, The Perl Foundation.
10 pirutil.c - various utility functions
20 #include "parrot/parrot.h"
28 =item C<char * clone_string(NOTNULL(char const * src))>
30 clone a string. Copy the characters of src into dest
31 and return dest. Memory allocation is done by this function, keeping
32 this function's client code simple. Please free() the memory after usage!
38 clone_string(NOTNULL(char const * src
))
44 /* dest is used as an iterator, ptr - still pointing to the beginning
45 * of the string - is returned
47 dest
= ptr
= (char *)calloc(srclen
+ 1, sizeof (char));
56 =item C<FILE * open_file(char const *filename, char const *mode)>
58 Open the file C<filename> in mode C<mode>. If this fails, an error message
59 is printed, and the program is terminated.
65 open_file(char const *filename
, char const *mode
)
67 FILE *file
= fopen(filename
, mode
);
70 fprintf(stderr
, "Failed to open file '%s' in mode '%s'\nTerminating\n", filename
, mode
);
79 =item C<void printverbose(char *message)>
81 Prints the specified message if the verbose flag was set
87 printverbose(char *message
)
89 fprintf(stdout
, message
);
94 =item C<void printdebug(char *message)>
96 Prints the specified message if the debug flag was set.
102 printdebug(char *message
)
104 fprintf(stdout
, message
);
109 /* Array holding all parrot ops */
110 static char const *parrot_ops
[] = {
298 "get_root_namespace",
428 =item C<int is_op(char *id)>
430 Return 1 if the specified id is a Parrot op, 0 otherwise.
438 char const *iter
= parrot_ops
[0];
441 /* very inefficient implementation, but for now it works */
442 /* suggestions: hashtable, binary search */
444 while (iter
!= NULL
) {
445 if (strcmp(iter
, id
) == 0)
448 iter
= parrot_ops
[++index
];
466 * c-file-style: "parrot"
468 * vim: expandtab shiftwidth=4: