ccStyle accepts font changes. Empty class name triggers error message.

Boldface as font in C code added.
This commit is contained in:
Lutz Kettner 1997-05-23 12:41:54 +00:00
parent 12346c22b1
commit 1c861ef193
5 changed files with 102 additions and 30 deletions

View File

@ -158,6 +158,8 @@ const char* new_remember_font( char c) {
return new_remember_font( tt_font);
case 'I':
return new_remember_font( it_font);
case 'B':
return new_remember_font( bf_font);
default:
font_tag_buffer[0] = '\\';
font_tag_buffer[1] = c;
@ -1099,6 +1101,41 @@ char* convert_C_to_html( const char* txt) {
return formatted;
}
char* convert_ccStyle2_to_html( const char* txt) {
if ( txt == NULL) {
char *q = new char[1];
q[0] = '\0';
return q;
}
char* s = new char[ strlen_ascii_to_html( txt) + 1];
char* p = s;
while( *txt) {
if ( *txt == '\\' && isupper(txt[1]) && txt[2] == '\\') {
const char* q = new_remember_font( txt[1]);
while ( *q)
*p++ = *q++;
txt += 2;
} else
*p++ = *txt;
++txt;
}
*p = '\0';
return s;
}
char* convert_ccStyle_to_html( const char* txt) {
current_font = it_font;
char* tmp = convert_ccStyle2_to_html( txt);
const char* end_font = new_font_tags( it_font);
char* formatted = new char[ strlen( tmp) + strlen( end_font) + 8];
strcpy( formatted, "<I>");
strcat( formatted, tmp);
strcat( formatted, end_font);
strcat( formatted, "</I>");
delete[] tmp;
return formatted;
}
// No longer is a scope operator appended.
char* convert_ascii_to_scrambled_html( const char* txt) {
char* s = new char[ strlen_ascii_to_html( txt) + 1
@ -3052,6 +3089,15 @@ char cross_link_anchor_buffer[ cross_link_anchor_len];
int cross_link_anchor_counter = 0;
const char* handleHtmlCrossLink( const char* key, bool tmpl_class) {
// test empty key.
const char* p = key;
while( p && isspace(*p))
p++;
if ( !p || *p == '\0') {
printErrorMessage( EmptyCrossLinkError);
exit( 1);
}
char *tmp_name = convert_ascii_to_html( key);
*anchor_stream << "[a-zA-Z0-9_]\"" << tmp_name
<< "\" { ECHO; }" << endl;
@ -3089,6 +3135,15 @@ const char* handleHtmlCrossLink( const char* key, bool tmpl_class) {
}
void handleClasses( const char* classname, const char* template_cls) {
// test empty classname.
const char* p = classname;
while( p && isspace(*p))
p++;
if ( !p || *p == '\0') {
printErrorMessage( EmptyClassNameError);
exit( 1);
}
// Name manipulation.
if ( template_cls)
template_class_name = newstr( template_cls);

View File

@ -254,12 +254,12 @@ if ( "$in_files" == "") goto usage
# Make a subdirectory for the temp_path:
# --------------------------------------
set tmp_name = "extract_html_tmp"
if ( $?DEBUG) echo "# Make a subdirectory 'extract_html_tmp' for the tmp_path."
set tmp_name = "extract_html_tmp_$USER"
if ( $?DEBUG) echo "# Make a subdirectory $tmp_name for the tmp_path."
set new_tmp_path = ${tmp_path}/${tmp_name}
if ( -d ${new_tmp_path}) then
echo "error: the subdirectory 'extract_html_tmp' for the tmp_path exists already."
echo "error: the subdirectory $tmp_name for the tmp_path exists already."
echo " type 'rm -r ${new_tmp_path}' to remove it."
goto usage
endif

View File

@ -195,7 +195,9 @@ enum ErrorNumber {
IncludeNestingTooDeepError,
IncludeOpenError,
ChapterStructureError,
UnknownIndexCategoryError
UnknownIndexCategoryError,
EmptyClassNameError,
EmptyCrossLinkError
};

View File

@ -1430,6 +1430,12 @@ calblockintro ([\{][\\](cal))|([\\]mathcal[\{])
yylval.string.len = -1;
return STRING;
}
<CCMode,ccStyleMode>[\\]bf/{noletter} {
skipspaces();
yylval.string.text = "\\B\\";
yylval.string.len = -1;
return STRING;
}
<CCMode,ccStyleMode>[\\]ccFont/{noletter} {
skipspaces();
yylval.string.text = "\\I\\";
@ -1559,18 +1565,27 @@ void init_scanner( FILE* in){
void skipspaces( void) {
int c = yyinput();
while( c && c <= ' ')
while( c && c <= ' ') {
if ( c == '\n')
line_number++;
c = yyinput();
}
unput( c);
}
void skipoptionalparam( void) {
int c = yyinput();
while( c && c <= ' ')
while( c && c <= ' ') {
if ( c == '\n')
line_number++;
c = yyinput();
}
if ( c == '[')
while( c && c != ']')
while( c && c != ']') {
if ( c == '\n')
line_number++;
c = yyinput();
}
else
unput( c);
}

View File

@ -54,6 +54,7 @@ int CCMode = 0;
extern char* class_name;
extern char* formatted_class_name;
char* text_block_to_string( const Text& T);
char* convert_ccStyle_to_html( const char* txt);
/* for the bibliography */
/* ==================== */
@ -273,10 +274,12 @@ stmt: string { handleBuffer( * $1);
| CREATIONVARIABLE {}
| CCSTYLE '{' nested_token_sequence '}' {
set_INITIAL = 1;
handleString( "<I>");
handleText( * $3);
handleString( "</I>");
char* s = text_block_to_string( *$3);
char* p = convert_ccStyle_to_html(s);
handleString( p);
current_font = unknown_font;
delete[] p;
delete[] s;
delete $3;
}
| INCLUDE '{' comment_sequence '}' {
@ -847,23 +850,15 @@ compound_comment: '{' full_comment_sequence '}' {
$2);
}
| CCSTYLE '{' nested_token_sequence '}' {
$$ = $3;
set_INITIAL = 1;
if ( $$->isEmpty() ||
$$->head().isSpace) // should not
$$->cons( *new TextToken( "<I>", 1));
else
$$->head().prepend( "<I>");
InListFIter< TextToken> ix( * $$);
ForAll( ix) {
if ( ix.isLast())
if ( ix->isSpace)
$$->append( *new TextToken(
"</I>", 1));
else
ix->add( "</I>");
}
current_font = unknown_font;
set_INITIAL = 1;
char* s = text_block_to_string( *$3);
char* p = convert_ccStyle_to_html(s);
$$ = new Text( managed);
$$->cons( *new TextToken( p));
current_font = unknown_font;
delete[] p;
delete[] s;
delete $3;
}
| verbatim_style {
$$ = new Text( managed);
@ -1240,6 +1235,10 @@ const char* errorMessage( ErrorNumber n) {
return "Malformed chapter structure: one chapter per file";
case UnknownIndexCategoryError:
return "Unknown index category in optional argument of \\ccHtmlIndex";
case EmptyClassNameError:
return "The classname was empty";
case EmptyCrossLinkError:
return "The key for a cross link was empty";
}
return "UNKNOWN ERROR MESSAGE NUMBER";
}
@ -1254,13 +1253,14 @@ void printErrorMessage( ErrorNumber n){
// -----------------
Text* blockintroProcessing( const char* text, int len, Text* t) {
if ( len < 0) { /* Hack! Here we know that t has to get capitalized.*/
len = 4;
len = strlen(text);
InListFIter< TextToken> ix( *t);
ForAll( ix) {
if ( ! (*ix).isSpace) {
char *s = (*ix).string;
while ( *s) {
*s++ = toupper( *s);
*s = toupper( *s);
s++;
}
}
}
@ -1275,7 +1275,7 @@ Text* blockintroProcessing( const char* text, int len, Text* t) {
Buffer* blockintroProcessing( const char* text, int len, Buffer* t) {
if ( len < 0) { /* Hack! Here we know that t has to get capitalized.*/
len = 4;
len = strlen(text);
t->capitalize();
}
t->prepend( text, len);