|
|
|
@ -38,13 +38,13 @@ NON-STANDARD FEATURES |
|
|
|
|
|
|
|
============================================================================*/ |
|
|
|
|
|
|
|
#include "cmpp.h" |
|
|
|
#include <stdio.h> |
|
|
|
#include <ctype.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdarg.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
#include "cmpp.h" |
|
|
|
|
|
|
|
|
|
|
|
/* *********************************************************************** */ |
|
|
|
@ -52,17 +52,17 @@ NON-STANDARD FEATURES |
|
|
|
char *prog_name; |
|
|
|
|
|
|
|
|
|
|
|
/* Initialize print_error() with the name of the program */ |
|
|
|
|
|
|
|
void init_error (char *program_name) |
|
|
|
/* Initialize external variable prog_name with the name of the program. |
|
|
|
* A copy is not made. */ |
|
|
|
void init_error(char *program_name) |
|
|
|
{ |
|
|
|
prog_name = program_name; |
|
|
|
} |
|
|
|
|
|
|
|
} /* end of function init_error */ |
|
|
|
|
|
|
|
|
|
|
|
/* Print an error message to stderr */ |
|
|
|
|
|
|
|
/* Print an error message to stderr. The message is prefixed with the |
|
|
|
* name of the program and a newline character is added to the end. */ |
|
|
|
void print_error(const char *fmt, ...) |
|
|
|
{ |
|
|
|
va_list ap; |
|
|
|
@ -73,37 +73,41 @@ void print_error(const char *fmt, ...) |
|
|
|
fprintf(stderr, "\n"); |
|
|
|
|
|
|
|
va_end(ap); |
|
|
|
} |
|
|
|
} /* end of function print_error */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Convert a string to all lower case */ |
|
|
|
|
|
|
|
void str_to_lower(char *s) |
|
|
|
{ |
|
|
|
int i; |
|
|
|
char c; |
|
|
|
int i; |
|
|
|
char c; |
|
|
|
|
|
|
|
for(i = 0; (c = s[i]) != '\0'; i++) |
|
|
|
for(i = 0; (c = s[i]) != '\0'; i++) { |
|
|
|
s[i] = tolower_c(c); |
|
|
|
} |
|
|
|
} |
|
|
|
} /* end of function str_to_lower */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* If *path_p is relative, prefix with the CMPP output or input string |
|
|
|
* build the path and open the file and return the path that was created. */ |
|
|
|
FILE *fopen_cmpp(const char **path_p, const char *mode) |
|
|
|
{ |
|
|
|
const char *path = *path_p; |
|
|
|
|
|
|
|
char buf[MAX_PATH_LEN+1]; |
|
|
|
char buf[MAX_PATH_LEN + 1]; |
|
|
|
|
|
|
|
if(path[0] != '/') { |
|
|
|
if (path[0] != '/') { |
|
|
|
const char *e = getenv((*mode == 'w') ? "CMPP_ODIR" : "CMPP_IDIR"); |
|
|
|
if(e) { |
|
|
|
if(strlen(e) + 1 + strlen(path) < sizeof(buf)) { |
|
|
|
if (e) { |
|
|
|
if (strlen(e) + 1 + strlen(path) < sizeof(buf)) { |
|
|
|
strcpy(buf, e); |
|
|
|
strcat(buf, "/"); |
|
|
|
strcat(buf, path); |
|
|
|
path = buf; |
|
|
|
} else { |
|
|
|
} |
|
|
|
else { |
|
|
|
path = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -112,4 +116,7 @@ FILE *fopen_cmpp(const char **path_p, const char *mode) |
|
|
|
*path_p = strdup(path); |
|
|
|
|
|
|
|
return fopen(path, mode); |
|
|
|
} |
|
|
|
} /* end of function fopen_cmpp */ |
|
|
|
|
|
|
|
|
|
|
|
|