Category : C Source Code
Archive   : XCPP.ZIP
Filename : XCPP.C
#include
#include
#define NOCOMMENT -1
void replace_comments(FILE *in, FILE *out);
void main(int argc, char **argv);
char *build_out_name(char *fname);
short locate_cpp_comment(char *buf);
char *process_comment(char *buf, short index);
void get_help(void);
void main(int argc, char **argv)
{
FILE *in, *out;
char *outname;
if (argc != 2) {
get_help();
exit(-1);
}
in = fopen(argv[1], "r");
if (!in) {
printf("Can't open File %s\n", argv[1]);
exit(-1);
}
outname = build_out_name(argv[1]);
out = fopen(outname, "w");
if (!out) {
printf("Can't open File %s\n", outname);
exit(-1);
}
replace_comments(in, out);
fclose(in);
fclose(out);
}
void get_help(void)
{
printf("Usage: xcpp
printf("\nThis program extracts C++ comments from C programs");
printf("\nfor acceptance by C compilers that don't allow them");
printf("\nand replaces them with standard comments");
}
char *build_out_name(char *fname)
{
char buf[_MAX_PATH];
short i = 0;
for (i = 0; fname[i] != '.'; i++) {
buf[i] = fname[i];
}
buf[i] = '\0';
strcat(buf, ".xcp");
return(buf);
}
void replace_comments(FILE *in, FILE *out)
{
char inbuf[100];
char *outbuf;
short index;
while (fgets(inbuf, 100, in)) {
index = locate_cpp_comment(inbuf);
if (index != NOCOMMENT) {
outbuf = process_comment(inbuf, index);
}
else {
outbuf = inbuf;
}
fprintf(out, "%s", outbuf);
}
}
char *process_comment(char *buf, short index)
{
short i;
buf[index + 1] = '*';
for (i = index+1; buf[i] != '\n'; i++) {
;
}
buf[i++] = '*';
buf[i++] = '/';
buf[i++] = '\n';
buf[i] = '\0';
return(buf);
}
short locate_cpp_comment(char *buf)
{
short len;
short i;
len = strlen(buf);
for (i = 0; i < len; i++) {
if (buf[i] == '/' && buf[i+1] == '/') {
return(i);
}
}
return(NOCOMMENT);
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/