#endif
/* The biggest line we can read in from a file */
-#define LINEBUFFERSIZE 400
+#define LINEBUFFERSIZE 1024
#define NUMTILDESUBS 30
#define NUMCONFIGSUBS 1000
#define TOKENBUFFERSIZE 80
{
FILE *ConfigSH, *Config_H;
char LineBuffer[LINEBUFFERSIZE], *TempValue, *StartTilde, *EndTilde;
- char SecondaryLineBuffer[LINEBUFFERSIZE];
+ char SecondaryLineBuffer[LINEBUFFERSIZE], OutBuf[LINEBUFFERSIZE];
char TokenBuffer[TOKENBUFFERSIZE];
int LineBufferLength, TempLength, DummyVariable, LineBufferLoop;
- int TokenBufferLoop, ConfigSubLoop, GotIt;
+ int TokenBufferLoop, ConfigSubLoop, GotIt, OutBufPos;
Translate TildeSub[NUMTILDESUBS]; /* Holds the tilde (~FOO~) */
/* substitutions */
Translate ConfigSub[NUMCONFIGSUBS]; /* Holds the substitutions from */
/* Any tag/value pairs on the command line? */
if (argc > 3) {
int i;
- char WorkString[80];
+ char WorkString[LINEBUFFERSIZE];
for (i=3; i < argc && argv[i]; i++) {
/* Local copy */
LineBufferLength--;
}
+ OutBufPos = 0;
/* Right. Go looking for $s. */
for(LineBufferLoop = 0; LineBufferLoop < LineBufferLength;
LineBufferLoop++) {
/* Did we find one? */
if ('$' != LineBuffer[LineBufferLoop]) {
/* Nope, spit out the value */
- putchar(LineBuffer[LineBufferLoop]);
+ OutBuf[OutBufPos++] = LineBuffer[LineBufferLoop];
} else {
/* Yes, we did. Is it escaped? */
if ((LineBufferLoop > 0) && ('\\' == LineBuffer[LineBufferLoop -
1])) {
/* Yup. Spit it out */
- putchar(LineBuffer[LineBufferLoop]);
+ OutBuf[OutBufPos++] = LineBuffer[LineBufferLoop];
} else {
/* Nope. Go grab us a token */
TokenBufferLoop = 0;
for(ConfigSubLoop = 0; ConfigSubLoop < ConfigSubCount;
ConfigSubLoop++) {
if (!strcmp(TokenBuffer, ConfigSub[ConfigSubLoop].Tag)) {
- GotIt = 1;
- printf("%s", ConfigSub[ConfigSubLoop].Value);
+ char *cp = ConfigSub[ConfigSubLoop].Value;
+ GotIt = 1;
+ while (*cp) OutBuf[OutBufPos++] = *(cp++);
break;
}
}
/* Did we find something? If not, spit out what was in our */
/* buffer */
if (!GotIt) {
- printf("$%s", TokenBuffer);
+ char *cp = TokenBuffer;
+ OutBuf[OutBufPos++] = '$';
+ while (*cp) OutBuf[OutBufPos++] = *(cp++);
}
} else {
/* Just a bare $. Spit it out */
- putchar('$');
+ OutBuf[OutBufPos++] = '$';
}
}
}
}
- /* We're all done. Spit out an EOL */
- printf("\n");
-
-
+ /* If we've created an #undef line, make sure we don't output anthing
+ * after the "#undef FOO" besides comments. We could do this as we
+ * go by recognizing the #undef as it goes by, and thus avoid another
+ * use of a fixed-length buffer, but this is simpler.
+ */
+ if (!strncmp(OutBuf,"#undef",6)) {
+ char *cp = OutBuf;
+ int i, incomment = 0;
+ LineBufferLoop = 0;
+ OutBuf[OutBufPos] = '\0';
+ for (i = 0; i <= 1; i++) {
+ while (!isspace(*cp)) LineBuffer[LineBufferLoop++] = *(cp++);
+ while ( isspace(*cp)) LineBuffer[LineBufferLoop++] = *(cp++);
+ }
+ while (*cp) {
+ while (isspace(*cp)) LineBuffer[LineBufferLoop++] = *(cp++);
+ if (!incomment && *cp == '/' && *(cp+1) == '*') incomment = 1;
+ while (*cp && !isspace(*cp)) {
+ if (incomment) LineBuffer[LineBufferLoop++] = *cp;
+ cp++;
+ }
+ if (incomment && *cp == '*' && *(cp+1) == '/') incomment = 0;
+ }
+ LineBuffer[LineBufferLoop] = '\0';
+ puts(LineBuffer);
+ }
+ else {
+ OutBuf[OutBufPos] = '\0';
+ puts(OutBuf);
+ }
}
/* Close the files */
} else {
/* 'Kay, not a tilde. Is it a word character? */
- if (isalnum(LineBuffer[TildeLoop]) || (LineBuffer[TildeLoop] =
- '-') ||
+ if (isalnum(LineBuffer[TildeLoop]) ||
(LineBuffer[TildeLoop] == '-')) {
TempTilde[TildeBufferLength++] = LineBuffer[TildeLoop];
} else {