#include <stdio.h>
#include <ctype.h>
#include "xref.h"
struct codeword_entry *root;
substitute_references(line, char_p)
char line[MAXLINE];
int *char_p;
{
int reference_type;
char current_token[MAXLINE];
char temp_token[MAXLINE];
int token_type;
struct codeword_entry *node;
for (token_type = get_token(line, char_p, current_token, SKIP_SPACES);
token_type != ENDOFLINE_TOKEN;
token_type = get_token(line, char_p, current_token, DONT_SKIP_SPACES)) {
if (token_type != DELIMITER_TOKEN) {
printf("%s", current_token);
continue;
}
if (strcmp(current_token, "@") != 0) {
printf("%s", current_token);
continue;
}
token_type = get_token(line, char_p,
current_token, DONT_SKIP_SPACES);
if (token_type == ENDOFLINE_TOKEN)
break;
if (strcmp(current_token, "@") == 0) {
printf("%s", current_token);
continue;
}
if (token_type != ALPHA_TOKEN) {
printf("@%s", current_token);
continue;
}
if (SCComp(current_token, "numberof") == TRUE)
reference_type = NUMBER;
else if (SCComp(current_token, "titleof") == TRUE)
reference_type = TITLE;
else if (SCComp(current_token, "pagenumber") == TRUE)
reference_type = TITLE;
else {
fprintf(stderr, "%s: Unknown command %s at line %d of file %s\n",
command_name, current_token, line_number, current_filename);
printf("@%s", current_token);
continue;
}
token_type = get_token(line, char_p, current_token, DONT_SKIP_SPACES);
if (token_type != DELIMITER_TOKEN) {
printf("%s", current_token);
continue;
}
if (strcmp(current_token, "(") != 0) {
if (reference_type == NUMBER)
printf("@NumberOf%s", current_token);
else
printf("@TitleOf%s", current_token);
continue;
}
token_type = get_token(line, char_p, current_token, DONT_SKIP_SPACES);
if (token_type != ALPHA_TOKEN) {
if (reference_type == NUMBER)
printf("@NumberOf(%s", current_token);
else
printf("@TitleOf(%s", current_token);
continue;
}
if ((node = locate_codeword_entry(root, current_token)) == NULL) {
fprintf(stderr, "%s: Unknown codeword %s at line %d of file %s\n",
command_name, current_token, line_number, current_filename);
if (reference_type == NUMBER)
printf("@NumberOf(%s", current_token);
else
printf("@TitleOf(%s", current_token);
continue;
}
strcpy(temp_token, current_token);
token_type = get_token(line, char_p, current_token, DONT_SKIP_SPACES);
if (token_type != DELIMITER_TOKEN) {
if (reference_type == NUMBER)
printf("@NumberOf(%s%s", temp_token, current_token);
else
printf("@TitleOf(%s%s", temp_token, current_token);
continue;
}
if (strcmp(current_token, ")") != 0) {
if (reference_type == NUMBER)
printf("@NumberOf(%s%s", temp_token, current_token);
else
printf("@TitleOf(%s%s", temp_token, current_token);
continue;
}
print_reference(node, reference_type);
}
putchar('\n');
}
int
try_reference_line(line, char_p)
char *line;
int char_p;
{
char current_token[MAXLINE];
int token_type;
token_type = get_token(line, char_p, current_token, SKIP_SPACES);
if (token_type != DELIMITER_TOKEN)
return (FALSE);
if (strcmp(current_token, ".") != 0)
return (FALSE);
token_type = get_token(line, char_p, current_token, DONT_SKIP_SPACES);
if (token_type != ALPHA_TOKEN)
return (FALSE);
if (strcmp(current_token, "XR") != 0)
return (FALSE);
return (TRUE);
}